pure sdk for main
This commit is contained in:
@@ -0,0 +1,267 @@
|
||||
/*****************************************************************************
|
||||
* Module : usb
|
||||
* File : usb.c
|
||||
* Author :
|
||||
* Function : USB驱动的一些公用模块
|
||||
*****************************************************************************/
|
||||
#ifndef USB_H
|
||||
#define USB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//typedef int8 bool;
|
||||
|
||||
#define MAX_EP 2 //最大的EP号
|
||||
|
||||
//in IC, in latest FPGA
|
||||
#define USB_FIX_BUG_0 0 //=0, =1
|
||||
#define USB_FIX_BUG_1 0 //=1, =1
|
||||
#define USB_FIX_BUG_2 0 //=0, =1
|
||||
#define USB_FIX_BUG_3 0 //=0, =1
|
||||
#define USB_FIX_BUG_4 0 //=0, =1
|
||||
|
||||
#define UCFG2_CNT 0x2000
|
||||
//USB SIE REG(common)
|
||||
#define M_FADDR 0x00
|
||||
#define M_POWER 0x01
|
||||
#define M_INTRTX1 0x02
|
||||
#define M_INTRTX2 0x03
|
||||
#define M_INTRRX1 0x04
|
||||
#define M_INTRRX2 0x05
|
||||
#define M_INTRUSB 0x06
|
||||
#define M_INTRTX1E 0x07
|
||||
#define M_INTRTX2E 0x08
|
||||
#define M_INTRRX1E 0x09
|
||||
#define M_INTRRX2E 0x0A
|
||||
#define M_INTRUSBE 0x0B
|
||||
#define M_FRAMENUM1 0x0C
|
||||
#define M_FRAMENUM2 0x0D
|
||||
#define M_INDEX 0x0E
|
||||
#define M_DEVCTL 0x0F
|
||||
//USB SIE REG(host & slave)
|
||||
#define M_TXMAXP 0x10
|
||||
#define M_CSR0 0x11
|
||||
#define M_TXCSR1 0x11
|
||||
#define M_TXCSR2 0x12
|
||||
#define M_RXMAXP 0x13
|
||||
#define M_RXCSR1 0x14
|
||||
#define M_RXCSR2 0x15
|
||||
#define M_COUNT0 0x16
|
||||
#define M_RXCOUNT1 0x16
|
||||
#define M_RXCOUNT2 0x17
|
||||
#define M_TXTYPE 0x18
|
||||
#define M_TXINTERVAL 0x19
|
||||
#define M_RXTYPE 0x1A
|
||||
#define M_RXINTERVAL 0x1B
|
||||
|
||||
#define M_FIFOSIZE 0x1F
|
||||
|
||||
|
||||
#define M_FIFO0 0x20 //FIFOS for endpoint0
|
||||
#define M_FIFO1 0x24 //FIFOS for endpoint1
|
||||
#define M_FIFO2 0x28 //FIFOS for endpoint2
|
||||
|
||||
/* Interrupt register bit */
|
||||
#define M_INTR_SUSPEND 0x01
|
||||
#define M_INTR_RESUME 0x02
|
||||
#define M_INTR_RESET 0x04
|
||||
#define M_INTR_SOF 0x08
|
||||
#define M_INTR_CONNECT 0x10
|
||||
#define M_INTR_DIS_CONNECT 0x20
|
||||
#define M_INTR_SESS_REQ 0x40
|
||||
#define M_INTR_VBUS_ERR 0x80
|
||||
|
||||
///USB DMA1_CTL/DMA2_CTL
|
||||
#define UDC_BUS_ERR (1<<15)
|
||||
#define UDC_MAXPKT_8BYTE(n) (((n)&0x7F)<<8)
|
||||
#define UDC_EP(n) (((n)&0xF)<<4)
|
||||
#define UDC_IE (1<<3)
|
||||
#define UDC_MODE(n) (((n)&0x1)<<2)
|
||||
#define UDC_DIR_RX ((0)<<1)
|
||||
#define UDC_DIR_TX ((1)<<1)
|
||||
#define UDC_EN ((1)<<0)
|
||||
|
||||
///UCFG1
|
||||
#define DMA4_MASK (1<<22)
|
||||
#define DMA3_MASK (1<<21)
|
||||
#define DMA2_MASK (1<<20)
|
||||
#define DMA1_MASK (1<<19)
|
||||
#define VBUS_Error_MASK (1<<18)
|
||||
#define Sess_Req_MASK (1<<17)
|
||||
#define Discon_MASK (1<<16)
|
||||
#define Conn_MASK (1<<15)
|
||||
#define Reset_MASK (1<<14)
|
||||
#define Resume_MASK (1<<13)
|
||||
#define Suspend_MASK (1<<12)
|
||||
#define EP2TX_MASK (1<<11)
|
||||
#define EP1TX_MASK (1<<10)
|
||||
#define EP0_MASK (1<<9)
|
||||
#define EP2RX_MASK (1<<8)
|
||||
#define EP1RX_MASK (1<<7)
|
||||
#define SOF_MASK (1<<6)
|
||||
|
||||
#define USB_DIF (1<<3)
|
||||
#define USB_DIM (1<<2)
|
||||
#define USB_DIP (1<<1)
|
||||
#define USB_TM1 (1<<0) ///0: normal mode 1:testmode, shorter time for simulation
|
||||
|
||||
#define USBIE_EN() //NVIC_EnableIRQ(USB_CTL_IRQn);
|
||||
#define USBIE_DIS() //NVIC_DisableIRQ(USB_CTL_IRQn);
|
||||
|
||||
#define USB_REG_CRITICAL_ENTER() //osMutexWait(usb_reg_lock_id, osWaitForever);
|
||||
#define USB_REG_CRITICAL_EXIT() //osMutexRelease(usb_reg_lock_id);
|
||||
|
||||
//写USB SIE寄存器
|
||||
#define write_usb_reg(reg_addr, reg_data) do {p_dev->usb_hw->SIE##reg_addr = reg_data;} while(0)
|
||||
//void write_usb_reg_index(uint8_t index, uint32_t reg_addr, uint8_t reg_data);
|
||||
#define write_usb_reg_index(index, reg_addr, reg_data)\
|
||||
do {\
|
||||
USB_REG_CRITICAL_ENTER();\
|
||||
p_dev->usb_hw->SIEM_INDEX = index;\
|
||||
*((volatile uint8_t *)((uint32_t)&p_dev->usb_hw->SIEM_FADDR + reg_addr)) = reg_data;\
|
||||
USB_REG_CRITICAL_EXIT();\
|
||||
} while(0)
|
||||
|
||||
|
||||
//读USB SIE寄存器
|
||||
#define read_usb_reg(reg_addr) (p_dev->usb_hw->SIE##reg_addr)
|
||||
//uint8_t read_usb_reg_index(uint8_t index, uint32_t reg_addr);
|
||||
#define read_usb_reg_index(index, reg_addr, reg_data)\
|
||||
do {\
|
||||
USB_REG_CRITICAL_ENTER();\
|
||||
p_dev->usb_hw->SIEM_INDEX = index;\
|
||||
reg_data = *((volatile uint8_t *)((uint32_t)&p_dev->usb_hw->SIEM_FADDR + reg_addr));\
|
||||
USB_REG_CRITICAL_EXIT();\
|
||||
} while(0)
|
||||
|
||||
|
||||
|
||||
|
||||
//USB当前状态机
|
||||
enum {
|
||||
USB_DEFAULT_STATE,
|
||||
USB_ADDRESS_STATE,
|
||||
USB_CONFIG_STATE
|
||||
};
|
||||
|
||||
//EP0状态机
|
||||
enum {
|
||||
IDLE_STATE,
|
||||
TRANSER_OVER_STATE,
|
||||
TRANSFERING_STATE,
|
||||
RECEIVING_STATE
|
||||
};
|
||||
|
||||
//接收者
|
||||
enum {
|
||||
REQUEST_TO_DEVICE,
|
||||
REQUEST_TO_INTERFACE,
|
||||
REQUEST_TO_ENDPOINT
|
||||
};
|
||||
|
||||
//设备描述符
|
||||
enum {
|
||||
DEVICE_DESCRIPTOR = 1,
|
||||
CONFIGURATION_DESCRIPTOR,
|
||||
STRING_DESCRIPTOR,
|
||||
INTERFACE_DESCRIPTOR,
|
||||
ENDPOINT_DESCRIPTOR,
|
||||
DEVICE_QUALIFIER_DESCRIPTOR,
|
||||
// OTHER_SPEED_CONFIG_DESCRIPTOR, USB 1.1没有该选项
|
||||
|
||||
HID_REPORT = 0x22,
|
||||
};
|
||||
|
||||
//Feature Selector
|
||||
enum {
|
||||
ENDPOINT_STALL,
|
||||
REMOTE_WAKEUP,
|
||||
TEST_MODE
|
||||
};
|
||||
|
||||
//检测模式
|
||||
enum {
|
||||
USB_CHECK_HOST, //尝试主机检测
|
||||
USB_CHECK_OTG, //尝试OTG检测,是否连接PC
|
||||
USB_STABLE_HOST, //已成功检测为USB主机
|
||||
USB_STABLE_DEVICE, //已成功检测为USB设备
|
||||
};
|
||||
|
||||
//返回值
|
||||
enum {
|
||||
USB_CONNECTED_NONE, //未连接
|
||||
USB_CONNECTED_PC, //连接PC,当Device
|
||||
USB_CONNECTED_DEVICE, //外接U盘,当Host
|
||||
};
|
||||
|
||||
//USB控制结构体
|
||||
struct hgusb11_dev_ctrl {
|
||||
uint8_t error; //USB通信错误
|
||||
|
||||
struct {
|
||||
uint16_t vid; //VID
|
||||
uint16_t pid; //PID
|
||||
uint16_t ver; //Version
|
||||
} info;
|
||||
|
||||
//EP0接收的命令
|
||||
struct {
|
||||
uint8_t rtype;
|
||||
uint8_t request;
|
||||
uint16_t value;
|
||||
uint16_t index;
|
||||
uint16_t length;
|
||||
} cmd;
|
||||
|
||||
uint8_t reserved[2];
|
||||
};
|
||||
|
||||
struct hgusb11_dev_chk {
|
||||
uint8_t check_mode;
|
||||
uint8_t check_cnt;
|
||||
uint8_t check_delay;
|
||||
} ;
|
||||
|
||||
|
||||
#define BYTE0(n) ((uint8_t)((uint16_t)(n)))
|
||||
#define BYTE1(n) ((uint8_t)(((uint16_t)(n))>>8))
|
||||
#define BYTE2(n) ((uint8_t)(((uint16_t)(((uint32_t)(n))>>8))>>8))
|
||||
#define BYTE3(n) ((uint8_t)(((uint16_t)(((uint32_t)(n))>>16))>>8))
|
||||
|
||||
#define LOAD_U32B(p) ((((volatile uint8_t *)(p))[0]<<24) | (((volatile uint8_t *)(p))[1]<<16) | (((volatile uint8_t *)(p))[2]<<8) | (((volatile uint8_t *)(p))[3]<<0))
|
||||
#define LOAD_U32L(p) ((((volatile uint8_t *)(p))[0]<<0) | (((volatile uint8_t *)(p))[1]<<8) | (((volatile uint8_t *)(p))[2]<<16)| (((volatile uint8_t *)(p))[3]<<24))
|
||||
#define LOAD_U16B(p) ((((volatile uint8_t *)(p))[0]<<8) | (((volatile uint8_t *)(p))[1]<<0))
|
||||
#define LOAD_U16L(p) ((((volatile uint8_t *)(p))[0]<<0) | (((volatile uint8_t *)(p))[1]<<8))
|
||||
|
||||
#define SAVE_U32B(p, num) do { \
|
||||
((volatile uint8_t *)(p))[0] = BYTE3(num); \
|
||||
((volatile uint8_t *)(p))[1] = BYTE2(num); \
|
||||
((volatile uint8_t *)(p))[2] = BYTE1(num); \
|
||||
((volatile uint8_t *)(p))[3] = BYTE0(num); \
|
||||
} while(0)
|
||||
|
||||
#define SAVE_U32L(p, num) do { \
|
||||
((volatile uint8_t *)(p))[0] = BYTE0(num); \
|
||||
((volatile uint8_t *)(p))[1] = BYTE1(num); \
|
||||
((volatile uint8_t *)(p))[2] = BYTE2(num); \
|
||||
((volatile uint8_t *)(p))[3] = BYTE3(num); \
|
||||
} while(0)
|
||||
|
||||
#define SAVE_U16B(p, num) do { \
|
||||
((volatile uint8_t *)(p))[0] = BYTE1(num); \
|
||||
((volatile uint8_t *)(p))[1] = BYTE0(num); \
|
||||
} while(0)
|
||||
|
||||
#define SAVE_U16L(p, num) do { \
|
||||
((volatile uint8_t *)(p))[0] = BYTE0(num); \
|
||||
((volatile uint8_t *)(p))[1] = BYTE1(num); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,229 @@
|
||||
#ifndef USB_DEV_API_H
|
||||
#define USB_DEV_API_H
|
||||
|
||||
/// include & define here
|
||||
#include "hal/usb_device.h"
|
||||
#include "dev/usb/hgusb11_base.h"
|
||||
#include "dev/usb/hgusb11_dev_ep0.h"
|
||||
|
||||
#define USB_DEV_DEBUG_ERR_ENABLE 0
|
||||
#if USB_DEV_DEBUG_ERR_ENABLE
|
||||
#define USB_DEV_ERR_PRINTF(fmt, args...) os_printf(fmt, ##args)
|
||||
#else
|
||||
#define USB_DEV_ERR_PRINTF(fmt, args...)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/// extern declare functions here
|
||||
|
||||
enum hgusb11_flags {
|
||||
HGUSB11_FLAGS_READY,
|
||||
};
|
||||
|
||||
struct hgusb11_hw_dma_st {
|
||||
__IO uint32_t EP_TXSTARTADR;
|
||||
__IO uint32_t EP_RXSTARTADR;
|
||||
__IO uint32_t EP_TXLEN;
|
||||
__IO uint32_t EP_RXLEN;
|
||||
} ;
|
||||
|
||||
struct hgusb11_hw_dma_end {
|
||||
__I uint32_t EP_TXADR;
|
||||
__I uint32_t EP_RXADR;
|
||||
} ;
|
||||
|
||||
/**
|
||||
* @brief USB2.0
|
||||
*/
|
||||
|
||||
struct hgusb11_dev_hw {
|
||||
/* SIE common reg : 0x0 ~ 0xf */
|
||||
__IO uint8_t SIEM_FADDR;
|
||||
__IO uint8_t SIEM_POWER;
|
||||
__IO uint8_t SIEM_INTRTX1;
|
||||
__IO uint8_t SIEM_INTRTX2;
|
||||
__IO uint8_t SIEM_INTRRX1;
|
||||
__IO uint8_t SIEM_INTRRX2;
|
||||
__IO uint8_t SIEM_INTRUSB;
|
||||
__IO uint8_t SIEM_INTRTX1E;
|
||||
__IO uint8_t SIEM_INTRTX2E;
|
||||
__IO uint8_t SIEM_INTRRX1E;
|
||||
__IO uint8_t SIEM_INTRRX2E;
|
||||
__IO uint8_t SIEM_INTRUSBE;
|
||||
__IO uint8_t SIEM_FRAMENUM1;
|
||||
__IO uint8_t SIEM_FRAMENUM2;
|
||||
__IO uint8_t SIEM_INDEX;
|
||||
__IO uint8_t SIEM_DEVCTL;
|
||||
|
||||
/* SIE indexed reg : 0x10 ~ 0x1f */
|
||||
__IO uint8_t SIEM_TXMAXP;
|
||||
__IO uint8_t SIEM_TXCSR1;
|
||||
__IO uint8_t SIEM_TXCSR2;
|
||||
__IO uint8_t SIEM_RXMAXP;
|
||||
__IO uint8_t SIEM_RXCSR1;
|
||||
__IO uint8_t SIEM_RXCSR2;
|
||||
__IO uint8_t SIEM_RXCOUNT1;
|
||||
__IO uint8_t SIEM_RXCOUNT2;
|
||||
__IO uint8_t SIEM_TXTYPE;
|
||||
__IO uint8_t SIEM_TXINTERVAL;
|
||||
__IO uint8_t SIEM_RXTYPE;
|
||||
__IO uint8_t SIEM_RXINTERVAL;
|
||||
uint8_t SIEreserved0[3];
|
||||
__IO uint8_t SIEM_FIFOSIZE;
|
||||
|
||||
/* SIE common reg : 0x20 ~ 0x2f */
|
||||
__IO uint8_t SIEM_FIFO0;
|
||||
uint8_t SIEreserved1[3];
|
||||
__IO uint8_t SIEM_FIFO1;
|
||||
uint8_t SIEreserved2[3];
|
||||
__IO uint8_t SIEM_FIFO2;
|
||||
uint8_t SIEreserved3[3 + 4];
|
||||
|
||||
uint8_t rsv0[0x200 - 0x30];
|
||||
|
||||
/* DMA common reg */
|
||||
__IO uint32_t DMA_INT; ///0x200
|
||||
__IO uint32_t DMA1_CTL;
|
||||
__IO uint32_t DMA1_ADDR;
|
||||
__IO uint32_t DMA1_CNT;
|
||||
uint32_t rsv1;
|
||||
__IO uint32_t DMA2_CTL;
|
||||
__IO uint32_t DMA2_ADDR;
|
||||
__IO uint32_t DMA2_CNT;
|
||||
uint32_t rsv2;
|
||||
__IO uint32_t DMA3_CTL;
|
||||
__IO uint32_t DMA3_ADDR;
|
||||
__IO uint32_t DMA3_CNT;
|
||||
uint32_t rsv3;
|
||||
__IO uint32_t DMA4_CTL;
|
||||
__IO uint32_t DMA4_ADDR;
|
||||
__IO uint32_t DMA4_CNT;
|
||||
|
||||
uint32_t rsv4[0x100 / 4 - 16];
|
||||
|
||||
/* CPU common reg */
|
||||
__IO uint32_t UCFG0; ///0x300
|
||||
__IO uint32_t UCFG1;
|
||||
__IO uint32_t UCFG2;
|
||||
__IO uint32_t UCFG3;
|
||||
|
||||
|
||||
__IO uint32_t EP_STATUS;
|
||||
__IO uint32_t EP_KICK;
|
||||
__IO uint32_t EP_CTL;
|
||||
uint32_t rsv5;
|
||||
__IO uint32_t EP0_TXSTARTADR;
|
||||
__IO uint32_t EP0_RXSTARTADR;
|
||||
__IO uint32_t EP0_TXLEN;
|
||||
uint32_t rsv6;
|
||||
__IO uint32_t EP1_TXSTARTADR;
|
||||
__IO uint32_t EP1_RXSTARTADR;
|
||||
__IO uint32_t EP1_TXLEN;
|
||||
__IO uint32_t EP1_RXLEN;
|
||||
|
||||
__IO uint32_t EP2_TXSTARTADR;
|
||||
__IO uint32_t EP2_RXSTARTADR;
|
||||
__IO uint32_t EP2_TXLEN;
|
||||
__IO uint32_t EP2_RXLEN;
|
||||
|
||||
__I uint32_t EP0_TXADR;
|
||||
__I uint32_t EP0_RXADR;
|
||||
|
||||
__I uint32_t EP1_TXADR;
|
||||
__I uint32_t EP1_RXADR;
|
||||
|
||||
__I uint32_t EP2_TXADR;
|
||||
__I uint32_t EP2_RXADR;
|
||||
|
||||
} ;
|
||||
|
||||
struct hgusb11_dev {
|
||||
struct usb_device dev;
|
||||
struct hgusb11_dev_hw *usb_hw;
|
||||
long flags;
|
||||
usbdev_irq_hdl irq_hdl;
|
||||
struct os_mutex tx_lock;
|
||||
struct os_semaphore tx_done;
|
||||
uint32 irq_num;
|
||||
uint32 sof_irq_num;
|
||||
uint8 *rx_buff;
|
||||
uint32 rx_len;
|
||||
uint32 opened;
|
||||
uint32 irq_data;
|
||||
struct usb_device_cfg cfg;
|
||||
struct os_task ep0_task;
|
||||
struct os_semaphore ep0_sema;
|
||||
|
||||
/* basic */
|
||||
struct hgusb11_dev_chk usb_chk;
|
||||
struct hgusb11_dev_ctrl usb_ctrl;
|
||||
struct hgusb11_dev_info usb_dev;
|
||||
struct hgusb11_audio_ctrl usb_audio_ctl;
|
||||
uint32_t usb_dma_int;
|
||||
uint8_t dev_type;
|
||||
uint8_t usb_exit ;
|
||||
uint8_t usb_dev_flag ;
|
||||
uint8_t usb_ep0buf[66];
|
||||
uint8_t usb_ep0_rxbuf[66];
|
||||
uint8_t usb_device_descriptor[18];
|
||||
uint8_t usb_device_qualifier[10];
|
||||
uint8_t usb_config_all_descriptor[512];
|
||||
|
||||
uint16_t usb_vid; /* */
|
||||
uint16_t usb_pid; /* */
|
||||
};
|
||||
|
||||
/* hgusb11_base */
|
||||
void hgusb11_switch_otg(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_switch_host(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_switch_stable_host(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_switch_stable_device(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_switch_stable_otg(struct hgusb11_dev *p_dev);
|
||||
uint8_t hgusb11_connected(struct hgusb11_dev *p_dev);
|
||||
uint8_t hgusb11_connected_do(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_intr_dis(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_suspend(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_resume(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_init_globle(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_dev_remote_wakeup(struct hgusb11_dev *p_dev);
|
||||
|
||||
|
||||
|
||||
/* hgusb11_dev_ep0 */
|
||||
uint8_t hgusb11_dev_init(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_dev_ep0_func(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_dev_intr_init_b(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_dev_exit(struct hgusb11_dev *p_dev);
|
||||
void hgusb11_dev_reset(struct hgusb11_dev *p_dev);
|
||||
|
||||
|
||||
|
||||
/* hgusb11_dev_api */
|
||||
int32 hgusb11_dev_attach(uint32 dev_id, struct hgusb11_dev *p_dev);
|
||||
void hgusb11_dev_irq(struct hgusb11_dev *p_dev);
|
||||
bool hgusb11_dev_ep_rx_kick(struct hgusb11_dev *p_dev, uint8_t ep, uint32_t addr, uint32_t len);
|
||||
bool hgusb11_dev_ep_tx_kick(struct hgusb11_dev *p_dev, uint8_t ep, uint32_t addr, uint32_t len);
|
||||
void hgusb11_dev_ep_set_rxrdy(struct hgusb11_dev *p_dev, uint8_t ep);
|
||||
void hgusb11_dev_ep_set_txrdy(struct hgusb11_dev *p_dev, uint8_t ep);
|
||||
void hgusb11_dev_hw_init(struct hgusb11_dev *p_dev);
|
||||
uint32_t hgusb11_dev_ep_get_rx_len(struct hgusb11_dev *p_dev, uint8_t ep);
|
||||
uint32_t hgusb11_dev_ep_get_tx_len(struct hgusb11_dev *p_dev, uint8_t ep);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* USB_DEV_API_H */
|
||||
@@ -0,0 +1,66 @@
|
||||
/*****************************************************************************
|
||||
* Module : usb
|
||||
* File : usb_dev.h
|
||||
* Author :
|
||||
* Function : USB Device驱动的一些定义
|
||||
*****************************************************************************/
|
||||
#ifndef USB_DEV_H
|
||||
#define USB_DEV_H
|
||||
|
||||
#include "typesdef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define USB_REQUEST_DIRECTION (p_dev->usb_ctrl.cmd.rtype & 0x80)
|
||||
#define USB_REQUEST_TYPE (p_dev->usb_ctrl.cmd.rtype & 0x60)
|
||||
#define USB_REQUEST_RECIPIENT (p_dev->usb_ctrl.cmd.rtype & 0x1f)
|
||||
#define USB_REQUEST_ENDPOINT BYTE0(p_dev->usb_ctrl.cmd.index)
|
||||
#define USB_REQUEST_FEATURE_SELECTOR (p_dev->usb_ctrl.cmd.value)
|
||||
#define USB_REQUEST_DESCRIPTOR_TYPE BYTE1(p_dev->usb_ctrl.cmd.value)
|
||||
#define USB_REQUEST_DESCRIPTOR_INDEX BYTE0(p_dev->usb_ctrl.cmd.value)
|
||||
#define USB_REQUEST_LENGTH (p_dev->usb_ctrl.cmd.length)
|
||||
|
||||
|
||||
struct hgusb11_dev_info {
|
||||
uint8_t type; //设备类型
|
||||
uint8_t set_addr; //设地址
|
||||
uint8_t cfg_value; //Config Value, 用于Set Config与Get Config
|
||||
uint8_t cur_state; //USB当前状态机
|
||||
uint8_t ep0_state; //EP0的状态机
|
||||
uint8_t ep0_pkt; //EP0包大小
|
||||
uint8_t *ep0_ptr; //当前发送指针
|
||||
uint16_t ep0_len; //当前发送剩余
|
||||
uint8_t isoc_tx_interface; //ISOC,MIC发送的接口
|
||||
uint8_t isoc_tx_enable; //ISOC使能
|
||||
uint8_t isoc_tx_enable_int; //在中断中配置ISOC使能
|
||||
|
||||
volatile uint8_t ep1_tx_stall; //ep1 tx stall标志
|
||||
volatile uint8_t ep1_rx_stall; //ep1 rx stall标志
|
||||
volatile uint8_t ep1_pipe_stall; //ep1 Stall的标志
|
||||
volatile uint8_t ep2_tx_stall; //ep1 tx stall标志
|
||||
volatile uint8_t ep2_rx_stall; //ep1 rx stall标志
|
||||
volatile uint8_t ep2_pipe_stall; //ep1 Stall的标志
|
||||
} ;
|
||||
|
||||
struct hgusb11_audio_ctrl {
|
||||
uint8_t speaker_mute;
|
||||
uint8_t mic_mute;
|
||||
uint8_t volume;
|
||||
/*
|
||||
uint8_t *adc_root;
|
||||
uint8_t *adc_end;
|
||||
uint8_t *adc_ptr;
|
||||
int16_t adc_cnt;
|
||||
int16_t adc_total;
|
||||
int8_t mic_speed;
|
||||
*/
|
||||
} ;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
/*****************************************************************************
|
||||
* Module : usb
|
||||
* File : usb_dev_tbl.h
|
||||
* Author :
|
||||
* Function : USB驱动的一些常量表的申明
|
||||
*****************************************************************************/
|
||||
#ifndef USB_DEV_TBL_H
|
||||
#define USB_DEV_TBL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
extern const uint8_t tbl_usb_device_descriptor[18];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_gen[9];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_wifi[23];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_mass[23];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_head[19];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_speaker[31];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_mic[30];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_speaker_stream[52];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_mic_stream[52];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_hid[25];
|
||||
extern const uint8_t tbl_usb_hid_report_descriptor[33];
|
||||
extern const uint8_t tbl_usb_language_id[4];
|
||||
extern const uint8_t tbl_usb_str_manufacturer[16];
|
||||
extern const uint8_t tbl_usb_str_product[28];
|
||||
extern const uint8_t tbl_usb_str_serial_number[30];
|
||||
extern const uint8_t tbl_scsi_inquiry_data[36];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
/*****************************************************************************
|
||||
* Module : usb
|
||||
* File : usb.c
|
||||
* Author :
|
||||
* Function : USB驱动的一些公用模块
|
||||
*****************************************************************************/
|
||||
#ifndef USB20_H
|
||||
#define USB20_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//typedef int8 bool;
|
||||
|
||||
|
||||
#define USBIE_EN() //NVIC_EnableIRQ(USB_CTL_IRQn);
|
||||
#define USBIE_DIS() //NVIC_DisableIRQ(USB_CTL_IRQn);
|
||||
|
||||
#define USB_REG_CRITICAL_ENTER() int32 ie = disable_irq();
|
||||
#define USB_REG_CRITICAL_EXIT() enable_irq(ie);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//USB当前状态机
|
||||
enum {
|
||||
USB_DEFAULT_STATE,
|
||||
USB_ADDRESS_STATE,
|
||||
USB_CONFIG_STATE
|
||||
};
|
||||
|
||||
//EP0状态机
|
||||
enum {
|
||||
IDLE_STATE,
|
||||
TRANSER_OVER_STATE,
|
||||
TRANSFERING_STATE,
|
||||
RECEIVING_STATE,
|
||||
RECEIV_OVER_STATE,
|
||||
};
|
||||
|
||||
//接收者
|
||||
enum {
|
||||
REQUEST_TO_DEVICE,
|
||||
REQUEST_TO_INTERFACE,
|
||||
REQUEST_TO_ENDPOINT
|
||||
};
|
||||
|
||||
//设备描述符
|
||||
enum {
|
||||
DEVICE_DESCRIPTOR = 1,
|
||||
CONFIGURATION_DESCRIPTOR,
|
||||
STRING_DESCRIPTOR,
|
||||
INTERFACE_DESCRIPTOR,
|
||||
ENDPOINT_DESCRIPTOR,
|
||||
DEVICE_QUALIFIER_DESCRIPTOR,
|
||||
// OTHER_SPEED_CONFIG_DESCRIPTOR, USB 1.1没有该选项
|
||||
INTERFACE_ASSOCIATION_DESCRIPTOR = 11,
|
||||
|
||||
HID_REPORT = 0x22,
|
||||
|
||||
BOS_DEVICE_DESCRIPTOR = 0xF,
|
||||
|
||||
WCID_DEVICE_DESCRIPTOR = 0xEE,
|
||||
};
|
||||
|
||||
//Feature Selector
|
||||
enum {
|
||||
ENDPOINT_STALL,
|
||||
REMOTE_WAKEUP,
|
||||
TEST_MODE
|
||||
};
|
||||
|
||||
//检测模式
|
||||
enum {
|
||||
USB_CHECK_HOST, //尝试主机检测
|
||||
USB_CHECK_OTG, //尝试OTG检测,是否连接PC
|
||||
USB_STABLE_HOST, //已成功检测为USB主机
|
||||
USB_STABLE_DEVICE, //已成功检测为USB设备
|
||||
};
|
||||
|
||||
//返回值
|
||||
enum {
|
||||
USB_CONNECTED_NONE, //未连接
|
||||
USB_CONNECTED_PC, //连接PC,当Device
|
||||
USB_CONNECTED_DEVICE, //外接U盘,当Host
|
||||
};
|
||||
|
||||
//USB控制结构体
|
||||
struct hgusb20_dev_ctrl {
|
||||
//EP0接收的命令
|
||||
struct {
|
||||
uint8_t rtype;
|
||||
uint8_t request;
|
||||
uint16_t value;
|
||||
uint16_t index;
|
||||
uint16_t length;
|
||||
} cmd;
|
||||
|
||||
uint8_t bus_high_speed : 1,
|
||||
auto_tx_null_pkt : 1, //ep1 tx null packet for non-potocol xfer
|
||||
reserved_bit0 : 1,
|
||||
error : 1,
|
||||
reserved_bit : 4;
|
||||
|
||||
uint8_t test_mode;
|
||||
|
||||
uint8_t reg_usb_csr0;
|
||||
uint8_t set_addr;
|
||||
|
||||
// struct {
|
||||
// uint16_t vid; //VID
|
||||
// uint16_t pid; //PID
|
||||
// uint16_t ver; //Version
|
||||
// } info;
|
||||
};
|
||||
|
||||
struct hgusb20_dev_chk {
|
||||
uint8_t check_mode;
|
||||
uint8_t check_cnt;
|
||||
uint8_t check_delay;
|
||||
} ;
|
||||
|
||||
|
||||
#define BYTE0(n) ((uint8_t)((uint16_t)(n)))
|
||||
#define BYTE1(n) ((uint8_t)(((uint16_t)(n))>>8))
|
||||
#define BYTE2(n) ((uint8_t)(((uint16_t)(((uint32_t)(n))>>8))>>8))
|
||||
#define BYTE3(n) ((uint8_t)(((uint16_t)(((uint32_t)(n))>>16))>>8))
|
||||
|
||||
#define LOAD_U32B(p) ((((volatile uint8_t *)(p))[0]<<24) | (((volatile uint8_t *)(p))[1]<<16) | (((volatile uint8_t *)(p))[2]<<8) | (((volatile uint8_t *)(p))[3]<<0))
|
||||
#define LOAD_U32L(p) ((((volatile uint8_t *)(p))[0]<<0) | (((volatile uint8_t *)(p))[1]<<8) | (((volatile uint8_t *)(p))[2]<<16)| (((volatile uint8_t *)(p))[3]<<24))
|
||||
#define LOAD_U16B(p) ((((volatile uint8_t *)(p))[0]<<8) | (((volatile uint8_t *)(p))[1]<<0))
|
||||
#define LOAD_U16L(p) ((((volatile uint8_t *)(p))[0]<<0) | (((volatile uint8_t *)(p))[1]<<8))
|
||||
|
||||
#define SAVE_U32B(p, num) do { \
|
||||
((volatile uint8_t *)(p))[0] = BYTE3(num); \
|
||||
((volatile uint8_t *)(p))[1] = BYTE2(num); \
|
||||
((volatile uint8_t *)(p))[2] = BYTE1(num); \
|
||||
((volatile uint8_t *)(p))[3] = BYTE0(num); \
|
||||
} while(0)
|
||||
|
||||
#define SAVE_U32L(p, num) do { \
|
||||
((volatile uint8_t *)(p))[0] = BYTE0(num); \
|
||||
((volatile uint8_t *)(p))[1] = BYTE1(num); \
|
||||
((volatile uint8_t *)(p))[2] = BYTE2(num); \
|
||||
((volatile uint8_t *)(p))[3] = BYTE3(num); \
|
||||
} while(0)
|
||||
|
||||
#define SAVE_U16B(p, num) do { \
|
||||
((volatile uint8_t *)(p))[0] = BYTE1(num); \
|
||||
((volatile uint8_t *)(p))[1] = BYTE0(num); \
|
||||
} while(0)
|
||||
|
||||
#define SAVE_U16L(p, num) do { \
|
||||
((volatile uint8_t *)(p))[0] = BYTE0(num); \
|
||||
((volatile uint8_t *)(p))[1] = BYTE1(num); \
|
||||
} while(0)
|
||||
|
||||
|
||||
|
||||
void hgusb20_write_usb_reg_index(uint32_t usb_dev_hw,uint32_t index,uint32_t reg_addr,uint32_t reg_data);
|
||||
void hgusb20_read_usb_reg_index(uint32_t usb_dev_hw,uint32_t index,uint32_t reg_addr,uint32_t *reg_data);
|
||||
uint32_t hgusb20_write_usb_reg(uint32_t usb_dev_hw,uint8_t reg_addr,uint8_t reg_data);
|
||||
uint32_t hgusb20_read_usb_reg(uint32_t usb_dev_hw,uint32_t reg_addr);
|
||||
void hgusb20_send_empty_packet(uint32_t usb_dev_hw);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,657 @@
|
||||
#ifndef USB20_DEV_API_H
|
||||
#define USB20_DEV_API_H
|
||||
|
||||
/// include & define here
|
||||
#include "sys_config.h"
|
||||
#include "hal/usb_device.h"
|
||||
#include "dev/usb/hgusb20_v1_base.h"
|
||||
#include "dev/usb/hgusb20_v1_dev_ep0.h"
|
||||
#include "osal/work.h"
|
||||
#include "osal/event.h"
|
||||
#include "lib/common/rbuffer.h"
|
||||
|
||||
#define USB_DEV_DEBUG_ERR_ENABLE 0
|
||||
#if USB_DEV_DEBUG_ERR_ENABLE
|
||||
#define USB_DEV_ERR_PRINTF(fmt, args...) os_printf(fmt, ##args)
|
||||
#else
|
||||
#define USB_DEV_ERR_PRINTF(fmt, args...)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* speed flags only host */
|
||||
#define HGUSB20_FLAGS_HIGH_SPEED (0)
|
||||
#define HGUSB20_FLAGS_FULL_SPEED (30)
|
||||
|
||||
#define USBDMA_RX_FLAG_RXING BIT(0)
|
||||
#define USBDMA_RX_FLAG_OVERFLOW BIT(1)
|
||||
#define USBDMA_RX_FLAG_FIFOFULL BIT(2)
|
||||
|
||||
#define USBDMA_TX_FLAG_TXING BIT(0)
|
||||
#define USBDMA_TX_FLAG_NULLPACKET BIT(1)
|
||||
#define USBDMA_TX_FLAG_MODE1 BIT(2)
|
||||
|
||||
typedef struct {
|
||||
uint8 ep0_pkt;
|
||||
uint8 max_lun;
|
||||
uint8 bulk_rx;
|
||||
uint8 bulk_tx;
|
||||
uint16 time_out;
|
||||
uint8 stall;
|
||||
uint8 if_mass;
|
||||
uint8 res;
|
||||
uint16 rx_pkt_size;
|
||||
uint16 tx_pkt_size;
|
||||
} type_usb_host;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8 offset;
|
||||
uint8 rx_len;
|
||||
uint16 rx_total;
|
||||
} type_ep0_ptr;
|
||||
|
||||
struct hgusb20_os_dev {
|
||||
struct os_task ep0_task __attribute__((aligned(4)));
|
||||
struct os_task ep0_hub_task __attribute__((aligned(4)));
|
||||
struct os_task ep0_usb_connect_task __attribute__((aligned(4)));
|
||||
struct os_semaphore ep0_sema __attribute__((aligned(4)));
|
||||
struct os_mutex tx_lock __attribute__((aligned(4)));
|
||||
struct os_semaphore tx_done __attribute__((aligned(4)));
|
||||
struct os_semaphore hub_sema __attribute__((aligned(4)));
|
||||
struct os_semaphore hub_finish_sema __attribute__((aligned(4)));
|
||||
uint32 dev_type; //device mode 1:udisk 2:uvc
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
UDISK_DEV = 1,
|
||||
UVC_DEV
|
||||
}USB_DEV_TYPE;
|
||||
|
||||
|
||||
struct hgusb20_dev {
|
||||
struct usb_device dev;
|
||||
void *usb_hw;
|
||||
struct hgusb20_os_dev *usb_os_msg;
|
||||
long flags;
|
||||
usbdev_irq_hdl irq_hdl;
|
||||
uint8 *rx_buff;
|
||||
uint32 rx_len;
|
||||
uint32 irq_data;
|
||||
|
||||
struct usb_device_cfg *cfg;
|
||||
uint8 *p_com_desc; /* usb descriptor */
|
||||
uint8 *p_config_desc; /* usb descriptor */
|
||||
uint16 vid; /* usb device VID */
|
||||
uint16 pid; /* usb device PID */
|
||||
|
||||
/* basic */
|
||||
struct hgusb20_dev_chk usb_chk;
|
||||
struct hgusb20_dev_ctrl usb_ctrl;
|
||||
struct hgusb20_dev_info usb_dev;
|
||||
type_ep0_ptr ep0_ptr;
|
||||
type_usb_host usb_host;
|
||||
|
||||
volatile uint32 usb_dma_int; /* dma intr status reg value */
|
||||
// volatile uint32 usb_rxdma_addr; /* rx dma start addr */
|
||||
// volatile uint32 usb_rx_len_limit; /* rx req len */
|
||||
// volatile uint16_t usb_rxdma_len; /* latest packet len */
|
||||
|
||||
volatile uint8 usb_rxdma_flag;
|
||||
volatile uint8 usb_txdma_flag;
|
||||
volatile uint16_t usb_tx_total_len; /* */
|
||||
|
||||
uint8 ep_irq_num;
|
||||
uint8 dma_irq_num;
|
||||
uint16_t usb_dev_flag;
|
||||
|
||||
uint8 usb_ep0_sbuf[8] __attribute__((aligned(4)));
|
||||
/* case : usb continue send 64byte data, 2nd data NAK */
|
||||
uint8 usb_ep0_rxbuf[68 + 68] __attribute__((aligned(4)));
|
||||
|
||||
uint8 usb_ep0_sta[8];
|
||||
RBUFFER_DEF_R(rb, uint8);
|
||||
struct os_work ep0_work;
|
||||
/* trx_lock[00:15] for EP_IN */
|
||||
/* trx_lock[15:31] for EP_OUT */
|
||||
struct os_event trx_lock;
|
||||
struct os_event trx_done;
|
||||
#ifdef CONFIG_SLEEP
|
||||
uint32 sys_regs[2];
|
||||
#endif
|
||||
};
|
||||
|
||||
/* hgusb20_base */
|
||||
/**
|
||||
* @brief read usb register
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep :
|
||||
* @param addr : register address offset
|
||||
* @param data : data return
|
||||
* @return : TRUE or FLASE
|
||||
* @note
|
||||
*/
|
||||
bool hgusb20_read_reg(struct hgusb20_dev *p_dev, uint8 ep, uint32 addr, uint32 *data);
|
||||
/**
|
||||
* @brief write usb register
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep :
|
||||
* @param addr : register address offset
|
||||
* @param data : data return
|
||||
* @return : TRUE or FLASE
|
||||
* @note
|
||||
*/
|
||||
bool hgusb20_write_reg(struct hgusb20_dev *p_dev, uint8 ep, uint32 addr, uint32 data);
|
||||
|
||||
void hgusb20_switch_otg(struct hgusb20_dev *p_dev);
|
||||
void hgusb20_switch_host(struct hgusb20_dev *p_dev);
|
||||
void hgusb20_switch_stable_host(struct hgusb20_dev *p_dev);
|
||||
void hgusb20_switch_stable_device(struct hgusb20_dev *p_dev);
|
||||
void hgusb20_switch_stable_otg(struct hgusb20_dev *p_dev);
|
||||
void hgusb20_intr_dis(struct hgusb20_dev *p_dev);
|
||||
uint8_t hgusb20_connected(struct hgusb20_dev * p_dev);
|
||||
|
||||
uint32 hgusb20_get_rx_crc_error_cnt(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb ep rx data kick
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep : [1,2]
|
||||
* @param addr : data address
|
||||
* @param len : data length
|
||||
* @return : TRUE or FLASE
|
||||
* @note use for host & device
|
||||
*/
|
||||
bool hgusb20_ep_rx_kick(struct hgusb20_dev *p_dev, uint8 ep, uint32 addr, uint32 len);
|
||||
/**
|
||||
* @brief usb ep tx data kick
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep : [1,2]
|
||||
* @param addr : data address
|
||||
* @param len : data length
|
||||
* @return : TRUE or FLASE
|
||||
* @note use for host & device
|
||||
*/
|
||||
bool hgusb20_ep_tx_kick(struct hgusb20_dev *p_dev, uint8 ep, uint32 addr, uint32 len);
|
||||
bool hgusb20_ep_rx_abort(struct hgusb20_dev *p_dev, uint8 ep);
|
||||
bool hgusb20_ep_tx_abort(struct hgusb20_dev *p_dev, uint8 ep);
|
||||
|
||||
/**
|
||||
* @brief usb ep get rx data length from dma
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep : [1,2]
|
||||
* @return : rx data length
|
||||
* @note use for host & device
|
||||
*/
|
||||
uint32 hgusb20_ep_get_dma_rx_len(struct hgusb20_dev *p_dev, uint8 ep);
|
||||
/**
|
||||
* @brief usb ep get rx data length from sie
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep : [1,2]
|
||||
* @return : rx data length
|
||||
* @note use for host & device
|
||||
*/
|
||||
uint32 hgusb20_ep_get_sie_rx_len(struct hgusb20_dev *p_dev, uint8 ep);
|
||||
/**
|
||||
* @brief usb ep get tx data length
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep : [1,2]
|
||||
* @return : tx data length (same with len in hgusb20_ep_tx_kick)
|
||||
* @note use for host & device
|
||||
*/
|
||||
uint32 hgusb20_ep_get_tx_len(struct hgusb20_dev *p_dev, uint8 ep);
|
||||
|
||||
|
||||
/**
|
||||
* @brief check if usb device online
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* - TRUE : online.
|
||||
* - FALSE : not online.
|
||||
* @note : For USB Host
|
||||
*/
|
||||
bool hgusb20_is_device_online(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief check if usb host online
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* - TRUE : online.
|
||||
* - FALSE : not online.
|
||||
* @note : For USB Device
|
||||
*/
|
||||
bool hgusb20_is_host_online(struct hgusb20_dev *p_dev);
|
||||
int32 hgusb20_is_host_mode(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief suspend usb device .
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return :
|
||||
* @note : For USB Host
|
||||
*/
|
||||
void hgusb20_host_suspend(struct hgusb20_dev *p_dev);
|
||||
/**
|
||||
* @brief resume usb device .
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return :
|
||||
* @note : For USB Host
|
||||
*/
|
||||
void hgusb20_host_resume(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb host set address(host address)
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param addr :
|
||||
* @return
|
||||
* @note use after usb_host_set_address(device address) cmd
|
||||
*/
|
||||
void hgusb20_set_address(struct hgusb20_dev *p_dev, uint8 addr);
|
||||
|
||||
/**
|
||||
* @brief usb host bus reset request
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
uint8 hgusb20_host_reset(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief remote_wakeup usb host .
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return :
|
||||
* @note : For USB Device
|
||||
*/
|
||||
void hgusb20_dev_remote_wakeup(struct hgusb20_dev *p_dev);
|
||||
|
||||
|
||||
/* hgusb20_dev_api */
|
||||
/**
|
||||
* @brief attach usb device
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param dev_id :
|
||||
* @return : err_code
|
||||
* @note
|
||||
*/
|
||||
int32 hgusb20_dev_attach(uint32 dev_id, struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief init usb to device mode .
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* - RET_OK : Successfully.
|
||||
* - RET_ERR : Failed.
|
||||
* @note
|
||||
*/
|
||||
uint8 hgusb20_dev_init(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief exit usb to device mode .
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* - RET_OK : Successfully.
|
||||
* - RET_ERR : Failed.
|
||||
* @note
|
||||
*/
|
||||
void hgusb20_dev_exit(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb device ep0 tx data stage handle:
|
||||
* addr = p_dev->ep0_ptr; len = p_dev->ep0_len;
|
||||
* 1、if buf is not NULL(first packet), update p_dev->ep0_ptr & p_dev->ep0_len
|
||||
* 2、TX one packet
|
||||
* 3、data end if len != ep0_pkt
|
||||
* 4、auto called repeat when last tx data done while (p_dev->usb_dev.ep0_state == TRANSER_OVER_STATE)
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param buf : valid when first packet, set NULL when other packet
|
||||
* @param len : valid when first packet, set 0 when other packet.
|
||||
* @return
|
||||
* - RET_OK : Successfully.
|
||||
* - RET_ERR : Failed.
|
||||
* @note : weak function, Users can use a strong statement function replace the weak statement function.
|
||||
*/
|
||||
bool hgusb20_dev_ep0_tx(struct hgusb20_dev *p_dev, void *buf, uint16_t len);
|
||||
/**
|
||||
* @brief usb device ep0 tx one packet only
|
||||
*/
|
||||
bool hgusb20_dev_ep0_tx_rtt(struct hgusb20_dev *p_dev, void *buf, uint16_t len);
|
||||
bool hgusb20_dev_ep0_tx_abort(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb ep rx data stage handle
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep : [1,2]
|
||||
* @param addr : data address
|
||||
* @param len : data length
|
||||
* @return : TRUE or FLASE
|
||||
* @note use for host & device
|
||||
*/
|
||||
bool hgusb20_dev_ep0_rx(struct hgusb20_dev *p_dev, void *buf, uint16_t len);
|
||||
/**
|
||||
* @brief usb device ep0 rx one packet only
|
||||
*/
|
||||
bool hgusb20_dev_ep0_rx_rtt(struct hgusb20_dev *p_dev, void *buf, uint16_t len);
|
||||
bool hgusb20_dev_ep0_rx_abort(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb device clear_stall_flag
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void hgusb20_dev_clear_stall_flag(struct hgusb20_dev *p_dev);
|
||||
/**
|
||||
* @brief usb device tx zero-packet & rx packet to usb_ep0_rxbuf
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
bool hgusb20_dev_ep0_clrrx_pkt0(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb device bus reset
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void hgusb20_dev_reset(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb device stall_ep
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param epnum : epnum, set BIT(7) when tx endpiont.
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void hgusb20_dev_stall_ep(struct hgusb20_dev *p_dev, uint8 epnum);
|
||||
/**
|
||||
* @brief usb device clear stall_ep
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param epnum : epnum, set BIT(7) when tx endpiont.
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void hgusb20_dev_clear_ep(struct hgusb20_dev *p_dev, uint8 epnum);
|
||||
/**
|
||||
* @brief usb device ep reset all endpiont in ep_cfg
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void hgusb20_dev_bot_reset(struct hgusb20_dev *p_dev);
|
||||
/**
|
||||
* @brief usb device cmd handle :get descriptor
|
||||
* 1、kick next rx to p_dev->usb_ep0_rxbuf
|
||||
* 2、tx data(addr = buf, length = len)
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return : TRUE or FLASE
|
||||
* @note
|
||||
*/
|
||||
bool hgusb20_dev_ep0_descriptor(struct hgusb20_dev *p_dev, void *buf, uint16_t len);
|
||||
/**
|
||||
* @brief usb device standard cmd handle
|
||||
* 1、
|
||||
* 2、handle DATA(IN or OUT)
|
||||
* 3、STATUS(zero-len packet)
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* @note : weak function, Users can use a strong statement function replace the weak statement function.
|
||||
* these function is called by func "hgusb20_dev_ep0_standard"
|
||||
*/
|
||||
|
||||
uint8 hgusb20_dev_cfg_desc_prepare(struct hgusb20_dev *p_dev);
|
||||
__weak bool hgusb20_dev_ep0_get_descriptor(struct hgusb20_dev *p_dev);
|
||||
__weak bool hgusb20_dev_ep0_get_configuration(struct hgusb20_dev *p_dev);
|
||||
__weak bool hgusb20_dev_ep0_set_configuration(struct hgusb20_dev *p_dev);
|
||||
__weak bool hgusb20_dev_ep0_get_interface(struct hgusb20_dev *p_dev);
|
||||
__weak bool hgusb20_dev_ep0_set_interface(struct hgusb20_dev *p_dev);
|
||||
__weak bool hgusb20_dev_ep0_set_address(struct hgusb20_dev *p_dev, uint8_t address);
|
||||
__weak bool hgusb20_dev_ep0_get_status(struct hgusb20_dev *p_dev);
|
||||
__weak bool hgusb20_dev_ep0_clr_feature(struct hgusb20_dev *p_dev);
|
||||
__weak bool hgusb20_dev_ep0_set_feature(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb device ep0 setup handle (standard cmd)
|
||||
* 1、
|
||||
* 2、handle DATA(IN or OUT)
|
||||
* 3、STATUS(zero-len packet)
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return : TRUE or FLASE
|
||||
* @note : weak function, Users can use a strong statement function replace the weak statement function.
|
||||
* the function is called by func "hgusb20_dev_ep0_request"
|
||||
*/
|
||||
__weak bool hgusb20_dev_ep0_standard(struct hgusb20_dev *p_dev);
|
||||
//__weak bool hgusb20_dev_ep0_class_reset(struct hgusb20_dev *p_dev);
|
||||
//__weak bool hgusb20_dev_ep0_class_get_lun(struct hgusb20_dev *p_dev);
|
||||
//__weak bool hgusb20_dev_ep0_audio_sample_ctrl(struct hgusb20_dev *p_dev);
|
||||
//__weak bool hgusb20_dev_ep0_audio_mute_ctrl(struct hgusb20_dev *p_dev);
|
||||
//__weak bool hgusb20_dev_ep0_audio_volume_ctrl(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb device ep0 setup handle (class cmd)
|
||||
* 1、
|
||||
* 2、handle DATA(IN or OUT)
|
||||
* 3、STATUS(zero-len packet)
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return : TRUE or FLASE
|
||||
* @note : weak function, Users can use a strong statement function replace the weak statement function.
|
||||
* the function is called by func "hgusb20_dev_ep0_request"
|
||||
*/
|
||||
__weak bool hgusb20_dev_ep0_class(struct hgusb20_dev *p_dev);
|
||||
/**
|
||||
* @brief usb device ep0 setup handle (vendor cmd)
|
||||
* 1、
|
||||
* 2、handle DATA(IN or OUT)
|
||||
* 3、STATUS(zero-len packet)
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return : TRUE or FLASE
|
||||
* @note : weak function, Users can use a strong statement function replace the weak statement function.
|
||||
* the function is called by func "hgusb20_dev_ep0_request"
|
||||
*/
|
||||
__weak bool hgusb20_vendor_cmd(struct hgusb20_dev *p_dev);
|
||||
/**
|
||||
* @brief usb device ep0 setup handle
|
||||
* 1、
|
||||
* 2、handle DATA(IN or OUT)
|
||||
* 3、STATUS(zero-len packet)
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return : TRUE or FLASE
|
||||
* @note : weak function, Users can use a strong statement function replace the weak statement function.
|
||||
*
|
||||
*/
|
||||
__weak bool hgusb20_dev_ep0_request(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb device config state indication
|
||||
* 1、 p_dev->usb_dev.cur_state = USB_CONFIG_STATE;
|
||||
* 2、p_dev->flags |= BIT(HGUSB20_FLAGS_READY);
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return :
|
||||
* @note : weak function, Users can use a strong statement function replace the weak statement function.
|
||||
*
|
||||
*/
|
||||
__weak void hgusb20_dev_state_config(struct hgusb20_dev *p_dev);
|
||||
|
||||
///**
|
||||
// * @brief usb device ep0 interrupt handle
|
||||
// * @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
// * @return
|
||||
// * @note : weak function, Users can use a strong statement function replace the weak statement function.
|
||||
// * !! Don't recommend a strong statement function
|
||||
// */
|
||||
//__weak void hgusb20_dev_ep0_func(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb device endpoint init & deinit
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep_addr : ep->ep_desc->bEndpointAddress
|
||||
* @param max_pkt_size :ep->ep_desc->wMaxPacketSize
|
||||
* @param attributes : ep->ep_desc->bmAttributes.
|
||||
* @return :
|
||||
* @note : weak function, Users can use a strong statement function replace the weak statement function.
|
||||
*/
|
||||
void hgusb20_dev_ep_init(struct hgusb20_dev *p_dev, uint8 ep_addr, uint16 max_pkt_size, uint8 attributes);
|
||||
void hgusb20_dev_ep_deinit(struct hgusb20_dev *p_dev, uint8 ep_addr);
|
||||
/**
|
||||
* @brief usb device IN data kick ( tx data )
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep : ep_num = ep->ep_desc->bEndpointAddress & 0x7F
|
||||
* @param buff : word aligned
|
||||
* @param len :
|
||||
* @param sync : 1: sync(recommand) 0: async
|
||||
* @return : error code
|
||||
* @note : weak function, Users can use a strong statement function replace the weak statement function.
|
||||
*/
|
||||
int32 hgusb20_dev_write(struct usb_device *usb, uint8 ep, uint8 *buff, uint32 len, uint8 sync);
|
||||
int32 hgusb20_dev_read(struct usb_device *p_usb_d, uint8 ep, uint8 *buff, uint32 len, uint8 sync);
|
||||
int32 hgusb20_dev_close(struct usb_device *p_usb_d);
|
||||
|
||||
|
||||
|
||||
/* hgusb20_host_api */
|
||||
|
||||
/**
|
||||
* @brief attach usb host
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param dev_id :
|
||||
* @return : err_code
|
||||
* @note
|
||||
*/
|
||||
int32 hgusb20_host_attach(uint32 dev_id, struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief init usb to host mode .
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* - RET_OK : Successfully.
|
||||
* - RET_ERR : Failed.
|
||||
* @note
|
||||
*/
|
||||
bool hgusb20_host_init(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb host ep0 cmd request
|
||||
* 1. SETUP: send setup packet , addr = p_dev->usb_ctrl.cmd, len = 8
|
||||
* 2. DATA : addr = p_buf, len = p_dev->usb_ctrl.cmd.length for rx/tx(p_dev->usb_ctrl.cmd.rtype & USB_DIR_IN)
|
||||
3. STA : if DATA tx null packet else rx null packet
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param p_buf : data buffer.
|
||||
* @return : TRUE or FLASE
|
||||
* @note Another choice user can realize function by calling "hgusb20_host_ep0_setup" & "hgusb20_host_ep0_rx" & "hgusb20_host_ep0_tx"
|
||||
*/
|
||||
bool usb_host_ep0_request(struct hgusb20_dev *p_dev, uint8 *pBuf);
|
||||
|
||||
/**
|
||||
* @brief usb host ep0 send SETUP packet
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
uint32_t hgusb20_host_ep0_setup(struct hgusb20_dev *p_dev);
|
||||
|
||||
/**
|
||||
* @brief usb host ep0 send IN packet & request a data packet
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @return
|
||||
* @note addr = p_dev->usb_ep0_buf, len = p_dev->ep0_ptr.rx_len
|
||||
*/
|
||||
uint32_t hgusb20_host_ep0_rx(struct hgusb20_dev *p_dev, uint8 *pBuf, bool first_pkt);
|
||||
/**
|
||||
* @brief usb host ep0 send IN packet & request a data packet
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param len :
|
||||
* @return
|
||||
* @note addr = p_dev->usb_ep0_buf, len = p_dev->ep0_ptr.rx_len
|
||||
*/
|
||||
uint32_t hgusb20_host_ep0_tx(struct hgusb20_dev *p_dev, uint8 *pBuf, uint8 len);
|
||||
|
||||
/**
|
||||
* @brief usb host endpiont init
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep_host : ep pipe of host
|
||||
* @param ep_dev : ep pipe of device
|
||||
* @param ep_type : USB_ENDPOINT_XFERTYPE_MASK @ref usb_ch9.h
|
||||
* @param max_pkt_size :
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void hgusb20_host_tx_ep_init(struct hgusb20_dev *p_dev, uint8 ep_host, uint8 ep_dev, uint8 ep_type, uint16 max_pkt_size);
|
||||
void hgusb20_host_rx_ep_init(struct hgusb20_dev *p_dev, uint8 ep_host, uint8 ep_dev, uint8 ep_type, uint16 max_pkt_size);
|
||||
|
||||
/**
|
||||
* @brief hgusb20_host_clear_data_toggle
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep_num : [1,2]
|
||||
* @param ep_type : EndpointDir BIT[7]:IN = 1, OUT = 0
|
||||
* @return :
|
||||
* @note
|
||||
*/
|
||||
void hgusb20_host_clear_data_toggle(struct hgusb20_dev *p_dev, uint8 ep_num, uint8 ep_type);
|
||||
|
||||
/**
|
||||
* @brief hgusb20_host_flush_fifo
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep_num : [1,2]
|
||||
* @param ep_type : EndpointDir BIT[7]:IN = 1, OUT = 0
|
||||
* @return :
|
||||
* @note
|
||||
*/
|
||||
void hgusb20_host_flush_fifo(struct hgusb20_dev *p_dev, uint8 ep_num, uint8 ep_type);
|
||||
|
||||
/**
|
||||
* @brief usb host get stall status
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep_num : [0,2]
|
||||
* @param ep_type : EndpointDir BIT[7]:IN = 1, OUT = 0
|
||||
* @return : TRUE or FLASE
|
||||
* @note
|
||||
*/
|
||||
bool hgusb20_host_is_rx_stall(struct hgusb20_dev *p_dev, uint8 ep_num, uint8 ep_type);
|
||||
/**
|
||||
* @brief usb host get xact error status (continous no response three times)
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep_num : [0,2]
|
||||
* @param ep_type : EndpointDir BIT[7]:IN = 1, OUT = 0
|
||||
* @return : TRUE or FLASE
|
||||
* @note
|
||||
*/
|
||||
bool hgusb20_host_is_xact_err(struct hgusb20_dev *p_dev, uint8 ep_num, uint8 ep_type);
|
||||
/**
|
||||
* @brief usb host get nak timeout status
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep_num : [0,2]
|
||||
* @param ep_type : EndpointDir BIT[7]:IN = 1, OUT = 0
|
||||
* @return : TRUE or FLASE
|
||||
* @note
|
||||
*/
|
||||
bool hgusb20_host_is_nak_timeout(struct hgusb20_dev *p_dev, uint8 ep_num, uint8 ep_type);
|
||||
/**
|
||||
* @brief usb host get rx crc status
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param ep_num : [0,2]
|
||||
* @return : TRUE or FLASE
|
||||
* @note
|
||||
*/
|
||||
bool hgusb20_host_is_crc_err(struct hgusb20_dev *p_dev, uint8 ep_num);
|
||||
|
||||
void hgusb20_host_reset_phy(struct hgusb20_dev * p_dev);
|
||||
|
||||
int32 hgusb20_host_set_interval(struct hgusb20_dev *p_dev, uint8_t ep_host, uint8_t mode, uint32_t interval);
|
||||
void hgusb20_host_reset_ep_rxcsr(struct hgusb20_dev *p_dev, uint8 ep_num);
|
||||
void hgusb20_host_reset_ep_txcsr(struct hgusb20_dev *p_dev, uint8 ep_num);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* USB_DEV_API_H */
|
||||
@@ -0,0 +1,69 @@
|
||||
/*****************************************************************************
|
||||
* Module : usb
|
||||
* File : usb_dev.h
|
||||
* Author :
|
||||
* Function : USB Device驱动的一些定义
|
||||
*****************************************************************************/
|
||||
#ifndef USB20_DEV_H
|
||||
#define USB20_DEV_H
|
||||
|
||||
#include "typesdef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define USB_REQUEST_DIRECTION (p_dev->usb_ctrl.cmd.rtype & 0x80)
|
||||
#define USB_REQUEST_TYPE (p_dev->usb_ctrl.cmd.rtype & 0x60)
|
||||
#define USB_REQUEST_RECIPIENT (p_dev->usb_ctrl.cmd.rtype & 0x1f)
|
||||
#define USB_REQUEST_ENDPOINT BYTE0(p_dev->usb_ctrl.cmd.index)
|
||||
#define USB_REQUEST_TEST_INDEX BYTE1(p_dev->usb_ctrl.cmd.index)
|
||||
#define USB_REQUEST_FEATURE_SELECTOR (p_dev->usb_ctrl.cmd.value)
|
||||
#define USB_REQUEST_DESCRIPTOR_TYPE BYTE1(p_dev->usb_ctrl.cmd.value)
|
||||
#define USB_REQUEST_DESCRIPTOR_INDEX BYTE0(p_dev->usb_ctrl.cmd.value)
|
||||
#define USB_REQUEST_LENGTH (p_dev->usb_ctrl.cmd.length)
|
||||
|
||||
|
||||
struct hgusb20_dev_info {
|
||||
//uint8_t type; //设备类型
|
||||
//uint8_t set_addr; //设地址
|
||||
//uint8_t cfg_value; //Config Value, 用于Set Config与Get Config
|
||||
uint8_t cur_state : 4, //USB当前状态机
|
||||
ep0_state : 4; //EP0的状态机
|
||||
uint8_t ep0_pkt; //EP0包大小
|
||||
uint8_t *ep0_ptr; //当前发送指针
|
||||
uint16_t ep0_len; //当前发送剩余
|
||||
uint8_t *ep0_ptr_rx; //当前发送指针
|
||||
uint16_t ep0_len_rx; //当前发送剩余
|
||||
|
||||
volatile uint8_t ep_tx_stall; //ep1 tx stall标志
|
||||
volatile uint8_t ep_rx_stall; //ep1 rx stall标志
|
||||
|
||||
// uint8_t ep_num_rx;
|
||||
// uint8_t ep_num_tx;
|
||||
// uint8_t ep_rx_type;
|
||||
// uint8_t ep_tx_type;
|
||||
// uint16_t max_pkt_rx[MAX_EP];
|
||||
// uint16_t max_pkt_tx[MAX_EP];
|
||||
} ;
|
||||
|
||||
struct hgusb20_audio_ctrl {
|
||||
uint8_t speaker_mute;
|
||||
uint8_t mic_mute;
|
||||
uint8_t volume;
|
||||
/*
|
||||
uint8_t *adc_root;
|
||||
uint8_t *adc_end;
|
||||
uint8_t *adc_ptr;
|
||||
int16_t adc_cnt;
|
||||
int16_t adc_total;
|
||||
int8_t mic_speed;
|
||||
*/
|
||||
} ;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*****************************************************************************
|
||||
* Module : usb
|
||||
* File : usb_dev_tbl.h
|
||||
* Author :
|
||||
* Function : USB驱动的一些常量表的申明
|
||||
*****************************************************************************/
|
||||
#ifndef USB_DEV_TBL_H
|
||||
#define USB_DEV_TBL_H
|
||||
|
||||
#define WCID_VENDOR_CODE 0xA0
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern const uint8_t tbl_usb_device_descriptor[18];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_gen[9];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_wifi[23];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_mass[23];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_head[19];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_speaker[31];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_audio_ctrl_mic[30];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_speaker_stream[52];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_mic_stream[52];
|
||||
extern const uint8_t tbl_usb_config_all_descriptor_hid[25];
|
||||
extern const uint8_t tbl_usb_hid_report_descriptor[33];
|
||||
extern const uint8_t tbl_usb_language_id[4];
|
||||
extern const uint8_t tbl_usb_str_manufacturer[16];
|
||||
extern const uint8_t tbl_usb_str_product[28];
|
||||
extern const uint8_t tbl_usb_str_serial_number[30];
|
||||
extern const uint8_t tbl_scsi_inquiry_data[36];
|
||||
|
||||
/* bcdUSB = 2.0 */
|
||||
extern const uint8_t tbl_winusb_device_descriptor[18];
|
||||
extern const uint8_t tbl_winusb_compatible_id_feature_descriptor[40];
|
||||
extern const uint8_t tbl_winncm_compatible_id_feature_descriptor[40];
|
||||
extern const uint8_t tbl_rndis_compatible_id_feature_descriptor[40];
|
||||
extern const uint8_t tbl_winusb_device_interface_guids[142];
|
||||
extern const uint8_t tbl_net_device_interface_guids[142];
|
||||
extern const uint8_t tbl_winncm_class_request_get_ntb_params[28];
|
||||
extern const uint8_t tbl_winusb20_wcid_descriptor_set[162];
|
||||
/* bcdUSB >= 2.01 , best 2.1 */
|
||||
extern const uint8_t tbl_winusb20_wcidbos[33];
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,619 @@
|
||||
#ifndef _UVC_HOST_H
|
||||
#define _UVC_HOST_H
|
||||
|
||||
#include "typesdef.h"
|
||||
#include "list.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UVC_DESCRIPTOR_UNDEFINED=0,
|
||||
UVC_HEADER,
|
||||
UVC_INPUT_TERMINAL,
|
||||
UVC_OUTPUT_TERMINAL,
|
||||
UVC_SELECTOR_UNIT,
|
||||
UVC_PROCESSING_UNIT,
|
||||
UVC_EXTENSION_UNIT,
|
||||
UVC_ENCODING_UNIT
|
||||
}VC_Subtype;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
VS_UNDEFINED=0,
|
||||
VS_INPUT_HEADER,
|
||||
VS_OUTPUT_HEADER,
|
||||
VS_STILL_IMAGE_FRAME,
|
||||
VS_FORMAT_UNCOMPRESSED,
|
||||
VS_FRAME_UNCOMPRESSED,
|
||||
VS_FORMAT_MJPEG,
|
||||
VS_FRAME_MJPEG,
|
||||
Reserved,
|
||||
Reserved1,
|
||||
VS_FORMAT_MPEG2TS,
|
||||
Reserved2,
|
||||
VS_FORMAT_DV,
|
||||
VS_COLORFORMAT,
|
||||
Reserved3,
|
||||
Reserved4,
|
||||
VS_FORMAT_FRAME_BASED,
|
||||
VS_FRAME_FRAME_BASED,
|
||||
VS_FORMAT_STREAM_BASED,
|
||||
VS_FORMAT_H264,
|
||||
VS_FRAME_H264,
|
||||
VS_FORMAT_H264_SIMULCAST
|
||||
}VS_Subtype;
|
||||
|
||||
// Standard Configuration Descriptor
|
||||
typedef struct
|
||||
{
|
||||
uint8 length; // Size of descriptor in uint8
|
||||
uint8 type; // Configuration
|
||||
uint16 t_length; // Total length
|
||||
uint8 num_intf; // Number of interface
|
||||
uint8 cv; // bConfigurationValue
|
||||
uint8 index; // iConfiguration
|
||||
uint8 attr; // Configuration Characteristic
|
||||
uint8 max_power; // Power config
|
||||
} SCFG_DESC, *P_SCFG_DESC;
|
||||
|
||||
|
||||
|
||||
// Standard Interface Descriptor
|
||||
typedef struct
|
||||
{
|
||||
uint8 length;
|
||||
uint8 type;
|
||||
uint8 num;
|
||||
uint8 alt_tring;
|
||||
uint8 end_points;
|
||||
uint8 iclass;
|
||||
uint8 sub;
|
||||
uint8 proto;
|
||||
uint8 index;
|
||||
} SINTF_DESC, *P_INTF_DESC;
|
||||
|
||||
// Standard Device Descriptor
|
||||
typedef struct
|
||||
{
|
||||
uint8 length;
|
||||
uint8 descriptor_type;
|
||||
uint16 bcd_usb;
|
||||
uint8 device_class;
|
||||
uint8 device_subclass;
|
||||
uint8 device_protocol;
|
||||
uint8 maxpacket_size0;
|
||||
uint16 id_vendor;
|
||||
uint16 id_product;
|
||||
uint16 bcd_device;
|
||||
uint8 manufacturer;
|
||||
uint8 product;
|
||||
uint8 serial_number;
|
||||
uint8 num_configurations;
|
||||
} SDEV_DESC, *P_DEV_DESC;
|
||||
|
||||
// Standard EndPoint Descriptor
|
||||
typedef struct
|
||||
{
|
||||
uint8 length;
|
||||
uint8 type;
|
||||
uint8 ep_addr;
|
||||
uint8 attr;
|
||||
uint16 pay_load; // low-speed this must be 0x08
|
||||
uint8 interval;
|
||||
} SEP_DESC, *P_EP_DESC;
|
||||
|
||||
struct VC_PROCESS{
|
||||
uint8 bLength;
|
||||
uint8 bDescriptorType;
|
||||
uint8 bDescriptorSubtype;
|
||||
uint8 bUnitID;
|
||||
uint8 bSourceID;
|
||||
uint16 wMaxMultiplier;
|
||||
uint8 bControlSize;
|
||||
uint32 bmControls;
|
||||
uint8 iProcessing;
|
||||
}__attribute__((packed));
|
||||
|
||||
typedef struct{
|
||||
uint8 bLength;
|
||||
uint8 bDescriptorType;
|
||||
uint8 bDescriptorSubtype;
|
||||
uint8 bFrameIndex;
|
||||
uint8 bmCapabilities;
|
||||
uint16 wWidth;
|
||||
uint16 wHeight;
|
||||
|
||||
}VS_FRAME;
|
||||
|
||||
typedef struct{
|
||||
uint8 bLength;
|
||||
uint8 bDescriptorType;
|
||||
uint8 bDescriptorSubtype;
|
||||
uint8 bFrameIndex;
|
||||
uint8 bNumFrameDescriptors;
|
||||
}VS_FORMAT;
|
||||
|
||||
typedef struct{
|
||||
uint8 bLength;
|
||||
uint8 bDescriptorType;
|
||||
uint8 bDescriptorSubtype;
|
||||
uint8 bNumFormats;
|
||||
}VS_HEAD;
|
||||
|
||||
#define INTERFACE_Type 0x24
|
||||
#define STRAME_O_CONTORL 0x04
|
||||
#define ENDPOINT_DESC 0x05
|
||||
|
||||
#define VS_FAME_TYPE_MAXNUM 20
|
||||
#define VS_FORMAT_TYPE_MAXNUM 2
|
||||
|
||||
#define __INTFS_STACK__ 32
|
||||
#define IS_UVC_JPEG 1
|
||||
|
||||
#define USB_DEV_UVC_CLASS 0xef
|
||||
#define USB_DEV_HUB_CLASS 0X09
|
||||
|
||||
|
||||
#define UVC_SET_REQ 0x21
|
||||
#define UVC_GET_REQ 0xA1
|
||||
#define UVC_SET_CUR 0x01
|
||||
#define UVC_GET_CUR 0x81
|
||||
#define UVC_GET_MIN 0x82
|
||||
#define UVC_GET_MAX 0x83
|
||||
#define UVC_GET_RES 0x84
|
||||
#define UVC_GET_LEN 0x85
|
||||
#define UVC_GET_INFO 0x86
|
||||
#define UVC_GET_DEF 0x87
|
||||
#define UVC_CLASS 0x0e
|
||||
#define UAC_CLASS 0x01
|
||||
#define UVC_VGA 1
|
||||
#define UVC_720P 2
|
||||
|
||||
|
||||
typedef struct{
|
||||
uint8 DesLen;
|
||||
uint8 DescriptorType;
|
||||
uint8 Subtype;
|
||||
uint8 control_endpoint;
|
||||
VS_HEAD vs_head;
|
||||
VS_FRAME vs_frame[VS_FAME_TYPE_MAXNUM];
|
||||
VS_FORMAT vs_format[VS_FORMAT_TYPE_MAXNUM];
|
||||
uint8 vs_frame_num;
|
||||
uint8 vs_format_num;
|
||||
uint32 intfs_count;
|
||||
uint32 edpt_count;
|
||||
SINTF_DESC intfs[__INTFS_STACK__];
|
||||
SEP_DESC edpt[__INTFS_STACK__];
|
||||
|
||||
struct VC_PROCESS vc_process;
|
||||
uint8 control_intfs;
|
||||
}UVC_DES;
|
||||
|
||||
typedef struct{
|
||||
uint8 ep;
|
||||
uint8 eptpye;
|
||||
uint16 len;
|
||||
}EP_DES;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8 ctyp;
|
||||
|
||||
uint8 cv;
|
||||
uint8 epctl;
|
||||
uint8 ctl_intfs;
|
||||
uint8 ctl_altset;
|
||||
uint8 ctl_pload;
|
||||
uint8 ctl_ttyp;
|
||||
uint8 ctl_interval;
|
||||
|
||||
uint8 epstrm;
|
||||
uint8 strm_intfs;
|
||||
uint8 strm_altset;
|
||||
uint16 strm_pload;
|
||||
uint8 strm_ttyp;
|
||||
uint8 strm_interval;
|
||||
}UVCDEV;
|
||||
|
||||
typedef struct{
|
||||
uint8 ctl_intfs;
|
||||
uint32 process_ctl;
|
||||
uint8 process_unitID;
|
||||
}UVC_PROCESS;
|
||||
|
||||
typedef struct {
|
||||
uint8 ctl_val;
|
||||
int16 info;
|
||||
int16 max;
|
||||
int16 min;
|
||||
uint16 res;
|
||||
int16 cur;
|
||||
}UVC_PROC_REQ;
|
||||
|
||||
typedef struct{
|
||||
UVC_PROC_REQ brightness;
|
||||
UVC_PROC_REQ contrast;
|
||||
UVC_PROC_REQ hue;
|
||||
UVC_PROC_REQ saturation;
|
||||
UVC_PROC_REQ sharpness;
|
||||
UVC_PROC_REQ gamma;
|
||||
UVC_PROC_REQ white_bal_temp;
|
||||
UVC_PROC_REQ white_bal_comp;
|
||||
UVC_PROC_REQ backlight_comp;
|
||||
UVC_PROC_REQ gain;
|
||||
UVC_PROC_REQ power_line_fre;
|
||||
UVC_PROC_REQ hue_auto;
|
||||
UVC_PROC_REQ white_bal_temp_auto;
|
||||
UVC_PROC_REQ white_bal_comp_auto;
|
||||
UVC_PROC_REQ digital_mult;
|
||||
UVC_PROC_REQ digital_mult_limit;
|
||||
UVC_PROC_REQ ana_video_stan;
|
||||
UVC_PROC_REQ ana_lock_sta;
|
||||
UVC_PROC_REQ contrast_auto;
|
||||
}UVC_PROCESS_INFO;
|
||||
|
||||
typedef enum {
|
||||
BRIGHTNESS,
|
||||
CONTRAST,
|
||||
HUE,
|
||||
SATURATION,
|
||||
SHARPNESS,
|
||||
GAMMA,
|
||||
WHITE_BAL_TEMP,
|
||||
WHITE_BAL_COMP,
|
||||
BACKLIGHT_COMP,
|
||||
GAIN,
|
||||
POWER_LINE_FRE,
|
||||
HUE_AUTO,
|
||||
WHITE_BAL_TEMP_AUTO,
|
||||
WHITE_BAL_COMP_AUTO,
|
||||
DIGITAL_MULT,
|
||||
DIGITAL_MULT_LIMIT,
|
||||
ANA_VIDEO_STAN,
|
||||
ANA_LOCK_STA,
|
||||
AONTRAST_AUTO
|
||||
}UVC_PROCESS_ENUM;
|
||||
|
||||
typedef struct{
|
||||
VS_FRAME vs_frame;
|
||||
VS_FORMAT vs_format;
|
||||
}UVC_SLEST;
|
||||
|
||||
struct VIDEO_COMMIT
|
||||
{
|
||||
uint16 bmhint;
|
||||
uint8 bFormatIndex;
|
||||
uint8 bFrameIndex;
|
||||
uint32 dwFrameInterval;
|
||||
uint16 wKeyFrameRate;
|
||||
uint16 wPFrameRate;
|
||||
uint16 wCompQuality;
|
||||
uint16 wCompWindowSize;
|
||||
uint16 wDelay;
|
||||
uint32 dwMaxVideoFrameSize;
|
||||
uint32 dwMaxPayloadTSize;
|
||||
}__attribute__((packed));
|
||||
|
||||
|
||||
typedef struct {
|
||||
struct list_head list;
|
||||
uint8 *cpbuff; //当前写入数据的地址
|
||||
uint8 uvc_head[16];//one pack head data
|
||||
uint8 frame_end; //frame结束标志,表示USB获取数据结束 0:进行中 1:正常结束 2:异常结束
|
||||
uint32 tgl;
|
||||
uint32 sta;
|
||||
uint32 state; //frame状态,0:空闲 1:正在填充 2:可用 3:应用正在使用
|
||||
uint32 frame_len; //帧长度
|
||||
uint32 data_len;//one packe data len
|
||||
uint32 head_len;//one packe head len
|
||||
uint32 re_space;//当前所写的buff剩余空间
|
||||
uint32 frame_counter;
|
||||
}UVC_MANAGE;
|
||||
|
||||
|
||||
typedef struct {
|
||||
struct list_head list; //BLANK块节点互连
|
||||
uint32 frame_counter; //此数据块代表的frame号
|
||||
uint32 blank_len; //blank可使用的数据长度,最后一个数据块非满外,其他都满
|
||||
uint32 re_space; //当前blank剩下多少空间可填
|
||||
uint8 blank_loop; //blank计数,每一帧都从0开始增加,便于后面重组
|
||||
uint8 *buf_ptr; //数据块指针
|
||||
uint8 busy; //blank块状态,0:空闲 1:正在填充或者发送 2:可用
|
||||
}UVC_BLANK;
|
||||
|
||||
typedef struct{
|
||||
uint8 addr;
|
||||
uint8 int_endpoint;
|
||||
uint8 port_num;
|
||||
uint8 connect_port;
|
||||
}HUB_manage;
|
||||
|
||||
|
||||
enum usb_host_io_cmd {
|
||||
USB_HOST_IO_CMD_RESET, //usb复位
|
||||
USB_HOST_IO_CMD_SET_CUR,
|
||||
USB_HOST_IO_CMD_GET_CUR,
|
||||
USB_HOST_IO_CMD_SET_IDX, //1:VGA, 2:720
|
||||
};
|
||||
|
||||
struct uvc_user_arg
|
||||
{
|
||||
void *usb_dev;
|
||||
uint32_t state; //0:可以创建任务 1:正在运行 2:等待任务删除
|
||||
uint32_t uvc_format;
|
||||
};
|
||||
|
||||
|
||||
/****************uac****************/
|
||||
typedef enum
|
||||
{
|
||||
AC_UNDEFINED=0,
|
||||
AC_HEADER_DES,
|
||||
AC_INPUT_DES,
|
||||
AC_OUTPUT_DES,
|
||||
AC_MIXER_DES,
|
||||
AC_SELECTOR_DES,
|
||||
AC_FEATURE_DES
|
||||
}AC_Subtype;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
AS_UNDEFINED=0,
|
||||
AS_General_Des,
|
||||
AS_Format_Des
|
||||
}AS_Subtype;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
USB_Undefined = 0x0100,
|
||||
USB_streaming = 0x0101,
|
||||
USB_vendor_specific = 0x01FF,
|
||||
Input_Undefined = 0x0200,
|
||||
Microphone = 0x0201,
|
||||
Desktop_microphone = 0x0202,
|
||||
Output_Undefined = 0x0300,
|
||||
Speaker = 0x0301,
|
||||
Headphones = 0x0302
|
||||
}AC_Terminal_Types;
|
||||
|
||||
typedef struct{
|
||||
uint8 bLength;
|
||||
uint8 bDescriptorType;
|
||||
uint8 bDescriptorSubtype;
|
||||
uint8 bTerminalID;
|
||||
uint16 wTerminalType;
|
||||
uint8 bAssocTerminal;
|
||||
uint8 bNrChannels;
|
||||
uint16 wChannelConfig;
|
||||
uint8 iChannelNames;
|
||||
uint8 iTerminal;
|
||||
}AC_INPUT;
|
||||
|
||||
typedef struct{
|
||||
uint8 bLength;
|
||||
uint8 bDescriptorType;
|
||||
uint8 bDescriptorSubtype;
|
||||
uint8 bUnitID;
|
||||
uint8 bSourceID;
|
||||
uint8 bControlSize;
|
||||
uint8 bmaControls[2];
|
||||
}AC_FEATURE;
|
||||
|
||||
typedef struct{
|
||||
uint8 bLength;
|
||||
uint8 bDescriptorType;
|
||||
uint8 bDescriptorSubtype;
|
||||
uint8 bTerminalID;
|
||||
uint16 wTerminalType;
|
||||
uint8 bAssocTerminal;
|
||||
uint8 bSourceID;
|
||||
uint8 iTerminal;
|
||||
}AC_OUTPUT;
|
||||
|
||||
typedef struct{
|
||||
uint8 bLength;
|
||||
uint8 bDescriptorType;
|
||||
uint8 bInterfaceNumber;
|
||||
uint8 bAlternateSetting;
|
||||
uint8 bNumEndpoints;
|
||||
uint8 bInterfaceClass;
|
||||
uint8 bInterfaceSubClass;
|
||||
uint8 bInterfaceProtocol;
|
||||
uint8 iInterface;
|
||||
}AS_INTERFACE;
|
||||
|
||||
typedef struct{
|
||||
uint8 bLength;
|
||||
uint8 bDescriptorType;
|
||||
uint8 bDescriptorSubtype;
|
||||
uint8 bTerminalLink;
|
||||
uint8 bDelay;
|
||||
uint16 wFormatTag;
|
||||
}AS_GENERAL;
|
||||
|
||||
typedef struct{
|
||||
uint8 bLength;
|
||||
uint8 bDescriptorType;
|
||||
uint8 bDescriptorSubtype;
|
||||
uint8 bFormatType;
|
||||
uint8 bNrChannels;
|
||||
uint8 bSubframeSize;
|
||||
uint8 bBitResolution;
|
||||
uint8 bSamFreqType;
|
||||
uint32 tSamFreq[4];
|
||||
}AS_FORMAT;
|
||||
|
||||
typedef struct{
|
||||
uint8 bLength;
|
||||
uint8 bDescriptorType;
|
||||
uint8 bEndpointAddress;
|
||||
uint8 bmAttributes;
|
||||
uint16 wMaxPacketSize;
|
||||
uint8 bInterval;
|
||||
uint8 bRefresh;
|
||||
uint8 bSynchAddress;
|
||||
}AS_ENDPOINT;
|
||||
|
||||
#define AS_GENERAL_TYPE_MAXNUM 10
|
||||
#define AS_FORMAT_TYPE_MAXNUM 10
|
||||
|
||||
typedef struct{
|
||||
uint8 DesLen;
|
||||
uint8 DescriptorType;
|
||||
uint8 Subtype;
|
||||
uint8 control_endpoint;
|
||||
uint8 control_interface;
|
||||
AC_INPUT ac_input[3];
|
||||
AC_OUTPUT ac_output[3];
|
||||
AC_FEATURE ac_feature[3];
|
||||
AS_INTERFACE as_interface[4];
|
||||
AS_GENERAL as_general[AS_GENERAL_TYPE_MAXNUM];
|
||||
AS_FORMAT as_format[AS_FORMAT_TYPE_MAXNUM];
|
||||
AS_ENDPOINT as_endpoint[10];
|
||||
uint8 ac_input_num;
|
||||
uint8 ac_feature_num;
|
||||
uint8 ac_output_num;
|
||||
uint8 as_interface_num;
|
||||
uint8 as_general_num;
|
||||
uint8 as_format_num;
|
||||
uint8 as_endpoint_num;
|
||||
}UAC_DES;
|
||||
|
||||
typedef struct{
|
||||
uint16 spk_type;
|
||||
uint8 spk_strm_intfs;
|
||||
uint8 spk_strm_altset[4];
|
||||
uint16 spk_fmttag[4];
|
||||
uint8 spk_fmttype[4];
|
||||
uint8 spk_nrchl[4];
|
||||
uint8 spk_fmsize[4];
|
||||
uint8 spk_bitres[4];
|
||||
uint8 spk_samfretype[4];
|
||||
uint8 spk_samfre[4][4];
|
||||
uint8 spk_epstrm[4];
|
||||
uint8 spk_eptype[4];
|
||||
uint16 spk_strm_pload[4];
|
||||
uint8 spk_feaunitID;
|
||||
uint8 spk_feaunit_ctl[2];
|
||||
int16 spk_max_vol;
|
||||
int16 spk_min_vol;
|
||||
|
||||
uint16 mic_type;
|
||||
uint8 mic_strm_intfs;
|
||||
uint8 mic_strm_altset[4];
|
||||
uint16 mic_fmttag[4];
|
||||
uint16 mic_fmttype[4];
|
||||
uint8 mic_nrchl[4];
|
||||
uint8 mic_fmsize[4];
|
||||
uint8 mic_bitres[4];
|
||||
uint8 mic_samfretype[4];
|
||||
uint8 mic_samfre[4][4];
|
||||
uint8 mic_epstrm[4];
|
||||
uint8 mic_eptype[4];
|
||||
uint16 mic_strm_pload[4];
|
||||
uint8 mic_feaunitID;
|
||||
uint8 mic_feaunit_ctl[2];
|
||||
int16 mic_max_vol;
|
||||
int16 mic_min_vol;
|
||||
|
||||
uint8 ctl_intfs;
|
||||
}UACDEV;
|
||||
|
||||
typedef struct{
|
||||
uint8 strm_intfs;
|
||||
uint8 strm_altset;
|
||||
uint8 epstrm;
|
||||
uint8 eptype;
|
||||
uint16 strm_pload;
|
||||
}MICDEV;
|
||||
|
||||
typedef struct{
|
||||
uint8 strm_intfs;
|
||||
uint8 strm_altset;
|
||||
uint8 epstrm;
|
||||
uint8 eptype;
|
||||
uint16 strm_pload;
|
||||
}SPKDEV;
|
||||
|
||||
typedef struct{
|
||||
struct list_head list;
|
||||
uint8 *data_addr; //当前写入数据的地址
|
||||
uint32 data_len;
|
||||
uint32 respace_len;
|
||||
uint32 offset;
|
||||
uint8 sta;
|
||||
}UAC_MANAGE;
|
||||
|
||||
/**********uac************/
|
||||
|
||||
#define HUB_STATU_CONNECT (BIT(1))
|
||||
#define HUB_STATU_RESTEND (BIT(1))
|
||||
/**hub clear feature **/
|
||||
#define PORT_CONNECT 0x10
|
||||
#define PORT_ENABLE 0X01
|
||||
#define CLEAR_PORT_REST 0x14
|
||||
/**hub set feature **/
|
||||
#define PORT_POWER 0X08
|
||||
#define PORT_REST 0x04
|
||||
|
||||
#define UVC_EP 2
|
||||
#define HUB_EP 1
|
||||
#define UAC_EP 3
|
||||
#define UVC2_EP 1
|
||||
|
||||
|
||||
#define ISO_HEAD 0
|
||||
#define BULK_HEAD 12
|
||||
#define UVC_HEAD BULK_HEAD
|
||||
|
||||
|
||||
#define UVC_HOST_NUM 2
|
||||
|
||||
void uvc_room_init(void *p_dev);
|
||||
void usb_dma_irq(void * dev, uint8_t* uvc_rx_buff, uint8_t uvc_head_res, uint8_t ep_type);
|
||||
|
||||
//void usb_host_irq(typedef_usb_t *usb_sw);
|
||||
|
||||
void uvc_user();
|
||||
|
||||
void uvc_room_init_mjpeg();
|
||||
void uvc_room_deinit_mjpeg();
|
||||
void uvc_room_init_h264();
|
||||
void uvc_room_deinit_h264(void);
|
||||
void uvc_reset_dev(uint8_t en);
|
||||
void uvc_reset_dev_mjpeg(uint8_t en);
|
||||
void uvc_reset_dev_h264(uint8_t en);
|
||||
|
||||
void uvc_sema_init();
|
||||
void uvc_sema_down(int32 tmo_ms);
|
||||
void uvc_sema_up();
|
||||
|
||||
|
||||
void uvc_app_user_init();
|
||||
void force_reset_uvc_frame();
|
||||
|
||||
UVC_MANAGE* get_uvc_message_gloal();
|
||||
uint32 get_uvc_frame_len();
|
||||
uint8* get_uvc_buf();
|
||||
uint8 free_uvc_blank(UVC_BLANK* uvc_b);
|
||||
UVC_BLANK* get_uvc_blank();
|
||||
|
||||
extern void del_usbmic_frame(UAC_MANAGE *uac_manage);
|
||||
extern UAC_MANAGE *get_usbmic_frame(void);
|
||||
extern uint32 get_uac_frame_datalen(UAC_MANAGE *uac_manage);
|
||||
extern uint8 *get_uac_frame_data(UAC_MANAGE *uac_manage);
|
||||
extern void set_uac_frame_datalen(UAC_MANAGE *uac_manage, uint32 len);
|
||||
extern UAC_MANAGE *get_usbspk_new_frame(uint8 grab);
|
||||
extern void put_usbspk_frame_to_use(UAC_MANAGE *uac_manage);
|
||||
extern void set_uac_frame_sta(UAC_MANAGE *uac_manage, uint8 sta);
|
||||
extern void usbspk_room_init(uint32_t empty_buf_len);
|
||||
extern void usbmic_room_init(void);
|
||||
extern void usbmic_dma_irq(void *dev, uint8_t* mic_rx_buff);
|
||||
extern void usbspk_dma_irq(void *dev);
|
||||
extern void uac_stop(void);
|
||||
extern void uac_start(void *dev, uint8_t* mic_rx_buff);
|
||||
extern int uvc_ep_bulk_or_isoc();
|
||||
extern void force_reset_usbmic_frame();
|
||||
extern void force_reset_usbspk_frame();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user