Driver_USBD.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /* -----------------------------------------------------------------------------
  2. * Copyright (c) 2013-2014 ARM Ltd.
  3. *
  4. * This software is provided 'as-is', without any express or implied warranty.
  5. * In no event will the authors be held liable for any damages arising from
  6. * the use of this software. Permission is granted to anyone to use this
  7. * software for any purpose, including commercial applications, and to alter
  8. * it and redistribute it freely, subject to the following restrictions:
  9. *
  10. * 1. The origin of this software must not be misrepresented; you must not
  11. * claim that you wrote the original software. If you use this software in
  12. * a product, an acknowledgment in the product documentation would be
  13. * appreciated but is not required.
  14. *
  15. * 2. Altered source versions must be plainly marked as such, and must not be
  16. * misrepresented as being the original software.
  17. *
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. *
  20. *
  21. * $Date: 3. Jun 2014
  22. * $Revision: V2.01
  23. *
  24. * Project: USB Device Driver definitions
  25. * -------------------------------------------------------------------------- */
  26. /* History:
  27. * Version 2.01
  28. * Added ARM_USBD_ReadSetupPacket function
  29. * Version 2.00
  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. #ifndef __DRIVER_USBD_H
  44. #define __DRIVER_USBD_H
  45. #include "Driver_USB.h"
  46. #define ARM_USBD_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2,01) /* API version */
  47. /**
  48. \brief USB Device State
  49. */
  50. typedef struct _ARM_USBD_STATE {
  51. uint32_t vbus : 1; ///< USB Device VBUS flag
  52. uint32_t speed : 2; ///< USB Device speed setting (ARM_USB_SPEED_xxx)
  53. uint32_t active : 1; ///< USB Device active flag
  54. } ARM_USBD_STATE;
  55. /****** USB Device Event *****/
  56. #define ARM_USBD_EVENT_VBUS_ON (1UL << 0) ///< USB Device VBUS On
  57. #define ARM_USBD_EVENT_VBUS_OFF (1UL << 1) ///< USB Device VBUS Off
  58. #define ARM_USBD_EVENT_RESET (1UL << 2) ///< USB Reset occurred
  59. #define ARM_USBD_EVENT_HIGH_SPEED (1UL << 3) ///< USB switch to High Speed occurred
  60. #define ARM_USBD_EVENT_SUSPEND (1UL << 4) ///< USB Suspend occurred
  61. #define ARM_USBD_EVENT_RESUME (1UL << 5) ///< USB Resume occurred
  62. /****** USB Endpoint Event *****/
  63. #define ARM_USBD_EVENT_SETUP (1UL << 0) ///< SETUP Packet
  64. #define ARM_USBD_EVENT_OUT (1UL << 1) ///< OUT Packet(s)
  65. #define ARM_USBD_EVENT_IN (1UL << 2) ///< IN Packet(s)
  66. #ifndef __DOXYGEN_MW__ // exclude from middleware documentation
  67. // Function documentation
  68. /**
  69. \fn ARM_DRIVER_VERSION ARM_USBD_GetVersion (void)
  70. \brief Get driver version.
  71. \return \ref ARM_DRIVER_VERSION
  72. */
  73. /**
  74. \fn ARM_USBD_CAPABILITIES ARM_USBD_GetCapabilities (void)
  75. \brief Get driver capabilities.
  76. \return \ref ARM_USBD_CAPABILITIES
  77. */
  78. /**
  79. \fn int32_t ARM_USBD_Initialize (ARM_USBD_SignalDeviceEvent_t cb_device_event,
  80. ARM_USBD_SignalEndpointEvent_t cb_endpoint_event)
  81. \brief Initialize USB Device Interface.
  82. \param[in] cb_device_event Pointer to \ref ARM_USBD_SignalDeviceEvent
  83. \param[in] cb_endpoint_event Pointer to \ref ARM_USBD_SignalEndpointEvent
  84. \return \ref execution_status
  85. */
  86. /**
  87. \fn int32_t ARM_USBD_Uninitialize (void)
  88. \brief De-initialize USB Device Interface.
  89. \return \ref execution_status
  90. */
  91. /**
  92. \fn int32_t ARM_USBD_PowerControl (ARM_POWER_STATE state)
  93. \brief Control USB Device Interface Power.
  94. \param[in] state Power state
  95. \return \ref execution_status
  96. */
  97. /**
  98. \fn int32_t ARM_USBD_DeviceConnect (void)
  99. \brief Connect USB Device.
  100. \return \ref execution_status
  101. */
  102. /**
  103. \fn int32_t ARM_USBD_DeviceDisconnect (void)
  104. \brief Disconnect USB Device.
  105. \return \ref execution_status
  106. */
  107. /**
  108. \fn ARM_USBD_STATE ARM_USBD_DeviceGetState (void)
  109. \brief Get current USB Device State.
  110. \return Device State \ref ARM_USBD_STATE
  111. */
  112. /**
  113. \fn int32_t ARM_USBD_DeviceRemoteWakeup (void)
  114. \brief Trigger USB Remote Wakeup.
  115. \return \ref execution_status
  116. */
  117. /**
  118. \fn int32_t ARM_USBD_DeviceSetAddress (uint8_t dev_addr)
  119. \brief Set USB Device Address.
  120. \param[in] dev_addr Device Address
  121. \return \ref execution_status
  122. */
  123. /**
  124. \fn int32_t ARM_USBD_ReadSetupPacket (uint8_t *setup)
  125. \brief Read setup packet received over Control Endpoint.
  126. \param[out] setup Pointer to buffer for setup packet
  127. \return \ref execution_status
  128. */
  129. /**
  130. \fn int32_t ARM_USBD_EndpointConfigure (uint8_t ep_addr,
  131. uint8_t ep_type,
  132. uint16_t ep_max_packet_size)
  133. \brief Configure USB Endpoint.
  134. \param[in] ep_addr Endpoint Address
  135. - ep_addr.0..3: Address
  136. - ep_addr.7: Direction
  137. \param[in] ep_type Endpoint Type (ARM_USB_ENDPOINT_xxx)
  138. \param[in] ep_max_packet_size Endpoint Maximum Packet Size
  139. \return \ref execution_status
  140. */
  141. /**
  142. \fn int32_t ARM_USBD_EndpointUnconfigure (uint8_t ep_addr)
  143. \brief Unconfigure USB Endpoint.
  144. \param[in] ep_addr Endpoint Address
  145. - ep_addr.0..3: Address
  146. - ep_addr.7: Direction
  147. \return \ref execution_status
  148. */
  149. /**
  150. \fn int32_t ARM_USBD_EndpointStall (uint8_t ep_addr, bool stall)
  151. \brief Set/Clear Stall for USB Endpoint.
  152. \param[in] ep_addr Endpoint Address
  153. - ep_addr.0..3: Address
  154. - ep_addr.7: Direction
  155. \param[in] stall Operation
  156. - \b false Clear
  157. - \b true Set
  158. \return \ref execution_status
  159. */
  160. /**
  161. \fn int32_t ARM_USBD_EndpointTransfer (uint8_t ep_addr, uint8_t *data, uint32_t num)
  162. \brief Read data from or Write data to USB Endpoint.
  163. \param[in] ep_addr Endpoint Address
  164. - ep_addr.0..3: Address
  165. - ep_addr.7: Direction
  166. \param[out] data Pointer to buffer for data to read or with data to write
  167. \param[in] num Number of data bytes to transfer
  168. \return \ref execution_status
  169. */
  170. /**
  171. \fn uint32_t ARM_USBD_EndpointTransferGetResult (uint8_t ep_addr)
  172. \brief Get result of USB Endpoint transfer.
  173. \param[in] ep_addr Endpoint Address
  174. - ep_addr.0..3: Address
  175. - ep_addr.7: Direction
  176. \return number of successfully transferred data bytes
  177. */
  178. /**
  179. \fn int32_t ARM_USBD_EndpointTransferAbort (uint8_t ep_addr)
  180. \brief Abort current USB Endpoint transfer.
  181. \param[in] ep_addr Endpoint Address
  182. - ep_addr.0..3: Address
  183. - ep_addr.7: Direction
  184. \return \ref execution_status
  185. */
  186. /**
  187. \fn uint16_t ARM_USBD_GetFrameNumber (void)
  188. \brief Get current USB Frame Number.
  189. \return Frame Number
  190. */
  191. /**
  192. \fn void ARM_USBD_SignalDeviceEvent (uint32_t event)
  193. \brief Signal USB Device Event.
  194. \param[in] event \ref USBD_dev_events
  195. \return none
  196. */
  197. /**
  198. \fn void ARM_USBD_SignalEndpointEvent (uint8_t ep_addr, uint32_t event)
  199. \brief Signal USB Endpoint Event.
  200. \param[in] ep_addr Endpoint Address
  201. - ep_addr.0..3: Address
  202. - ep_addr.7: Direction
  203. \param[in] event \ref USBD_ep_events
  204. \return none
  205. */
  206. typedef void (*ARM_USBD_SignalDeviceEvent_t) (uint32_t event); ///< Pointer to \ref ARM_USBD_SignalDeviceEvent : Signal USB Device Event.
  207. typedef void (*ARM_USBD_SignalEndpointEvent_t) (uint8_t ep_addr, uint32_t event); ///< Pointer to \ref ARM_USBD_SignalEndpointEvent : Signal USB Endpoint Event.
  208. /**
  209. \brief USB Device Driver Capabilities.
  210. */
  211. typedef struct _ARM_USBD_CAPABILITIES {
  212. uint32_t vbus_detection : 1; ///< VBUS detection
  213. uint32_t event_vbus_on : 1; ///< Signal VBUS On event
  214. uint32_t event_vbus_off : 1; ///< Signal VBUS Off event
  215. } ARM_USBD_CAPABILITIES;
  216. /**
  217. \brief Access structure of the USB Device Driver.
  218. */
  219. typedef struct _ARM_DRIVER_USBD {
  220. ARM_DRIVER_VERSION (*GetVersion) (void); ///< Pointer to \ref ARM_USBD_GetVersion : Get driver version.
  221. ARM_USBD_CAPABILITIES (*GetCapabilities) (void); ///< Pointer to \ref ARM_USBD_GetCapabilities : Get driver capabilities.
  222. int32_t (*Initialize) (ARM_USBD_SignalDeviceEvent_t cb_device_event,
  223. ARM_USBD_SignalEndpointEvent_t cb_endpoint_event); ///< Pointer to \ref ARM_USBD_Initialize : Initialize USB Device Interface.
  224. int32_t (*Uninitialize) (void); ///< Pointer to \ref ARM_USBD_Uninitialize : De-initialize USB Device Interface.
  225. int32_t (*PowerControl) (ARM_POWER_STATE state); ///< Pointer to \ref ARM_USBD_PowerControl : Control USB Device Interface Power.
  226. int32_t (*DeviceConnect) (void); ///< Pointer to \ref ARM_USBD_DeviceConnect : Connect USB Device.
  227. int32_t (*DeviceDisconnect) (void); ///< Pointer to \ref ARM_USBD_DeviceDisconnect : Disconnect USB Device.
  228. ARM_USBD_STATE (*DeviceGetState) (void); ///< Pointer to \ref ARM_USBD_DeviceGetState : Get current USB Device State.
  229. int32_t (*DeviceRemoteWakeup) (void); ///< Pointer to \ref ARM_USBD_DeviceRemoteWakeup : Trigger USB Remote Wakeup.
  230. int32_t (*DeviceSetAddress) (uint8_t dev_addr); ///< Pointer to \ref ARM_USBD_DeviceSetAddress : Set USB Device Address.
  231. int32_t (*ReadSetupPacket) (uint8_t *setup); ///< Pointer to \ref ARM_USBD_ReadSetupPacket : Read setup packet received over Control Endpoint.
  232. int32_t (*EndpointConfigure) (uint8_t ep_addr,
  233. uint8_t ep_type,
  234. uint16_t ep_max_packet_size); ///< Pointer to \ref ARM_USBD_EndpointConfigure : Configure USB Endpoint.
  235. int32_t (*EndpointUnconfigure) (uint8_t ep_addr); ///< Pointer to \ref ARM_USBD_EndpointUnconfigure : Unconfigure USB Endpoint.
  236. int32_t (*EndpointStall) (uint8_t ep_addr, bool stall); ///< Pointer to \ref ARM_USBD_EndpointStall : Set/Clear Stall for USB Endpoint.
  237. 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.
  238. uint32_t (*EndpointTransferGetResult) (uint8_t ep_addr); ///< Pointer to \ref ARM_USBD_EndpointTransferGetResult : Get result of USB Endpoint transfer.
  239. int32_t (*EndpointTransferAbort) (uint8_t ep_addr); ///< Pointer to \ref ARM_USBD_EndpointTransferAbort : Abort current USB Endpoint transfer.
  240. uint16_t (*GetFrameNumber) (void); ///< Pointer to \ref ARM_USBD_GetFrameNumber : Get current USB Frame Number.
  241. } const ARM_DRIVER_USBD;
  242. #endif /* __DOXYGEN_MW__ */
  243. #endif /* __DRIVER_USBD_H */