merge from master
This commit is contained in:
		
						commit
						3996250d81
					
				
					 11279 changed files with 499671 additions and 99678 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
#include "progmem.h"
 | 
			
		||||
#include "stddef.h"
 | 
			
		||||
#include "inttypes.h"
 | 
			
		||||
#include <stddef.h>
 | 
			
		||||
#include <inttypes.h>
 | 
			
		||||
 | 
			
		||||
#define ATTR_PACKED __attribute__((packed))
 | 
			
		||||
/** Concatenates the given input into a single token, via the C Preprocessor.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,8 +15,8 @@
 | 
			
		|||
 * GPL v2 or later.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "ch.h"
 | 
			
		||||
#include "hal.h"
 | 
			
		||||
#include <ch.h>
 | 
			
		||||
#include <hal.h>
 | 
			
		||||
 | 
			
		||||
#include "usb_main.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -31,10 +31,11 @@
 | 
			
		|||
#include "led.h"
 | 
			
		||||
#include "sendchar.h"
 | 
			
		||||
#include "debug.h"
 | 
			
		||||
#include "printf.h"
 | 
			
		||||
#include "print.h"
 | 
			
		||||
 | 
			
		||||
#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
 | 
			
		||||
// Change this to be TRUE once we've migrated keyboards to the new init system
 | 
			
		||||
// Remember to change docs/platformdev_chibios_earlyinit.md as well.
 | 
			
		||||
#    define EARLY_INIT_PERFORM_BOOTLOADER_JUMP FALSE
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -53,6 +54,9 @@
 | 
			
		|||
#ifdef STM32_EEPROM_ENABLE
 | 
			
		||||
#    include "eeprom_stm32.h"
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef EEPROM_DRIVER
 | 
			
		||||
#    include "eeprom_driver.h"
 | 
			
		||||
#endif
 | 
			
		||||
#include "suspend.h"
 | 
			
		||||
#include "wait.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -154,6 +158,9 @@ int main(void) {
 | 
			
		|||
#ifdef STM32_EEPROM_ENABLE
 | 
			
		||||
    EEPROM_Init();
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef EEPROM_DRIVER
 | 
			
		||||
    eeprom_driver_init();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    // TESTING
 | 
			
		||||
    // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
 | 
			
		||||
| 
						 | 
				
			
			@ -163,9 +170,6 @@ int main(void) {
 | 
			
		|||
    /* Init USB */
 | 
			
		||||
    init_usb_driver(&USB_DRIVER);
 | 
			
		||||
 | 
			
		||||
    /* init printf */
 | 
			
		||||
    init_printf(NULL, sendchar_pf);
 | 
			
		||||
 | 
			
		||||
