summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/chibios
diff options
context:
space:
mode:
authorDrashna Jael're <drashna@live.com>2021-12-07 09:27:44 -0800
committerDrashna Jael're <drashna@live.com>2021-12-07 09:27:44 -0800
commit7c18b1c9d3d968ded45e072af3483547c3ec7859 (patch)
treeed7c8a4176033046eacff21228364290b44fcfdb /tmk_core/protocol/chibios
parent43002bdf77ab0f48af6b04e87edcc37f7cb7b905 (diff)
parent6d0a62920410f50d7f6707960ca1ca0c8fd1d1fa (diff)
Merge commit '6d0a62920410f50d7f6707960ca1ca0c8fd1d1fa' into firmware21
Diffstat (limited to 'tmk_core/protocol/chibios')
-rw-r--r--tmk_core/protocol/chibios/chibios.c63
-rw-r--r--tmk_core/protocol/chibios/usb_main.c40
2 files changed, 51 insertions, 52 deletions
diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c
index fece8903d2..29a26a9ce8 100644
--- a/tmk_core/protocol/chibios/chibios.c
+++ b/tmk_core/protocol/chibios/chibios.c
@@ -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;
@@ -179,13 +166,6 @@ void protocol_init(void) {
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
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 697566e27a..14de2fc8cc 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -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) {