fa07deda9f
The previous version did not work on MCUs that only had USB device mode (compared to OTG) because of the handling of NAK. And this previous handling of NAK had a race condition where a new packet could come in before USBD_HID_SetNAK was called (since USBD_HID_ReceivePacket clears NAK as part of its operation). Furthermore, the double buffering of incoming reports was not working, only one buffer could be used at a time. This commit rewrites the HID interface code to have a single incoming buffer, and only calls USBD_HID_ReceivePacket after the user has read the incoming report (similar to how the VCP does its flow control). As such, USBD_HID_SetNAK and USBD_HID_ClearNAK are no longer needed. API functionality from the user's point of view should be unchanged with this commit.
26 lines
743 B
C
26 lines
743 B
C
/*
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
*/
|
|
#ifndef MICROPY_INCLUDED_STM32_USBD_HID_INTERFACE_H
|
|
#define MICROPY_INCLUDED_STM32_USBD_HID_INTERFACE_H
|
|
|
|
#include <stdint.h>
|
|
#include "usbd_cdc_msc_hid.h"
|
|
|
|
#define USBD_HID_REPORT_INVALID ((size_t)-1)
|
|
|
|
typedef struct _usbd_hid_itf_t {
|
|
usbd_hid_state_t base; // state for the base HID layer
|
|
|
|
volatile size_t report_in_len;
|
|
uint8_t report_in_buf[HID_DATA_FS_MAX_PACKET_SIZE];
|
|
} usbd_hid_itf_t;
|
|
|
|
static inline int usbd_hid_rx_num(usbd_hid_itf_t *hid) {
|
|
return hid->report_in_len != USBD_HID_REPORT_INVALID;
|
|
}
|
|
|
|
int usbd_hid_rx(usbd_hid_itf_t *hid, size_t len, uint8_t *buf, uint32_t timeout_ms);
|
|
|
|
#endif // MICROPY_INCLUDED_STM32_USBD_HID_INTERFACE_H
|