first
This commit is contained in:
18
include_lib/driver/device/anctool.h
Normal file
18
include_lib/driver/device/anctool.h
Normal 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
|
||||
72
include_lib/driver/device/sdio_host_init.h
Normal file
72
include_lib/driver/device/sdio_host_init.h
Normal file
@ -0,0 +1,72 @@
|
||||
#ifndef _SDIO_HOST_INIT_H_
|
||||
#define _SDIO_HOST_INIT_H_
|
||||
|
||||
/*
|
||||
SDIO_GRP_0|SDIO_PORT_0: PA1-PA4->CMD,CLK,D2,D0; PH13,PH15->D3,D1
|
||||
SDIO_GRP_0|SDIO_PORT_1: PH6-PH11->D3,CMD,CLK,D2,D0,D1
|
||||
SDIO_GRP_0|SDIO_PORT_2: PC8-PC13->D2,D3,CMD,CLK,D0,D1
|
||||
SDIO_GRP_0|SDIO_PORT_3: PG8-PG13->D2,D3,CMD,CLK,D0,D1
|
||||
SDIO_GRP_1|SDIO_PORT_0: PF4-PF9->D2,D3,CMD,CLK,D0,D1
|
||||
SDIO_GRP_1|SDIO_PORT_1: PG0-PG5->D2,D3,CMD,CLK,D0,D1
|
||||
SDIO_GRP_1|SDIO_PORT_2: PD6-PD11->D2,D3,CMD,CLK,D0,D1
|
||||
SDIO_GRP_1|SDIO_PORT_3: PA10-PA15->D2,D3,CMD,CLK,D0,D1
|
||||
*/
|
||||
|
||||
//选择SDIO0? SDIO1? 作为输出,默认为SDIO1
|
||||
#define SDIO_GRP_0 0
|
||||
#define SDIO_GRP_1 (1 << 31)
|
||||
#define SDIO_GRP_2 (1 << 30)
|
||||
#define SDIO_GRP_MASK (1 << 31|1 << 30)
|
||||
|
||||
//选择SDIOx的哪个出口作为输出,默认为出口0
|
||||
#define SDIO_PORT_0 0
|
||||
#define SDIO_PORT_1 (1 << 29)
|
||||
#define SDIO_PORT_2 (1 << 28)
|
||||
#define SDIO_PORT_3 (1 << 29|1 << 28)
|
||||
#define SDIO_PORT_MASK (1 << 29|1 << 28)
|
||||
|
||||
//是否使用四线模式, 默认为单线模式
|
||||
#define SDIO_1_BIT_DATA 0
|
||||
#define SDIO_4_BIT_DATA (1 << 27)
|
||||
#define SDIO_4_BIT_DATA_MASK (1 << 27)
|
||||
|
||||
//是否使用硬件中断检测外设事件,例如接收到数据. , 默认使用轮询方式查询事件, //对接收速度不敏感使用SDIO_POLLING即可 ,使用SDIO_DATA1_IRQ如果接收数据量过大会导致CPU不足的问题.
|
||||
#define SDIO_POLLING 0
|
||||
#define SDIO_DATA1_IRQ (1 << 26)
|
||||
#define SDIO_DATA1_IRQ_MASK (1 << 26)
|
||||
|
||||
//配置SDIO时钟(HZ), 默认为40MHZ
|
||||
#define SDIO_MAX_CLK_MASK ((1 << 26)-1)
|
||||
|
||||
#define SDIO_CLOCK_80M (0) //80M 写0
|
||||
#define SDIO_CLOCK_40M (40 * 1000000)
|
||||
#define SDIO_CLOCK_26M (26 * 1000000)
|
||||
#define SDIO_CLOCK_20M (20 * 1000000)
|
||||
#define SDIO_CLOCK_16M (16 * 1000000)
|
||||
#define SDIO_CLOCK_8M (8 * 1000000)
|
||||
#define SDIO_CLOCK_4M (4 * 1000000)
|
||||
#define SDIO_CLOCK_2M (2 * 1000000)
|
||||
|
||||
/*
|
||||
sdio_host_init(0);
|
||||
sdio_host_init(SDIO_GRP_1|SDIO_4_BIT_DATA);
|
||||
sdio_host_init(SDIO_GRP_1|SDIO_PORT_1|SDIO_DATA1_IRQ);
|
||||
sdio_host_init(SDIO_GRP_0|SDIO_PORT_0|SDIO_4_BIT_DATA|SDIO_DATA1_IRQ|(10*1000000));
|
||||
*/
|
||||
|
||||
extern void sdio_host_init(unsigned int parm);
|
||||
extern unsigned char *SDIO_GET_CMD_BUF(void);
|
||||
extern void SDIO_SET_GRP_PORT(u32 grp, u32 port);
|
||||
extern void cpu_sdio_host_uninit(void);
|
||||
extern void sdio_dat1_irq_uninit(void);
|
||||
extern void sdio_dat1_irq_init(void);
|
||||
extern void host_set_timing(void *host, unsigned int timing);
|
||||
extern void mmc_set_bus_width(void *host, unsigned int width);
|
||||
extern void mmc_set_clock(void *host, unsigned int hz);
|
||||
extern void SDIO_CONTROLLER_RESET(void);
|
||||
extern void SDIO_IDLE_CLK_EN(u8 enable) ;
|
||||
extern void SDIO_CONTROLLER_START(void);
|
||||
extern void SDIO_CONTROLLER_SET_IRQ(void);
|
||||
extern void SDIO_SET_4WIRE_MODE(u8 enable);
|
||||
|
||||
#endif //_SDIO_HOST_INIT_H_
|
||||
42
include_lib/driver/device/sdmmc.h
Normal file
42
include_lib/driver/device/sdmmc.h
Normal file
@ -0,0 +1,42 @@
|
||||
#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_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)
|
||||
|
||||
|
||||
#define SD_IOCTL_SUPPORT_ERASE_OPERAT 1
|
||||
|
||||
typedef enum {
|
||||
SDMMC_NORMAL_ERASE,
|
||||
SDMMC_TRIM_ERASE,
|
||||
SDMMC_DISCARD,
|
||||
SDMMC_SECURE_ERASE,
|
||||
SDMMC_SECURE_TRIM_STEP_1,
|
||||
SDMMC_SECURE_TRIM_STEP_2,
|
||||
} sdmmc_erase_type;
|
||||
|
||||
struct sdmmc_erase_arg_t {
|
||||
sdmmc_erase_type erase_type;
|
||||
u32 block_addr;
|
||||
u32 block_quantity;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
125
include_lib/driver/device/spiflash.h
Normal file
125
include_lib/driver/device/spiflash.h
Normal file
@ -0,0 +1,125 @@
|
||||
#ifndef __SPIFLASH_H__
|
||||
#define __SPIFLASH_H__
|
||||
|
||||
|
||||
|
||||
#include "typedef.h"
|
||||
#include "generic/list.h"
|
||||
#include "generic/ioctl.h"
|
||||
#include "device/device.h"
|
||||
#include "system/task.h"
|
||||
|
||||
|
||||
struct spi_device;
|
||||
|
||||
enum spiflash_bit_mode {
|
||||
SPI_2WIRE_MODE,
|
||||
SPI_ODD_MODE,
|
||||
SPI_DUAL_MODE,
|
||||
SPI_QUAD_MODE,
|
||||
};
|
||||
|
||||
enum spiflash_read_mode {
|
||||
FAST_READ_OUTPUT_MODE,
|
||||
FAST_READ_IO_MODE,
|
||||
FAST_READ_IO_CONTINUOUS_READ_MODE,
|
||||
};
|
||||
|
||||
enum sfc_run_mode {
|
||||
//1bit mode
|
||||
SFC_READ_DATA_MODE = (1 << 0),
|
||||
SFC_FAST_READ_MODE = (1 << 1),
|
||||
//2bit mode
|
||||
SFC_FAST_READ_DUAL_IO_NORMAL_READ_MODE = (1 << 2),
|
||||
SFC_FAST_READ_DUAL_IO_CONTINUOUS_READ_MODE = (1 << 3),
|
||||
SFC_FAST_READ_DUAL_OUTPUT_MODE = (1 << 4),
|
||||
//4bit mode
|
||||
SFC_FAST_READ_QUAD_IO_NORMAL_READ_MODE = (1 << 5),
|
||||
SFC_FAST_READ_QUAD_IO_CONTINUOUS_READ_MODE = (1 << 6),
|
||||
SFC_FAST_READ_QUAD_OUTPUT_MODE = (1 << 7),
|
||||
|
||||
};
|
||||
struct spi_ops {
|
||||
int (*set_cs)(int);
|
||||
int (*init)(void *);
|
||||
u8(*read_byte)(int *err);
|
||||
int (*read)(u8 *, u32 len, u8 mode);
|
||||
int (*write_byte)(u8 cmd);
|
||||
int (*write_cmd)(u8 *cmd, u32 len);
|
||||
int (*write)(u8 *, u32 len);
|
||||
u8(*get_bit_mode)();
|
||||
};
|
||||
|
||||
|
||||
struct sf_info {
|
||||
u32 id;
|
||||
u16 page_size; //byte
|
||||
u16 block_size; //KByte
|
||||
u32 chip_size; //KByte
|
||||
};
|
||||
|
||||
enum sf_erase_type {
|
||||
SF_SECTOR_ERASE,
|
||||
SF_BLOCK_ERASE,
|
||||
SF_CHIP_ERASE,
|
||||
};
|
||||
|
||||
//struct sf_erase {
|
||||
//enum sf_erase_type type;
|
||||
//u32 addr;
|
||||
//};
|
||||
|
||||
|
||||
//struct sf_wp {
|
||||
//u8 enable;
|
||||
//u8 cmd;
|
||||
//};
|
||||
|
||||
|
||||
struct spi_device {
|
||||
const char *name;
|
||||
const struct spi_ops *ops;
|
||||
};
|
||||
|
||||
struct spiflash_platform_data {
|
||||
const char *name;
|
||||
enum spiflash_read_mode mode;
|
||||
enum sfc_run_mode sfc_run_mode;
|
||||
void *private_data;
|
||||
};
|
||||
|
||||
|
||||
struct spiflash {
|
||||
struct list_head entry;
|
||||
void *device;
|
||||
struct device dev;
|
||||
struct sf_info info;
|
||||
const struct spiflash_platform_data *pd;
|
||||
const char *name;
|
||||
OS_MUTEX mutext;
|
||||
u8 inited;
|
||||
u8 read_mode;
|
||||
u8 read_cmd_mode;
|
||||
u8 write_cmd_mode;
|
||||
u8 continuous_read_mode;
|
||||
};
|
||||
|
||||
|
||||
#define REGISTER_SPIFLASH_DEVICE(dev) \
|
||||
static const struct spi_device dev sec(.spi_device)
|
||||
|
||||
|
||||
extern struct spi_device spi_device_begin[];
|
||||
extern struct spi_device spi_device_end[];
|
||||
|
||||
|
||||
|
||||
|
||||
extern struct spiflash *__get_spiflash(const char *name);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
131
include_lib/driver/device/uart.h
Normal file
131
include_lib/driver/device/uart.h
Normal file
@ -0,0 +1,131 @@
|
||||
#ifndef DEVICE_UART_H
|
||||
#define DEVICE_UART_H
|
||||
|
||||
#include "typedef.h"
|
||||
#include "device/device.h"
|
||||
#include "generic/ioctl.h"
|
||||
#include "system/task.h"
|
||||
|
||||
#define UART_DISABLE 0x00000000
|
||||
#define UART_DMA_SUPPORT 0x00000001
|
||||
#define UART_TX_USE_DMA 0x00000003
|
||||
#define UART_RX_USE_DMA 0x00000005
|
||||
#define UART_DEBUG 0x00000008
|
||||
|
||||
struct uart_outport {
|
||||
u8 tx_pin;
|
||||
u8 rx_pin;
|
||||
u16 value;
|
||||
};
|
||||
|
||||
extern void putbyte(char a);
|
||||
|
||||
|
||||
|
||||
|
||||
enum uart_clk_src {
|
||||
LSB_CLK,
|
||||
OSC_CLK,
|
||||
PLL_48M,
|
||||
};
|
||||
|
||||
|
||||
enum _uart_port_out {
|
||||
//uart0
|
||||
PORTC_0_1 = 0x00001000,
|
||||
PORTG_6_7 = 0x00002000,
|
||||
PORTH_12_13 = 0x00003000,
|
||||
PORTB_14_15 = 0x00004000,
|
||||
//uart1
|
||||
PORTC_2_3 = 0x00005000,
|
||||
PORTH_2_5 = 0x00006000,
|
||||
PORTH_14_15 = 0x00007000,
|
||||
PORTC_6_7 = 0x00008000,
|
||||
//uart3
|
||||
PORTE_0_1 = 0x00009000,
|
||||
PORTB_4_3 = 0x0000A000,
|
||||
PORTD_9_10 = 0x0000B000,
|
||||
PORTD_14_15 = 0x0000C000,
|
||||
|
||||
PORT_REMAP = 0x0000D000,
|
||||
};
|
||||
|
||||
struct uart_platform_data {
|
||||
u8 *name;
|
||||
|
||||
u8 irq;
|
||||
u8 tx_pin;
|
||||
u8 rx_pin;
|
||||
u32 flags;
|
||||
u32 baudrate;
|
||||
|
||||
enum _uart_port_out port;
|
||||
void (*port_remap_func)(void);
|
||||
u32 max_continue_recv_cnt;
|
||||
u32 idle_sys_clk_cnt;
|
||||
enum uart_clk_src clk_src;
|
||||
};
|
||||
|
||||
enum {
|
||||
UART_CIRCULAR_BUFFER_WRITE_OVERLAY = -1,
|
||||
UART_RECV_TIMEOUT = -2,
|
||||
UART_RECV_EXIT = -3,
|
||||
};
|
||||
|
||||
#define UART_MAGIC 'U'
|
||||
#define UART_FLUSH _IO(UART_MAGIC,1)
|
||||
#define UART_SET_RECV_ALL _IOW(UART_MAGIC,2,bool)
|
||||
#define UART_SET_RECV_BLOCK _IOW(UART_MAGIC,3,bool)
|
||||
#define UART_SET_RECV_TIMEOUT _IOW(UART_MAGIC,4,u32)
|
||||
#define UART_SET_RECV_TIMEOUT_CB _IOW(UART_MAGIC,5,int (*)(void))
|
||||
#define UART_GET_RECV_CNT _IOR(UART_MAGIC,6,u32)
|
||||
#define UART_START _IO(UART_MAGIC,7)
|
||||
#define UART_SET_CIRCULAR_BUFF_ADDR _IOW(UART_MAGIC,8,void *)
|
||||
#define UART_SET_CIRCULAR_BUFF_LENTH _IOW(UART_MAGIC,9,u32)
|
||||
|
||||
|
||||
#define UART_PLATFORM_DATA_BEGIN(data) \
|
||||
static const struct uart_platform_data data = {
|
||||
|
||||
|
||||
#define UART_PLATFORM_DATA_END() \
|
||||
};
|
||||
|
||||
|
||||
struct uart_device {
|
||||
char *name;
|
||||
const struct uart_operations *ops;
|
||||
struct device dev;
|
||||
const struct uart_platform_data *priv;
|
||||
OS_MUTEX mutex;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
struct uart_operations {
|
||||
int (*init)(struct uart_device *);
|
||||
int (*read)(struct uart_device *, void *buf, u32 len);
|
||||
int (*write)(struct uart_device *, void *buf, u16 len);
|
||||
int (*ioctl)(struct uart_device *, u32 cmd, u32 arg);
|
||||
int (*close)(struct uart_device *);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define REGISTER_UART_DEVICE(dev) \
|
||||
static struct uart_device dev sec(.uart)
|
||||
|
||||
extern struct uart_device uart_device_begin[], uart_device_end[];
|
||||
|
||||
#define list_for_each_uart_device(p) \
|
||||
for (p=uart_device_begin; p<uart_device_end; p++)
|
||||
|
||||
|
||||
|
||||
extern const struct device_operations uart_dev_ops;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
1011
include_lib/driver/device/usb/ch9.h
Normal file
1011
include_lib/driver/device/usb/ch9.h
Normal file
File diff suppressed because it is too large
Load Diff
99
include_lib/driver/device/usb/device/descriptor.h
Normal file
99
include_lib/driver/device/usb/device/descriptor.h
Normal file
@ -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 "asm/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*/
|
||||
212
include_lib/driver/device/usb/device/hid.h
Normal file
212
include_lib/driver/device/usb/device/hid.h
Normal file
@ -0,0 +1,212 @@
|
||||
/**@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 "asm/usb.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
|
||||
34
include_lib/driver/device/usb/device/msd.h
Normal file
34
include_lib/driver/device/usb/device/msd.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef __USBD_MSD_H__
|
||||
#define __USBD_MSD_H__
|
||||
|
||||
#include "asm/usb.h"
|
||||
#include "usb_stack.h"
|
||||
|
||||
#define MAX_MSD_DEV 2
|
||||
#define MSD_DEV_NAME_LEN 12
|
||||
|
||||
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*/
|
||||
470
include_lib/driver/device/usb/device/uac_audio.h
Normal file
470
include_lib/driver/device/usb/device/uac_audio.h
Normal file
@ -0,0 +1,470 @@
|
||||
/**
|
||||
* <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 "asm/usb.h"
|
||||
struct uac1_status_word {
|
||||
u8 bStatusType;
|
||||
u8 bOriginator;
|
||||
} __attribute__((packed));
|
||||
|
||||
u32 uac_setup_endpoint(struct usb_device_t *usb_device, struct usb_ctrlrequest *req);
|
||||
u32 uac_spk_desc_config(const usb_dev usb_id, u8 *ptr, u32 *cur_itf_num);
|
||||
void uac_speaker_stream_write(const u8 *obuf, u32 len);
|
||||
void uac_speaker_stream_open(u32 samplerate, u32 ch);
|
||||
void uac_speaker_stream_close();
|
||||
|
||||
u32 uac_mic_desc_config(const usb_dev usb_id, u8 *ptr, u32 *cur_itf_num);
|
||||
u32 uac_mic_stream_open(u32 samplerate, u32 frame_len, u32 ch);
|
||||
int uac_mic_stream_read(u8 *buf, u32 len);
|
||||
void uac_mic_stream_close();
|
||||
void uac_mute_volume(u32 type, u32 l_vol, u32 r_vol);
|
||||
int uac_get_spk_vol();
|
||||
u32 uac_audio_desc_config(const usb_dev usb_id, u8 *ptr, u32 *cur_itf_num);
|
||||
void uac_audio_disable(const usb_dev usb_id);
|
||||
const u8 *uac_get_string(u32 id);
|
||||
u32 uac_register(const usb_dev usb_id, const u32 class);
|
||||
void uac_release(const usb_dev usb_id);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /** __LINUX_USB_AUDIO_H */
|
||||
226
include_lib/driver/device/usb/device/usb_stack.h
Normal file
226
include_lib/driver/device/usb/device/usb_stack.h
Normal file
@ -0,0 +1,226 @@
|
||||
#ifndef __USB_STACK_H__
|
||||
#define __USB_STACK_H__
|
||||
#include "typedef.h"
|
||||
#include "asm/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 0
|
||||
#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 bRemoteWakup: 1;
|
||||
u8 baddr_config: 1;
|
||||
#if USB_MAX_HW_NUM == 2
|
||||
u8 usb_id: 1;
|
||||
u8 res: 5;
|
||||
#else
|
||||
u8 res: 6;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef u32(*itf_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];
|
||||
} __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);
|
||||
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();
|
||||
|
||||
extern void usb_start();
|
||||
extern void usb_stop();
|
||||
extern void usb_pause();
|
||||
extern void usb_cdc_background_run();
|
||||
|
||||
/* #define usb_add_desc_config(fn) \ */
|
||||
/* const desc_config usb_desc_config##fn sec(.usb.desc_config) = fn */
|
||||
|
||||
#endif /*USB_STACK_H*/
|
||||
261
include_lib/driver/device/usb/host/usb_host.h
Normal file
261
include_lib/driver/device/usb/host/usb_host.h
Normal file
@ -0,0 +1,261 @@
|
||||
/**@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 "asm/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);
|
||||
};
|
||||
|
||||
/**@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;
|
||||
void *p;
|
||||
} dev;
|
||||
};
|
||||
#define MAX_HOST_INTERFACE 4
|
||||
|
||||
/**@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))
|
||||
|
||||
/**@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);
|
||||
|
||||
#endif /*USB_HOST_H*/
|
||||
140
include_lib/driver/device/usb/otg.h
Normal file
140
include_lib/driver/device/usb/otg.h
Normal file
@ -0,0 +1,140 @@
|
||||
/**@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 "asm/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恢复
|
||||
};
|
||||
|
||||
#define OTG_HOST_MODE BIT(0)
|
||||
#define OTG_SLAVE_MODE BIT(1)
|
||||
#define OTG_CHARGE_MODE BIT(2)
|
||||
#define OTG_DET_DP_ONLY BIT(3)
|
||||
#define OTG_DET_DM_ONLY BIT(4)
|
||||
|
||||
/**@struct otg_dev_data
|
||||
* @brief otg_dev_data信息结构体 \n
|
||||
* 自定义的存储otg设备相关数据信息
|
||||
*/
|
||||
struct otg_dev_data {
|
||||
u8 usb_dev_en; ///<有哪几个otg设备使能,如USB0,USB1。
|
||||
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_otg_sof_check_register_hooks(void (*before)(), void (*after)());
|
||||
|
||||
extern const struct device_operations usb_dev_ops;
|
||||
|
||||
|
||||
#endif /*OTG_H*/
|
||||
251
include_lib/driver/device/usb/scsi.h
Normal file
251
include_lib/driver/device/usb/scsi.h
Normal 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*/
|
||||
213
include_lib/driver/device/usb/usb_phy.h
Normal file
213
include_lib/driver/device/usb/usb_phy.h
Normal file
@ -0,0 +1,213 @@
|
||||
#ifndef __USB_PHY_H__
|
||||
#define __USB_PHY_H__
|
||||
#include "typedef.h"
|
||||
#include "asm/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
|
||||
|
||||
/* common api */
|
||||
u32 usb_get_jiffies();
|
||||
u32 usb_host_timeout(u32 ot);
|
||||
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);
|
||||
u32 usb_read_sofpnd(const usb_dev id);
|
||||
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);
|
||||
|
||||
|
||||
/* 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);
|
||||
void usb_phy_resume(const usb_dev usb_id);
|
||||
void usb_phy_suspend(const usb_dev usb_id);
|
||||
|
||||
/* 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 usb_host_reset(const usb_dev usb_id, u32 reset_delay, u32 timeout);
|
||||
void usb_h_force_reset(const usb_dev usb_id);
|
||||
// u32 usb_h_sie_init(u32 reset_delay, u32 timeout);
|
||||
// void usb_h_sie_close();
|
||||
|
||||
#endif /*USB_PHY_H*/
|
||||
Reference in New Issue
Block a user