Browse Source

stmhal/usb: Make state for USB device private to top-level USB driver.

pull/3062/merge
Damien George 8 years ago
parent
commit
f86c57fedf
  1. 4
      stmhal/usb.c
  2. 1
      stmhal/usb.h
  3. 4
      stmhal/usbd_hid_interface.c
  4. 2
      stmhal/usbd_hid_interface.h

4
stmhal/usb.c

@ -54,7 +54,7 @@
mp_uint_t pyb_usb_flags = 0;
#ifdef USE_DEVICE_MODE
USBD_HandleTypeDef hUSBDDevice;
STATIC USBD_HandleTypeDef hUSBDDevice;
pyb_usb_storage_medium_t pyb_usb_storage_medium = PYB_USB_STORAGE_MEDIUM_NONE;
#endif
@ -568,7 +568,7 @@ STATIC mp_obj_t pyb_usb_hid_recv(mp_uint_t n_args, const mp_obj_t *args, mp_map_
mp_obj_t o_ret = pyb_buf_get_for_recv(vals[0].u_obj, &vstr);
// receive the data
int ret = USBD_HID_Rx((uint8_t*)vstr.buf, vstr.len, vals[1].u_int);
int ret = USBD_HID_Rx(&hUSBDDevice, (uint8_t*)vstr.buf, vstr.len, vals[1].u_int);
// return the received data
if (o_ret != MP_OBJ_NULL) {

1
stmhal/usb.h

@ -47,7 +47,6 @@ typedef enum {
} USB_PHY_ID;
extern mp_uint_t pyb_usb_flags;
extern struct _USBD_HandleTypeDef hUSBDDevice;
extern pyb_usb_storage_medium_t pyb_usb_storage_medium;
extern const struct _mp_obj_tuple_t pyb_usb_hid_mouse_obj;
extern const struct _mp_obj_tuple_t pyb_usb_hid_keyboard_obj;

4
stmhal/usbd_hid_interface.c

@ -101,7 +101,7 @@ int USBD_HID_RxNum(void) {
// timout in milliseconds.
// 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(USBD_HandleTypeDef *pdev, uint8_t *buf, uint32_t len, uint32_t timeout) {
// Wait until we have buffer to read
uint32_t start = HAL_GetTick();
while (current_read_buffer == current_write_buffer) {
@ -127,7 +127,7 @@ int USBD_HID_Rx(uint8_t *buf, uint32_t len, uint32_t timeout) {
current_read_buffer = !current_read_buffer;
// Clear NAK to indicate we are ready to read more data
USBD_HID_ClearNAK(&hUSBDDevice);
USBD_HID_ClearNAK(pdev);
// Success, return number of bytes read
return last_read_len;

2
stmhal/usbd_hid_interface.h

@ -7,4 +7,4 @@
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(USBD_HandleTypeDef *pdev, uint8_t *buf, uint32_t len, uint32_t timeout);

Loading…
Cancel
Save