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.
This commit is contained in:
Scott Shawcroft 2021-05-18 15:56:37 -07:00
parent 6164d44e6d
commit 642fbcf87a
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
15 changed files with 46 additions and 38 deletions

20
main.c
View File

@ -338,6 +338,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
#if CIRCUITPY_STATUS_LED #if CIRCUITPY_STATUS_LED
uint32_t color; uint32_t color;
uint8_t blink_count; uint8_t blink_count;
bool led_active = false;
#if CIRCUITPY_ALARM #if CIRCUITPY_ALARM
if (result.return_code & PYEXEC_DEEP_SLEEP) { if (result.return_code & PYEXEC_DEEP_SLEEP) {
color = BLACK; color = BLACK;
@ -360,9 +361,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
size_t single_blink_time = (OFF_ON_RATIO + 1) * BLINK_TIME_MS; size_t single_blink_time = (OFF_ON_RATIO + 1) * BLINK_TIME_MS;
size_t blink_time = single_blink_time * blink_count; size_t blink_time = single_blink_time * blink_count;
size_t total_time = blink_time + LED_SLEEP_TIME_MS; size_t total_time = blink_time + LED_SLEEP_TIME_MS;
if (blink_count > 0) {
status_led_init();
}
#endif #endif
#if CIRCUITPY_ALARM #if CIRCUITPY_ALARM
@ -432,7 +430,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
common_hal_alarm_pretending_deep_sleep(); common_hal_alarm_pretending_deep_sleep();
} else if (connecting_delay_ticks < 0) { } else if (connecting_delay_ticks < 0) {
// Entering deep sleep (may be fake or real.) // Entering deep sleep (may be fake or real.)
new_status_color(BLACK);
board_deinit(); board_deinit();
if (!supervisor_workflow_active()) { if (!supervisor_workflow_active()) {
// Enter true deep sleep. When we wake up we'll be back at the // 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) {
if (tick_diff < blink_time) { if (tick_diff < blink_time) {
uint32_t blink_diff = tick_diff % (single_blink_time); uint32_t blink_diff = tick_diff % (single_blink_time);
if (blink_diff >= BLINK_TIME_MS) { if (blink_diff >= BLINK_TIME_MS) {
if (led_active) {
new_status_color(BLACK); new_status_color(BLACK);
status_led_deinit();
led_active = false;
}
time_to_next_change = single_blink_time - blink_diff; time_to_next_change = single_blink_time - blink_diff;
} else { } else {
if (!led_active) {
status_led_init();
new_status_color(color); new_status_color(color);
led_active = true;
}
time_to_next_change = BLINK_TIME_MS - blink_diff; time_to_next_change = BLINK_TIME_MS - blink_diff;
} }
} else if (tick_diff > total_time) { } else if (tick_diff > total_time) {
pattern_start = supervisor_ticks_ms32(); pattern_start = supervisor_ticks_ms32();
} else { } else {
if (led_active) {
new_status_color(BLACK);
status_led_deinit();
led_active = false;
}
time_to_next_change = total_time - tick_diff; time_to_next_change = total_time - tick_diff;
} }
#if CIRCUITPY_DISPLAYIO #if CIRCUITPY_DISPLAYIO
@ -495,8 +505,10 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
} }
// Done waiting, start the board back up. // Done waiting, start the board back up.
#if CIRCUITPY_STATUS_LED #if CIRCUITPY_STATUS_LED
if (led_active) {
new_status_color(BLACK); new_status_color(BLACK);
status_led_deinit(); status_led_deinit();
}
#endif #endif
#if CIRCUITPY_ALARM #if CIRCUITPY_ALARM

View File

@ -6,13 +6,14 @@
// Rev E // Rev E
#define MICROPY_HW_LED_STATUS (&pin_PA23) #define MICROPY_HW_LED_STATUS (&pin_PA23)
#define MICROPY_HW_NEOPIXEL (&pin_PB03) #define MICROPY_HW_NEOPIXEL (&pin_PB02)
#define CIRCUITPY_STATUS_LED_POWER (&pin_PB03)
// These are pins not to reset. // These are pins not to reset.
// QSPI Data pins // QSPI Data pins
#define MICROPY_PORT_A (PORT_PA08 | PORT_PA09 | PORT_PA10 | PORT_PA11) #define MICROPY_PORT_A (PORT_PA08 | PORT_PA09 | PORT_PA10 | PORT_PA11)
// QSPI CS, QSPI SCK and NeoPixel pin // QSPI CS, QSPI SCK and NeoPixel pin
#define MICROPY_PORT_B (PORT_PB03 | PORT_PB10 | PORT_PB11) #define MICROPY_PORT_B (PORT_PB10 | PORT_PB11)
#define MICROPY_PORT_C (0) #define MICROPY_PORT_C (0)
#define MICROPY_PORT_D (0) #define MICROPY_PORT_D (0)

View File

@ -25,15 +25,8 @@
*/ */
#include "supervisor/board.h" #include "supervisor/board.h"
#include "common-hal/microcontroller/Pin.h"
#include "supervisor/shared/board.h"
#include "hal/include/hal_gpio.h"
void board_init(void) { void board_init(void) {
gpio_set_pin_function(PIN_PA15, GPIO_PIN_FUNCTION_OFF);
gpio_set_pin_direction(PIN_PA15, GPIO_DIRECTION_OUT);
gpio_set_pin_level(PIN_PA15, true); // Turn on neopixel by default
never_reset_pin_number(PIN_PA15);
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -2,6 +2,7 @@
#define MICROPY_HW_MCU_NAME "samd21e18" #define MICROPY_HW_MCU_NAME "samd21e18"
#define MICROPY_HW_NEOPIXEL (&pin_PA18) #define MICROPY_HW_NEOPIXEL (&pin_PA18)
#define CIRCUITPY_STATUS_LED_POWER (&pin_PA15)
#define MICROPY_PORT_A (0) #define MICROPY_PORT_A (0)
#define MICROPY_PORT_B (0) #define MICROPY_PORT_B (0)

View File

@ -25,15 +25,8 @@
*/ */
#include "supervisor/board.h" #include "supervisor/board.h"
#include "common-hal/microcontroller/Pin.h"
#include "supervisor/shared/board.h"
#include "hal/include/hal_gpio.h"
void board_init(void) { void board_init(void) {
gpio_set_pin_function(PIN_PA15, GPIO_PIN_FUNCTION_OFF);
gpio_set_pin_direction(PIN_PA15, GPIO_DIRECTION_OUT);
gpio_set_pin_level(PIN_PA15, true); // Turn on neopixel by default
never_reset_pin_number(PIN_PA15);
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -2,6 +2,7 @@
#define MICROPY_HW_MCU_NAME "samd21e18" #define MICROPY_HW_MCU_NAME "samd21e18"
#define MICROPY_HW_NEOPIXEL (&pin_PA18) #define MICROPY_HW_NEOPIXEL (&pin_PA18)
#define CIRCUITPY_STATUS_LED_POWER (&pin_PA15)
#define MICROPY_PORT_A (0) #define MICROPY_PORT_A (0)
#define MICROPY_PORT_B (0) #define MICROPY_PORT_B (0)

View File

@ -30,6 +30,7 @@
#define MICROPY_HW_MCU_NAME "ESP32S2" #define MICROPY_HW_MCU_NAME "ESP32S2"
#define MICROPY_HW_NEOPIXEL (&pin_GPIO33) #define MICROPY_HW_NEOPIXEL (&pin_GPIO33)
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO21)
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0) #define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)

View File

@ -30,6 +30,7 @@
#define MICROPY_HW_MCU_NAME "ESP32S2" #define MICROPY_HW_MCU_NAME "ESP32S2"
#define MICROPY_HW_NEOPIXEL (&pin_GPIO33) #define MICROPY_HW_NEOPIXEL (&pin_GPIO33)
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO21)
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0) #define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)

View File

@ -30,6 +30,7 @@
#define MICROPY_HW_MCU_NAME "ESP32S2" #define MICROPY_HW_MCU_NAME "ESP32S2"
#define MICROPY_HW_NEOPIXEL (&pin_GPIO1) #define MICROPY_HW_NEOPIXEL (&pin_GPIO1)
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO21)
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0) #define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)

