Skip to content

Commit a4c41d7

Browse files
Add porting guide
1 parent 951751b commit a4c41d7

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

docs/building/desktop.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ sudo apt install libv4l-dev # For webcam support
3333

3434
## Running on Desktop
3535

36-
1. Download a release (e.g., `MicroPythonOS_amd64_Linux_0.0.8`) or use your build.
36+
1. Download a release (e.g., `MicroPythonOS_amd64_Linux`) or use your build.
3737
2. Run the application:
3838

39+
<pre>
3940
```bash
4041
cd internal_filesystem/
41-
/path/to/MicroPythonOS_amd64_Linux_0.0.8 -X heapsize=32M -v -i -c "$(cat boot_unix.py main.py)"
42+
/path/to/MicroPythonOS_amd64_Linux -X heapsize=32M -v -i -c "$(cat boot_unix.py main.py)"
4243
```
44+
</pre>
4345

4446
3. Check `scripts/run_on_desktop.sh` for options like fullscreen or direct app launch.
4547

docs/building/porting.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Porting to a new device
2+
3+
Porting MicroPythonOS to a new device can be fairly easy, if it's a common device that can already run MicroPython.
4+
5+
Ideally, the hardware drivers (for your display) are also already available in the [lvgl_micropython](https://github.com/lvgl-micropython/lvgl_micropython) project, which MicroPythonOS heavily relies upon.
6+
7+
Of course, porting is always quite a technical undertaking, so if you want to make your life easy, just purchase one of the already supported devices - they're fairly cheap.
8+
9+
## What to write
10+
11+
By design, the only device-specific code for MicroPythonOS is found in the ```internal_filesystem/boot*.py``` files.
12+
13+
## Steps to port to a new device
14+
15+
1. Compile [lvgl_micropython](https://github.com/lvgl-micropython/lvgl_micropython) for the new device.
16+
17+
The goal is to have it boot and show a MicroPython REPL shell on the serial line.
18+
19+
Take a look at our [build_lvgl_micropython.sh](https://github.com/MicroPythonOS/MicroPythonOS/blob/main/scripts/build_lvgl_micropython.sh) script. A "dev" build (without any "frozen" filesystem) is preferred as this will still change a lot.
20+
21+
Also go over the [official lvgl_micropython documentation](https://github.com/lvgl-micropython/lvgl_micropython/blob/main/README.md) for porting instructions. If you're in luck, your device is already listed in the esp32 BOARD list. Otherwise use a generic one like `BOARD=ESP32_GENERIC` with `BOARD_VARIANT=SPIRAM` or `BOARD=ESP32_GENERIC_S3` with `BOARD_VARIANT=SPIRAM_OCT` if it has an SPIRAM.
22+
23+
2. Figure out how to initialize the display for the new device
24+
25+
Use the MicroPython REPL shell on the serial port to type or paste (CTRL-E) MicroPython code.
26+
27+
Check out how it's done for the [Waveshare 2 inch Touch Screen](https://github.com/MicroPythonOS/MicroPythonOS/blob/main/internal_filesystem/boot.py) and for the [Fri3d Camp 2024 Badge](https://github.com/MicroPythonOS/MicroPythonOS/blob/main/internal_filesystem/boot_fri3d-2024.py). You essentially need to set the correct pins to which the display is connected (like `LCD_SCLK`, `LCD_MOSI`, `LCD_MOSI` etc.) and also set the resolution of the display (`TFT_HOR_RES`, `TFT_VER_RE`S).
28+
29+
After a failed attempt, reset the device to make sure the hardware is in a known initial state again.
30+
31+
If the display stays black, and your pins are correct, you may need to change between reset_state=0 and reset_state=1.
32+
33+
If the colors are off, play around with `color_space=lv.COLOR_FORMAT.RGB565`, `color_byte_order=st7789.BYTE_ORDER_BGR` and `rgb565_byte_swap=True`.
34+
35+
If you're successful, the display will still be black because LVGL isn't drawing anything to it yet.
36+
So use this code (based on main.py and helloworld.py) at the end to display something:
37+
<pre>
38+
```
39+
import lvgl as lv
40+
import task_handler
41+
task_handler.TaskHandler(duration=5)
42+
label = lv.label(lv.screen_active())
43+
label.set_text('Hello World!')
44+
label.center()
45+
```
46+
</pre>
47+
48+
3. Put the initialization code in a custom boot_...py file for your device
49+
50+
4. Copy the custom boot_...py file and the generic MicroPythonOS files to your device (see [install.sh](https://github.com/MicroPythonOS/MicroPythonOS/blob/main/scripts/install.sh)
51+
52+
After reset, your custom boot_...py file should initialize the display and then MicroPythonOS should start, run the launcher, which shows the icons etc.
53+
54+
5. Add more hardware support
55+
56+
If your device has a touch screen, check out how it's initialized for the [Waveshare 2 inch Touch Screen](https://github.com/MicroPythonOS/MicroPythonOS/blob/main/internal_filesystem/boot.py).
57+
If it has buttons for input, check out the KeyPad code for the [Fri3d Camp 2024 Badge](https://github.com/MicroPythonOS/MicroPythonOS/blob/main/internal_filesystem/boot_fri3d-2024.py).
58+
59+
Now you should be able to control the device, connect to WiFi and install more apps from the AppStore.
60+
61+
This would be a good time to create a pull-request to merge your boot_...py file into the main codebase so the support becomes official!

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ nav:
5050
- Building:
5151
- For ESP32: building/esp32.md
5252
- For Desktop: building/desktop.md
53+
- Porting Guide: building/porting.md
5354
- Release Checklist: building/release-checklist.md
5455
extra:
5556
social:

0 commit comments

Comments
 (0)