aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George2019-07-03 11:58:56 +1000
committerDamien George2019-07-03 11:58:56 +1000
commitf114ce0a4b43474a73e9e5ddddbcf9a36553f954 (patch)
tree18646394ea7f4f7c37e70f55fbc4c94e07b265af
parent46b3cc4572036c9e2185b4aa8fb77dff29967680 (diff)
stm32/usb: Add "port" keyword argument to pyb.usb_mode, to select FS/HS.
If the board supports it, the USB port can now be explicitly specified, eg: pyb.usb_mode('VCP', port=0). port=0 is USB FS and port=1 is USB HS.
-rw-r--r--ports/stm32/usb.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/ports/stm32/usb.c b/ports/stm32/usb.c
index 12e138818..51e6e7a39 100644
--- a/ports/stm32/usb.c
+++ b/ports/stm32/usb.c
@@ -255,9 +255,10 @@ usbd_cdc_itf_t *usb_vcp_get(int idx) {
*/
STATIC mp_obj_t pyb_usb_mode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
- enum { ARG_mode, ARG_vid, ARG_pid, ARG_msc, ARG_hid, ARG_high_speed };
+ enum { ARG_mode, ARG_port, ARG_vid, ARG_pid, ARG_msc, ARG_hid, ARG_high_speed };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
+ { MP_QSTR_port, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
{ MP_QSTR_vid, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = USBD_VID} },
{ MP_QSTR_pid, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
{ MP_QSTR_msc, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_empty_tuple_obj)} },
@@ -427,8 +428,14 @@ STATIC mp_obj_t pyb_usb_mode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
}
#endif
+ // Work out which port/peripheral to use, either user supplied or auto detect
+ int dev_id = args[ARG_port].u_int;
+ if (dev_id == -1) {
+ dev_id = pyb_usb_dev_detect();
+ }
+
// init the USB device
- if (!pyb_usb_dev_init(pyb_usb_dev_detect(), vid, pid, mode, msc_n, msc_unit, &hid_info)) {
+ if (!pyb_usb_dev_init(dev_id, vid, pid, mode, msc_n, msc_unit, &hid_info)) {
goto bad_mode;
}