diff options
| author | Damien George | 2014-03-30 00:00:15 +0000 |
|---|---|---|
| committer | Damien George | 2014-03-30 00:00:15 +0000 |
| commit | 038df4318362325b5b6b77f7582fb6373a240f3c (patch) | |
| tree | 412143786f23fc67681f44f0673ee72f2a6a7f0d /stmhal/usb.c | |
| parent | d40d8f1e168c5bc3cf52f51d9592425574e7e6a9 (diff) | |
stmhal: Implement selector for USB device mode; improve boot up.
Can now choose at boot up whether the USB device is CDC+MSC or CDC+HID.
Choice is made by an option in boot.py, with default being CDC+MSC.
HID+MSC is not currently supported, but should be easy to implement.
Boot up now has ability to change the reset mode: hold down USR switch
while booting and LEDs will count from 1 to 7 to indicate the boot mode.
Release USR when correct mode is selected. Current modes are 1 (normal
boot), 2 (safe mode), 3 (reset FS mode).
Diffstat (limited to 'stmhal/usb.c')
| -rw-r--r-- | stmhal/usb.c | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/stmhal/usb.c b/stmhal/usb.c index 79f9b85f3..3d795f182 100644 --- a/stmhal/usb.c +++ b/stmhal/usb.c @@ -2,7 +2,7 @@ #include "usbd_core.h" #include "usbd_desc.h" -#include "usbd_cdc_msc.h" +#include "usbd_cdc_msc_hid.h" #include "usbd_cdc_interface.h" #include "usbd_msc_storage.h" @@ -19,28 +19,24 @@ USBD_HandleTypeDef hUSBDDevice; static int dev_is_enabled = 0; mp_obj_t mp_const_vcp_interrupt = MP_OBJ_NULL; -void pyb_usb_dev_init(usbd_device_kind_t device_kind, usbd_storage_medium_kind_t medium_kind) { +void pyb_usb_dev_init(usb_device_mode_t mode, usb_storage_medium_t medium) { #ifdef USE_DEVICE_MODE if (!dev_is_enabled) { // only init USB once in the device's power-lifetime - switch (device_kind) { - case USBD_DEVICE_CDC_MSC: - USBD_Init(&hUSBDDevice, &VCP_Desc, 0); - USBD_RegisterClass(&hUSBDDevice, &USBD_CDC_MSC); - USBD_CDC_RegisterInterface(&hUSBDDevice, (USBD_CDC_ItfTypeDef*)&USBD_CDC_fops); - if (medium_kind == USBD_STORAGE_MEDIUM_FLASH) { - USBD_MSC_RegisterStorage(&hUSBDDevice, (USBD_StorageTypeDef*)&USBD_FLASH_STORAGE_fops); - } else { - USBD_MSC_RegisterStorage(&hUSBDDevice, (USBD_StorageTypeDef*)&USBD_SDCARD_STORAGE_fops); - } - USBD_Start(&hUSBDDevice); - break; - - case USBD_DEVICE_HID: - //USBD_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_PYB_HID_cb, &USR_cb); - // TODO - break; + if (mode == USB_DEVICE_MODE_CDC_MSC) { + USBD_SelectMode(USBD_MODE_CDC_MSC); + } else { + USBD_SelectMode(USBD_MODE_CDC_HID); } + USBD_Init(&hUSBDDevice, &VCP_Desc, 0); + USBD_RegisterClass(&hUSBDDevice, &USBD_CDC_MSC_HID); + USBD_CDC_RegisterInterface(&hUSBDDevice, (USBD_CDC_ItfTypeDef*)&USBD_CDC_fops); + if (medium == USB_STORAGE_MEDIUM_FLASH) { + USBD_MSC_RegisterStorage(&hUSBDDevice, (USBD_StorageTypeDef*)&USBD_FLASH_STORAGE_fops); + } else { + USBD_MSC_RegisterStorage(&hUSBDDevice, (USBD_StorageTypeDef*)&USBD_SDCARD_STORAGE_fops); + } + USBD_Start(&hUSBDDevice); } dev_is_enabled = 1; |
