123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- #include <ch.h>
- #include <hal.h>
- #include "usb_main.h"
- #include "report.h"
- #include "host.h"
- #include "host_driver.h"
- #include "keyboard.h"
- #include "action.h"
- #include "action_util.h"
- #include "mousekey.h"
- #include "led.h"
- #include "sendchar.h"
- #include "debug.h"
- #include "print.h"
- #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
- # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP FALSE
- #endif
- #ifdef SLEEP_LED_ENABLE
- # include "sleep_led.h"
- #endif
- #ifdef SERIAL_LINK_ENABLE
- # include "serial_link/system/serial_link.h"
- #endif
- #ifdef VISUALIZER_ENABLE
- # include "visualizer/visualizer.h"
- #endif
- #ifdef MIDI_ENABLE
- # include "qmk_midi.h"
- #endif
- #ifdef STM32_EEPROM_ENABLE
- # include "eeprom_stm32.h"
- #endif
- #ifdef EEPROM_DRIVER
- # include "eeprom_driver.h"
- #endif
- #include "suspend.h"
- #include "wait.h"
- uint8_t keyboard_leds(void);
- void send_keyboard(report_keyboard_t *report);
- void send_mouse(report_mouse_t *report);
- void send_system(uint16_t data);
- void send_consumer(uint16_t data);
- host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
- #ifdef VIRTSER_ENABLE
- void virtser_task(void);
- #endif
- #ifdef RAW_ENABLE
- void raw_hid_task(void);
- #endif
- #ifdef CONSOLE_ENABLE
- void console_task(void);
- #endif
- #ifdef MIDI_ENABLE
- void midi_ep_task(void);
- #endif
- __attribute__((weak)) void early_hardware_init_pre(void) {
- #if EARLY_INIT_PERFORM_BOOTLOADER_JUMP
- void enter_bootloader_mode_if_requested(void);
- enter_bootloader_mode_if_requested();
- #endif
- }
- __attribute__((weak)) void early_hardware_init_post(void) {}
- __attribute__((weak)) void board_init(void) {}
- void __early_init(void) {
- early_hardware_init_pre();
-
- void __chibios_override___early_init(void);
- __chibios_override___early_init();
- early_hardware_init_post();
- }
- void boardInit(void) {
-
- void __chibios_override_boardInit(void);
- __chibios_override_boardInit();
- board_init();
- }
- int main(void) {
-
- halInit();
- chSysInit();
- #ifdef STM32_EEPROM_ENABLE
- EEPROM_Init();
- #endif
- #ifdef EEPROM_DRIVER
- eeprom_driver_init();
- #endif
-
-
- keyboard_setup();
-
- init_usb_driver(&USB_DRIVER);
- #ifdef MIDI_ENABLE
- setup_midi();
- #endif
- #ifdef SERIAL_LINK_ENABLE
- init_serial_link();
- #endif
- #ifdef VISUALIZER_ENABLE
- visualizer_init();
- #endif
- host_driver_t *driver = NULL;
-
- while (true) {
- #if defined(WAIT_FOR_USB) || defined(SERIAL_LINK_ENABLE)
- if (USB_DRIVER.state == USB_ACTIVE) {
- driver = &chibios_driver;
- break;
- }
- #else
- driver = &chibios_driver;
- break;
- #endif
- #ifdef SERIAL_LINK_ENABLE
- if (is_serial_link_connected()) {
- driver = get_serial_link_driver();
- break;
- }
- serial_link_update();
- #endif
- wait_ms(50);
- }
-
- wait_ms(50);
- print("USB configured.\n");
-
- keyboard_init();
- host_set_driver(driver);
- #ifdef SLEEP_LED_ENABLE
- sleep_led_init();
- #endif
- print("Keyboard start.\n");
-
- while (true) {
- #if !defined(NO_USB_STARTUP_CHECK)
- if (USB_DRIVER.state == USB_SUSPENDED) {
- print("[s]");
- # ifdef VISUALIZER_ENABLE
- visualizer_suspend();
- # endif
- while (USB_DRIVER.state == USB_SUSPENDED) {
-
- # ifdef SERIAL_LINK_ENABLE
- serial_link_update();
- # endif
- suspend_power_down();
-
- if (suspend_wakeup_condition()) {
- usbWakeupHost(&USB_DRIVER);
- restart_usb_driver(&USB_DRIVER);
- }
- }
-
-
- send_keyboard_report();
- # ifdef MOUSEKEY_ENABLE
- mousekey_send();
- # endif
- # ifdef VISUALIZER_ENABLE
- visualizer_resume();
- # endif
- }
- #endif
- keyboard_task();
- #ifdef CONSOLE_ENABLE
- console_task();
- #endif
- #ifdef MIDI_ENABLE
- midi_ep_task();
- #endif
- #ifdef VIRTSER_ENABLE
- virtser_task();
- #endif
- #ifdef RAW_ENABLE
- raw_hid_task();
- #endif
-
- housekeeping_task_kb();
- housekeeping_task_user();
- }
- }
|