Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Keyboard annepro2 ble caps lock (qmk#12)
Browse files Browse the repository at this point in the history
* Move matrix_scan_kb out of board.c to annepro2.c

* add buffer clear after init and caplock polling
  • Loading branch information
tech2077 authored and shearn89 committed Feb 16, 2022
1 parent d9ba2ec commit 61d984f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
25 changes: 24 additions & 1 deletion keyboards/annepro2/annepro2.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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};

uint16_t annepro2LedMatrix[MATRIX_ROWS * MATRIX_COLS] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,
Expand Down Expand Up @@ -50,7 +51,11 @@ void OVERRIDE keyboard_post_init_kb(void) {

// Give the send uart thread some time to
// send out the queue before we read back
wait_ms(5);
wait_ms(15);

// loop to clear out receive buffer from ble wakeup
while(!sdGetWouldBlock(&SD1))
sdGet(&SD1);

keyboard_post_init_user();
}
Expand All @@ -59,6 +64,24 @@ void OVERRIDE matrix_init_kb(void) {
matrix_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);

// if it's capslock from ble, darken led
if (BLECapsLock.caps_lock) {
annepro2LedClearMask(MATRIX_COLS * 2);
} else {
annepro2LedSetMask(MATRIX_COLS * 2);
}
}


matrix_scan_user();
}

/*!
* @returns false processing for this keycode has been completed.
*/
Expand Down
7 changes: 7 additions & 0 deletions keyboards/annepro2/annepro2.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@

#define OVERRIDE __attribute__ ((noinline))

typedef struct __attribute__((__packed__)) {
uint8_t _dummy[10];
bool caps_lock;
} ble_capslock_t;

extern uint16_t annepro2LedMatrix[MATRIX_ROWS * MATRIX_COLS];

extern ble_capslock_t BLECapsLock;

enum AP2KeyCodes {
KC_AP2_BT1 = SAFE_RANGE,
KC_AP2_BT2,
Expand Down
4 changes: 0 additions & 4 deletions keyboards/annepro2/boards/ANNEPRO2/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ void __early_init(void) {
ht32_clock_init();
}

void matrix_scan_kb() {
matrix_scan_user();
}

/**
* @brief Board-specific initialization code.
* @todo Add your board-specific code, if any.
Expand Down

0 comments on commit 61d984f

Please sign in to comment.