Skip to content

Commit bec912d

Browse files
committed
Safe mode and power-on sequencing
In order to stay on the board must set HOLD(GPIO4) high early during boot. When running off battery the power-on button must be held for 2s to power things on, but if it's held for too long the board powers off. We need to disable the 1s safe mode timer in order to give the user a long enough window to set the pins up so the button can be released and the board stay powered on. Safe mode can be entered by holding BTN_A during boot.
1 parent 3b875b8 commit bec912d

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

ports/espressif/boards/m5stack_stick_c_plus2/board.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,42 @@ static void display_init(void) {
9696
void board_init(void) {
9797
display_init();
9898
}
99+
100+
bool board_requests_safe_mode(void) {
101+
// Enable HOLD early on
102+
config_pin_as_output_with_level(GPIO_NUM_4, true);
103+
104+
// Change the buttons to inputs
105+
gpio_set_direction(GPIO_NUM_35, GPIO_MODE_INPUT);
106+
gpio_set_pull_mode(GPIO_NUM_35, GPIO_FLOATING);
107+
gpio_set_direction(GPIO_NUM_37, GPIO_MODE_INPUT);
108+
gpio_set_pull_mode(GPIO_NUM_37, GPIO_FLOATING);
109+
gpio_set_direction(GPIO_NUM_39, GPIO_MODE_INPUT);
110+
gpio_set_pull_mode(GPIO_NUM_39, GPIO_FLOATING);
111+
112+
// Let the pins settle
113+
mp_hal_delay_ms(1);
114+
115+
// Safe mode if BTN_A is held at boot (logic low)
116+
return gpio_get_level(GPIO_NUM_37) == 0; // BTN_A
117+
}
118+
119+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
120+
switch (pin_number) {
121+
case GPIO_NUM_4: // HOLD
122+
// HOLD(G4) pin must be set high to avoid a power off when battery powered
123+
config_pin_as_output_with_level(pin_number, true);
124+
return true;
125+
126+
case GPIO_NUM_35: // BTN_C/PWR
127+
case GPIO_NUM_37: // BTN_A
128+
case GPIO_NUM_39: // BTN_B
129+
gpio_set_direction(pin_number, GPIO_MODE_INPUT);
130+
gpio_set_pull_mode(pin_number, GPIO_FLOATING);
131+
return true;
132+
133+
default:
134+
return false;
135+
}
136+
return false;
137+
}

ports/espressif/boards/m5stack_stick_c_plus2/mpconfigboard.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ CIRCUITPY_ESP_FLASH_SIZE = 8MB
1010
CIRCUITPY_ESP_PSRAM_MODE = qio
1111
CIRCUITPY_ESP_PSRAM_FREQ = 80m
1212
CIRCUITPY_ESP_PSRAM_SIZE = 2MB
13+
14+
# The safe mode wait gets us very close to the 3s time for the board to shut
15+
# down when BTN_C/PWR is held down. We skip the wait and instead enter safe
16+
# mode if BTN_A is held down during boot with no timeout.
17+
CIRCUITPY_SKIP_SAFE_MODE_WAIT = 1

0 commit comments

Comments
 (0)