6683 views|5 replies

256

Posts

0

Resources
The OP
 

【Qinheng Trial】Implementation of USB HID [Copy link]

 This post was last edited by viphotman on 2019-7-24 13:57

Simulate the left and right mouse buttons by touching the buttons;

File structure:

mainly integrates the functions of gpio, touch and usb demos;

The GPIO part is for LED control;

TOUCH is used as a button;

USB uses HID to convert mouse left and right press and release;

Look at the USB descriptor;

The following figure is a structural diagram; it is a screenshot from the USB protocol

There are: setup descriptor, configuration descriptor; interface descriptor, endpoint descriptor, HID descriptor, HID report, string descriptor;

Mouse and keyboard class in interface description

Let's comment on the descriptor part below;

/*
// USB 描述符
// 1 设备描述符(=1)
// 2 配置描述符(=2)
// 3 字符串描述符(=3)
// 4 接口描述符(4)
// 5 端点描述符(5)
// 
// HID描述符(0x21)
*/

/*设备描述符*/
UINT8C DevDesc[] = { 
0x12, //长度
0x01, //类型:设备描述符(=1)
0x10, 0x01, // USB 协议版本 低8位在前
0x00,//类代码 
0x00,//子类代码
0x00,//设备使用的协议
THIS_ENDP0_SIZE, //端点0最大包长
0x86,0x1a,// 厂商  VID
0xe1,0xe6,// 产品 PID 
0x00,0x01,//设备版本号
0x01,//字符串索引 :描述厂商
0x02,//字符串索引 :描述产品
0x00,//字符串索引 :产品序列
0x01 //配置数
                   };
/*字符串描述符*/
UINT8C  MyLangDescr[] = { 0x04, 0x03, 0x09, 0x04 };                                    // 语言描述符
UINT8C  MyManuInfo[] = { 0x0E, 0x03, 'w', 0, 'c', 0, 'h', 0, '.', 0, 'c', 0, 'n', 0 }; // 厂家信息
UINT8C  MyProdInfo[] = { 0x0C, 0x03, 'C', 0, 'H', 0, '5', 0, '4', 0, '9', 0 };         // 产品信息
/*配置描述符*/
UINT8C CfgDesc[] =
{
    0x09,0x02,//此描述符长度 ,配置描述符
	0x3b,0x00,//配置描述符集合总长度 0x003b
	0x02,//支持接口数: 0,1 
	0x01,//该配置的值
	0x00,//该配置的字符串索引
	0xA0,//设备属性
	0x32,//最大要电电流 0x32 x 2mA = 100mA                    

    0x09,0x04,//此描述符长度 , 接口描述符,键盘
	0x00,//接口编号:0 
	0x00,//备用编号
	0x01,//此接口使用端点数
	0x03,//此接口使用的类 :HID
	0x01,//此接口使用的子类: 
	0x01,//此接口使用的协议:KEYBOARD
	0x00,// 此接口字符串索引
	
    0x09,0x21,//此描述符长度 ,HID类描述符
	0x11,0x01,// USB HID version 
	0x00,// 国家代码 00 是没定义,33是US
	0x01,//下级描述符的数量
	0x22,//下级描述符的类型  
	sizeof(KeyRepDesc)&0xFF,sizeof(KeyRepDesc)>>8, //下级描述符的长度
    
	0x07,0x05,//此描述符长度 ,端点描述符
	0x81,//端点地址
	0x03,//属性
	EP1_IN_SIZE,0x00,//端点支持最大的包长度
	0x0a,//端口查询时间

    0x09,0x04,//此描述符长度 ,接口描述符,鼠标
	0x01,//接口编号:1
	0x00,//备用编号
	0x01,//此接口使用端点数
	0x03,//此接口使用的类 HID
	0x01,//此接口使用的子类
	0x02,//此接口使用的协议: MOUSE
	0x00,//// 此接口字符串索引
	
    0x09,0x21,//此描述符长度 ,HID类描述符
	0x10,0x01,// USB HID version 
	0x00,// 国家代码
	0x01,//下级描述符的数量
	0x22,//下级描述符的类型 
	sizeof(MouseRepDesc)&0xFF,sizeof(MouseRepDesc)>>8,//下级描述符的长度
    
	0x07,0x05,//此描述符长度 ,端点描述符
	0x82,//端点地址
	0x03,//属性
	EP2_IN_SIZE,0x00,//端点支持最大的包长度
	0x0a //端口查询时间
};

Qinheng's MCU does not require much programming or modification.

Here are the project files:

myCH549HID.zip (276.97 KB, downloads: 45)

This content is originally created by viphotman
, a user of EEWORLD forum . If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source.

This post is from Domestic Chip Exchange

Latest reply

Can be used as a slider, with multiple touch buttons   Details Published on 2019-7-25 18:24
 
 

1w

Posts

25

Resources
2
 

It seems very simple to use.

This post is from Domestic Chip Exchange

Comments

It works well initially. The USB part has less code and is easier to understand than the 32-bit microcontroller code I saw before.  Details Published on 2019-7-24 14:08
 
 
 

256

Posts

0

Resources
3
 
dcexpert posted on 2019-7-24 14:00 It looks very simple to use

It works well initially. The USB part has less code and is easier to understand than the 32-bit microcontroller code I saw before.

This post is from Domestic Chip Exchange
 
 
 

305

Posts

0

Resources
4
 

One function debugged multiple function modules

This post is from Domestic Chip Exchange

Comments

Can your touch buttons be combined into gestures?  Details Published on 2019-7-25 11:56
Personal signature单价1元含税的USB和Touchkey单片机CH551G已大批量出货,试样QQ:1258305301
 
 
 

256

Posts

0

Resources
5
 
Qinheng USB microcontroller published on 2019-7-25 09:26 One function debugged multiple function modules

Can your touch buttons be combined into gestures?

This post is from Domestic Chip Exchange

Comments

Can be used as a slider, with multiple touch buttons  Details Published on 2019-7-25 18:24
 
 
 

305

Posts

0

Resources
6
 
viphotman posted on 2019-7-25 11:56 Can your touch buttons be combined into gestures!

Can be used as a slider, with multiple touch buttons

This post is from Domestic Chip Exchange
Personal signature单价1元含税的USB和Touchkey单片机CH551G已大批量出货,试样QQ:1258305301
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list