From 5233d3aab1822c15463033696bb2a365e4de23dc Mon Sep 17 00:00:00 2001 From: jmarmstrong1207 <32995055+jmarmstrong1207@users.noreply.github.com> Date: Sat, 30 Jan 2021 22:09:18 -0800 Subject: [PATCH] Implement QMK's IAP default keybind (#29) * Add keymap for going into IAP * switch to default QMK keybind for IAP mode * implement bluetooth IAP mode --- keyboards/annepro2/annepro2.c | 21 +++++++++++++++++++++ keyboards/annepro2/annepro2_ble.c | 8 ++++++++ keyboards/annepro2/annepro2_ble.h | 1 + keyboards/annepro2/c18/rules.mk | 2 +- keyboards/annepro2/qmk_ap2_led.h | 2 ++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/keyboards/annepro2/annepro2.c b/keyboards/annepro2/annepro2.c index f978039459c3..5c2ebfc934fa 100644 --- a/keyboards/annepro2/annepro2.c +++ b/keyboards/annepro2/annepro2.c @@ -29,6 +29,26 @@ uint16_t annepro2LedMatrix[MATRIX_ROWS * MATRIX_COLS] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0, }; +void OVERRIDE bootloader_jump(void) { + + // Send msg to shine to boot into IAP + sdPut(&SD0, CMD_LED_IAP); + + // wait for shine to boot into IAP + wait_ms(15); + + // Load ble into IAP + annepro2_ble_bootload(); + wait_ms(15); + + // Magic key to set keyboard to IAP + *((uint32_t*)0x20001ffc) = 0x0000fab2; + + // Load the main MCU into IAP + __disable_irq(); + NVIC_SystemReset(); +} + void OVERRIDE keyboard_pre_init_kb(void) { #if HAL_USE_SPI == TRUE spi_init(); @@ -146,6 +166,7 @@ bool OVERRIDE process_record_kb(uint16_t keycode, keyrecord_t *record) { case KC_AP_LED_SPEED: annepro2LedNextAnimationSpeed(); return false; + default: break; } diff --git a/keyboards/annepro2/annepro2_ble.c b/keyboards/annepro2/annepro2_ble.c index 5fce1716aa72..43290fdc8cfb 100644 --- a/keyboards/annepro2/annepro2_ble.c +++ b/keyboards/annepro2/annepro2_ble.c @@ -54,6 +54,10 @@ static uint8_t bleMcuUnpair[10] = { 0x7b, 0x10, 0x53, 0x10, 0x02, 0x00, 0x00, 0x7d, 0x40, 0x05, }; +static uint8_t bleMcuBootload[11] = { + 0x7b, 0x10, 0x51, 0x10, 0x03, 0x00, 0x00, 0x7d, 0x02, 0x01, 0x01 +}; + static host_driver_t *lastHostDriver = NULL; #ifdef NKRO_ENABLE static bool lastNkroStatus = false; @@ -61,6 +65,10 @@ static bool lastNkroStatus = false; /* -------------------- Public Function Implementation ---------------------- */ +void annepro2_ble_bootload(void) { + sdWrite(&SD1, bleMcuBootload, 11); +} + void annepro2_ble_startup(void) { sdWrite(&SD1, bleMcuWakeup, 11); } diff --git a/keyboards/annepro2/annepro2_ble.h b/keyboards/annepro2/annepro2_ble.h index 71498890fdee..0cfb68e07163 100644 --- a/keyboards/annepro2/annepro2_ble.h +++ b/keyboards/annepro2/annepro2_ble.h @@ -19,6 +19,7 @@ #include "annepro2.h" #include "quantum.h" +void annepro2_ble_bootload(void); void annepro2_ble_startup(void); void annepro2_ble_broadcast(uint8_t port); void annepro2_ble_connect(uint8_t port); diff --git a/keyboards/annepro2/c18/rules.mk b/keyboards/annepro2/c18/rules.mk index 11efab064870..1bf42df7d4e3 100644 --- a/keyboards/annepro2/c18/rules.mk +++ b/keyboards/annepro2/c18/rules.mk @@ -36,7 +36,7 @@ EXTRAKEY_ENABLE = yes KEY_LOCK_ENABLE = no # Other featues -BOOTMAGIC_ENABLE = no +BOOTMAGIC_ENABLE = yes CONSOLE_ENABLE = no COMMAND_ENABLE = yes RAW_ENABLE = yes diff --git a/keyboards/annepro2/qmk_ap2_led.h b/keyboards/annepro2/qmk_ap2_led.h index 664944c0d47d..cbb08ffa7d91 100644 --- a/keyboards/annepro2/qmk_ap2_led.h +++ b/keyboards/annepro2/qmk_ap2_led.h @@ -15,7 +15,9 @@ #define CMD_LED_NEXT_ANIMATION_SPEED 0xD #define CMD_LED_SET_FOREGROUND_COLOR 0xE #define CMD_LED_KEYPRESS 0xF +#define CMD_LED_IAP 0x10 +void annepro2SetIAP(void); void annepro2LedDisable(void); void annepro2LedEnable(void); void annepro2LedUpdate(uint8_t row, uint8_t col);