forked from mirrors/qmk_userspace
Add adaptive NKRO feature
This commit is contained in:
parent
fd0426237f
commit
6aa63c3c63
4 changed files with 136 additions and 3 deletions
|
@ -41,6 +41,9 @@ uint8_t has_anykey(void) {
|
|||
uint8_t* p = keyboard_report->keys;
|
||||
uint8_t lp = sizeof(keyboard_report->keys);
|
||||
#ifdef NKRO_ENABLE
|
||||
# ifdef APDAPTIVE_NKRO_ENABLE
|
||||
return kb_keys_count + nkro_bit_count;
|
||||
# endif
|
||||
if (keyboard_protocol && keymap_config.nkro) {
|
||||
p = nkro_report->bits;
|
||||
lp = sizeof(nkro_report->bits);
|
||||
|
@ -58,12 +61,16 @@ uint8_t has_anykey(void) {
|
|||
*/
|
||||
uint8_t get_first_key(void) {
|
||||
#ifdef NKRO_ENABLE
|
||||
# ifdef APDAPTIVE_NKRO_ENABLE
|
||||
return keyboard_report->keys[0];
|
||||
# else
|
||||
if (keyboard_protocol && keymap_config.nkro) {
|
||||
uint8_t i = 0;
|
||||
for (; i < NKRO_REPORT_BITS && !nkro_report->bits[i]; i++)
|
||||
;
|
||||
return i << 3 | biton(nkro_report->bits[i]);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
#ifdef RING_BUFFERED_6KRO_REPORT_ENABLE
|
||||
uint8_t i = cb_head;
|
||||
|
@ -89,6 +96,11 @@ bool is_key_pressed(uint8_t key) {
|
|||
return false;
|
||||
}
|
||||
#ifdef NKRO_ENABLE
|
||||
# ifdef APDAPTIVE_NKRO_ENABLE
|
||||
if (keyboard_protocol && nkro_bit_count) {
|
||||
if ((key >> 3) < NKRO_REPORT_BITS && (nkro_report->bits[key >> 3] & 1 << (key & 7))) return true;
|
||||
}
|
||||
# else
|
||||
if (keyboard_protocol && keymap_config.nkro) {
|
||||
if ((key >> 3) < NKRO_REPORT_BITS) {
|
||||
return nkro_report->bits[key >> 3] & 1 << (key & 7);
|
||||
|
@ -96,6 +108,7 @@ bool is_key_pressed(uint8_t key) {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
|
||||
if (keyboard_report->keys[i] == key) {
|
||||
|
@ -167,6 +180,10 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) {
|
|||
if (i == KEYBOARD_REPORT_KEYS) {
|
||||
if (empty != -1) {
|
||||
keyboard_report->keys[empty] = code;
|
||||
# ifdef APDAPTIVE_NKRO_ENABLE
|
||||
kb_report_changed |= KB_RPT_STD;
|
||||
++kb_keys_count;
|
||||
# endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -206,6 +223,10 @@ void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) {
|
|||
for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
|
||||
if (keyboard_report->keys[i] == code) {
|
||||
keyboard_report->keys[i] = 0;
|
||||
# ifdef APDAPTIVE_NKRO_ENABLE
|
||||
kb_report_changed |= KB_RPT_STD;
|
||||
--kb_keys_count;
|
||||
# endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -219,6 +240,10 @@ void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) {
|
|||
void add_key_bit(report_nkro_t* nkro_report, uint8_t code) {
|
||||
if ((code >> 3) < NKRO_REPORT_BITS) {
|
||||
nkro_report->bits[code >> 3] |= 1 << (code & 7);
|
||||
# ifdef APDAPTIVE_NKRO_ENABLE
|
||||
kb_report_changed |= KB_RPT_NKRO;
|
||||
++nkro_bit_count;
|
||||
# endif
|
||||
} else {
|
||||
dprintf("add_key_bit: can't add: %02X\n", code);
|
||||
}
|
||||
|
@ -228,12 +253,24 @@ void add_key_bit(report_nkro_t* nkro_report, uint8_t code) {
|
|||
*
|
||||
* FIXME: Needs doc
|
||||
*/
|
||||
void del_key_bit(report_nkro_t* nkro_report, uint8_t code) {
|
||||
bool del_key_bit(report_nkro_t* nkro_report, uint8_t code) {
|
||||
if ((code >> 3) < NKRO_REPORT_BITS) {
|
||||
# ifdef APDAPTIVE_NKRO_ENABLE
|
||||
if (nkro_report->bits[code >> 3] & (1 << (code & 7))) {
|
||||
nkro_report->bits[code >> 3] &= ~(1 << (code & 7));
|
||||
kb_report_changed |= KB_RPT_NKRO;
|
||||
--nkro_bit_count;
|
||||
return true;
|
||||
}
|
||||
# else
|
||||
nkro_report->bits[code >> 3] &= ~(1 << (code & 7));
|
||||
return true;
|
||||
# endif
|
||||
} else {
|
||||
dprintf("del_key_bit: can't del: %02X\n", code);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -243,7 +280,11 @@ void del_key_bit(report_nkro_t* nkro_report, uint8_t code) {
|
|||
*/
|
||||
void add_key_to_report(uint8_t key) {
|
||||
#ifdef NKRO_ENABLE
|
||||
# ifdef APDAPTIVE_NKRO_ENABLE
|
||||
if (keyboard_protocol && kb_keys_count == KEYBOARD_REPORT_KEYS) {
|
||||
# else
|
||||
if (keyboard_protocol && keymap_config.nkro) {
|
||||
# endif
|
||||
add_key_bit(nkro_report, key);
|
||||
return;
|
||||
}
|
||||
|
@ -257,10 +298,14 @@ void add_key_to_report(uint8_t key) {
|
|||
*/
|
||||
void del_key_from_report(uint8_t key) {
|
||||
#ifdef NKRO_ENABLE
|
||||
# ifdef APDAPTIVE_NKRO_ENABLE
|
||||
if (keyboard_protocol && nkro_bit_count && del_key_bit(nkro_report, key)) return;
|
||||
# else
|
||||
if (keyboard_protocol && keymap_config.nkro) {
|
||||
del_key_bit(nkro_report, key);
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
del_key_byte(keyboard_report, key);
|
||||
}
|
||||
|
@ -272,10 +317,25 @@ void del_key_from_report(uint8_t key) {
|
|||
void clear_keys_from_report(void) {
|
||||
// not clear mods
|
||||
#ifdef NKRO_ENABLE
|
||||
# ifdef APDAPTIVE_NKRO_ENABLE
|
||||
memset(nkro_report->bits, 0, sizeof(nkro_report->bits));
|
||||
if (nkro_bit_count) {
|
||||
kb_report_changed |= KB_RPT_NKRO;
|
||||
nkro_bit_count = 0;
|
||||
}
|
||||
|
||||
memset(keyboard_report->keys, 0, sizeof(keyboard_report->keys));
|
||||
if (kb_keys_count) {
|
||||
kb_report_changed |= KB_RPT_STD;
|
||||
kb_keys_count = 0;
|
||||
}
|
||||
return;
|
||||
# else
|
||||
if (keyboard_protocol && keymap_config.nkro) {
|
||||
memset(nkro_report->bits, 0, sizeof(nkro_report->bits));
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
memset(keyboard_report->keys, 0, sizeof(keyboard_report->keys));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue