2 * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * Project: USB Device Driver definitions
26 * Added ARM_USBD_ReadSetupPacket function
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
37 * Namespace prefix ARM_ added
42 #ifndef DRIVER_USBD_H_
43 #define DRIVER_USBD_H_
50 #include "Driver_USB.h"
52 #define ARM_USBD_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,01) /* API version */
56 \brief USB Device State
58 typedef struct _ARM_USBD_STATE {
59 uint32_t vbus : 1; ///< USB Device VBUS flag
60 uint32_t speed : 2; ///< USB Device speed setting (ARM_USB_SPEED_xxx)
61 uint32_t active : 1; ///< USB Device active flag
65 /****** USB Device Event *****/
66 #define ARM_USBD_EVENT_VBUS_ON (1UL << 0) ///< USB Device VBUS On
67 #define ARM_USBD_EVENT_VBUS_OFF (1UL << 1) ///< USB Device VBUS Off
68 #define ARM_USBD_EVENT_RESET (1UL << 2) ///< USB Reset occurred
69 #define ARM_USBD_EVENT_HIGH_SPEED (1UL << 3) ///< USB switch to High Speed occurred
70 #define ARM_USBD_EVENT_SUSPEND (1UL << 4) ///< USB Suspend occurred
71 #define ARM_USBD_EVENT_RESUME (1UL << 5) ///< USB Resume occurred
73 /****** USB Endpoint Event *****/
74 #define ARM_USBD_EVENT_SETUP (1UL << 0) ///< SETUP Packet
75 #define ARM_USBD_EVENT_OUT (1UL << 1) ///< OUT Packet(s)
76 #define ARM_USBD_EVENT_IN (1UL << 2) ///< IN Packet(s)
79 #ifndef __DOXYGEN_MW__ // exclude from middleware documentation
81 // Function documentation
83 \fn ARM_DRIVER_VERSION ARM_USBD_GetVersion (void)
84 \brief Get driver version.
85 \return \ref ARM_DRIVER_VERSION
88 \fn ARM_USBD_CAPABILITIES ARM_USBD_GetCapabilities (void)
89 \brief Get driver capabilities.
90 \return \ref ARM_USBD_CAPABILITIES
93 \fn int32_t ARM_USBD_Initialize (ARM_USBD_SignalDeviceEvent_t cb_device_event,
94 ARM_USBD_SignalEndpointEvent_t cb_endpoint_event)
95 \brief Initialize USB Device Interface.
96 \param[in] cb_device_event Pointer to \ref ARM_USBD_SignalDeviceEvent
97 \param[in] cb_endpoint_event Pointer to \ref ARM_USBD_SignalEndpointEvent
98 \return \ref execution_status
101 \fn int32_t ARM_USBD_Uninitialize (void)
102 \brief De-initialize USB Device Interface.
103 \return \ref execution_status
106 \fn int32_t ARM_USBD_PowerControl (ARM_POWER_STATE state)
107 \brief Control USB Device Interface Power.
108 \param[in] state Power state
109 \return \ref execution_status
112 \fn int32_t ARM_USBD_DeviceConnect (void)
113 \brief Connect USB Device.
114 \return \ref execution_status
117 \fn int32_t ARM_USBD_DeviceDisconnect (void)
118 \brief Disconnect USB Device.
119 \return \ref execution_status
122 \fn ARM_USBD_STATE ARM_USBD_DeviceGetState (void)
123 \brief Get current USB Device State.
124 \return Device State \ref ARM_USBD_STATE
127 \fn int32_t ARM_USBD_DeviceRemoteWakeup (void)
128 \brief Trigger USB Remote Wakeup.
129 \return \ref execution_status
132 \fn int32_t ARM_USBD_DeviceSetAddress (uint8_t dev_addr)
133 \brief Set USB Device Address.
134 \param[in] dev_addr Device Address
135 \return \ref execution_status
138 \fn int32_t ARM_USBD_ReadSetupPacket (uint8_t *setup)
139 \brief Read setup packet received over Control Endpoint.
140 \param[out] setup Pointer to buffer for setup packet
141 \return \ref execution_status
144 \fn int32_t ARM_USBD_EndpointConfigure (uint8_t ep_addr,
146 uint16_t ep_max_packet_size)
147 \brief Configure USB Endpoint.
148 \param[in] ep_addr Endpoint Address
149 - ep_addr.0..3: Address
150 - ep_addr.7: Direction
151 \param[in] ep_type Endpoint Type (ARM_USB_ENDPOINT_xxx)
152 \param[in] ep_max_packet_size Endpoint Maximum Packet Size
153 \return \ref execution_status
156 \fn int32_t ARM_USBD_EndpointUnconfigure (uint8_t ep_addr)
157 \brief Unconfigure USB Endpoint.
158 \param[in] ep_addr Endpoint Address
159 - ep_addr.0..3: Address
160 - ep_addr.7: Direction
161 \return \ref execution_status
164 \fn int32_t ARM_USBD_EndpointStall (uint8_t ep_addr, bool stall)
165 \brief Set/Clear Stall for USB Endpoint.
166 \param[in] ep_addr Endpoint Address
167 - ep_addr.0..3: Address
168 - ep_addr.7: Direction
169 \param[in] stall Operation
172 \return \ref execution_status
175 \fn int32_t ARM_USBD_EndpointTransfer (uint8_t ep_addr, uint8_t *data, uint32_t num)
176 \brief Read data from or Write data to USB Endpoint.
177 \param[in] ep_addr Endpoint Address
178 - ep_addr.0..3: Address
179 - ep_addr.7: Direction
180 \param[out] data Pointer to buffer for data to read or with data to write
181 \param[in] num Number of data bytes to transfer
182 \return \ref execution_status
185 \fn uint32_t ARM_USBD_EndpointTransferGetResult (uint8_t ep_addr)
186 \brief Get result of USB Endpoint transfer.
187 \param[in] ep_addr Endpoint Address
188 - ep_addr.0..3: Address
189 - ep_addr.7: Direction
190 \return number of successfully transferred data bytes
193 \fn int32_t ARM_USBD_EndpointTransferAbort (uint8_t ep_addr)
194 \brief Abort current USB Endpoint transfer.
195 \param[in] ep_addr Endpoint Address
196 - ep_addr.0..3: Address
197 - ep_addr.7: Direction
198 \return \ref execution_status
201 \fn uint16_t ARM_USBD_GetFrameNumber (void)
202 \brief Get current USB Frame Number.
207 \fn void ARM_USBD_SignalDeviceEvent (uint32_t event)
208 \brief Signal USB Device Event.
209 \param[in] event \ref USBD_dev_events
213 \fn void ARM_USBD_SignalEndpointEvent (uint8_t ep_addr, uint32_t event)
214 \brief Signal USB Endpoint Event.
215 \param[in] ep_addr Endpoint Address
216 - ep_addr.0..3: Address
217 - ep_addr.7: Direction
218 \param[in] event \ref USBD_ep_events
222 typedef void (*ARM_USBD_SignalDeviceEvent_t) (uint32_t event); ///< Pointer to \ref ARM_USBD_SignalDeviceEvent : Signal USB Device Event.
223 typedef void (*ARM_USBD_SignalEndpointEvent_t) (uint8_t ep_addr, uint32_t event); ///< Pointer to \ref ARM_USBD_SignalEndpointEvent : Signal USB Endpoint Event.
227 \brief USB Device Driver Capabilities.
229 typedef struct _ARM_USBD_CAPABILITIES {
230 uint32_t vbus_detection : 1; ///< VBUS detection
231 uint32_t event_vbus_on : 1; ///< Signal VBUS On event
232 uint32_t event_vbus_off : 1; ///< Signal VBUS Off event
233 } ARM_USBD_CAPABILITIES;
237 \brief Access structure of the USB Device Driver.
239 typedef struct _ARM_DRIVER_USBD {
240 ARM_DRIVER_VERSION (*GetVersion) (void); ///< Pointer to \ref ARM_USBD_GetVersion : Get driver version.
241 ARM_USBD_CAPABILITIES (*GetCapabilities) (void); ///< Pointer to \ref ARM_USBD_GetCapabilities : Get driver capabilities.
242 int32_t (*Initialize) (ARM_USBD_SignalDeviceEvent_t cb_device_event,
243 ARM_USBD_SignalEndpointEvent_t cb_endpoint_event); ///< Pointer to \ref ARM_USBD_Initialize : Initialize USB Device Interface.
244 int32_t (*Uninitialize) (void); ///< Pointer to \ref ARM_USBD_Uninitialize : De-initialize USB Device Interface.
245 int32_t (*PowerControl) (ARM_POWER_STATE state); ///< Pointer to \ref ARM_USBD_PowerControl : Control USB Device Interface Power.
246 int32_t (*DeviceConnect) (void); ///< Pointer to \ref ARM_USBD_DeviceConnect : Connect USB Device.
247 int32_t (*DeviceDisconnect) (void); ///< Pointer to \ref ARM_USBD_DeviceDisconnect : Disconnect USB Device.
248 ARM_USBD_STATE (*DeviceGetState) (void); ///< Pointer to \ref ARM_USBD_DeviceGetState : Get current USB Device State.
249 int32_t (*DeviceRemoteWakeup) (void); ///< Pointer to \ref ARM_USBD_DeviceRemoteWakeup : Trigger USB Remote Wakeup.
250 int32_t (*DeviceSetAddress) (uint8_t dev_addr); ///< Pointer to \ref ARM_USBD_DeviceSetAddress : Set USB Device Address.
251 int32_t (*ReadSetupPacket) (uint8_t *setup); ///< Pointer to \ref ARM_USBD_ReadSetupPacket : Read setup packet received over Control Endpoint.
252 int32_t (*EndpointConfigure) (uint8_t ep_addr,
254 uint16_t ep_max_packet_size); ///< Pointer to \ref ARM_USBD_EndpointConfigure : Configure USB Endpoint.
255 int32_t (*EndpointUnconfigure) (uint8_t ep_addr); ///< Pointer to \ref ARM_USBD_EndpointUnconfigure : Unconfigure USB Endpoint.
256 int32_t (*EndpointStall) (uint8_t ep_addr, bool stall); ///< Pointer to \ref ARM_USBD_EndpointStall : Set/Clear Stall for USB Endpoint.
257 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.
258 uint32_t (*EndpointTransferGetResult) (uint8_t ep_addr); ///< Pointer to \ref ARM_USBD_EndpointTransferGetResult : Get result of USB Endpoint transfer.
259 int32_t (*EndpointTransferAbort) (uint8_t ep_addr); ///< Pointer to \ref ARM_USBD_EndpointTransferAbort : Abort current USB Endpoint transfer.
260 uint16_t (*GetFrameNumber) (void); ///< Pointer to \ref ARM_USBD_GetFrameNumber : Get current USB Frame Number.
261 } const ARM_DRIVER_USBD;
263 #endif /* __DOXYGEN_MW__ */
269 #endif /* DRIVER_USBD_H_ */