📄 d12.c
字号:
#include "./src/config.h"
#define SWAP16(x) ((((uint16)(x))<<8)|(((uint16)(x))>>8))
#define MSB(x) (((x) >> 8) & 0xFF)
#define LSB(x) (((x) >> 0) & 0xFF)
#define D12_CMD (*((volatile uint8 *)0x82000001)) //命令
#define D12_DAT (*((volatile uint8 *)0x82000000)) //数据
#define D12_NOP (*((volatile uint8 *)0x80000000)) //空操作
//*************************************************************************************************
extern void DelayNS(uint32 dly);
extern uint8 rcv_buf[];
uint8 dat_buf[8];
uint8 GenEpBuf[16];
uint8 EpBuf[64];
//*************************************************************************************************
uint32 vic_temp;
void DISABLE(void)
{
vic_temp = VICIntEnable;
//VICIntEnClr = 0xffffffff;
}
void ENABLE(void)
{
//VICIntEnable |= vic_temp;
}
//*************************************************************************************************
EVENT_FLAGS event_flag;
CONTROL_XFER control_data;
//0 = main;1=globl;2=local;3=reserved
const uint8 ReportDescriptor[40] =
{
0x05, 0x0c, // USAGE_PAGE (Consumer Page) 1=globl
0x09, 0x01, // USAGE (Consumer Control) 2=local
0xa1, 0x01, // COLLECTION (Application) 0=main
0x09, 0xea, // USAGE (Volume Decrement) 2=local
0x09, 0xe9, // USAGE (Volume Increment) 2=local
0x09, 0xe2, // USAGE (Mute) 2=local
0x09, 0xcd, // USAGE (Play/Pause) 2=local
0x0a, 0x83, 0x01, // USAGE (Windows Media Player(0x183)) 2=local
0x0a, 0x23, 0x02, // USAGE (AC Home(0x0223)) 2=local
0x0a, 0x92, 0x01, // USAGE (AL Calculator(0x192)) 2=local
0x15, 0x00, // LOGICAL_MINIMUM (0) 1=globl
0x25, 0x01, // LOGICAL_MAXIMUM (1) 1=globl
0x95, 0x07, // REPORT_COUNT (7) 1=globl
0x75, 0x01, // REPORT_SIZE (1) 1=globl
0x81, 0x02, // INPUT (Data,Var,Abs) 0=main
0x75, 0x01, // REPORT_SIZE (1) 1=globl
0x95, 0x01, // REPORT_COUNT (1) 1=globl
0x81, 0x03, // INPUT (Cnst,Var,Abs) 0=main
0xc0 // END_COLLECTION 0=main
}; /* ReportDescriptor */
//
const uint8 KeyBoardReportDescriptor[119] = {
//const uint8 KeyBoardReportDescriptor[63] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x85, 0x01, // Report Id (1) //报告类型为1
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x95, 0x05, // REPORT_COUNT (5)
0x75, 0x01, // REPORT_SIZE (1)
0x05, 0x08, // USAGE_PAGE (LEDs)
0x19, 0x01, // USAGE_MINIMUM (Num Lock)
0x29, 0x05, // USAGE_MAXIMUM (Kana)
0x91, 0x02, // OUTPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x03, // REPORT_SIZE (3)
0x91, 0x03, // OUTPUT (Cnst,Var,Abs)
0x95, 0x06, // REPORT_COUNT (6)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0xFF, // LOGICAL_MAXIMUM (255)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0, // END_COLLECTION
//};
//const uint8 Mouse_ReportDescritptor[54] =
//{
//通用桌面设备
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
//鼠标
0x09, 0x02, // USAGE (Mouse)
//集合
0xa1, 0x01, // COLLECTION (Application)
//指针设备
0x09, 0x01, // USAGE (Pointer)
//集合
0xa1, 0x00, // COLLECTION (Physical)
//按键
0x05, 0x09, // USAGE_PAGE (Button)
//使用最小值1
0x19, 0x01, // USAGE_MINIMUM (Button 1)
//使用最大值3。1表示左键,2表示右键,3表示中键
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
//逻辑最小值0
0x15, 0x00, // LOGICAL_MINIMUM (0)
//逻辑最大值1
0x25, 0x01, // LOGICAL_MAXIMUM (1)
//数量为3
0x85, 0x02, /* Report Id (2) */
0x95, 0x03, // REPORT_COUNT (3)
//大小为1bit
0x75, 0x01, // REPORT_SIZE (1)
//输入,变量,数值,绝对值
//以上3个bit分别表示鼠标的三个按键情况,最低位(bit-0)为左键
//bit-1为右键,bit-2为中键,按下时对应的位值为1,释放时对应的值为0
0x81, 0x02, // INPUT (Data,Var,Abs)
//填充5个bit,补足一个字节
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x05, // REPORT_SIZE (5)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
//用途页为通用桌面
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
//用途为X
0x09, 0x30, // USAGE (X)
//用途为Y
0x09, 0x31, // USAGE (Y)
//用途为滚轮
0x09, 0x38, // USAGE (Wheel)
//逻辑最小值为-127
0x15, 0x81, // LOGICAL_MINIMUM (-127)
//逻辑最大值为+127
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
//大小为8个bits
0x75, 0x08, // REPORT_SIZE (8)
//数量为3个,即分别代表x,y,滚轮
0x95, 0x03, // REPORT_COUNT (3)
//输入,变量,值,相对值
0x81, 0x06, // INPUT (Data,Var,Rel)
//关集合
0xc0, // END_COLLECTION
0xc0 // END_COLLECTION
};
//*************************************************************************************************
//字符串定义
//*************************************************************************************************
//字符串描述符所用的语言种类
const uint8 LANGUAGE_ID[4]={0x04,0x03,0x09,0x04};
//设备序列号
const uint8 device_serial_number[]=
{22,0x03,'2',0,'0',0,'0',0,'7',0,'-',0,'0',0,'3',0,'-',0,'2',0,'3',0};
//厂商字符串
const uint8 ManufacturerString[80]=
{80,0x03,0x35,0x75,0x11,0x81,0x08,0x57,0x08,0x57,0x84,0x76,0xB6,0x5B,
0x53,0x5F,'-',0x00,'-',0x00,'-',0x00,'-',0x00,'@',0,0x20,0x00,'H',0,'t',0,'t',0,
'p',0,':',0,'/',0,'/',0,'C',0,'o',0,'m',0,'p',0,'u',0,'t',0,'e',0,'r',0,'0',0,
'0',0,'.',0,'2',0,'1',0,'i',0,'c',0,'.',0,'o',0,'r',0,'g',0};
//产品字符串
const uint8 ProducterString[80]=
{80,0x03,0x35,0x75,0x11,0x81,0x08,0x57,0x08,0x57,0x5A,0x50,0x84,0x76,
'U',0,'S',0,'B',0,0x2E,0x95,0xD8,0x76,'@',0,0x20,0x00,'H',0,'t',0,'t',0,
'p',0,':',0,'/',0,'/',0,'C',0,'o',0,'m',0,'p',0,'u',0,'t',0,'e',0,'r',0,'0',0,
'0',0,'.',0,'2',0,'1',0,'i',0,'c',0,'.',0,'o',0,'r',0,'g',0};
//*************************************************************************************************
//描述符结构体整理
//******************
//设备描述符
//******************
const uint8 Device_Descriptor[18]=
{
0x12, //设备描述符长度
0x01, //设备描述符类型
0x10,0x01, //协议版本
0x00, //设备类型
0x00, //设备子类
0x00, //设备协议
0x10, //端点0最大数据包大小
0xff,0xff, //NXP公司的设备ID
0x02,0x00, //设备制造商定的产品ID
0x01,0x00, //设备系列号
0x01, //厂商描述符字符串索引
0x02, //产品描述符字符串索引
0x03, //设备序列号字符串索引
0x01 //可能配置数
};
//****************
//配置描述符
//****************
const uint8 Configuration_Descriptor[41]=
{
0x09, //配置描述符长度
0x02, //配置描述符类型
0x29,0x00, //描述符总长度
1, //只支持一个接口
1, //配置值
0, //字符串描述符指针(无)
0xA0, //总线供电,支持远程唤醒
0xC8, //最大功耗(400ma)
//};
//****************
//接口描述符
//****************
//const uint8 Interface_Descriptor[9]=
//{
0x09, //接口描述符长度
0x04, //接口置描述符类型
0x00, //接口数
0x00, //可选配置
0x02, //除端点0外的端点索引数目
0x03, //设备类型
0x00, //子类代码
0x00, //协议代码 //none
0, //字符串描述符索引
//};
//****************
//HID描述符
//****************
//const uint8 HID_Descriptor[]=
//{
0x09,
0x21,
0x10,0x01,
0x21,
1,
0x22,
0x77,0,//sizeof(KeyBoardReportDescriptor), //鼠标报告描述符的长度
//};
//****************
//端点描述符
//****************
/*
//端点1输入
//const uint8 Endponit1_IN_Descriptor[7]=
//{
0x07, //端点描述符长度
0x05, //端点描述符类型
0x81, //端点1IN
0x03, //中断传输
0x00,0x10, //端点最大包的大小
10, //传输间隔时间
//};
//端点1输出
//const uint8 Endponit1_OUT_Descriptor[7]=
//{
0x07, //端点描述符长度
0x05, //端点描述符类型
0x01, //端点1OUT
0x03, //中断传输
0x00,0x10, //端点最大包的大小
10, //传输间隔时间
//};
*/
//端点2输入
//const uint8 Endponit2_IN_Descriptor[7]=
//{
0x07, //端点描述符长度
0x05, //端点描述符类型
0x82, //端点2IN
0x03, //中断传输
0x40,0x00, //端点最大包的大小
0x0a, //传输间隔时间
//};
//端点2输出
//const uint8 Endponit2_OUT_Descriptor[7]=
//{
0x07, //端点描述符长度
0x05, //端点描述符类型
0x02, //端点2OUT
0x03, //中断传输
0x40,0x00, //端点最大包的大小
0x0a //传输间隔时间
};
//*************************************************************************************************
//硬件层(0)
//*************************************************************************************************
//**********
//初始化命令
//**********
//设置地址使能
void D12_set_addr_en(uint8 bAddr,uint8 bEnable)
{
D12_CMD = 0xd0;
if(bEnable>0)
bAddr |= 0x80;
D12_DAT = bAddr;
}
//设置端点使能
void D12_set_endpoint_en(uint8 bEnable)
{
D12_CMD = 0xd8;
if(bEnable>0) //原因在这!!!!终于把你找出来了!!!唉,真不知道当初怎么把这写错了!!
D12_DAT = 0x01;
else
D12_DAT = 0x00;
}
//设置模式
void D12_set_mode(uint8 bConfig,uint8 bClkDiv)
{
D12_CMD = 0xf3;
D12_DAT = bConfig;
D12_DAT = bClkDiv;
}
//设置DMA
void D12_set_DMA(uint8 bMode)
{
D12_CMD = 0xfb;
D12_DAT = bMode;
}
//**********
//数据流命令
//**********
//读中断寄存器
uint16 D12_read_interrupt_reg(void)
{
uint16 i,j;
D12_CMD = 0xf4;
i = D12_DAT;
j = D12_DAT;
i+= (j<<8);
return i;
}
//选择端点
uint8 D12_Endpoint_select(uint8 bEndpoint)
{
D12_CMD = 0x00 + bEndpoint;
return D12_DAT;
}
//读端点状态
uint8 D12_read_Endpoint_status(uint8 bEndpoint)
{
D12_CMD = 0x80 + bEndpoint;
return D12_DAT;
}
//设最后状态处理寄存器
uint8 D12_read_last_status_reg(uint8 bEndpoint)
{
D12_CMD = 0x40 + bEndpoint;
return D12_DAT;
}
//设置端点状态
void D12_set_Endpoint_status(uint8 bEndpoint,uint8 bStatus)
{
D12_CMD = 0x40 + bEndpoint;
D12_DAT = bStatus;
}
//清空缓冲区
void D12_clear_buff(void)
{
D12_CMD = 0xf2;
}
/*
//应答SETUP
void D12_ack_SETUP(void)
{
D12_CMD = 0xf1;
}
//使缓冲区有效
void D12_enable_buff(void)
{
D12_CMD = 0xfa;
}
*/
//读缓冲区
uint16 D12_read_buff(uint8 *buff,uint16 bLenth)
{
uint16 i,j;
D12_CMD = 0xf0;
j = D12_DAT;
j = D12_DAT;
if(j>bLenth)
j = bLenth;
for(i=0; i<j; i++)
{
*(buff+i) = D12_DAT;
}
D12_CMD = 0xf2;//清空缓冲区
return j;
}
//写缓冲区
uint16 D12_write_buff(const uint8 *buff,uint16 bLenth)
{
uint16 i;
//if(bLenth >128)
// bLenth = 128;
D12_CMD = 0xf0;
D12_DAT = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -