From 355bf8b5538b4fe2f9f07b0d8fb2f4500c2f96c6 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 26 Mar 2018 18:13:49 -0500 Subject: Conditionally compile out nonstandard array/struct typecodes .. defaulting to off for circuitpython-supported boards, on for others. .. fixing up the tests that fail when it is turned off, so that they skip instead of failing --- shared-module/struct/__init__.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'shared-module') diff --git a/shared-module/struct/__init__.c b/shared-module/struct/__init__.c index e944f7738..eac41c9c3 100644 --- a/shared-module/struct/__init__.c +++ b/shared-module/struct/__init__.c @@ -33,9 +33,11 @@ #include "py/parsenum.h" void struct_validate_format(char fmt) { +#if MICROPY_NONSTANDARD_TYPECODES if( fmt == 'S' || fmt == 'O') { mp_raise_RuntimeError("'S' and 'O' are not supported format types"); } +#endif } char get_fmt_type(const char **fmt) { -- cgit v1.2.3 From 968763aa1d4ee5ed597d6f32b19fef6cbbed5c5c Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 27 Mar 2018 21:28:18 -0500 Subject: factor out storage_object_from_path --- shared-module/storage/__init__.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'shared-module') diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 97a049bac..3e7b90384 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -109,19 +109,15 @@ void common_hal_storage_umount_object(mp_obj_t vfs_obj) { mp_vfs_proxy_call(vfs, MP_QSTR_umount, 0, NULL); } -void common_hal_storage_umount_path(const char* mount_path) { - // remove vfs from the mount table - mp_obj_t *vfs_obj = NULL; +STATIC mp_obj_t storage_object_from_path(const char* mount_path) { for (mp_vfs_mount_t **vfsp = &MP_STATE_VM(vfs_mount_table); *vfsp != NULL; vfsp = &(*vfsp)->next) { if (strcmp(mount_path, (*vfsp)->str) == 0) { - vfs_obj = (*vfsp)->obj; - break; + return (*vfsp)->obj; } } + mp_raise_OSError(MP_EINVAL); +} - if (vfs_obj == NULL) { - mp_raise_OSError(MP_EINVAL); - } - - common_hal_storage_umount_object(vfs_obj); +void common_hal_storage_umount_path(const char* mount_path) { + common_hal_storage_umount_object(storage_object_from_path(mount_path)); } -- cgit v1.2.3 From c08f5a3a0071dd1940a09c6b5f0bdd8e4768c7f0 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 27 Mar 2018 21:28:18 -0500 Subject: Add storage.getmount to retrieve the mount object associated with a path --- shared-bindings/storage/__init__.c | 10 ++++++++++ shared-bindings/storage/__init__.h | 1 + shared-module/storage/__init__.c | 4 ++++ 3 files changed, 15 insertions(+) (limited to 'shared-module') diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index 6f6a30da6..837017ef9 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -122,12 +122,22 @@ mp_obj_t storage_remount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a } MP_DEFINE_CONST_FUN_OBJ_KW(storage_remount_obj, 1, storage_remount); +//| .. function:: getmount(mount_path) +//| +//| Retrieves the mount object associated with the mount path +//| +mp_obj_t storage_getmount(const mp_obj_t mnt_in) { + return common_hal_storage_getmount(mp_obj_str_get_str(mnt_in)); +} +MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount); + STATIC const mp_rom_map_elem_t storage_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_storage) }, { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&storage_mount_obj) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&storage_umount_obj) }, { MP_ROM_QSTR(MP_QSTR_remount), MP_ROM_PTR(&storage_remount_obj) }, + { MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) }, //| .. class:: VfsFat(block_device) //| diff --git a/shared-bindings/storage/__init__.h b/shared-bindings/storage/__init__.h index 574b5ff8d..76b9ae854 100644 --- a/shared-bindings/storage/__init__.h +++ b/shared-bindings/storage/__init__.h @@ -34,5 +34,6 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* path, bool readonly) void common_hal_storage_umount_path(const char* path); void common_hal_storage_umount_object(mp_obj_t vfs_obj); void common_hal_storage_remount(const char* path, bool readonly); +mp_obj_t common_hal_storage_getmount(const char* path); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_STORAGE___INIT___H diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 3e7b90384..5b0bbe01e 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -121,3 +121,7 @@ STATIC mp_obj_t storage_object_from_path(const char* mount_path) { void common_hal_storage_umount_path(const char* mount_path) { common_hal_storage_umount_object(storage_object_from_path(mount_path)); } + +mp_obj_t common_hal_storage_getmount(const char *mount_path) { + return storage_object_from_path(mount_path); +} -- cgit v1.2.3 From 280374fa63e284f272b714358aac32b75a4bee6a Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Sat, 31 Mar 2018 21:13:02 +0200 Subject: Respect pin's pull in gamepad While it is traditional to have buttons on pins that are pulled up, and have the button connect them to the ground, some CircuitPython boards (notably the CPX) have the button pins pulled low and the button connects them to VCC. This patch makes the gamepad only change the pin's pull if it wasn't already set when passed to the constructor, and also makes it consider a button pressed when its value is the opposite of its pull. --- shared-module/gamepad/GamePad.c | 8 +++++++- shared-module/gamepad/__init__.c | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'shared-module') diff --git a/shared-module/gamepad/GamePad.c b/shared-module/gamepad/GamePad.c index 3a2b8a3fe..cd1df9b57 100644 --- a/shared-module/gamepad/GamePad.c +++ b/shared-module/gamepad/GamePad.c @@ -31,6 +31,7 @@ #include "shared-bindings/digitalio/Pull.h" #include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/util.h" void gamepad_init(size_t n_pins, const mp_obj_t* pins) { @@ -39,8 +40,13 @@ void gamepad_init(size_t n_pins, const mp_obj_t* pins) { } for (size_t i=0; ipins[i] = pin; - common_hal_digitalio_digitalinout_switch_to_input(pin, PULL_UP); } gamepad_singleton->last = 0; } diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c index b6c8be215..591a2fa0a 100644 --- a/shared-module/gamepad/__init__.c +++ b/shared-module/gamepad/__init__.c @@ -42,8 +42,10 @@ void gamepad_tick(void) { if (!pin) { break; } - if (!common_hal_digitalio_digitalinout_get_value(pin)) { - gamepad_current |= 1<pressed |= gamepad_singleton->last & gamepad_current; -- cgit v1.2.3