diff --git a/keyboards/annepro2/annepro2.c b/keyboards/annepro2/annepro2.c index cdabe35fb45..f978039459c 100644 --- a/keyboards/annepro2/annepro2.c +++ b/keyboards/annepro2/annepro2.c @@ -89,6 +89,10 @@ void matrix_scan_kb() { */ bool OVERRIDE process_record_kb(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { + if (AP2_LED_ENABLED && AP2_LED_DYNAMIC_PROFILE) { + annepro2LedForwardKeypress(record->event.key.row, record->event.key.col); + } + switch (keycode) { case KC_AP2_BT1: annepro2_ble_broadcast(0); diff --git a/keyboards/annepro2/qmk_ap2_led.c b/keyboards/annepro2/qmk_ap2_led.c index d92c1392848..08a59adf6e8 100644 --- a/keyboards/annepro2/qmk_ap2_led.c +++ b/keyboards/annepro2/qmk_ap2_led.c @@ -2,14 +2,19 @@ #include "annepro2.h" #include "qmk_ap2_led.h" +bool AP2_LED_ENABLED = false; +bool AP2_LED_DYNAMIC_PROFILE = false; + void annepro2LedDisable(void) { sdPut(&SD0, CMD_LED_OFF); + AP2_LED_ENABLED = false; } void annepro2LedEnable(void) { sdPut(&SD0, CMD_LED_ON); + AP2_LED_ENABLED = true; } void annepro2LedUpdate(uint8_t row, uint8_t col) @@ -31,6 +36,8 @@ void annepro2LedSetProfile(uint8_t prof) { sdPut(&SD0, CMD_LED_SET_PROFILE); sdPut(&SD0, prof); + uint8_t buf = sdGet(&SD0); + AP2_LED_DYNAMIC_PROFILE = buf; } uint8_t annepro2LedGetProfile() @@ -52,6 +59,8 @@ uint8_t annepro2LedGetNumProfiles() void annepro2LedNextProfile() { sdPut(&SD0, CMD_LED_NEXT_PROFILE); + uint8_t buf = sdGet(&SD0); + AP2_LED_DYNAMIC_PROFILE = buf; } void annepro2LedNextIntensity() @@ -94,3 +103,20 @@ void annepro2LedResetForegroundColor() annepro2LedSetProfile(currentProfile); } +/* + * 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) +{ + uint8_t msg = 0b10000000 | (row << 4) | col; + sdPut(&SD0, msg); +} diff --git a/keyboards/annepro2/qmk_ap2_led.h b/keyboards/annepro2/qmk_ap2_led.h index c626fc14c12..664944c0d47 100644 --- a/keyboards/annepro2/qmk_ap2_led.h +++ b/keyboards/annepro2/qmk_ap2_led.h @@ -14,6 +14,7 @@ #define CMD_LED_NEXT_INTENSITY 0xC #define CMD_LED_NEXT_ANIMATION_SPEED 0xD #define CMD_LED_SET_FOREGROUND_COLOR 0xE +#define CMD_LED_KEYPRESS 0xF void annepro2LedDisable(void); void annepro2LedEnable(void); @@ -30,3 +31,8 @@ void annepro2LedNextIntensity(void); void annepro2LedNextAnimationSpeed(void); void annepro2LedSetForegroundColor(uint8_t red, uint8_t green, uint8_t blue); void annepro2LedResetForegroundColor(void); +void annepro2LedForwardKeypress(uint8_t row, uint8_t col); + + +extern bool AP2_LED_ENABLED; +extern bool AP2_LED_DYNAMIC_PROFILE;