Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
200
sdk/include/dev/usb/hgusb20_v1_base.h
Normal file
200
sdk/include/dev/usb/hgusb20_v1_base.h
Normal file
@@ -0,0 +1,200 @@
|
||||
/*****************************************************************************
|
||||
* 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 SIE寄存器
|
||||
#define write_usb_reg(reg_addr, reg_data) do {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();\
|
||||
hw->SIEM_INDEX = index;\
|
||||
*((volatile uint8_t *)((uint32_t)&hw->SIEM_FADDR + reg_addr)) = reg_data;\
|
||||
USB_REG_CRITICAL_EXIT();\
|
||||
} while(0)
|
||||
|
||||
|
||||
//读USB SIE寄存器
|
||||
#define read_usb_reg(reg_addr) (*((volatile uint8_t *)((uint32_t)&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();\
|
||||
hw->SIEM_INDEX = index;\
|
||||
reg_data = *((volatile uint8_t *)((uint32_t)&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,
|
||||
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
|
||||
hdr_req : 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
|
||||
691
sdk/include/dev/usb/hgusb20_v1_dev_api.h
Normal file
691
sdk/include/dev/usb/hgusb20_v1_dev_api.h
Normal file
@@ -0,0 +1,691 @@
|
||||
#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;
|
||||
uint16 time_out;
|
||||
uint8 stall;
|
||||
} type_usb_host;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
uint8 dev_hub_addr : 7,
|
||||
hub_mtt_en : 1;
|
||||
};
|
||||
uint8 usb_hub_addr;
|
||||
} u_usb_hub_addr;
|
||||
uint8 dev_hub_port;
|
||||
uint8 dev_addr;
|
||||
|
||||
uint8 ep_host : 4,
|
||||
ep_host_rsv : 4;
|
||||
|
||||
#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
|
||||
#define USB_ENDPOINT_XFER_CONTROL 0
|
||||
#define USB_ENDPOINT_XFER_ISOC 1
|
||||
#define USB_ENDPOINT_XFER_BULK 2
|
||||
#define USB_ENDPOINT_XFER_INT 3
|
||||
#define USB_ENDPOINT_SPEED_DEFAULT 0x00
|
||||
#define USB_ENDPOINT_SPEED_HIGH 0x01
|
||||
#define USB_ENDPOINT_SPEED_FULL 0x02
|
||||
#define USB_ENDPOINT_SPEED_LOW 0x03
|
||||
uint8 ep_dev : 4,
|
||||
ep_type : 2,
|
||||
ep_speed : 2;
|
||||
|
||||
uint16 max_pkt_size;
|
||||
} hgusb20_pipe_attr ;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8 offset;
|
||||
uint8 rx_len;
|
||||
uint16 rx_total;
|
||||
} type_ep0_ptr;
|
||||
|
||||
|
||||
typedef enum {
|
||||
UDISK_DEV = 1,
|
||||
UVC_DEV
|
||||
}USB_DEV_TYPE;
|
||||
|
||||
|
||||
struct ep_trx_ctrl {
|
||||
uint32 addr;
|
||||
uint32 total_bytes;
|
||||
uint32 max_packet_size;
|
||||
uint32 cur_addr;
|
||||
uint32 cur_counter;
|
||||
uint32 last_counter;
|
||||
uint32 tx_null_pkt_en;
|
||||
uint32 tx_null_pkt_flag;
|
||||
};
|
||||
|
||||
|
||||
struct hgusb20_dev {
|
||||
struct usb_device dev;
|
||||
void *usb_hw;
|
||||
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 uint8 usb_rxdma_flag;
|
||||
volatile uint8 usb_txdma_flag;
|
||||
|
||||
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;
|
||||
|
||||
struct ep_trx_ctrl ep_trans_ctrl[7];
|
||||
struct ep_trx_ctrl ep_recevice_ctrl[7];
|
||||
|
||||
#ifdef CONFIG_SLEEP
|
||||
uint32 sys_regs[4];
|
||||
#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 (TXW81X)
|
||||
* @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 usb host pipe init (TXW82X)
|
||||
* @param p_dev : hgusb20_dev use @ref dev_get() function to get the handle.
|
||||
* @param usb_pipe : ep pipe of host
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void hgusb20_host_tx_pipe_combine(struct hgusb20_dev *p_dev, hgusb20_pipe_attr *usb_pipe);
|
||||
void hgusb20_host_rx_pipe_combine(struct hgusb20_dev *p_dev, hgusb20_pipe_attr *usb_pipe);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
void hgusb20_host_hub_ep0_mange(struct hgusb20_dev *p_dev, hgusb20_pipe_attr *usb_pipe);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* USB_DEV_API_H */
|
||||
69
sdk/include/dev/usb/hgusb20_v1_dev_ep0.h
Normal file
69
sdk/include/dev/usb/hgusb20_v1_dev_ep0.h
Normal file
@@ -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
|
||||
56
sdk/include/dev/usb/hgusb_dev_tbl.h
Normal file
56
sdk/include/dev/usb/hgusb_dev_tbl.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*****************************************************************************
|
||||
* 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
|
||||
|
||||
138
sdk/include/dev/usb/usb11_v0/hgusb11_v0_dev_api.h
Normal file
138
sdk/include/dev/usb/usb11_v0/hgusb11_v0_dev_api.h
Normal file
@@ -0,0 +1,138 @@
|
||||
#ifndef _HG_USB11_V0_DEV_H
|
||||
#define _HG_USB11_V0_DEV_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "hal/usb_device.h"
|
||||
|
||||
enum hgusb11_device_flags {
|
||||
HGUSB11_DEVICE_FLAGS_OPENED = BIT(0),
|
||||
HGUSB11_DEVICE_FLAGS_READY = BIT(1),
|
||||
HGUSB11_DEVICE_FLAGS_SUSPEND = BIT(2),
|
||||
HGUSB11_DEVICE_FLAGS_DMA_MODE = BIT(3),
|
||||
HGUSB11_DEVICE_FLAGS_SOFT_SUBPACKAGE = BIT(4),
|
||||
};
|
||||
|
||||
/* USB通信控制块:USB Device Requests */
|
||||
struct _usb_device_requests {
|
||||
uint8 bmrequesttype;
|
||||
uint8 brequest;
|
||||
uint16 wvalue;
|
||||
uint16 windex;
|
||||
uint16 wlength;
|
||||
};
|
||||
|
||||
|
||||
/* USB EP0控制块:状态机 */
|
||||
enum _usb_ep0_state {
|
||||
USB_EP0_STATE_SETUP,
|
||||
USB_EP0_STATE_OUT,
|
||||
USB_EP0_STATE_IN,
|
||||
USB_EP0_STATE_LAST_IN,
|
||||
USB_EP0_STATE_LAST_OUT,
|
||||
USB_EP0_STATE_STATUS_IN,
|
||||
USB_EP0_STATE_STATUS_OUT,
|
||||
USB_EP0_STATE_STALL,
|
||||
};
|
||||
|
||||
|
||||
/* USB EP0控制块 */
|
||||
struct _usb_ep0_ctrl {
|
||||
|
||||
enum _usb_ep0_state ep0_state;
|
||||
|
||||
//本次要发送包的地址、总长度
|
||||
uint8 *p_ep0_ptk2send;
|
||||
uint32 ep0_ptk2send_size;
|
||||
|
||||
//偏移量和计数
|
||||
uint32 ep0_ptk_counter;
|
||||
uint32 ep0_buf_offset;
|
||||
|
||||
//单次发送包的最大长度
|
||||
uint32 ep0_oneptk_max_size;
|
||||
|
||||
uint8 ep0_buf[1024] __attribute__((aligned(4))); //针对iso传输接收非word对齐的数据dma写入的情况 fix:修改64为1024
|
||||
|
||||
};
|
||||
|
||||
struct usb11_ep_trx_ctrl {
|
||||
uint32 addr;
|
||||
uint32 total_bytes;
|
||||
uint32 max_packet_size;
|
||||
uint32 cur_addr;
|
||||
uint32 cur_counter;
|
||||
uint32 last_counter;
|
||||
};
|
||||
|
||||
union __comm_state{
|
||||
uint32 comm;
|
||||
struct {
|
||||
uint32 dev_open : 1,
|
||||
dev_host_mode : 1,
|
||||
dev_device_mode : 1,
|
||||
reserve : 29;
|
||||
} comm_bits;
|
||||
};
|
||||
typedef union __comm_state hgusb11_dev_v0_comm;
|
||||
|
||||
struct hgusb11_dev {
|
||||
struct usb_device dev;
|
||||
void *usb_hw;
|
||||
usbdev_irq_hdl irq_hdl;
|
||||
uint32 irq_data;
|
||||
uint8 ep_irq_num;
|
||||
uint8 dma_irq_num;
|
||||
|
||||
/* common areas */
|
||||
union __comm_state comm_dat;
|
||||
/* Pointer of common areas */
|
||||
void *p_comm;
|
||||
|
||||
/*
|
||||
* USB EP0的控制块
|
||||
*/
|
||||
struct _usb_ep0_ctrl ep0_ctrl;
|
||||
|
||||
struct os_event trx_lock;
|
||||
struct os_event trx_done;
|
||||
|
||||
struct usb11_ep_trx_ctrl ep_trans_ctrl[4];
|
||||
struct usb11_ep_trx_ctrl ep_recevice_ctrl[4];
|
||||
|
||||
//状态位
|
||||
uint32 flags;
|
||||
};
|
||||
|
||||
|
||||
int32 hgusb11_v0_dev_ep_set_stall(struct usb_device *p_usb_d, uint8 address);
|
||||
int32 hgusb11_v0_dev_ep_clear_stall(struct usb_device *p_usb_d, uint8 address);
|
||||
int32 hgusb11_v0_dev_set_address(struct usb_device *p_usb_d, uint8 address);
|
||||
int32 hgusb11_v0_dev_set_config(struct usb_device *p_usb_d, uint8 address);
|
||||
int32 hgusb11_v0_dev_ep_enable(struct usb_device *p_usb_d, uint8 ep, uint16 max_pkt_size, uint8 attributes);
|
||||
int32 hgusb11_v0_dev_ep_disable(struct usb_device *p_usb_d, uint8 ep);
|
||||
int32 hgusb11_v0_dev_ep_read(struct usb_device *p_usb_d, uint8 address, void *buffer);
|
||||
int32 hgusb11_v0_dev_ep_read_prepare(struct usb_device *p_usb_d, uint8 address, void *buffer, uint32 size);
|
||||
int32 hgusb11_v0_dev_read(struct usb_device *p_usb_d, uint8 ep, uint8 *buff, uint32 len, uint8 sync);
|
||||
int32 hgusb11_v0_dev_ep_write(struct usb_device *p_usb_d, uint8 address, void *buffer, uint32 size);
|
||||
int32 hgusb11_v0_dev_write(struct usb_device *p_usb_d, uint8 ep, uint8 *buff, uint32 len, uint8 sync);
|
||||
int32 hgusb11_v0_dev_ep0_send_status(struct usb_device *p_usb_d);
|
||||
int32 hgusb11_v0_dev_attach(uint32 dev_id, struct hgusb11_dev *p_dev);
|
||||
int32 hgusb11_v0_dev_close(struct usb_device *p_usb_d);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _HG_USB11_V0_DEV_H */
|
||||
|
||||
96
sdk/include/dev/usb/usb11_v0/hgusb11_v0_host_api.h
Normal file
96
sdk/include/dev/usb/usb11_v0/hgusb11_v0_host_api.h
Normal file
@@ -0,0 +1,96 @@
|
||||
#ifndef _HG_USB11_V0_HOST_H
|
||||
#define _HG_USB11_V0_HOST_H
|
||||
|
||||
#include "typesdef.h"
|
||||
#include "list.h"
|
||||
#include "errno.h"
|
||||
#include "dev.h"
|
||||
#include "osal/irq.h"
|
||||
#include "osal/string.h"
|
||||
#include "osal/semaphore.h"
|
||||
#include "osal/mutex.h"
|
||||
#include "osal/event.h"
|
||||
#include "hal/usb_device.h"
|
||||
#include "dev/usb/usb11_v0/hgusb11_v0_dev_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define USB11_CORE_HOST_EP_RX 0
|
||||
#define USB11_CORE_HOST_EP_TX 1
|
||||
|
||||
#define USB11_CORE_HOST_EP0_TIMEOUT 18000
|
||||
|
||||
#define USB11_EP_ATTR_CONTROL 0x00
|
||||
#define USB11_EP_ATTR_ISOC 0x01
|
||||
#define USB11_EP_ATTR_BULK 0x02
|
||||
#define USB11_EP_ATTR_INT 0x03
|
||||
#define USB11_EP_ATTR_TYPE_MASK 0x03
|
||||
|
||||
#define USB11_DIR_OUT 0
|
||||
#define USB11_DIR_IN 0x80
|
||||
|
||||
enum hgusb11_host_flags {
|
||||
HGUSB11_HOST_FLAGS_OPENED = BIT(0),
|
||||
HGUSB11_HOST_FLAGS_READY = BIT(1),
|
||||
HGUSB11_HOST_FLAGS_SUSPEND = BIT(2),
|
||||
HGUSB11_HOST_FLAGS_DMA_MODE = BIT(3),
|
||||
HGUSB11_HOST_FLAGS_SOFT_SUBPACKAGE = BIT(4),
|
||||
};
|
||||
|
||||
enum hgusb11_host_speed_det {
|
||||
HGUSB11_HOST_NONE = 0,
|
||||
HGUSB11_HOST_FS,
|
||||
HGUSB11_HOST_LS,
|
||||
};
|
||||
|
||||
struct hgusb11_host {
|
||||
struct usb_device dev;
|
||||
void *usb_hw;
|
||||
usbdev_irq_hdl irq_hdl;
|
||||
uint32 irq_data;
|
||||
uint8 ep_irq_num;
|
||||
uint8 dma_irq_num;
|
||||
/*
|
||||
* USB EP0的控制块
|
||||
*/
|
||||
struct _usb_ep0_ctrl ep0_ctrl;
|
||||
/* Pointer of common areas */
|
||||
void * p_comm;
|
||||
|
||||
struct os_event trx_lock;
|
||||
struct os_event trx_done;
|
||||
|
||||
struct usb11_ep_trx_ctrl ep_trans_ctrl[4];
|
||||
struct usb11_ep_trx_ctrl ep_recevice_ctrl[4];
|
||||
|
||||
//状态位
|
||||
uint32 flags;
|
||||
};
|
||||
|
||||
int32 hgusb11_v0_host_dev_speed_detect();
|
||||
int32 hgusb11_v0_host_set_address(uint8 addr);
|
||||
int32 hgusb11_v0_host_reset();
|
||||
int32 hgusb11_v0_host_is_ep_crc_err(uint8 ep_num);
|
||||
int32 hgusb11_v0_host_is_rx_stall(uint8 ep_num, uint8 ep_type);
|
||||
int32 hgusb11_v0_host_is_xact_err(uint8 ep_num, uint8 ep_type);
|
||||
int32 hgusb11_v0_host_is_nak_timeout(uint8 ep_num, uint8 ep_type);
|
||||
void hgusb11_v0_host_clear_data_toggle(uint8 ep_num, uint8 ep_type);
|
||||
void hgusb11_v0_host_reset_ep_rxcsr(uint8 ep_num);
|
||||
void hgusb11_v0_host_reset_ep_txcsr(uint8 ep_num);
|
||||
int32 hgusb11_v0_host_ep_get_rx_dma_len(uint8 ep_num);
|
||||
int32 hgusb11_v0_host_ep0_tx_kick(struct usb_device *p_usb_d, uint8 setup_pkt, uint8 *buf, uint32 len);
|
||||
int32 hgusb11_v0_host_ep0_rx_kick(struct usb_device *p_usb_d, uint8* buf, uint32 len);
|
||||
int32 hgusb11_v0_host_ep_init(struct usb_device *p_usb_d, uint8 tx_or_rx, uint8 ep_num, uint8 ep_addr, uint8 ep_type, uint32 max_pktsize);
|
||||
int32 hgusb11_v0_host_set_ep_interval(uint8 tx_or_rx, uint8 ep_num, uint32 interval);
|
||||
int32 hgusb11_v0_host_ep_rx_kick(struct usb_device *p_usb_d, uint8 ep_num, uint8 *buf, uint32 len);
|
||||
int32 hgusb11_v0_host_ep_tx_kick(struct usb_device *p_usb_d, uint8 ep_num, uint8 *buf, uint32 len, uint8 setup_pkt);
|
||||
int32 hgusb11_v0_host_ep_abort(struct usb_device *p_usb_d, uint8 tx_or_rx, uint8 ep_num);
|
||||
int32 hgusb11_v0_host_attch(uint32 dev_id, struct hgusb11_host *p_dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
402
sdk/include/dev/usb/uvc_host.h
Normal file
402
sdk/include/dev/usb/uvc_host.h
Normal file
@@ -0,0 +1,402 @@
|
||||
#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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#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();
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user