implemented microSD mount/unmount functions
This commit is contained in:
+23
-1
@@ -5,7 +5,7 @@ import os
|
||||
|
||||
MCU_STORAGE = False
|
||||
try:
|
||||
import storage
|
||||
import storage, sdcardio, board
|
||||
MCU_STORAGE = True
|
||||
except:
|
||||
pass
|
||||
@@ -18,6 +18,28 @@ def lock_rootfs():
|
||||
if MCU_STORAGE:
|
||||
storage.remount("/", readonly=True)
|
||||
|
||||
def mount_sd(path='/sd', readonly=False):
|
||||
sd_ok = True
|
||||
if MCU_STORAGE:
|
||||
try:
|
||||
sdcard = sdcardio.SDCard(board.SPI(), board.SDCARD_CS)
|
||||
vfs = storage.VfsFat(sdcard)
|
||||
storage.mount(vfs, path, readonly=readonly)
|
||||
sd_ok = True
|
||||
except:
|
||||
sd_ok = False
|
||||
return sd_ok
|
||||
|
||||
def umount_sd(path='/sd'):
|
||||
sd_ok = True
|
||||
if MCU_STORAGE:
|
||||
try:
|
||||
storage.umount(path)
|
||||
sd_ok = True
|
||||
except:
|
||||
sd_ok = False
|
||||
return sd_ok
|
||||
|
||||
# TODO: switch to buffered copying to avoid RAM overflow
|
||||
def copy(p1, p2):
|
||||
with open(p1, 'rb') as f1:
|
||||
|
||||
Reference in New Issue
Block a user