📄 ds_ms_kb.h
字号:
//*****************************************************************************************// Constant specific to USB Slave Descriptors//*****************************************************************************************#define DEV_LEN 0x12 // Device Descriptor Length#define HID_LEN 0x09 // HID-Class Descriptor Length#define CFG_LEN 0x3b // Configuration Descriptor Length#define REP_LEN 0x34 // HID Report Descriptor Length
#define REP_LEN1 0x3f // HID Report Descriptor Length
#define EP0_LEN 0x10#include "std_defs.h"#include "chap_9.h"
#define code
//---------------------------------------------------------------------------------------------------------------------// DEVICE DESCRIPTOR//---------------------------------------------------------------------------------------------------------------------code BYTE Dev_Descp[] = { DEV_LEN, // bLength: Size of descriptor 0x01, // bDescriptorType: Device 0x10,0x01, // bcdUSB: USB 1.1 0x00, // bDeviceClass: none 0x00, // bDeviceSubClass: none 0x00, // bDeviceProtocol: none EP0_LEN, // bMaxPacketSize0: 16 bytes 0x88,0x88, // idVendor 0x02,0x00, // idProduct 0x00,0x01, // bcdDevice: version 1.0 STR_INDEX_MANUFACTURER, // iManufacturer STR_INDEX_PRODUCT, // iProduct 0x00, // iSerialNumber: none 0x01}; // bNumConfigurations: 1//---------------------------------------------------------------------------------------------------------------------// CONFIGURATION DESCRIPTOR//---------------------------------------------------------------------------------------------------------------------code BYTE Cfg_Descp[] = { 0x09, // bLength: Size of descriptor 0x02, // bDescriptorType: Configuration CFG_LEN,0x00, // wTotalLength: Cfg+Ifc+Class+Ep = 34 bytes 0x02, // bNumInterfaces: 1 interface 0x01, // bConfigurationValue: 1 0x00, // iConfiguration: none 0xA0, // bmAttributes: bus-powered, remote-wakeup 0x32, // MaxPower: 100mA//---------------------------------------------------------------------------------------------------------------------// INTERFACE DESCRIPTOR//--------------------------------------------------------------------------------------------------------------------- 0x09, // bLength: Size of descriptor 0x04, // bDescriptorType: Interface 0x00, // bInterfaceNumber: #0 0x00, // bAlternateSetting: #0 0x01, // bNumEndpoints: 1 0x03, // bInterfaceClass: HID-class 0x01, // bInterfaceSubClass 0x02, // bInterfaceProtocol: Mouse 0x00, // iInterface: none//---------------------------------------------------------------------------------------------------------------------// HID-CLASS DESCRIPTOR//--------------------------------------------------------------------------------------------------------------------- 0x09, // bLength: Size of descriptor 0x21, // bDescriptorType: HID Class 0x01,0x01, // bcdHID: HID Class version 1.1 0x00, // bCountryCode: none 0x01, // bNumDescriptors: 1 report descp 0x22, // bDescriptorType: report descriptor type REP_LEN,0x00, // wDescriptorLength//---------------------------------------------------------------------------------------------------------------------// ENDPOINT DESCRIPTOR//--------------------------------------------------------------------------------------------------------------------- 0x07, // bLength: Size of descriptor 0x05, // bDescriptorType: Endpoint 0x81, // bEndpointAddress: IN, EP1 0x03, // bmAttributes: Interrupt 0x10,0x00, // wMaxPacketSize: EP1_LEN -> 0x10 0x0A, // bInterval: 10ms//---------------------------------------------------------------------------------------------------------------------
// INTERFACE DESCRIPTOR
//---------------------------------------------------------------------------------------------------------------------
0x09, // bLength: Size of descriptor
0x04, // bDescriptorType: Interface
0x01, // bInterfaceNumber: #0
0x00, // bAlternateSetting: #0
0x01, // bNumEndpoints: 1
0x03, // bInterfaceClass: HID-class
0x01, // bInterfaceSubClass
0x01, // bInterfaceProtocol: Keyboard
0x00, // iInterface: none
//---------------------------------------------------------------------------------------------------------------------
// HID-CLASS DESCRIPTOR
//---------------------------------------------------------------------------------------------------------------------
0x09, // bLength: Size of descriptor
0x21, // bDescriptorType: HID Class
0x01,0x01, // bcdHID: HID Class version 1.1
0x00, // bCountryCode: none
0x01, // bNumDescriptors: 1 report descp
0x22, // bDescriptorType: report descriptor type
REP_LEN1,0x00, // wDescriptorLength
//---------------------------------------------------------------------------------------------------------------------
// ENDPOINT DESCRIPTOR
//---------------------------------------------------------------------------------------------------------------------
0x07, // bLength: Size of descriptor
0x05, // bDescriptorType: Endpoint
0x82, // bEndpointAddress: IN, EP2
0x03, // bmAttributes: Interrupt
0x10,0x00, // wMaxPacketSize: EP1_LEN -> 0x10
0x0A}; // bInterval: 10ms
//---------------------------------------------------------------------------------------------------------------------// REPORT DESCRIPTORcode BYTE Rep_Descp[] = { 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 (Buttons), 0x19, 0x01, // Usage Minimum (01), 0x29, 0x03, // Usage Maximun (03), 0x15, 0x00, // Logical Minimum (0), 0x25, 0x01, // Logical Maximum (1), 0x95, 0x03, // Report Count (3), 0x75, 0x01, // Report Size (1), 0x81, 0x02, // Input (Data, Variable, Absolute), ;3 button bits 0x95, 0x01, // Report Count (1), 0x75, 0x05, // Report Size (5), 0x81, 0x01, // Input (Constant), ;5 bit padding 0x05, 0x01, // Usage Page (Generic Desktop), 0x09, 0x30, // Usage (X), 0x09, 0x31, // Usage (Y), 0x09, 0x38, // Usage (Wheel), 0x15, 0x81, // Logical Minimum (-127), 0x25, 0x7F, // Logical Maximum (127), 0x75, 0x08, // Report Size (8), 0x95, 0x03, // Report Count (3), 0x81, 0x06, // Input (Data, Variable, Relative), ;2 position bytes (X & Y) 0xC0, // End Collection, 0xC0}; // End Collection code BYTE Rep_Descp1[] = {0x05, 0x01, // Usage Page (Generic Desktop),
0x09, 0x06, // Usage (Keyboard),
0xA1, 0x01, // Collection (Application),
0x05, 0x07, // Usage Page (Key Codes);
0x19, 0xE0, // Usage Minimum (224),
0x29, 0xE7, // Usage Maximum (231),
0x15, 0x00, // Logical Minimum (0),
0x25, 0x01, // Logical Maximum (1),
0x75, 0x01, // Report Size (1),
0x95, 0x08, // Report Count (8),
0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte
0x95, 0x01, // Report Count (1),
0x75, 0x08, // Report Size (8),
0x81, 0x01, // Input (Constant), ;Reserved byte
0x95, 0x05, // Report Count (5),
0x75, 0x01, // Report Size (1),
0x05, 0x08, // Usage Page (Page# for LEDs),
0x19, 0x01, // Usage Minimum (1),
0x29, 0x05, // Usage Maximum (5),
0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
0x95, 0x01, // Report Count (1),
0x75, 0x03, // Report Size (3),
0x91, 0x01, // Output (Constant), ;LED report padding
0x95, 0x06, // Report Count (6),
0x75, 0x08, // Report Size (8),
0x15, 0x00, // Logical Minimum (0),
0x25, 0x65, // Logical Maximum(101),
0x05, 0x07, // Usage Page (Key Codes),
0x19, 0x00, // Usage Minimum (0),
0x29, 0x65, // Usage Maximum (101),
0x81, 0x00, // Input (Data, Array), ;Key arrays (6 bytes)
0xC0}; // End Collection
//---------------------------------------------------------------------------------------------------------------------// STRING DESCRIPTOR//---------------------------------------------------------------------------------------------------------------------code BYTE LangString[] = {4,3,9,4};code BYTE MfgString[] = {12,3,'C',0,'h',0,'i',0,'n',0,'a',0};code BYTE ProdString[] = {72,3,'N',0,'o',0,'S',0,'t',0,'o',0,'p',0,' ',0,'P', 0,'D',0,'I',0,'U',0,'S',0,'B',0,'D',0,'1',0,'2',0, ' ',0,'H',0,'I',0,'D',0,' ',0,'D',0,'e',0,'m',0, 'o',0,'-',0,'U',0,'S',0,'B',0,' ',0,'M',0,'o',0, 'u',0,'s',0,'e',0};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -