Skip to content

Commit 11fa3d3

Browse files
committed
pulse D13 LED during bootloader active
1 parent fd50d90 commit 11fa3d3

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

bootloaders/zero/main.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,15 @@ int main(void)
280280
pCdc = (P_USB_CDC)usb_init();
281281
#endif
282282
DEBUG_PIN_LOW;
283+
284+
// output on D13 (PA.17)
285+
LED_PORT.PINCFG[LED_PIN].reg &= ~ (uint8_t)(PORT_PINCFG_INEN);
286+
LED_PORT.DIRSET.reg = (uint32_t)(1 << LED_PIN);
287+
283288
/* Wait for a complete enum on usb or a '#' char on serial line */
284289
while (1) {
290+
pulse_led(1); // while we're waiting, blink the D13
291+
285292
#if SAM_BA_INTERFACE == SAM_BA_USBCDC_ONLY || SAM_BA_INTERFACE == SAM_BA_BOTH_INTERFACES
286293
if (pCdc->IsConfigured(pCdc) != 0) {
287294
main_b_cdc_enable = true;
@@ -309,3 +316,28 @@ int main(void)
309316
#endif
310317
}
311318
}
319+
320+
321+
// We'll have the D13 LED slowly pulse on and off with bitbang PWM
322+
// for a nice 'hey we're in bootload mode' indication! -ada
323+
static uint8_t pulse_tick=0;
324+
static int8_t pulse_dir=1;
325+
static int16_t pulse_pwm;
326+
void pulse_led(int8_t speed) {
327+
// blink D13
328+
pulse_tick++;
329+
if (pulse_tick==0) {
330+
pulse_pwm += pulse_dir * speed;
331+
if (pulse_pwm > 255) {
332+
pulse_pwm = 255;
333+
pulse_dir = -1;
334+
}
335+
if (pulse_pwm < 0) {
336+
pulse_pwm = 0;
337+
pulse_dir = +1;
338+
}
339+
LED_ON;
340+
}
341+
if (pulse_tick==pulse_pwm)
342+
LED_OFF;
343+
}

bootloaders/zero/main.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929

3030
#pragma once
3131

32+
// Gently pulse the D13 LED
33+
#define LED_PIN 17
34+
#define PORTA PORT->Group[0]
35+
#define LED_PORT PORTA
36+
37+
#define LED_ON LED_PORT.OUTSET.reg = (uint32_t)(1 << LED_PIN);
38+
#define LED_OFF LED_PORT.OUTCLR.reg = (uint32_t)(1 << LED_PIN);
3239
/*
3340
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
3441
* quickly tapping two times on the reset button.

bootloaders/zero/sam_ba_monitor.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ void put_uint32(uint32_t n) {
201201

202202
void sam_ba_monitor_loop(void)
203203
{
204+
pulse_led(3);
204205
length = ptr_monitor_if->getdata(data, SIZEBUFMAX);
205206
ptr = data;
206207
for (i = 0; i < length; i++, ptr++)

0 commit comments

Comments
 (0)