1 /*
2  * ===========================================================================================
3  *
4  *       Filename:  sunxi_usb_common.h
5  *
6  *    Description:  USB HAL definition.
7  * ===========================================================================================
8  */
9 #ifndef SUNXI_HAL_UDC_H
10 #define SUNXI_HAL_UDC_H
11 
12 #include <stdint.h>
13 #include "ch9.h"
14 
15 typedef enum {
16     UDC_EVENT_RX_STANDARD_REQUEST = 1,
17     UDC_EVENT_RX_CLASS_REQUEST = 2,
18     UDC_EVENT_RX_DATA = 3,
19     UDC_EVENT_TX_COMPLETE = 4,
20 } udc_callback_event_t;
21 
22 typedef enum {
23     UDC_ERRNO_SUCCESS = 0,
24     UDC_ERRNO_CMD_NOT_SUPPORTED = -1,
25     UDC_ERRNO_CMD_INVALID = -2,
26     UDC_ERRNO_BUF_NULL = -3,
27     UDC_ERRNO_BUF_FULL = -4,
28     UDC_ERRNO_EP_INVALID = -5,
29     UDC_ERRNO_RX_NOT_READY = -6,
30     UDC_ERRNO_TX_BUSY = -7,
31 } udc_errno_t;
32 
33 typedef udc_errno_t (*udc_callback_t)(uint8_t ep_addr, udc_callback_event_t event,
34                 void *data, uint32_t len);
35 
36 int32_t hal_udc_init(void);
37 int32_t hal_udc_deinit(void);
38 int32_t hal_udc_enter_test_mode(uint32_t test_mode);
39 void hal_udc_device_desc_init(struct usb_device_descriptor *device_desc);
40 void hal_udc_config_desc_init(void *config_desc, uint32_t len);
41 void hal_udc_string_desc_init(const void *string_desc);
42 void hal_udc_register_callback(udc_callback_t user_callback);
43 int32_t hal_udc_ep_read(uint8_t ep_addr, void *buf, uint32_t len);
44 int32_t hal_udc_ep_write(uint8_t ep_addr, void *buf , uint32_t len);
45 void hal_udc_ep_enable(uint8_t ep_addr, uint16_t maxpacket, uint32_t ts_type);
46 void hal_udc_ep_disable(uint8_t ep_addr);
47 void hal_udc_ep_set_buf(uint8_t ep_addr, void *buf, uint32_t len);
48 ssize_t ed_test(const char *buf, size_t count);
49 ssize_t hal_udc_driverlevel_adjust(int driverlevel);
50 #endif
51