C8051F320 上的 HID 输入报告队列

发布于 2024-08-17 04:46:11 字数 764 浏览 6 评论 0原文

看起来,一旦主机准备好数据(例如,当我使用 WriteFile 向 HID 发送命令时,我告诉 HID 返回一些数据,例如端口值)并且数据包中的就绪位是设置后,主机会在调用 ReadFile 之前读取它(由另一个 USB 中断确认)。随后使用 ReadFile 将这些数据放入主机上的缓冲区中。这是事情应该发生的方式吗?我预计 ReadFile 调用会导致 in 中断。

所以这是我的问题:我有一个可以很好地协同工作的 GUI 和 HID。 HID 可以与另一个 IC 进行 I2C,GUI 可以告诉 HID 进行 I2C 就好了。启动后,GUI 会从 HID 读取数据并获取正确的值(例如 0x49)。打开同一 HID 的第二个 GUI 会从 HID 读取相同的初始数据并获取正确的值(例如 0x49;它应该与第一个 GUI 的读取相同)。现在,如果我转到第一个 GUI,并执行 I2C 读取,则读回值为 0x49,这是第二个 GUI 从 HID 请求的值。看来 HID 将此值放在连接到它的所有设备的端点上。因此,第一个 GUI 错误地认为这是正确的值。

根据 Jan Axelson 的 HID 常见问题解答,“HID 的每个打开句柄都有自己的报告队列。设备发送的每个报告都会进入所有队列,以便多个应用程序可以读取相同的报告。”我相信这是我的问题。如何在第一个 GUI 发出请求之前清除此值并清除端点,以便正确的值(HID 向调试器发送的值)通过?我尝试了 HidD_FlushQueue,但它一直返回 False(不起作用;不断收到“句柄无效”错误,尽管使用相同句柄的每次 WriteFile/ReadFile 成功该句柄都是有效的)。有什么想法吗?

谢谢!

it seems that as soon as data is ready for the host (such as when I use WriteFile to send a command to the HID in which I tell the HID to give back some data such as the port value) and the in packet ready bit is set, the host reads it (as confirmed by another USB interrupt) before ReadFile ever is called. ReadFile is later used to put this data into a buffer on the host. Is this the way it should happen? I would have expected the ReadFile call to cause the in interrupt.

So here is my problem: I have a GUI and HID that work well together. The HID can do I2C to another IC, and the GUI can tell the HID to do I2C just fine. Upon startup, the GUI reads data from the HID and gets a correct value (say, 0x49). Opening a second GUI to the same HID does the same initial data read from the HID and gets the correct value (say, 0x49; it should be the same as the first GUI's read). Now, if I go to the first GUI, and do an I2C read, the readback value is 0x49, which was the value that the 2nd GUI had requested from the HID. It seems that the HID puts this value on the in endpoint for all devices attached to it. Thus the 1st GUI incorrectly thinks that this is the correct value.

Per Jan Axelson's HID FAQ, "every open handle to the HID has its own report queue. Every report a device sends goes into all of the queues so multiple applications can read the same report." I believe this is my problem. How do I purge this and clear the endpoint before the 1st GUI does its request so that the correct value (which the HID does send per the debugger) gets through? I tried HidD_FlushQueue, but it keeps returning False (not working; keep getting "handle is invalid" errors, although the handle is valid per WriteFile/ReadFile success with the same handles). Any ideas?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天旳寂寞 2024-08-24 04:46:11

您可能不喜欢这个建议,但一种选择是一次只允许一个 GUI 有一个打开的句柄。使用您最喜欢的资源分配锁定机制,让 GUI 在打开句柄并使用它之前请求 HID 资源。

You might not like this suggestion, but one option would be to only allow one GUI at a time to have an open handle. Use your favorite resource allocation lock mechanism and make the GUIs ask for the HID resource before opening the handle and using it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文