Driver_USBD.h 12 KB

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