前面的cubelmx项目配置参考
stm32实现hid鼠标-CSDN博客https://blog.csdn.net/anlog/article/details/137814494?spm=1001.2014.3001.5502两个项目的配置完全相同。
代码
引用
键盘代码:
替换hid设备描述符
先屏蔽鼠标设备描述符
替换为键盘设备描述符
修改宏定义
修改大小为63U
运行后如下图
参考链接
参考宝藏ub主
3分钟,教会你做键盘。使用STM32 USB的HID 方式制作一个键盘_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV1dA4m1c7VE/?spm_id_from=333.999.0.0&vd_source=e821a225c7ba4a7b85e5aa6d013ac92e
HID键盘设备 - 哔哩哔哩 (bilibili.com)https://www.bilibili.com/read/cv33532705/?spm_id_from=333.999.0.0
/** buffer[0] - bit0: Left CTRL* -bit1: Left SHIFT* -bit2: Left ALT* -bit3: Left GUI(win)* -bit4: Right CTRL* -bit5: Right SHIFT* -bit6: Right ALT* -bit7: Right GUI ()* buffer[1] - Padding = Always 0x00* buffer[2] - Key 1* buffer[3] - Key 2* buffer[4] - Key 3* buffer[5] - Key 4* buffer[6] - Key 5* buffer[7] - Key 6*//*修改usbd_hid.c中的报告设备描述符*/__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END ={0x05, 0x01, // USAGE_PAGE (Generic Desktop) //630x09, 0x06, // USAGE (Keyboard)0xa1, 0x01, // COLLECTION (Application)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, 0x65, // LOGICAL_MAXIMUM (101)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};#include “usbd_hid.h” 文件中的申明文件,修改一下。#define HID_MOUSE_REPORT_DESC_SIZE 63U
HID Usages and Descriptions (gitee.com)https://gitee.com/siyu233/Stm32Code_1/raw/master/USB_HID_keyboard/hut1_HID_22.pdf
学习过程
特此记录
anlog
2024年4月16日