]> begriffs open source - cmsis/blob - CMSIS/Driver/Include/Driver_USBD.h
Prepared frames for documenting RTOS RTX Configuration
[cmsis] / CMSIS / Driver / Include / Driver_USBD.h
1 /*
2  * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * $Date:        3. Jun 2014
19  * $Revision:    V2.01
20  *
21  * Project:      USB Device Driver definitions
22  */
23
24 /* History:
25  *  Version 2.01
26  *    Added ARM_USBD_ReadSetupPacket function
27  *  Version 2.00
28  *    Removed ARM_USBD_DeviceConfigure function
29  *    Removed ARM_USBD_SET_ADDRESS_STAGE parameter from ARM_USBD_DeviceSetAddress function
30  *    Removed ARM_USBD_EndpointReadStart function
31  *    Replaced ARM_USBD_EndpointRead and ARM_USBD_EndpointWrite functions with ARM_USBD_EndpointTransfer
32  *    Added ARM_USBD_EndpointTransferGetResult function
33  *    Renamed ARM_USBD_EndpointAbort function to ARM_USBD_EndpointTransferAbort
34  *    Changed prefix ARM_DRV -> ARM_DRIVER
35  *    Changed return values of some functions to int32_t
36  *  Version 1.10
37  *    Namespace prefix ARM_ added
38  *  Version 1.00
39  *    Initial release
40  */
41
42 #ifndef DRIVER_USBD_H_
43 #define DRIVER_USBD_H_
44
45 #include "Driver_USB.h"
46
47 #define ARM_USBD_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,01)  /* API version */
48
49
50 /**
51 \brief USB Device State
52 */
53 typedef struct _ARM_USBD_STATE {
54   uint32_t vbus   : 1;                  ///< USB Device VBUS flag
55   uint32_t speed  : 2;                  ///< USB Device speed setting (ARM_USB_SPEED_xxx)
56   uint32_t active : 1;                  ///< USB Device active flag
57 } ARM_USBD_STATE;
58
59
60 /****** USB Device Event *****/
61 #define ARM_USBD_EVENT_VBUS_ON          (1UL << 0)      ///< USB Device VBUS On
62 #define ARM_USBD_EVENT_VBUS_OFF         (1UL << 1)      ///< USB Device VBUS Off
63 #define ARM_USBD_EVENT_RESET            (1UL << 2)      ///< USB Reset occurred
64 #define ARM_USBD_EVENT_HIGH_SPEED       (1UL << 3)      ///< USB switch to High Speed occurred
65 #define ARM_USBD_EVENT_SUSPEND          (1UL << 4)      ///< USB Suspend occurred
66 #define ARM_USBD_EVENT_RESUME           (1UL << 5)      ///< USB Resume occurred
67
68 /****** USB Endpoint Event *****/
69 #define ARM_USBD_EVENT_SETUP            (1UL << 0)      ///< SETUP Packet
70 #define ARM_USBD_EVENT_OUT              (1UL << 1)      ///< OUT Packet(s)
71 #define ARM_USBD_EVENT_IN               (1UL << 2)      ///< IN Packet(s)
72
73
74 #ifndef __DOXYGEN_MW__                  // exclude from middleware documentation
75
76 // Function documentation
77 /**
78   \fn          ARM_DRIVER_VERSION ARM_USBD_GetVersion (void)
79   \brief       Get driver version.
80   \return      \ref ARM_DRIVER_VERSION
81 */
82 /**
83   \fn          ARM_USBD_CAPABILITIES ARM_USBD_GetCapabilities (void)
84   \brief       Get driver capabilities.
85   \return      \ref ARM_USBD_CAPABILITIES
86 */
87 /**
88   \fn          int32_t ARM_USBD_Initialize (ARM_USBD_SignalDeviceEvent_t   cb_device_event,
89                                             ARM_USBD_SignalEndpointEvent_t cb_endpoint_event)
90   \brief       Initialize USB Device Interface.
91   \param[in]   cb_device_event    Pointer to \ref ARM_USBD_SignalDeviceEvent
92   \param[in]   cb_endpoint_event  Pointer to \ref ARM_USBD_SignalEndpointEvent
93   \return      \ref execution_status
94 */
95 /**
96   \fn          int32_t ARM_USBD_Uninitialize (void)
97   \brief       De-initialize USB Device Interface.
98   \return      \ref execution_status
99 */
100 /**
101   \fn          int32_t ARM_USBD_PowerControl (ARM_POWER_STATE state)
102   \brief       Control USB Device Interface Power.
103   \param[in]   state  Power state
104   \return      \ref execution_status
105 */
106 /**
107   \fn          int32_t ARM_USBD_DeviceConnect (void)
108   \brief       Connect USB Device.
109   \return      \ref execution_status
110 */
111 /**
112   \fn          int32_t ARM_USBD_DeviceDisconnect (void)
113   \brief       Disconnect USB Device.
114   \return      \ref execution_status
115 */
116 /**
117   \fn          ARM_USBD_STATE ARM_USBD_DeviceGetState (void)
118   \brief       Get current USB Device State.
119   \return      Device State \ref ARM_USBD_STATE
120 */
121 /**
122   \fn          int32_t ARM_USBD_DeviceRemoteWakeup (void)
123   \brief       Trigger USB Remote Wakeup.
124   \return      \ref execution_status
125 */
126 /**
127   \fn          int32_t ARM_USBD_DeviceSetAddress (uint8_t dev_addr)
128   \brief       Set USB Device Address.
129   \param[in]   dev_addr  Device Address
130   \return      \ref execution_status
131 */
132 /**
133   \fn          int32_t ARM_USBD_ReadSetupPacket (uint8_t *setup)
134   \brief       Read setup packet received over Control Endpoint.
135   \param[out]  setup  Pointer to buffer for setup packet
136   \return      \ref execution_status
137 */
138 /**
139   \fn          int32_t ARM_USBD_EndpointConfigure (uint8_t  ep_addr,
140                                                    uint8_t  ep_type,
141                                                    uint16_t ep_max_packet_size)
142   \brief       Configure USB Endpoint.
143   \param[in]   ep_addr  Endpoint Address
144                 - ep_addr.0..3: Address
145                 - ep_addr.7:    Direction
146   \param[in]   ep_type  Endpoint Type (ARM_USB_ENDPOINT_xxx)
147   \param[in]   ep_max_packet_size Endpoint Maximum Packet Size
148   \return      \ref execution_status
149 */
150 /**
151   \fn          int32_t ARM_USBD_EndpointUnconfigure (uint8_t ep_addr)
152   \brief       Unconfigure USB Endpoint.
153   \param[in]   ep_addr  Endpoint Address
154                 - ep_addr.0..3: Address
155                 - ep_addr.7:    Direction
156   \return      \ref execution_status
157 */
158 /**
159   \fn          int32_t ARM_USBD_EndpointStall (uint8_t ep_addr, bool stall)
160   \brief       Set/Clear Stall for USB Endpoint.
161   \param[in]   ep_addr  Endpoint Address
162                 - ep_addr.0..3: Address
163                 - ep_addr.7:    Direction
164   \param[in]   stall  Operation
165                 - \b false Clear
166                 - \b true Set
167   \return      \ref execution_status
168 */
169 /**
170   \fn          int32_t ARM_USBD_EndpointTransfer (uint8_t ep_addr, uint8_t *data, uint32_t num)
171   \brief       Read data from or Write data to USB Endpoint.
172   \param[in]   ep_addr  Endpoint Address
173                 - ep_addr.0..3: Address
174                 - ep_addr.7:    Direction
175   \param[out]  data Pointer to buffer for data to read or with data to write
176   \param[in]   num  Number of data bytes to transfer
177   \return      \ref execution_status
178 */
179 /**
180   \fn          uint32_t ARM_USBD_EndpointTransferGetResult (uint8_t ep_addr)
181   \brief       Get result of USB Endpoint transfer.
182   \param[in]   ep_addr  Endpoint Address
183                 - ep_addr.0..3: Address
184                 - ep_addr.7:    Direction
185   \return      number of successfully transferred data bytes
186 */
187 /**
188   \fn          int32_t ARM_USBD_EndpointTransferAbort (uint8_t ep_addr)
189   \brief       Abort current USB Endpoint transfer.
190   \param[in]   ep_addr  Endpoint Address
191                 - ep_addr.0..3: Address
192                 - ep_addr.7:    Direction
193   \return      \ref execution_status
194 */
195 /**
196   \fn          uint16_t ARM_USBD_GetFrameNumber (void)
197   \brief       Get current USB Frame Number.
198   \return      Frame Number
199 */
200
201 /**
202   \fn          void ARM_USBD_SignalDeviceEvent (uint32_t event)
203   \brief       Signal USB Device Event.
204   \param[in]   event \ref USBD_dev_events
205   \return      none
206 */
207 /**
208   \fn          void ARM_USBD_SignalEndpointEvent (uint8_t ep_addr, uint32_t event)
209   \brief       Signal USB Endpoint Event.
210   \param[in]   ep_addr  Endpoint Address
211                 - ep_addr.0..3: Address
212                 - ep_addr.7:    Direction
213   \param[in]   event \ref USBD_ep_events
214   \return      none
215 */
216
217 typedef void (*ARM_USBD_SignalDeviceEvent_t)   (uint32_t event);                    ///< Pointer to \ref ARM_USBD_SignalDeviceEvent : Signal USB Device Event.
218 typedef void (*ARM_USBD_SignalEndpointEvent_t) (uint8_t ep_addr, uint32_t event);   ///< Pointer to \ref ARM_USBD_SignalEndpointEvent : Signal USB Endpoint Event.
219
220
221 /**
222 \brief USB Device Driver Capabilities.
223 */
224 typedef struct _ARM_USBD_CAPABILITIES {
225   uint32_t vbus_detection  : 1;         ///< VBUS detection
226   uint32_t event_vbus_on   : 1;         ///< Signal VBUS On event
227   uint32_t event_vbus_off  : 1;         ///< Signal VBUS Off event
228 } ARM_USBD_CAPABILITIES;
229
230
231 /**
232 \brief Access structure of the USB Device Driver.
233 */
234 typedef struct _ARM_DRIVER_USBD {
235   ARM_DRIVER_VERSION    (*GetVersion)                (void);                                              ///< Pointer to \ref ARM_USBD_GetVersion : Get driver version.
236   ARM_USBD_CAPABILITIES (*GetCapabilities)           (void);                                              ///< Pointer to \ref ARM_USBD_GetCapabilities : Get driver capabilities.
237   int32_t               (*Initialize)                (ARM_USBD_SignalDeviceEvent_t   cb_device_event,                     
238                                                       ARM_USBD_SignalEndpointEvent_t cb_endpoint_event);  ///< Pointer to \ref ARM_USBD_Initialize : Initialize USB Device Interface. 
239   int32_t               (*Uninitialize)              (void);                                              ///< Pointer to \ref ARM_USBD_Uninitialize : De-initialize USB Device Interface.
240   int32_t               (*PowerControl)              (ARM_POWER_STATE state);                             ///< Pointer to \ref ARM_USBD_PowerControl : Control USB Device Interface Power.
241   int32_t               (*DeviceConnect)             (void);                                              ///< Pointer to \ref ARM_USBD_DeviceConnect : Connect USB Device.
242   int32_t               (*DeviceDisconnect)          (void);                                              ///< Pointer to \ref ARM_USBD_DeviceDisconnect : Disconnect USB Device.
243   ARM_USBD_STATE        (*DeviceGetState)            (void);                                              ///< Pointer to \ref ARM_USBD_DeviceGetState : Get current USB Device State.
244   int32_t               (*DeviceRemoteWakeup)        (void);                                              ///< Pointer to \ref ARM_USBD_DeviceRemoteWakeup : Trigger USB Remote Wakeup.
245   int32_t               (*DeviceSetAddress)          (uint8_t dev_addr);                                  ///< Pointer to \ref ARM_USBD_DeviceSetAddress : Set USB Device Address.
246   int32_t               (*ReadSetupPacket)           (uint8_t *setup);                                    ///< Pointer to \ref ARM_USBD_ReadSetupPacket : Read setup packet received over Control Endpoint.
247   int32_t               (*EndpointConfigure)         (uint8_t ep_addr,
248                                                       uint8_t ep_type,
249                                                       uint16_t ep_max_packet_size);                       ///< Pointer to \ref ARM_USBD_EndpointConfigure : Configure USB Endpoint.
250   int32_t               (*EndpointUnconfigure)       (uint8_t ep_addr);                                   ///< Pointer to \ref ARM_USBD_EndpointUnconfigure : Unconfigure USB Endpoint.
251   int32_t               (*EndpointStall)             (uint8_t ep_addr, bool stall);                       ///< Pointer to \ref ARM_USBD_EndpointStall : Set/Clear Stall for USB Endpoint.
252   int32_t               (*EndpointTransfer)          (uint8_t ep_addr, uint8_t *data, uint32_t num);      ///< Pointer to \ref ARM_USBD_EndpointTransfer : Read data from or Write data to USB Endpoint.
253   uint32_t              (*EndpointTransferGetResult) (uint8_t ep_addr);                                   ///< Pointer to \ref ARM_USBD_EndpointTransferGetResult : Get result of USB Endpoint transfer.
254   int32_t               (*EndpointTransferAbort)     (uint8_t ep_addr);                                   ///< Pointer to \ref ARM_USBD_EndpointTransferAbort : Abort current USB Endpoint transfer.
255   uint16_t              (*GetFrameNumber)            (void);                                              ///< Pointer to \ref ARM_USBD_GetFrameNumber : Get current USB Frame Number.
256 } const ARM_DRIVER_USBD;
257
258 #endif /* __DOXYGEN_MW__ */
259
260 #endif /* DRIVER_USBD_H_ */