Skip to content

Commit 4c1cdee

Browse files
tsteinrueckenLzw655
authored andcommitted
Provides an example of how to integrate this library into micropython
Fixes #186
1 parent 31771b3 commit 4c1cdee

File tree

2 files changed

+182
-0
lines changed

2 files changed

+182
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The functional block diagram is shown below:
4545
* [ESP-IDF](./docs/envs/use_with_idf.md)
4646
* [Arduino IDE](./docs/envs/use_with_arduino.md)
4747
* [PlatformIO](./examples/platformio/lvgl_v8_port/README.md)
48+
* [Micropython](./mpy_support/README.md)
4849

4950
## Supported Boards
5051

mpy_support/README.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Using with micropython
2+
3+
This is an example of how to integrate this library into micropython. It's written for an ESP32-S3, however
4+
it should be easy to adapt to different supported ESP-Chips. Please note, that you'll need at least 4mb of flash.
5+
6+
7+
## Step-by-Step instructions
8+
9+
1. Install IDF and micropython
10+
11+
```bash
12+
mkdir ~/esp32build
13+
pushd ~/esp32build
14+
git clone -b v5.2.2 --recursive https://github.com/espressif/esp-idf.git
15+
pushd esp-idf
16+
./install.sh esp32
17+
source export.sh
18+
popd
19+
git clone https://github.com/micropython/micropython.git
20+
pushd micropython
21+
git submodule update --init --recursive
22+
pushd mpy-cross
23+
make
24+
popd
25+
```
26+
27+
2. Ensure, you can build a working firmware
28+
29+
```bash
30+
make BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT -C ports/esp32
31+
pushd ports/esp32
32+
python -m esptool --port /dev/ttyACM0 --chip esp32s3 -b 460800 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size 4MB --flash_freq 80m 0x0 build-ESP32_GENERIC_S3-SPIRAM_OCT/bootloader/bootloader.bin 0x8000 build-ESP32_GENERIC_S3-SPIRAM_OCT/partition_table/partition-table.bin 0x10000 build-ESP32_GENERIC_S3-SPIRAM_OCT/micropython.bin
33+
popd
34+
popd
35+
```
36+
Now, test the board and ensure your build of micropython works.
37+
38+
3. Download ESP32_Display_Panel and it's dependencies
39+
```bash
40+
git clone https://github.com/esp-arduino-libs/ESP32_Display_Panel.git
41+
git clone https://github.com/esp-arduino-libs/esp-lib-utils.git
42+
git clone https://github.com/esp-arduino-libs/ESP32_IO_Expander.git
43+
```
44+
45+
4. Create a custom user-module definition
46+
```bash
47+
cat > micropython.cmake << EOF
48+
include(~/esp32build/ESP32_Display_Panel/micropython.cmake)
49+
include(~/esp32build/esp-lib-utils/micropython.cmake)
50+
include(~/esp32build/ESP32_IO_Expander/micropython.cmake)
51+
EOF
52+
```
53+
54+
5. Copy some header-files
55+
```bash
56+
cp esp-idf/components/esp_lcd/include/esp_lcd_panel_commands.h ESP32_Display_Panel/mpy_support/
57+
cp esp-idf/components/esp_lcd/interface/esp_lcd_panel_interface.h ESP32_Display_Panel/mpy_support/
58+
cp esp-idf/components/esp_lcd/include/esp_lcd_panel_io.h ESP32_Display_Panel/mpy_support/
59+
cp esp-idf/components/esp_lcd/interface/esp_lcd_panel_io_interface.h ESP32_Display_Panel/mpy_support/
60+
cp esp-idf/components/esp_lcd/include/esp_lcd_panel_ops.h ESP32_Display_Panel/mpy_support/
61+
cp esp-idf/components/esp_lcd/include/esp_lcd_panel_rgb.h ESP32_Display_Panel/mpy_support/
62+
cp esp-idf/components/esp_lcd/include/esp_lcd_panel_vendor.h ESP32_Display_Panel/mpy_support/
63+
cp esp-idf/components/esp_lcd/include/esp_lcd_types.h ESP32_Display_Panel/mpy_support/
64+
```
65+
66+
6. Rebuild micropython to include the new modules
67+
```bash
68+
pushd micropython
69+
make BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT USER_C_MODULES=~/esp32build/micropython.cmake -C ports/esp32
70+
pushd ports/esp32
71+
python -m esptool --port /dev/ttyACM0 --chip esp32s3 -b 460800 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size 4MB --flash_freq 80m 0x0 build-ESP32_GENERIC_S3-SPIRAM_OCT/bootloader/bootloader.bin 0x8000 build-ESP32_GENERIC_S3-SPIRAM_OCT/partition_table/partition-table.bin 0x10000 build-ESP32_GENERIC_S3-SPIRAM_OCT/micropython.bin
72+
popd
73+
popd
74+
```
75+
This may fail if your chip has a small flash size, in this case you have to increase the size of the
76+
application partition. E.g. for a 4mb flash chip edit micropython/ports/esp32/partitions-4MiB.csv and change the last
77+
two lines from:
78+
79+
```csv
80+
factory, app, factory, 0x10000, 0x1F0000,
81+
vfs, data, fat, 0x200000, 0x200000,
82+
```
83+
to
84+
```csv
85+
factory, app, factory, 0x10000, 0x2F0000,
86+
vfs, data, fat, 0x300000, 0x100000,
87+
```
88+
89+
7. Test the module
90+
Connect to your board and run:
91+
```python
92+
from esp_panel import Board
93+
board = Board()
94+
board.init()
95+
```
96+
board.init() should return False, as we yet have to define a board.
97+
98+
8. Define your Board
99+
Edit ESP32_Display_Panel/mpy_support/esp_panel_mp_board.cpp.
100+
Add a Board definition:
101+
```c++
102+
const BoardConfig BOARD_EXTERNAL_CONFIG = {
103+
/* General */
104+
.name = "ESP_PANEL_BOARD_NAME",
105+
.lcd = BoardConfig::LCD_Config{
106+
.bus_config = esp_panel::drivers::BusSPI::Config{
107+
.host_id = 1,
108+
// Host
109+
.host = esp_panel::drivers::BusSPI::HostPartialConfig{
110+
.mosi_io_num = 6, //ESP_PANEL_BOARD_LCD_SPI_IO_MOSI,
111+
.miso_io_num = 8, //ESP_PANEL_BOARD_LCD_SPI_IO_MISO,
112+
.sclk_io_num = 7, //ESP_PANEL_BOARD_LCD_SPI_IO_SCK,
113+
},
114+
// Control Panel
115+
.control_panel = esp_panel::drivers::BusSPI::ControlPanelPartialConfig{
116+
.cs_gpio_num = 5, //ESP_PANEL_BOARD_LCD_SPI_IO_CS,
117+
.dc_gpio_num = 4, //ESP_PANEL_BOARD_LCD_SPI_IO_DC,
118+
.spi_mode = 0, //ESP_PANEL_BOARD_LCD_SPI_MODE,
119+
.pclk_hz = 40 * 1000 * 1000, //ESP_PANEL_BOARD_LCD_SPI_CLK_HZ,
120+
.lcd_cmd_bits = 8, //ESP_PANEL_BOARD_LCD_SPI_CMD_BITS,
121+
.lcd_param_bits = 8, //ESP_PANEL_BOARD_LCD_SPI_PARAM_BITS,
122+
},
123+
},
124+
.device_name = "ILI9341",
125+
.device_config = {
126+
// Device
127+
.device = esp_panel::drivers::LCD::DevicePartialConfig{
128+
.reset_gpio_num = 48, //ESP_PANEL_BOARD_LCD_RST_IO,
129+
.rgb_ele_order = 0, //ESP_PANEL_BOARD_LCD_COLOR_BGR_ORDER,
130+
.bits_per_pixel = 18, //ESP_PANEL_BOARD_LCD_COLOR_BITS, 16/18/24
131+
.flags_reset_active_high = 0, //ESP_PANEL_BOARD_LCD_RST_LEVEL,
132+
},
133+
// Vendor
134+
.vendor = esp_panel::drivers::LCD::VendorPartialConfig{
135+
.hor_res = 320, //ESP_PANEL_BOARD_WIDTH,
136+
.ver_res = 480, //ESP_PANEL_BOARD_HEIGHT,
137+
},
138+
},
139+
.pre_process = {
140+
.invert_color = 0, //ESP_PANEL_BOARD_LCD_COLOR_INEVRT_BIT,
141+
},
142+
},
143+
};
144+
```
145+
Then replace the constructor
146+
```c++
147+
self->board = utils::make_shared<Board>()
148+
```
149+
with
150+
```c++
151+
self->board = utils::make_shared<Board>(BOARD_EXTERNAL_CONFIG);
152+
```
153+
9. Edit esp_panel_drivers_conf.h
154+
Edit ESP32_Display_Panel/esp_panel_drivers_conf.h and ensure, the drivers referenced in your board config are being
155+
build. Warning: ESP_PANEL_DRIVERS_BUS_USE_ALL does not seem to work. Set to 0 and manually include the bus driver
156+
you need. Same goes for ESP_PANEL_DRIVERS_BUS_COMPILE_UNUSED_DRIVERS.
157+
158+
10. Repeat Step 6 to rebuild micropython
159+
160+
11. Test your display
161+
Connect to your board and run:
162+
```python
163+
from esp_panel import Board
164+
board = Board()
165+
board.init()
166+
board.begin()
167+
board.color_bar_test()
168+
```
169+
170+
12. Profit! :)
171+
172+
To include touch support, see ESP32_Display_Panel/examples/arduino/board/board_dynamic_config/board_external_config.cpp
173+
for an example touch definition.
174+
175+
176+
## Known Pitfalls
177+
178+
1. When board.init() returns false, likely your driver-definition in esp_panel_drivers_conf.h does not match.
179+
2. board.begin() crashes, if you rely on ESP_PANEL_DRIVERS_BUS_USE_ALL
180+
3. If you edit ESP32_Display_Panel/esp_panel_drivers_conf.h, also modify ESP32_Display_Panel/mpy_support/esp_panel_mp_board.cpp
181+
(like add or remove an empty line). Otherwise, changes to esp_panel_drivers_conf.h will not be recognized.

0 commit comments

Comments
 (0)