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>
master
Joel Challis 2019-12-14 01:29:54 +00:00 committed by GitHub
parent 707d449ba0
commit 80c2e26741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 69 additions and 55 deletions

View File

@ -15,6 +15,16 @@
* GPL v2 or later. * 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 "ch.h"
#include "hal.h" #include "hal.h"
@ -98,7 +108,7 @@ static const USBDescriptor *usb_get_descriptor_cb(USBDriver *usbp, uint8_t dtype
#ifndef KEYBOARD_SHARED_EP #ifndef KEYBOARD_SHARED_EP
/* keyboard endpoint state structure */ /* keyboard endpoint state structure */
static USBInEndpointState kbd_ep_state; 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 = { static const USBEndpointConfig kbd_ep_config = {
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
NULL, /* SETUP packet notification callback */ NULL, /* SETUP packet notification callback */
@ -117,7 +127,7 @@ static const USBEndpointConfig kbd_ep_config = {
/* mouse endpoint state structure */ /* mouse endpoint state structure */
static USBInEndpointState mouse_ep_state; 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 = { static const USBEndpointConfig mouse_ep_config = {
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
NULL, /* SETUP packet notification callback */ NULL, /* SETUP packet notification callback */
@ -136,7 +146,7 @@ static const USBEndpointConfig mouse_ep_config = {
/* shared endpoint state structure */ /* shared endpoint state structure */
static USBInEndpointState shared_ep_state; 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 = { static const USBEndpointConfig shared_ep_config = {
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
NULL, /* SETUP packet notification callback */ NULL, /* SETUP packet notification callback */
@ -164,58 +174,62 @@ typedef struct {
QMKUSBDriver driver; QMKUSBDriver driver;
} usb_driver_config_t; } usb_driver_config_t;
#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \ /* 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 = {.ep_mode = stream##_IN_MODE, \ .queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \
.setup_cb = NULL, \ .in_ep_config = \
.in_cb = qmkusbDataTransmitted, \ { \
.out_cb = NULL, \ stream##_IN_MODE, /* Interrupt EP */ \
.in_maxsize = stream##_EPSIZE, \ NULL, /* SETUP packet notification callback */ \
.out_maxsize = 0, /* The pointer to the states will be filled during initialization */ \ qmkusbDataTransmitted, /* IN notification callback */ \
.in_state = NULL, \ NULL, /* OUT notification callback */ \
.out_state = NULL, \ stream##_EPSIZE, /* IN maximum packet size */ \
.ep_buffers = 2, \ 0, /* OUT maximum packet size */ \
.setup_buf = NULL}, \ NULL, /* IN Endpoint state */ \
.out_ep_config = \ NULL, /* OUT endpoint state */ \
{ \ 2, /* IN multiplier */ \
.ep_mode = stream##_OUT_MODE, \ NULL /* SETUP buffer (not a SETUP endpoint) */ \
.setup_cb = NULL, \ }, \
.in_cb = NULL, \ .out_ep_config = \
.out_cb = qmkusbDataReceived, \ { \
.in_maxsize = 0, \ stream##_OUT_MODE, /* Interrupt EP */ \
.out_maxsize = stream##_EPSIZE, /* The pointer to the states will be filled during initialization */ \ NULL, /* SETUP packet notification callback */ \
.in_state = NULL, \ NULL, /* IN notification callback */ \
.out_state = NULL, \ qmkusbDataReceived, /* OUT notification callback */ \
.ep_buffers = 2, \ 0, /* IN maximum packet size */ \
.setup_buf = NULL, \ stream##_EPSIZE, /* OUT maximum packet size */ \
}, \ NULL, /* IN Endpoint state */ \
.int_ep_config = \ NULL, /* OUT endpoint state */ \
{ \ 2, /* IN multiplier */ \
.ep_mode = USB_EP_MODE_TYPE_INTR, \ NULL, /* SETUP buffer (not a SETUP endpoint) */ \
.setup_cb = NULL, \ }, \
.in_cb = qmkusbInterruptTransmitted, \ .int_ep_config = \
.out_cb = NULL, \ { \
.in_maxsize = CDC_NOTIFICATION_EPSIZE, \ USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ \
.out_maxsize = 0, /* The pointer to the states will be filled during initialization */ \ NULL, /* SETUP packet notification callback */ \
.in_state = NULL, \ qmkusbInterruptTransmitted, /* IN notification callback */ \
.out_state = NULL, \ NULL, /* OUT notification callback */ \
.ep_buffers = 2, \ CDC_NOTIFICATION_EPSIZE, /* IN maximum packet size */ \
.setup_buf = NULL, \ 0, /* OUT maximum packet size */ \
}, \ NULL, /* IN Endpoint state */ \
.config = { \ NULL, /* OUT endpoint state */ \
.usbp = &USB_DRIVER, \ 2, /* IN multiplier */ \
.bulk_in = stream##_IN_EPNUM, \ NULL, /* SETUP buffer (not a SETUP endpoint) */ \
.bulk_out = stream##_OUT_EPNUM, \ }, \
.int_in = notification, \ .config = { \
.in_buffers = stream##_IN_CAPACITY, \ .usbp = &USB_DRIVER, \
.out_buffers = stream##_OUT_CAPACITY, \ .bulk_in = stream##_IN_EPNUM, \
.in_size = stream##_EPSIZE, \ .bulk_out = stream##_OUT_EPNUM, \
.out_size = stream##_EPSIZE, \ .int_in = notification, \
.fixed_size = fixedsize, \ .in_buffers = stream##_IN_CAPACITY, \
.ib = (uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){}, \ .out_buffers = stream##_OUT_CAPACITY, \
.ob = (uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \ .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 { typedef struct {