hal_usb_lld.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file hal_usb_lld.c
  15. * @brief PLATFORM USB subsystem low level driver source.
  16. *
  17. * @addtogroup USB
  18. * @{
  19. */
  20. #include "hal.h"
  21. #if (HAL_USE_USB == TRUE) || defined(__DOXYGEN__)
  22. /*===========================================================================*/
  23. /* Driver local definitions. */
  24. /*===========================================================================*/
  25. /*===========================================================================*/
  26. /* Driver exported variables. */
  27. /*===========================================================================*/
  28. /**
  29. * @brief USB1 driver identifier.
  30. */
  31. #if (PLATFORM_USB_USE_USB1 == TRUE) || defined(__DOXYGEN__)
  32. USBDriver USBD1;
  33. #endif
  34. /*===========================================================================*/
  35. /* Driver local variables and types. */
  36. /*===========================================================================*/
  37. /**
  38. * @brief EP0 state.
  39. * @note It is an union because IN and OUT endpoints are never used at the
  40. * same time for EP0.
  41. */
  42. static union {
  43. /**
  44. * @brief IN EP0 state.
  45. */
  46. USBInEndpointState in;
  47. /**
  48. * @brief OUT EP0 state.
  49. */
  50. USBOutEndpointState out;
  51. } ep0_state;
  52. /**
  53. * @brief EP0 initialization structure.
  54. */
  55. static const USBEndpointConfig ep0config = {
  56. USB_EP_MODE_TYPE_CTRL,
  57. _usb_ep0setup,
  58. _usb_ep0in,
  59. _usb_ep0out,
  60. 0x40,
  61. 0x40,
  62. &ep0_state.in,
  63. &ep0_state.out
  64. };
  65. /*===========================================================================*/
  66. /* Driver local variables and types. */
  67. /*===========================================================================*/
  68. /*===========================================================================*/
  69. /* Driver local functions. */
  70. /*===========================================================================*/
  71. /*===========================================================================*/
  72. /* Driver interrupt handlers and threads. */
  73. /*===========================================================================*/
  74. /*===========================================================================*/
  75. /* Driver exported functions. */
  76. /*===========================================================================*/
  77. /**
  78. * @brief Low level USB driver initialization.
  79. *
  80. * @notapi
  81. */
  82. void usb_lld_init(void) {
  83. #if PLATFORM_USB_USE_USB1 == TRUE
  84. /* Driver initialization.*/
  85. usbObjectInit(&USBD1);
  86. #endif
  87. }
  88. /**
  89. * @brief Configures and activates the USB peripheral.
  90. *
  91. * @param[in] usbp pointer to the @p USBDriver object
  92. *
  93. * @notapi
  94. */
  95. void usb_lld_start(USBDriver *usbp) {
  96. if (usbp->state == USB_STOP) {
  97. /* Enables the peripheral.*/
  98. #if PLATFORM_USB_USE_USB1 == TRUE
  99. if (&USBD1 == usbp) {
  100. }
  101. #endif
  102. }
  103. /* Configures the peripheral.*/
  104. }
  105. /**
  106. * @brief Deactivates the USB peripheral.
  107. *
  108. * @param[in] usbp pointer to the @p USBDriver object
  109. *
  110. * @notapi
  111. */
  112. void usb_lld_stop(USBDriver *usbp) {
  113. if (usbp->state == USB_READY) {
  114. /* Resets the peripheral.*/
  115. /* Disables the peripheral.*/
  116. #if PLATFORM_USB_USE_USB1 == TRUE
  117. if (&USBD1 == usbp) {
  118. }
  119. #endif
  120. }
  121. }
  122. /**
  123. * @brief USB low level reset routine.
  124. *
  125. * @param[in] usbp pointer to the @p USBDriver object
  126. *
  127. * @notapi
  128. */
  129. void usb_lld_reset(USBDriver *usbp) {
  130. /* Post reset initialization.*/
  131. /* EP0 initialization.*/
  132. usbp->epc[0] = &ep0config;
  133. usb_lld_init_endpoint(usbp, 0);
  134. }
  135. /**
  136. * @brief Sets the USB address.
  137. *
  138. * @param[in] usbp pointer to the @p USBDriver object
  139. *
  140. * @notapi
  141. */
  142. void usb_lld_set_address(USBDriver *usbp) {
  143. (void)usbp;
  144. }
  145. /**
  146. * @brief Enables an endpoint.
  147. *
  148. * @param[in] usbp pointer to the @p USBDriver object
  149. * @param[in] ep endpoint number
  150. *
  151. * @notapi
  152. */
  153. void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
  154. (void)usbp;
  155. (void)ep;
  156. }
  157. /**
  158. * @brief Disables all the active endpoints except the endpoint zero.
  159. *
  160. * @param[in] usbp pointer to the @p USBDriver object
  161. *
  162. * @notapi
  163. */
  164. void usb_lld_disable_endpoints(USBDriver *usbp) {
  165. (void)usbp;
  166. }
  167. /**
  168. * @brief Returns the status of an OUT endpoint.
  169. *
  170. * @param[in] usbp pointer to the @p USBDriver object
  171. * @param[in] ep endpoint number
  172. * @return The endpoint status.
  173. * @retval EP_STATUS_DISABLED The endpoint is not active.
  174. * @retval EP_STATUS_STALLED The endpoint is stalled.
  175. * @retval EP_STATUS_ACTIVE The endpoint is active.
  176. *
  177. * @notapi
  178. */
  179. usbepstatus_t usb_lld_get_status_out(USBDriver *usbp, usbep_t ep) {
  180. (void)usbp;
  181. (void)ep;
  182. return EP_STATUS_DISABLED;
  183. }
  184. /**
  185. * @brief Returns the status of an IN endpoint.
  186. *
  187. * @param[in] usbp pointer to the @p USBDriver object
  188. * @param[in] ep endpoint number
  189. * @return The endpoint status.
  190. * @retval EP_STATUS_DISABLED The endpoint is not active.
  191. * @retval EP_STATUS_STALLED The endpoint is stalled.
  192. * @retval EP_STATUS_ACTIVE The endpoint is active.
  193. *
  194. * @notapi
  195. */
  196. usbepstatus_t usb_lld_get_status_in(USBDriver *usbp, usbep_t ep) {
  197. (void)usbp;
  198. (void)ep;
  199. return EP_STATUS_DISABLED;
  200. }
  201. /**
  202. * @brief Reads a setup packet from the dedicated packet buffer.
  203. * @details This function must be invoked in the context of the @p setup_cb
  204. * callback in order to read the received setup packet.
  205. * @pre In order to use this function the endpoint must have been
  206. * initialized as a control endpoint.
  207. * @post The endpoint is ready to accept another packet.
  208. *
  209. * @param[in] usbp pointer to the @p USBDriver object
  210. * @param[in] ep endpoint number
  211. * @param[out] buf buffer where to copy the packet data
  212. *
  213. * @notapi
  214. */
  215. void usb_lld_read_setup(USBDriver *usbp, usbep_t ep, uint8_t *buf) {
  216. (void)usbp;
  217. (void)ep;
  218. (void)buf;
  219. }
  220. /**
  221. * @brief Prepares for a receive operation.
  222. *
  223. * @param[in] usbp pointer to the @p USBDriver object
  224. * @param[in] ep endpoint number
  225. *
  226. * @notapi
  227. */
  228. void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep) {
  229. (void)usbp;
  230. (void)ep;
  231. }
  232. /**
  233. * @brief Prepares for a transmit operation.
  234. *
  235. * @param[in] usbp pointer to the @p USBDriver object
  236. * @param[in] ep endpoint number
  237. *
  238. * @notapi
  239. */
  240. void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep) {
  241. (void)usbp;
  242. (void)ep;
  243. }
  244. /**
  245. * @brief Starts a receive operation on an OUT endpoint.
  246. *
  247. * @param[in] usbp pointer to the @p USBDriver object
  248. * @param[in] ep endpoint number
  249. *
  250. * @notapi
  251. */
  252. void usb_lld_start_out(USBDriver *usbp, usbep_t ep) {
  253. (void)usbp;
  254. (void)ep;
  255. }
  256. /**
  257. * @brief Starts a transmit operation on an IN endpoint.
  258. *
  259. * @param[in] usbp pointer to the @p USBDriver object
  260. * @param[in] ep endpoint number
  261. *
  262. * @notapi
  263. */
  264. void usb_lld_start_in(USBDriver *usbp, usbep_t ep) {
  265. (void)usbp;
  266. (void)ep;
  267. }
  268. /**
  269. * @brief Brings an OUT endpoint in the stalled state.
  270. *
  271. * @param[in] usbp pointer to the @p USBDriver object
  272. * @param[in] ep endpoint number
  273. *
  274. * @notapi
  275. */
  276. void usb_lld_stall_out(USBDriver *usbp, usbep_t ep) {
  277. (void)usbp;
  278. (void)ep;
  279. }
  280. /**
  281. * @brief Brings an IN endpoint in the stalled state.
  282. *
  283. * @param[in] usbp pointer to the @p USBDriver object
  284. * @param[in] ep endpoint number
  285. *
  286. * @notapi
  287. */
  288. void usb_lld_stall_in(USBDriver *usbp, usbep_t ep) {
  289. (void)usbp;
  290. (void)ep;
  291. }
  292. /**
  293. * @brief Brings an OUT endpoint in the active state.
  294. *
  295. * @param[in] usbp pointer to the @p USBDriver object
  296. * @param[in] ep endpoint number
  297. *
  298. * @notapi
  299. */
  300. void usb_lld_clear_out(USBDriver *usbp, usbep_t ep) {
  301. (void)usbp;
  302. (void)ep;
  303. }
  304. /**
  305. * @brief Brings an IN endpoint in the active state.
  306. *
  307. * @param[in] usbp pointer to the @p USBDriver object
  308. * @param[in] ep endpoint number
  309. *
  310. * @notapi
  311. */
  312. void usb_lld_clear_in(USBDriver *usbp, usbep_t ep) {
  313. (void)usbp;
  314. (void)ep;
  315. }
  316. #endif /* HAL_USE_USB == TRUE */
  317. /** @} */