usbh_usr.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /**
  2. ******************************************************************************
  3. * @file usbh_usr.c
  4. * @author MCD Application Team
  5. * @version V2.1.0
  6. * @date 19-March-2012
  7. * @brief This file includes the usb host library user callbacks
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "usbh_usr.h"
  29. #include "ff.h" /* FATFS */
  30. #include "usbh_msc_bot.h"
  31. #include "usbh_msc_core.h"
  32. #include "usbh_msc_scsi.h"
  33. #include <string.h>
  34. #define usb_printf printf
  35. //#define usb_printf printf(...)
  36. USB_OTG_CORE_HANDLE USB_OTG_Core;
  37. USBH_HOST USB_Host;
  38. /* Points to the DEVICE_PROP structure of current device */
  39. /* The purpose of this register is to speed up the execution */
  40. USBH_Usr_cb_TypeDef USR_cb =
  41. {
  42. USBH_USR_Init,
  43. USBH_USR_DeInit,
  44. USBH_USR_DeviceAttached,
  45. USBH_USR_ResetDevice,
  46. USBH_USR_DeviceDisconnected,
  47. USBH_USR_OverCurrentDetected,
  48. USBH_USR_DeviceSpeedDetected,
  49. USBH_USR_Device_DescAvailable,
  50. USBH_USR_DeviceAddressAssigned,
  51. USBH_USR_Configuration_DescAvailable,
  52. USBH_USR_Manufacturer_String,
  53. USBH_USR_Product_String,
  54. USBH_USR_SerialNum_String,
  55. USBH_USR_EnumerationDone,
  56. USBH_USR_UserInput,
  57. USBH_USR_MSC_Application,
  58. USBH_USR_DeviceNotSupported,
  59. USBH_USR_UnrecoveredError};
  60. /**
  61. * @}
  62. */
  63. /** @defgroup USBH_USR_Private_Constants
  64. * @{
  65. */
  66. /*--------------- LCD Messages ---------------*/
  67. const uint8_t MSG_HOST_INIT[] = "> Host Library Initialized\r\n";
  68. const uint8_t MSG_DEV_ATTACHED[] = "> Device Attached \r\n";
  69. const uint8_t MSG_DEV_DISCONNECTED[] = "> Device Disconnected\r\n";
  70. const uint8_t MSG_DEV_ENUMERATED[] = "> Enumeration completed \r\n";
  71. const uint8_t MSG_DEV_HIGHSPEED[] = "> High speed device detected\r\n";
  72. const uint8_t MSG_DEV_FULLSPEED[] = "> Full speed device detected\r\n";
  73. const uint8_t MSG_DEV_LOWSPEED[] = "> Low speed device detected\r\n";
  74. const uint8_t MSG_DEV_ERROR[] = "> Device fault \r\n";
  75. const uint8_t MSG_MSC_CLASS[] = "> Mass storage device connected\r\n";
  76. const uint8_t MSG_HID_CLASS[] = "> HID device connected\r\n";
  77. const uint8_t MSG_DISK_SIZE[] = "> Size of the disk in MBytes: \r\n";
  78. const uint8_t MSG_LUN[] = "> LUN Available in the device:\r\n";
  79. const uint8_t MSG_ROOT_CONT[] = "> Exploring disk flash ...\r\n";
  80. const uint8_t MSG_WR_PROTECT[] = "> The disk is write protected\r\n";
  81. const uint8_t MSG_UNREC_ERROR[] = "> UNRECOVERED ERROR STATE\r\n";
  82. /**
  83. * @}
  84. */
  85. /** @defgroup USBH_USR_Private_FunctionPrototypes
  86. * @{
  87. */
  88. /**
  89. * @}
  90. */
  91. /** @defgroup USBH_USR_Private_Functions
  92. * @{
  93. */
  94. /**
  95. * @brief USBH_USR_Init
  96. * Displays the message on LCD for host lib initialization
  97. * @param None
  98. * @retval None
  99. */
  100. void USBH_USR_Init(void)
  101. {
  102. static uint8_t startup = 0;
  103. if (startup == 0)
  104. {
  105. startup = 1;
  106. #ifdef USE_USB_OTG_HS
  107. usb_printf("> USB OTG HS MSC Host\r\n");
  108. #else
  109. usb_printf("> USB OTG FS MSC Host\r\n");
  110. #endif
  111. usb_printf("> USB Host library started.\r\n");
  112. usb_printf(" USB Host Library v2.1.0\r\n");
  113. }
  114. }
  115. /**
  116. * @brief USBH_USR_DeviceAttached
  117. * Displays the message on LCD on device attached
  118. * @param None
  119. * @retval None
  120. */
  121. void USBH_USR_DeviceAttached(void)
  122. {
  123. usb_printf((char *)MSG_DEV_ATTACHED);
  124. }
  125. /**
  126. * @brief USBH_USR_UnrecoveredError
  127. * @param None
  128. * @retval None
  129. */
  130. void USBH_USR_UnrecoveredError(void)
  131. {
  132. usb_printf((char *)MSG_UNREC_ERROR);
  133. }
  134. /**
  135. * @brief USBH_DisconnectEvent
  136. * Device disconnect event
  137. * @param None
  138. * @retval Staus
  139. */
  140. void USBH_USR_DeviceDisconnected(void)
  141. {
  142. usb_printf((char *)MSG_DEV_DISCONNECTED);
  143. }
  144. /**
  145. * @brief USBH_USR_ResetUSBDevice
  146. * @param None
  147. * @retval None
  148. */
  149. void USBH_USR_ResetDevice(void)
  150. {
  151. /* callback for USB-Reset */
  152. usb_printf("> USBH_USR_ResetDevice \r\n");
  153. }
  154. /**
  155. * @brief USBH_USR_DeviceSpeedDetected
  156. * Displays the message on LCD for device speed
  157. * @param Device speed
  158. * @retval None
  159. */
  160. void USBH_USR_DeviceSpeedDetected(uint8_t DeviceSpeed)
  161. {
  162. if (DeviceSpeed == HPRT0_PRTSPD_HIGH_SPEED)
  163. {
  164. usb_printf((char *)MSG_DEV_HIGHSPEED);
  165. }
  166. else if (DeviceSpeed == HPRT0_PRTSPD_FULL_SPEED)
  167. {
  168. usb_printf((char *)MSG_DEV_FULLSPEED);
  169. }
  170. else if (DeviceSpeed == HPRT0_PRTSPD_LOW_SPEED)
  171. {
  172. usb_printf((char *)MSG_DEV_LOWSPEED);
  173. }
  174. else
  175. {
  176. usb_printf((char *)MSG_DEV_ERROR);
  177. }
  178. }
  179. /**
  180. * @brief USBH_USR_Device_DescAvailable
  181. * Displays the message on LCD for device descriptor
  182. * @param device descriptor
  183. * @retval None
  184. */
  185. void USBH_USR_Device_DescAvailable(void *DeviceDesc)
  186. {
  187. USBH_DevDesc_TypeDef *hs;
  188. hs = DeviceDesc;
  189. usb_printf("> VID : %04Xh\r\n", (uint32_t)(*hs).idVendor);
  190. usb_printf("> PID : %04Xh\r\n", (uint32_t)(*hs).idProduct);
  191. }
  192. /**
  193. * @brief USBH_USR_DeviceAddressAssigned
  194. * USB device is successfully assigned the Address
  195. * @param None
  196. * @retval None
  197. */
  198. void USBH_USR_DeviceAddressAssigned(void)
  199. {
  200. }
  201. /**
  202. * @brief USBH_USR_Conf_Desc
  203. * Displays the message on LCD for configuration descriptor
  204. * @param Configuration descriptor
  205. * @retval None
  206. */
  207. void USBH_USR_Configuration_DescAvailable(USBH_CfgDesc_TypeDef *cfgDesc,
  208. USBH_InterfaceDesc_TypeDef *itfDesc,
  209. USBH_EpDesc_TypeDef *epDesc)
  210. {
  211. USBH_InterfaceDesc_TypeDef *id;
  212. id = itfDesc;
  213. if ((*id).bInterfaceClass == 0x08)
  214. {
  215. usb_printf((char *)MSG_MSC_CLASS);
  216. }
  217. else if ((*id).bInterfaceClass == 0x03)
  218. {
  219. usb_printf((char *)MSG_HID_CLASS);
  220. }
  221. }
  222. /**
  223. * @brief USBH_USR_Manufacturer_String
  224. * Displays the message on LCD for Manufacturer String
  225. * @param Manufacturer String
  226. * @retval None
  227. */
  228. void USBH_USR_Manufacturer_String(void *ManufacturerString)
  229. {
  230. usb_printf("> Manufacturer : %sr\r\n", (char *)ManufacturerString);
  231. }
  232. /**
  233. * @brief USBH_USR_Product_String
  234. * Displays the message on LCD for Product String
  235. * @param Product String
  236. * @retval None
  237. */
  238. void USBH_USR_Product_String(void *ProductString)
  239. {
  240. usb_printf("> Product : %s\r\n", (char *)ProductString);
  241. }
  242. /**
  243. * @brief USBH_USR_SerialNum_String
  244. * Displays the message on LCD for SerialNum_String
  245. * @param SerialNum_String
  246. * @retval None
  247. */
  248. void USBH_USR_SerialNum_String(void *SerialNumString)
  249. {
  250. usb_printf("> Serial Number : %s\r\n", (char *)SerialNumString);
  251. }
  252. /**
  253. * @brief EnumerationDone
  254. * User response request is displayed to ask application jump to class
  255. * @param None
  256. * @retval None
  257. */
  258. void USBH_USR_EnumerationDone(void)
  259. {
  260. /* Enumeration complete */
  261. usb_printf((void *)MSG_DEV_ENUMERATED);
  262. }
  263. /**
  264. * @brief USBH_USR_DeviceNotSupported
  265. * Device is not supported
  266. * @param None
  267. * @retval None
  268. */
  269. void USBH_USR_DeviceNotSupported(void)
  270. {
  271. usb_printf("> Device not supported.\r\n");
  272. }
  273. /**
  274. * @brief USBH_USR_UserInput
  275. * User Action for application state entry
  276. * @param None
  277. * @retval USBH_USR_Status : User response for key button
  278. */
  279. USBH_USR_Status USBH_USR_UserInput(void)
  280. {
  281. #if 1
  282. /* HOST_ENUMERATION 和 HOST_CLASS_REQUEST
  283. 在枚举成功和类请求之间等待用户输入。
  284. 此处直接返回OK,无需等待。
  285. */
  286. return USBH_USR_RESP_OK;
  287. #else
  288. USBH_USR_Status usbh_usr_status;
  289. usbh_usr_status = USBH_USR_NO_RESP;
  290. #if 0
  291. /*Key B3 is in polling mode to detect user action */
  292. if(STM_EVAL_PBGetState(Button_KEY) == RESET)
  293. {
  294. usbh_usr_status = USBH_USR_RESP_OK;
  295. }
  296. #endif
  297. return usbh_usr_status;
  298. #endif
  299. }
  300. /**
  301. * @brief USBH_USR_OverCurrentDetected
  302. * Over Current Detected on VBUS
  303. * @param None
  304. * @retval Staus
  305. */
  306. void USBH_USR_OverCurrentDetected(void)
  307. {
  308. usb_printf("> Overcurrent detected.\r\n");
  309. }
  310. /**
  311. * @brief USBH_USR_MSC_Application
  312. * Demo application for mass storage
  313. * @param None
  314. * @retval Staus
  315. */
  316. int USBH_USR_MSC_Application(void)
  317. {
  318. return 0;
  319. }
  320. /**
  321. * @brief USBH_USR_DeInit
  322. * Deint User state and associated variables
  323. * @param None
  324. * @retval None
  325. */
  326. void USBH_USR_DeInit(void)
  327. {
  328. // USBH_USR_ApplicationState = USH_USR_FS_INIT;
  329. }
  330. /**
  331. * @}
  332. */
  333. /**
  334. * @}
  335. */
  336. /**
  337. * @}
  338. */
  339. /**
  340. * @}
  341. */
  342. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/