M471M/R1/S BSP V3.01.000
The Board Support Package for M4521
usbh_lib.h
Go to the documentation of this file.
1/**************************************************************************/
8#ifndef _USBH_LIB_H_
9#define _USBH_LIB_H_
10
11#include "NuMicro.h"
12
13#ifdef __cplusplus
14extern "C"
15{
16#endif
17
30#define USBH_OK 0
31#define USBH_ERR_MEMORY_OUT -10
32#define USBH_ERR_IF_ALT_LIMIT -11
33#define USBH_ERR_IF_EP_LIMIT -15
34#define USBH_ERR_NOT_SUPPORTED -101
35#define USBH_ERR_NOT_MATCHED -103
36#define USBH_ERR_NOT_EXPECTED -104
37#define USBH_ERR_INVALID_PARAM -105
38#define USBH_ERR_NOT_FOUND -106
39#define USBH_ERR_EP_NOT_FOUND -107
40#define USBH_ERR_DESCRIPTOR -137
41#define USBH_ERR_SET_DEV_ADDR -139
42#define USBH_ERR_SET_CONFIG -151
44#define USBH_ERR_TRANSFER -201
45#define USBH_ERR_TIMEOUT -203
46#define USBH_ERR_ABORT -205
47#define USBH_ERR_PORT_RESET -255
48#define USBH_ERR_SCH_OVERRUN -257
49#define USBH_ERR_DISCONNECTED -259
51#define USBH_ERR_TRANSACTION -271
52#define USBH_ERR_BABBLE_DETECTED -272
53#define USBH_ERR_DATA_BUFF -274
55#define USBH_ERR_CC_NO_ERR -280
56#define USBH_ERR_CRC -281
57#define USBH_ERR_BIT_STUFF -282
58#define USBH_ERR_DATA_TOGGLE -283
59#define USBH_ERR_STALL -284
60#define USBH_ERR_DEV_NO_RESP -285
61#define USBH_ERR_PID_CHECK -286
62#define USBH_ERR_UNEXPECT_PID -287
63#define USBH_ERR_DATA_OVERRUN -288
64#define USBH_ERR_DATA_UNDERRUN -289
65#define USBH_ERR_BUFF_OVERRUN -292
66#define USBH_ERR_BUFF_UNDERRUN -293
67#define USBH_ERR_NOT_ACCESS0 -294
68#define USBH_ERR_NOT_ACCESS1 -295
70#define USBH_ERR_OHCI_INIT -301
71#define USBH_ERR_OHCI_EP_BUSY -303
73#define USBH_ERR_EHCI_INIT -501
74#define USBH_ERR_EHCI_QH_BUSY -503
76#define UMAS_OK 0
77#define UMAS_ERR_NO_DEVICE -1031
78#define UMAS_ERR_IO -1033
79#define UMAS_ERR_INIT_DEVICE -1035
80#define UMAS_ERR_CMD_STATUS -1037
81#define UMAS_ERR_IVALID_PARM -1038
82#define UMAS_ERR_DRIVE_NOT_FOUND -1039
84#define HID_RET_OK 0
85#define HID_RET_DEV_NOT_FOUND -1081
86#define HID_RET_IO_ERR -1082
87#define HID_RET_INVALID_PARAMETER -1083
88#define HID_RET_OUT_OF_MEMORY -1084
89#define HID_RET_NOT_SUPPORTED -1085
90#define HID_RET_EP_NOT_FOUND -1086
91#define HID_RET_PARSING -1087
92#define HID_RET_XFER_IS_RUNNING -1089
93#define HID_RET_REPORT_NOT_FOUND -1090
95#define UAC_RET_OK 0
96#define UAC_RET_DEV_NOT_FOUND -2001
97#define UAC_RET_FUNC_NOT_FOUND -2002
98#define UAC_RET_IO_ERR -2003
99#define UAC_RET_DATA_LEN -2004
100#define UAC_RET_INVALID -2005
101#define UAC_RET_OUT_OF_MEMORY -2007
102#define UAC_RET_DRV_NOT_SUPPORTED -2009
103#define UAC_RET_DEV_NOT_SUPPORTED -2011
104#define UAC_RET_PARSER -2013
105#define UAC_RET_IS_STREAMING -2015 /* end of group USBH_EXPORTED_CONSTANTS */
109
110
114struct udev_t;
115typedef void (CONN_FUNC)(struct udev_t *udev, int param);
116
117struct line_coding_t;
118struct cdc_dev_t;
119typedef void (CDC_CB_FUNC)(struct cdc_dev_t *cdev, uint8_t *rdata, int data_len);
120
121struct usbhid_dev;
122typedef void (HID_IR_FUNC)(struct usbhid_dev *hdev, uint16_t ep_addr, int status, uint8_t *rdata, uint32_t data_len);
123typedef void (HID_IW_FUNC)(struct usbhid_dev *hdev, uint16_t ep_addr, int status, uint8_t *wbuff, uint32_t *data_len);
125struct uac_dev_t;
126typedef int (UAC_CB_FUNC)(struct uac_dev_t *dev, uint8_t *data, int len); /* end of group USBH_EXPORTED_STRUCT */
129
130
131
136/*------------------------------------------------------------------*/
137/* */
138/* USB Core Library APIs */
139/* */
140/*------------------------------------------------------------------*/
141extern void usbh_core_init(void);
142extern int usbh_pooling_hubs(void);
143extern void usbh_install_conn_callback(CONN_FUNC *conn_func, CONN_FUNC *disconn_func);
144extern void usbh_suspend(void);
145extern void usbh_resume(void);
146extern struct udev_t * usbh_find_device(char *hub_id, int port);
153extern uint32_t get_ticks(void); /* This function must be provided by user application. */
154
155/*------------------------------------------------------------------*/
156/* */
157/* USB Communication Device Class Library APIs */
158/* */
159/*------------------------------------------------------------------*/
160extern void usbh_cdc_init(void);
161extern struct cdc_dev_t * usbh_cdc_get_device_list(void);
163extern int32_t usbh_cdc_get_line_coding(struct cdc_dev_t *cdev, struct line_coding_t *line_code);
164extern int32_t usbh_cdc_set_line_coding(struct cdc_dev_t *cdev, struct line_coding_t *line_code);
166extern int32_t usbh_cdc_set_control_line_state(struct cdc_dev_t *cdev, int active_carrier, int DTE_present);
167extern int32_t usbh_cdc_start_polling_status(struct cdc_dev_t *cdev, CDC_CB_FUNC *func);
168extern int32_t usbh_cdc_start_to_receive_data(struct cdc_dev_t *cdev, CDC_CB_FUNC *func);
169extern int32_t usbh_cdc_send_data(struct cdc_dev_t *cdev, uint8_t *buff, int buff_len);
170
171
172/*------------------------------------------------------------------*/
173/* */
174/* USB Human Interface Class Library APIs */
175/* */
176/*------------------------------------------------------------------*/
177extern void usbh_hid_init(void);
178extern struct usbhid_dev * usbh_hid_get_device_list(void);
179extern int32_t usbh_hid_get_report_descriptor(struct usbhid_dev *hdev, uint8_t *desc_buf, int buf_max_len);
180extern int32_t usbh_hid_get_report(struct usbhid_dev *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len);
181extern int32_t usbh_hid_set_report(struct usbhid_dev *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len);
182extern int32_t usbh_hid_get_idle(struct usbhid_dev *hdev, int rtp_id, uint8_t *idle_rate);
183extern int32_t usbh_hid_set_idle(struct usbhid_dev *hdev, int rtp_id, uint8_t idle_rate);
184extern int32_t usbh_hid_get_protocol(struct usbhid_dev *hdev, uint8_t *protocol);
185extern int32_t usbh_hid_set_protocol(struct usbhid_dev *hdev, uint8_t protocol);
186extern int32_t usbh_hid_start_int_read(struct usbhid_dev *hdev, uint8_t ep_addr, HID_IR_FUNC *func);
187extern int32_t usbh_hid_stop_int_read(struct usbhid_dev *hdev, uint8_t ep_addr);
188extern int32_t usbh_hid_start_int_write(struct usbhid_dev *hdev, uint8_t ep_addr, HID_IW_FUNC *func);
189extern int32_t usbh_hid_stop_int_write(struct usbhid_dev *hdev, uint8_t ep_addr);
190
191/*------------------------------------------------------------------*/
192/* */
193/* USB Mass Storage Class Library APIs */
194/* */
195/*------------------------------------------------------------------*/
196extern int usbh_umas_init(void);
197extern int usbh_umas_disk_status(int drv_no);
198extern int usbh_umas_read(int drv_no, uint32_t sec_no, int sec_cnt, uint8_t *buff);
199extern int usbh_umas_write(int drv_no, uint32_t sec_no, int sec_cnt, uint8_t *buff);
200extern int usbh_umas_ioctl(int drv_no, int cmd, void *buff);
202extern int usbh_umas_reset_disk(int drv_no);
204/*------------------------------------------------------------------*/
205/* */
206/* USB Audio Class Library APIs */
207/* */
208/*------------------------------------------------------------------*/
209extern void usbh_uac_init(void);
210extern int usbh_uac_open(struct uac_dev_t *audev);
211extern struct uac_dev_t * usbh_uac_get_device_list(void);
212extern int usbh_uac_get_channel_number(struct uac_dev_t *audev, uint8_t target);
213extern int usbh_uac_get_bit_resolution(struct uac_dev_t *audev, uint8_t target, uint8_t *byte_cnt);
214extern int usbh_uac_get_sampling_rate(struct uac_dev_t *audev, uint8_t target, uint32_t *srate_list, int max_cnt, uint8_t *type);
215extern int usbh_uac_sampling_rate_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint32_t *srate);
216extern int usbh_uac_mute_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint16_t chn, uint8_t *mute);
217extern int usbh_uac_vol_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint16_t chn, uint16_t *volume);
218extern int usbh_uac_auto_gain_control(struct uac_dev_t *audev, uint8_t target, uint8_t req, uint16_t chn, uint8_t *bAGC);
219extern int usbh_uac_start_audio_in(struct uac_dev_t *uac, UAC_CB_FUNC *func);
220extern int usbh_uac_stop_audio_in(struct uac_dev_t *audev);
221extern int usbh_uac_start_audio_out(struct uac_dev_t *uac, UAC_CB_FUNC *func);
222extern int usbh_uac_stop_audio_out(struct uac_dev_t *audev);
223
224
226
227extern void dump_ohci_regs(void);
228extern void dump_ehci_regs(void);
229extern void dump_ohci_ports(void);
230extern void dump_ehci_ports(void);
231extern uint32_t usbh_memory_used(void);
232
234
235 /* end of group USBH_EXPORTED_FUNCTIONS */
237 /* end of group USBH_Library */
239 /* end of group LIBRARY */
241
242#ifdef __cplusplus
243}
244#endif
245
246#endif /* _USBH_LIB_H_ */
247
248
249
250
251
NuMicro peripheral access layer header file.
int32_t usbh_cdc_set_line_coding(CDC_DEV_T *cdev, LINE_CODING_T *line_code)
SET_LINE_CODING request.
Definition: cdc_core.c:87
int32_t usbh_cdc_get_line_coding(CDC_DEV_T *cdev, LINE_CODING_T *line_code)
GET_LINE_CODING request.
Definition: cdc_core.c:49
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:384
int usbh_uac_stop_audio_out(struct uac_dev_t *audev)
Stop UAC device audio out data stream.
Definition: uac_core.c:944
int32_t usbh_hid_stop_int_read(struct usbhid_dev *hdev, uint8_t ep_addr)
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:167
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:42
int32_t usbh_hid_start_int_write(struct usbhid_dev *hdev, uint8_t ep_addr, HID_IW_FUNC *func)
int32_t usbh_hid_get_protocol(struct usbhid_dev *hdev, uint8_t *protocol)
int32_t usbh_hid_set_protocol(struct usbhid_dev *hdev, uint8_t protocol)
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:137
void usbh_suspend(void)
Suspend USB Host Controller and devices.
Definition: usb_core.c:95
int usbh_uac_stop_audio_in(struct uac_dev_t *audev)
Stop UAC device audio in data stream.
Definition: uac_core.c:701
struct usbhid_dev * usbh_hid_get_device_list(void)
Get a list of currently connected USB Hid devices.
Definition: hid_driver.c:224
struct udev_t * usbh_find_device(char *hub_id, int port)
Find the device under the specified hub port.
Definition: hub.c:670
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:636
int32_t usbh_hid_get_report_descriptor(struct usbhid_dev *hdev, uint8_t *desc_buf, int buf_max_len)
int usbh_uac_open(struct uac_dev_t *audev)
Open an connected UAC device.
Definition: uac_core.c:995
int32_t usbh_hid_start_int_read(struct usbhid_dev *hdev, uint8_t ep_addr, HID_IR_FUNC *func)
void usbh_cdc_init(void)
Init USB Host CDC driver.
Definition: cdc_driver.c:264
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:321
struct cdc_dev_t * usbh_cdc_get_device_list(void)
Get a list of currently connected USB Hid devices.
Definition: cdc_driver.c:279
int usbh_umas_read(int drv_no, uint32_t sec_no, int sec_cnt, uint8_t *buff)
int32_t usbh_hid_get_idle(struct usbhid_dev *hdev, int rtp_id, uint8_t *idle_rate)
int usbh_umas_write(int drv_no, uint32_t sec_no, int sec_cnt, uint8_t *buff)
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:214
int32_t usbh_hid_get_report(struct usbhid_dev *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len)
int usbh_umas_init(void)
Register and initialize USB Host Mass Storage driver.
Definition: msc_driver.c:630
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:794
void usbh_core_init(void)
Initialize M471M/R1/S USB Host controller and USB stack.
Definition: usb_core.c:37
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:69
void usbh_install_conn_callback(CONN_FUNC *conn_func, CONN_FUNC *disconn_func)
Install device connect and disconnect callback function.
Definition: usb_core.c:70
int usbh_umas_ioctl(int drv_no, int cmd, void *buff)
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:383
int32_t usbh_hid_set_idle(struct usbhid_dev *hdev, int rtp_id, uint8_t idle_rate)
int usbh_umas_disk_status(int drv_no)
struct uac_dev_t * usbh_uac_get_device_list(void)
Get a list of currently connected USB Audio Class devices.
Definition: uac_driver.c:264
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:114
void usbh_hid_init(void)
Initialize USB Host HID driver.
Definition: hid_driver.c:208
int32_t usbh_hid_set_report(struct usbhid_dev *hdev, int rtp_typ, int rtp_id, uint8_t *data, int len)
uint32_t get_ticks(void)
A function return current tick count.
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:238
int32_t usbh_cdc_start_to_receive_data(struct cdc_dev_t *cdev, CDC_CB_FUNC *func)
HIDDEN_SYMBOLS.
Definition: cdc_core.c:307
int32_t usbh_hid_stop_int_write(struct usbhid_dev *hdev, uint8_t ep_addr)
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:552
void usbh_resume(void)
Resume USB Host controller and devices.
Definition: usb_core.c:121
HIDDEN_SYMBOLS void usbh_uac_init(void)
Initialize USB Audio Class driver.
Definition: uac_driver.c:248
void() CDC_CB_FUNC(struct cdc_dev_t *cdev, uint8_t *rdata, int data_len)
Definition: usbh_lib.h:119
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:122
int() UAC_CB_FUNC(struct uac_dev_t *dev, uint8_t *data, int len)
Definition: usbh_lib.h:126
void() CONN_FUNC(struct udev_t *udev, int param)
Definition: usbh_lib.h:115
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:123