-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboot.py
More file actions
executable file
·53 lines (43 loc) · 1.34 KB
/
Copy pathboot.py
File metadata and controls
executable file
·53 lines (43 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# SPDX-FileCopyrightText: Copyright (c) 2026 Bob Grant for grgrant
#
# SPDX-License-Identifier: MIT
"""
boot.py -- implements switching R/O R/W CircuitPython and saves state
"""
VERSION = 0.7
DEBUG = False
DISPLAY_ROTATION = 0
import sys
import board
import storage
import supervisor
sys.path.append('/bin') # Add a user directory for imports
DISABLE_CIRCUITPY = False
SUPERVISOR_AUTORELOAD = False
print(f"boot.py V{VERSION}")
# Check if NVM exists and is a decent size
try:
from microcontroller import nvm
HAVE_NVM = len(nvm) > 512
except:
HAVE_NVM = False
if HAVE_NVM:
try:
import nvmflags as nf
DISABLE_CIRCUITPY = nf.is_set(nvm, nf.DISABLE_CIRCUITPY)
SUPERVISOR_AUTORELOAD = nf.is_set(nvm, nf.SUPERVISOR_AUTORELOAD)
except ImportError:
print("nvmflags not found -- using defaults")
if DEBUG:
print("DISABLE_CIRCUITPY", DISABLE_CIRCUITPY,
"SUPERVISOR_AUTORELOAD", SUPERVISOR_AUTORELOAD)
# Not all systems support usb drive
if hasattr(storage, 'disable_usb_drive'):
if DISABLE_CIRCUITPY:
storage.disable_usb_drive()
else:
storage.enable_usb_drive()
supervisor.runtime.autoreload = SUPERVISOR_AUTORELOAD
# Fail board rotation gracefully if not exists
if hasattr(board, 'DISPLAY') and hasattr(board.DISPLAY, 'rotation'):
board.DISPLAY.rotation = DISPLAY_ROTATION