瀏覽代碼

Upload files to 'CARDPUTER CircuitPython'

cube 9 月之前
父節點
當前提交
656e1a921c
共有 1 個檔案被更改,包括 58 行新增0 行删除
  1. 58
    0
      CARDPUTER CircuitPython/boot.py

+ 58
- 0
CARDPUTER CircuitPython/boot.py 查看文件

@@ -0,0 +1,58 @@
1
+"""CircuitPython Essentials Storage logging boot.py file"""
2
+from sys import implementation
3
+import board
4
+import digitalio
5
+import storage
6
+
7
+# The PyDOS file system will be set to Read/Write status for next
8
+# power cycle unless a control GPIO is grounded (GP2,5 or 6 depending on the Microcontroller)
9
+# in which case the host computer will have Read/Write access and PyDOS will have readonly access.
10
+
11
+if board.board_id == 'arduino_nano_rp2040_connect':
12
+    swpin = board.D2
13
+elif board.board_id in ['raspberry_pi_pico','cytron_maker_pi_rp2040']:
14
+    swpin = board.GP6
15
+elif board.board_id == 'adafruit_qtpy_esp32c3':
16
+    swpin = board.A1
17
+elif board.board_id == 'adafruit_itsybitsy_rp2040':
18
+    swpin = board.D7
19
+else:
20
+    if "D5" in dir(board):
21
+        swpin = board.D5
22
+    elif "GP5" in dir(board):
23
+        swpin = board.GP5
24
+    elif "IO5" in dir(board):
25
+        swpin = board.IO5
26
+    elif "D6" in dir(board):
27
+        swpin = board.D6
28
+    elif "GP6" in dir(board):
29
+        swpin = board.GP6
30
+    elif "IO6" in dir(board):
31
+        swpin = board.IO6
32
+    elif "D2" in dir(board):
33
+        swpin = board.D2
34
+    elif "GP2" in dir(board):
35
+        swpin = board.GP2
36
+    elif "IO2" in dir(board):
37
+        swpin = board.IO2
38
+    else:
39
+        swpin = None
40
+
41
+if swpin:
42
+    switch = digitalio.DigitalInOut(swpin)
43
+    switch.direction = digitalio.Direction.INPUT
44
+    switch.pull = digitalio.Pull.UP
45
+
46
+# If the switch pin is connected to ground (switch.value == False) allow host to write to the drive
47
+    if switch.value == False:
48
+        # Mounts so Host computer can write to micro-flash
49
+        storage.remount("/", True)
50
+        print("Switch False (pin grounded), PyDOS FS is ReadOnly")
51
+    else:
52
+        storage.remount("/", False)
53
+        print("Switch True (not grounded), PyDOS FS is ReadWrite")
54
+
55
+    switch.deinit()
56
+else:
57
+    print("If write access from the host is needed, enter the following PyDOS command:\nfs ro")
58
+    storage.remount("/", False )