stmhal: Implement ioctl for USB HID read.

This commit is contained in:
Pavol Rusnak 2016-12-28 18:56:03 +01:00 committed by Damien George
parent 89f2b62016
commit 6ace84b089
3 changed files with 9 additions and 0 deletions

View File

@ -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;
}

View File

@ -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) {

View File

@ -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);