Merge commit 'd9e077468ab3446cbd7306a453a73dad2c1403e8' into firmware_21

This commit is contained in:
Drashna Jael're
2021-10-11 20:36:47 -07:00
831 changed files with 23110 additions and 8122 deletions
@@ -65,6 +65,7 @@ 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_digitizer(report_digitizer_t *report);
/* host struct */
host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
@@ -141,18 +142,14 @@ void boardInit(void) {
board_init();
}
/* Main thread
*/
int main(void) {
/* ChibiOS/RT init */
halInit();
chSysInit();
void protocol_setup(void) {
// TESTING
// chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
keyboard_setup();
}
void protocol_init(void) {
/* Init USB */
usb_event_queue_init();
init_usb_driver(&USB_DRIVER);
@@ -210,60 +207,57 @@ int main(void) {
#endif
print("Keyboard start.\n");
}
/* Main loop */
while (true) {
usb_event_queue_task();
void protocol_task(void) {
usb_event_queue_task();
#if !defined(NO_USB_STARTUP_CHECK)
if (USB_DRIVER.state == USB_SUSPENDED) {
print("[s]");
if (USB_DRIVER.state == USB_SUSPENDED) {
print("[s]");
# ifdef VISUALIZER_ENABLE
visualizer_suspend();
visualizer_suspend();
# endif
while (USB_DRIVER.state == USB_SUSPENDED) {
/* Do this in the suspended state */
while (USB_DRIVER.state == USB_SUSPENDED) {
/* Do this in the suspended state */
# ifdef SERIAL_LINK_ENABLE
serial_link_update();
serial_link_update();
# endif
suspend_power_down(); // on AVR this deep sleeps for 15ms
/* Remote wakeup */
if (suspend_wakeup_condition()) {
usbWakeupHost(&USB_DRIVER);
restart_usb_driver(&USB_DRIVER);
}
suspend_power_down(); // on AVR this deep sleeps for 15ms
/* Remote wakeup */
if (suspend_wakeup_condition()) {
usbWakeupHost(&USB_DRIVER);
restart_usb_driver(&USB_DRIVER);
}
/* Woken up */
// variables has been already cleared by the wakeup hook
send_keyboard_report();
}
/* Woken up */
// variables has been already cleared by the wakeup hook
send_keyboard_report();
# ifdef MOUSEKEY_ENABLE
mousekey_send();
mousekey_send();
# endif /* MOUSEKEY_ENABLE */
# ifdef VISUALIZER_ENABLE
visualizer_resume();
visualizer_resume();
# endif
}
}
#endif
keyboard_task();
keyboard_task();
#ifdef CONSOLE_ENABLE
console_task();
console_task();
#endif
#ifdef MIDI_ENABLE
midi_ep_task();
midi_ep_task();
#endif
#ifdef VIRTSER_ENABLE
virtser_task();
virtser_task();
#endif
#ifdef RAW_ENABLE
raw_hid_task();
raw_hid_task();
#endif
#ifdef WEBUSB_ENABLE
webusb_task();
webusb_task();
#endif
// Run housekeeping
housekeeping_task();
}
}
+54 -19
View File
@@ -339,6 +339,9 @@ typedef struct {
#endif
#ifdef JOYSTICK_ENABLE
usb_driver_config_t joystick_driver;
#endif
#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
usb_driver_config_t digitizer_driver;
#endif
};
usb_driver_config_t array[0];
@@ -391,6 +394,14 @@ static usb_driver_configs_t drivers = {
# define JOYSTICK_OUT_MODE USB_EP_MODE_TYPE_BULK
.joystick_driver = QMK_USB_DRIVER_CONFIG(JOYSTICK, 0, false),
#endif
#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
# define DIGITIZER_IN_CAPACITY 4
# define DIGITIZER_OUT_CAPACITY 4
# define DIGITIZER_IN_MODE USB_EP_MODE_TYPE_BULK
# define DIGITIZER_OUT_MODE USB_EP_MODE_TYPE_BULK
.digitizer_driver = QMK_USB_DRIVER_CONFIG(DIGITIZER, 0, false),
#endif
};
#define NUM_USB_DRIVERS (sizeof(drivers) / sizeof(usb_driver_config_t))
@@ -446,14 +457,18 @@ static inline void usb_event_wakeup_handler(void) {
#endif /* SLEEP_LED_ENABLE */
}
bool last_suspend_state = false;
void usb_event_queue_task(void) {
usbevent_t event;
while (usb_event_queue_dequeue(&event)) {
switch (event) {
case USB_EVENT_SUSPEND:
last_suspend_state = true;
usb_event_suspend_handler();
break;
case USB_EVENT_WAKEUP:
last_suspend_state = false;
usb_event_wakeup_handler();
break;
default:
@@ -495,6 +510,9 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
qmkusbConfigureHookI(&drivers.array[i].driver);
}
osalSysUnlockFromISR();
if (last_suspend_state) {
usb_event_queue_enqueue(USB_EVENT_WAKEUP);
}
return;
case USB_EVENT_SUSPEND:
usb_event_queue_enqueue(USB_EVENT_SUSPEND);
@@ -549,7 +567,7 @@ static uint16_t get_hword(uint8_t *p) {
* Other Device Required Optional Optional Optional Optional Optional
*/
static uint8_t set_report_buf[2] __attribute__((aligned(2)));
static uint8_t set_report_buf[2] __attribute__((aligned(4)));
static void set_led_transfer_cb(USBDriver *usbp) {
if (usbp->setup[6] == 2) { /* LSB(wLength) */
uint8_t report_id = set_report_buf[0];
@@ -757,7 +775,7 @@ void init_usb_driver(USBDriver *usbp) {
chVTObjectInit(&keyboard_idle_timer);
}
void restart_usb_driver(USBDriver *usbp) {
__attribute__((weak)) void restart_usb_driver(USBDriver *usbp) {
usbStop(usbp);
usbDisconnectBus(usbp);
@@ -955,7 +973,8 @@ static void send_extra(uint8_t report_id, uint16_t data) {
return;
}
report_extra_t report = {.report_id = report_id, .usage = data};
static report_extra_t report;
report = (report_extra_t){.report_id = report_id, .usage = data};
usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report_extra_t));
osalSysUnlock();
@@ -974,6 +993,23 @@ void send_consumer(uint16_t data) {
#endif
}
void send_digitizer(report_digitizer_t *report) {
#ifdef DIGITIZER_ENABLE
# ifdef DIGITIZER_SHARED_EP
osalSysLock();
if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
osalSysUnlock();
return;
}
usbStartTransmitI(&USB_DRIVER, DIGITIZER_IN_EPNUM, (uint8_t *)report, sizeof(report_digitizer_t));
osalSysUnlock();
# else
chnWrite(&drivers.digitizer_driver.driver, (uint8_t *)report, sizeof(report_digitizer_t));
# endif
#endif
}
/* ---------------------------------------------------------
* Console functions
* ---------------------------------------------------------
@@ -1128,45 +1164,44 @@ void virtser_task(void) {
#ifdef JOYSTICK_ENABLE
void send_joystick_packet(joystick_t *joystick) {
joystick_report_t rep = {
static joystick_report_t rep;
rep = (joystick_report_t) {
# if JOYSTICK_AXES_COUNT > 0
.axes =
{
joystick->axes[0],
{ joystick->axes[0],
# if JOYSTICK_AXES_COUNT >= 2
joystick->axes[1],
joystick->axes[1],
# endif
# if JOYSTICK_AXES_COUNT >= 3
joystick->axes[2],
joystick->axes[2],
# endif
# if JOYSTICK_AXES_COUNT >= 4
joystick->axes[3],
joystick->axes[3],
# endif
# if JOYSTICK_AXES_COUNT >= 5
joystick->axes[4],
joystick->axes[4],
# endif
# if JOYSTICK_AXES_COUNT >= 6
joystick->axes[5],
joystick->axes[5],
# endif
},
},
# endif // JOYSTICK_AXES_COUNT>0
# if JOYSTICK_BUTTON_COUNT > 0
.buttons =
{
joystick->buttons[0],
.buttons = {
joystick->buttons[0],
# if JOYSTICK_BUTTON_COUNT > 8
joystick->buttons[1],
joystick->buttons[1],
# endif
# if JOYSTICK_BUTTON_COUNT > 16
joystick->buttons[2],
joystick->buttons[2],
# endif
# if JOYSTICK_BUTTON_COUNT > 24
joystick->buttons[3],
joystick->buttons[3],
# endif
}
}
# endif // JOYSTICK_BUTTON_COUNT>0
};
+1 -1
View File
@@ -16,6 +16,6 @@
#include <hal.h>
#include "usb_util.h"
void usb_disable(void) { usbStop(&USBD1); }
void usb_disconnect(void) { usbStop(&USBD1); }
bool usb_connected_state(void) { return usbGetDriverStateI(&USBD1) == USB_ACTIVE; }