This commit is contained in:
huxi
2025-12-03 11:12:34 +08:00
parent c23ae4f24c
commit bc195654bf
8163 changed files with 3799544 additions and 92 deletions
+18
View File
@@ -0,0 +1,18 @@
#ifndef __ANCTOOL_H__
#define __ANCTOOL_H__
#include "typedef.h"
struct anctool_data {
void (*send_packet)(u8 *data, u16 size);
void (*recv_packet)(u8 *data, u16 size);
};
void anctool_api_rx_data(u8 *buf, u16 len);
u8 *anctool_api_write_alloc(u16 len);
void anctool_api_set_active(u8 active);
u16 anctool_api_write(u8 *buf, u16 length);
void anctool_api_init(const struct anctool_data *arg);
void anctool_api_uninit(void);
#endif
+105
View File
@@ -0,0 +1,105 @@
#ifndef __chargebox_H__
#define __chargebox_H__
#include "typedef.h"
#define DEVICE_EVENT_FROM_CHARGEBOX (('C' << 24) | ('H' << 16) | ('B' << 8) | '\0')
enum {
CMD_COMPLETE,
CMD_RECVDATA,
CMD_RECVBYTE,
};
enum {
MODE_RECVDATA,
MODE_SENDDATA,
};
enum {
EAR_L,
EAR_R,
EAR_MAX,
};
struct chargebox_platform_data {
u32 baudrate;
u32 L_port;
u32 R_port;
void (*init)(const struct chargebox_platform_data *);
void (*open)(u8 l_r, u8 mode);
void (*close)(u8 l_r);
u8(*write)(u8 l_r, u8 *data, u8 len);
void (*set_baud)(u8 l_r, u32 baudrate);
};
/////handshake部分
enum {
HS_CMD0,
HS_CMD1,
HS_CMD2,
HS_CMD3,
};
enum {
HS_DELAY_48M,
HS_DELAY_60M,
HS_DELAY_80M,
HS_DELAY_96M,
HS_DELAY_120M,
HS_DELAY_160M,
HS_DELAY_192M,
HS_DELAY_240M,
};
enum {
HS_DELAY_2US,
HS_DELAY_3US,
HS_DELAY_4US,
HS_DELAY_7US,
HS_DELAY_8US,
HS_DELAY_14US,
HS_DELAY_16US,
};
//自定义指令
enum {
CMD_USER = 0xC0,
/*可添加自定义指令*/
};
struct _hs_hdl {
u32 port0;
u32 port1;
void (*send_delay_us)(u8 us);
};
//handshake
void handshake_ctrl_init(struct _hs_hdl *hs);
void handshake_send_app(u8 cmd);
u8 handshake_check_fast_charge(u32 ms);
//app层使用的接口
bool chargebox_api_write_read(u8 l_r, u8 *buf, u8 len, u8 timeout);
void chargebox_api_init(const struct chargebox_platform_data *arg);
void chargebox_api_uninit(void);
void chargebox_api_set_baud(u8 l_r, u32 baudrate);
void chargebox_api_shutdown_port(u8 l_r);
void chargebox_api_close_port(u8 l_r);
void chargebox_api_open_port(u8 l_r);
void chargebox_api_reset(void);//左右耳掉线时调用
//协议层api
u8 chargebox_get_power(u8 lr);
u8 chargebox_send_power_close(u8 lr, u8 power, u8 is_charge, u8 other_power);
u8 chargebox_send_power_open(u8 lr, u8 power, u8 is_charge, u8 other_power);
u8 chargebox_send_shut_down(u8 lr);
u8 chargebox_send_restore_sys(u8 lr);
u8 chargebox_send_enter_dut(u8 lr);
u8 chargebox_send_close_cid(u8 lr, u8 data);
u8 chargebox_delete_tws_addr(u8 lr);
u8 chargebox_delete_phone_addr(u8 lr);
u8 chargebox_delete_all_addr(u8 lr);
u8 chargebox_send_L_or_R(u8 lr);
u8 chargebox_exchange_addr(void (*get_addr_cb)(u8 lr, u8 *inbuf), void (*exchange_succ_cb)(void));
#endif
+87
View File
@@ -0,0 +1,87 @@
#ifndef __RTC_H__
#define __RTC_H__
#include "typedef.h"
#include "sys_time.h"
#define CLK_SEL_LRC 1
#define CLK_SEL_32K 2
#define CLK_SEL_BTOSC 3
#define USE_VIR_RTC 1
#define RTC_ALM_WKUP 1
#define RTC_OVERFLOW_WKUP 2
extern const int config_rtc_enable;
struct rtc_config_init {
const struct sys_time *default_sys_time;
const struct sys_time *default_alarm;
void (*cbfun)(u32 event);
u32 rtc_clk;
u8 alm_en;
};
enum {
P11_LPTMR_WKUP_EVENT = 1, //p11定时唤醒事件
MSYS_ALARM_WKUP_EVENT,//闹钟唤醒事件
MSYS_RTC_1HZ_EVENT,//触发主系统1s更新1次时间事件
MSYS_SOFF_WKUP_EVENT,//soff定时唤醒事件
LPTMR_INTERRUPT_EVENT,//lptmr中断事件
};
struct set_lptmr1_wkup_time {
u64 wkup_us;
u8 type;
};
#if 0
struct sys_time {
u16 year;
u8 month;
u8 day;
u8 hour;
u8 min;
u8 sec;
} _GNU_PACKED_;
#endif
//API
void vir_rtc_wakeup_enable(u32 wkup_ms);//softoff定时唤醒配置,wkup_ms单位:ms
void vir_rtc_wakeup_disable(void);
void rtc_set_1s_read_time_switch(u8 sw);
u64 lptmr1_get_pass_us(void);
void rtc_dev_init(const struct rtc_config_init *rtc);
void rtc_dev_deinit(void);
void rtc_read_time(struct sys_time *time);
void rtc_write_time(const struct sys_time *time);
void rtc_read_alarm(struct sys_time *time);
void rtc_write_alarm(const struct sys_time *time);
void rtc_debug_dump(void);
void rtc_alarm_switch(u32 en);
void rtc_save_context_to_vm(void);
void rtc_reset_save_time(void);
u32 rtc_is_alarm_en(void);
u32 rtc_is_alarm_wkup(void);
u32 rtc_get_clk_sel(void);
bool leapyear(u32 year); //判断是否为闰年
u32 year_to_day(u32 year);
u32 month_to_day(u32 year, u32 month);
void day_to_ymd(u32 day, struct sys_time *sys_time);
u32 ymd_to_day(struct sys_time *time);
u32 caculate_weekday_by_time(struct sys_time *r_time); //计算当天为星期几
u32 get_day_of_month(u32 year, u32 month); //返回每月的天数
#endif // __RTC_API_H__
+31
View File
@@ -0,0 +1,31 @@
#ifndef SDMMC_MODULE_H
#define SDMMC_MODULE_H
#include "generic/typedef.h"
#include "generic/ioctl.h"
#define SD_CMD_DECT 0
#define SD_CLK_DECT 1
#define SD_IO_DECT 2
#define SD_PWR_SDPG 0
#define SD_PWR_NULL 1
#define SD_CLASS_0 0
#define SD_CLASS_2 1
#define SD_CLASS_4 2
#define SD_CLASS_6 3
#define SD_CLASS_10 4
#define SD_IOCTL_GET_CLASS _IOR('S', 0, 4)
#endif
+211
View File
@@ -0,0 +1,211 @@
#ifndef __TZFLASH_API_H__
#define __TZFLASH_API_H__
#include "typedef.h"
#include "device.h"
struct flash_func_len {
u16 all_len;
u8 version;
u8 func_len;//lb
u8 sta_len;//lb
u8 func_otp;//lb
u8 func_dtr;
u8 func_wp;//bp,tb,sec,cmp
u8 func_wps;
u8 func_wps_op;
u8 func_qe;
u8 func_srp;
u8 func_sus;
u8 func_dc;
u8 func_drv;
u8 func_mpm;//dp
u8 func_qpi;
u8 func_init;
u8 func_read_continue;
} __attribute__((packed));
#define TZFLASH_STA_NUM 4
struct flash_sta_cmd {
u8 sta_cmd_r[TZFLASH_STA_NUM];
u8 sta_cmd_w[TZFLASH_STA_NUM];
} __attribute__((packed));
struct flash_otp_cfg {//flash otp信息
u32 otp_offset[5];//otp page的偏移地址组数
u16 otp_page_size;//otp的page大小
u8 otp_NumberOfpage;//otp的page数量
// struct flash_reg lock_cfg[2];//read,write
u8 wr_en_cmd;//0x50h:sr,0x06h:wr_en
u8 sr_mask[TZFLASH_STA_NUM];
u8 sr_value[TZFLASH_STA_NUM];//注意:锁定后不可擦写,sr的值也常是1
} __attribute__((packed));
struct flash_wps_cfg {//flash wps信息
u8 wr_en_cmd;//0x50h:sr,0x06h:wr_en
u8 sr_mask[TZFLASH_STA_NUM];
u8 sr_value[TZFLASH_STA_NUM];
// struct flash_reg r_reg_cfg;//read
// struct flash_reg w_reg_cfg;//write
} __attribute__((packed));
struct flash_wp_cfg { //写保护配置信息
u8 numOfwp_array;//写保护参数的个数
u8 wr_en_cmd;//0x50h:sr,06h:
u8 sr_mask[TZFLASH_STA_NUM]; //sr要保留或修改的bit
struct {
u8 sr_value[TZFLASH_STA_NUM]; //写保护sr取值
u16 wp_addr;//写保护结束地址,单位K
} wp_array[0]; //写保护的组数,修改可变长
} __attribute__((packed));
struct flash_dtr_cfg {
s8 x1_dummy;//-1:使用默认值
s8 x2_dummy;//-1:使用默认值
s8 x4_dummy;//-1:使用默认值,-2:不支持
} __attribute__((packed));
struct flash_io_drv {
u8 cs_drv: 2;
u8 clk_drv: 2;
u8 do_drv: 2;
u8 di_drv: 2;
u8 d2_drv: 2;
u8 d3_drv: 2;
} __attribute__((packed));
struct flash_reg {
u8 cmd[4];
u8 sr_value[4];
u8 sr_mask[4];
u8 continue_mode: 4;
u8 num_of_reg: 2;
u8 wr_en_mode: 1;
u8 rev: 1;
};
#define FLASH_SUPPORT_MPM_FUNC 0
#define FLASH_SUPPORT_DC_FUNC 0
#define FLASH_SUPPORT_QPI_FUNC 0
#if FLASH_SUPPORT_MPM_FUNC
struct flash_mpm_cfg {//flash 多page模式;无该功能配0
u16 mpm_size;//page len:256/512/1024/4096; 默认:0256byte
u8 sr_mask[TZFLASH_STA_NUM];
u8 sr_value[TZFLASH_STA_NUM];
u8 wr_en_cmd;//0x50h:sr,0x06h:wr_en
//页擦除命令擦除大小为mpm_size
} __attribute__((packed));
#endif
#if FLASH_SUPPORT_DC_FUNC
//dummy:cfg
//spi模式下:str:bbh,ebh
// dtr:bdh,edh
//qpi: dtr:0dh,edh
struct flash_dc_cfg {//flash dc信息。
u32 dtr_freq;
u32 str_freq;
u8 dtr_2io_NumberOfdummy;//bdh 含M7-M0
u8 dtr_4io_NumberOfdummy;//edh 含M7-M0
u8 str_2io_NumberOfdummy;//bbh 含M7-M0
u8 str_4io_NumberOfdummy;//ebh 含M7-M0
// struct flash_reg reg_cfg[2];//read,write
u8 sr_mask[TZFLASH_STA_NUM];//set DC
u8 sr_value[TZFLASH_STA_NUM];
u8 wr_en_cmd;//0x50h:sr,0x06h:wr_en
} __attribute__((packed));
#endif
#if FLASH_SUPPORT_QPI_FUNC
//dummy:cfg
//qpi: str:0bh,ebh(C0H)
// dtr:0dh,edh(DC)
struct flash_qpi_cfg {//flash dc信息
u32 dtr_freq;
u32 str_freq;
u8 dtr_1io_NumberOfdummy;//0dh
u8 dtr_4io_NumberOfdummy;//edh
u8 str_1io_NumberOfdummy;//0bh
u8 str_4io_NumberOfdummy;//ebh
// struct flash_reg reg_cfg[2];//read,write
u8 sr_mask[TZFLASH_STA_NUM];//set DC,cmd_w与qpi_cmd_w只能二选一,不能同时赋值
u8 sr_value[TZFLASH_STA_NUM];//set DC
u8 wr_en_cmd; //set DC//0x50h:sr,0x06h:wr_en
u8 qpi_cmd_w;//set C0H
u8 qpi_dummy_wl_value;//dummy & wrap len
u8 qpi_dummy_wl_mask;//cmd_w与qpi_cmd_w只能二选一,不能同时赋值
} __attribute__((packed));
#endif
struct flash_wps_area_cfg {
u32 start_addr;//任意地址,非对齐时不包含地址所在块
u32 end_addr;//任意地址,非对齐时不包含地址所在块
u8 lock_en;//1:保护, 0:解保护
} __attribute__((packed)); //size(1byte)
typedef enum {
TEE_SUCCESS = 0,
TEE_ERROR_TZASC_OUT_OF_IDX = 1,
TEE_ERROR_TZASC_IDX_CONFLICT = 2,
TEE_ERROR_TZASC_IDX_ACCESS_DENIED = 3,
TEE_ERROR_TZMPU_OUT_OF_IDX = 4,
TEE_ERROR_TZMPU_IDX_CONFLICT = 5,
TEE_ERROR_TZMPU_IDX_ACCESS_DENIED = 6,
TEE_ERROR_OUT_OF_MEMORY = 7,
TEE_ERROR_NOT_FOUND_TA = 8,
TEE_ERROR_EINVAL = 22, /* Invalid argument */
TEE_ERROR_ACCESS_DENIED = 23,
} TEE_Result;
struct tzspi_target {
void (*suspend)(u32 id);
void (*resume)(u32 id);
};
#define REGISTER_TZSPI_TARGET(target) \
const struct tzspi_target target SEC_USED(.tzspi_target)
extern const struct tzspi_target tzspi_target_begin[];
extern const struct tzspi_target tzspi_target_end[];
#define list_for_each_tzspi_target(p) \
for (p = tzspi_target_begin; p < tzspi_target_end; p++)
int tzflash_init(void *arg);
int tzflash_origin_read(u8 *buf, u32 offset, u32 len);
int tzflash_read(void *buf, u32 len, u32 offset);
int tzflash_write(const void *buf, u32 len, u32 offset);
int tzflash_ioctl(u32 cmd, u32 arg);
void tzflash_dump();
u32 sfc0_flash_addr2cpu_addr(u32 offset);
void tzflash_read_uuid(u8 *buf);
u8 *tzflash_get_uuid(void);
u32 tzflash_erase_otp();
u32 tzflash_read_otp(void *buf, u32 len, u32 addr);
u32 tzflash_write_otp(const u8 *buf, u32 len, u32 addr);
void tzflash_vm_info_set(void *_arg, u8 early_mode);
void tzflash_mutex_enter();
void tzflash_mutex_exit();
int tzflash_set_write_protect(u32 lock_en, u32 wp_s_addr, u32 wp_e_addr);
void tzflash_change_mode();//dtr(clk),continue,wps
u32 syscfg_read_otp(u32 id, u8 *buf, u32 len);
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,14 @@
#ifndef __CUSTOM_HID_H__
#define __CUSTOM_HID_H__
#include "typedef.h"
#include "usb/usb.h"
u32 custom_hid_tx_data(const usb_dev usb_id, const u8 *buffer, u32 len);
int custom_hid_get_ready(const usb_dev usb_id);
void custom_hid_set_rx_hook(void *priv, void (*rx_hook)(void *priv, u8 *buf, u32 len));
u32 custom_hid_desc_config(const usb_dev usb_id, u8 *ptr, u32 *cur_itf_num);
u32 custom_hid_register(usb_dev usb_id);
void custom_hid_release();
#endif
@@ -0,0 +1,99 @@
/**@file descriptor.h
* @brief 各种描述符头文件
* @details 结构体声明,功能函数声明
* @author jieli
* @date 2021-9-1
* @version V1.0
* @copyright Copyright(c)2010-2021 珠海市杰理科技股份有限公司
*********************************************************
* @attention
* 硬件平台:AC632N
* SDK版本:AC632N_V1.0.0_SDK
* @修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-9-1 <td>1.0 <td>jieli <td>创建初始版本
* </table>
*
*********************************************************
*/
#ifndef __DESCRIPTOR_H__
#define __DESCRIPTOR_H__
#include "usb/usb.h"
/**@brief USB获取设备描述符
* @param[in] *ptr 存放设备描述符的地址
* @return 无
* @par 示例:
* @code
* get_device_descriptor(ptr);
* @encode
*/
void get_device_descriptor(u8 *ptr);
/**@brief USB获取语言字符串描述符
* @param[in] *ptr 存放语言字符串描述符的地址
* @return 无
* @par 示例:
* @code
* get_language_str(ptr);
* @encode
*/
void get_language_str(u8 *ptr);
/**@brief USB获取生产商字符串描述符
* @param[in] *ptr 存放生产商字符串描述符的地址
* @return 无
* @par 示例:
* @code
* get_manufacture_str(ptr);
* @encode
*/
void get_manufacture_str(u8 *ptr);
/**@brief USB获取产品字符串描述符
* @param[in] *ptr 存放产品字符串描述符的地址
* @return 无
* @par 示例:
* @code
* get_product_str(ptr);
* @encode
*/
void get_product_str(u8 *ptr);
/**@brief USB获取序列号字符串描述符
* @param[in] *ptr 存放序列号字符串描述符的地址
* @return 无
* @par 示例:
* @code
* get_iserialnumber_str(ptr);
* @encode
*/
void get_iserialnumber_str(u8 *ptr);
/**@brief USB获取***字符串描述符
* @param[in] *ptr 存放***字符串描述符的地址
* @return 无
* @par 示例:
* @code
* get_string_ee(ptr);
* @encode
*/
void get_string_ee(u8 *ptr);
/**@brief USB设置描述符
* @param[in] usb_id USB接口的id号
* @param[in] class_config 类配置
* @param[in] *p 存放描述符的地址
* @param[in] max_len 最大长度
* @return
* @par 示例:
* @code
* set_descriptor(usb_id,class_config,p,max_len);
* @encode
*/
u32 set_descriptor(const usb_dev usb_id, u32 class_config, u8 *p, u32 max_len);
#endif /*DESCRIPTOR_H*/
@@ -0,0 +1,213 @@
/**@file hid.h
* @brief hid驱动头文件(做从机)
* @details 结构体声明,功能函数声明
* @author jieli
* @date 2021-9-1
* @version V1.0
* @copyright Copyright(c)2010-2021 珠海市杰理科技股份有限公司
*********************************************************
* @attention
* 硬件平台:AC632N
* SDK版本:AC632N_V1.0.0_SDK
* @修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-9-1 <td>1.0 <td>jieli <td>创建初始版本
* </table>
*
*********************************************************
*/
#ifndef __USB_HID_H__
#define __USB_HID_H__
#include "typedef.h"
#include "usb/usb.h"
#include "usb/device/usb_stack.h"
//do not add brace to the macro outside
#define SHORT_ITEMS(prefix, _len, ...) \
((prefix) | (((_len) > 0) ? 1 << ((_len) - 1) : 0)), ##__VA_ARGS__
/*Main Items*/
#define INPUT(len, ...) SHORT_ITEMS(0x80, len, ##__VA_ARGS__)
#define OUTPUT(len, ...) SHORT_ITEMS(0x90, len, ##__VA_ARGS__)
#define COLLECTION(len, ...) SHORT_ITEMS(0xA0, len, ##__VA_ARGS__)
#define FEATURE(len, ...) SHORT_ITEMS(0xB0, len, ##__VA_ARGS__)
#define END_COLLECTION 0xC0
/*Golbal Items*/
#define USAGE_PAGE(len, ...) SHORT_ITEMS(0x04, len, ##__VA_ARGS__)
#define LOGICAL_MIN(len, ...) SHORT_ITEMS(0x14, len, ##__VA_ARGS__)
#define LOGICAL_MAX(len, ...) SHORT_ITEMS(0x24, len, ##__VA_ARGS__)
#define PHYSICAL_MIN(len, ...) SHORT_ITEMS(0x34, len, ##__VA_ARGS__)
#define PHYSICAL_MAX(len, ...) SHORT_ITEMS(0x44, len, ##__VA_ARGS__)
#define UNIT_EXPONENT(len, ...) SHORT_ITEMS(0x54, len, ##__VA_ARGS__)
#define UNIT(len, ...) SHORT_ITEMS(0x64, len, ##__VA_ARGS__)
#define REPORT_SIZE(len, ...) SHORT_ITEMS(0x74, len, ##__VA_ARGS__)
#define REPORT_ID(len, ...) SHORT_ITEMS(0x84, len, ##__VA_ARGS__)
#define REPORT_COUNT(len, ...) SHORT_ITEMS(0x94, len, ##__VA_ARGS__)
#define PUSH SHORT_ITEMS(0xA4, 0)
#define POP SHORT_ITEMS(0xB4, 0)
/*Local Items*/
#define USAGE(len, ...) SHORT_ITEMS(0x08, len, ##__VA_ARGS__)
#define USAGE_MIN(len, ...) SHORT_ITEMS(0x18, len, ##__VA_ARGS__)
#define USAGE_MAX(len, ...) SHORT_ITEMS(0x28, len, ##__VA_ARGS__)
#define DESIGNATOR_INDEX(len, ...) SHORT_ITEMS(0x38, len, ##__VA_ARGS__)
#define DESIGNATOR_MIN(len, ...) SHORT_ITEMS(0x48, len, ##__VA_ARGS__)
#define DESIGNATOR_MAX(len, ...) SHORT_ITEMS(0x58, len, ##__VA_ARGS__)
#define STRING_INDEX(len, ...) SHORT_ITEMS(0x78, len, ##__VA_ARGS__)
#define STRING_MIN(len, ...) SHORT_ITEMS(0x88, len, ##__VA_ARGS__)
#define STRING_MAX(len, ...) SHORT_ITEMS(0x98, len, ##__VA_ARGS__)
#define DELIMITER(len, ...) SHORT_ITEMS(0xA8, len, ##__VA_ARGS__)
/*Consumer Page*/
#define CONSUMER_PAGE 0x0C
#define CONSUMER_CONTROL 0x01
#define GENERIC_DESKTOP_CTRLS 0x01
/*Usage*/
#define POINTER 0x01
#define MOUSE 0x02
#define BUTTON 0x09
#define X_AXIS 0x30
#define Y_AXIS 0x31
//Collection
#define PHYSICAL 0x00
#define APPLICATION 0x01
#define LOGICAL 0x02
#define REPORT 0x03
#define USB_HID_DT_HID (USB_TYPE_CLASS | 0x01)
#define USB_HID_DT_REPORT (USB_TYPE_CLASS | 0x02)
#define USB_HID_DT_PHYSICAL (USB_TYPE_CLASS | 0x03)
/*
* * HID requests
* */
#define USB_REQ_GET_REPORT 0x01
#define USB_REQ_GET_IDLE 0x02
#define USB_REQ_GET_PROTOCOL 0x03
#define USB_REQ_SET_REPORT 0x09
#define USB_REQ_SET_IDLE 0x0A
#define USB_REQ_SET_PROTOCOL 0x0B
#define PLAY 0xB0
#define PAUSE 0xB1
#define RECORD 0xB2
#define FAST_FORWARD 0xB3
#define REWIND 0xB4
#define SCAN_NEXT_TRACK 0xB5
#define SCAN_PREV_TRACK 0xB6
#define STOP 0xB7
#define FRAME_FORWARD 0xC0
#define FRAME_BACK 0xC1
#define TRACKING_INC 0xCA
#define TRACKING_DEC 0xCB
#define STOP_EJECT 0xCC
#define PLAY_PAUSE 0xCD
#define PLAY_SKIP 0xCE
#define VOLUME 0xE0
#define BALANCE 0xE1
#define MUTE 0xE2
#define BASS 0xE3
#define VOLUME_INC 0xE9
#define VOLUME_DEC 0xEA
#define BALANCE_LEFT 0x50, 0x01
#define BALANCE_RIGHT 0x51, 0x01
#define CHANNEL_LEFT 0x61, 0x01
#define CHANNEL_RIGHT 0x62, 0x01
//----------------------------------
// HID key for audio
//----------------------------------
#define USB_AUDIO_NONE 0
#define USB_AUDIO_VOLUP BIT(0)
#define USB_AUDIO_VOLDOWN BIT(1)
#define USB_AUDIO_MUTE BIT(2)
#define USB_AUDIO_PP BIT(3)
#define USB_AUDIO_NEXTFILE BIT(4)
#define USB_AUDIO_PREFILE BIT(5)
#define USB_AUDIO_FASTFORWARD BIT(5)
#define USB_AUDIO_STOP BIT(7)
#define USB_AUDIO_TRACKING_INC BIT(8)
#define USB_AUDIO_TRACKING_DEC BIT(9)
#define USB_AUDIO_STOP_EJECT BIT(10)
#define USB_AUDIO_VOLUME BIT(11)
#define USB_AUDIO_BALANCE_RIGHT BIT(12)
#define USB_AUDIO_BALANCE_LEFT BIT(13)
#define USB_AUDIO_PLAY BIT(14)
#define USB_AUDIO_PAUSE BIT(15)
/**@brief USB hid描述符配置
* @param[in] usb_id usb的id号
* @param[in] *ptr 指向HID描述符
* @param[in] *cur_itf_num 当前接口号
* @return HID描述符长度,单位Byte
* @par 示例:
* @code
* hid_desc_config(usb_id,ptr,cur_itf_num);
* @encode
*/
u32 hid_desc_config(const usb_dev usb_id, u8 *ptr, u32 *cur_itf_num);
u32 hid_second_desc_config(const usb_dev usb_id, u8 *ptr, u32 *cur_itf_num);
/**@brief hid按键处理函数
* @param[in] *usb_device usb_device_t定义的结构体指针
* @param[in] hid_key hid按键信息
* @return 无
* @par 示例:
* @code
* hid_key_handler(usb_device,hidkey);
* @encode
*/
void hid_key_handler(struct usb_device_t *usb_device, u32 hid_key);
/**@brief hid按键处理函数,用于特殊发送一个包的场景(正常hidkey有两个包)
* @param[in] *usb_device usb_device_t定义的结构体指针
* @param[in] hid_key hid按键信息
* @return 无
* @par 示例:
* @code
* hid_key_handler_send_one_packet(usb_device,hidkey);
* @encode
*/
void hid_key_handler_send_one_packet(struct usb_device_t *usb_device, u32 hid_key);
/**@brief hid发送数据
* @param[in] *p 数据指针,指向存放数据的地址
* @param[in] len 发送的数据长度
* @return
* @par 示例:
* @code
* hid_send_data(p,len);
* @encode
*/
u32 hid_send_data(const void *p, u32 len);
/**@brief hid注册
* @param[in] usb_id usb的id号
* @return 0
* @par 示例:
* @code
* hid_register(usb_id);
* @encode
*/
u32 hid_register(const usb_dev usb_id);
/**@brief hid释放(暂未使用)
* @param[in] usb_id usb的id号
* @return 0
* @par 示例:
* @code
* hid_release(usb_id);
* @encode
*/
void hid_release(const usb_dev usb_id);
#endif
@@ -0,0 +1,34 @@
#ifndef __USBD_MSD_H__
#define __USBD_MSD_H__
#include "usb/usb.h"
#include "usb_stack.h"
#define MAX_MSD_DEV 2
#define MSD_DEV_NAME_LEN 14
struct msd_info {
u8 bError;
u8 bSenseKey;
u8 bAdditionalSenseCode;
u8 bAddiSenseCodeQualifier;
u8 bDisk_popup[MAX_MSD_DEV];
void *dev_handle[MAX_MSD_DEV];
char dev_name[MAX_MSD_DEV][MSD_DEV_NAME_LEN];
void (*msd_wakeup_handle)(struct usb_device_t *usb_device);
void (*msd_reset_wakeup_handle)(struct usb_device_t *usb_device, u32 itf_num);
};
u32 msd_desc_config(const usb_dev usb_id, u8 *ptr, u32 *cur_itf_num);
void USB_MassStorage(const struct usb_device_t *usb_device);
u32 msd_set_wakeup_handle(void (*handle)(struct usb_device_t *usb_device));
u32 msd_register_disk(const char *name, void *arg);
u32 msd_unregister_disk(const char *name);
u32 msd_unregister_all();
u32 msd_register(const usb_dev id);
u32 msd_release();
void msd_set_reset_wakeup_handle(void (*handle)(struct usb_device_t *usb_device, u32 itf_num));
void msd_reset(struct usb_device_t *usb_device, u32 itf_num);
#endif /*USBD_MSD_H*/
@@ -0,0 +1,464 @@
/**
* <linux/usb/audio.h> -- USB Audio definitions.
*
* Copyright (C) 2006 Thumtronics Pty Ltd.
* Developed for Thumtronics by Grey Innovation
* Ben Williamson <ben.williamson@greyinnovation.com>
*
* This software is distributed under the terms of the GNU General Public
* License ("GPL") version 2, as published by the Free Software Foundation.
*
* This file holds USB constants and structures defined
* by the USB Device Class Definition for Audio Devices.
* Comments below reference relevant sections of that document:
*
* http://www.usb.org/developers/devclass_docs/audio10.pdf
*
* Types and defines in this file are either specific to version 1.0 of
* this standard or common for newer versions.
*/
#ifndef __LINUX_USB_AUDIO_H
#define __LINUX_USB_AUDIO_H
#ifdef __cplusplus
extern "C" {
#endif
#define __le16 u16
#define u8 unsigned char // u8 to u32 special for struct
#define u16 unsigned short // u16 to u32 special for struct
#ifndef __s16
#define s16 short // only s16
#endif
#define u32 unsigned int
/* A.8. Audio Class-Specific Request Codes */
#define UAC_RC_UNDEFINED 0x00
#define UAC_SET_CUR 0x01
#define UAC_GET_CUR 0x81
#define UAC_GET_MIN 0x82
#define UAC_GET_MAX 0x83
#define UAC_GET_RES 0x84
#define UAC_GET_LEN 0x85
#define UAC_GET_INFO 0x86
#define UAC_GET_DEF 0x87
/** bInterfaceProtocol values to denote the version of the standard used */
#define UAC_VERSION_1 0x00
#define UAC_VERSION_2 0x20
/** A.2 Audio Interface Subclass Codes */
#define USB_SUBCLASS_AUDIOCONTROL 0x01
#define USB_SUBCLASS_AUDIOSTREAMING 0x02
#define USB_SUBCLASS_MIDISTREAMING 0x03
/** A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
#define UAC_HEADER 0x01
#define UAC_INPUT_TERMINAL 0x02
#define UAC_OUTPUT_TERMINAL 0x03
#define UAC_MIXER_UNIT 0x04
#define UAC_SELECTOR_UNIT 0x05
#define UAC_FEATURE_UNIT 0x06
#define UAC1_PROCESSING_UNIT 0x07
#define UAC1_EXTENSION_UNIT 0x08
/** A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
#define UAC_AS_GENERAL 0x01
#define UAC_FORMAT_TYPE 0x02
#define UAC_FORMAT_SPECIFIC 0x03
/** A.7 Processing Unit Process Types */
#define UAC_PROCESS_UNDEFINED 0x00
#define UAC_PROCESS_UP_DOWNMIX 0x01
#define UAC_PROCESS_DOLBY_PROLOGIC 0x02
#define UAC_PROCESS_STEREO_EXTENDER 0x03
#define UAC_PROCESS_REVERB 0x04
#define UAC_PROCESS_CHORUS 0x05
#define UAC_PROCESS_DYN_RANGE_COMP 0x06
/** A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
#define UAC_EP_GENERAL 0x01
/** A.9 Audio Class-Specific Request Codes */
#define UAC_GET_STAT 0xff
/** A.10 Control Selector Codes */
/** A.10.1 Terminal Control Selectors */
#define UAC_TERM_COPY_PROTECT 0x01
/** A.10.2 Feature Unit Control Selectors */
#define UAC_FU_MUTE 0x01
#define UAC_FU_VOLUME 0x02
#define UAC_FU_BASS 0x03
#define UAC_FU_MID 0x04
#define UAC_FU_TREBLE 0x05
#define UAC_FU_GRAPHIC_EQUALIZER 0x06
#define UAC_FU_AUTOMATIC_GAIN 0x07
#define UAC_FU_DELAY 0x08
#define UAC_FU_BASS_BOOST 0x09
#define UAC_FU_LOUDNESS 0x0a
#define UAC_CONTROL_BIT(CS) (1 << ((CS) - 1))
/** A.10.3.1 Up/Down-mix Processing Unit Controls Selectors */
#define UAC_UD_ENABLE 0x01
#define UAC_UD_MODE_SELECT 0x02
/** A.10.3.2 Dolby Prologic (tm) Processing Unit Controls Selectors */
#define UAC_DP_ENABLE 0x01
#define UAC_DP_MODE_SELECT 0x02
/** A.10.3.3 3D Stereo Extender Processing Unit Control Selectors */
#define UAC_3D_ENABLE 0x01
#define UAC_3D_SPACE 0x02
/** A.10.3.4 Reverberation Processing Unit Control Selectors */
#define UAC_REVERB_ENABLE 0x01
#define UAC_REVERB_LEVEL 0x02
#define UAC_REVERB_TIME 0x03
#define UAC_REVERB_FEEDBACK 0x04
/** A.10.3.5 Chorus Processing Unit Control Selectors */
#define UAC_CHORUS_ENABLE 0x01
#define UAC_CHORUS_LEVEL 0x02
#define UAC_CHORUS_RATE 0x03
#define UAC_CHORUS_DEPTH 0x04
/** A.10.3.6 Dynamic Range Compressor Unit Control Selectors */
#define UAC_DCR_ENABLE 0x01
#define UAC_DCR_RATE 0x02
#define UAC_DCR_MAXAMPL 0x03
#define UAC_DCR_THRESHOLD 0x04
#define UAC_DCR_ATTACK_TIME 0x05
#define UAC_DCR_RELEASE_TIME 0x06
/** A.10.4 Extension Unit Control Selectors */
#define UAC_XU_ENABLE 0x01
/** MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
#define UAC_MS_HEADER 0x01
#define UAC_MIDI_IN_JACK 0x02
#define UAC_MIDI_OUT_JACK 0x03
/** MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
#define UAC_MS_GENERAL 0x01
/** Terminals - 2.1 USB Terminal Types */
#define UAC_TERMINAL_UNDEFINED 0x0100
#define UAC_TERMINAL_STREAMING 0x0101
#define UAC_TERMINAL_VENDOR_SPEC 0x01FF
/** Terminal Control Selectors */
/** 4.3.2 Class-Specific AC Interface Descriptor */
struct uac1_ac_header_descriptor {
u8 bLength; /** 8 + n */
u8 bDescriptorType; /** USB_DT_CS_INTERFACE */
u8 bDescriptorSubtype; /** UAC_MS_HEADER */
__le16 bcdADC; /** 0x0100 */
__le16 wTotalLength; /** includes Unit and Terminal desc. */
u8 bInCollection; /** n */
u8 baInterfaceNr[]; /** [n] */
} __attribute__((packed));
#define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
/** As above, but more useful for defining your own descriptors: */
#define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
struct uac1_ac_header_descriptor_##n { \
u8 bLength; \
u8 bDescriptorType; \
u8 bDescriptorSubtype; \
__le16 bcdADC; \
__le16 wTotalLength; \
u8 bInCollection; \
u8 baInterfaceNr[n]; \
} __attribute__ ((packed))
/** 4.3.2.1 Input Terminal Descriptor */
struct uac_input_terminal_descriptor {
u8 bLength; /** in bytes: 12 */
u8 bDescriptorType; /** CS_INTERFACE descriptor type */
u8 bDescriptorSubtype; /** INPUT_TERMINAL descriptor subtype */
u8 bTerminalID; /** Constant uniquely terminal ID */
__le16 wTerminalType; /** USB Audio Terminal Types */
u8 bAssocTerminal; /** ID of the Output Terminal associated */
u8 bNrChannels; /** Number of logical output channels */
__le16 wChannelConfig;
u8 iChannelNames;
u8 iTerminal;
} __attribute__((packed));
#define UAC_DT_INPUT_TERMINAL_SIZE 12
/** Terminals - 2.2 Input Terminal Types */
#define UAC_INPUT_TERMINAL_UNDEFINED 0x200
#define UAC_INPUT_TERMINAL_MICROPHONE 0x201
#define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
#define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
#define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
#define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
#define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
/** Terminals - control selectors */
#define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01
/** 4.3.2.2 Output Terminal Descriptor */
struct uac1_output_terminal_descriptor {
u8 bLength; /** in bytes: 9 */
u8 bDescriptorType; /** CS_INTERFACE descriptor type */
u8 bDescriptorSubtype; /** OUTPUT_TERMINAL descriptor subtype */
u8 bTerminalID; /** Constant uniquely terminal ID */
__le16 wTerminalType; /** USB Audio Terminal Types */
u8 bAssocTerminal; /** ID of the Input Terminal associated */
u8 bSourceID; /** ID of the connected Unit or Terminal*/
u8 iTerminal;
} __attribute__((packed));
#define UAC_DT_OUTPUT_TERMINAL_SIZE 9
/** Terminals - 2.3 Output Terminal Types */
#define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300
#define UAC_OUTPUT_TERMINAL_SPEAKER 0x301
#define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302
#define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
#define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
#define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
#define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
#define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
#define UAC_OUTPUT_TERMINAL_HEADSET 0x0402
/** Set bControlSize = 2 as default setting */
#define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
/** As above, but more useful for defining your own descriptors: */
#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
struct uac_feature_unit_descriptor_##ch { \
u8 bLength; \
u8 bDescriptorType; \
u8 bDescriptorSubtype; \
u8 bUnitID; \
u8 bSourceID; \
u8 bControlSize; \
__le16 bmaControls[ch + 1]; \
u8 iFeature; \
} __attribute__ ((packed))
/** 4.3.2.3 Mixer Unit Descriptor */
struct uac_mixer_unit_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bUnitID;
u8 bNrInPins;
u8 baSourceID[];
} __attribute__((packed));
/** 4.3.2.4 Selector Unit Descriptor */
struct uac_selector_unit_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bUintID;
u8 bNrInPins;
u8 baSourceID[];
} __attribute__((packed));
/** 4.3.2.5 Feature Unit Descriptor */
struct uac_feature_unit_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bUnitID;
u8 bSourceID;
u8 bControlSize;
u8 bmaControls[0]; /** variable length */
} __attribute__((packed));
/** 4.3.2.6 Processing Unit Descriptors */
struct uac_processing_unit_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bUnitID;
u16 wProcessType;
u8 bNrInPins;
u8 baSourceID[];
} __attribute__((packed));
/** 4.5.2 Class-Specific AS Interface Descriptor */
struct uac1_as_header_descriptor {
u8 bLength; /** in bytes: 7 */
u8 bDescriptorType; /** USB_DT_CS_INTERFACE */
u8 bDescriptorSubtype; /** AS_GENERAL */
u8 bTerminalLink; /** Terminal ID of connected Terminal */
u8 bDelay; /** Delay introduced by the data path */
__le16 wFormatTag; /** The Audio Data Format */
} __attribute__((packed));
#define UAC_DT_AS_HEADER_SIZE 7
/** Formats - A.1.1 Audio Data Format Type I Codes */
#define UAC_FORMAT_TYPE_I_UNDEFINED 0x0
#define UAC_FORMAT_TYPE_I_PCM 0x1
#define UAC_FORMAT_TYPE_I_PCM8 0x2
#define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3
#define UAC_FORMAT_TYPE_I_ALAW 0x4
#define UAC_FORMAT_TYPE_I_MULAW 0x5
struct uac_format_type_i_continuous_descriptor {
u8 bLength; /** in bytes: 8 + (ns * 3) */
u8 bDescriptorType; /** USB_DT_CS_INTERFACE */
u8 bDescriptorSubtype; /** FORMAT_TYPE */
u8 bFormatType; /** FORMAT_TYPE_1 */
u8 bNrChannels; /** physical channels in the stream */
u8 bSubframeSize; /** */
u8 bBitResolution;
u8 bSamFreqType;
u8 tLowerSamFreq[3];
u8 tUpperSamFreq[3];
} __attribute__((packed));
#define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
struct uac_format_type_i_discrete_descriptor {
u8 bLength; /** in bytes: 8 + (ns * 3) */
u8 bDescriptorType; /** USB_DT_CS_INTERFACE */
u8 bDescriptorSubtype; /** FORMAT_TYPE */
u8 bFormatType; /** FORMAT_TYPE_1 */
u8 bNrChannels; /** physical channels in the stream */
u8 bSubframeSize; /** */
u8 bBitResolution;
u8 bSamFreqType;
u8 tSamFreq[][3];
} __attribute__((packed));
#define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
struct uac_format_type_i_discrete_descriptor_##n { \
u8 bLength; \
u8 bDescriptorType; \
u8 bDescriptorSubtype; \
u8 bFormatType; \
u8 bNrChannels; \
u8 bSubframeSize; \
u8 bBitResolution; \
u8 bSamFreqType; \
u8 tSamFreq[n][3]; \
} __attribute__ ((packed))
#define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
struct uac_format_type_i_ext_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bFormatType;
u8 bSubslotSize;
u8 bBitResolution;
u8 bHeaderLength;
u8 bControlSize;
u8 bSideBandProtocol;
} __attribute__((packed));
/** Formats - Audio Data Format Type I Codes */
#define UAC_FORMAT_TYPE_II_MPEG 0x1001
#define UAC_FORMAT_TYPE_II_AC3 0x1002
struct uac_format_type_ii_discrete_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bFormatType;
__le16 wMaxBitRate;
__le16 wSamplesPerFrame;
u8 bSamFreqType;
u8 tSamFreq[][3];
} __attribute__((packed));
struct uac_format_type_ii_ext_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bFormatType;
u16 wMaxBitRate;
u16 wSamplesPerFrame;
u8 bHeaderLength;
u8 bSideBandProtocol;
} __attribute__((packed));
/** type III */
#define UAC_FORMAT_TYPE_III_IEC1937_AC3 0x2001
#define UAC_FORMAT_TYPE_III_IEC1937_MPEG1_LAYER1 0x2002
#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_NOEXT 0x2003
#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_EXT 0x2004
#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER1_LS 0x2005
#define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER23_LS 0x2006
/** Formats - A.2 Format Type Codes */
#define UAC_FORMAT_TYPE_UNDEFINED 0x0
#define UAC_FORMAT_TYPE_I 0x1
#define UAC_FORMAT_TYPE_II 0x2
#define UAC_FORMAT_TYPE_III 0x3
#define UAC_EXT_FORMAT_TYPE_I 0x81
#define UAC_EXT_FORMAT_TYPE_II 0x82
#define UAC_EXT_FORMAT_TYPE_III 0x83
struct uac_iso_endpoint_descriptor {
u8 bLength; /** in bytes: 7 */
u8 bDescriptorType; /** USB_DT_CS_ENDPOINT */
u8 bDescriptorSubtype; /** EP_GENERAL */
u8 bmAttributes;
u8 bLockDelayUnits;
__le16 wLockDelay;
} __attribute__((packed));
#define UAC_ISO_ENDPOINT_DESC_SIZE 7
#define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01
#define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02
#define UAC_EP_CS_ATTR_FILL_MAX 0x80
/** status word format (3.7.1.1) */
#define UAC1_STATUS_TYPE_ORIG_MASK 0x0f
#define UAC1_STATUS_TYPE_ORIG_AUDIO_CONTROL_IF 0x0
#define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_IF 0x1
#define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_EP 0x2
#define UAC1_STATUS_TYPE_IRQ_PENDING (1 << 7)
#define UAC1_STATUS_TYPE_MEM_CHANGED (1 << 6)
#include "usb/usb.h"
struct uac1_status_word {
u8 bStatusType;
u8 bOriginator;
} __attribute__((packed));
u32 uac_spk_desc_config(const usb_dev usb_id, u8 *ptr, u32 *cur_itf_num);
u32 uac_mic_desc_config(const usb_dev usb_id, u8 *ptr, u32 *cur_itf_num);
u32 uac_audio_desc_config(const usb_dev usb_id, u8 *ptr, u32 *cur_itf_num);
const u8 *uac_get_string(u32 id);
void uac_get_cur_vol(const usb_dev usb_id, u16 *l_vol, u16 *r_vol);
u16 uac_get_mic_vol(const usb_dev usb_id);
u32 uac_spk_register(const usb_dev usb_id);
void uac_spk_release(const usb_dev usb_id);
u32 uac_mic_register(const usb_dev usb_id);
void uac_mic_release(const usb_dev usb_id);
#ifdef __cplusplus
}
#endif
#endif /** __LINUX_USB_AUDIO_H */
@@ -0,0 +1,462 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2010 Daniel Mack <daniel@caiaq.de>
*
* This software is distributed under the terms of the GNU General Public
* License ("GPL") version 2, as published by the Free Software Foundation.
*
* This file holds USB constants and structures defined
* by the USB Device Class Definition for Audio Devices in version 2.0.
* Comments below reference relevant sections of the documents contained
* in http://www.usb.org/developers/devclass_docs/Audio2.0_final.zip
*/
#ifndef __LINUX_USB_AUDIO_V2_H
#define __LINUX_USB_AUDIO_V2_H
#include "typedef.h"
/* v1.0 and v2.0 of this standard have many things in common. For the rest
* of the definitions, please refer to audio.h */
/*
* bmControl field decoders
*
* From the USB Audio spec v2.0:
*
* bmaControls() is a (ch+1)-element array of 4-byte bitmaps,
* each containing a set of bit pairs. If a Control is present,
* it must be Host readable. If a certain Control is not
* present then the bit pair must be set to 0b00.
* If a Control is present but read-only, the bit pair must be
* set to 0b01. If a Control is also Host programmable, the bit
* pair must be set to 0b11. The value 0b10 is not allowed.
*
*/
static inline bool uac2_control_is_readable(u32 bmControls, u8 control)
{
return (bmControls >> (control * 2)) & 0x1;
}
static inline bool uac2_control_is_writeable(u32 bmControls, u8 control)
{
return (bmControls >> (control * 2)) & 0x2;
}
/* 4.7.2 Class-Specific AC Interface Descriptor */
struct uac2_ac_header_descriptor {
u8 bLength; /* 9 */
u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
u8 bDescriptorSubtype; /* UAC_MS_HEADER */
u16 bcdADC; /* 0x0200 */
u8 bCategory;
u16 wTotalLength; /* includes Unit and Terminal desc. */
u8 bmControls;
} __packed;
/* 2.3.1.6 Type I Format Type Descriptor (Frmts20 final.pdf)*/
struct uac2_format_type_i_descriptor {
u8 bLength; /* in bytes: 6 */
u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
u8 bDescriptorSubtype; /* FORMAT_TYPE */
u8 bFormatType; /* FORMAT_TYPE_1 */
u8 bSubslotSize; /* {1,2,3,4} */
u8 bBitResolution;
} __packed;
/* 4.7.2.1 Clock Source Descriptor */
struct uac_clock_source_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bClockID;
u8 bmAttributes;
u8 bmControls;
u8 bAssocTerminal;
u8 iClockSource;
} __attribute__((packed));
/* bmAttribute fields */
#define UAC_CLOCK_SOURCE_TYPE_EXT 0x0
#define UAC_CLOCK_SOURCE_TYPE_INT_FIXED 0x1
#define UAC_CLOCK_SOURCE_TYPE_INT_VAR 0x2
#define UAC_CLOCK_SOURCE_TYPE_INT_PROG 0x3
#define UAC_CLOCK_SOURCE_SYNCED_TO_SOF (1 << 2)
/* 4.7.2.2 Clock Source Descriptor */
struct uac_clock_selector_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bClockID;
u8 bNrInPins;
u8 baCSourceID[];
/* bmControls, bAssocTerminal and iClockSource omitted */
} __attribute__((packed));
/* 4.7.2.3 Clock Multiplier Descriptor */
struct uac_clock_multiplier_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bClockID;
u8 bCSourceID;
u8 bmControls;
u8 iClockMultiplier;
} __attribute__((packed));
/* 4.7.2.4 Input terminal descriptor */
struct uac2_input_terminal_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bTerminalID;
u16 wTerminalType;
u8 bAssocTerminal;
u8 bCSourceID;
u8 bNrChannels;
u32 bmChannelConfig;
u8 iChannelNames;
u16 bmControls;
u8 iTerminal;
} __attribute__((packed));
/* 4.7.2.5 Output terminal descriptor */
struct uac2_output_terminal_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bTerminalID;
u16 wTerminalType;
u8 bAssocTerminal;
u8 bSourceID;
u8 bCSourceID;
u16 bmControls;
u8 iTerminal;
} __attribute__((packed));
/* 4.7.2.8 Feature Unit Descriptor */
struct uac2_feature_unit_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bUnitID;
u8 bSourceID;
/* bmaControls is actually u32,
* but u8 is needed for the hybrid parser */
u8 bmaControls[0]; /* variable length */
} __attribute__((packed));
/* 4.9.2 Class-Specific AS Interface Descriptor */
struct uac2_as_header_descriptor {
u8 bLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bTerminalLink;
u8 bmControls;
u8 bFormatType;
u32 bmFormats;
u8 bNrChannels;
u32 bmChannelConfig;
u8 iChannelNames;
} __attribute__((packed));
#define UAC2_FORMAT_TYPE_I_RAW_DATA (1 << 31)
/* 4.10.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor */
struct uac2_iso_endpoint_descriptor {
u8 bLength; /* in bytes: 8 */
u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
u8 bDescriptorSubtype; /* EP_GENERAL */
u8 bmAttributes;
u8 bmControls;
u8 bLockDelayUnits;
u16 wLockDelay;
} __attribute__((packed));
#define UAC2_CONTROL_PITCH (3 << 0)
#define UAC2_CONTROL_DATA_OVERRUN (3 << 2)
#define UAC2_CONTROL_DATA_UNDERRUN (3 << 4)
/* 6.1 Interrupt Data Message */
#define UAC2_INTERRUPT_DATA_MSG_VENDOR (1 << 0)
#define UAC2_INTERRUPT_DATA_MSG_EP (1 << 1)
struct uac2_interrupt_data_msg {
u8 bInfo;
u8 bAttribute;
u16 wValue;
u16 wIndex;
} __attribute__((packed));
/* A.7 Audio Function Category Codes */
#define UAC2_FUNCTION_SUBCLASS_UNDEFINED 0x00
#define UAC2_FUNCTION_DESKTOP_SPEAKER 0x01
#define UAC2_FUNCTION_HOME_THEATER 0x02
#define UAC2_FUNCTION_MICROPHONE 0x03
#define UAC2_FUNCTION_HEADSET 0x04
#define UAC2_FUNCTION_TELEPHONE 0x05
#define UAC2_FUNCTION_CONVERTER 0x06
#define UAC2_FUNCTION_SOUND_RECORDER 0x07
#define UAC2_FUNCTION_IO_BOX 0x08
#define UAC2_FUNCTION_MUSICAL_INSTRUMENT 0x09
#define UAC2_FUNCTION_PRO_AUDIO 0x0a
#define UAC2_FUNCTION_AUDIO_VIDEO 0x0b
#define UAC2_FUNCTION_CONTROL_PANEL 0x0c
#define UAC2_FUNCTION_OTHER 0xff
/* A.9 Audio Class-Specific AC Interface Descriptor Subtypes */
/* see audio.h for the rest, which is identical to v1 */
#define UAC2_EFFECT_UNIT 0x07
#define UAC2_PROCESSING_UNIT_V2 0x08
#define UAC2_EXTENSION_UNIT_V2 0x09
#define UAC2_CLOCK_SOURCE 0x0a
#define UAC2_CLOCK_SELECTOR 0x0b
#define UAC2_CLOCK_MULTIPLIER 0x0c
#define UAC2_SAMPLE_RATE_CONVERTER 0x0d
/* A.10 Audio Class-Specific AS Interface Descriptor Subtypes */
/* see audio.h for the rest, which is identical to v1 */
#define UAC2_ENCODER 0x03
#define UAC2_DECODER 0x04
/* A.11 Effect Unit Effect Types */
#define UAC2_EFFECT_UNDEFINED 0x00
#define UAC2_EFFECT_PARAM_EQ 0x01
#define UAC2_EFFECT_REVERB 0x02
#define UAC2_EFFECT_MOD_DELAY 0x03
#define UAC2_EFFECT_DYN_RANGE_COMP 0x04
/* A.12 Processing Unit Process Types */
#define UAC2_PROCESS_UNDEFINED 0x00
#define UAC2_PROCESS_UP_DOWNMIX 0x01
#define UAC2_PROCESS_DOLBY_PROLOCIC 0x02
#define UAC2_PROCESS_STEREO_EXTENDER 0x03
/* A.14 Audio Class-Specific Request Codes */
#define UAC2_CS_CUR 0x01
#define UAC2_CS_RANGE 0x02
#define UAC2_CS_MEM 0x03
/* A.15 Encoder Type Codes */
#define UAC2_ENCODER_UNDEFINED 0x00
#define UAC2_ENCODER_OTHER 0x01
#define UAC2_ENCODER_MPEG 0x02
#define UAC2_ENCODER_AC3 0x03
#define UAC2_ENCODER_WMA 0x04
#define UAC2_ENCODER_DTS 0x05
/* A.16 Decoder Type Codes */
#define UAC2_DECODER_UNDEFINED 0x00
#define UAC2_DECODER_OTHER 0x01
#define UAC2_DECODER_MPEG 0x02
#define UAC2_DECODER_AC3 0x03
#define UAC2_DECODER_WMA 0x04
#define UAC2_DECODER_DTS 0x05
/* A.17.1 Clock Source Control Selectors */
#define UAC2_CS_UNDEFINED 0x00
#define UAC2_CS_CONTROL_SAM_FREQ 0x01
#define UAC2_CS_CONTROL_CLOCK_VALID 0x02
/* A.17.2 Clock Selector Control Selectors */
#define UAC2_CX_UNDEFINED 0x00
#define UAC2_CX_CLOCK_SELECTOR 0x01
/* A.17.3 Clock Multiplier Control Selectors */
#define UAC2_CM_UNDEFINED 0x00
#define UAC2_CM_NUMERATOR 0x01
#define UAC2_CM_DENOMINTATOR 0x02
/* A.17.4 Terminal Control Selectors */
#define UAC2_TE_UNDEFINED 0x00
#define UAC2_TE_COPY_PROTECT 0x01
#define UAC2_TE_CONNECTOR 0x02
#define UAC2_TE_OVERLOAD 0x03
#define UAC2_TE_CLUSTER 0x04
#define UAC2_TE_UNDERFLOW 0x05
#define UAC2_TE_OVERFLOW 0x06
#define UAC2_TE_LATENCY 0x07
/* A.17.5 Mixer Control Selectors */
#define UAC2_MU_UNDEFINED 0x00
#define UAC2_MU_MIXER 0x01
#define UAC2_MU_CLUSTER 0x02
#define UAC2_MU_UNDERFLOW 0x03
#define UAC2_MU_OVERFLOW 0x04
#define UAC2_MU_LATENCY 0x05
/* A.17.6 Selector Control Selectors */
#define UAC2_SU_UNDEFINED 0x00
#define UAC2_SU_SELECTOR 0x01
#define UAC2_SU_LATENCY 0x02
/* A.17.7 Feature Unit Control Selectors */
/* see audio.h for the rest, which is identical to v1 */
#define UAC2_FU_INPUT_GAIN 0x0b
#define UAC2_FU_INPUT_GAIN_PAD 0x0c
#define UAC2_FU_PHASE_INVERTER 0x0d
#define UAC2_FU_UNDERFLOW 0x0e
#define UAC2_FU_OVERFLOW 0x0f
#define UAC2_FU_LATENCY 0x10
/* A.17.8.1 Parametric Equalizer Section Effect Unit Control Selectors */
#define UAC2_PE_UNDEFINED 0x00
#define UAC2_PE_ENABLE 0x01
#define UAC2_PE_CENTERFREQ 0x02
#define UAC2_PE_QFACTOR 0x03
#define UAC2_PE_GAIN 0x04
#define UAC2_PE_UNDERFLOW 0x05
#define UAC2_PE_OVERFLOW 0x06
#define UAC2_PE_LATENCY 0x07
/* A.17.8.2 Reverberation Effect Unit Control Selectors */
#define UAC2_RV_UNDEFINED 0x00
#define UAC2_RV_ENABLE 0x01
#define UAC2_RV_TYPE 0x02
#define UAC2_RV_LEVEL 0x03
#define UAC2_RV_TIME 0x04
#define UAC2_RV_FEEDBACK 0x05
#define UAC2_RV_PREDELAY 0x06
#define UAC2_RV_DENSITY 0x07
#define UAC2_RV_HIFREQ_ROLLOFF 0x08
#define UAC2_RV_UNDERFLOW 0x09
#define UAC2_RV_OVERFLOW 0x0a
#define UAC2_RV_LATENCY 0x0b
/* A.17.8.3 Modulation Delay Effect Control Selectors */
#define UAC2_MD_UNDEFINED 0x00
#define UAC2_MD_ENABLE 0x01
#define UAC2_MD_BALANCE 0x02
#define UAC2_MD_RATE 0x03
#define UAC2_MD_DEPTH 0x04
#define UAC2_MD_TIME 0x05
#define UAC2_MD_FEEDBACK 0x06
#define UAC2_MD_UNDERFLOW 0x07
#define UAC2_MD_OVERFLOW 0x08
#define UAC2_MD_LATENCY 0x09
/* A.17.8.4 Dynamic Range Compressor Effect Unit Control Selectors */
#define UAC2_DR_UNDEFINED 0x00
#define UAC2_DR_ENABLE 0x01
#define UAC2_DR_COMPRESSION_RATE 0x02
#define UAC2_DR_MAXAMPL 0x03
#define UAC2_DR_THRESHOLD 0x04
#define UAC2_DR_ATTACK_TIME 0x05
#define UAC2_DR_RELEASE_TIME 0x06
#define UAC2_DR_UNDEFLOW 0x07
#define UAC2_DR_OVERFLOW 0x08
#define UAC2_DR_LATENCY 0x09
/* A.17.9.1 Up/Down-mix Processing Unit Control Selectors */
#define UAC2_UD_UNDEFINED 0x00
#define UAC2_UD_ENABLE 0x01
#define UAC2_UD_MODE_SELECT 0x02
#define UAC2_UD_CLUSTER 0x03
#define UAC2_UD_UNDERFLOW 0x04
#define UAC2_UD_OVERFLOW 0x05
#define UAC2_UD_LATENCY 0x06
/* A.17.9.2 Dolby Prologic[tm] Processing Unit Control Selectors */
#define UAC2_DP_UNDEFINED 0x00
#define UAC2_DP_ENABLE 0x01
#define UAC2_DP_MODE_SELECT 0x02
#define UAC2_DP_CLUSTER 0x03
#define UAC2_DP_UNDERFFLOW 0x04
#define UAC2_DP_OVERFLOW 0x05
#define UAC2_DP_LATENCY 0x06
/* A.17.9.3 Stereo Expander Processing Unit Control Selectors */
#define UAC2_ST_EXT_UNDEFINED 0x00
#define UAC2_ST_EXT_ENABLE 0x01
#define UAC2_ST_EXT_WIDTH 0x02
#define UAC2_ST_EXT_UNDEFLOW 0x03
#define UAC2_ST_EXT_OVERFLOW 0x04
#define UAC2_ST_EXT_LATENCY 0x05
/* A.17.10 Extension Unit Control Selectors */
#define UAC2_XU_UNDEFINED 0x00
#define UAC2_XU_ENABLE 0x01
#define UAC2_XU_CLUSTER 0x02
#define UAC2_XU_UNDERFLOW 0x03
#define UAC2_XU_OVERFLOW 0x04
#define UAC2_XU_LATENCY 0x05
/* A.17.11 AudioStreaming Interface Control Selectors */
#define UAC2_AS_UNDEFINED 0x00
#define UAC2_AS_ACT_ALT_SETTING 0x01
#define UAC2_AS_VAL_ALT_SETTINGS 0x02
#define UAC2_AS_AUDIO_DATA_FORMAT 0x03
/* A.17.12 Encoder Control Selectors */
#define UAC2_EN_UNDEFINED 0x00
#define UAC2_EN_BIT_RATE 0x01
#define UAC2_EN_QUALITY 0x02
#define UAC2_EN_VBR 0x03
#define UAC2_EN_TYPE 0x04
#define UAC2_EN_UNDERFLOW 0x05
#define UAC2_EN_OVERFLOW 0x06
#define UAC2_EN_ENCODER_ERROR 0x07
#define UAC2_EN_PARAM1 0x08
#define UAC2_EN_PARAM2 0x09
#define UAC2_EN_PARAM3 0x0a
#define UAC2_EN_PARAM4 0x0b
#define UAC2_EN_PARAM5 0x0c
#define UAC2_EN_PARAM6 0x0d
#define UAC2_EN_PARAM7 0x0e
#define UAC2_EN_PARAM8 0x0f
/* A.17.13.1 MPEG Decoder Control Selectors */
#define UAC2_MPEG_UNDEFINED 0x00
#define UAC2_MPEG_DUAL_CHANNEL 0x01
#define UAC2_MPEG_SECOND_STEREO 0x02
#define UAC2_MPEG_MULTILINGUAL 0x03
#define UAC2_MPEG_DYN_RANGE 0x04
#define UAC2_MPEG_SCALING 0x05
#define UAC2_MPEG_HILO_SCALING 0x06
#define UAC2_MPEG_UNDERFLOW 0x07
#define UAC2_MPEG_OVERFLOW 0x08
#define UAC2_MPEG_DECODER_ERROR 0x09
/* A17.13.2 AC3 Decoder Control Selectors */
#define UAC2_AC3_UNDEFINED 0x00
#define UAC2_AC3_MODE 0x01
#define UAC2_AC3_DYN_RANGE 0x02
#define UAC2_AC3_SCALING 0x03
#define UAC2_AC3_HILO_SCALING 0x04
#define UAC2_AC3_UNDERFLOW 0x05
#define UAC2_AC3_OVERFLOW 0x06
#define UAC2_AC3_DECODER_ERROR 0x07
/* A17.13.3 WMA Decoder Control Selectors */
#define UAC2_WMA_UNDEFINED 0x00
#define UAC2_WMA_UNDERFLOW 0x01
#define UAC2_WMA_OVERFLOW 0x02
#define UAC2_WMA_DECODER_ERROR 0x03
/* A17.13.4 DTS Decoder Control Selectors */
#define UAC2_DTS_UNDEFINED 0x00
#define UAC2_DTS_UNDERFLOW 0x01
#define UAC2_DTS_OVERFLOW 0x02
#define UAC2_DTS_DECODER_ERROR 0x03
/* A17.14 Endpoint Control Selectors */
#define UAC2_EP_CS_UNDEFINED 0x00
#define UAC2_EP_CS_PITCH 0x01
#define UAC2_EP_CS_DATA_OVERRUN 0x02
#define UAC2_EP_CS_DATA_UNDERRUN 0x03
#endif /* __LINUX_USB_AUDIO_V2_H */
@@ -0,0 +1,231 @@
#ifndef __USB_STACK_H__
#define __USB_STACK_H__
#include "typedef.h"
#include "usb/usb.h"
#include "usb/ch9.h"
#include "usb/usb_phy.h"
#include "usb/otg.h"
#define MAX_INTERFACE_NUM 6
#define USB_SUSPEND_RESUME 0
#define USB_SUSPEND_RESUME_SYSTEM_NO_SLEEP 1
#define USB_REMOTE_WAKEUP_TIMEOUT_DETECT_TIMES 2000
#define USB_SETUP_SIZE (512)
#if 0
#define USB_ATTACHED BIT(0)
#define USB_POWERED BIT(1)
#define USB_DEFAULT BIT(2)
#define USB_ADDRESS BIT(3)
#define USB_CONFIGURED BIT(4)
#define USB_SUSPENDED BIT(5)
#else
enum {
USB_ATTACHED,
USB_POWERED,
USB_DEFAULT,
USB_ADDRESS,
USB_CONFIGURED,
USB_SUSPENDED
};
#endif
struct usb_device_t {
u8 baddr;
u8 bsetup_phase; //ep0 setup状态机
u16 wDataLength; //ep0 setup data stage数据长度
u8 *setup_buffer; //本次传输的bufer地址
u8 *setup_ptr; //当前传输的位置
u32(*setup_hook)(struct usb_device_t *, struct usb_ctrlrequest *);
u32(*setup_recv)(struct usb_device_t *, struct usb_ctrlrequest *);
u8 bDeviceStates;
u8 bDataOverFlag; //ep0 0包标识
u8 wDeviceClass; // 设备类
u8 bSpeed; //速率:如USB_SPEED_FULL
u8 bRemoteWakup: 1;
u8 baddr_config: 1;
u8 usb_id: 1;
u8 res: 5;
};
typedef u32(*itf_hander)(struct usb_device_t *usb_device, struct usb_ctrlrequest *);
typedef u32(*ep_setup_hander)(struct usb_device_t *usb_device, struct usb_ctrlrequest *);
typedef void(*itf_reset_hander)(struct usb_device_t *, u32 itf);
typedef void(*usb_interrupt)(struct usb_device_t *, u32 ep);
typedef u32(*desc_config)(const usb_dev usb_id, u8 *ptr, u32 *cur_itf_num);
struct usb_setup_t {
struct usb_device_t usb_device;
struct usb_ctrlrequest request;
itf_hander interface_hander[MAX_INTERFACE_NUM];
itf_reset_hander reset_hander[MAX_INTERFACE_NUM];
ep_setup_hander ep_setup_tx[USB_MAX_HW_EPNUM];
ep_setup_hander ep_setup_rx[USB_MAX_HW_EPNUM];
} __attribute__((aligned(4)));
/**@brief 获取USB接口的id号
* @param[in] *usb_device usb_device_t定义的结构体指针
* @return USB的id号
* @par 示例:
* @code
* usb_device2id(usb_device);
* @encode
*/
const usb_dev usb_device2id(const struct usb_device_t *usb_device);
/**@brief 获取usb_device_t定义的结构体地址
* @param[in] usb_id USB接口的id号
* @return 该结构的地址
* @par 示例:
* @code
* usb_id2device(usb_device);
* @encode
*/
struct usb_device_t *usb_id2device(const usb_dev usb_id);
/**@brief USB setup阶段控制传输
* @param[in] *usb_device usb_device_t定义的结构体指针
* @return 无
* @par 示例:
* @code
* usb_control_transfer(usb_device);
* @encode
*/
void usb_control_transfer(struct usb_device_t *usb_device);
/**@brief USB设置设备类
* @param[in] *usb_device usb_device_t定义的结构体指针
* @param[in] class_config 设备类设置
* @return 无
* @par 示例:
* @code
* usb_device_set_class(usb_device,class_config);
* @encode
*/
void usb_device_set_class(struct usb_device_t *usb_device, u32 class_config);
u32 usb_g_set_intr_hander(const usb_dev usb_id, u32 ep, usb_interrupt hander);
/**@brief USB设置接口服务函数
* @param[in] usb_id USB接口的id号
* @param[in] itf_num 接口号
* @param[in] hander 自己定义的函数
* @return itf_num:成功 0:失败
* @par 示例:
* @code
* usb_set_interface_hander(usb_id,itf_num,hander);
* @encode
*/
u32 usb_set_interface_hander(const usb_dev usb_id, u32 itf_num, itf_hander hander);
u32 usb_set_ep_setup_hander(const usb_dev usb_id, u32 ep, ep_setup_hander hander);
void usb_add_desc_config(const usb_dev usb_id, u32 index, const desc_config desc);
const u8 *usb_get_config_desc();
/**@brief USB设置复位服务函数
* @param[in] usb_id USB接口的id号
* @param[in] itf_num 接口号
* @param[in] hander 自己定义的函数
* @return itf_num:成功 0:失败
* @par 示例:
* @code
* usb_set_reset_hander(usb_id,itf_num,hander);
* @encode
*/
u32 usb_set_reset_hander(const usb_dev usb_id, u32 itf_num, itf_reset_hander hander);
/**@brief USB接口复位
* @param[in] *usb_device usb_device_t定义的结构体指针
* @return 无
* @par 示例:
* @code
* usb_reset_interface(usb_device);
* @encode
*/
void usb_reset_interface(struct usb_device_t *usb_device);
void usb_set_setup_recv(struct usb_device_t *usb_device, void *recv);
void usb_set_setup_hook(struct usb_device_t *usb_device, void *hook);
int usb_device_mode(const usb_dev usb_id, const u32 class);
/**@brief otg检测中sof初始化
* @param[in] usb_id USB接口的id号
* @return 1:等待sof信号
* @par 示例:
* @code
* usb_otg_sof_check_init(usb_id);
* @encode
*/
u32 usb_otg_sof_check_init(const usb_dev id);
/**@brief USB setup阶段初始化
* @param[in] usb_id USB接口的id号
* @param[in] *ptr usb_setup_t定义的结构体地址
* @param[in] *setup_buffer setup_buffer的地址
* @return 无
* @par 示例:
* @code
* usb_setup_init(usb_id,ptr,setup_buffer);
* @encode
*/
void usb_setup_init(const usb_dev usb_id, void *ptr, u8 *setup_buffer);
/**@brief USB setup阶段释放
* @param[in] usb_id USB接口的id号
* @return 0:成功
* @par 示例:
* @code
* usb_setup_release(usb_id);
* @encode
*/
u32 usb_setup_release(const usb_dev usb_id);
/**@brief USB设置数据载荷
* @param[in] *usb_device usb_device_t定义的结构体指针
* @param[in] *req usb_ctrlrequest定义的结构体指针
* @param[in] *data 存放数据指针
* @param[in] len 数据长度
* @return setup_buffer的地址
* @par 示例:
* @code
* usb_set_data_payload(usb_device,req,tx_payload,len);
* @encode
*/
u8 *usb_set_data_payload(struct usb_device_t *usb_device, struct usb_ctrlrequest *req, const void *data, u32 len);
/**@brief USB设置控制传输阶段
* @param[in] *usb_device usb_device_t定义的结构体指针
* @param[in] setup_phase 需要设置成的阶段
* @return 无
* @par 示例:
* @code
* usb_set_setup_phase(usb_id);
* @encode
*/
void usb_set_setup_phase(struct usb_device_t *usb_device, u8 setup_phase);
void dump_setup_request(const struct usb_ctrlrequest *request);
void user_setup_filter_install(struct usb_device_t *usb_device);
void usb_ep_enable(const usb_dev usb_id, u32 ep, u32 is_enable);
/**@brief USB获取本次传输的buffer地址
* @param[in] *usb_device usb_device_t定义的结构体指针
* @return setup_buffer地址
* @par 示例:
* @code
* usb_get_setup_buffer(usb_device);
* @encode
*/
void *usb_get_setup_buffer(const struct usb_device_t *usb_device);
u32 usb_root2_testing();
void usb_start(const usb_dev usbfd);
void usb_stop(const usb_dev usbfd);
void usb_pause(const usb_dev usbfd);
int usb_standby(const usb_dev usbfd);
void get_device_info_to_ota(void *parm_priv);
int pc_device_event_handler(int *msg);
/* #define usb_add_desc_config(fn) \ */
/* const desc_config usb_desc_config##fn sec(.usb.desc_config) = fn */
#endif /*USB_STACK_H*/
@@ -0,0 +1,271 @@
/**@file usb_host.h
* @brief usb_host驱动头文件(做主机)
* @details 结构体声明,功能函数声明
* @author jieli
* @date 2021-8-1
* @version V1.0
* @copyright Copyright(c)2010-2021 珠海市杰理科技股份有限公司
*********************************************************
* @attention
* 硬件平台:AC695N
* SDK版本:AC695N_V1.0.0_SDK
* @修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-8-1 <td>1.0 <td>jieli <td>创建初始版本
* </table>
*
*********************************************************
*/
#ifndef __USB_HOST_H__
#define __USB_HOST_H__
#include "system/task.h"
#include "device/device.h"
#include "usb/usb.h"
#include "usb/ch9.h"
#include "usb/usb_phy.h"
// #include "usb_config.h"
#define USB_HUB 0
/**@struct usb_private_data
* @brief usb_private_data私有数据结构体\n
* 自定义一些私有数据信息存储在该结构体中
*/
struct usb_private_data {
usb_dev usb_id; ///<USB的id号,如:0 : USB0 ; 1 : USB1
u8 status; ///<当前状态,如:0:上线 ; 1:下线
u8 devnum; ///<设备编号
u8 ep0_max_packet_size;///<端点0最大包长,单位:byte
/* ///<以下为保留信息,暂时未使用
u8 speed; ///<传输速度
u16 vendor_id; ///<供应商
u16 product_id; ///<产品id号
u16 language; ///<语言
u8 manufacturer[64]; ///<制造商
u8 product[64]; ///<产品序列
*/
};
struct usb_host_device;
/**@struct interface_ctrl
* @brief interface_ctrl
*/
struct interface_ctrl {
u8 interface_class;
int (*set_power)(struct usb_host_device *host_dev, u32 value);
int (*get_power)(struct usb_host_device *host_dev, u32 value);
int (*ioctl)(struct usb_host_device *host_dev, u32 cmd, u32 arg);
int (*release)(struct usb_host_device *host_dev);
};
/**@struct usb_interface_info
*@brief usb_interface_info
*/
struct usb_interface_info {
struct interface_ctrl *ctrl;
union {
struct mass_storage *disk;
struct adb_device_t *adb;
struct hid_device_t *hid;
struct aoa_device_t *aoa;
struct audio_device_t *audio;
struct usb_uvc *uvc;
void *p;
} dev;
};
#define MAX_HOST_INTERFACE 6
/**@struct usb_host_device
*@brief usb_host_device
*/
struct usb_host_device {
#if USB_HUB
struct usb_host_device *father;
#endif
OS_SEM *sem;
struct usb_private_data private_data;
const struct usb_interface_info *interface_info[MAX_HOST_INTERFACE];
};
#define device_to_usbdev(device) ((struct usb_host_device *)((device)->private_data))
#define usbdev_to_usbpriv(host) ((struct usb_private_data *)(&host->private_data))
#define usbpriv_to_usbid(priv) ((usb_dev)(priv->usb_id))
/**@brief USB设备id号获取
* @param[in] usb_host_device定义的结构体指针
* @return USB设备的id号,如 0:USB0 ; 1:USB1
* @par 示例:
* @code
* host_device2id(host_dev); 获取host_dev的USB设备id号
* @encode
*/
u32 host_device2id(const struct usb_host_device *host_dev);
/**@brief USB设备状态获取
* @param[in] usb_host_device定义的结构体指针
* @return USB设备的状态,如 0:下线 ; 1:上线
* @par 示例:
* @code
* host_dev_status(host_dev); 获取host_dev的USB设备状态
* @encode
*/
int host_dev_status(const struct usb_host_device *host_dev);
/**@brief 获取usb_host_device结构体的信息
* @param[in] USB的id号
* @return 结构体信息的存储首地址
* @par 示例:
* @code
* struct usb_host_device *host_dev = &host_devices[usb_id];
* @encode
*/
const struct usb_host_device *host_id2device(const usb_dev id);
#define check_usb_mount(ret) \
if(ret == -DEV_ERR_OFFLINE){\
log_error("%s() @ %d DEV_ERR_OFFLINE\n", __func__, __LINE__);\
goto __exit_fail;\
} else if(ret){\
log_error("%s() @ %d %x\n", __func__, __LINE__, ret);\
continue;\
}
typedef void(*usb_h_interrupt)(struct usb_host_device *, u32 ep);
/**@brief USB_sem初始化
* @param[in] usb_host_device定义的结构体指针
* @return 0:成功
* @par 示例:
* @code
* host_sem_init(host_dev);
* @encode
*/
int usb_sem_init(struct usb_host_device *host_dev);
/**@brief USB_sem申请一个信号量
* @param[in] usb_host_device定义的结构体指针
* @param[in] timeout 超时时间设置,单位ms
* @return
* @par 示例:
* @code
* host_sem_pend(host_dev,1000);
* @encode
*/
int usb_sem_pend(struct usb_host_device *host_dev, u32 timeout);
/**@brief USB_sem释放一个信号量
* @param[in] usb_host_device定义的结构体指针
* @return 0:成功
* @par 示例:
* @code
* host_sem_psot(host_dev);
* @encode
*/
int usb_sem_post(struct usb_host_device *host_dev);
/**@brief USB_sem删除
* @param[in] usb_host_device定义的结构体指针
* @return
* @par 示例:
* @code
* host_sem_del(host_dev);
* @encode
*/
int usb_sem_del(struct usb_host_device *host_dev);
/**@brief USB主机模式设置端点中断
* @param[in] usb_host_device定义的结构体指针
* @param[in] ep 端点号
* @param[in] hander usb_h_interrupt定义的指针函数
* @param[in] *p
* @return 无
* @par 示例:
* @code
* usb_h_set_ep_isr(host_dev , 0 , func , host_dev);
* @encode
*/
void usb_h_set_ep_isr(struct usb_host_device *host_dev, u32 ep, usb_h_interrupt hander, void *p);
/**@brief USB主机设置中断处理函数
* @param[in] usb_id USB的id号
* @param[in] ep 端点号
* @param[in] hander usb_h_interrupt定义的指针函数
* @return 0:成功
* @par 示例:
* @code
* usb_h_set_intr_hander(usb_id , 0 , func);
* @encode
*/
u32 usb_h_set_intr_hander(const usb_dev usb_id, u32 ep, usb_h_interrupt hander);
/**@brief USB主机模式挂载
* @param[in] usb_id USB的id号
* @param[in] retry 主机挂载重试次数
* @param[in] reset_delay 复位等待延时 单位ms
* @param[in] mount_timeout 挂载超时时间 单位ms
* @return
* @par 示例:
* @code
* usb_host_mount(usb_id , 5 , 10 , 1000 );
* @encode
*/
u32 usb_host_mount(const usb_dev usb_id, u32 retry, u32 reset_delay, u32 mount_timeout);
/**@brief USB主机模式卸载
* @param[in] usb_id USB的id号
* @return 0:成功
* @par 示例:
* @code
* usb_host_unmount(usb_id);
* @encode
*/
u32 usb_host_unmount(const usb_dev usb_id);
/**@brief USB主机模式重新挂载
* @param[in] usb_id USB的id号
* @param[in] retry 主机挂载重试次数
* @param[in] delay 复位等待延时 单位ms
* @param[in] ot 挂载超时时间 单位ms
* @param[in] notify 事件发送开关 1:开启 0:关闭
* @return 0:成功
* @par 示例:
* @code
* usb_host_remount(usb_id , 5 , 10 , 1000 , 1);
* @encode
*/
u32 usb_host_remount(const usb_dev usb_id, u32 retry, u32 delay, u32 ot, u8 notify);
/**@brief USB主机模式挂起
* @param[in] usb_id USB的id号
* @return 无
* @par 示例:
* @code
* usb_host_suspend(usb_id);
* @encode
*/
void usb_host_suspend(const usb_dev usb_id);
/**@brief USB主机模式恢复
* @param[in] usb_id USB的id号
* @return 无
* @par 示例:
* @code
* usb_host_resume(usb_id);
* @encode
*/
void usb_host_resume(const usb_dev usb_id);
int usb_host_force_reset(const usb_dev usb_id);
void usb_host_clock_lock(void);
void usb_host_clock_unlock(void *priv);
#endif /*USB_HOST_H*/
@@ -0,0 +1,207 @@
/*****************************************************************
>file name : uvc_device.h
>author : lichao
>create time : Sat 02 Sep 2017 03:22:12 PM HKT
*****************************************************************/
#ifndef _UVC_DEVICE_H_
#define _UVC_DEVICE_H_
#include "video.h"
// #include "video/camera.h"
#define UVC_CMD_BASE 0x00010000
#define UVC_SET_CUR_FPS (UVC_CMD_BASE + 0)
#define UVC_GET_CUR_FPS (UVC_CMD_BASE + 1)
#define UVC_GET_CUR_BITS_RATE (UVC_CMD_BASE + 2)
#define UVC_CAMERA_FMT_YUY2 0x1
#define UVC_CAMERA_FMT_MJPG 0x2
#define UVC_CAMERA_FMT_H264 0x3
#define USBIOC_MASS_STORAGE_CONNECT _IOW('U', 0, sizeof(struct usb_mass_storage))
#define USBIOC_UVC_CAMERA_CONNECT _IOW('U', 1, sizeof(struct uvc_format))
#define USBIOC_UAC_MICROPHONE_CONNECT _IOW('U', 2, sizeof(struct uvc_format))
//#define USBIOC_UVC_CAMERA1_CONNECT _IOW('U', 2, sizeof(struct uvc_format))
#define USBIOC_SLAVE_MODE_START _IOW('U', 3, sizeof(unsigned int))
#define USBIOC_SLAVE_DISCONNECT _IOW('U', 4, sizeof(unsigned int))
#define UVCIOC_QUERYCAP _IOR('U', 5, sizeof(struct uvc_capability))
#define UVCIOC_SET_CAP_SIZE _IOW('U', 5, sizeof(unsigned int))
#define UVCIOC_SET_FPS _IOW('U', 6, sizeof(unsigned int))
#define UVCIOC_STREAM_ON _IOW('U', 7, sizeof(unsigned int))
#define UVCIOC_STREAM_OFF _IOW('U', 8, sizeof(unsigned int))
#define UVCIOC_REQBUFS _IOW('U', 9, sizeof(unsigned int))
#define UVCIOC_DQBUF _IOW('U', 10, sizeof(unsigned int))
#define UVCIOC_QBUF _IOW('U', 11, sizeof(unsigned int))
#define UVCIOC_RESET _IOW('U', 12, sizeof(unsigned int))
#define UVCIOC_REQ_PROCESSING_UNIT _IOR('U', 13, sizeof(struct uvc_processing_unit))
#define UVCIOC_SET_PROCESSING_UNIT _IOW('U', 14, sizeof(struct uvc_processing_unit))
#define UVCIOC_GET_DEVICE_ID _IOR('U', 15, sizeof(struct usb_device_id))
#define USBIOC_SLAVE_RESET _IOW('U', 16, sizeof(unsigned int))
/***********2018-06-21************/
#define USBIOC_GET_DEVICE_ID _IOR('U', 17, sizeof(struct usb_device_id))
#define USBIOC_GET_MANUFACTURER _IOR('U', 18, sizeof(struct usb_string))
#define USBIOC_GET_PRODUCT_NAME _IOR('U', 19, sizeof(struct usb_string))
/*********************************/
/***********2018-07-30************/
#define UVCIOC_SET_EVENT_LISTENER _IOW('U', 19, sizeof(struct uvc_event_listener))
/*********************************/
#define USBIOC_HID_CONNECT _IOW('U', 20, sizeof(struct usb_hid_arg))
#define USBIOC_HID_CONTROL _IOW('U', 21, sizeof(struct usb_hid_arg))
#define USBIOC_CDC_CONNECT _IOW('U', 22, sizeof(struct usb_cdc_arg))
#define USBIOC_CDC_CONTROL _IOW('U', 23, sizeof(unsigned int))
/***********2020-05-11,设置uvc摄像头黑白切换************/
#define UVCIOC_SET_CUR_GRAY _IOW('U', 24, sizeof(unsigned int))
#define UVCIOC_GET_IMAMGE _IOR('U', 24, sizeof(unsigned int))
#define UVCIOC_SET_CUR_FPS _IOW('U', 25, sizeof(unsigned int))
/*********************************/
#define UVCIOC_GET_FMT _IOR('U', 26, sizeof(unsigned int))
/* ------------------------------------------------------------------------
* Driver specific constants.
*/
typedef int (*UVC_STREAM_OUT)(void *, int, void *, int);
struct uvc_parm {
s16 brightness_min;
s16 brightness_max;
s16 brightness_def;
s16 brightness_res;
s16 brightness_cur;
s16 contrast_min;
s16 contrast_max;
s16 contrast_def;
s16 contrast_res;
s16 contrast_cur;
s16 hue_min;
s16 hue_max;
s16 hue_def;
s16 hue_res;
s16 hue_cur;
s16 saturation_min;
s16 saturation_max;
s16 saturation_def;
s16 saturation_res;
s16 saturation_cur;
s16 sharpness_min;
s16 sharpness_max;
s16 sharpness_def;
s16 sharpness_res;
s16 sharpness_cur;
s16 gamma_min;
s16 gamma_max;
s16 gamma_def;
s16 gamma_res;
s16 gamma_cur;
s16 white_balance_temp_min;
s16 white_balance_temp_max;
s16 white_balance_temp_def;
s16 white_balance_temp_res;
s16 white_balance_temp_cur;
s16 power_line_freq_min;
s16 power_line_freq_max;
s16 power_line_freq_def;
s16 power_line_freq_res;
s16 power_line_freq_cur;
};
struct uvc_host_param {
char *name;
void *priv;
UVC_STREAM_OUT uvc_stream_out;
int (*uvc_out)(void *priv);
};
struct uvc_stream_list {
void *addr;
u32 length;
};
struct uvc_frame_info {
u16 width;
u16 height;
};
struct uvc_reqbufs {
void *buf;
int size;
};
struct uvc_capability {
int fmt;
int fps;
int reso_num;
struct uvc_frame_info reso[8];
};
struct uvc_processing_unit {
u8 request;
u8 type;
u16 value;
u16 index;
u8 buf[4];
int len;
};
struct usb_device_id {
u16 vendor;
u16 product;
};
struct usb_string {
u8 code_type;
u16 language;
int len;
u8 *string;
};
enum trans_mode {
UVC_PUSH_PHY_MODE,
UVC_PUSH_VIRTUAL_MODE,
};
struct usb_camera_info {
u16 width;
u16 height;
int fps;
int sample_fmt;
enum trans_mode mode;
};
struct uvc_platform_data {
u16 width;
u16 height;
int fps;
int fmt;
int mem_size;
int timeout;
u8 put_msg;
};
#define UVC_PLATFORM_DATA_BEGIN(data) \
static const struct uvc_platform_data data = {\
#define UVC_PLATFORM_DATA_END() \
};
extern const struct device_operations uvc_dev_ops;
int uvc_get_src_pixformat(void *fh);
int uvc_set_output_buf(void *fh, void *buf, int size);
void set_uvc_gray(u32 flag);
// void *uvc_output_open(u8 mijor, struct camera_device_info *info);
// int uvc_output_set_fmt(void *fh, struct video_format *f);
int uvc_get_real_fps(void *fh);
int uvc_output_one_frame(void *fh);
int uvc_output_stop(void *fh);
int uvc_output_close(void *fh);
int uvc_set_output_buffer(void *fh, void *buf, int num);
// int uvc_set_scaler_handler(void *fh, void *priv, int (*handler)(void *, struct YUV_frame_data *));
// int uvc_output_set_reso(void *fh, struct video_format *f, u16 *width, u16 *height);
#endif
+137
View File
@@ -0,0 +1,137 @@
/**@file otg.h
* @brief otg驱动头文件
* @details 结构体声明,功能函数声明
* @author jieli
* @date 2021-7-22
* @version V1.0
* @copyright Copyright(c)2010-2021 珠海市杰理科技股份有限公司
*********************************************************************
* @attention
* 硬件平台:AC632N
* SDK版本:AC632N_V1.0.0_SDK
* @修改日志:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-7-22 <td>1.0 <td>jieli <td>创建初始版本
* </table>
*
*********************************************************************
*/
#ifndef __OTG_H__
#define __OTG_H__
#include "usb/usb.h"
/**@enum usb_hotplug.state 或 usb_hotplug.last_state
* @brief otg当前所处模式 或 上一次所处模式
*/
enum {
IDLE_MODE = 0, ///<空闲模式
DISCONN_MODE = 1, ///<断连模式
HOST_MODE = 2, ///<主机模式
PRE_SLAVE_MODE, ///<成为从机模式前的一个中间模式
SLAVE_MODE_WAIT_CONFIRMATION, ///<从机模式还需等待再次确认
SLAVE_MODE, ///<从机模式
CHARGE_MODE, ///<充电模式
OTG_USER_MODE, ///<用户模式,暂时未具体定义
};
/**@enum 空
* @brief otg挂起时,所选操作模式
*/
enum {
OTG_OP_NULL = 0, ///< ///<空,无意义
OTG_UNINSTALL = 1, ///<OTG卸载
OTG_KEEP_STATE, ///<OTG保持
OTG_SUSPEND, ///< OTG挂起
OTG_RESUME, ///< OTG恢复
};
/**@struct otg_dev_data
* @brief otg_dev_data信息结构体 \n
* 自定义的存储otg设备相关数据信息
*/
struct otg_dev_data {
u8 usb_dev_en; ///<有哪几个otg设备使能,如USB0USB1。
u8 slave_online_cnt; ///<从机上线阈值
u8 slave_offline_cnt; ///<从机下线阈值
u8 host_online_cnt; ///<主机上线阈值
u8 host_offline_cnt; ///<主机下线阈值
u8 detect_mode; ///<otg可用模式配置
u8 detect_time_interval; ///<检测时间间隔,单位 ms
void *otg1; //需要使用双USB口独立配置时,在板级.c文件用户自定义一个otg信息的结构体,并指向它。
};
/**@brief USB设备当前模式获取
* @param[in] usb_id USB接口的id号
* @return 函数的执行结果
* - IDLE_MODE
* - DISCONN_MODE
* - HOST_MODE
* - PRE_SLAVE_MODE
* - SLAVE_MODE_WAIT_CONFIRMATION
* - SLAVE_MODE
* - CHARGE_MODE
* - OTG_USER_MODE
* @par 示例:
* @code
* usb_otg_online(0); 获取USB0当前模式
* @encode
*/
u32 usb_otg_online(const usb_dev usb_id);
// u32 usb_otg_init(u32 mode);
/**@brief 将DP/DM脚设为高阻
* @param[in] usb_id USB接口的id号
* @return 无
* @par 示例:
* @code
* usb_otg_io_suspend(0); 将USB0的DP/DM脚设为高阻状态
* @encode
*/
void usb_otg_io_suspend(usb_dev usb_id);
/**@brief 恢复DP/DM引脚的USB功能,并发起usb reset
* @param[in] usb_id USB接口的id号
* @return 无
* @par 示例:
* @code
* usb_otg_io_resume(0); 将USB0的IO口功能恢复
* @encode
*/
void usb_otg_io_resume(usb_dev usb_id);
/**@brief 将usb_otg设备挂起
* @param[in] usb_id USB接口的id号
* @param[in] op_mode 选择挂起模式
* @ref OTG_UNINSTALL OTG卸载
* @ref OTG_KEEP_STATE OTG保持原模式
* @return 无
* @par 示例:
* @code
* usb_otg_suspend(0,OTG_KEEP_STATE); USB0保持原来的模式
* @encode
*/
void usb_otg_suspend(usb_dev usb_id, u8 op_mode);
/**@brief 将usb_otg设备恢复
* @param[in] usb_id USB接口的id号
* @return 无
* @par 示例:
* @code
* usb_otg_resume(0); USB0恢复
* @encode
*/
void usb_otg_resume(usb_dev usb_id);
void usb_detect_timer_add();
void usb_detect_timer_del();
extern const struct device_operations usb_dev_ops;
#endif /*OTG_H*/
+251
View File
@@ -0,0 +1,251 @@
#ifndef __SCSI_H__
#define __SCSI_H__
#define USB_MSD_MAX_LUN 0xfe
#define USB_MSD_RESET 0xff
/*
* SCSI opcodes
*/
#define TEST_UNIT_READY 0x00
#define REZERO_UNIT 0x01
#define REQUEST_SENSE 0x03
#define FORMAT_UNIT 0x04
#define READ_BLOCK_LIMITS 0x05
#define REASSIGN_BLOCKS 0x07
#define INITIALIZE_ELEMENT_STATUS 0x07
#define READ_6 0x08
#define WRITE_6 0x0a
#define SEEK_6 0x0b
#define READ_REVERSE 0x0f
#define WRITE_FILEMARKS 0x10
#define SPACE 0x11
#define INQUIRY 0x12
#define RECOVER_BUFFERED_DATA 0x14
#define MODE_SELECT 0x15
#define RESERVE 0x16
#define RELEASE 0x17
#define COPY 0x18
#define ERASE 0x19
#define MODE_SENSE 0x1a
#define START_STOP 0x1b
#define RECEIVE_DIAGNOSTIC 0x1c
#define SEND_DIAGNOSTIC 0x1d
#define ALLOW_MEDIUM_REMOVAL 0x1e
#define READ_FORMAT_CAPACITIES 0x23
#define SET_WINDOW 0x24
#define READ_CAPACITY 0x25
#define READ_10 0x28
#define WRITE_10 0x2a
#define SEEK_10 0x2b
#define POSITION_TO_ELEMENT 0x2b
#define WRITE_VERIFY 0x2e
#define VERIFY 0x2f
#define SEARCH_HIGH 0x30
#define SEARCH_EQUAL 0x31
#define SEARCH_LOW 0x32
#define SET_LIMITS 0x33
#define PRE_FETCH 0x34
#define READ_POSITION 0x34
#define SYNCHRONIZE_CACHE 0x35
#define LOCK_UNLOCK_CACHE 0x36
#define READ_DEFECT_DATA 0x37
#define MEDIUM_SCAN 0x38
#define COMPARE 0x39
#define COPY_VERIFY 0x3a
#define WRITE_BUFFER 0x3b
#define READ_BUFFER 0x3c
#define UPDATE_BLOCK 0x3d
#define READ_LONG 0x3e
#define WRITE_LONG 0x3f
#define CHANGE_DEFINITION 0x40
#define WRITE_SAME 0x41
#define UNMAP 0x42
#define READ_TOC 0x43
#define READ_HEADER 0x44
#define GET_EVENT_STATUS_NOTIFICATION 0x4a
#define LOG_SELECT 0x4c
#define LOG_SENSE 0x4d
#define XDWRITEREAD_10 0x53
#define MODE_SELECT_10 0x55
#define RESERVE_10 0x56
#define RELEASE_10 0x57
#define MODE_SENSE_10 0x5a
#define PERSISTENT_RESERVE_IN 0x5e
#define PERSISTENT_RESERVE_OUT 0x5f
#define VARIABLE_LENGTH_CMD 0x7f
#define REPORT_LUNS 0xa0
#define SECURITY_PROTOCOL_IN 0xa2
#define MAINTENANCE_IN 0xa3
#define MAINTENANCE_OUT 0xa4
#define MOVE_MEDIUM 0xa5
#define EXCHANGE_MEDIUM 0xa6
#define READ_12 0xa8
#define WRITE_12 0xaa
#define READ_MEDIA_SERIAL_NUMBER 0xab
#define WRITE_VERIFY_12 0xae
#define VERIFY_12 0xaf
#define SEARCH_HIGH_12 0xb0
#define SEARCH_EQUAL_12 0xb1
#define SEARCH_LOW_12 0xb2
#define SECURITY_PROTOCOL_OUT 0xb5
#define READ_ELEMENT_STATUS 0xb8
#define SEND_VOLUME_TAG 0xb6
#define WRITE_LONG_2 0xea
#define EXTENDED_COPY 0x83
#define RECEIVE_COPY_RESULTS 0x84
#define ACCESS_CONTROL_IN 0x86
#define ACCESS_CONTROL_OUT 0x87
#define READ_16 0x88
#define WRITE_16 0x8a
#define READ_ATTRIBUTE 0x8c
#define WRITE_ATTRIBUTE 0x8d
#define VERIFY_16 0x8f
#define SYNCHRONIZE_CACHE_16 0x91
#define WRITE_SAME_16 0x93
#define SERVICE_ACTION_IN 0x9e
/*
* SENSE KEYS
*/
#define NO_SENSE 0x00
#define RECOVERED_ERROR 0x01
#define NOT_READY 0x02
#define MEDIUM_ERROR 0x03
#define HARDWARE_ERROR 0x04
#define ILLEGAL_REQUEST 0x05
#define UNIT_ATTENTION 0x06
#define DATA_PROTECT 0x07
#define BLANK_CHECK 0x08
#define COPY_ABORTED 0x0a
#define ABORTED_COMMAND 0x0b
#define VOLUME_OVERFLOW 0x0d
#define MISCOMPARE 0x0e
/* Additional Sense code definition*/
#define ASC_NO_ADDITIONAL_SENSE_INFORMATION 0x00
#define ASC_RECOVERED_DATA_WITH_RETRIES 0x17
#define ASC_RECOVERED_DATA_WITH_ECC 0x18
#define ASC_MEDIUM_PRESENT 0x3A
#define ASC_LOGICAL_DRIVE_NOT_READY_BEING_READY 0x04
#define ASC_LOGICAL_DRIVE_NOT_READY_FMT_IN_PRGS 0x04
#define ASC_NO_REFERENCE_POSITION_FOUND 0x06
#define ASC_NO_SEEK_COMPLETE 0x02
#define ASC_WRITE_FAULT 0x03
#define ASC_ID_CRC_ERROR 0x10
#define ASC_UNRECOVERED_READ_ERROR 0x11
#define ASC_ADDRESS_MARK_NOT_FOUND_FOR_ID_FIELD 0x12
#define ASC_RECORDED_ENTITY_NOT_FOUND 0x14
#define ASC_INCOMPATIBLE_MEDIUM_INSTALLED 0x30
#define ASC_CANNOT_READ_MEDIUM_INCOMPATIBLE_FMT 0x30
#define ASC_CANNOT_READ_MEDIUM_UNKNOWN_FORMAT 0x30
#define ASC_FORMAT_COMMAND_FAILED 0x31
#define ASC_INVALID_COMMAND_OPERATION_CODE 0x20
#define ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x21
#define ASC_INVALID_FIELD_IN_COMMAND_PACKET 0x24
#define ASC_LOGICAL_UNIT_NOT_SUPPORTED 0x25
#define ASC_INVALID_FIELD_IN_PARAMETER_LIST 0x26
#define ASC_MEDIUM_REMOVAL_PREVENTED 0x53
#define ASC_NOT_READY_TO_READY_TRANSIT_MDI_CHNG 0x28
#define ASC_POWER_ON_OR_BUS_DEVICE_RESET 0x29
#define ASC_WRITE_PROTECTED_MEDIA 0x27
#define ASC_OVERLAPPED_COMMAND_ATTEMPTED 0x4E
/* Definition of additional sense code qualifier*/
/* Additional Sense code definition */
#define ASCQ_NO_ADDITIONAL_SENSE_INFORMATION 0x00
#define ASCQ_RECOVERED_DATA_WITH_RETRIES 0x01
#define ASCQ_RECOVERED_DATA_WITH_ECC 0x00
#define ASCQ_MEDIUM_PRESENT 0x00
#define ASCQ_LOGICAL_DRIVE_NOT_READY_BEING_READY 0x01
#define ASCQ_LOGICAL_DRIVE_NOT_READY_FMT_IN_PRGS 0x04
#define ASCQ_NO_REFERENCE_POSITION_FOUND 0x00
#define ASCQ_NO_SEEK_COMPLETE 0x00
#define ASCQ_WRITE_FAULT 0x00
#define ASCQ_ID_CRC_ERROR 0x00
#define ASCQ_UNRECOVERED_READ_ERROR 0x00
#define ASCQ_ADDRESS_MARK_NOT_FOUND_FOR_ID_FIELD 0x00
#define ASCQ_RECORDED_ENTITY_NOT_FOUND 0x00
#define ASCQ_INCOMPATIBLE_MEDIUM_INSTALLED 0x00
#define ASCQ_CANNOT_READ_MEDIUM_INCOMPATIBLE_FMT 0x02
#define ASCQ_CANNOT_READ_MEDIUM_UNKNOWN_FORMAT 0x01
#define ASCQ_FORMAT_COMMAND_FAILED 0x01
#define ASCQ_INVALID_COMMAND_OPERATION_CODE 0x00
#define ASCQ_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x00
#define ASCQ_INVALID_FIELD_IN_COMMAND_PACKET 0x00
#define ASCQ_LOGICAL_UNIT_NOT_SUPPORTED 0x00
#define ASCQ_INVALID_FIELD_IN_PARAMETER_LIST 0x00
#define ASCQ_MEDIUM_REMOVAL_PREVENTED 0x02
#define ASCQ_NOT_READY_TO_READY_TRANSIT_MDI_CHNG 0x00
#define ASCQ_POWER_ON_OR_BUS_DEVICE_RESET 0x00
#define ASCQ_WRITE_PROTECTED_MEDIA 0x00
#define ASCQ_OVERLAPPED_COMMAND_ATTEMPTED 0x00
#define USB_LITTLE_ENDIAN
#ifdef USB_LITTLE_ENDIAN
#define CBW_SIGNATURE 0x43425355L
#define CSW_SIGNATURE 0x53425355L
#define CBW_TAG 0x34675326L
#elif defined(USB_BIG_ENDIAN)
#define CBW_SIGNATURE 0x55534243L
#define CSW_SIGNATURE 0x55534253L
#define CBW_TAG 0x26536734L
#else
#error not define endian
#endif
struct usb_scsi_cbw {
u32 dCBWSignature; //[3:0]
u32 dCBWTag; //[7:4]
u32 dCBWDataTransferLength; //[11:8]
u8 bmCBWFlags; //[12]
u8 bCBWLUN; //[13] lun=[3:0] res=[7:4]
u8 bCBWLength; //[14] len=[4:0] res=[7:5]
u8 operationCode;
u8 lun; //<Logical Unit Number
u8 lba[4]; //<Logical Block Address[7:31]
u8 Reserved;
u8 LengthH; //<Transfer or Parameter List or Allocation Length
u8 LengthL;
u8 XLength;
u8 Null[6];
} __attribute__((packed)) ;
struct usb_scsi_csw {
u32 dCSWSignature; //[3:0]
u32 dCSWTag; //[7:4]
u32 uCSWDataResidue; //[11:8]
volatile u8 bCSWStatus; //[12]
} __attribute__((packed)) ;
struct inquiry_data {
u8 PeripheralDeviceType;
u8 RMB;
u8 ISO;
u8 ResponseDataFormat;
u8 AdditionalLength;
u8 Reserved[3];
u8 VendorInfo[8];
u8 ProductInfo[16];
u8 ProductRevisionLevel[4];
} __attribute__((packed)) ;
struct read_capacity_data {
u32 block_num;
u32 block_size;
} __attribute__((packed)) ;
struct request_sense_data {
u8 ErrorCode;
u8 Reserved;
volatile u8 SenseKey;
u8 Info[4];
u8 ASL;
u8 Reserved1[4];
u8 ASC;
u8 ASCQ;
u8 Reserved2[4];
} __attribute__((packed)) ;
#endif /*SCSI_H*/
+139
View File
@@ -0,0 +1,139 @@
#ifndef _USB_H_
#define _USB_H_
#include "typedef.h"
#include "generic/ioctl.h"
#include "asm/usb_hw.h"
#ifndef USB_DIR_OUT
#define USB_DIR_OUT 0 /* to device */
#endif
#ifndef USB_DIR_IN
#define USB_DIR_IN 0x80 /* to host */
#endif
#define EP0_SETUP_LEN 0x40
struct usb_ep_addr_t {
u32 ep0_addr;
u32 ep_usage;
u32 ep_taddr[4];
u32 ep_dual_taddr[4];
u32 ep_raddr[4];
u32 ep_dual_raddr[4];
u32 ep_tsize[4];
u32 ep_rsize[4];
} __attribute__((aligned(4)));
typedef struct {
u32 stamp;
u32 left_time;
} usb_ot_t;
typedef u8 usb_dev;
u32 usb_phy_status(const usb_dev id);
u32 usb_sie_status(const usb_dev id);
u32 usb_check_dpo(const usb_dev id);
u32 usb_check_dmo(const usb_dev id);
u32 usb_read_dp_se(const usb_dev id);
u32 usb_read_dm_se(const usb_dev id);
u16 usb_read_sofframe(const usb_dev id);
void usb_sie_enable(const usb_dev usb_id);
void usb_sie_disable(const usb_dev id);
void usb_write_ep_cnt(const usb_dev usb_id, u32 ep, u32 len);
u32 usb_g_dev_status(const usb_dev usb_id);
u32 usb_h_dev_status(const usb_dev usb_id);
void usb_set_low_speed(const usb_dev usb_id, u8 flag);
void usb_write_ep0(const usb_dev usb_id, const u8 *ptr, u32 len);
void usb_read_ep0(const usb_dev usb_id, u8 *ptr, u32 len);
u32 usb_get_dma_size(const usb_dev usb_id, u32 ep);
void usb_set_dma_tsize(const usb_dev usb_id, u32 ep, u32 size);
void usb_set_dma_rsize(const usb_dev usb_id, u32 ep, u32 size);
void *usb_get_dma_taddr(const usb_dev usb_id, u32 ep);
void usb_set_dma_taddr(const usb_dev usb_id, u32 ep, void *ptr);
void *usb_get_dma_raddr(const usb_dev usb_id, u32 ep);
void usb_set_dma_raddr(const usb_dev usb_id, u32 ep, void *ptr);
void usb_set_dma_dual_raddr(const usb_dev usb_id, u32 ep, void *ptr);
void usb_write_power(const usb_dev usb_id, u32 value);
u32 usb_read_power(const usb_dev usb_id);
u32 usb_read_devctl(const usb_dev usb_id);
void usb_write_devctl(const usb_dev usb_id, u32 value);
u32 usb_read_csr0(const usb_dev usb_id);
void usb_write_csr0(const usb_dev usb_id, u32 csr0);
void usb_ep0_ClrRxPktRdy(const usb_dev usb_id);
void usb_ep0_TxPktEnd(const usb_dev usb_id);
void usb_ep0_RxPktEnd(const usb_dev usb_id);
void usb_ep0_Set_Stall(const usb_dev usb_id);
u32 usb_read_count0(const usb_dev usb_id);
void usb_read_intre(const usb_dev usb_id,
u32 *const intr_usbe,
u32 *const intr_txe,
u32 *const intr_rxe);
void usb_read_intr(const usb_dev usb_id,
u32 *const intr_usb,
u32 *const intr_tx,
u32 *const intr_rx);
void usb_write_intr_usbe(const usb_dev usb_id, u32 intr_usbe);
void usb_set_intr_txe(const usb_dev usb_id, const u32 ep);
void usb_clr_intr_txe(const usb_dev usb_id, const u32 ep);
void usb_set_intr_rxe(const usb_dev usb_id, const u32 ep);
void usb_clr_intr_rxe(const usb_dev usb_id, const u32 ep);
void usb_write_faddr(const usb_dev usb_id, u32 addr);
void usb_write_txcsr(const usb_dev usb_id, const u32 ep, u32 txcsr);
u32 usb_read_txcsr(const usb_dev usb_id, const u32 ep);
void usb_write_rxcsr(const usb_dev usb_id, const u32 ep, u32 rxcsr);
u32 usb_read_rxcsr(const usb_dev usb_id, const u32 ep);
void usb_write_rxmaxp(const usb_dev usb_id, const u32 ep, u32 value);
void usb_write_txmaxp(const usb_dev usb_id, const u32 ep, u32 value);
void usb_write_rxtype(const usb_dev usb_id, const u32 ep, u32 value);
void usb_write_txtype(const usb_dev usb_id, const u32 ep, u32 value);
int usb_read_rxcount(const usb_dev usb_id, u32 ep);
u32 usb_g_ep_read64byte_fast(const usb_dev usb_id, const u32 ep, u8 *ptr, u32 len);
u32 usb_g_ep_read(const usb_dev usb_id, const u32 ep, u8 *ptr, u32 len, u32 block);
u32 usb_g_ep_write(const usb_dev usb_id, u32 ep, const u8 *ptr, u32 len);
u32 usb_g_ep_config(const usb_dev usb_id, u32 ep, u32 type, u32 ie, u8 *ptr, u32 dma_size);
void usb_g_sie_init(const usb_dev usb_id);
void usb_g_hold(const usb_dev usb_id);
u32 usb_get_ep_num(const usb_dev usb_id, u32 ep_dir, u32 type);
u32 usb_h_ep_config(const usb_dev usb_id, u32 ep, u32 type, u32 ie, u32 interval, u8 *ptr, u32 dma_size);
u32 usb_h_ep_write(const usb_dev usb_id, u8 host_ep, u16 txmaxp, u8 target_ep, const u8 *ptr, u32 len, u32 xfer);
int usb_h_ep_write_async(const usb_dev id, u8 host_ep, u16 txmaxp, u8 target_ep, const u8 *ptr, u32 len, u32 xfer, u32 kstart);
u32 usb_h_ep_read(const usb_dev usb_id, u8 host_ep, u16 rxmaxp, u8 target_ep, u8 *ptr, u32 len, u32 xfer);
int usb_h_ep_read_async(const usb_dev id, u8 host_ep, u8 target_ep, u8 *ptr, u32 len, u32 xfer, u32 kstart);
void usb_h_sie_init(const usb_dev usb_id);
void usb_h_sie_close(const usb_dev usb_id);
u32 usb_h_chirp_and_reset(const usb_dev id, u32 reset_delay, u32 timeout);
void usb_h_sie_reset(const usb_dev usb_id);
void usb_hotplug_disable(const usb_dev usb_id);
void usb_hotplug_enable(const usb_dev usb_id, u32 mode);
void usb_pdchkdp_disable(const usb_dev usb_id);
void usb_pdchkdp_enable(const usb_dev usb_id);
void usb_sie_close(const usb_dev usb_id);
void usb_sie_close_all(void);
void usb_var_init(const usb_dev usb_id, void *ptr);
void usb_var_release(const usb_dev usb_id);
void usb_enable_ep(const usb_dev usb_id, u32 eps);
void usb_disable_ep(const usb_dev usb_id, u32 eps);
u32 usb_get_ep_status(const usb_dev usb_id, u32 epx);
void usb_sofie_enable(const usb_dev id);
void usb_sofie_disable(const usb_dev id);
u32 usb_read_sofpnd(const usb_dev id);
void usb_sof_clr_pnd(const usb_dev id);
void usb_ep0_Set_ignore(const usb_dev id, u32 addr);
void usb_recover_io_status(const usb_dev id);
void usb_write_rxinterval(const usb_dev id, const u32 ep, u32 value);
void usb_write_txinterval(const usb_dev id, const u32 ep, u32 value);
void usb_write_txfuncaddr(const usb_dev id, const u32 ep, const u32 devnum);
void usb_write_rxfuncaddr(const usb_dev id, const u32 ep, const u32 devnum);
void usb_h_force_reset(const usb_dev usb_id);
void usb_lowpower_enter_sleep(void);
void usb_lowpower_exit_sleep(void);
#endif
+209
View File
@@ -0,0 +1,209 @@
#ifndef __USB_PHY_H__
#define __USB_PHY_H__
#include "typedef.h"
#include "usb/usb.h"
#ifndef min
#define min(a,b) ((a)<(b) ? (a) : (b))
#endif
#ifndef max
#define max(a,b) ((a)>(b) ? (a) : (b))
#endif
#define ___ntohl(X) ((((u16)(X) & 0xff00) >> 8) |(((u16)(X) & 0x00ff) << 8))
#define ___ntohs(X) ((((u32)(X) & 0xff000000) >> 24) | \
(((u32)(X) & 0x00ff0000) >> 8) | \
(((u32)(X) & 0x0000ff00) << 8) | \
(((u32)(X) & 0x000000ff) << 24))
#if defined(cpu_to_be16) || defined(cpu_to_be32) || defined(be16_to_cpu) || defined(be32_to_cpu)
#error #define cpu_to_be16
#endif
#define cpu_to_be16(v16) ___ntohl(v16)
#define cpu_to_be32(v32) ___ntohs(v32)
#define be16_to_cpu(v16) cpu_to_be16(v16)
#define be32_to_cpu(v32) cpu_to_be32(v32)
#define __le16_to_cpu(v16) (v16)
#define __le32_to_cpu(v32) (v32)
#if defined(cpu_to_le16) || defined(cpu_to_le32) || defined(le16_to_cpu) || defined(le32_to_cpu)
#error #define cpu_to_be16
#endif
#define cpu_to_le16(v16) (v16)
#define cpu_to_le32(v32) (v32)
#define le16_to_cpu(v16) cpu_to_le16(v16)
#define le32_to_cpu(v32) cpu_to_le32(v32)
#define LOWORD(l) ((u16)(l))
#define HIWORD(l) ((u16)(((u32)(l) >> 16) & 0xFFFF))
#define LOBYTE(w) ((u8)(w))
#define HIBYTE(w) ((u8)(((u16)(w) >> 8) & 0xFF))
#define DW1BYTE(dw) (LOBYTE(LOWORD(dw)))
#define DW2BYTE(dw) (HIBYTE(LOWORD(dw)))
#define DW3BYTE(dw) (LOBYTE(HIWORD(dw)))
#define DW4BYTE(dw) (HIBYTE(HIWORD(dw)))
//............. Full Speed USB ...................
#define MUSB_FADDR 0x00
#define MUSB_POWER 0x01
#define MUSB_INTRTX1 0x02
#define MUSB_INTRTX2 0x03
#define MUSB_INTRRX1 0x04
#define MUSB_INTRRX2 0x05
#define MUSB_INTRUSB 0x06
#define MUSB_INTRTX1E 0x07
#define MUSB_INTRTX2E 0x08
#define MUSB_INTRRX1E 0x09
#define MUSB_INTRRX2E 0x0a
#define MUSB_INTRUSBE 0x0b
#define MUSB_FRAME1 0x0c
#define MUSB_FRAME2 0x0d
#define MUSB_INDEX 0x0e
#define MUSB_DEVCTL 0x0f
#define MUSB_TXMAXP 0x10
#define MUSB_CSR0 0x11
#define MUSB_TXCSR1 0x11
#define MUSB_TXCSR2 0x12
#define MUSB_RXMAXP 0x13
#define MUSB_RXCSR1 0x14
#define MUSB_RXCSR2 0x15
#define MUSB_COUNT0 0x16
#define MUSB_RXCOUNT1 0x16
#define MUSB_RXCOUNT2 0x17
#define MUSB_TXTYPE 0x18
#define MUSB_TXINTERVAL 0x19
#define MUSB_RXTYPE 0x1a
#define MUSB_RXINTERVAL 0x1b
/*****MUSB SFR BitMap******/
/*INTRUSB mode*/
#define INTRUSB_SUSPEND BIT(0)
#define INTRUSB_RESUME BIT(1)
#define INTRUSB_RESET_BABBLE BIT(2)
#define INTRUSB_SOF BIT(3)
#define INTRUSB_CONNECT BIT(4)
#define INTRUSB_DISCONNECT BIT(5)
#define INTRUSB_SESS_REQ BIT(6)
#define INTRUSB_VBUS_ERROR BIT(7)
/*CSR0 peripheral mode*/
#define CSR0P_RxPktRdy 0x01
#define CSR0P_TxPktRdy 0x02
#define CSR0P_SentStall 0x04
#define CSR0P_DataEnd 0x08
#define CSR0P_SetupEnd 0x10
#define CSR0P_SendStall 0x20
#define CSR0P_ClrRxPktRdy 0x40
#define CSR0P_ClrSetupEnd 0x80
/*TXCSR1 peripheral mode*/
#define TXCSRP_TxPktRdy 0x01
#define TXCSRP_FIFONotEmpty 0x02
#define TXCSRP_UnderRun 0x04
#define TXCSRP_FlushFIFO 0x08
#define TXCSRP_SendStall 0x10
#define TXCSRP_SentStall 0x20
#define TXCSRP_ClrDataTog 0x40
#define TXCSRP_IncompTx 0x80
#define TXCSRP_DIR (BIT(13))
#define TXCSRP_ISOCHRONOUS (BIT(14))
/*RXCSR1 peripheral mode*/
#define RXCSRP_RxPktRdy 0x01
#define RXCSRP_FIFOFull 0x02
#define RXCSRP_OverRun 0x04
#define RXCSRP_DataError 0x08
#define RXCSRP_FlushFIFO 0x10
#define RXCSRP_SendStall 0x20
#define RXCSRP_SentStall 0x40
#define RXCSRP_ClrDataTog 0x80
#define RXCSRP_IncompRx (BIT(8))
#define RXCSRP_ISOCHRONOUS (BIT(14))
/*CSR0 host mode*/
#define CSR0H_RxPktRdy 0x01
#define CSR0H_TxPktRdy 0x02
#define CSR0H_RxStall 0x04
#define CSR0H_SetupPkt 0x08
#define CSR0H_Error 0x10
#define CSR0H_ReqPkt 0x20
#define CSR0H_StatusPkt 0x40
#define CSR0H_DISPING (BIT(11))
/*TXCSR1 host mode*/
#define TXCSRH_TxPktRdy 0x01
#define TXCSRH_FIFONotEmpty 0x02
#define TXCSRH_Error 0x04
#define TXCSRH_FlushFIFO 0x08
#define TXCSRH_RxStall 0x20
#define TXCSRH_ClrDataTog 0x40
#define TXCSRH_NAK 0x80
/*RXCSR1 host mode*/
#define RXCSRH_RxPktRdy 0x01
#define RXCSRH_FIFOFull 0x02
#define RXCSRH_Error 0x04
#define RXCSRH_DataError 0x08
#define RXCSRH_FlushFIFO 0x10
#define RXCSRH_ReqPkt 0x20
#define RXCSRH_RxStall 0x40
#define RXCSRH_ClrDataTog 0x80
#define RXCSRH_IncompRx BIT(8)
#define RXCSRH_PIDError BIT(12)
///USB Slave 控制传输各阶段
#define USB_EP0_STAGE_SETUP 0
#define USB_EP0_STAGE_IN 1
#define USB_EP0_STAGE_OUT 2
#define USB_EP0_SET_STALL 3
#define USB_EP0_IGNORE 4
#define USB_EP0_STAGE_NAK 5
///USB suspend_resume各阶段状态
#define USB_READY 0
#define USB_SUSPEND 1
#define USB_RESUME_WAIT 2
#define USB_RESUME_OK 3
/* common api */
u32 usb_get_jiffies();
u32 usb_host_timeout(u32 ot);
void usb_mdelay(unsigned int ms);
/* slave api */
u32 usb_g_bulk_read64byte_fast(const usb_dev usb_id, u32 ep, u8 *ptr, u32 len);
u32 usb_g_bulk_read(const usb_dev usb_id, u32 ep, u8 *ptr, u32 len, u32 block);
u32 usb_g_bulk_write(const usb_dev usb_id, u32 ep, const u8 *ptr, u32 len);
u32 usb_g_intr_read(const usb_dev usb_id, u32 ep, u8 *ptr, u32 len, u32 block);
u32 usb_g_intr_write(const usb_dev usb_id, u32 ep, const u8 *ptr, u32 len);
u32 usb_g_iso_read(const usb_dev usb_id, u32 ep, u8 *ptr, u32 len, u32 block);
u32 usb_g_iso_write(const usb_dev usb_id, u32 ep, const u8 *ptr, u32 len);
void usb_slave_init(const usb_dev usb_id, u32 speed);
/* host api */
u32 usb_h_bulk_read(const usb_dev usb_id, u8 host_ep, u16 rxmaxp, u8 target_ep, u8 *ptr, u32 len);
u32 usb_h_bulk_write(const usb_dev usb_id, u8 host_ep, u16 txmaxp, u8 target_ep, u8 *ptr, u32 len);
u32 usb_h_intr_read(const usb_dev usb_id, u8 host_ep, u16 rxmaxp, u8 target_ep, u8 *ptr, u32 len);
u32 usb_h_intr_write(const usb_dev usb_id, u8 host_ep, u16 txmaxp, u8 target_ep, u8 *ptr, u32 len);
u32 usb_h_iso_read(const usb_dev usb_id, u8 host_ep, u16 rxmaxp, u8 target_ep, u8 *ptr, u32 len);
u32 usb_h_iso_write(const usb_dev usb_id, u8 host_ep, u16 txmaxp, u8 target_ep, u8 *ptr, u32 len);
void usb_h_entry_suspend(const usb_dev usb_id);
void usb_h_resume(const usb_dev usb_id);
u32 usb_host_init(const usb_dev usb_id, u32 reset_delay, u32 timeout, u32 speed);
u32 usb_host_reset(const usb_dev usb_id, u32 reset_delay, u32 timeout, u32 speed);
void usb_driver_event_to_user(u32 from, u32 event, void *arg);
void usb_driver_event_from_otg(u32 from, u32 event, void *arg);
#endif /*USB_PHY_H*/
@@ -0,0 +1,53 @@
#ifndef __WIRELESS_H__
#define __WIRELESS_H__
#include "cpu/includes.h"
enum {
IO_LOW, //低
IO_HIGH, //高
IO_OVERTURN, //翻转
IO_OPEN, //打开
IO_DIR_IN,//高阻
IO_INIT, //初始化
};
struct _wireless_info {
volatile u8 busy: 1;
volatile u8 open: 1;
volatile u8 flag: 1;
volatile u8 dcdc_en: 1;
volatile u8 bit_totle: 4;
volatile u8 bit_num: 4;
volatile u8 byte_num: 4;
volatile u8 data_number: 4;
volatile u8 error_count: 4;
volatile u8 bit_count;
volatile u8 nex_packet;
};
typedef struct _wireless_hdl_ {
u16(*get_wl_power)(void);
void (*dcdc_en_set)(u8 en);
void (*wpc_set)(u8 en);
u16 *send_buff;
u16 voltage_max;
u16 voltage_min;
u8 err_packet_fast_cnt;
struct _wireless_info info;
} _wireless_hdl;
//库C函数声明
void wireless_250us_run(void);
void wireless_open(u16 min, u16 max);
void wireless_close(void);
void get_signal_value(void);
void get_configuration(void);
void get_identification(void);
void wireless_100ms_run(void);
void wireless_lib_init(_wireless_hdl *wldata, u16 min, u16 max);
#endif/*__WIRELESS_H__*/