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>
This commit is contained in:
parent
707d449ba0
commit
80c2e26741
1 changed files with 69 additions and 55 deletions
|
@ -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,44 +174,48 @@ typedef struct {
|
||||||
QMKUSBDriver driver;
|
QMKUSBDriver driver;
|
||||||
} usb_driver_config_t;
|
} usb_driver_config_t;
|
||||||
|
|
||||||
|
/* Reusable initialization structure - see USBEndpointConfig comment at top of file */
|
||||||
#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
|
#define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize) \
|
||||||
{ \
|
{ \
|
||||||
.queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \
|
.queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY, \
|
||||||
.in_ep_config = {.ep_mode = stream##_IN_MODE, \
|
.in_ep_config = \
|
||||||
.setup_cb = NULL, \
|
{ \
|
||||||
.in_cb = qmkusbDataTransmitted, \
|
stream##_IN_MODE, /* Interrupt EP */ \
|
||||||
.out_cb = NULL, \
|
NULL, /* SETUP packet notification callback */ \
|
||||||
.in_maxsize = stream##_EPSIZE, \
|
qmkusbDataTransmitted, /* IN notification callback */ \
|
||||||
.out_maxsize = 0, /* The pointer to the states will be filled during initialization */ \
|
NULL, /* OUT notification callback */ \
|
||||||
.in_state = NULL, \
|
stream##_EPSIZE, /* IN maximum packet size */ \
|
||||||
.out_state = NULL, \
|
0, /* OUT maximum packet size */ \
|
||||||
.ep_buffers = 2, \
|
NULL, /* IN Endpoint state */ \
|
||||||
.setup_buf = NULL}, \
|
NULL, /* OUT endpoint state */ \
|
||||||
|
2, /* IN multiplier */ \
|
||||||
|
NULL /* SETUP buffer (not a SETUP endpoint) */ \
|
||||||
|
}, \
|
||||||
.out_ep_config = \
|
.out_ep_config = \
|
||||||
{ \
|
{ \
|
||||||
.ep_mode = stream##_OUT_MODE, \
|
stream##_OUT_MODE, /* Interrupt EP */ \
|
||||||
.setup_cb = NULL, \
|
NULL, /* SETUP packet notification callback */ \
|
||||||
.in_cb = NULL, \
|
NULL, /* IN notification callback */ \
|
||||||
.out_cb = qmkusbDataReceived, \
|
qmkusbDataReceived, /* OUT notification callback */ \
|
||||||
.in_maxsize = 0, \
|
0, /* IN maximum packet size */ \
|
||||||
.out_maxsize = stream##_EPSIZE, /* The pointer to the states will be filled during initialization */ \
|
stream##_EPSIZE, /* OUT maximum packet size */ \
|
||||||
.in_state = NULL, \
|
NULL, /* IN Endpoint state */ \
|
||||||
.out_state = NULL, \
|
NULL, /* OUT endpoint state */ \
|
||||||
.ep_buffers = 2, \
|
2, /* IN multiplier */ \
|
||||||
.setup_buf = NULL, \
|
NULL, /* SETUP buffer (not a SETUP endpoint) */ \
|
||||||
}, \
|
}, \
|
||||||
.int_ep_config = \
|
.int_ep_config = \
|
||||||
{ \
|
{ \
|
||||||
.ep_mode = USB_EP_MODE_TYPE_INTR, \
|
USB_EP_MODE_TYPE_INTR, /* Interrupt EP */ \
|
||||||
.setup_cb = NULL, \
|
NULL, /* SETUP packet notification callback */ \
|
||||||
.in_cb = qmkusbInterruptTransmitted, \
|
qmkusbInterruptTransmitted, /* IN notification callback */ \
|
||||||
.out_cb = NULL, \
|
NULL, /* OUT notification callback */ \
|
||||||
.in_maxsize = CDC_NOTIFICATION_EPSIZE, \
|
CDC_NOTIFICATION_EPSIZE, /* IN maximum packet size */ \
|
||||||
.out_maxsize = 0, /* The pointer to the states will be filled during initialization */ \
|
0, /* OUT maximum packet size */ \
|
||||||
.in_state = NULL, \
|
NULL, /* IN Endpoint state */ \
|
||||||
.out_state = NULL, \
|
NULL, /* OUT endpoint state */ \
|
||||||
.ep_buffers = 2, \
|
2, /* IN multiplier */ \
|
||||||
.setup_buf = NULL, \
|
NULL, /* SETUP buffer (not a SETUP endpoint) */ \
|
||||||
}, \
|
}, \
|
||||||
.config = { \
|
.config = { \
|
||||||
.usbp = &USB_DRIVER, \
|
.usbp = &USB_DRIVER, \
|
||||||
|
|
Loading…
Reference in a new issue