Skip to content

Commit

Permalink
Merge pull request #305 from hyx0329/pr-m60-fix
Browse files Browse the repository at this point in the history
Fix M60
  • Loading branch information
hathach committed May 26, 2023
2 parents 80c3a84 + e34b183 commit 277a0c8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/boards/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ bool button_pressed(uint32_t pin)
}

// This is declared so that a board specific init can be called from here.
void __attribute__((weak)) board_init_extra(void) { }
void __attribute__((weak)) board_init2(void) { }

void board_init(void)
{
// stop LF clock just in case we jump from application without reset
Expand Down Expand Up @@ -96,7 +97,7 @@ void board_init(void)
NRF_POWER->DCDCEN = 1;
#endif
// Make sure any custom inits are performed
board_init_extra();
board_init2();

// When board is supplied on VDDH (and not VDD), this specifies what voltage the GPIO should run at
// and what voltage is output at VDD. The default (0xffffffff) is 1.8V; typically you'll want
Expand Down Expand Up @@ -129,6 +130,9 @@ void board_init(void)
SysTick_Config(SystemCoreClock/1000);
}

// Actions at the end of board_teardown.
void __attribute__((weak)) board_teardown2(void) { }

void board_teardown(void)
{
// Disable systick, turn off LEDs
Expand Down Expand Up @@ -159,6 +163,9 @@ void board_teardown(void)
{
nrf_gpio_cfg_default(i);
}

// board specific teardown actions
board_teardown2();
}

static uint32_t _systick_count = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/boards/challenger_840_ble/pinconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const uint32_t bootloaderConfig[] =
/* CF2 END */
};

void board_init_extra(void)
void board_init2(void)
{
// Turn LDO on
nrf_gpio_cfg_output(LDO_CONTROL_PIN);
Expand Down
7 changes: 6 additions & 1 deletion src/boards/m60_keyboard/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@
*------------------------------------------------------------------*/
#define BUTTONS_NUMBER 2
#define BUTTON_1 _PINNUM(0, 27)
#define BUTTON_2 _PINNUM(1, 7)
#define BUTTON_2 _PINNUM(0, 19) // ESC
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP

/*------------------------------------------------------------------*/
/* On board regulator control
*------------------------------------------------------------------*/
#define LDO_CONTROL_PIN _PINNUM(0, 28) // Enables external pwr

//--------------------------------------------------------------------+
// BLE OTA
//--------------------------------------------------------------------+
Expand Down
38 changes: 38 additions & 0 deletions src/boards/m60_keyboard/pinconfig.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "boards.h"
#include "board.h"
#include "uf2/configkeys.h"

__attribute__((used, section(".bootloaderConfig")))
Expand All @@ -17,3 +18,40 @@ const uint32_t bootloaderConfig[] =
0, 0, 0, 0, 0, 0, 0, 0
/* CF2 END */
};

static void power_on(void)
{
// Turn on the regulator
nrf_gpio_cfg_output(LDO_CONTROL_PIN);
nrf_gpio_pin_write(LDO_CONTROL_PIN, 1);
}

void board_init2(void)
{
power_on();

// configure P0.05 for ESC/BUTTON_2
// P0.05 --- |<- --- / --- P0.19
// diode sw(esc)
// mode: output, push-pull, low
nrf_gpio_cfg(
_PINNUM(0, 5),
NRF_GPIO_PIN_DIR_OUTPUT,
NRF_GPIO_PIN_INPUT_DISCONNECT,
NRF_GPIO_PIN_NOPULL,
NRF_GPIO_PIN_H0D1,
NRF_GPIO_PIN_NOSENSE
);
nrf_gpio_pin_write(_PINNUM(0, 5), 0);

// Wait the buttons stable.
// This is mandatory, or the keyboard will enter bootloader whenever
// booted by pressing the button at back (same with BUTTON_1)
NRFX_DELAY_MS(300);
}

void board_teardown2(void)
{
// re-enable the battery
power_on();
}

0 comments on commit 277a0c8

Please sign in to comment.