From 4995cfc61e7d2d0c05cf493959456b5bc9a74f19 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Sun, 18 Dec 2022 14:53:27 +0100 Subject: Rename matrix to keymat and refactor key matrix access --- src/main.c | 102 +++++++------------------------------------------------------ 1 file changed, 11 insertions(+), 91 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index f571a89..265b8af 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ #include "board.h" #include "usb_stdio.h" -#include "matrix.h" +#include "keymat.h" #include "keysym.h" #include "split.h" #include "led.h" @@ -22,29 +22,32 @@ #include #include -bool send_hid_report(int id); void cdc_task(void); -const uint32_t **keymap_layers = keymap_layers_de; - int main(void) { + uint32_t start, stop; + board_init(); tud_init(BOARD_TUD_RHPORT); usb_stdio_init(); led_init(); - matrix_init(); + keymat_init(); split_init(); - //hid_init(); + hid_init(); + start = board_millis(); while (true) { tud_task(); cdc_task(); led_task(); split_task(); - //hid_task(); - send_hid_report(REPORT_ID_MIN); + hid_task(); + + stop = board_millis(); + DEBUG("Main loop: %i ms", stop - start); + start = stop; } return 0; @@ -106,89 +109,6 @@ tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, { } -void -tud_hid_report_complete_cb(uint8_t instance, - uint8_t const *report, uint8_t len) -{ - uint8_t id; - - for (id = report[0] + 1; id < REPORT_ID_MAX; id++) { - if (send_hid_report(id)) - break; - } -} - -bool -send_keyboard_report(void) -{ - static bool cleared = true; - uint8_t report[6] = { 0 }; - bool any; - - any = hid_gen_report(report); - - if (any) { - tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, report); - cleared = false; - return true; - } else if (!cleared) { - tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL); - cleared = true; - return true; - } - - return false; -} - -bool -send_mouse_report(bool state) -{ - if (state) { - tud_hid_mouse_report(REPORT_ID_MOUSE, 0, 10, 10, 0, 0); - return true; - } - - return false; -} - -bool -send_consumer_control_report(bool state) -{ - static bool cleared = true; - uint16_t report; - - if (state) { - report = HID_USAGE_CONSUMER_VOLUME_DECREMENT; - tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &report, 2); - cleared = false; - return true; - } else if (!cleared) { - report = 0; - tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &report, 2); - cleared = true; - return true; - } - - return false; -} - -bool -send_hid_report(int id) -{ - if (!tud_hid_ready()) return false; - - switch (id) { - case REPORT_ID_KEYBOARD: - return send_keyboard_report(); - case REPORT_ID_MOUSE: - return send_mouse_report(false); - case REPORT_ID_CONSUMER_CONTROL: - return send_consumer_control_report(false); - } - - return false; -} - void process_cmd(char *cmd) { -- cgit v1.2.3-71-gd317