gpt4 book ai didi

无法弄清楚如何通过 USB 将数据从 stm32f103c8 发送到 PC

转载 作者:行者123 更新时间:2023-11-30 16:05:54 25 4
gpt4 key购买 nike

我最近重新开始玩微 Controller ,最后有点卡住了。所以我正在构建的是一个自定义游戏 handle 。我可以正确模拟按钮的数据,但当我引入帽子开关时,没有任何效果。我假设我发送了错误的数据包,但无法找出正确的结构。在测试代​​码中,我只是尝试发送一些“按钮按下”,并尝试按下帽子开关上的一个键,但看起来该电脑无法识别我的数据包。我确实经历了the hid documentation (尤其是第 64、65 页),但仍然不知道为什么这不起作用。

我的 HID 描述符:

0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
0x09, 0x05, // USAGE (Game Pad)
0xa1, 0x01, // COLLECTION (Application)
0xa1, 0x00, // COLLECTION (Physical)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x0e, // USAGE_MAXIMUM (Button 14)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x0e, // REPORT_COUNT (14)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x02, // REPORT_SIZE (2)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x39, // USAGE (Hat switch)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x03, // LOGICAL_MAXIMUM (3)
0x35, 0x00, // PHYSICAL_MINIMUM (0)
0x46, 0x0e, 0x01, // PHYSICAL_MAXIMUM (270)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x04, // REPORT_SIZE (4)
0x81, 0x42, // INPUT (Data,Var,Abs,Null)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x04, // REPORT_SIZE (4)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0xc0, // END_COLLECTION
0xc0 // END_COLLECTION

基本测试代码:

struct gamepad_report_t
{
uint16_t buttons;
uint8_t hs0 : 1;
uint8_t hs1 : 1;
uint8_t hs2 : 1;
uint8_t hs3 : 1;
};

struct gamepad_report_t gamepad_report;

gamepad_report.buttons = 0x0001;
gamepad_report.hs0 = 1;
gamepad_report.hs1 = 0;
gamepad_report.hs2 = 0;
gamepad_report.hs3 = 0;

int main()
{
while (1)
{
gamepad_report.buttons = 0x0010;
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_4);
USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, &gamepad_report, sizeof(struct gamepad_report_t));
HAL_Delay(500);
}
}

Data packet structure I have imaganed

What I see in the device properties when the uC is connected

最佳答案

我在这里遇到的问题是我想发送到 PC 的结构变量。如果我发送一个数组,一切都会按预期工作...所以结论是 sizeof(struct) 没有返回正确的值,我应该通读 data structure alignment ...通常很简单的问题会让人发疯。

关于无法弄清楚如何通过 USB 将数据从 stm32f103c8 发送到 PC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60132199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com