xref: /btstack/port/stm32-f4discovery-usb/USB_HOST/App/usb_host.c (revision 40bec0daf6d951307948c7855ec9f3a709b68ba6)
1a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN Header */
2a8f7f3fcSMatthias Ringwald /**
3a8f7f3fcSMatthias Ringwald   ******************************************************************************
4a8f7f3fcSMatthias Ringwald   * @file            : usb_host.c
5a8f7f3fcSMatthias Ringwald   * @version         : v1.0_Cube
6a8f7f3fcSMatthias Ringwald   * @brief           : This file implements the USB Host
7a8f7f3fcSMatthias Ringwald   ******************************************************************************
8a8f7f3fcSMatthias Ringwald   * @attention
9a8f7f3fcSMatthias Ringwald   *
10a8f7f3fcSMatthias Ringwald   * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
11a8f7f3fcSMatthias Ringwald   * All rights reserved.</center></h2>
12a8f7f3fcSMatthias Ringwald   *
13a8f7f3fcSMatthias Ringwald   * This software component is licensed by ST under Ultimate Liberty license
14a8f7f3fcSMatthias Ringwald   * SLA0044, the "License"; You may not use this file except in compliance with
15a8f7f3fcSMatthias Ringwald   * the License. You may obtain a copy of the License at:
16a8f7f3fcSMatthias Ringwald   *                             www.st.com/SLA0044
17a8f7f3fcSMatthias Ringwald   *
18a8f7f3fcSMatthias Ringwald   ******************************************************************************
19a8f7f3fcSMatthias Ringwald   */
20a8f7f3fcSMatthias Ringwald /* USER CODE END Header */
21a8f7f3fcSMatthias Ringwald 
22a8f7f3fcSMatthias Ringwald /* Includes ------------------------------------------------------------------*/
23a8f7f3fcSMatthias Ringwald 
24a8f7f3fcSMatthias Ringwald #include "usb_host.h"
25a8f7f3fcSMatthias Ringwald #include "usbh_core.h"
26a8f7f3fcSMatthias Ringwald 
27a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN Includes */
28*40bec0daSMatthias Ringwald #include "usbh_bluetooth.h"
29a8f7f3fcSMatthias Ringwald 
30a8f7f3fcSMatthias Ringwald /* USER CODE END Includes */
31a8f7f3fcSMatthias Ringwald 
32a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN PV */
33a8f7f3fcSMatthias Ringwald /* Private variables ---------------------------------------------------------*/
34a8f7f3fcSMatthias Ringwald 
35a8f7f3fcSMatthias Ringwald /* USER CODE END PV */
36a8f7f3fcSMatthias Ringwald 
37a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN PFP */
38a8f7f3fcSMatthias Ringwald /* Private function prototypes -----------------------------------------------*/
39a8f7f3fcSMatthias Ringwald 
40a8f7f3fcSMatthias Ringwald /* USER CODE END PFP */
41a8f7f3fcSMatthias Ringwald 
42a8f7f3fcSMatthias Ringwald /* USB Host core handle declaration */
43a8f7f3fcSMatthias Ringwald USBH_HandleTypeDef hUsbHostFS;
44a8f7f3fcSMatthias Ringwald ApplicationTypeDef Appli_state = APPLICATION_IDLE;
45a8f7f3fcSMatthias Ringwald 
46a8f7f3fcSMatthias Ringwald /*
47a8f7f3fcSMatthias Ringwald  * -- Insert your variables declaration here --
48a8f7f3fcSMatthias Ringwald  */
49a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN 0 */
50a8f7f3fcSMatthias Ringwald 
51a8f7f3fcSMatthias Ringwald /* USER CODE END 0 */
52a8f7f3fcSMatthias Ringwald 
53a8f7f3fcSMatthias Ringwald /*
54a8f7f3fcSMatthias Ringwald  * user callback declaration
55a8f7f3fcSMatthias Ringwald  */
56a8f7f3fcSMatthias Ringwald static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id);
57a8f7f3fcSMatthias Ringwald 
58a8f7f3fcSMatthias Ringwald /*
59a8f7f3fcSMatthias Ringwald  * -- Insert your external function declaration here --
60a8f7f3fcSMatthias Ringwald  */
61a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN 1 */
62a8f7f3fcSMatthias Ringwald 
63a8f7f3fcSMatthias Ringwald /* USER CODE END 1 */
64a8f7f3fcSMatthias Ringwald 
65a8f7f3fcSMatthias Ringwald /**
66a8f7f3fcSMatthias Ringwald   * Init USB host library, add supported class and start the library
67a8f7f3fcSMatthias Ringwald   * @retval None
68a8f7f3fcSMatthias Ringwald   */
MX_USB_HOST_Init(void)69a8f7f3fcSMatthias Ringwald void MX_USB_HOST_Init(void)
70a8f7f3fcSMatthias Ringwald {
71a8f7f3fcSMatthias Ringwald   /* USER CODE BEGIN USB_HOST_Init_PreTreatment */
72a8f7f3fcSMatthias Ringwald 
73a8f7f3fcSMatthias Ringwald   /* USER CODE END USB_HOST_Init_PreTreatment */
74a8f7f3fcSMatthias Ringwald 
75a8f7f3fcSMatthias Ringwald   /* Init host Library, add supported class and start the library. */
76a8f7f3fcSMatthias Ringwald   if (USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS) != USBH_OK)
77a8f7f3fcSMatthias Ringwald   {
78a8f7f3fcSMatthias Ringwald     Error_Handler();
79a8f7f3fcSMatthias Ringwald   }
80*40bec0daSMatthias Ringwald   if (USBH_RegisterClass(&hUsbHostFS, USBH_BLUETOOTH_CLASS) != USBH_OK)
81a8f7f3fcSMatthias Ringwald   {
82a8f7f3fcSMatthias Ringwald     Error_Handler();
83a8f7f3fcSMatthias Ringwald   }
84a8f7f3fcSMatthias Ringwald   if (USBH_Start(&hUsbHostFS) != USBH_OK)
85a8f7f3fcSMatthias Ringwald   {
86a8f7f3fcSMatthias Ringwald     Error_Handler();
87a8f7f3fcSMatthias Ringwald   }
88a8f7f3fcSMatthias Ringwald   /* USER CODE BEGIN USB_HOST_Init_PostTreatment */
89a8f7f3fcSMatthias Ringwald 
90a8f7f3fcSMatthias Ringwald   /* USER CODE END USB_HOST_Init_PostTreatment */
91a8f7f3fcSMatthias Ringwald }
92a8f7f3fcSMatthias Ringwald 
93a8f7f3fcSMatthias Ringwald /*
94a8f7f3fcSMatthias Ringwald  * Background task
95a8f7f3fcSMatthias Ringwald  */
MX_USB_HOST_Process(void)96a8f7f3fcSMatthias Ringwald void MX_USB_HOST_Process(void)
97a8f7f3fcSMatthias Ringwald {
98a8f7f3fcSMatthias Ringwald   /* USB Host Background task */
99a8f7f3fcSMatthias Ringwald   USBH_Process(&hUsbHostFS);
100a8f7f3fcSMatthias Ringwald }
101a8f7f3fcSMatthias Ringwald /*
102a8f7f3fcSMatthias Ringwald  * user callback definition
103a8f7f3fcSMatthias Ringwald  */
USBH_UserProcess(USBH_HandleTypeDef * phost,uint8_t id)104a8f7f3fcSMatthias Ringwald static void USBH_UserProcess  (USBH_HandleTypeDef *phost, uint8_t id)
105a8f7f3fcSMatthias Ringwald {
106a8f7f3fcSMatthias Ringwald   /* USER CODE BEGIN CALL_BACK_1 */
107a8f7f3fcSMatthias Ringwald   switch(id)
108a8f7f3fcSMatthias Ringwald   {
109a8f7f3fcSMatthias Ringwald   case HOST_USER_SELECT_CONFIGURATION:
110a8f7f3fcSMatthias Ringwald   break;
111a8f7f3fcSMatthias Ringwald 
112a8f7f3fcSMatthias Ringwald   case HOST_USER_DISCONNECTION:
113a8f7f3fcSMatthias Ringwald   Appli_state = APPLICATION_DISCONNECT;
114a8f7f3fcSMatthias Ringwald   break;
115a8f7f3fcSMatthias Ringwald 
116a8f7f3fcSMatthias Ringwald   case HOST_USER_CLASS_ACTIVE:
117a8f7f3fcSMatthias Ringwald   Appli_state = APPLICATION_READY;
118a8f7f3fcSMatthias Ringwald   break;
119a8f7f3fcSMatthias Ringwald 
120a8f7f3fcSMatthias Ringwald   case HOST_USER_CONNECTION:
121a8f7f3fcSMatthias Ringwald   Appli_state = APPLICATION_START;
122a8f7f3fcSMatthias Ringwald   break;
123a8f7f3fcSMatthias Ringwald 
124a8f7f3fcSMatthias Ringwald   default:
125a8f7f3fcSMatthias Ringwald   break;
126a8f7f3fcSMatthias Ringwald   }
127a8f7f3fcSMatthias Ringwald   /* USER CODE END CALL_BACK_1 */
128a8f7f3fcSMatthias Ringwald }
129a8f7f3fcSMatthias Ringwald 
130a8f7f3fcSMatthias Ringwald /**
131a8f7f3fcSMatthias Ringwald   * @}
132a8f7f3fcSMatthias Ringwald   */
133a8f7f3fcSMatthias Ringwald 
134a8f7f3fcSMatthias Ringwald /**
135a8f7f3fcSMatthias Ringwald   * @}
136a8f7f3fcSMatthias Ringwald   */
137a8f7f3fcSMatthias Ringwald 
138a8f7f3fcSMatthias Ringwald /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
139