Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
739aef8fcThis file is pinned to the selected release. Download the original to open it in your design tool.
import os
import sys
from wintertools import fs, circuitpython, fw_fetch, jlink, uf2_to_bin
from libsol import calibrate
DEVICE_NAME = "winterbloom_sol"
JLINK_DEVICE = "ATSAMD51J20"
JLINK_SCRIPT = "scripts/flash.jlink"
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
FIRMWARE_DIR = os.path.join(ROOT_DIR, "firmware")
LIB_DIR = os.path.join(FIRMWARE_DIR, "lib")
EXAMPLES_DIR = os.path.join(ROOT_DIR, "examples")
FILES_TO_DOWNLOAD = {
"https+zip://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/releases/download/6.3.6/adafruit-circuitpython-neopixel-7.x-mpy-6.3.6.zip:*/lib/neopixel.mpy": "neopixel.mpy",
"https+zip://github.com/adafruit/Adafruit_CircuitPython_BusDevice/releases/download/5.2.3/adafruit-circuitpython-busdevice-7.x-mpy-5.2.3.zip:*/lib/adafruit_bus_device/*": "adafruit_bus_device/"
}
FILES_TO_DEPLOY = {
fs.cache_path("neopixel.mpy"): "lib",
fs.cache_path("adafruit_bus_device"): "lib",
os.path.join(FIRMWARE_DIR, "winterbloom_sol"): "lib",
os.path.join(FIRMWARE_DIR, "LICENSE"): ".",
os.path.join(FIRMWARE_DIR, "README.HTM"): ".",
os.path.join(LIB_DIR, "winterbloom_ad_dacs/winterbloom_ad_dacs"): "lib",
os.path.join(LIB_DIR, "winterbloom_voltageio/winterbloom_voltageio.py"): "lib",
os.path.join(LIB_DIR, "winterbloom_smolmidi/winterbloom_smolmidi.py"): "lib",
EXAMPLES_DIR: ".",
os.path.join(EXAMPLES_DIR, "1_default.py"): "code.py",
}
def program_firmware():
print("========== PROGRAMMING FIRMWARE ==========")
fw_fetch.latest_bootloader(DEVICE_NAME)
firmware_path = fw_fetch.latest_circuitpython(DEVICE_NAME)
uf2_to_bin.with_file(firmware_path)
jlink.run(JLINK_DEVICE, JLINK_SCRIPT)
def deploy_circuitpython_code(destination=None, publish_only=False):
print("========== DEPLOYING CODE ==========")
if not destination:
print("Waiting for CIRCUITPY drive...")
destination = fs.wait_for_drive("CIRCUITPY")
if not publish_only:
print("Forcing device into repl (workaround for CircuitPython issue #3986)")
circuitpython.force_into_repl(calibrate.USB_DEVICE_ID)
print("Cleaning temporary files from src directories...")
fs.clean_pycache(FIRMWARE_DIR)
fs.clean_pycache(EXAMPLES_DIR)
print("Downloading files to cache...")
fs.download_files_to_cache(FILES_TO_DOWNLOAD)
print("Copying files...")
fs.deploy_files(FILES_TO_DEPLOY, destination)
if not publish_only:
print("Done copying files, resetting...")
circuitpython.reset_via_serial(calibrate.USB_DEVICE_ID)
print("Done!")
def run_calibration():
print("========== CALIBRATION & TEST ==========")
calibrate.main()
def main():
if len(sys.argv) > 1 and sys.argv[1] == "publish":
deploy_circuitpython_code("distribution", publish_only=True)
return
try:
circuitpython_drive = fs.find_drive_by_name("CIRCUITPY")
except:
circuitpython_drive = None
if not circuitpython_drive:
program_firmware()
if circuitpython_drive and os.path.exists(
os.path.join(circuitpython_drive, "code.py")
):
if input("redeploy code? y/n: ").strip() == "y":
deploy_circuitpython_code()
else:
deploy_circuitpython_code()
if not circuitpython_drive or not os.path.exists(
os.path.join(circuitpython_drive, "calibration.py")
):
run_calibration()
elif input("recalibrate? y/n: ").strip() == "y":
run_calibration()
if __name__ == "__main__":
main()