#ifdef MIDI_ENABLE
 | 
			
		||||
    setup_midi();
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -237,6 +241,7 @@ int main(void) {
 | 
			
		|||
                /* Remote wakeup */
 | 
			
		||||
                if (suspend_wakeup_condition()) {
 | 
			
		||||
                    usbWakeupHost(&USB_DRIVER);
 | 
			
		||||
                    restart_usb_driver(&USB_DRIVER);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            /* Woken up */
 | 
			
		||||
| 
						 | 
				
			
			@ -268,5 +273,9 @@ int main(void) {
 | 
			
		|||
#ifdef RAW_ENABLE
 | 
			
		||||
        raw_hid_task();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        // Run housekeeping
 | 
			
		||||
        housekeeping_task_kb();
 | 
			
		||||
        housekeeping_task_user();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,7 +22,7 @@
 | 
			
		|||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "hal.h"
 | 
			
		||||
#include <hal.h>
 | 
			
		||||
#include "usb_driver.h"
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,10 +22,9 @@
 | 
			
		|||
 * @{
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef USB_DRIVER_H
 | 
			
		||||
#    define USB_DRIVER_H
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#    include "hal_usb_cdc.h"
 | 
			
		||||
#include <hal_usb_cdc.h>
 | 
			
		||||
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
/* Driver constants.                                                         */
 | 
			
		||||
| 
						 | 
				
			
			@ -35,9 +34,9 @@
 | 
			
		|||
/* Derived constants and error checks.                                       */
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
 | 
			
		||||
#    if HAL_USE_USB == FALSE
 | 
			
		||||
#        error "The USB Driver requires HAL_USE_USB"
 | 
			
		||||
#    endif
 | 
			
		||||
#if HAL_USE_USB == FALSE
 | 
			
		||||
#    error "The USB Driver requires HAL_USE_USB"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
/* Driver data structures and types.                                         */
 | 
			
		||||
| 
						 | 
				
			
			@ -112,21 +111,21 @@ typedef struct {
 | 
			
		|||
/**
 | 
			
		||||
 * @brief   @p SerialDriver specific data.
 | 
			
		||||
 */
 | 
			
		||||
#    define _qmk_usb_driver_data                           \
 | 
			
		||||
        _base_asynchronous_channel_data /* Driver state.*/ \
 | 
			
		||||
            qmkusbstate_t state;                           \
 | 
			
		||||
        /* Input buffers queue.*/                          \
 | 
			
		||||
        input_buffers_queue_t ibqueue;                     \
 | 
			
		||||
        /* Output queue.*/                                 \
 | 
			
		||||
        output_buffers_queue_t obqueue;                    \
 | 
			
		||||
        /* End of the mandatory fields.*/                  \
 | 
			
		||||
        /* Current configuration data.*/                   \
 | 
			
		||||
        const QMKUSBConfig *config;
 | 
			
		||||
#define _qmk_usb_driver_data                           \
 | 
			
		||||
    _base_asynchronous_channel_data /* Driver state.*/ \
 | 
			
		||||
        qmkusbstate_t state;                           \
 | 
			
		||||
    /* Input buffers queue.*/                          \
 | 
			
		||||
    input_buffers_queue_t ibqueue;                     \
 | 
			
		||||
    /* Output queue.*/                                 \
 | 
			
		||||
    output_buffers_queue_t obqueue;                    \
 | 
			
		||||
    /* End of the mandatory fields.*/                  \
 | 
			
		||||
    /* Current configuration data.*/                   \
 | 
			
		||||
    const QMKUSBConfig *config;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief   @p SerialUSBDriver specific methods.
 | 
			
		||||
 */
 | 
			
		||||
#    define _qmk_usb_driver_methods _base_asynchronous_channel_methods
 | 
			
		||||
#define _qmk_usb_driver_methods _base_asynchronous_channel_methods
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @extends BaseAsynchronousChannelVMT
 | 
			
		||||
| 
						 | 
				
			
			@ -158,9 +157,9 @@ struct QMKUSBDriver {
 | 
			
		|||
/* External declarations.                                                    */
 | 
			
		||||
/*===========================================================================*/
 | 
			
		||||
 | 
			
		||||
#    ifdef __cplusplus
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#    endif
 | 
			
		||||
#endif
 | 
			
		||||
void qmkusbInit(void);
 | 
			
		||||
void qmkusbObjectInit(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config);
 | 
			
		||||
void qmkusbStart(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config);
 | 
			
		||||
| 
						 | 
				
			
			@ -173,10 +172,8 @@ void qmkusbSOFHookI(QMKUSBDriver *qmkusbp);
 | 
			
		|||
void qmkusbDataTransmitted(USBDriver *usbp, usbep_t ep);
 | 
			
		||||
void qmkusbDataReceived(USBDriver *usbp, usbep_t ep);
 | 
			
		||||
void qmkusbInterruptTransmitted(USBDriver *usbp, usbep_t ep);
 | 
			
		||||
#    ifdef __cplusplus
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#    endif
 | 
			
		||||
 | 
			
		||||
#endif /* USB_DRIVER_H */
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,8 +25,8 @@
 | 
			
		|||
 *   makes the assumption this is safe to avoid littering with preprocessor directives.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "ch.h"
 | 
			
		||||
#include "hal.h"
 | 
			
		||||
#include <ch.h>
 | 
			
		||||
#include <hal.h>
 | 
			
		||||
 | 
			
		||||
#include "usb_main.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -70,7 +70,7 @@ extern keymap_config_t keymap_config;
 | 
			
		|||
 | 
			
		||||
uint8_t                keyboard_idle __attribute__((aligned(2)))     = 0;
 | 
			
		||||
uint8_t                keyboard_protocol __attribute__((aligned(2))) = 1;
 | 
			
		||||
uint8_t                keyboard_led_stats                            = 0;
 | 
			
		||||
uint8_t                keyboard_led_state                            = 0;
 | 
			
		||||
volatile uint16_t      keyboard_idle_count                           = 0;
 | 
			
		||||
static virtual_timer_t keyboard_idle_timer;
 | 
			
		||||
static void            keyboard_idle_timer_cb(void *arg);
 | 
			
		||||
| 
						 | 
				
			
			@ -169,6 +169,19 @@ static const USBEndpointConfig shared_ep_config = {
 | 
			
		|||
};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if STM32_USB_USE_OTG1
 | 
			
		||||
typedef struct {
 | 
			
		||||
    size_t              queue_capacity_in;
 | 
			
		||||
    size_t              queue_capacity_out;
 | 
			
		||||
    USBInEndpointState  in_ep_state;
 | 
			
		||||
    USBOutEndpointState out_ep_state;
 | 
			
		||||
    USBInEndpointState  int_ep_state;
 | 
			
		||||
    USBEndpointConfig   inout_ep_config;
 | 
			
		||||
    USBEndpointConfig   int_ep_config;
 | 
			
		||||
    const QMKUSBConfig  config;
 | 
			
		||||
    QMKUSBDriver        driver;
 | 
			
		||||
} usb_driver_config_t;
 | 
			
		||||
#else
 | 
			
		||||
typedef struct {
 | 
			
		||||
    size_t              queue_capacity_in;
 | 
			
		||||
    size_t              queue_capacity_out;
 | 
			
		||||
| 
						 | 
				
			
			@ -181,64 +194,112 @@ typedef struct {
 | 
			
		|||
    const QMKUSBConfig  config;
 | 
			
		||||
    QMKUSBDriver        driver;
 | 
			
		||||
} usb_driver_config_t;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if STM32_USB_USE_OTG1
 | 
			
		||||
/* 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          = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){},  \
 | 
			
		||||
            .ob          = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
 | 
			
		||||
        }                                                                                                                   \
 | 
			
		||||
    }
 | 
			
		||||
#    define QMK_USB_DRIVER_CONFIG(stream, notification, fixedsize)                                                              \
 | 
			
		||||
        {                                                                                                                       \
 | 
			
		||||
            .queue_capacity_in = stream##_IN_CAPACITY, .queue_capacity_out = stream##_OUT_CAPACITY,                             \
 | 
			
		||||
            .inout_ep_config =                                                                                                  \
 | 
			
		||||
                {                                                                                                               \
 | 
			
		||||
                    stream##_IN_MODE,      /* Interrupt EP */                                                                   \
 | 
			
		||||
                    NULL,                  /* SETUP packet notification callback */                                             \
 | 
			
		||||
                    qmkusbDataTransmitted, /* IN notification callback */                                                       \
 | 
			
		||||
                    qmkusbDataReceived,    /* OUT notification callback */                                                      \
 | 
			
		||||
                    stream##_EPSIZE,       /* 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          = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){},  \
 | 
			
		||||
                .ob          = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
 | 
			
		||||
            }                                                                                                                   \
 | 
			
		||||
        }
 | 
			
		||||
#else
 | 
			
		||||
/* 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          = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_IN_CAPACITY, stream##_EPSIZE)]){},  \
 | 
			
		||||
                .ob          = (__attribute__((aligned(4))) uint8_t[BQ_BUFFER_SIZE(stream##_OUT_CAPACITY, stream##_EPSIZE)]){}, \
 | 
			
		||||
            }                                                                                                                   \
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    union {
 | 
			
		||||
| 
						 | 
				
			
			@ -342,8 +403,12 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
 | 
			
		|||
            usbInitEndpointI(usbp, SHARED_IN_EPNUM, &shared_ep_config);
 | 
			
		||||
#endif
 | 
			
		||||
            for (int i = 0; i < NUM_USB_DRIVERS; i++) {
 | 
			
		||||
#if STM32_USB_USE_OTG1
 | 
			
		||||
                usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].inout_ep_config);
 | 
			
		||||
#else
 | 
			
		||||
                usbInitEndpointI(usbp, drivers.array[i].config.bulk_in, &drivers.array[i].in_ep_config);
 | 
			
		||||
                usbInitEndpointI(usbp, drivers.array[i].config.bulk_out, &drivers.array[i].out_ep_config);
 | 
			
		||||
#endif
 | 
			
		||||
                if (drivers.array[i].config.int_in) {
 | 
			
		||||
                    usbInitEndpointI(usbp, drivers.array[i].config.int_in, &drivers.array[i].int_ep_config);
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			@ -416,10 +481,10 @@ static void    set_led_transfer_cb(USBDriver *usbp) {
 | 
			
		|||
    if (usbp->setup[6] == 2) { /* LSB(wLength) */
 | 
			
		||||
        uint8_t report_id = set_report_buf[0];
 | 
			
		||||
        if ((report_id == REPORT_ID_KEYBOARD) || (report_id == REPORT_ID_NKRO)) {
 | 
			
		||||
            keyboard_led_stats = set_report_buf[1];
 | 
			
		||||
            keyboard_led_state = set_report_buf[1];
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        keyboard_led_stats = set_report_buf[0];
 | 
			
		||||
        keyboard_led_state = set_report_buf[0];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -571,12 +636,21 @@ static const USBConfig usbcfg = {
 | 
			
		|||
 */
 | 
			
		||||
void init_usb_driver(USBDriver *usbp) {
 | 
			
		||||
    for (int i = 0; i < NUM_USB_DRIVERS; i++) {
 | 
			
		||||
#if STM32_USB_USE_OTG1
 | 
			
		||||
        QMKUSBDriver *driver                       = &drivers.array[i].driver;
 | 
			
		||||
        drivers.array[i].inout_ep_config.in_state  = &drivers.array[i].in_ep_state;
 | 
			
		||||
        drivers.array[i].inout_ep_config.out_state = &drivers.array[i].out_ep_state;
 | 
			
		||||
        drivers.array[i].int_ep_config.in_state    = &drivers.array[i].int_ep_state;
 | 
			
		||||
        qmkusbObjectInit(driver, &drivers.array[i].config);
 | 
			
		||||
        qmkusbStart(driver, &drivers.array[i].config);
 | 
			
		||||
#else
 | 
			
		||||
        QMKUSBDriver *driver                     = &drivers.array[i].driver;
 | 
			
		||||
        drivers.array[i].in_ep_config.in_state   = &drivers.array[i].in_ep_state;
 | 
			
		||||
        drivers.array[i].out_ep_config.out_state = &drivers.array[i].out_ep_state;
 | 
			
		||||
        drivers.array[i].int_ep_config.in_state  = &drivers.array[i].int_ep_state;
 | 
			
		||||
        qmkusbObjectInit(driver, &drivers.array[i].config);
 | 
			
		||||
        qmkusbStart(driver, &drivers.array[i].config);
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
| 
						 | 
				
			
			@ -592,6 +666,13 @@ void init_usb_driver(USBDriver *usbp) {
 | 
			
		|||
    chVTObjectInit(&keyboard_idle_timer);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void restart_usb_driver(USBDriver *usbp) {
 | 
			
		||||
    usbStop(usbp);
 | 
			
		||||
    usbDisconnectBus(usbp);
 | 
			
		||||
    usbStart(usbp, &usbcfg);
 | 
			
		||||
    usbConnectBus(usbp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* ---------------------------------------------------------
 | 
			
		||||
 *                  Keyboard functions
 | 
			
		||||
 * ---------------------------------------------------------
 | 
			
		||||
| 
						 | 
				
			
			@ -645,7 +726,7 @@ static void keyboard_idle_timer_cb(void *arg) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/* LED status */
 | 
			
		||||
uint8_t keyboard_leds(void) { return keyboard_led_stats; }
 | 
			
		||||
uint8_t keyboard_leds(void) { return keyboard_led_state; }
 | 
			
		||||
 | 
			
		||||
/* prepare and start sending a report IN
 | 
			
		||||
 * not callable from ISR or locked state */
 | 
			
		||||
| 
						 | 
				
			
			@ -747,7 +828,7 @@ 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 */
 | 
			
		||||
 | 
			
		||||
/* ---------------------------------------------------------
 | 
			
		||||
| 
						 | 
				
			
			@ -833,10 +914,7 @@ int8_t sendchar(uint8_t c) {
 | 
			
		|||
}
 | 
			
		||||
#endif /* CONSOLE_ENABLE */
 | 
			
		||||
 | 
			
		||||
void sendchar_pf(void *p, char c) {
 | 
			
		||||
    (void)p;
 | 
			
		||||
    sendchar((uint8_t)c);
 | 
			
		||||
}
 | 
			
		||||
void _putchar(char character) { sendchar(character); }
 | 
			
		||||
 | 
			
		||||
#ifdef RAW_ENABLE
 | 
			
		||||
void raw_hid_send(uint8_t *data, uint8_t length) {
 | 
			
		||||
| 
						 | 
				
			
			@ -913,39 +991,43 @@ void virtser_task(void) {
 | 
			
		|||
void send_joystick_packet(joystick_t *joystick) {
 | 
			
		||||
    joystick_report_t rep = {
 | 
			
		||||
#    if JOYSTICK_AXES_COUNT > 0
 | 
			
		||||
        .axes = {joystick->axes[0],
 | 
			
		||||
        .axes =
 | 
			
		||||
            {
 | 
			
		||||
                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
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,14 +15,13 @@
 | 
			
		|||
 * GPL v2 or later.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef _USB_MAIN_H_
 | 
			
		||||
#define _USB_MAIN_H_
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
// TESTING
 | 
			
		||||
// extern uint8_t blinkLed;
 | 
			
		||||
 | 
			
		||||
#include "ch.h"
 | 
			
		||||
#include "hal.h"
 | 
			
		||||
#include <ch.h>
 | 
			
		||||
#include <hal.h>
 | 
			
		||||
 | 
			
		||||
/* -------------------------
 | 
			
		||||
 * General USB driver header
 | 
			
		||||
| 
						 | 
				
			
			@ -35,6 +34,9 @@
 | 
			
		|||
/* Initialize the USB driver and bus */
 | 
			
		||||
void init_usb_driver(USBDriver *usbp);
 | 
			
		||||
 | 
			
		||||
/* Restart the USB driver and bus */
 | 
			
		||||
void restart_usb_driver(USBDriver *usbp);
 | 
			
		||||
 | 
			
		||||
/* ---------------
 | 
			
		||||
 * Keyboard header
 | 
			
		||||
 * ---------------
 | 
			
		||||
| 
						 | 
				
			
			@ -86,7 +88,3 @@ int8_t sendchar(uint8_t c);
 | 
			
		|||
void console_flush_output(void);
 | 
			
		||||
 | 
			
		||||
#endif /* CONSOLE_ENABLE */
 | 
			
		||||
 | 
			
		||||
void sendchar_pf(void *p, char c);
 | 
			
		||||
 | 
			
		||||
#endif /* _USB_MAIN_H_ */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue