Skip to content

Commit 642fbcf

Browse files
committed
Handle status led power
This no longer turns on status LED power before running user code. Therefore, use of the status LED on some boards will also have to enable the power.
1 parent 6164d44 commit 642fbcf

File tree

15 files changed

+46
-38
lines changed

15 files changed

+46
-38
lines changed

main.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
338338
#if CIRCUITPY_STATUS_LED
339339
uint32_t color;
340340
uint8_t blink_count;
341+
bool led_active = false;
341342
#if CIRCUITPY_ALARM
342343
if (result.return_code & PYEXEC_DEEP_SLEEP) {
343344
color = BLACK;
@@ -360,9 +361,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
360361
size_t single_blink_time = (OFF_ON_RATIO + 1) * BLINK_TIME_MS;
361362
size_t blink_time = single_blink_time * blink_count;
362363
size_t total_time = blink_time + LED_SLEEP_TIME_MS;
363-
if (blink_count > 0) {
364-
status_led_init();
365-
}
366364
#endif
367365

368366
#if CIRCUITPY_ALARM
@@ -432,7 +430,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
432430
common_hal_alarm_pretending_deep_sleep();
433431
} else if (connecting_delay_ticks < 0) {
434432
// Entering deep sleep (may be fake or real.)
435-
new_status_color(BLACK);
436433
board_deinit();
437434
if (!supervisor_workflow_active()) {
438435
// Enter true deep sleep. When we wake up we'll be back at the
@@ -469,15 +466,28 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
469466
if (tick_diff < blink_time) {
470467
uint32_t blink_diff = tick_diff % (single_blink_time);
471468
if (blink_diff >= BLINK_TIME_MS) {
472-
new_status_color(BLACK);
469+
if (led_active) {
470+
new_status_color(BLACK);
471+
status_led_deinit();
472+
led_active = false;
473+
}
473474
time_to_next_change = single_blink_time - blink_diff;
474475
} else {
475-
new_status_color(color);
476+
if (!led_active) {
477+
status_led_init();
478+
new_status_color(color);
479+
led_active = true;
480+
}
476481
time_to_next_change = BLINK_TIME_MS - blink_diff;
477482
}
478483
} else if (tick_diff > total_time) {
479484
pattern_start = supervisor_ticks_ms32();
480485
} else {
486+
if (led_active) {
487+
new_status_color(BLACK);
488+
status_led_deinit();
489+
led_active = false;
490+
}
481491
time_to_next_change = total_time - tick_diff;
482492
}
483493
#if CIRCUITPY_DISPLAYIO
@@ -495,8 +505,10 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
495505
}
496506
// Done waiting, start the board back up.
497507
#if CIRCUITPY_STATUS_LED
498-
new_status_color(BLACK);
499-
status_led_deinit();
508+
if (led_active) {
509+
new_status_color(BLACK);
510+
status_led_deinit();
511+
}
500512
#endif
501513

502514
#if CIRCUITPY_ALARM

ports/atmel-samd/boards/feather_m4_can/mpconfigboard.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
// Rev E
77

88
#define MICROPY_HW_LED_STATUS (&pin_PA23)
9-
#define MICROPY_HW_NEOPIXEL (&pin_PB03)
9+
#define MICROPY_HW_NEOPIXEL (&pin_PB02)
10+
#define CIRCUITPY_STATUS_LED_POWER (&pin_PB03)
1011

1112
// These are pins not to reset.
1213
// QSPI Data pins
1314
#define MICROPY_PORT_A (PORT_PA08 | PORT_PA09 | PORT_PA10 | PORT_PA11)
1415
// QSPI CS, QSPI SCK and NeoPixel pin
15-
#define MICROPY_PORT_B (PORT_PB03 | PORT_PB10 | PORT_PB11)
16+
#define MICROPY_PORT_B (PORT_PB10 | PORT_PB11)
1617
#define MICROPY_PORT_C (0)
1718
#define MICROPY_PORT_D (0)
1819

ports/atmel-samd/boards/qtpy_m0/board.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,8 @@
2525
*/
2626

2727
#include "supervisor/board.h"
28-
#include "common-hal/microcontroller/Pin.h"
29-
#include "supervisor/shared/board.h"
30-
#include "hal/include/hal_gpio.h"
3128

3229
void board_init(void) {
33-
gpio_set_pin_function(PIN_PA15, GPIO_PIN_FUNCTION_OFF);
34-
gpio_set_pin_direction(PIN_PA15, GPIO_DIRECTION_OUT);
35-
gpio_set_pin_level(PIN_PA15, true); // Turn on neopixel by default
36-
never_reset_pin_number(PIN_PA15);
3730
}
3831

3932
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/qtpy_m0/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MICROPY_HW_MCU_NAME "samd21e18"
33

44
#define MICROPY_HW_NEOPIXEL (&pin_PA18)
5+
#define CIRCUITPY_STATUS_LED_POWER (&pin_PA15)
56

67
#define MICROPY_PORT_A (0)
78
#define MICROPY_PORT_B (0)

ports/atmel-samd/boards/qtpy_m0_haxpress/board.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,8 @@
2525
*/
2626

2727
#include "supervisor/board.h"
28-
#include "common-hal/microcontroller/Pin.h"
29-
#include "supervisor/shared/board.h"
30-
#include "hal/include/hal_gpio.h"
3128

3229
void board_init(void) {
33-
gpio_set_pin_function(PIN_PA15, GPIO_PIN_FUNCTION_OFF);
34-
gpio_set_pin_direction(PIN_PA15, GPIO_DIRECTION_OUT);
35-
gpio_set_pin_level(PIN_PA15, true); // Turn on neopixel by default
36-
never_reset_pin_number(PIN_PA15);
3730
}
3831

3932
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/qtpy_m0_haxpress/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MICROPY_HW_MCU_NAME "samd21e18"
33

44
#define MICROPY_HW_NEOPIXEL (&pin_PA18)
5+
#define CIRCUITPY_STATUS_LED_POWER (&pin_PA15)
56

67
#define MICROPY_PORT_A (0)
78
#define MICROPY_PORT_B (0)

ports/esp32s2/boards/adafruit_feather_esp32s2_nopsram/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define MICROPY_HW_MCU_NAME "ESP32S2"
3131

3232
#define MICROPY_HW_NEOPIXEL (&pin_GPIO33)
33+
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO21)
3334

3435
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
3536

ports/esp32s2/boards/adafruit_feather_esp32s2_tftback_nopsram/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define MICROPY_HW_MCU_NAME "ESP32S2"
3131

3232
#define MICROPY_HW_NEOPIXEL (&pin_GPIO33)
33+
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO21)
3334

3435
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
3536

ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define MICROPY_HW_MCU_NAME "ESP32S2"
3131

3232
#define MICROPY_HW_NEOPIXEL (&pin_GPIO1)
33+
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO21)
3334

3435
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
3536

ports/esp32s2/boards/unexpectedmaker_tinys2/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define MICROPY_HW_MCU_NAME "ESP32S2"
3131

3232
#define MICROPY_HW_NEOPIXEL (&pin_GPIO1)
33+
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO2)
3334
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
3435
#define BOARD_USER_SAFE_MODE_ACTION translate("pressing boot button at start up.\n")
3536

0 commit comments

Comments
 (0)