Skip to content

Commit 6ace84b

Browse files
prusnakdpgeorge
authored andcommitted
stmhal: Implement ioctl for USB HID read.
1 parent 89f2b62 commit 6ace84b

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

stmhal/usb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ STATIC mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_
636636
if (request == MP_STREAM_POLL) {
637637
mp_uint_t flags = arg;
638638
ret = 0;
639+
if ((flags & MP_STREAM_POLL_RD) && USBD_HID_RxNum() > 0) {
640+
ret |= MP_STREAM_POLL_RD;
641+
}
639642
if ((flags & MP_STREAM_POLL_WR) && USBD_HID_CanSendReport(&hUSBDDevice)) {
640643
ret |= MP_STREAM_POLL_WR;
641644
}

stmhal/usbd_hid_interface.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ static int8_t HID_Itf_Receive(uint8_t* Buf, uint32_t Len) {
9393
return USBD_OK;
9494
}
9595

96+
// Returns number of ready rx buffers.
97+
int USBD_HID_RxNum(void) {
98+
return (current_read_buffer != current_write_buffer);
99+
}
100+
96101
// timout in milliseconds.
97102
// Returns number of bytes read from the device.
98103
int USBD_HID_Rx(uint8_t *buf, uint32_t len, uint32_t timeout) {

stmhal/usbd_hid_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66

77
extern const USBD_HID_ItfTypeDef USBD_HID_fops;
88

9+
int USBD_HID_RxNum(void);
910
int USBD_HID_Rx(uint8_t *buf, uint32_t len, uint32_t timeout);

0 commit comments

Comments
 (0)