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