summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/chibios
diff options
context:
space:
mode:
authorDrashna Jael're <drashna@live.com>2022-03-25 16:19:22 -0700
committerDrashna Jael're <drashna@live.com>2022-03-25 16:19:22 -0700
commit53ff570bf068e04740f187163774327839dfa68b (patch)
tree5429e069fc593d484b0b479de422b51ac239be83 /tmk_core/protocol/chibios
parente8171efc7158ba4ebb24827680b19b775d366b1a (diff)
parentefc9c525b19b33c6e09057218ea64f07f45f9555 (diff)
Remerge 0.16.x' into firmware21
Diffstat (limited to 'tmk_core/protocol/chibios')
-rw-r--r--tmk_core/protocol/chibios/chibios.c11
-rw-r--r--tmk_core/protocol/chibios/usb_driver.c32
-rw-r--r--tmk_core/protocol/chibios/usb_main.c55
-rw-r--r--tmk_core/protocol/chibios/usb_util.c8
4 files changed, 84 insertions, 22 deletions
diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c
index 29a26a9ce8..bd6adbe17e 100644
--- a/tmk_core/protocol/chibios/chibios.c
+++ b/tmk_core/protocol/chibios/chibios.c
@@ -60,10 +60,11 @@ 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);
+void send_programmable_button(uint32_t data);
void send_digitizer(report_digitizer_t *report);
/* host struct */
-host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
+host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer, send_programmable_button};
#ifdef VIRTSER_ENABLE
void virtser_task(void);
@@ -110,7 +111,7 @@ __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 // EARLY_INIT_PERFORM_BOOTLOADER_JUMP
+#endif // EARLY_INIT_PERFORM_BOOTLOADER_JUMP
}
__attribute__((weak)) void early_hardware_init_post(void) {}
@@ -179,7 +180,9 @@ void protocol_pre_init(void) {
print("USB configured.\n");
}
-void protocol_post_init(void) { host_set_driver(driver); }
+void protocol_post_init(void) {
+ host_set_driver(driver);
+}
void protocol_pre_task(void) {
usb_event_queue_task();
@@ -189,7 +192,7 @@ void protocol_pre_task(void) {
print("[s]");
while (USB_DRIVER.state == USB_SUSPENDED) {
/* Do this in the suspended state */
- suspend_power_down(); // on AVR this deep sleeps for 15ms
+ suspend_power_down(); // on AVR this deep sleeps for 15ms
/* Remote wakeup */
if (suspend_wakeup_condition()) {
usbWakeupHost(&USB_DRIVER);
diff --git a/tmk_core/protocol/chibios/usb_driver.c b/tmk_core/protocol/chibios/usb_driver.c
index cc0ce7600f..4de060f306 100644
--- a/tmk_core/protocol/chibios/usb_driver.c
+++ b/tmk_core/protocol/chibios/usb_driver.c
@@ -80,21 +80,37 @@ static bool qmkusb_start_receive(QMKUSBDriver *qmkusbp) {
* Interface implementation.
*/
-static size_t _write(void *ip, const uint8_t *bp, size_t n) { return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, TIME_INFINITE); }
+static size_t _write(void *ip, const uint8_t *bp, size_t n) {
+ return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, TIME_INFINITE);
+}
-static size_t _read(void *ip, uint8_t *bp, size_t n) { return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, TIME_INFINITE); }
+static size_t _read(void *ip, uint8_t *bp, size_t n) {
+ return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, TIME_INFINITE);
+}
-static msg_t _put(void *ip, uint8_t b) { return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, TIME_INFINITE); }
+static msg_t _put(void *ip, uint8_t b) {
+ return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, TIME_INFINITE);
+}
-static msg_t _get(void *ip) { return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, TIME_INFINITE); }
+static msg_t _get(void *ip) {
+ return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, TIME_INFINITE);
+}
-static msg_t _putt(void *ip, uint8_t b, sysinterval_t timeout) { return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, timeout); }
+static msg_t _putt(void *ip, uint8_t b, sysinterval_t timeout) {
+ return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, timeout);
+}
-static msg_t _gett(void *ip, sysinterval_t timeout) { return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, timeout); }
+static msg_t _gett(void *ip, sysinterval_t timeout) {
+ return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, timeout);
+}
-static size_t _writet(void *ip, const uint8_t *bp, size_t n, sysinterval_t timeout) { return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, timeout); }
+static size_t _writet(void *ip, const uint8_t *bp, size_t n, sysinterval_t timeout) {
+ return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, timeout);
+}
-static size_t _readt(void *ip, uint8_t *bp, size_t n, sysinterval_t timeout) { return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, timeout); }
+static size_t _readt(void *ip, uint8_t *bp, size_t n, sysinterval_t timeout) {
+ return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, timeout);
+}
static const struct QMKUSBDriverVMT vmt = {0, _write, _read, _put, _get, _putt, _gett, _writet, _readt};
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 14de2fc8cc..e18268db3b 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -786,7 +786,7 @@ void init_usb_driver(USBDriver *usbp) {
* after a reset.
*/
usbDisconnectBus(usbp);
- wait_ms(1500);
+ wait_ms(50);
usbStart(usbp, &usbcfg);
usbConnectBus(usbp);
@@ -827,7 +827,9 @@ void kbd_in_cb(USBDriver *usbp, usbep_t ep) {
/* start-of-frame handler
* TODO: i guess it would be better to re-implement using timers,
* so that this is not going to have to be checked every 1ms */
-void kbd_sof_cb(USBDriver *usbp) { (void)usbp; }
+void kbd_sof_cb(USBDriver *usbp) {
+ (void)usbp;
+}
/* Idle requests timer code
* callback (called from ISR, unlocked state) */
@@ -867,7 +869,9 @@ static void keyboard_idle_timer_cb(void *arg) {
}
/* LED status */
-uint8_t keyboard_leds(void) { return keyboard_led_state; }
+uint8_t keyboard_leds(void) {
+ return keyboard_led_state;
+}
/* prepare and start sending a report IN
* not callable from ISR or locked state */
@@ -967,7 +971,9 @@ void send_mouse(report_mouse_t *report) {
}
#else /* MOUSE_ENABLE */
-void send_mouse(report_mouse_t *report) { (void)report; }
+void send_mouse(report_mouse_t *report) {
+ (void)report;
+}
#endif /* MOUSE_ENABLE */
/* ---------------------------------------------------------
@@ -1027,6 +1033,35 @@ void send_consumer(uint16_t data) {
#endif
}
+void send_programmable_button(uint32_t data) {
+#ifdef PROGRAMMABLE_BUTTON_ENABLE
+ osalSysLock();
+ if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
+ osalSysUnlock();
+ 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_programmable_button_t report = {
+ .report_id = REPORT_ID_PROGRAMMABLE_BUTTON,
+ };
+
+ report.usage = data;
+
+ usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report));
+ osalSysUnlock();
+#endif
+}
+
void send_digitizer(report_digitizer_t *report) {
#ifdef DIGITIZER_ENABLE
# ifdef DIGITIZER_SHARED_EP
@@ -1155,7 +1190,9 @@ void webusb_task(void) {
#ifdef MIDI_ENABLE
-void send_midi_packet(MIDI_EventPacket_t *event) { chnWrite(&drivers.midi_driver.driver, (uint8_t *)event, sizeof(MIDI_EventPacket_t)); }
+void send_midi_packet(MIDI_EventPacket_t *event) {
+ chnWrite(&drivers.midi_driver.driver, (uint8_t *)event, sizeof(MIDI_EventPacket_t));
+}
bool recv_midi_packet(MIDI_EventPacket_t *const event) {
size_t size = chnReadTimeout(&drivers.midi_driver.driver, (uint8_t *)event, sizeof(MIDI_EventPacket_t), TIME_IMMEDIATE);
@@ -1178,7 +1215,9 @@ void midi_ep_task(void) {
void virtser_init(void) {}
-void virtser_send(const uint8_t byte) { chnWrite(&drivers.serial_driver.driver, &byte, 1); }
+void virtser_send(const uint8_t byte) {
+ chnWrite(&drivers.serial_driver.driver, &byte, 1);
+}
__attribute__((weak)) void virtser_recv(uint8_t c) {
// Ignore by default
@@ -1222,7 +1261,7 @@ void send_joystick_packet(joystick_t *joystick) {
joystick->axes[5],
# endif
},
-# endif // JOYSTICK_AXES_COUNT>0
+# endif // JOYSTICK_AXES_COUNT>0
# if JOYSTICK_BUTTON_COUNT > 0
.buttons = {
@@ -1238,7 +1277,7 @@ void send_joystick_packet(joystick_t *joystick) {
joystick->buttons[3],
# endif
}
-# endif // JOYSTICK_BUTTON_COUNT>0
+# endif // JOYSTICK_BUTTON_COUNT>0
};
// chnWrite(&drivers.joystick_driver.driver, (uint8_t *)&rep, sizeof(rep));
diff --git a/tmk_core/protocol/chibios/usb_util.c b/tmk_core/protocol/chibios/usb_util.c
index e32d6ebfa4..c8b435db0c 100644
--- a/tmk_core/protocol/chibios/usb_util.c
+++ b/tmk_core/protocol/chibios/usb_util.c
@@ -16,6 +16,10 @@
#include <hal.h>
#include "usb_util.h"
-void usb_disconnect(void) { usbStop(&USBD1); }
+void usb_disconnect(void) {
+ usbStop(&USBD1);
+}
-bool usb_connected_state(void) { return usbGetDriverStateI(&USBD1) == USB_ACTIVE; }
+bool usb_connected_state(void) {
+ return usbGetDriverStateI(&USBD1) == USB_ACTIVE;
+}