1 /*
2  * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include <stdlib.h>
10 #include <stdint.h>
11 #include "esp_err.h"
12 #include "usb_private.h"
13 #include "usbh.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 // ------------------------------------------------------ Types --------------------------------------------------------
20 
21 /**
22  * @brief Hub driver configuration
23  */
24 typedef struct {
25     usb_notif_cb_t notif_cb;            /**< Notification callback */
26     void *notif_cb_arg;                 /**< Notification callback argument */
27 } hub_config_t;
28 
29 // ---------------------------------------------- Hub Driver Functions -------------------------------------------------
30 
31 /**
32  * @brief Install Hub driver
33  *
34  * Entry:
35  * - USBH must already be installed
36  * Exit:
37  * - Install Hub driver memory resources
38  * - Initializes the HCD root port
39  *
40  * @param[in] hub_config Hub driver configuration
41  * @return esp_err_t
42  */
43 esp_err_t hub_install(hub_config_t *hub_config);
44 
45 /**
46  * @brief Uninstall Hub driver
47  *
48  * This must be called before uninstalling the USBH
49  * Entry:
50  * - Must have stopped the root port
51  * Exit:
52  * - HCD root port deinitialized
53  *
54  * @return esp_err_t
55  */
56 esp_err_t hub_uninstall(void);
57 
58 /**
59  * @brief Start the Hub driver's root port
60  *
61  * This will power the root port ON
62  *
63  * @return esp_err_t
64  */
65 esp_err_t hub_root_start(void);
66 
67 /**
68  * @brief Stops the Hub driver's root port
69  *
70  * This will power OFF the root port
71  *
72  * @return esp_err_t
73  */
74 esp_err_t hub_root_stop(void);
75 
76 /**
77  * @brief Hub driver's processing function
78  *
79  * Hub driver handling function that must be called repeatdly to process the Hub driver's events. If blocking, the
80  * caller can block on the notification callback of source USB_NOTIF_SOURCE_HUB to run this function.
81  *
82  * @return esp_err_t
83  */
84 esp_err_t hub_process(void);
85 
86 #ifdef __cplusplus
87 }
88 #endif
89