summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-04-02 19:19:43 -0400
committerDan Halbert <halbert@halwitz.org>2018-04-02 19:19:43 -0400
commit435e894fa0ec5e9ce82b7bdef308413c6731e06a (patch)
treeaf8d62363157a6ba969684538e012871a88224c6 /shared-module
parentd005b123267ab4ac2f0471c730b762cc3e94232c (diff)
parent98c7d70fe406d66d80c3c9cc888602f96cf444c4 (diff)
Merge branch 'master' into 3.0_hid
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/gamepad/GamePad.c8
-rw-r--r--shared-module/gamepad/__init__.c6
-rw-r--r--shared-module/storage/__init__.c18
-rw-r--r--shared-module/struct/__init__.c2
4 files changed, 22 insertions, 12 deletions
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; i<n_pins; ++i) {
digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(pins[i]);
+ raise_error_if_deinited(common_hal_digitalio_digitalinout_deinited(pin));
+ digitalio_direction_t direction = common_hal_digitalio_digitalinout_get_direction(pin);
+ digitalio_pull_t pull = common_hal_digitalio_digitalinout_get_pull(pin);
+ if (direction != DIRECTION_INPUT || pull == PULL_NONE) {
+ common_hal_digitalio_digitalinout_switch_to_input(pin, PULL_UP);
+ }
gamepad_singleton->pins[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<<i;
+ digitalio_pull_t pull = common_hal_digitalio_digitalinout_get_pull(pin);
+ bool value = common_hal_digitalio_digitalinout_get_value(pin);
+ if ((pull == PULL_UP && !value) || (pull == PULL_DOWN && value)) {
+ gamepad_current |= 1 << i;
}
}
gamepad_singleton->pressed |= gamepad_singleton->last & gamepad_current;
diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c
index 97a049bac..5b0bbe01e 100644
--- a/shared-module/storage/__init__.c
+++ b/shared-module/storage/__init__.c
@@ -109,19 +109,19 @@ 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);
- }
+void common_hal_storage_umount_path(const char* mount_path) {
+ common_hal_storage_umount_object(storage_object_from_path(mount_path));
+}
- common_hal_storage_umount_object(vfs_obj);
+mp_obj_t common_hal_storage_getmount(const char *mount_path) {
+ return storage_object_from_path(mount_path);
}
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) {