]> apps.delaporte.us Git - dotfiles.git/blobdiff - invoke/esptool/tasks.py
lama.cpp pull helper
[dotfiles.git] / invoke / esptool / tasks.py
index 43df54eaa318ba40446290c601001449da905d0f..546e261607629037533c0fe0fea13d3b18b7f55d 100644 (file)
@@ -6,6 +6,16 @@ import os
 HOME = os.path.expanduser('~')
 TODAY = dt.now().strftime('%Y.%m.%d')
 
 HOME = os.path.expanduser('~')
 TODAY = dt.now().strftime('%Y.%m.%d')
 
+# Examples for CardputerAdv
+DEVICE = 'Espressif'
+PORT='/dev/ttyACM0' # Linux
+CHIP='ESP32-S3'
+# PORT='COM0' # Windows
+MICROPYTHON=f'$HOME/Downloads/ESP32_GENERIC_S3-20260406-v1.28.0.bin'
+# MicroPython version 
+# from 
+# https://micropython.org/download/ESP32_GENERIC_S3/
+
 @task
 def help(c):
     '''
 @task
 def help(c):
     '''
@@ -44,21 +54,45 @@ def usbdiff(c):
 
 # Maybe https://thelastoutpostworkshop.github.io/ESPConnect/ in Chromium?
 
 
 # Maybe https://thelastoutpostworkshop.github.io/ESPConnect/ in Chromium?
 
-DEV='/dev/ttyACM0'
 
 @task
 
 @task
-def check_connected(c):
-    dev = 'Espressif'
-    result = c.run(f'lsusb | grep {dev}')
-    assert dev in result.stdout
+def check_conn(c):
+    result = c.run(f'lsusb | grep {DEVICE}')
+    assert DEVICE in result.stdout
     print('[ok]')
 
 @task
 def listusb(c):
     print('[ok]')
 
 @task
 def listusb(c):
-    c.run('ls /dev/ttyACM*')
+    # result = c.run('ls /dev/ttyACM*')
+    result = c.run(f'ls {PORT}')
+    assert result.ok
+    print('[ok]')
     # c.run('ls /dev/ttyUSB*')
 
     # c.run('ls /dev/ttyUSB*')
 
-@task()
+@task
 def chip_id(c):
 def chip_id(c):
-    c.run(f'esptool --port {DEV} chip-id')
+    result = c.run(f'esptool --port {PORT} chip-id')
+    assert CHIP in result.stdout
+    print('[ok]')
+
+@task
+def check_all(c):
+    listusb(c)
+    check_conn(c)
+    chip_id(c)
+
+@task
+def erase_flash(c):
+    '''Erasing flash is recommended before flashing fresh.'''
+    c.run(f'esptool --port {PORT} erase-flash')
+
+@task
+def write_flash(c, filepath=MICROPYTHON):
+    '''Write flash - defaults to MicroPython
+
+    Requires .bin file from micropython.org
+    '''
+    c.run(f'esptool --chip {CHIP} --port {PORT} --baud 460800 write-flash -z 0x1000 {filepath}')
+
+