I have a lot of boards and usually need to re-use code even for different projects.

boot.py 1.9KB

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