diff options
Diffstat (limited to 'tmk_core/common/report.c')
-rw-r--r-- | tmk_core/common/report.c | 66 |
1 files changed, 27 insertions, 39 deletions
diff --git a/tmk_core/common/report.c b/tmk_core/common/report.c index 6a06b70c60..f4758b48ec 100644 --- a/tmk_core/common/report.c +++ b/tmk_core/common/report.c @@ -25,20 +25,18 @@ * * FIXME: Needs doc */ -uint8_t has_anykey(report_keyboard_t* keyboard_report) -{ - uint8_t cnt = 0; - uint8_t *p = keyboard_report->keys; - uint8_t lp = sizeof(keyboard_report->keys); +uint8_t has_anykey(report_keyboard_t* keyboard_report) { + uint8_t cnt = 0; + uint8_t* p = keyboard_report->keys; + uint8_t lp = sizeof(keyboard_report->keys); #ifdef NKRO_ENABLE if (keyboard_protocol && keymap_config.nkro) { - p = keyboard_report->nkro.bits; + p = keyboard_report->nkro.bits; lp = sizeof(keyboard_report->nkro.bits); } #endif while (lp--) { - if (*p++) - cnt++; + if (*p++) cnt++; } return cnt; } @@ -47,14 +45,13 @@ uint8_t has_anykey(report_keyboard_t* keyboard_report) * * FIXME: Needs doc */ -uint8_t get_first_key(report_keyboard_t* keyboard_report) -{ +uint8_t get_first_key(report_keyboard_t* keyboard_report) { #ifdef NKRO_ENABLE if (keyboard_protocol && keymap_config.nkro) { uint8_t i = 0; for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) ; - return i<<3 | biton(keyboard_report->nkro.bits[i]); + return i << 3 | biton(keyboard_report->nkro.bits[i]); } #endif #ifdef USB_6KRO_ENABLE @@ -75,10 +72,9 @@ uint8_t get_first_key(report_keyboard_t* keyboard_report) * * FIXME: Needs doc */ -void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) -{ +void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) { #ifdef USB_6KRO_ENABLE - int8_t i = cb_head; + int8_t i = cb_head; int8_t empty = -1; if (cb_count) { do { @@ -97,18 +93,16 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) // pop head when has no empty space cb_head = RO_INC(cb_head); cb_count--; - } - else { + } else { // left shift when has empty space uint8_t offset = 1; - i = RO_INC(empty); + i = RO_INC(empty); do { if (keyboard_report->keys[i] != 0) { keyboard_report->keys[empty] = keyboard_report->keys[i]; - keyboard_report->keys[i] = 0; - empty = RO_INC(empty); - } - else { + keyboard_report->keys[i] = 0; + empty = RO_INC(empty); + } else { offset++; } i = RO_INC(i); @@ -120,10 +114,10 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) } // add to tail keyboard_report->keys[cb_tail] = code; - cb_tail = RO_INC(cb_tail); + cb_tail = RO_INC(cb_tail); cb_count++; #else - int8_t i = 0; + int8_t i = 0; int8_t empty = -1; for (; i < KEYBOARD_REPORT_KEYS; i++) { if (keyboard_report->keys[i] == code) { @@ -145,8 +139,7 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) * * FIXME: Needs doc */ -void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) -{ +void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) { #ifdef USB_6KRO_ENABLE uint8_t i = cb_head; if (cb_count) { @@ -186,10 +179,9 @@ void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) * * FIXME: Needs doc */ -void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code) -{ - if ((code>>3) < KEYBOARD_REPORT_BITS) { - keyboard_report->nkro.bits[code>>3] |= 1<<(code&7); +void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code) { + if ((code >> 3) < KEYBOARD_REPORT_BITS) { + keyboard_report->nkro.bits[code >> 3] |= 1 << (code & 7); } else { dprintf("add_key_bit: can't add: %02X\n", code); } @@ -199,10 +191,9 @@ void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code) * * FIXME: Needs doc */ -void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) -{ - if ((code>>3) < KEYBOARD_REPORT_BITS) { - keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7)); +void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) { + if ((code >> 3) < KEYBOARD_REPORT_BITS) { + keyboard_report->nkro.bits[code >> 3] &= ~(1 << (code & 7)); } else { dprintf("del_key_bit: can't del: %02X\n", code); } @@ -213,8 +204,7 @@ void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) * * FIXME: Needs doc */ -void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key) -{ +void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key) { #ifdef NKRO_ENABLE if (keyboard_protocol && keymap_config.nkro) { add_key_bit(keyboard_report, key); @@ -228,8 +218,7 @@ void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key) * * FIXME: Needs doc */ -void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key) -{ +void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key) { #ifdef NKRO_ENABLE if (keyboard_protocol && keymap_config.nkro) { del_key_bit(keyboard_report, key); @@ -243,8 +232,7 @@ void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key) * * FIXME: Needs doc */ -void clear_keys_from_report(report_keyboard_t* keyboard_report) -{ +void clear_keys_from_report(report_keyboard_t* keyboard_report) { // not clear mods #ifdef NKRO_ENABLE if (keyboard_protocol && keymap_config.nkro) { |