summaryrefslogtreecommitdiffstats
path: root/keyboards/annepro2
diff options
context:
space:
mode:
authorbwisn <56162793+bwisn@users.noreply.github.com>2022-03-08 02:12:53 +0100
committerGitHub <noreply@github.com>2022-03-08 12:12:53 +1100
commit893d86cb896d82eb8c9d16251062dd6afa802533 (patch)
treecfadc87d02f22b583542f0e6030ad4c8150e279a /keyboards/annepro2
parent2ff646c642152df064da8dcf62ef328585de0197 (diff)
Add Anne Pro 2 keyboard (#14385)
* [keyboard] Initial support for Anne Pro 2 * [keyboard][AnnePro2] Keymap:update to a reasonable keymap with caps+hjkl => arrow * :( * changed to use HSI * support for annepro2 c18 * keyboard/annepro2: Very stupid matrix scan bug fix. * typo * swap COL14/13 * keyboard/annepro2: startup secondary LED MCU * keyboard/annepro2: typo fix * Add IO Values * Disable Combo feature * Update default keymap to Anne Pro 2 Official Keymap * keyboard/annepro2: keymap layer name changes * keyboard/annepro2 BLE Support * Fix keymap comment FN1 ESC was listed as ~ instead of ` * keyboard/annepro2: Bluetooth path * Keyboard annepro2 bidir led comms (#5) * Added bidirectional shine comms and moved led functionality to new file * Added bidirectional shine comms and moved led functionality to new file * Restore original functionality to existing keymaps using new shine commands * Fix dangling bracketless if statements * PR cleanup * add custom keycodes to switch led profiles * Optimize code * switch to prev profile before turning leds off * Add persistent led support with eeprom (#9) * adding HT32 support to chibios SPI master driver * add support for W25X20CL SPI eeprom * add makefile flag for eeprom feature * add spi support to keyboard startup and config * example keymap using eeprom profile loading * Cleanup to fix C15 eeprom/spi build errors (#11) * Cleanup to fix C15 eeprom/spi build errors * add newline at eof * LED Masking support for Shine Introduce companion update to ledSetMask and ledClearMask. In keymap `codetector` there is example of how to map caps_lock to the caps_lock key light on the keyboard. * [AnnePro2]: update bluetooth connection * Merge the custom keys enums on annepro2.h (#13) * Keyboard annepro2 ble caps lock (#12) * Move matrix_scan_kb out of board.c to annepro2.c * add buffer clear after init and caplock polling * Add support for LED intensity (#15) * Improve logic for switching off and on of LEDs (#16) * Implement animation speed (#17) * Include logic to send solid colors as foreground to shine and add sample profiles (#14) Include the logic to send a solid color from qmk to shine. That solid color will act as a foreground (will override the current profile) until reset (witch will reactivate the current profile). This functionality depends on changes made for shine as well. Include 3 new profiles: default-full-caps -> same as default, but with the logic of using the red foreground color on caps lock. default-layer-indicators -> same as default, but with the logic of red foreground on caps lock, green foreground on FN1 and blue foreground on FN2. thomazmoura -> my own profile as a sample of an over-engineered advanced case scenario. * Implement reactive lighting effects (#18) * Added multiarrow keymap (#19) * Add LED documentation (#26) * add LED documentation * add LED documentation to other default profiles * 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 * Make default config more like Obins stock default (#30) * Add new message type for resetting foreground color (#31) * annepro2(bluetooth): add media keys support (#41) * Asynchronous, robust serial protocol. (#39) * bla personal ap2-c18 keymap. * Bidirectional, asynchronous message-based communication with Shine. - Requires a matching Shine version. - Protocol is resiliant to loosing bytes during communication, chips won't lock waiting for bytes that aren't coming. - Chips resynchronize in event of loosing a byte using a AA0D header. Regressions: - Key masking/locking doesn't work right now. (did it work before?) - Not all user keymaps build against it. * Clang-format + code to ease reducing speed of LED UART. - Did clang-format --style=file -i on multiple files according to coding_conventions_c.md - Added separate serial speed for IAP boot and Led communication, it's possible that reducing this to 9600 helped someone with faulty HW. With this code they can do it with simple replacing of a value. * Main chip can set/clear foreground using a mask mechanism. - Some preparations for selective colouring. * Selective mask works - tested on capslock. - Migrated personal keymaps to new status API. * Clear the foreground colors to show profile when it's modified. - Show example of achieving selective caps-lock painting + foreground painting for layers. - annepro2LedMaskSetRow is implemented, but still requires testing. * Implement the QMK side of led blinking to indicate the command was received. - This stupidly blinks the key when user presses one of the bluetooth commands to let the user know that the command was received and forwarded to the BT chip. - TODO: Row/col key positions are hardcoded and not taken from the keymap. * Reduce memory footprint. Applying code review suggestions. Moved msgId to globals - preparing for transmission without copying payload when no retries are necessary. Added empty readme.md files - required by QMK lint. Co-authored-by: Tomasz bla Fortuna <bla@thera.be> * Let the LED chip settle a bit before waking it from the bootloader. (#42) At least for one person that helps to reliably get the LEDs working without disconnecting/reconnecting the power to the board multiple times. Co-authored-by: Tomasz bla Fortuna <bla@thera.be> * annepro2: rename KEYMAP to LAYOUT, as required by new version of QMK * annepro2: update ChibiOS configuration files * annepro2: fix undefined reference to dprint and timer_read32 * annepro2: update ChibiOS MCU name * update spi driver, fix bad merging with master * annepro2: add readme and info.json * annepro2: make code compatible with QMK coding conventions * tmk_core: temporary fix to allow HT32 based keyboards to work without patched ChibiOS-contrib (AnnePro2) * AnnePro2: removed core changes * AnnePro2: Leave only default keymaps Missing keymaps will be restored in another PR * annepro2: add licence information * annepro2: satisfy qmk lint * annepro2: fix drashna's suggestions * annepro2: fix matrix * annepro2: apply code review suggestions * annepro2: apply remaining code review suggestions * annepro2: update info.json * annepro2: remove include * annepro2: rename keymap to layout * annepro2: fix typing * annepro2: apply suggestions from tzarc's code review Co-authored-by: Nick Brassel <nick@tzarc.org> * annepro2: more fixes * annepro2: apply suggestions from code review Co-authored-by: Joel Challis <git@zvecr.com> * annepro2: rename file * more fixes * Apply suggestions from @tzarc code review Co-authored-by: Nick Brassel <nick@tzarc.org> * Update keyboards/annepro2/protocol.h Co-authored-by: Nick Brassel <nick@tzarc.org> * Update keyboards/annepro2/chconf.h Co-authored-by: Nick Brassel <nick@tzarc.org> * apply CR suggestions * upgrade readme * IAP * update IAP comments, defines * led fix * init fix * annepro2: GPIO cleanup * annepro2: ioline * change waiting time * Start develop for 2022q2 * [Core] Squeeze AVR some more with `-mrelax` and `-mcall-prologues` (#16269) * Rework generate-api CLI command to use .build directory (#16441) * Remove `send_unicode_hex_string()` (#16518) * Change data driven "str" type to represent a quoted string literal (#16516) * Change data driven "str" type to represent a quoted string literal * Update docs * Map data driven `DESCRIPTION` as string literal (#16523) * update bootloader * Revert "Merge pull request #2 from qmk/develop" This reverts commit 9c76065188c3adda98bdaa1f28dad85600e73ee9, reversing changes made to 240745dc05783c612e92bab153da5c46e037d675. * Revert "update bootloader" This reverts commit 240745dc05783c612e92bab153da5c46e037d675. * fix rules.mk * change PROGRAM_CMD Co-authored-by: codetector <codetector@codetector.cn> Co-authored-by: Fagl4 <18francisco18@gmail.com> Co-authored-by: Jakob Gillich <jakob@gillich.me> Co-authored-by: tech2077 <tech2077@gmail.com> Co-authored-by: jcdeA <31413538+JcdeA@users.noreply.github.com> Co-authored-by: Thomaz Moura <5599621+thomazmoura@users.noreply.github.com> Co-authored-by: Darkhan <darkhanu@gmail.com> Co-authored-by: Paco <70448173+packorf@users.noreply.github.com> Co-authored-by: jmarmstrong1207 <32995055+jmarmstrong1207@users.noreply.github.com> Co-authored-by: 1Conan <7620342+1Conan@users.noreply.github.com> Co-authored-by: Tomasz bla Fortuna <blagh@thera.be> Co-authored-by: Tomasz bla Fortuna <bla@thera.be> Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: Joel Challis <git@zvecr.com> Co-authored-by: QMK Bot <hello@qmk.fm> Co-authored-by: Stefan Kerkmann <karlk90@pm.me> Co-authored-by: Ryan <fauxpark@gmail.com>
Diffstat (limited to 'keyboards/annepro2')
-rw-r--r--keyboards/annepro2/annepro2.c202
-rw-r--r--keyboards/annepro2/annepro2.h65
-rw-r--r--keyboards/annepro2/annepro2_ble.c170
-rw-r--r--keyboards/annepro2/annepro2_ble.h27
-rw-r--r--keyboards/annepro2/ap2_led.c134
-rw-r--r--keyboards/annepro2/ap2_led.h84
-rw-r--r--keyboards/annepro2/boards/ANNEPRO2_C15/board.c103
-rw-r--r--keyboards/annepro2/boards/ANNEPRO2_C15/board.h39
-rw-r--r--keyboards/annepro2/boards/ANNEPRO2_C15/board.mk5
-rw-r--r--keyboards/annepro2/boards/ANNEPRO2_C18/board.c103
-rw-r--r--keyboards/annepro2/boards/ANNEPRO2_C18/board.h39
-rw-r--r--keyboards/annepro2/boards/ANNEPRO2_C18/board.mk5
-rw-r--r--keyboards/annepro2/c15/config.h47
-rw-r--r--keyboards/annepro2/c15/readme.md1
-rw-r--r--keyboards/annepro2/c15/rules.mk37
-rw-r--r--keyboards/annepro2/c18/config.h45
-rw-r--r--keyboards/annepro2/c18/readme.md1
-rw-r--r--keyboards/annepro2/c18/rules.mk37
-rw-r--r--keyboards/annepro2/chconf.h31
-rw-r--r--keyboards/annepro2/halconf.h28
-rw-r--r--keyboards/annepro2/info.json330
-rw-r--r--keyboards/annepro2/keymaps/default-full-caps/config.h20
-rw-r--r--keyboards/annepro2/keymaps/default-full-caps/keymap.c120
-rw-r--r--keyboards/annepro2/keymaps/default-layer-indicators/config.h20
-rw-r--r--keyboards/annepro2/keymaps/default-layer-indicators/keymap.c147
-rw-r--r--keyboards/annepro2/keymaps/default/config.h20
-rw-r--r--keyboards/annepro2/keymaps/default/keymap.c106
-rw-r--r--keyboards/annepro2/ld/HT32F52342_ANNEPRO2.ld91
-rw-r--r--keyboards/annepro2/matrix.c63
-rw-r--r--keyboards/annepro2/mcuconf.h62
-rw-r--r--keyboards/annepro2/protocol.c116
-rw-r--r--keyboards/annepro2/protocol.h111
-rw-r--r--keyboards/annepro2/readme.md50
33 files changed, 2459 insertions, 0 deletions
diff --git a/keyboards/annepro2/annepro2.c b/keyboards/annepro2/annepro2.c
new file mode 100644
index 0000000000..37489defff
--- /dev/null
+++ b/keyboards/annepro2/annepro2.c
@@ -0,0 +1,202 @@
+/* Copyright 2021 OpenAnnePro community
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "hal.h"
+#include "annepro2.h"
+#include "annepro2_ble.h"
+#include "spi_master.h"
+#include "ap2_led.h"
+#include "protocol.h"
+
+#define RAM_MAGIC_LOCATION 0x20001ffc
+#define IAP_MAGIC_VALUE 0x0000fab2
+
+static const SerialConfig ledUartInitConfig = {
+ .speed = 115200,
+};
+
+#ifndef LED_UART_BAUD_RATE
+# define LED_UART_BAUD_RATE 115200
+#endif // LED_UART_BAUD_RATE
+
+static const SerialConfig ledUartRuntimeConfig = {
+ .speed = LED_UART_BAUD_RATE,
+};
+
+static const SerialConfig bleUartConfig = {
+ .speed = 115200,
+};
+
+static uint8_t ledMcuWakeup[11] = {0x7b, 0x10, 0x43, 0x10, 0x03, 0x00, 0x00, 0x7d, 0x02, 0x01, 0x02};
+
+ble_capslock_t BLECapsLock = {._dummy = {0}, .caps_lock = false};
+
+void bootloader_jump(void) {
+ // Send msg to shine to boot into IAP
+ annepro2SetIAP();
+
+ // 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
+ // It’s from reversing original boot loader
+ // If value is that it stays in boot loader aka IAP
+ *((uint32_t *)RAM_MAGIC_LOCATION) = IAP_MAGIC_VALUE;
+
+ // Load the main MCU into IAP
+ __disable_irq();
+ NVIC_SystemReset();
+}
+
+void keyboard_pre_init_kb(void) {
+ // Start LED UART
+ sdStart(&SD0, &ledUartInitConfig);
+ /* Let the LED chip settle a bit before switching the mode.
+ * That helped at least one person. */
+ wait_ms(15);
+ sdWrite(&SD0, ledMcuWakeup, sizeof(ledMcuWakeup));
+
+ // wait to receive response from wakeup
+ wait_ms(15);
+
+ protoInit(&proto, ledCommandCallback);
+
+ // loop to clear out receive buffer from shine wakeup
+ while (!sdGetWouldBlock(&SD0)) sdGet(&SD0);
+
+ sdStart(&SD0, &ledUartRuntimeConfig);
+ keyboard_pre_init_user();
+}
+
+void keyboard_post_init_kb(void) {
+ // Start BLE UART
+ sdStart(&SD1, &bleUartConfig);
+ annepro2_ble_startup();
+
+ // Give the send uart thread some time to
+ // send out the queue before we read back
+ wait_ms(100);
+
+ // loop to clear out receive buffer from ble wakeup
+ while (!sdGetWouldBlock(&SD1)) sdGet(&SD1);
+
+ annepro2LedGetStatus();
+
+ keyboard_post_init_user();
+}
+
+void matrix_scan_kb() {
+ // if there's stuff on the ble serial buffer
+ // read it into the capslock struct
+ while (!sdGetWouldBlock(&SD1)) {
+ sdReadTimeout(&SD1, (uint8_t *)&BLECapsLock, sizeof(ble_capslock_t), 10);
+ }
+
+ /* While there's data from LED keyboard sent - read it. */
+ while (!sdGetWouldBlock(&SD0)) {
+ uint8_t byte = sdGet(&SD0);
+ protoConsume(&proto, byte);
+ }
+
+ matrix_scan_user();
+}
+
+bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
+ if (record->event.pressed) {
+ if (annepro2LedStatus.matrixEnabled && annepro2LedStatus.isReactive) {
+ annepro2LedForwardKeypress(record->event.key.row, record->event.key.col);
+ }
+
+ const annepro2Led_t blue = {
+ .p.blue = 0xff,
+ .p.red = 0x00,
+ .p.green = 0x00,
+ .p.alpha = 0xff,
+ };
+
+ switch (keycode) {
+ case KC_AP2_BT1:
+ annepro2_ble_broadcast(0);
+ /* FIXME: This hardcodes col/row position */
+ annepro2LedBlink(0, 1, blue, 8, 50);
+ return false;
+
+ case KC_AP2_BT2:
+ annepro2_ble_broadcast(1);
+ annepro2LedBlink(0, 2, blue, 8, 50);
+ return false;
+
+ case KC_AP2_BT3:
+ annepro2_ble_broadcast(2);
+ annepro2LedBlink(0, 3, blue, 8, 50);
+ return false;
+
+ case KC_AP2_BT4:
+ annepro2_ble_broadcast(3);
+ annepro2LedBlink(0, 4, blue, 8, 50);
+ return false;
+
+ case KC_AP2_USB:
+ annepro2_ble_disconnect();
+ return false;
+
+ case KC_AP2_BT_UNPAIR:
+ annepro2_ble_unpair();
+ return false;
+
+ case KC_AP_LED_OFF:
+ annepro2LedDisable();
+ break;
+
+ case KC_AP_LED_ON:
+ if (annepro2LedStatus.matrixEnabled) {
+ annepro2LedNextProfile();
+ } else {
+ annepro2LedEnable();
+ }
+ annepro2LedResetForegroundColor();
+ break;
+
+ case KC_AP_LED_NEXT_PROFILE:
+ annepro2LedNextProfile();
+ annepro2LedResetForegroundColor();
+ break;
+
+ case KC_AP_LED_PREV_PROFILE:
+ annepro2LedPrevProfile();
+ annepro2LedResetForegroundColor();
+ break;
+
+ case KC_AP_LED_NEXT_INTENSITY:
+ annepro2LedNextIntensity();
+ annepro2LedResetForegroundColor();
+ return false;
+
+ case KC_AP_LED_SPEED:
+ annepro2LedNextAnimationSpeed();
+ annepro2LedResetForegroundColor();
+ return false;
+
+ default:
+ break;
+ }
+ }
+ return process_record_user(keycode, record);
+}
diff --git a/keyboards/annepro2/annepro2.h b/keyboards/annepro2/annepro2.h
new file mode 100644
index 0000000000..b08f8c5352
--- /dev/null
+++ b/keyboards/annepro2/annepro2.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2018 Yaotian Feng
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+#include "quantum.h"
+#include <stdint.h>
+#include "ap2_led.h"
+
+typedef struct __attribute__((__packed__)) {
+ uint8_t _dummy[10];
+ bool caps_lock;
+} ble_capslock_t;
+extern ble_capslock_t BLECapsLock;
+
+// Matrix keymap
+// clang-format off
+#define LAYOUT( \
+ K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
+ K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
+ K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, \
+ K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, \
+ K40, K42, K43, K46, K49, K4A, K4B, K4C \
+) { \
+ /* COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9 COL10 COL11 COL12 COL13 COL14*/ \
+ /* ROW1 */ { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D }, \
+ /* ROW2 */ { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D }, \
+ /* ROW3 */ { K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, KC_NO}, \
+ /* ROW4 */ { K30, KC_NO, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, KC_NO}, \
+ /* ROW5 */ { K40, KC_NO, K42, K43, KC_NO, KC_NO, K46, KC_NO, KC_NO, K49, K4A, K4B, K4C, KC_NO}, \
+}
+// clang-format on
+
+enum AP2KeyCodes {
+ KC_AP2_BT1 = SAFE_RANGE,
+ KC_AP2_BT2,
+ KC_AP2_BT3,
+ KC_AP2_BT4,
+ KC_AP2_BT_UNPAIR,
+ KC_AP2_USB,
+ KC_AP_LED_ON,
+ KC_AP_LED_OFF,
+ KC_AP_LED_NEXT_PROFILE,
+ KC_AP_LED_PREV_PROFILE,
+ KC_AP_LED_NEXT_INTENSITY,
+ KC_AP_LED_SPEED,
+ AP2_SAFE_RANGE,
+};
+
+#undef SAFE_RANGE
+#define SAFE_RANGE AP2_SAFE_RANGE
+
diff --git a/keyboards/annepro2/annepro2_ble.c b/keyboards/annepro2/annepro2_ble.c
new file mode 100644
index 0000000000..72cbb68016
--- /dev/null
+++ b/keyboards/annepro2/annepro2_ble.c
@@ -0,0 +1,170 @@
+/*
+ Copyright (C) 2020 Yaotian Feng, Codetector<codetector@codetector.cn>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "annepro2_ble.h"
+#include "ch.h"
+#include "hal.h"
+#include "host.h"
+#include "host_driver.h"
+#include "report.h"
+
+/* -------------------- Static Function Prototypes -------------------------- */
+static uint8_t ap2_ble_leds(void);
+static void ap2_ble_mouse(report_mouse_t *report);
+static void ap2_ble_system(uint16_t data);
+static void ap2_ble_consumer(uint16_t data);
+static void ap2_ble_keyboard(report_keyboard_t *report);
+
+static void ap2_ble_swtich_ble_driver(void);
+
+/* -------------------- Static Local Variables ------------------------------ */
+static host_driver_t ap2_ble_driver = {
+ ap2_ble_leds, ap2_ble_keyboard, ap2_ble_mouse, ap2_ble_system, ap2_ble_consumer,
+};
+
+static uint8_t bleMcuWakeup[11] = {0x7b, 0x12, 0x53, 0x00, 0x03, 0x00, 0x01, 0x7d, 0x02, 0x01, 0x02};
+
+static uint8_t bleMcuStartBroadcast[11] = {
+ 0x7b, 0x12, 0x53, 0x00, 0x03, 0x00, 0x00, 0x7d, 0x40, 0x01, 0x00 // Broadcast ID[0-3]
+};
+
+static uint8_t bleMcuConnect[11] = {
+ 0x7b, 0x12, 0x53, 0x00, 0x03, 0x00, 0x00, 0x7d, 0x40, 0x04, 0x00 // Connect ID [0-3]
+};
+
+static uint8_t bleMcuSendReport[10] = {
+ 0x7b, 0x12, 0x53, 0x00, 0x0A, 0x00, 0x00, 0x7d, 0x10, 0x04,
+};
+
+static uint8_t bleMcuSendConsumerReport[10] = {
+ 0x7b, 0x12, 0x53, 0x00, 0x06, 0x00, 0x00, 0x7d, 0x10, 0x08,
+};
+
+static uint8_t bleMcuUnpair[10] = {
+ 0x7b, 0x12, 0x53, 0x00, 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;
+#endif // NKRO_ENABLE
+
+/* -------------------- Public Function Implementation ---------------------- */
+
+void annepro2_ble_bootload(void) { sdWrite(&SD1, bleMcuBootload, sizeof(bleMcuBootload)); }
+
+void annepro2_ble_startup(void) { sdWrite(&SD1, bleMcuWakeup, sizeof(bleMcuWakeup)); }
+
+void annepro2_ble_broadcast(uint8_t port) {
+ if (port > 3) {
+ port = 3;
+ }
+ // sdPut(&SD1, 0x00);
+ sdWrite(&SD1, bleMcuStartBroadcast, sizeof(bleMcuStartBroadcast));
+ sdPut(&SD1, port);
+ static int lastBroadcast = -1;
+ if (lastBroadcast == port) {
+ annepro2_ble_connect(port);
+ }
+ lastBroadcast = port;
+}
+
+void annepro2_ble_connect(uint8_t port) {
+ if (port > 3) {
+ port = 3;
+ }
+ sdWrite(&SD1, bleMcuConnect, sizeof(bleMcuConnect));
+ sdPut(&SD1, port);
+ ap2_ble_swtich_ble_driver();
+}
+
+void annepro2_ble_disconnect(void) {
+ /* Skip if the driver is already enabled */
+ if (host_get_driver() != &ap2_ble_driver) {
+ return;
+ }
+
+ clear_keyboard();
+#ifdef NKRO_ENABLE
+ keymap_config.nkro = lastNkroStatus;
+#endif
+ host_set_driver(lastHostDriver);
+}
+
+void annepro2_ble_unpair(void) {
+ // sdPut(&SD1, 0x0);
+ sdWrite(&SD1, bleMcuUnpair, sizeof(bleMcuUnpair));
+}
+
+/* ------------------- Static Function Implementation ----------------------- */
+static void ap2_ble_swtich_ble_driver(void) {
+ if (host_get_driver() == &ap2_ble_driver) {
+ return;
+ }
+ clear_keyboard();
+ lastHostDriver = host_get_driver();
+#ifdef NKRO_ENABLE
+ lastNkroStatus = keymap_config.nkro;
+#endif
+ keymap_config.nkro = false;
+ host_set_driver(&ap2_ble_driver);
+}
+
+static uint8_t ap2_ble_leds(void) {
+ return 0; // TODO: Figure out how to obtain LED status
+}
+
+static void ap2_ble_mouse(report_mouse_t *report) {}
+
+static void ap2_ble_system(uint16_t data) {}
+
+static inline uint16_t CONSUMER2AP2(uint16_t usage) {
+ switch (usage) {
+ case AUDIO_VOL_DOWN:
+ return 0x04;
+ case AUDIO_VOL_UP:
+ return 0x02;
+ case AUDIO_MUTE:
+ return 0x01;
+ case TRANSPORT_PLAY_PAUSE:
+ return 0x08;
+ case TRANSPORT_NEXT_TRACK:
+ return 0x10;
+ case TRANSPORT_PREV_TRACK:
+ return 0x20;
+ default:
+ return 0x00;
+ }
+}
+
+static void ap2_ble_consumer(uint16_t data) {
+ sdPut(&SD1, 0x0);
+ sdWrite(&SD1, bleMcuSendConsumerReport, sizeof(bleMcuSendConsumerReport));
+ sdPut(&SD1, CONSUMER2AP2(data));
+ static const uint8_t dummy[3] = {0};
+ sdWrite(&SD1, dummy, sizeof(dummy));
+}
+
+/*!
+ * @brief Send keyboard HID report for Bluetooth driver
+ */
+static void ap2_ble_keyboard(report_keyboard_t *report) {
+ sdPut(&SD1, 0x0);
+ sdWrite(&SD1, bleMcuSendReport, sizeof(bleMcuSendReport));
+ sdWrite(&SD1, &report->raw[0], KEYBOARD_REPORT_SIZE);
+}
diff --git a/keyboards/annepro2/annepro2_ble.h b/keyboards/annepro2/annepro2_ble.h
new file mode 100644
index 0000000000..0cfb68e071
--- /dev/null
+++ b/keyboards/annepro2/annepro2_ble.h
@@ -0,0 +1,27 @@
+/*
+ Copyright (C) 2020 Yaotian Feng, Codetector<codetector@codetector.cn>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#pragma once
+
+#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);
+void annepro2_ble_disconnect(void);
+void annepro2_ble_unpair(void);
diff --git a/keyboards/annepro2/ap2_led.c b/keyboards/annepro2/ap2_led.c
new file mode 100644
index 0000000000..9969fcd02a
--- /dev/null
+++ b/keyboards/annepro2/ap2_led.c
@@ -0,0 +1,134 @@
+/* Copyright 2021 OpenAnnePro community
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include "hal.h"
+#include "annepro2.h"
+#include "ap2_led.h"
+#include "protocol.h"
+
+annepro2Led_t ledMask[KEY_COUNT];
+annepro2LedStatus_t annepro2LedStatus;
+
+void ledCommandCallback(const message_t *msg) {
+ switch (msg->command) {
+ case CMD_LED_STATUS:
+ annepro2LedStatus.amountOfProfiles = msg->payload[0];
+ annepro2LedStatus.currentProfile = msg->payload[1];
+ annepro2LedStatus.matrixEnabled = msg->payload[2];
+ annepro2LedStatus.isReactive = msg->payload[3];
+ annepro2LedStatus.ledIntensity = msg->payload[4];
+ annepro2LedStatus.errors = msg->payload[5];
+ break;
+
+#ifdef CONSOLE_ENABLE
+ case CMD_LED_DEBUG:
+ /* TODO: Don't use printf. */
+ printf("LED:");
+ for (int i = 0; i < msg->payloadSize; i++) {
+ printf("%02x ", msg->payload[i]);
+ }
+ for (int i = 0; i < msg->payloadSize; i++) {
+ printf("%c", msg->payload[i]);
+ }
+ printf("\n");
+ break;
+#endif
+ }
+}
+
+void annepro2SetIAP(void) { protoTx(CMD_LED_IAP, NULL, 0, 3); }
+
+void annepro2LedDisable(void) { protoTx(CMD_LED_OFF, NULL, 0, 3); }
+
+void annepro2LedEnable(void) { protoTx(CMD_LED_ON, NULL, 0, 3); }
+
+void annepro2LedSetProfile(uint8_t prof) { protoTx(CMD_LED_SET_PROFILE, &prof, sizeof(prof), 3); }
+
+void annepro2LedGetStatus() { protoTx(CMD_LED_GET_STATUS, NULL, 0, 3); }
+
+void annepro2LedNextProfile() { protoTx(CMD_LED_NEXT_PROFILE, NULL, 0, 3); }
+
+void annepro2LedNextIntensity() { protoTx(CMD_LED_NEXT_INTENSITY, NULL, 0, 3); }
+
+void annepro2LedNextAnimationSpeed() { protoTx(CMD_LED_NEXT_ANIMATION_SPEED, NULL, 0, 3); }
+
+void annepro2LedPrevProfile() { protoTx(CMD_LED_PREV_PROFILE, NULL, 0, 3); }
+
+void annepro2LedMaskSetKey(uint8_t row, uint8_t col, annepro2Led_t color) {
+ uint8_t payload[] = {row, col, color.p.blue, color.p.green, color.p.red, color.p.alpha};
+ protoTx(CMD_LED_MASK_SET_KEY, payload, sizeof(payload), 1);
+}
+
+/* Push a whole local row to the shine */
+void annepro2LedMaskSetRow(uint8_t row) {
+ uint8_t payload[NUM_COLUMN * sizeof(annepro2Led_t) + 1];
+ payload[0] = row;
+ memcpy(payload + 1, &ledMask[ROWCOL2IDX(row, 0)], sizeof(*ledMask) * NUM_COLUMN);
+ protoTx(CMD_LED_MASK_SET_ROW, payload, sizeof(payload), 1);
+}
+
+/* Synchronize all rows */
+void annepro2LedMaskSetAll(void) {
+ for (int row = 0; row < 5; row++) annepro2LedMaskSetRow(row);
+}
+
+/* Set all keys to a given color */
+void annepro2LedMaskSetMono(const annepro2Led_t color) { protoTx(CMD_LED_MASK_SET_MONO, (uint8_t *)&color, sizeof(color), 1); }
+
+void annepro2LedBlink(uint8_t row, uint8_t col, annepro2Led_t color, uint8_t count, uint8_t hundredths) {
+ uint8_t payload[] = {row, col, color.p.blue, color.p.green, color.p.red, color.p.alpha, count, hundredths};
+ protoTx(CMD_LED_KEY_BLINK, payload, sizeof(payload), 1);
+}
+
+void annepro2LedSetForegroundColor(uint8_t red, uint8_t green, uint8_t blue) {
+ annepro2Led_t color = {.p.red = red, .p.green = green, .p.blue = blue, .p.alpha = 0xff};
+ annepro2LedMaskSetMono(color);
+}
+
+void annepro2LedResetForegroundColor() {
+ annepro2Led_t color = {
+ .p.red = 0,
+ .p.green = 0,
+ .p.blue = 0,
+ .p.alpha = 0,
+ };
+ annepro2LedMaskSetMono(color);
+}
+
+/*
+ * Currently keypresses are unified with other messages, still with single 1
+ * byte payload. Transfer is normally fast enough for that to not be a problem -
+ * especially with asynchronous message reading.
+ *
+ *
+ * Previous description:
+ * If enabled, this data is sent to LED MCU on every keypress.
+ * In order to improve performance, both row and column values
+ * are packed into a single byte.
+ * Row range is [0, 4] and requires only 3 bits.
+ * Column range is [0, 13] and requires 4 bits.
+ *
+ * In order to differentiate this command from regular commands,
+ * the leftmost bit is set to 1 (0b10000000).
+ * Following it are 3 bits of row and 4 bits of col.
+ * 1 + 3 + 4 = 8 bits - only a single byte is sent for every keypress.
+ */
+void annepro2LedForwardKeypress(uint8_t row, uint8_t col) {
+ const uint8_t payload = row << 4 | col;
+ protoTx(CMD_LED_KEY_DOWN, &payload, 1, 1);
+}
diff --git a/keyboards/annepro2/ap2_led.h b/keyboards/annepro2/ap2_led.h
new file mode 100644
index 0000000000..23712a2555
--- /dev/null
+++ b/keyboards/annepro2/ap2_led.h
@@ -0,0 +1,84 @@
+ /* Copyright 2021 OpenAnnePro community
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This