Skip to content

Commit bf67ea3

Browse files
authored
Merge pull request #8043 from hyx0329/m60-tweak
Makerdiary M60 keyboard: allow run on battery
2 parents 7d77f34 + d73f390 commit bf67ea3

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

ports/nrf/boards/makerdiary_m60_keyboard/board.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,39 @@
2525
*/
2626

2727
#include "supervisor/board.h"
28+
#include "supervisor/shared/board.h"
29+
#include "mpconfigboard.h"
2830

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+
}
2962

3063
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/nrf/boards/makerdiary_m60_keyboard/mpconfigboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@
4949

5050
#define DEFAULT_I2C_BUS_SCL (&pin_P1_06)
5151
#define DEFAULT_I2C_BUS_SDA (&pin_P1_05)
52+
53+
#define POWER_SWITCH_PIN (&pin_P0_28)

ports/nrf/boards/makerdiary_m60_keyboard/pins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
3939
{ MP_ROM_QSTR(MP_QSTR_CHARGING), MP_ROM_PTR(&pin_P0_03) },
4040
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_P0_02) },
4141
{ MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_P0_02) },
42+
{ MP_ROM_QSTR(MP_QSTR_BATTERY_ENABLE), MP_ROM_PTR(&pin_P0_28) },
4243

4344
{ MP_ROM_QSTR(MP_QSTR_RGB_POWER), MP_ROM_PTR(&pin_P1_04) },
4445

0 commit comments

Comments
 (0)