2 * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
\r
4 * SPDX-License-Identifier: Apache-2.0
\r
6 * Licensed under the Apache License, Version 2.0 (the License); you may
\r
7 * not use this file except in compliance with the License.
\r
8 * You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software
\r
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
\r
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 * See the License for the specific language governing permissions and
\r
16 * limitations under the License.
\r
18 * $Date: 3. Jun 2014
\r
21 * Project: USB Device Driver definitions
\r
26 * Added ARM_USBD_ReadSetupPacket function
\r
28 * Removed ARM_USBD_DeviceConfigure function
\r
29 * Removed ARM_USBD_SET_ADDRESS_STAGE parameter from ARM_USBD_DeviceSetAddress function
\r
30 * Removed ARM_USBD_EndpointReadStart function
\r
31 * Replaced ARM_USBD_EndpointRead and ARM_USBD_EndpointWrite functions with ARM_USBD_EndpointTransfer
\r
32 * Added ARM_USBD_EndpointTransferGetResult function
\r
33 * Renamed ARM_USBD_EndpointAbort function to ARM_USBD_EndpointTransferAbort
\r
34 * Changed prefix ARM_DRV -> ARM_DRIVER
\r
35 * Changed return values of some functions to int32_t
\r
37 * Namespace prefix ARM_ added
\r
42 #ifndef __DRIVER_USBD_H
\r
43 #define __DRIVER_USBD_H
\r
45 #include "Driver_USB.h"
\r
47 #define ARM_USBD_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,01) /* API version */
\r
51 \brief USB Device State
\r
53 typedef struct _ARM_USBD_STATE {
\r
54 uint32_t vbus : 1; ///< USB Device VBUS flag
\r
55 uint32_t speed : 2; ///< USB Device speed setting (ARM_USB_SPEED_xxx)
\r
56 uint32_t active : 1; ///< USB Device active flag
\r
60 /****** USB Device Event *****/
\r
61 #define ARM_USBD_EVENT_VBUS_ON (1UL << 0) ///< USB Device VBUS On
\r
62 #define ARM_USBD_EVENT_VBUS_OFF (1UL << 1) ///< USB Device VBUS Off
\r
63 #define ARM_USBD_EVENT_RESET (1UL << 2) ///< USB Reset occurred
\r
64 #define ARM_USBD_EVENT_HIGH_SPEED (1UL << 3) ///< USB switch to High Speed occurred
\r
65 #define ARM_USBD_EVENT_SUSPEND (1UL << 4) ///< USB Suspend occurred
\r
66 #define ARM_USBD_EVENT_RESUME (1UL << 5) ///< USB Resume occurred
\r
68 /****** USB Endpoint Event *****/
\r
69 #define ARM_USBD_EVENT_SETUP (1UL << 0) ///< SETUP Packet
\r
70 #define ARM_USBD_EVENT_OUT (1UL << 1) ///< OUT Packet(s)
\r
71 #define ARM_USBD_EVENT_IN (1UL << 2) ///< IN Packet(s)
\r
74 #ifndef __DOXYGEN_MW__ // exclude from middleware documentation
\r
76 // Function documentation
\r
78 \fn ARM_DRIVER_VERSION ARM_USBD_GetVersion (void)
\r
79 \brief Get driver version.
\r
80 \return \ref ARM_DRIVER_VERSION
\r
83 \fn ARM_USBD_CAPABILITIES ARM_USBD_GetCapabilities (void)
\r
84 \brief Get driver capabilities.
\r
85 \return \ref ARM_USBD_CAPABILITIES
\r
88 \fn int32_t ARM_USBD_Initialize (ARM_USBD_SignalDeviceEvent_t cb_device_event,
\r
89 ARM_USBD_SignalEndpointEvent_t cb_endpoint_event)
\r
90 \brief Initialize USB Device Interface.
\r
91 \param[in] cb_device_event Pointer to \ref ARM_USBD_SignalDeviceEvent
\r
92 \param[in] cb_endpoint_event Pointer to \ref ARM_USBD_SignalEndpointEvent
\r
93 \return \ref execution_status
\r
96 \fn int32_t ARM_USBD_Uninitialize (void)
\r
97 \brief De-initialize USB Device Interface.
\r
98 \return \ref execution_status
\r
101 \fn int32_t ARM_USBD_PowerControl (ARM_POWER_STATE state)
\r
102 \brief Control USB Device Interface Power.
\r
103 \param[in] state Power state
\r
104 \return \ref execution_status
\r
107 \fn int32_t ARM_USBD_DeviceConnect (void)
\r
108 \brief Connect USB Device.
\r
109 \return \ref execution_status
\r
112 \fn int32_t ARM_USBD_DeviceDisconnect (void)
\r
113 \brief Disconnect USB Device.
\r
114 \return \ref execution_status
\r
117 \fn ARM_USBD_STATE ARM_USBD_DeviceGetState (void)
\r
118 \brief Get current USB Device State.
\r
119 \return Device State \ref ARM_USBD_STATE
\r
122 \fn int32_t ARM_USBD_DeviceRemoteWakeup (void)
\r
123 \brief Trigger USB Remote Wakeup.
\r
124 \return \ref execution_status
\r
127 \fn int32_t ARM_USBD_DeviceSetAddress (uint8_t dev_addr)
\r
128 \brief Set USB Device Address.
\r
129 \param[in] dev_addr Device Address
\r
130 \return \ref execution_status
\r
133 \fn int32_t ARM_USBD_ReadSetupPacket (uint8_t *setup)
\r
134 \brief Read setup packet received over Control Endpoint.
\r
135 \param[out] setup Pointer to buffer for setup packet
\r
136 \return \ref execution_status
\r
139 \fn int32_t ARM_USBD_EndpointConfigure (uint8_t ep_addr,
\r
141 uint16_t ep_max_packet_size)
\r
142 \brief Configure USB Endpoint.
\r
143 \param[in] ep_addr Endpoint Address
\r
144 - ep_addr.0..3: Address
\r
145 - ep_addr.7: Direction
\r
146 \param[in] ep_type Endpoint Type (ARM_USB_ENDPOINT_xxx)
\r
147 \param[in] ep_max_packet_size Endpoint Maximum Packet Size
\r
148 \return \ref execution_status
\r
151 \fn int32_t ARM_USBD_EndpointUnconfigure (uint8_t ep_addr)
\r
152 \brief Unconfigure USB Endpoint.
\r
153 \param[in] ep_addr Endpoint Address
\r
154 - ep_addr.0..3: Address
\r
155 - ep_addr.7: Direction
\r
156 \return \ref execution_status
\r
159 \fn int32_t ARM_USBD_EndpointStall (uint8_t ep_addr, bool stall)
\r
160 \brief Set/Clear Stall for USB Endpoint.
\r
161 \param[in] ep_addr Endpoint Address
\r
162 - ep_addr.0..3: Address
\r
163 - ep_addr.7: Direction
\r
164 \param[in] stall Operation
\r
167 \return \ref execution_status
\r
170 \fn int32_t ARM_USBD_EndpointTransfer (uint8_t ep_addr, uint8_t *data, uint32_t num)
\r
171 \brief Read data from or Write data to USB Endpoint.
\r
172 \param[in] ep_addr Endpoint Address
\r
173 - ep_addr.0..3: Address
\r
174 - ep_addr.7: Direction
\r
175 \param[out] data Pointer to buffer for data to read or with data to write
\r
176 \param[in] num Number of data bytes to transfer
\r
177 \return \ref execution_status
\r
180 \fn uint32_t ARM_USBD_EndpointTransferGetResult (uint8_t ep_addr)
\r
181 \brief Get result of USB Endpoint transfer.
\r
182 \param[in] ep_addr Endpoint Address
\r
183 - ep_addr.0..3: Address
\r
184 - ep_addr.7: Direction
\r
185 \return number of successfully transferred data bytes
\r
188 \fn int32_t ARM_USBD_EndpointTransferAbort (uint8_t ep_addr)
\r
189 \brief Abort current USB Endpoint transfer.
\r
190 \param[in] ep_addr Endpoint Address
\r
191 - ep_addr.0..3: Address
\r
192 - ep_addr.7: Direction
\r
193 \return \ref execution_status
\r
196 \fn uint16_t ARM_USBD_GetFrameNumber (void)
\r
197 \brief Get current USB Frame Number.
\r
198 \return Frame Number
\r
202 \fn void ARM_USBD_SignalDeviceEvent (uint32_t event)
\r
203 \brief Signal USB Device Event.
\r
204 \param[in] event \ref USBD_dev_events
\r
208 \fn void ARM_USBD_SignalEndpointEvent (uint8_t ep_addr, uint32_t event)
\r
209 \brief Signal USB Endpoint Event.
\r
210 \param[in] ep_addr Endpoint Address
\r
211 - ep_addr.0..3: Address
\r
212 - ep_addr.7: Direction
\r
213 \param[in] event \ref USBD_ep_events
\r
217 typedef void (*ARM_USBD_SignalDeviceEvent_t) (uint32_t event); ///< Pointer to \ref ARM_USBD_SignalDeviceEvent : Signal USB Device Event.
\r
218 typedef void (*ARM_USBD_SignalEndpointEvent_t) (uint8_t ep_addr, uint32_t event); ///< Pointer to \ref ARM_USBD_SignalEndpointEvent : Signal USB Endpoint Event.
\r
222 \brief USB Device Driver Capabilities.
\r
224 typedef struct _ARM_USBD_CAPABILITIES {
\r
225 uint32_t vbus_detection : 1; ///< VBUS detection
\r
226 uint32_t event_vbus_on : 1; ///< Signal VBUS On event
\r
227 uint32_t event_vbus_off : 1; ///< Signal VBUS Off event
\r
228 } ARM_USBD_CAPABILITIES;
\r
232 \brief Access structure of the USB Device Driver.
\r
234 typedef struct _ARM_DRIVER_USBD {
\r
235 ARM_DRIVER_VERSION (*GetVersion) (void); ///< Pointer to \ref ARM_USBD_GetVersion : Get driver version.
\r
236 ARM_USBD_CAPABILITIES (*GetCapabilities) (void); ///< Pointer to \ref ARM_USBD_GetCapabilities : Get driver capabilities.
\r
237 int32_t (*Initialize) (ARM_USBD_SignalDeviceEvent_t cb_device_event,
\r
238 ARM_USBD_SignalEndpointEvent_t cb_endpoint_event); ///< Pointer to \ref ARM_USBD_Initialize : Initialize USB Device Interface.
\r
239 int32_t (*Uninitialize) (void); ///< Pointer to \ref ARM_USBD_Uninitialize : De-initialize USB Device Interface.
\r
240 int32_t (*PowerControl) (ARM_POWER_STATE state); ///< Pointer to \ref ARM_USBD_PowerControl : Control USB Device Interface Power.
\r
241 int32_t (*DeviceConnect) (void); ///< Pointer to \ref ARM_USBD_DeviceConnect : Connect USB Device.
\r
242 int32_t (*DeviceDisconnect) (void); ///< Pointer to \ref ARM_USBD_DeviceDisconnect : Disconnect USB Device.
\r
243 ARM_USBD_STATE (*DeviceGetState) (void); ///< Pointer to \ref ARM_USBD_DeviceGetState : Get current USB Device State.
\r
244 int32_t (*DeviceRemoteWakeup) (void); ///< Pointer to \ref ARM_USBD_DeviceRemoteWakeup : Trigger USB Remote Wakeup.
\r
245 int32_t (*DeviceSetAddress) (uint8_t dev_addr); ///< Pointer to \ref ARM_USBD_DeviceSetAddress : Set USB Device Address.
\r
246 int32_t (*ReadSetupPacket) (uint8_t *setup); ///< Pointer to \ref ARM_USBD_ReadSetupPacket : Read setup packet received over Control Endpoint.
\r
247 int32_t (*EndpointConfigure) (uint8_t ep_addr,
\r
249 uint16_t ep_max_packet_size); ///< Pointer to \ref ARM_USBD_EndpointConfigure : Configure USB Endpoint.
\r
250 int32_t (*EndpointUnconfigure) (uint8_t ep_addr); ///< Pointer to \ref ARM_USBD_EndpointUnconfigure : Unconfigure USB Endpoint.
\r
251 int32_t (*EndpointStall) (uint8_t ep_addr, bool stall); ///< Pointer to \ref ARM_USBD_EndpointStall : Set/Clear Stall for USB Endpoint.
\r
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.
\r
253 uint32_t (*EndpointTransferGetResult) (uint8_t ep_addr); ///< Pointer to \ref ARM_USBD_EndpointTransferGetResult : Get result of USB Endpoint transfer.
\r
254 int32_t (*EndpointTransferAbort) (uint8_t ep_addr); ///< Pointer to \ref ARM_USBD_EndpointTransferAbort : Abort current USB Endpoint transfer.
\r
255 uint16_t (*GetFrameNumber) (void); ///< Pointer to \ref ARM_USBD_GetFrameNumber : Get current USB Frame Number.
\r
256 } const ARM_DRIVER_USBD;
\r
258 #endif /* __DOXYGEN_MW__ */
\r
260 #endif /* __DRIVER_USBD_H */
\r