summaryrefslogtreecommitdiff
path: root/shared-module/storage
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2018-10-19 18:46:22 -0700
committerScott Shawcroft <scott@tannewt.org>2018-11-08 17:25:30 -0800
commit9d91111b1b6a1eee77a88b13faf695ee0c5caea3 (patch)
tree97b1bf6ae67f8c91f7a32a0246e2f8ebd9a749c7 /shared-module/storage
parentd08747d374057b24803b429bbf6474a2e4dcea5c (diff)
Move atmel-samd to tinyusb and support nRF flash.
This started while adding USB MIDI support (and descriptor support is in this change.) When seeing that I'd have to implement the MIDI class logic twice, once for atmel-samd and once for nrf, I decided to refactor the USB stack so its shared across ports. This has led to a number of changes that remove items from the ports folder and move them into supervisor. Furthermore, we had external SPI flash support for nrf pending so I factored out the connection between the usb stack and the flash API as well. This PR also includes the QSPI support for nRF.
Diffstat (limited to 'shared-module/storage')
-rw-r--r--shared-module/storage/__init__.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c
index edce286b1..f09edd785 100644
--- a/shared-module/storage/__init__.c
+++ b/shared-module/storage/__init__.c
@@ -32,8 +32,12 @@
#include "py/mperrno.h"
#include "py/obj.h"
#include "py/runtime.h"
+#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/os/__init__.h"
#include "shared-bindings/storage/__init__.h"
+#include "supervisor/filesystem.h"
+#include "supervisor/flash.h"
+#include "supervisor/usb.h"
STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) {
if (vfs == MP_VFS_NONE) {
@@ -138,3 +142,25 @@ void common_hal_storage_umount_path(const char* mount_path) {
mp_obj_t common_hal_storage_getmount(const char *mount_path) {
return storage_object_from_path(mount_path);
}
+
+void common_hal_storage_remount(const char *mount_path, bool readonly) {
+ if (strcmp(mount_path, "/") != 0) {
+ mp_raise_OSError(MP_EINVAL);
+ }
+
+ #ifdef USB_AVAILABLE
+ // TODO(dhalbert): is this is a good enough check? It checks for
+ // CDC enabled. There is no "MSC enabled" check.
+ if (usb_enabled()) {
+ mp_raise_RuntimeError(translate("Cannot remount '/' when USB is active."));
+ }
+ #endif
+
+ supervisor_flash_set_usb_writable(readonly);
+}
+
+void common_hal_storage_erase_filesystem(void) {
+ filesystem_init(false, true); // Force a re-format.
+ common_hal_mcu_reset();
+ // We won't actually get here, since we're resetting.
+}