]> us-delaporte.pagekite.me Git - dotfiles.git/blob - invoke/esptool/tasks.py
Print more example lines from file
[dotfiles.git] / invoke / esptool / tasks.py
1 from invoke import task
2
3 from datetime import datetime as dt
4 import os
5
6 HOME = os.path.expanduser('~')
7 TODAY = dt.now().strftime('%Y.%m.%d')
8
9 # Examples for CardputerAdv
10 DEVICE = 'Espressif'
11 PORT='/dev/ttyACM0' # Linux
12 CHIP='ESP32-S3'
13 # PORT='COM0' # Windows
14 MICROPYTHON=f'$HOME/Downloads/ESP32_GENERIC_S3-20260406-v1.28.0.bin'
15 # MicroPython version
16 # from
17 # https://micropython.org/download/ESP32_GENERIC_S3/
18
19 @task
20 def help(c):
21 '''
22 On using this tasks file
23
24 - Set the Cardputer Adv power to 'off' state
25 - Plugging in to USB will cause it to boot
26 - Hold 'Go' while booting
27 - Hold 'Go' and press 'Reset' to try again.
28 - On success, the usual screen content still shows up
29 > Tip: Be sure to use a cable that can carry data, not just power.
30
31 Consider burnin
32 https://github.com/echo-lalia/MicroHydra
33
34 '''
35 print(help.__doc__)
36
37 @task
38 def groups(c):
39 '''Check that the current user is a member of dialout'''
40 result = c.run(f'groups {os.getlogin()}')
41 assert 'dialout' in result.stdout
42 print('ok')
43
44 @task
45 def usbdiff(c):
46 '''Use lsusb to try to find the new device.'''
47 input('Un-plug in the device...')
48 c.run('lsusb > /tmp/before.txt')
49 input('Plug in the device...')
50 c.run('lsusb > /tmp/after.txt')
51 result = c.run('diff /tmp/before.txt /tmp/after.txt')
52 print(result.stdout)
53 # breakpoint()
54
55 # Maybe https://thelastoutpostworkshop.github.io/ESPConnect/ in Chromium?
56
57
58 @task
59 def check_conn(c):
60 result = c.run(f'lsusb | grep {DEVICE}')
61 assert DEVICE in result.stdout
62 print('[ok]')
63
64 @task
65 def listusb(c):
66 # result = c.run('ls /dev/ttyACM*')
67 result = c.run(f'ls {PORT}')
68 assert result.ok
69 print('[ok]')
70 # c.run('ls /dev/ttyUSB*')
71
72 @task
73 def chip_id(c):
74 result = c.run(f'esptool --port {PORT} chip-id')
75 assert CHIP in result.stdout
76 print('[ok]')
77
78 @task
79 def check_all(c):
80 listusb(c)
81 check_conn(c)
82 chip_id(c)
83
84 @task
85 def erase_flash(c):
86 '''Erasing flash is recommended before flashing fresh.'''
87 c.run(f'esptool --port {PORT} erase-flash')
88
89 @task
90 def write_flash(c, filepath=MICROPYTHON):
91 '''Write flash - defaults to MicroPython
92
93 Requires .bin file from micropython.org
94 '''
95 c.run(f'esptool --chip {CHIP} --port {PORT} --baud 460800 write-flash -z 0x1000 {filepath}')
96
97
98