From 4e4962d1f0ae7f252969b8c975b759add1ca6884 Mon Sep 17 00:00:00 2001 From: swym <0xfd000000@gmail.com> Date: Tue, 20 Aug 2019 08:42:47 +0200 Subject: [PATCH 1/2] feat(pycardium): Add ESB API --- pycardium/modules/os.c | 31 +++++++++++++++++++++++++++++++ pycardium/modules/qstrdefs.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/pycardium/modules/os.c b/pycardium/modules/os.c index bee4bad3..384a71e2 100644 --- a/pycardium/modules/os.c +++ b/pycardium/modules/os.c @@ -188,6 +188,32 @@ static mp_obj_t mp_os_urandom(mp_obj_t size_in) } static MP_DEFINE_CONST_FUN_OBJ_1(urandom_obj, mp_os_urandom); +enum usb_config_device { + USB_DEVICE_NONE, + USB_DEVICE_FLASH, + USB_DEVICE_SERIAL, +}; + +static mp_obj_t mp_os_usbconfig(mp_obj_t dev) +{ + int device = mp_obj_get_int(dev); + switch (device) { + case USB_DEVICE_NONE: + epic_usb_shutdown(); + break; + case USB_DEVICE_FLASH: + epic_usb_storage(); + break; + case USB_DEVICE_SERIAL: + epic_usb_cdcacm(); + break; + default: + mp_raise_ValueError("Invalid parameter"); + } + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_1(usbconfig_obj, mp_os_usbconfig); + static const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, { MP_ROM_QSTR(MP_QSTR_exit), MP_ROM_PTR(&exit_obj) }, @@ -199,6 +225,11 @@ static const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&rename_obj) }, { MP_ROM_QSTR(MP_QSTR_read_battery), MP_ROM_PTR(&read_battery_obj) }, { MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&urandom_obj) }, + { MP_ROM_QSTR(MP_QSTR_usbconfig), MP_ROM_PTR(&usbconfig_obj) }, + + { MP_ROM_QSTR(MP_QSTR_USB_SERIAL), MP_ROM_INT(USB_DEVICE_SERIAL) }, + { MP_ROM_QSTR(MP_QSTR_USB_FLASH), MP_ROM_INT(USB_DEVICE_FLASH) }, + { MP_ROM_QSTR(MP_QSTR_USB_NONE), MP_ROM_INT(USB_DEVICE_NONE) }, }; static MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); diff --git a/pycardium/modules/qstrdefs.h b/pycardium/modules/qstrdefs.h index 3e28a103..2e24b050 100644 --- a/pycardium/modules/qstrdefs.h +++ b/pycardium/modules/qstrdefs.h @@ -141,6 +141,10 @@ Q(mkdir) Q(rename) Q(read_battery) Q(urandom) +Q(usbconfig) +Q(USB_FLASH) +Q(USB_SERIAL) +Q(USB_NONE) /* gpio */ Q(gpio) -- GitLab From 23ab69df8da62586024490764d015ca21598f91b Mon Sep 17 00:00:00 2001 From: swym <0xfd000000@gmail.com> Date: Wed, 28 Aug 2019 00:26:21 +0200 Subject: [PATCH 2/2] docs(pycardium): Document os.usbconfig --- Documentation/pycardium/os.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Documentation/pycardium/os.rst b/Documentation/pycardium/os.rst index ce71c1b4..c14e8c92 100644 --- a/Documentation/pycardium/os.rst +++ b/Documentation/pycardium/os.rst @@ -72,3 +72,28 @@ Card10-Specific Please only call this function if absolutely necessary. In most cases you'll want to just :py:func:`os.exit` instead. + +.. py:function:: usbconfig(config_type) + + Change active USB configuration. By default, card10 boots with + :py:data:`os.USB_SERIAL` active. + + This will deactivate the currently active USB configuration. This means + that, if you activate :py:data:`os.USB_FLASH` while :py:data:`os.USB_SERIAL` + was active, the USB serial will be disconnected. + + :param config_type: Selects which config to activate. Possible + values are :py:data:`os.USB_SERIAL`, :py:data:`os.USB_FLASH`, + or :py:data:`os.USB_NONE`. + +.. py:data:: USB_NONE + + No USB device active. + +.. py:data:: USB_SERIAL + + CDC-ACM serial device active. + +.. py:data:: USB_FLASH + + Mass-Storage device active. -- GitLab