Skip to content
Snippets Groups Projects
Commit 5773e2e1 authored by rahix's avatar rahix
Browse files

Merge 'Python API for ESB'

See merge request !126
parents 1798ca80 23ab69df
Branches
Tags
1 merge request!126ESB: python API
Pipeline #3997 passed
......@@ -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.
......@@ -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);
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment