我正在尝试在 STM32 板上制作 HID。但是我遇到了下一个问题:我不明白我的错误在哪里,我传递了一个指向包含报告函数数据的结构的指针,但是当我尝试编译代码时,我得到下一条消息:“keyboardHID *”类型的参数不兼容使用“uint8_t *”类型的参数,我以与此视频中的人相同的方式编写代码https://www.youtube.com/watch?v=tj1_hsQ5PR0。在他的情况下,这不是一个严重错误并且代码可以编译。
我的结构:
typedef struct
{
uint8_t MODIFIER;
uint8_t RESERVED;
uint8_t KEYCODE1;
uint8_t KEYCODE2;
uint8_t KEYCODE3;
uint8_t KEYCODE4;
uint8_t KEYCODE5;
uint8_t KEYCODE6;
} keyboardHID;
keyboardHID keyboardhid = {0,0,0,0,0,0,0,0}; // it should be like this, not differently
修改结构元素并向计算机发送报告的代码:
keyboardhid.MODIFIER = 0x02; // left Shift
keyboardhid.KEYCODE1 = 0x04; // press 'a'
keyboardhid.KEYCODE2 = 0x05; // press 'b'
USBD_HID_SendReport(&hUsbDeviceFS, &keyboardhid, sizeof (keyboardhid));
HAL_Delay (50);
keyboardhid.MODIFIER = 0x00; // shift release
keyboardhid.KEYCODE1 = 0x00; // release key
keyboardhid.KEYCODE2 = 0x00; // release key
USBD_HID_SendReport(&hUsbDeviceFS, &keyboardhid, sizeof (keyboardhid));
HAL_Delay (1000);