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