diff options
Diffstat (limited to 'common/host.c')
| -rw-r--r-- | common/host.c | 150 |
1 files changed, 1 insertions, 149 deletions
diff --git a/common/host.c b/common/host.c index 569451652..0703dba01 100644 --- a/common/host.c +++ b/common/host.c | |||
| @@ -27,7 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 27 | bool keyboard_nkro = false; | 27 | bool keyboard_nkro = false; |
| 28 | #endif | 28 | #endif |
| 29 | 29 | ||
| 30 | report_keyboard_t *keyboard_report = &(report_keyboard_t){}; | ||
| 31 | report_mouse_t mouse_report = {}; | 30 | report_mouse_t mouse_report = {}; |
| 32 | 31 | ||
| 33 | 32 | ||
| @@ -35,13 +34,6 @@ static host_driver_t *driver; | |||
| 35 | static uint16_t last_system_report = 0; | 34 | static uint16_t last_system_report = 0; |
| 36 | static uint16_t last_consumer_report = 0; | 35 | static uint16_t last_consumer_report = 0; |
| 37 | 36 | ||
| 38 | static inline void add_key_byte(uint8_t code); | ||
| 39 | static inline void del_key_byte(uint8_t code); | ||
| 40 | #ifdef NKRO_ENABLE | ||
| 41 | static inline void add_key_bit(uint8_t code); | ||
| 42 | static inline void del_key_bit(uint8_t code); | ||
| 43 | #endif | ||
| 44 | |||
| 45 | 37 | ||
| 46 | void host_set_driver(host_driver_t *d) | 38 | void host_set_driver(host_driver_t *d) |
| 47 | { | 39 | { |
| @@ -67,7 +59,7 @@ void host_keyboard_send(report_keyboard_t *report) | |||
| 67 | if (debug_keyboard) { | 59 | if (debug_keyboard) { |
| 68 | dprint("keyboard_report: "); | 60 | dprint("keyboard_report: "); |
| 69 | for (uint8_t i = 0; i < REPORT_SIZE; i++) { | 61 | for (uint8_t i = 0; i < REPORT_SIZE; i++) { |
| 70 | dprintf("%02X ", keyboard_report->raw[i]); | 62 | dprintf("%02X ", report->raw[i]); |
| 71 | } | 63 | } |
| 72 | dprint("\n"); | 64 | dprint("\n"); |
| 73 | } | 65 | } |
| @@ -97,98 +89,6 @@ void host_consumer_send(uint16_t report) | |||
| 97 | (*driver->send_consumer)(report); | 89 | (*driver->send_consumer)(report); |
| 98 | } | 90 | } |
| 99 | 91 | ||
| 100 | |||
| 101 | |||
| 102 | /* keyboard report utils */ | ||
| 103 | void host_add_key(uint8_t key) | ||
| 104 | { | ||
| 105 | #ifdef NKRO_ENABLE | ||
| 106 | if (keyboard_nkro) { | ||
| 107 | add_key_bit(key); | ||
| 108 | return; | ||
| 109 | } | ||
| 110 | #endif | ||
| 111 | add_key_byte(key); | ||
| 112 | } | ||
| 113 | |||
| 114 | void host_del_key(uint8_t key) | ||
| 115 | { | ||
| 116 | #ifdef NKRO_ENABLE | ||
| 117 | if (keyboard_nkro) { | ||
| 118 | del_key_bit(key); | ||
| 119 | return; | ||
| 120 | } | ||
| 121 | #endif | ||
| 122 | del_key_byte(key); | ||
| 123 | } | ||
| 124 | |||
| 125 | void host_clear_keys(void) | ||
| 126 | { | ||
| 127 | // not clea mods | ||
| 128 | for (int8_t i = 1; i < REPORT_SIZE; i++) { | ||
| 129 | keyboard_report->raw[i] = 0; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | uint8_t host_get_mods(void) | ||
| 134 | { | ||
| 135 | return keyboard_report->mods; | ||
| 136 | } | ||
| 137 | |||
| 138 | void host_add_mods(uint8_t mods) | ||
| 139 | { | ||
| 140 | keyboard_report->mods |= mods; | ||
| 141 | } | ||
| 142 | |||
| 143 | void host_del_mods(uint8_t mods) | ||
| 144 | { | ||
| 145 | keyboard_report->mods &= ~mods; | ||
| 146 | } | ||
| 147 | |||
| 148 | void host_set_mods(uint8_t mods) | ||
| 149 | { | ||
| 150 | keyboard_report->mods = mods; | ||
| 151 | } | ||
| 152 | |||
| 153 | void host_clear_mods(void) | ||
| 154 | { | ||
| 155 | keyboard_report->mods = 0; | ||
| 156 | } | ||
| 157 | |||
| 158 | uint8_t host_has_anykey(void) | ||
| 159 | { | ||
| 160 | uint8_t cnt = 0; | ||
| 161 | for (uint8_t i = 1; i < REPORT_SIZE; i++) { | ||
| 162 | if (keyboard_report->raw[i]) | ||
| 163 | cnt++; | ||
| 164 | } | ||
| 165 | return cnt; | ||
| 166 | } | ||
| 167 | |||
| 168 | uint8_t host_has_anymod(void) | ||
| 169 | { | ||
| 170 | return bitpop(keyboard_report->mods); | ||
| 171 | } | ||
| 172 | |||
| 173 | uint8_t host_get_first_key(void) | ||
| 174 | { | ||
| 175 | #ifdef NKRO_ENABLE | ||
| 176 | if (keyboard_nkro) { | ||
| 177 | uint8_t i = 0; | ||
| 178 | for (; i < REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) | ||
| 179 | ; | ||
| 180 | return i<<3 | biton(keyboard_report->nkro.bits[i]); | ||
| 181 | } | ||
| 182 | #endif | ||
| 183 | return keyboard_report->keys[0]; | ||
| 184 | } | ||
| 185 | |||
| 186 | void host_send_keyboard_report(void) | ||
| 187 | { | ||
| 188 | if (!driver) return; | ||
| 189 | host_keyboard_send(keyboard_report); | ||
| 190 | } | ||
| 191 | |||
| 192 | uint8_t host_mouse_in_use(void) | 92 | uint8_t host_mouse_in_use(void) |
| 193 | { | 93 | { |
| 194 | return (mouse_report.buttons | mouse_report.x | mouse_report.y | mouse_report.v | mouse_report.h); | 94 | return (mouse_report.buttons | mouse_report.x | mouse_report.y | mouse_report.v | mouse_report.h); |
| @@ -203,51 +103,3 @@ uint16_t host_last_consumer_report(void) | |||
| 203 | { | 103 | { |
| 204 | return last_consumer_report; | 104 | return last_consumer_report; |
| 205 | } | 105 | } |
| 206 | |||
| 207 | static inline void add_key_byte(uint8_t code) | ||
| 208 | { | ||
| 209 | int8_t i = 0; | ||
| 210 | int8_t empty = -1; | ||
| 211 | for (; i < REPORT_KEYS; i++) { | ||
| 212 | if (keyboard_report->keys[i] == code) { | ||
| 213 | break; | ||
| 214 | } | ||
| 215 | if (empty == -1 && keyboard_report->keys[i] == 0) { | ||
| 216 | empty = i; | ||
| 217 | } | ||
| 218 | } | ||
| 219 | if (i == REPORT_KEYS) { | ||
| 220 | if (empty != -1) { | ||
| 221 | keyboard_report->keys[empty] = code; | ||
| 222 | } | ||
| 223 | } | ||
| 224 | } | ||
| 225 | |||
| 226 | static inline void del_key_byte(uint8_t code) | ||
| 227 | { | ||
| 228 | for (uint8_t i = 0; i < REPORT_KEYS; i++) { | ||
| 229 | if (keyboard_report->keys[i] == code) { | ||
| 230 | keyboard_report->keys[i] = 0; | ||
| 231 | } | ||
| 232 | } | ||
| 233 | } | ||
| 234 | |||
| 235 | #ifdef NKRO_ENABLE | ||
| 236 | static inline void add_key_bit(uint8_t code) | ||
| 237 | { | ||
| 238 | if ((code>>3) < REPORT_BITS) { | ||
| 239 | keyboard_report->nkro.bits[code>>3] |= 1<<(code&7); | ||
| 240 | } else { | ||
| 241 | dprintf("add_key_bit: can't add: %02X\n", code); | ||
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 245 | static inline void del_key_bit(uint8_t code) | ||
| 246 | { | ||
| 247 | if ((code>>3) < REPORT_BITS) { | ||
| 248 | keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7)); | ||
| 249 | } else { | ||
| 250 | dprintf("del_key_bit: can't del: %02X\n", code); | ||
| 251 | } | ||
| 252 | } | ||
| 253 | #endif | ||
