|
25 | 25 | */
|
26 | 26 |
|
27 | 27 | #include "supervisor/board.h"
|
| 28 | +#include "supervisor/shared/board.h" |
| 29 | +#include "mpconfigboard.h" |
28 | 30 |
|
| 31 | +static void power_on(void) { |
| 32 | + // turn on internal battery |
| 33 | + nrf_gpio_cfg(POWER_SWITCH_PIN->number, |
| 34 | + NRF_GPIO_PIN_DIR_OUTPUT, |
| 35 | + NRF_GPIO_PIN_INPUT_DISCONNECT, |
| 36 | + NRF_GPIO_PIN_NOPULL, |
| 37 | + NRF_GPIO_PIN_S0S1, |
| 38 | + NRF_GPIO_PIN_NOSENSE); |
| 39 | + nrf_gpio_pin_write(POWER_SWITCH_PIN->number, true); |
| 40 | +} |
| 41 | + |
| 42 | +static void preserve_and_release_battery_pin(void) { |
| 43 | + // Preserve the battery state. The battery is enabled by default in factory bootloader. |
| 44 | + // Reset claimed_pins so user can control pin's state in the vm. |
| 45 | + // The code below doesn't actually reset the pin's state, but only set the flags. |
| 46 | + reset_pin_number(POWER_SWITCH_PIN->number); // clear claimed_pins and never_reset_pins |
| 47 | + never_reset_pin_number(POWER_SWITCH_PIN->number); // set never_reset_pins |
| 48 | +} |
| 49 | + |
| 50 | +void board_init(void) { |
| 51 | + // As of cpy 8.1.0, board_init() runs after reset_ports() on first run. That means |
| 52 | + // never_reset_pins won't be set at boot, the battery pin is reset, causing system |
| 53 | + // shutdown. |
| 54 | + // So if we need to run on battery, we must enable the battery here. |
| 55 | + power_on(); |
| 56 | + preserve_and_release_battery_pin(); |
| 57 | +} |
| 58 | + |
| 59 | +void reset_board(void) { |
| 60 | + preserve_and_release_battery_pin(); |
| 61 | +} |
29 | 62 |
|
30 | 63 | // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
|
0 commit comments