Driver_USBD.h 12 KB

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