stmhal: Implement ioctl for USB HID read.
This commit is contained in:
parent
89f2b62016
commit
6ace84b089
@ -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) {
|
if (request == MP_STREAM_POLL) {
|
||||||
mp_uint_t flags = arg;
|
mp_uint_t flags = arg;
|
||||||
ret = 0;
|
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)) {
|
if ((flags & MP_STREAM_POLL_WR) && USBD_HID_CanSendReport(&hUSBDDevice)) {
|
||||||
ret |= MP_STREAM_POLL_WR;
|
ret |= MP_STREAM_POLL_WR;
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,11 @@ static int8_t HID_Itf_Receive(uint8_t* Buf, uint32_t Len) {
|
|||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns number of ready rx buffers.
|
||||||
|
int USBD_HID_RxNum(void) {
|
||||||
|
return (current_read_buffer != current_write_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
// timout in milliseconds.
|
// timout in milliseconds.
|
||||||
// Returns number of bytes read from the device.
|
// Returns number of bytes read from the device.
|
||||||
int USBD_HID_Rx(uint8_t *buf, uint32_t len, uint32_t timeout) {
|
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;
|
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);
|
int USBD_HID_Rx(uint8_t *buf, uint32_t len, uint32_t timeout);
|
||||||
|
Loading…
Reference in New Issue
Block a user