summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-06-07 16:00:18 +1000
committerDamien George <damien.p.george@gmail.com>2017-06-07 16:03:45 +1000
commitf86c57fedffcabbec94d4b56bb45cc627f48ab55 (patch)
tree6781b9af8082ca5f1d6402b0956dbbc6df24bef7
parent3bb69f645a29429be63756616d3019e889c1d355 (diff)
downloadmicropython-f86c57fedffcabbec94d4b56bb45cc627f48ab55.tar.gz
micropython-f86c57fedffcabbec94d4b56bb45cc627f48ab55.zip
stmhal/usb: Make state for USB device private to top-level USB driver.
-rw-r--r--stmhal/usb.c4
-rw-r--r--stmhal/usb.h1
-rw-r--r--stmhal/usbd_hid_interface.c4
-rw-r--r--stmhal/usbd_hid_interface.h2
4 files changed, 5 insertions, 6 deletions
diff --git a/stmhal/usb.c b/stmhal/usb.c
index 9428cf7db9..f70dea1428 100644
--- a/stmhal/usb.c
+++ b/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) {
diff --git a/stmhal/usb.h b/stmhal/usb.h
index bc2b91c3db..42e6c76f81 100644
--- a/stmhal/usb.h
+++ b/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;
diff --git a/stmhal/usbd_hid_interface.c b/stmhal/usbd_hid_interface.c
index 9eee451f3c..11b3a3acdc 100644
--- a/stmhal/usbd_hid_interface.c
+++ b/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;
diff --git a/stmhal/usbd_hid_interface.h b/stmhal/usbd_hid_interface.h
index 959c46ff8a..fbc874796e 100644
--- a/stmhal/usbd_hid_interface.h
+++ b/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);