diff --git a/Documentation/pycardium/os.rst b/Documentation/pycardium/os.rst index d2fd7cf224b316050b8f84df838213c0c6116df9..7915fccdf6f8e33f71f73057fb118847d757bd4f 100644 --- a/Documentation/pycardium/os.rst +++ b/Documentation/pycardium/os.rst @@ -115,3 +115,17 @@ Card10-Specific .. py:data:: USB_FLASH Mass-Storage device active. + +.. py:function:: fs_is_attached() + + Check whether the filesystem is currently attached to card10 (or whether a connected + USB host is currently holding control over it and possibly writing to it). + + :returns: + + - ``True`` if the filesystem is attached to card10 and an app can read and + write files. + - ``False`` if the filesystem is not available to card10 because a USB + host is currently controlling it. + + .. versionadded: 1.18 diff --git a/pycardium/modules/os.c b/pycardium/modules/os.c index ea8b4d0f9a814bdc37853fd873697d3fd2ae1d83..ad704f103f412ba73bc48ce2dee9b63715931af1 100644 --- a/pycardium/modules/os.c +++ b/pycardium/modules/os.c @@ -220,6 +220,16 @@ static mp_obj_t mp_os_usbconfig(mp_obj_t dev) } static MP_DEFINE_CONST_FUN_OBJ_1(usbconfig_obj, mp_os_usbconfig); +static mp_obj_t mp_os_fs_is_attached(void) +{ + if (epic_fs_is_attached()) { + return mp_const_true; + } else { + return mp_const_false; + } +} +static MP_DEFINE_CONST_FUN_OBJ_0(fs_is_attached_obj, mp_os_fs_is_attached); + 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) }, @@ -232,6 +242,8 @@ static const mp_rom_map_elem_t os_module_globals_table[] = { { 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_fs_is_attached), + MP_ROM_PTR(&fs_is_attached_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) }, diff --git a/pycardium/modules/qstrdefs.h b/pycardium/modules/qstrdefs.h index ad36658088e1d9c89126d7247acdfd439cb24ae8..01f32c679c012a70d4ed1db0e8711b1bc861e3b6 100644 --- a/pycardium/modules/qstrdefs.h +++ b/pycardium/modules/qstrdefs.h @@ -154,6 +154,7 @@ Q(usbconfig) Q(USB_FLASH) Q(USB_SERIAL) Q(USB_NONE) +Q(fs_is_attached) /* gpio */ Q(gpio)