Skip to content

Commit aed3a34

Browse files
facchinmcmaglie
authored andcommitted
[bl] add Leonardo-like led pulse
1 parent fb2ab4a commit aed3a34

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

bootloaders/zero/board_driver_led.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ inline void LEDTX_on(void) { PORT->Group[BOARD_LEDTX_PORT].OUTCLR.reg = (1<<BOAR
3838
inline void LEDTX_off(void) { PORT->Group[BOARD_LEDTX_PORT].OUTSET.reg = (1<<BOARD_LEDTX_PIN); }
3939
inline void LEDTX_toggle(void) { PORT->Group[BOARD_LEDTX_PORT].OUTTGL.reg = (1<<BOARD_LEDTX_PIN); }
4040

41+
inline void LED_configure(uint32_t sampleRate) { SysTick_Config(sampleRate); }
42+
4143
#endif // _BOARD_DRIVER_LED_

bootloaders/zero/board_startup.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include <sam.h>
21+
#include "board_driver_led.h"
2122

2223
struct ConstVectors
2324
{
@@ -140,8 +141,25 @@ void PendSV_Handler(void)
140141
while (1);
141142
}
142143

144+
volatile uint8_t keepValue = 0;
145+
volatile uint8_t targetValue = 20;
146+
volatile int8_t direction = 1;
147+
143148
void SysTick_Handler(void)
144149
{
145-
__BKPT(1);
146-
while (1);
147-
}
150+
if (keepValue == 0) {
151+
targetValue += direction;
152+
LED_toggle();
153+
}
154+
keepValue ++;
155+
156+
if (targetValue > 240 || targetValue < 10) {
157+
direction = -direction;
158+
targetValue += direction;
159+
}
160+
161+
if (keepValue == targetValue) {
162+
LED_toggle();
163+
}
164+
//TC5->COUNT16.INTFLAG.bit.MC0 = 1; // Clear interrupt
165+
}

bootloaders/zero/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ int main(void)
181181

182182
/* Initialize LEDs */
183183
LED_init();
184-
LED_on();
184+
LED_configure(1000);
185185
LEDRX_init();
186186
LEDRX_off();
187187
LEDTX_init();

0 commit comments

Comments
 (0)