Merge commit '6d0a62920410f50d7f6707960ca1ca0c8fd1d1fa' into firmware21
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include "keyboard.h"
|
||||
#include "action.h"
|
||||
#include "action_util.h"
|
||||
#include "usb_device_state.h"
|
||||
#include "mousekey.h"
|
||||
#include "led.h"
|
||||
#include "sendchar.h"
|
||||
@@ -42,12 +43,6 @@
|
||||
#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
|
||||
@@ -143,13 +138,15 @@ void boardInit(void) {
|
||||
}
|
||||
|
||||
void protocol_setup(void) {
|
||||
usb_device_state_init();
|
||||
|
||||
// TESTING
|
||||
// chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
|
||||
|
||||
keyboard_setup();
|
||||
}
|
||||
|
||||
void protocol_init(void) {
|
||||
static host_driver_t *driver = NULL;
|
||||
|
||||
void protocol_pre_init(void) {
|
||||
/* Init USB */
|
||||
usb_event_queue_init();
|
||||
init_usb_driver(&USB_DRIVER);
|
||||
@@ -158,19 +155,9 @@ void protocol_init(void) {
|
||||
setup_midi();
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_LINK_ENABLE
|
||||
init_serial_link();
|
||||
#endif
|
||||
|
||||
#ifdef VISUALIZER_ENABLE
|
||||
visualizer_init();
|
||||
#endif
|
||||
|
||||
host_driver_t *driver = NULL;
|
||||
|
||||
/* Wait until the USB or serial link is active */
|
||||
/* Wait until USB is active */
|
||||
while (true) {
|
||||
#if defined(WAIT_FOR_USB) || defined(SERIAL_LINK_ENABLE)
|
||||
#if defined(WAIT_FOR_USB)
|
||||
if (USB_DRIVER.state == USB_ACTIVE) {
|
||||
driver = &chibios_driver;
|
||||
break;
|
||||
@@ -178,13 +165,6 @@ void protocol_init(void) {
|
||||
#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);
|
||||
}
|
||||
@@ -197,32 +177,18 @@ void protocol_init(void) {
|
||||
wait_ms(50);
|
||||
|
||||
print("USB configured.\n");
|
||||
|
||||
/* init TMK modules */
|
||||
keyboard_init();
|
||||
host_set_driver(driver);
|
||||
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_init();
|
||||
#endif
|
||||
|
||||
print("Keyboard start.\n");
|
||||
}
|
||||
|
||||
void protocol_task(void) {
|
||||
void protocol_post_init(void) { host_set_driver(driver); }
|
||||
|
||||
void protocol_pre_task(void) {
|
||||
usb_event_queue_task();
|
||||
|
||||
#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) {
|
||||
/* Do this in the suspended state */
|
||||
# ifdef SERIAL_LINK_ENABLE
|
||||
serial_link_update();
|
||||
# endif
|
||||
suspend_power_down(); // on AVR this deep sleeps for 15ms
|
||||
/* Remote wakeup */
|
||||
if (suspend_wakeup_condition()) {
|
||||
@@ -236,14 +202,11 @@ void protocol_task(void) {
|
||||
# ifdef MOUSEKEY_ENABLE
|
||||
mousekey_send();
|
||||
# endif /* MOUSEKEY_ENABLE */
|
||||
|
||||
# ifdef VISUALIZER_ENABLE
|
||||
visualizer_resume();
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
keyboard_task();
|
||||
void protocol_post_task(void) {
|
||||
#ifdef CONSOLE_ENABLE
|
||||
console_task();
|
||||
#endif
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
# include "led.h"
|
||||
#endif
|
||||
#include "wait.h"
|
||||
#include "usb_device_state.h"
|
||||
#include "usb_descriptor.h"
|
||||
#include "usb_driver.h"
|
||||
|
||||
@@ -74,7 +75,12 @@ uint8_t keyboard_protocol __attribute__((aligned(2))) = 1;
|
||||
uint8_t keyboard_led_state = 0;
|
||||
volatile uint16_t keyboard_idle_count = 0;
|
||||
static virtual_timer_t keyboard_idle_timer;
|
||||
static void keyboard_idle_timer_cb(void *arg);
|
||||
|
||||
#if CH_KERNEL_MAJOR >= 7
|
||||
static void keyboard_idle_timer_cb(struct ch_virtual_timer *, void *arg);
|
||||
#elif CH_KERNEL_MAJOR <= 6
|
||||
static void keyboard_idle_timer_cb(void *arg);
|
||||
#endif
|
||||
|
||||
report_keyboard_t keyboard_report_sent = {{0}};
|
||||
#ifdef MOUSE_ENABLE
|
||||
@@ -443,6 +449,7 @@ static inline bool usb_event_queue_dequeue(usbevent_t *event) {
|
||||
}
|
||||
|
||||
static inline void usb_event_suspend_handler(void) {
|
||||
usb_device_state_set_suspend(USB_DRIVER.configuration != 0, USB_DRIVER.configuration);
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_enable();
|
||||
#endif /* SLEEP_LED_ENABLE */
|
||||
@@ -450,6 +457,7 @@ static inline void usb_event_suspend_handler(void) {
|
||||
|
||||
static inline void usb_event_wakeup_handler(void) {
|
||||
suspend_wakeup_init();
|
||||
usb_device_state_set_resume(USB_DRIVER.configuration != 0, USB_DRIVER.configuration);
|
||||
#ifdef SLEEP_LED_ENABLE
|
||||
sleep_led_disable();
|
||||
// NOTE: converters may not accept this
|
||||
@@ -471,6 +479,15 @@ void usb_event_queue_task(void) {
|
||||
last_suspend_state = false;
|
||||
usb_event_wakeup_handler();
|
||||
break;
|
||||
case USB_EVENT_CONFIGURED:
|
||||
usb_device_state_set_configuration(USB_DRIVER.configuration != 0, USB_DRIVER.configuration);
|
||||
break;
|
||||
case USB_EVENT_UNCONFIGURED:
|
||||
usb_device_state_set_configuration(false, 0);
|
||||
break;
|
||||
case USB_EVENT_RESET:
|
||||
usb_device_state_set_reset();
|
||||
break;
|
||||
default:
|
||||
// Nothing to do, we don't handle it.
|
||||
break;
|
||||
@@ -513,13 +530,14 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
|
||||
if (last_suspend_state) {
|
||||
usb_event_queue_enqueue(USB_EVENT_WAKEUP);
|
||||
}
|
||||
usb_event_queue_enqueue(USB_EVENT_CONFIGURED);
|
||||
return;
|
||||
case USB_EVENT_SUSPEND:
|
||||
usb_event_queue_enqueue(USB_EVENT_SUSPEND);
|
||||
/* Falls into.*/
|
||||
case USB_EVENT_UNCONFIGURED:
|
||||
/* Falls into.*/
|
||||
case USB_EVENT_RESET:
|
||||
usb_event_queue_enqueue(event);
|
||||
for (int i = 0; i < NUM_USB_DRIVERS; i++) {
|
||||
chSysLockFromISR();
|
||||
/* Disconnection event on suspend.*/
|
||||
@@ -813,7 +831,12 @@ void kbd_sof_cb(USBDriver *usbp) { (void)usbp; }
|
||||
|
||||
/* Idle requests timer code
|
||||
* callback (called from ISR, unlocked state) */
|
||||
#if CH_KERNEL_MAJOR >= 7
|
||||
static void keyboard_idle_timer_cb(struct ch_virtual_timer *timer, void *arg) {
|
||||
(void)timer;
|
||||
#elif CH_KERNEL_MAJOR <= 6
|
||||
static void keyboard_idle_timer_cb(void *arg) {
|
||||
#endif
|
||||
USBDriver *usbp = (USBDriver *)arg;
|
||||
|
||||
osalSysLockFromISR();
|
||||
@@ -973,6 +996,17 @@ static void send_extra(uint8_t report_id, uint16_t data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (usbGetTransmitStatusI(&USB_DRIVER, SHARED_IN_EPNUM)) {
|
||||
/* Need to either suspend, or loop and call unlock/lock during
|
||||
* every iteration - otherwise the system will remain locked,
|
||||
* no interrupts served, so USB not going through as well.
|
||||
* Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
|
||||
if (osalThreadSuspendTimeoutS(&(&USB_DRIVER)->epc[SHARED_IN_EPNUM]->in_state->thread, TIME_MS2I(10)) == MSG_TIMEOUT) {
|
||||
osalSysUnlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static report_extra_t report;
|
||||
report = (report_extra_t){.report_id = report_id, .usage = data};
|
||||
|
||||
@@ -1142,6 +1176,8 @@ void midi_ep_task(void) {
|
||||
|
||||
#ifdef VIRTSER_ENABLE
|
||||
|
||||
void virtser_init(void) {}
|
||||
|
||||
void virtser_send(const uint8_t byte) { chnWrite(&drivers.serial_driver.driver, &byte, 1); }
|
||||
|
||||
__attribute__((weak)) void virtser_recv(uint8_t c) {
|
||||
|
||||
Reference in New Issue
Block a user