summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/chibios
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2019-12-14 01:29:54 +0000
committerFlorian Didron <fdidron@users.noreply.github.com>2020-01-09 08:57:11 +0900
commit9c06f5a2e6f69211c52447eaeaabc80764ccbfee (patch)
treed300dc56392fcdf7e603a90081b89c88b629b812 /tmk_core/protocol/chibios
parent052e4ee4d2a0dfdaa31da97c5a9cc738df7785c6 (diff)
Fix ChibiOS USB config for chips which support OTGv1 (#7564)
* Align endpoint config as per rest of file (fixes #4783) * Add comments about explicit order use * Update tmk_core/protocol/chibios/usb_main.c Co-Authored-By: fauxpark <fauxpark@gmail.com>
Diffstat (limited to 'tmk_core/protocol/chibios')
-rw-r--r--tmk_core/protocol/chibios/usb_main.c124
1 files changed, 69 insertions, 55 deletions
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index b4ee55ce9f..57ac7ce0e0 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -15,6 +15,16 @@
* GPL v2 or later.
*/
+/*
+ * Implementation notes:
+ *
+ * USBEndpointConfig - Configured using explicit order instead of struct member name.
+ * This is due to ChibiOS hal LLD differences, which is dependent on hardware,
+ * "USBv1" devices have `ep_buffers` and "OTGv1" have `in_multiplier`.
+ * Given `USBv1/hal_usb_lld.h` marks the field as "not currently used" this code file
+ * makes the assumption this is safe to avoid littering with preprocessor directives.
+ */
+
#include "ch.h"
#include "hal.h"
@@ -101,7 +111,7 @@ static const USBDescriptor *usb_get_descriptor_cb(USBDriver *usbp, uint8_t dtype
#ifndef KEYBOARD_SHARED_EP
/* keyboard endpoint state structure */
static USBInEndpointState kbd_ep_state;
-/* keyboard endpoint initialization structure (IN) */
+/* keyboard endpoint initialization structure (IN) - see USBEndpointConfig comment at top of file */
static const USBEndpointConfig kbd_ep_config = {
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
NULL, /* SETUP packet notification callback */
@@ -120,7 +130,7 @@ static const USBEndpointConfig kbd_ep_config = {
/* mouse endpoint state structure */
static USBInEndpointState mouse_ep_state;
-/* mouse endpoint initialization structure (IN) */
+/* mouse endpoint initialization structure (IN) - see USBEndpointConfig comment at top of file */
static const USBEndpointConfig mouse_ep_config = {
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
NULL, /* SETUP packet notification callback */
@@ -139,7 +149,7 @@ static const USBEndpointConfig mouse_ep_config = {
/* shared endpoint state structure */
static USBInEndpointState shared_ep_state;
-/* shared endpoint initialization structure (IN) */
+/* shared endpoint initialization structure (IN) - see USBEndpointConfig comment at top of file */
static const USBEndpointConfig shared_ep_config = {
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
NULL, /* SETUP packet notification callback */
@@ -183,58 +193,62 @@ typedef struct {
QMKUSBDriver driver;
} usb_driver_config_t;
-#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
- { \
- .queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \
- .in_ep_config = {.ep_mode = stream##_IN_MODE, \
- .setup_cb = NULL, \
- .in_cb = qmkusbDataTransmitted, \
- .out_cb = NULL, \
- .in_maxsize = stream##_EPSIZE, \
- .out_maxsize = 0, /* The pointer to the states will be filled during initialization */ \
- .in_state = NULL, \
- .out_state = NULL, \
- .ep_buffers = 2, \
- .setup_buf = NULL}, \
- .out_ep_config = \
- { \
- .ep_mode = stream##_OUT_MODE, \
- .setup_cb = NULL, \
- .in_cb = NULL, \
- .out_cb = qmkusbDataReceived, \
- .in_maxsize = 0, \
- .out_maxsize = stream##_EPSIZE, /* The pointer to the states will be filled during initialization */ \
- .in_state = NULL, \
- .out_state = NULL, \
- .ep_buffers = 2, \
- .setup_buf = NULL, \
- }, \
- .int_ep_config = \
- { \
- .ep_mode = USB_EP_MODE_TYPE_INTR, \
- .setup_cb = NULL, \
- .in_cb = qmkusbInterruptTransmitted, \
- .out_cb = NULL, \
- .in_maxsize = CDC_NOTIFICATION_EPSIZE, \
- .out_maxsize = 0, /* The pointer to the states will be filled during initialization */ \
- .in_state = NULL, \
- .out_state = NULL, \
- .ep_buffers = 2, \
- .setup_buf = NULL, \
- }, \
- .config = { \
- .usbp = &USB_DRIVER, \
- .bulk_in = stream##_IN_EPNUM, \
- .bulk_out = stream##_OUT_EPNUM, \
- .int_in = notification, \
- .in_buffers = stream##_IN_CAPACITY, \
- .out_buffers = stream##_OUT_CAPACITY, \
- .in_size = stream##_EPSIZE, \
- .out_size = stream##_EPSIZE, \
- .fixed_size = fixedsize, \
- .ib = (uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){}, \
- .ob = (uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
- } \
+/* Reusable initialization structure - see USBEndpointConfig comment at top of file */
+#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
+ { \
+ .queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \
+ .in_ep_config = \
+ { \
+ stream##_IN_MODE, /* Interrupt EP */ \
+ NULL, /* SETUP packet notification callback */ \
+ qmkusbDataTransmitted, /* IN notification callback */ \
+ NULL, /* OUT notification callback */ \
+ stream##_EPSIZE, /* IN maximum packet size */ \
+ 0, /* OUT maximum packet size */ \
+ NULL, /* IN Endpoint state */ \
+ NULL, /* OUT endpoint state */ \
+ 2, /* IN multiplier */ \
+ NULL /* SETUP buffer (not a SETUP endpoint) */ \
+ }, \
+ .out_ep_config = \
+ { \
+ stream##_OUT_MODE, /* Interrupt EP */ \
+ NULL, /* SETUP packet notification callback */ \
+ NULL, /* IN notification callback */ \
+ qmkusbDataReceived, /* OUT notification callback */ \
+ 0, /* IN maximum packet size */ \
+ stream##_EPSIZE, /* OUT maximum packet size */ \
+ NULL, /* IN Endpoint state */ \
+ NULL, /* OUT endpoint state */ \
+ 2, /* IN multiplier */ \
+ NULL, /* SETUP buffer (not a SETUP endpoint) */ \
+ }, \
+ .int_ep_config = \
+ { \
+ USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ \
+ NULL, /* SETUP packet notification callback */ \
+ qmkusbInterruptTransmitted, /* IN notification callback */ \
+ NULL, /* OUT notification callback */ \
+ CDC_NOTIFICATION_EPSIZE, /* IN maximum packet size */ \
+ 0, /* OUT maximum packet size */ \
+ NULL, /* IN Endpoint state */ \
+ NULL, /* OUT endpoint state */ \
+ 2, /* IN multiplier */ \
+ NULL, /* SETUP buffer (not a SETUP endpoint) */ \
+ }, \
+ .config = { \
+ .usbp = &USB_DRIVER, \
+ .bulk_in = stream##_IN_EPNUM, \
+ .bulk_out = stream##_OUT_EPNUM, \
+ .int_in = notification, \
+ .in_buffers = stream##_IN_CAPACITY, \
+ .out_buffers = stream##_OUT_CAPACITY, \
+ .in_size = stream##_EPSIZE, \
+ .out_size = stream##_EPSIZE, \
+ .fixed_size = fixedsize, \
+ .ib = (uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){}, \
+ .ob = (uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
+ } \
}
typedef struct {