2 ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
19 * @brief Usb driver suitable for both packet and serial formats
21 * @addtogroup SERIAL_USB
28 #include "hal_usb_cdc.h"
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
34 /*===========================================================================*/
35 /* Derived constants and error checks. */
36 /*===========================================================================*/
38 #if HAL_USE_USB == FALSE
39 #error "The USB Driver requires HAL_USE_USB"
42 /*===========================================================================*/
43 /* Driver data structures and types. */
44 /*===========================================================================*/
47 * @brief Driver state machine possible states.
50 QMKUSB_UNINIT = 0, /**< Not initialized. */
51 QMKUSB_STOP = 1, /**< Stopped. */
52 QMKUSB_READY = 2 /**< Ready. */
56 * @brief Structure representing a serial over USB driver.
58 typedef struct QMKUSBDriver QMKUSBDriver;
61 * @brief Serial over USB Driver configuration structure.
62 * @details An instance of this structure must be passed to @p sduStart()
63 * in order to configure and start the driver operations.
67 * @brief USB driver to use.
71 * @brief Bulk IN endpoint used for outgoing data transfer.
75 * @brief Bulk OUT endpoint used for incoming data transfer.
79 * @brief Interrupt IN endpoint used for notifications.
80 * @note If set to zero then the INT endpoint is assumed to be not
81 * present, USB descriptors must be changed accordingly.
86 * @brief The number of buffers in the queues
92 * @brief The size of each buffer in the queue, typically the same as the endpoint size
98 * @brief Always send full buffers in_size (the rest is filled with zeroes)
103 * @note needs to be initialized with a memory buffer of the right size
107 * @note needs to be initialized with a memory buffer of the right size
113 * @brief @p SerialDriver specific data.
115 #define _qmk_usb_driver_data \
116 _base_asynchronous_channel_data \
118 qmkusbstate_t state; \
119 /* Input buffers queue.*/ \
120 input_buffers_queue_t ibqueue; \
122 output_buffers_queue_t obqueue; \
123 /* End of the mandatory fields.*/ \
124 /* Current configuration data.*/ \
125 const QMKUSBConfig *config;
128 * @brief @p SerialUSBDriver specific methods.
130 #define _qmk_usb_driver_methods \
131 _base_asynchronous_channel_methods
134 * @extends BaseAsynchronousChannelVMT
136 * @brief @p SerialDriver virtual methods table.
138 struct QMKUSBDriverVMT {
139 _qmk_usb_driver_methods
143 * @extends BaseAsynchronousChannel
145 * @brief Full duplex serial driver class.
146 * @details This class extends @p BaseAsynchronousChannel by adding physical
149 struct QMKUSBDriver {
150 /** @brief Virtual Methods Table.*/
151 const struct QMKUSBDriverVMT *vmt;
155 /*===========================================================================*/
157 /*===========================================================================*/
159 /*===========================================================================*/
160 /* External declarations. */
161 /*===========================================================================*/
166 void qmkusbInit(void);
167 void qmkusbObjectInit(QMKUSBDriver *qmkusbp, const QMKUSBConfig * config);
168 void qmkusbStart(QMKUSBDriver *qmkusbp, const QMKUSBConfig *config);
169 void qmkusbStop(QMKUSBDriver *qmkusbp);
170 void qmkusbSuspendHookI(QMKUSBDriver *qmkusbp);
171 void qmkusbWakeupHookI(QMKUSBDriver *qmkusbp);
172 void qmkusbConfigureHookI(QMKUSBDriver *qmkusbp);
173 bool qmkusbRequestsHook(USBDriver *usbp);
174 void qmkusbSOFHookI(QMKUSBDriver *qmkusbp);
175 void qmkusbDataTransmitted(USBDriver *usbp, usbep_t ep);
176 void qmkusbDataReceived(USBDriver *usbp, usbep_t ep);
177 void qmkusbInterruptTransmitted(USBDriver *usbp, usbep_t ep);
182 #endif /* USB_DRIVER_H */