View File

@ -30,6 +30,7 @@
#define MICROPY_HW_MCU_NAME "ESP32S2" #define MICROPY_HW_MCU_NAME "ESP32S2"
#define MICROPY_HW_NEOPIXEL (&pin_GPIO1) #define MICROPY_HW_NEOPIXEL (&pin_GPIO1)
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO2)
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0) #define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
#define BOARD_USER_SAFE_MODE_ACTION translate("pressing boot button at start up.\n") #define BOARD_USER_SAFE_MODE_ACTION translate("pressing boot button at start up.\n")

View File

@ -26,14 +26,7 @@
#include "supervisor/board.h" #include "supervisor/board.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
void board_init(void) { void board_init(void) {
common_hal_never_reset_pin(&pin_GPIO16);
gpio_init(16);
gpio_set_dir(16, GPIO_OUT);
gpio_put(16, true);
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -2,6 +2,7 @@
#define MICROPY_HW_MCU_NAME "rp2040" #define MICROPY_HW_MCU_NAME "rp2040"
#define MICROPY_HW_NEOPIXEL (&pin_GPIO17) #define MICROPY_HW_NEOPIXEL (&pin_GPIO17)
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO16)
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO3) #define DEFAULT_I2C_BUS_SCL (&pin_GPIO3)
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO2) #define DEFAULT_I2C_BUS_SDA (&pin_GPIO2)

View File

@ -26,14 +26,7 @@
#include "supervisor/board.h" #include "supervisor/board.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
void board_init(void) { void board_init(void) {
common_hal_never_reset_pin(&pin_GPIO11);
gpio_init(11);
gpio_set_dir(11, GPIO_OUT);
gpio_put(11, true);
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -2,6 +2,7 @@
#define MICROPY_HW_MCU_NAME "rp2040" #define MICROPY_HW_MCU_NAME "rp2040"
#define MICROPY_HW_NEOPIXEL (&pin_GPIO12) #define MICROPY_HW_NEOPIXEL (&pin_GPIO12)
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO11)
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO25) #define DEFAULT_I2C_BUS_SCL (&pin_GPIO25)
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO24) #define DEFAULT_I2C_BUS_SDA (&pin_GPIO24)

View File

@ -31,6 +31,12 @@
#include "supervisor/shared/tick.h" #include "supervisor/shared/tick.h"
#include "py/obj.h" #include "py/obj.h"
#ifdef CIRCUITPY_STATUS_LED_POWER
#include "shared-bindings/digitalio/DigitalInOut.h"
static digitalio_digitalinout_obj_t _status_power;
#endif
#ifdef MICROPY_HW_NEOPIXEL #ifdef MICROPY_HW_NEOPIXEL
uint8_t rgb_status_brightness = 63; uint8_t rgb_status_brightness = 63;
#include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/digitalio/DigitalInOut.h"
@ -116,6 +122,11 @@ void status_led_init() {
} }
status_led_init_in_progress = true; status_led_init_in_progress = true;
#ifdef CIRCUITPY_STATUS_LED_POWER
common_hal_digitalio_digitalinout_construct(&_status_power, CIRCUITPY_STATUS_LED_POWER);
common_hal_digitalio_digitalinout_switch_to_output(&_status_power, true, DRIVE_MODE_PUSH_PULL);
#endif
#ifdef MICROPY_HW_NEOPIXEL #ifdef MICROPY_HW_NEOPIXEL
common_hal_digitalio_digitalinout_construct(&status_neopixel, MICROPY_HW_NEOPIXEL); common_hal_digitalio_digitalinout_construct(&status_neopixel, MICROPY_HW_NEOPIXEL);
common_hal_digitalio_digitalinout_switch_to_output(&status_neopixel, false, DRIVE_MODE_PUSH_PULL); common_hal_digitalio_digitalinout_switch_to_output(&status_neopixel, false, DRIVE_MODE_PUSH_PULL);
@ -212,6 +223,10 @@ void status_led_deinit() {
#elif defined(MICROPY_HW_LED_STATUS) #elif defined(MICROPY_HW_LED_STATUS)
common_hal_digitalio_digitalinout_deinit(&single_color_led); common_hal_digitalio_digitalinout_deinit(&single_color_led);
#endif #endif
#ifdef CIRCUITPY_STATUS_LED_POWER
common_hal_digitalio_digitalinout_deinit(&_status_power);
#endif
} }
void new_status_color(uint32_t rgb) { void new_status_color(uint32_t rgb) {