1 /**
2  * @file usbh.h
3  * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited
4  */
5 
6 #ifndef HAL_USBH_H
7 #define HAL_USBH_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /** @addtogroup hal_usbh USBH
14  *  usbh hal API.
15  *
16  *  @{
17  */
18 
19 #include <stdint.h>
20 
21 /**
22  * @brief Initialize The USB Host Controller
23  *
24  * @param[in]  phost  pointer to the usb host handler
25  * @param[out] phcd   pointer to the usb hcd driver pointer
26  *
27  * @return 0:success, otherwise is failed
28  */
29 int hal_usbh_init(void *phost, void **phcd);
30 
31 /**
32  * @brief Finalize The USB Host Controller
33  *
34  * @param[in]  hcd  pointer to the usb hcd
35  *
36  * @return 0:success, otherwise is failed
37  */
38 int hal_usbh_finalize(void *hcd);
39 
40 /**
41  * @brief Reset Host Controller's Port
42  *
43  * @param[in]  hcd  pointer to the usb hcd
44  *
45  * @return 0:success, otherwise is failed
46  */
47 int hal_usbh_port_reset(void *hcd);
48 
49 /**
50  * @brief Get Device Speed
51  *
52  * @param[in]  hcd  pointer to the usb hcd
53  *
54  * @return the usb host controller's speed
55  * (0:USB_PORT_SPEED_LOW, 1:USB_PORT_SPEED_FULL, 2:USB_PORT_SPEED_HIGH)
56  */
57 int hal_usbh_get_speed(void *hcd);
58 
59 /**
60  * @brief Free The Host Controll's Pipe
61  *
62  * @param[in]  hcd       pointer to the usb hcd
63  * @param[in]  pipe_num  the index of the pipe
64  *
65  * @return 0:success, otherwise is failed
66  */
67 int hal_usbh_pipe_free(void *hcd, uint8_t pipe_num);
68 
69 /**
70  * @brief Configure The Host Controller's Pipe
71  *
72  * @param[in]  hcd       pointer to the usb hcd
73  * @param[in]  index     the index of the pipe
74  * @param[in]  ep_addr   the endpoint address
75  * @param[in]  dev_addr  the device address
76  * @param[in]  speed     the device speed
77  * @param[in]  token     the transmit PID token
78  * @param[in]  ep_type   the endpoint type
79  * @param[in]  mps       the max packet size per transmit
80  *
81  * @return 0:success, otherwise is failed
82  */
83 int hal_usbh_pipe_configure(void *hcd, uint8_t index, uint8_t ep_addr, uint8_t dev_addr,
84                             uint8_t speed, uint8_t ep_type, uint16_t mps);
85 
86 /**
87  * @brief Submit The Urb, start to send or receive data
88  *
89  * @param[in]      hcd        pointer to the usb hcd
90  * @param[in]      pipe_num   the index of the pipe
91  * @param[in]      direction  the transmit direction
92  * @param[in]      ep_type    the endpoint type
93  * @param[in]      token      the transmit token
94  * @param[in/out]  buf        pointer to the buffer which will be send or recv
95  * @param[in]      length     the length of buffer
96  *
97  * @return 0:success, otherwise is failed
98  */
99 int hal_usbh_submit_urb(void *hcd, uint8_t pipe_num, uint8_t direction, uint8_t ep_type,
100                         uint8_t token, uint8_t *buf, uint16_t length);
101 
102 /**
103  * @brief Get The Urb Transmit State
104  *
105  * @param[in]  hcd       pointer to the usb hcd
106  * @param[in]  pipe_num  the index of the pipe
107  *
108  * @return 0:Idle, 1:Done, 2:Not Ready, 3:Nyet, 4:Error, 5:Stall
109  */
110 int hal_usbh_get_urb_state(void *hcd, uint8_t pipe_num);
111 
112 /** @} */
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif /* HAL_USBH_H */
119 
120