Commit 6ace84b0 authored by Pavol Rusnak's avatar Pavol Rusnak Committed by Damien George
Browse files

stmhal: Implement ioctl for USB HID read.

parent 89f2b620
......@@ -636,6 +636,9 @@ STATIC mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_
if (request == MP_STREAM_POLL) {
mp_uint_t flags = arg;
ret = 0;
if ((flags & MP_STREAM_POLL_RD) && USBD_HID_RxNum() > 0) {
ret |= MP_STREAM_POLL_RD;
}
if ((flags & MP_STREAM_POLL_WR) && USBD_HID_CanSendReport(&hUSBDDevice)) {
ret |= MP_STREAM_POLL_WR;
}
......
......@@ -93,6 +93,11 @@ static int8_t HID_Itf_Receive(uint8_t* Buf, uint32_t Len) {
return USBD_OK;
}
// Returns number of ready rx buffers.
int USBD_HID_RxNum(void) {
return (current_read_buffer != current_write_buffer);
}
// timout in milliseconds.
// Returns number of bytes read from the device.
int USBD_HID_Rx(uint8_t *buf, uint32_t len, uint32_t timeout) {
......
......@@ -6,4 +6,5 @@
extern const USBD_HID_ItfTypeDef USBD_HID_fops;
int USBD_HID_RxNum(void);
int USBD_HID_Rx(uint8_t *buf, uint32_t len, uint32_t timeout);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment