Skip to content

Commit 69f09cc

Browse files
committed
python: Update README
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 2325ec3 commit 69f09cc

File tree

2 files changed

+101
-189
lines changed

2 files changed

+101
-189
lines changed

python.md

Lines changed: 0 additions & 58 deletions
This file was deleted.

python/README.md

Lines changed: 101 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,19 @@
1-
# Framework Laptop 16 - Input Module Firmware/Software
1+
# Framework Laptop 16 - Input Module Software
22

3-
This repository contains both the firmware for the Framework Laptop 16 input modules,
4-
as well as the tool to control them.
3+
This repository contains a python library and scripts to control the
4+
(non-keyboard) input modules, which is currently just the LED Matrix.
55

6-
Rust firmware project setup based off of: https://github.com/rp-rs/rp2040-project-template
6+
## Installing
77

8-
## Modules
8+
Pre-requisites: Python with pip
99

10-
See pages of the individual modules for details about how they work and how
11-
they're controlled.
12-
13-
- [LED Matrix](ledmatrix/README.md)
14-
- [Minimal C1 Input Module](c1minimal/README.md)
15-
- [2nd Display](b1display/README.md)
16-
- [QT PY RP2040](qtpy/README.md)
17-
18-
## Generic Features
19-
20-
All modules are built with an RP2040 microcontroller
21-
Features that all modules share
22-
23-
- Firmware written in bare-metal Rust
24-
- Reset into RP2040 bootloader when firmware crashes/panics
25-
- Sleep Mode to save power
26-
- API over USB ACM Serial Port - Requires no Drivers on Windows and Linux
27-
- Go to sleep
28-
- Reset into bootloader
29-
- Control and read module state (brightness, displayed image, ...)
10+
```sh
11+
python3 -m pip install framework16_inputmodule
12+
```
3013

3114
## Control from the host
3215

33-
To build your own application see the: [API command documentation](commands.md)
34-
35-
Or use our `inputmodule-control` app, which you can download from the latest
36-
[GH Actions](https://github.com/FrameworkComputer/led_matrix_fw/actions) run or
37-
the [release page](https://github.com/FrameworkComputer/led_matrix_fw/releases).
38-
Optionally there are is also a [Python script](python.md).
39-
40-
For device specific commands, see their individual documentation pages.
16+
To build your own application see the: [API command documentation](https://github.com/FrameworkComputer/inputmodule-rs/tree/main/commands.md)
4117

4218
###### Permissions on Linux
4319
To ensure that the input module's port is accessible, install the `udev` rule and trigger a reload:
@@ -52,126 +28,131 @@ sudo udevadm control --reload && sudo udevadm trigger
5228
###### Listing available devices
5329

5430
```sh
55-
> inputmodule-control --list
56-
/dev/ttyACM0
57-
VID 0x32AC
58-
PID 0x0020
59-
SN FRAKDEAM0020110001
60-
Product LED_Matrix
31+
> ledmatrixctl
32+
More than 1 compatible device found. Please choose with --serial-dev ...
33+
Example on Windows: --serial-dev COM3
34+
Example on Linux: --serial-dev /dev/ttyACM0
6135
/dev/ttyACM1
62-
VID 0x32AC
63-
PID 0x0021
64-
SN FRAKDEAM0000000000
65-
Product B1_Display
36+
VID: 0x32AC
37+
PID: 0x0020
38+
SN: FRAKDEBZ0100000000
39+
Product: LED Matrix Input Module
40+
/dev/ttyACM0
41+
VID: 0x32AC
42+
PID: 0x0020
43+
SN: FRAKDEBZ0100000000
44+
Product: LED Matrix Input Module
6645
```
6746

6847
###### Apply command to single device
6948

70-
By default a command will be sent to all devices that can be found, to apply it
71-
to a single device, specify the COM port.
72-
In this example the command is targeted at `b1-display`, so it will only apply
73-
to this module type.
49+
When there are multiple devices you need to select which one to control.
7450

7551
```
7652
# Example on Linux
77-
> inputmodule-control --serial-dev /dev/ttyACM0 b1-display --pattern black
53+
> ledmatrixctl --serial-dev /dev/ttyACM0 --percentage 33
7854
7955
# Example on Windows
80-
> inputmodule-control.exe --serial-dev COM5 b1-display --pattern black
56+
> ledmatrixctl --serial-dev COM5 --percentage 33
8157
```
8258

83-
###### Send command when device connects
59+
### Graphical Application
60+
61+
Launch the graphical application
8462

85-
By default the app tries to connect with the device and aborts if it can't
86-
connect. But you might want to start the app, have it wait until the device is
87-
connected and then send the command.
63+
```sh
64+
# Either via the commandline
65+
ledmatrixctl --gui
8866

67+
# Or using the standanlone application
68+
ledmatrixgui
8969
```
90-
> inputmodule-control b1-display --pattern black
91-
Failed to find serial devivce. Please manually specify with --serial-dev
9270

93-
# No failure, waits until the device is connected, sends command and exits
94-
> inputmodule-control --wait-for-device b1-display --pattern black
71+
### Other example commands
72+
73+
```sh
9574

96-
# If the device is already connected, it does nothing, just wait 1s.
97-
# This means you can run this command by a system service and restart it when
98-
# it finishes. Then it will only ever do anything if the device reconnects.
99-
> inputmodule-control --wait-for-device b1-display --pattern black
100-
Device already present. No need to wait. Not executing command.
75+
# Show current time and keep updating it
76+
ledmatrixctl --clock
77+
78+
# Draw PNG or GIF
79+
ledmatrixctl --image stripe.gif
80+
ledmatrixctl --image stripe.png
81+
82+
# Change brightness (0-255)
83+
ledmatrixctl --brightness 50
84+
```
85+
86+
### All commandline options
87+
88+
```
89+
> ledmatrixctl --help
90+
options:
91+
-h, --help show this help message and exit
92+
-l, --list List all compatible devices
93+
--bootloader Jump to the bootloader to flash new firmware
94+
--sleep, --no-sleep Simulate the host going to sleep or waking up
95+
--is-sleeping Check current sleep state
96+
--brightness BRIGHTNESS
97+
Adjust the brightness. Value 0-255
98+
--get-brightness Get current brightness
99+
--animate, --no-animate
100+
Start/stop vertical scrolling
101+
--get-animate Check if currently animating
102+
--pwm {29000,3600,1800,900}
103+
Adjust the PWM frequency. Value 0-255
104+
--get-pwm Get current PWM Frequency
105+
--pattern {...} Display a pattern
106+
--image IMAGE Display a PNG or GIF image in black and white only)
107+
--image-grey IMAGE_GREY
108+
Display a PNG or GIF image in greyscale
109+
--camera Stream from the webcam
110+
--video VIDEO Play a video
111+
--percentage PERCENTAGE
112+
Fill a percentage of the screen
113+
--clock Display the current time
114+
--string STRING Display a string or number, like FPS
115+
--symbols SYMBOLS [SYMBOLS ...]
116+
Show symbols (degF, degC, :), snow, cloud, ...)
117+
--gui Launch the graphical version of the program
118+
--panic Crash the firmware (TESTING ONLY)
119+
--blink Blink the current pattern
120+
--breathing Breathing of the current pattern
121+
--eq EQ [EQ ...] Equalizer
122+
--random-eq Random Equalizer
123+
--wpm WPM Demo
124+
--snake Snake
125+
--snake-embedded Snake on the module
126+
--pong-embedded Pong on the module
127+
--game-of-life-embedded {currentmatrix,pattern1,blinker,toad,beacon,glider}
128+
Game of Life
129+
--quit-embedded-game Quit the current game
130+
--all-brightnesses Show every pixel in a different brightness
131+
-v, --version Get device version
132+
--serial-dev SERIAL_DEV
133+
Change the serial dev. Probably /dev/ttyACM0 on Linux, COM0 on Windows
101134
```
102135

103136
## Update the Firmware
104137

105138
First, put the module into bootloader mode.
106139

107-
This can be done either by pressing the bootsel button while plugging it in or
140+
This can be done either by flipping DIP switch #2 or
108141
by using one of the following commands:
109142

110143
```sh
111-
inputmodule-control led-matrix --bootloader
112-
inputmodule-control b1-display --bootloader
113-
inputmodule-control c1-minimal --bootloader
144+
> ledmatrixctl --bootloader
114145
```
115146

116147
Then the module will present itself in the same way as a USB thumb drive.
117148
Copy the UF2 firmware file onto it and the device will flash and reset automatically.
118-
Alternatively when building from source, run one of the following commands:
119-
120-
```sh
121-
cargo run -p ledmatrix
122-
cargo run -p b1display
123-
cargo run -p c1minimal
124-
```
125-
126-
## Building the firmware
127-
128-
Dependencies: Rust
129-
130-
Prepare Rust toolchain (once):
131-
132-
```sh
133-
rustup target install thumbv6m-none-eabi
134-
cargo install flip-link
135-
```
136-
137-
Build:
138-
139-
```sh
140-
cargo make --cwd ledmatrix
141-
cargo make --cwd b1display
142-
cargo make --cwd c1minimal
143-
```
144-
145-
Generate the UF2 update file:
146-
147-
```sh
148-
cargo make --cwd ledmatrix uf2
149-
cargo make --cwd b1display uf2
150-
cargo make --cwd c1minimal uf2
151-
```
152-
153-
## Building the Application
154-
155-
Dependencies: Rust, pkg-config, libudev
156-
157-
Currently have to specify the build target because it's not possible to specify a per package build target.
158-
Tracking issue: https://github.com/rust-lang/cargo/issues/9406
159-
160-
```
161-
# Build it
162-
> cargo make --cwd inputmodule-control
163-
164-
# Build and run it, showing the tool version
165-
> cargo make --cwd inputmodule-control run -- --version
166149
```
167150
168151
### Check the firmware version of the device
169152
170-
###### In-band using commandline
171-
172153
```sh
173-
> inputmodule-control b1-display --version
174-
Device Version: 0.1.3
154+
> ledmatrixctl --version
155+
Device Version: 0.1.7
175156
```
176157

177158
###### By looking at the USB descriptor
@@ -180,18 +161,7 @@ On Linux:
180161

181162
```sh
182163
> lsusb -d 32ac: -v 2> /dev/null | grep -P 'ID 32ac|bcdDevice'
183-
Bus 003 Device 078: ID 32ac:0021 Framework Laptop 16 B1 Display
184-
bcdDevice 0.10
164+
Bus 003 Device 078: ID 32ac:0020 Framework Computer Inc LED Matrix Input Module
165+
bcdDevice 0.17
185166
```
186167

187-
## Rust Panic
188-
189-
When the Rust code panics, the RP2040 resets itself into bootloader mode.
190-
This means a new firmware can be written to overwrite the old one.
191-
192-
Additionally the panic message is written to XIP RAM, which can be read with [picotool](https://github.com/raspberrypi/picotool):
193-
194-
```sh
195-
sudo picotool save -r 0x15000000 0x15004000 message.bin
196-
strings message.bin | head
197-
```

0 commit comments

Comments
 (0)