Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
François Revol
firmware
Commits
5773e2e1
Commit
5773e2e1
authored
Sep 21, 2019
by
Rahix
Browse files
Merge 'Python API for ESB'
See merge request
card10/firmware!126
parents
1798ca80
23ab69df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Documentation/pycardium/os.rst
View file @
5773e2e1
...
...
@@ -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.
pycardium/modules/os.c
View file @
5773e2e1
...
...
@@ -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
);
...
...
pycardium/modules/qstrdefs.h
View file @
5773e2e1
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment