Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Commit 1a4bc10

Browse files
authored
Merge pull request #3 from alfran/development
Development
2 parents 94b2460 + 21b1097 commit 1a4bc10

File tree

15 files changed

+212
-1057
lines changed

15 files changed

+212
-1057
lines changed

cores/arduino/HardwareSPI.h

Lines changed: 0 additions & 163 deletions
This file was deleted.

cores/arduino/HardwareTimer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ void HardwareTimer::attachInterrupt(int channel, voidFuncPtr handler) {
128128
timer_attach_interrupt(this->dev, (uint8)channel, handler);
129129
}
130130

131+
void HardwareTimer::toneAttachInterrupt(int channel, voidFuncPtr handler) {
132+
tone_attach_interrupt(this->dev, (uint8)channel, handler);
133+
}
134+
131135
void HardwareTimer::detachInterrupt(int channel) {
132136
timer_detach_interrupt(this->dev, (uint8)channel);
133137
}

cores/arduino/HardwareTimer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class HardwareTimer {
192192
* @see voidFuncPtr
193193
*/
194194
void attachInterrupt(int channel, voidFuncPtr handler);
195+
void toneAttachInterrupt(int channel, voidFuncPtr handler); // alfran : used for tone
195196

196197
/**
197198
* @brief Remove the interrupt handler attached to the given

cores/arduino/HardwareSPI.cpp renamed to cores/arduino/SPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern "C" {
2424

2525
}
2626

27-
#include "HardwareSPI.h"
27+
#include "SPI.h"
2828
SPIClass SPI;
2929

3030
SPI_HandleTypeDef hSPIx;

cores/arduino/Tone.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Version Modified By Date Comments
4040

4141
volatile static int toggle_count=0;
4242
static int tone_pin;
43-
int timer_CH = 2;
43+
int timer_CH = 5;
4444

4545
HardwareTimer timer(timer_CH);
4646

@@ -55,7 +55,7 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
5555
timer.setOverflow(1000000/frequency/4);
5656
timer.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);
5757
timer.setCompare(TIMER_CH1, 1); // Interrupt 1 count after each update
58-
timer.attachInterrupt(TIMER_CH1, handler_tone);
58+
timer.toneAttachInterrupt(TIMER_CH1, handler_tone);
5959
timer.refresh(); // start it up
6060
timer.resume();
6161

@@ -66,17 +66,23 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
6666
void noTone(uint8_t pin)
6767
{
6868
timer.pause();
69-
gpio_write_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, 0);
70-
71-
return;
69+
timer.setPrescaleFactor(1);
70+
timer.setOverflow(0xFFFF);
71+
timer.setMode(TIMER_CH1, TIMER_PWM);
72+
timer.refresh();
73+
timer.resume();
74+
gpio_write_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, 0);
75+
pinMode(pin,INPUT); //to fix dfu issue
76+
77+
return;
7278
}
73-
79+
/*
7480
void set_timer(int ch)
7581
{
7682
HardwareTimer timer(ch);
7783
timer_CH = ch;
7884
}
79-
85+
*/
8086
void handler_tone(void)
8187
{
8288
if (toggle_count != 0){

cores/arduino/pwm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void analogWrite(uint8 pin, uint16 passed_val)
6767
timer_dev *dev = PIN_MAP[pin].timer_device;
6868
if (pin >= GPIO_PINS || dev == NULL || dev->type == TIMER_BASIC)
6969
{
70-
return;
70+
return;
7171
}
7272
if (PIN_MAP[pin].alternate_function != AFx)
7373
{
@@ -76,6 +76,7 @@ void analogWrite(uint8 pin, uint16 passed_val)
7676
timer_set_compare(dev, PIN_MAP[pin].timer_channel, duty_cycle);
7777
timer_cc_enable(dev, PIN_MAP[pin].timer_channel);
7878
gpio_set_mode(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, GPIO_AF_OUTPUT_PP);
79+
7980
}
8081
}
8182

0 commit comments

Comments
 (0)