| M480 BSP V3.05.001 The Board Support Package for M480 Series

usbh_lib.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #ifndef _USBH_LIB_H_
10 #define _USBH_LIB_H_
11
12 #include "NuMicro.h"
13
14 #ifdef __cplusplus
15 extern "C"
16 {
17 #endif
18
31 #define USBH_OK 0
32 #define USBH_ERR_MEMORY_OUT -10
33 #define USBH_ERR_IF_ALT_LIMIT -11
34 #define USBH_ERR_IF_EP_LIMIT -15
35 #define USBH_ERR_NOT_SUPPORTED -101
36 #define USBH_ERR_NOT_MATCHED -103
37 #define USBH_ERR_NOT_EXPECTED -104
38 #define USBH_ERR_INVALID_PARAM -105
39 #define USBH_ERR_NOT_FOUND -106
40 #define USBH_ERR_EP_NOT_FOUND -107
41 #define USBH_ERR_DESCRIPTOR -137
42 #define USBH_ERR_SET_DEV_ADDR -139
43 #define USBH_ERR_SET_CONFIG -151
45 #define USBH_ERR_TRANSFER -201
46 #define USBH_ERR_TIMEOUT -203
47 #define USBH_ERR_ABORT -205
48 #define USBH_ERR_PORT_RESET -255
49 #define USBH_ERR_SCH_OVERRUN -257
50 #define USBH_ERR_DISCONNECTED -259
52 #define USBH_ERR_TRANSACTION -271
53 #define USBH_ERR_BABBLE_DETECTED -272
54 #define USBH_ERR_DATA_BUFF -274
56 #define USBH_ERR_CC_NO_ERR -280
57 #define USBH_ERR_CRC -281
58 #define USBH_ERR_BIT_STUFF -282
59 #define USBH_ERR_DATA_TOGGLE -283
60 #define USBH_ERR_STALL -284
61 #define USBH_ERR_DEV_NO_RESP -285
62 #define USBH_ERR_PID_CHECK -286
63 #define USBH_ERR_UNEXPECT_PID -287
64 #define USBH_ERR_DATA_OVERRUN -288
65 #define USBH_ERR_DATA_UNDERRUN -289
66 #define USBH_ERR_BUFF_OVERRUN -292
67 #define USBH_ERR_BUFF_UNDERRUN -293
68 #define USBH_ERR_NOT_ACCESS0 -294
69 #define USBH_ERR_NOT_ACCESS1 -295
71 #define USBH_ERR_OHCI_INIT -301
72 #define USBH_ERR_OHCI_EP_BUSY -303
74 #define USBH_ERR_EHCI_INIT -501
75 #define USBH_ERR_EHCI_QH_BUSY -503
77 #define UMAS_OK 0
78 #define UMAS_ERR_NO_DEVICE -1031
79 #define UMAS_ERR_IO -1033
80 #define UMAS_ERR_INIT_DEVICE -1035
81 #define UMAS_ERR_CMD_STATUS -1037
82 #define UMAS_ERR_IVALID_PARM -1038
83 #define UMAS_ERR_DRIVE_NOT_FOUND -1039
85 #define HID_RET_OK 0
86 #define HID_RET_DEV_NOT_FOUND -1081
87 #define HID_RET_IO_ERR -1082
88 #define HID_RET_INVALID_PARAMETER -1083
89 #define HID_RET_OUT_OF_MEMORY -1084
90 #define HID_RET_NOT_SUPPORTED -1085
91 #define HID_RET_EP_NOT_FOUND -1086
92 #define HID_RET_PARSING -1087
93 #define HID_RET_XFER_IS_RUNNING -1089
94 #define HID_RET_REPORT_NOT_FOUND -1090
96 #define UAC_RET_OK 0
97 #define UAC_RET_DEV_NOT_FOUND -2001
98 #define UAC_RET_FUNC_NOT_FOUND -2002
99 #define UAC_RET_IO_ERR -2003
100 #define UAC_RET_DATA_LEN -2004
101 #define UAC_RET_INVALID -2005
102 #define UAC_RET_OUT_OF_MEMORY -2007
103 #define UAC_RET_DRV_NOT_SUPPORTED -2009
104 #define UAC_RET_DEV_NOT_SUPPORTED -2011
105 #define UAC_RET_PARSER -2013
106 #define UAC_RET_IS_STREAMING -2015
109 /* end of group USBH_EXPORTED_CONSTANTS */
110
111
115 struct udev_t;
116 typedef void (CONN_FUNC)(struct udev_t *udev, int param);
117
118 struct line_coding_t;
119 struct cdc_dev_t;
120 typedef void (CDC_CB_FUNC)(struct cdc_dev_t *cdev, uint8_t *rdata, int data_len);
121
122 struct usbhid_dev;
123 typedef void (HID_IR_FUNC)(struct usbhid_dev *hdev, uint16_t ep_addr, int status, uint8_t *rdata, uint32_t data_len);
124 typedef void (HID_IW_FUNC)(struct usbhid_dev *hdev, uint16_t ep_addr, int status, uint8_t *wbuff, uint32_t *data_len);
126 struct uac_dev_t;
127 typedef int (UAC_CB_FUNC)(struct uac_dev_t *dev, uint8_t *data, int len);
129 /* end of group USBH_EXPORTED_STRUCT */
130
131
132
137 /*------------------------------------------------------------------*/
138 /* */
139 /* USB Core Library APIs */
140 /* */
141 /*------------------------------------------------------------------*/
142 extern void usbh_core_init(void);
143 extern int usbh_pooling_hubs(void);
144 extern void usbh_install_conn_callback(CONN_FUNC *conn_func, CONN_FUNC *disconn_func);
145 extern void usbh_suspend(void);
146 extern void usbh_resume(void);
147 extern struct udev_t * usbh_find_device(char *hub_id, int port);
154 extern uint32_t get_ticks(void); /* This function must be provided by user application. */
155
156 /*------------------------------------------------------------------*/
157 /* */
158 /* USB Communication Device Class Library APIs */
159 /* */
160 /*------------------------------------------------------------------*/
161 extern void usbh_cdc_init(void);
162 extern struct cdc_dev_t * usbh_cdc_get_device_list(void);
164 extern int32_t usbh_cdc_get_line_coding(struct cdc_dev_t *cdev, struct line_coding_t *line_code);
165 extern int32_t usbh_cdc_set_line_coding(struct cdc_dev_t *cdev, struct line_coding_t *line_code);
167 extern int32_t usbh_cdc_set_control_line_state(struct cdc_dev_t *cdev, int active_carrier, int DTE_present);
168 extern int32_t usbh_cdc_start_polling_status(struct cdc_dev_t *cdev, CDC_CB_FUNC *func);
169 extern int32_t usbh_cdc_start_to_receive_data(struct cdc_dev_t *cdev, CDC_CB_FUNC *func);
170 extern int32_t usbh_cdc_send_data(struct cdc_dev_t *cdev, uint8_t *buff, int buff_len);
171
172
173 /*------------------------------------------------------------------*/
174 /* */
175 /* USB Human Interface Class Library APIs */
176 /* */
177 /*------------------------------------------------------------------*/
178 extern void usbh_hid_init(void);
179 extern struct usbhid_dev * usbh_hid_get_device_list(void);
180 extern int32_t usbh_hid_get_report_descriptor(struct usbhid_dev *hdev, uint8_t *desc_buf, int buf_max_len);
181 extern int32_t usbh_hid_get_report(struct usbhid_dev *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len);
182 extern int32_t usbh_hid_set_report(struct usbhid_dev *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len);
183 extern int32_t usbh_hid_get_idle(struct usbhid_dev *hdev, int rtp_id, uint8_t *idle_rate);
184 extern int32_t usbh_hid_set_idle(struct usbhid_dev *hdev, int rtp_id, uint8_t idle_rate);
185 extern int32_t usbh_hid_get_protocol(struct usbhid_dev *hdev, uint8_t *protocol);
186 extern int32_t usbh_hid_set_protocol(struct usbhid_dev *hdev, uint8_t protocol);
187 extern int32_t usbh_hid_start_int_read(struct usbhid_dev *hdev, uint8_t ep_addr, HID_IR_FUNC *func);
188 extern int32_t usbh_hid_stop_int_read(struct usbhid_dev *hdev, uint8_t ep_addr);
189 extern int32_t usbh_hid_start_int_write(struct usbhid_dev *hdev, uint8_t ep_addr, HID_IW_FUNC *func);
190 extern int32_t usbh_hid_stop_int_write(struct usbhid_dev *hdev, uint8_t ep_addr);
191
192 /*------------------------------------------------------------------*/
193 /* */
194 /* USB Mass Storage Class Library APIs */
195 /* */
196 /*------------------------------------------------------------------*/
197 extern int usbh_umas_init(void);
198 extern int usbh_umas_disk_status(int drv_no);
199 extern int usbh_umas_read(int drv_no, uint32_t sec_no, int sec_cnt, uint8_t *buff);
200 extern int usbh_umas_write(int drv_no, uint32_t sec_no, int sec_cnt, uint8_t *buff);
201 extern int usbh_umas_ioctl(int drv_no, int cmd, void *buff);
203 extern int usbh_umas_reset_disk(int drv_no);
205 /*------------------------------------------------------------------*/
206 /* */
207 /* USB Audio Class Library APIs */
208 /* */
209 /*------------------------------------------------------------------*/
210 extern void usbh_uac_init(void);
211 extern int usbh_uac_open(struct uac_dev_t *audev);
212 extern struct uac_dev_t * usbh_uac_get_device_list(void);
213 extern int usbh_uac_get_channel_number(struct uac_dev_t *audev, uint8_t target);
214 extern int usbh_uac_get_bit_resolution(struct uac_dev_t *audev, uint8_t target, uint8_t *byte_cnt);
215 extern int usbh_uac_get_sampling_rate(struct uac_dev_t *audev, uint8_t target, uint32_t *srate_list, int max_cnt, uint8_t *type);
216 extern int usbh_uac_sampling_rate_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint32_t *srate);
217 extern int usbh_uac_mute_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint16_t chn, uint8_t *mute);
218 extern int usbh_uac_vol_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint16_t chn, uint16_t *volume);
219 extern int usbh_uac_auto_gain_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint16_t chn, uint8_t *bAGC);
220 extern int usbh_uac_start_audio_in(struct uac_dev_t *uac, UAC_CB_FUNC *func);
221 extern int usbh_uac_stop_audio_in(struct uac_dev_t *audev);
222 extern int usbh_uac_start_audio_out(struct uac_dev_t *uac, UAC_CB_FUNC *func);
223 extern int usbh_uac_stop_audio_out(struct uac_dev_t *audev);
224
225
227
228 extern void dump_ohci_regs(void);
229 extern void dump_ehci_regs(void);
230 extern void dump_ohci_ports(void);
231 extern void dump_ehci_ports(void);
232 extern uint32_t usbh_memory_used(void);
233
235
236 /* end of group USBH_EXPORTED_FUNCTIONS */
238 /* end of group USBH_Library */
240 /* end of group LIBRARY */
242
243 #ifdef __cplusplus
244 }
245 #endif
246
247 #endif /* _USBH_LIB_H_ */
248
249 /*** (C) COPYRIGHT 2017 Nuvoton Technology Corp. ***/
250
251
252
usbh_hid_get_report_descriptor
int32_t usbh_hid_get_report_descriptor(struct usbhid_dev *hdev, uint8_t *desc_buf, int buf_max_len)
usbh_uac_get_device_list
struct uac_dev_t * usbh_uac_get_device_list(void)
Get a list of currently connected USB Audio Class devices.
Definition: uac_driver.c:266
usbh_core_init
void usbh_core_init(void)
Initialize M480 USB Host controller and USB stack.
Definition: usb_core.c:39
usbh_cdc_send_data
int32_t usbh_cdc_send_data(struct cdc_dev_t *cdev, uint8_t *buff, int buff_len)
Send a block of data via CDC device's bulk-out transfer pipe.
Definition: cdc_core.c:383
UAC_CB_FUNC
int() UAC_CB_FUNC(struct uac_dev_t *dev, uint8_t *data, int len)
Definition: usbh_lib.h:127
usbh_hid_get_device_list
struct usbhid_dev * usbh_hid_get_device_list(void)
Get a list of currently connected USB Hid devices.
Definition: hid_driver.c:225
usbh_cdc_set_line_coding
int32_t usbh_cdc_set_line_coding(CDC_DEV_T *cdev, LINE_CODING_T *line_code)
SET_LINE_CODING request.
Definition: cdc_core.c:85
usbh_uac_get_channel_number
int usbh_uac_get_channel_number(struct uac_dev_t *audev, uint8_t target)
Obtain Audio Class device's channel number.
Definition: uac_core.c:44
usbh_uac_stop_audio_in
int usbh_uac_stop_audio_in(struct uac_dev_t *audev)
Stop UAC device audio in data stream.
Definition: uac_core.c:703
usbh_suspend
void usbh_suspend(void)
Suspend USB Host Controller and devices.
Definition: usb_core.c:115
usbh_install_conn_callback
void usbh_install_conn_callback(CONN_FUNC *conn_func, CONN_FUNC *disconn_func)
Install device connect and disconnect callback function.
Definition: usb_core.c:86
HID_IR_FUNC
void() HID_IR_FUNC(struct usbhid_dev *hdev, uint16_t ep_addr, int status, uint8_t *rdata, uint32_t data_len)
Definition: usbh_lib.h:123
NuMicro.h
NuMicro peripheral access layer header file.
usbh_pooling_hubs
int usbh_pooling_hubs(void)
Let USB stack polls all root hubs and downstream hubs. If there's any hub port change found,...
Definition: hub.c:637
usbh_cdc_start_to_receive_data
int32_t usbh_cdc_start_to_receive_data(struct cdc_dev_t *cdev, CDC_CB_FUNC *func)
Make CDC device start to receive data from bulk-in transfer pipe.
Definition: cdc_core.c:306
uac_dev_t
Definition: usbh_uac.h:109
usbh_hid_init
void usbh_hid_init(void)
Initialize USB Host HID driver.
Definition: hid_driver.c:209
usbh_umas_ioctl
int usbh_umas_ioctl(int drv_no, int cmd, void *buff)
usbh_uac_get_sampling_rate
int usbh_uac_get_sampling_rate(struct uac_dev_t *audev, uint8_t target, uint32_t *srate_list, int max_cnt, uint8_t *type)
Get a list of sampling rate frequencies supported by the UAC device.
Definition: uac_core.c:116
usbh_uac_vol_control
int usbh_uac_vol_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint16_t chn, uint16_t *volume)
Audio Class device volume control.
Definition: uac_core.c:323
usbh_uac_open
int usbh_uac_open(struct uac_dev_t *audev)
Open an connected UAC device.
Definition: uac_core.c:997
usbh_umas_disk_status
int usbh_umas_disk_status(int drv_no)
usbh_uac_start_audio_in
int usbh_uac_start_audio_in(struct uac_dev_t *uac, UAC_CB_FUNC *func)
Start to receive audio data from UAC device. (Microphone)
Definition: uac_core.c:554
usbh_hid_get_report
int32_t usbh_hid_get_report(struct usbhid_dev *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len)
usbh_umas_write
int usbh_umas_write(int drv_no, uint32_t sec_no, int sec_cnt, uint8_t *buff)
usbh_cdc_set_control_line_state
HIDDEN_SYMBOLS int32_t usbh_cdc_set_control_line_state(struct cdc_dev_t *cdev, int active_carrier, int DTE_present)
SET_CONTROL_LINE_STATE request.
Definition: cdc_core.c:135
usbh_uac_mute_control
int usbh_uac_mute_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint16_t chn, uint8_t *mute)
Control Audio Class device mute on/off.
Definition: uac_core.c:240
usbh_hid_start_int_write
int32_t usbh_hid_start_int_write(struct usbhid_dev *hdev, uint8_t ep_addr, HID_IW_FUNC *func)
usbh_hid_start_int_read
int32_t usbh_hid_start_int_read(struct usbhid_dev *hdev, uint8_t ep_addr, HID_IR_FUNC *func)
CONN_FUNC
void() CONN_FUNC(struct udev_t *udev, int param)
Definition: usbh_lib.h:116
get_ticks
uint32_t get_ticks(void)
A function return current tick count.
HID_IW_FUNC
void() HID_IW_FUNC(struct usbhid_dev *hdev, uint16_t ep_addr, int status, uint8_t *wbuff, uint32_t *data_len)
Definition: usbh_lib.h:124
usbh_uac_start_audio_out
int usbh_uac_start_audio_out(struct uac_dev_t *uac, UAC_CB_FUNC *func)
Start to transmit audio data to UAC device. (Speaker)
Definition: uac_core.c:796
usbh_hid_set_protocol
int32_t usbh_hid_set_protocol(struct usbhid_dev *hdev, uint8_t protocol)
usbh_umas_read
int usbh_umas_read(int drv_no, uint32_t sec_no, int sec_cnt, uint8_t *buff)
usbh_hid_stop_int_write
int32_t usbh_hid_stop_int_write(struct usbhid_dev *hdev, uint8_t ep_addr)
usbh_uac_init
HIDDEN_SYMBOLS void usbh_uac_init(void)
Initialize USB Audio Class driver.
Definition: uac_driver.c:250
usbh_hid_get_protocol
int32_t usbh_hid_get_protocol(struct usbhid_dev *hdev, uint8_t *protocol)
usbhid_dev
Definition: usbh_hid.h:264
usbh_cdc_get_line_coding
int32_t usbh_cdc_get_line_coding(CDC_DEV_T *cdev, LINE_CODING_T *line_code)
GET_LINE_CODING request.
Definition: cdc_core.c:46
usbh_uac_stop_audio_out
int usbh_uac_stop_audio_out(struct uac_dev_t *audev)
Stop UAC device audio out data stream.
Definition: uac_core.c:946
usbh_cdc_get_device_list
struct cdc_dev_t * usbh_cdc_get_device_list(void)
Get a list of currently connected USB Hid devices.
Definition: cdc_driver.c:280
usbh_hid_stop_int_read
int32_t usbh_hid_stop_int_read(struct usbhid_dev *hdev, uint8_t ep_addr)
usbh_cdc_start_polling_status
int32_t usbh_cdc_start_polling_status(struct cdc_dev_t *cdev, CDC_CB_FUNC *func)
Start purge the CDC device's interrupt-in transfer pipe.
Definition: cdc_core.c:213
usbh_hid_get_idle
int32_t usbh_hid_get_idle(struct usbhid_dev *hdev, int rtp_id, uint8_t *idle_rate)
usbh_uac_get_bit_resolution
int usbh_uac_get_bit_resolution(struct uac_dev_t *audev, uint8_t target, uint8_t *byte_cnt)
Obtain Audio Class device subframe bit resolution..
Definition: uac_core.c:71
usbh_uac_sampling_rate_control
int usbh_uac_sampling_rate_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint32_t *srate)
Set sampling rate frequency.
Definition: uac_core.c:169
usbh_uac_auto_gain_control
int usbh_uac_auto_gain_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint16_t chn, uint8_t *bAGC)
Audio Class device automatic gain control.
Definition: uac_core.c:385
usbh_hid_set_report
int32_t usbh_hid_set_report(struct usbhid_dev *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len)
usbh_find_device
struct udev_t * usbh_find_device(char *hub_id, int port)
Find the device under the specified hub port.
Definition: hub.c:685
CDC_CB_FUNC
void() CDC_CB_FUNC(struct cdc_dev_t *cdev, uint8_t *rdata, int data_len)
Definition: usbh_lib.h:120
usbh_resume
void usbh_resume(void)
Resume USB Host controller and devices.
Definition: usb_core.c:176
usbh_umas_init
int usbh_umas_init(void)
Register and initialize USB Host Mass Storage driver.
Definition: msc_driver.c:631
cdc_dev_t
Definition: usbh_cdc.h:175
usbh_hid_set_idle
int32_t usbh_hid_set_idle(struct usbhid_dev *hdev, int rtp_id, uint8_t idle_rate)
usbh_cdc_init
void usbh_cdc_init(void)
Init USB Host CDC driver.
Definition: cdc_driver.c:265