Skip to content

Commit ef8b48b

Browse files
committed
feat(docs): support micropython
1 parent 4c1cdee commit ef8b48b

File tree

7 files changed

+254
-48
lines changed

7 files changed

+254
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +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)
48+
* [Micropython](./docs/envs/use_with_micropython.md)
4949

5050
## Supported Boards
5151

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ESP32_Display_Panel 的主要特性如下:
4545
* [ESP-IDF](./docs/envs/use_with_idf_cn.md)
4646
* [Arduino IDE](./docs/envs/use_with_arduino_cn.md)
4747
* [PlatformIO](./examples/platformio/lvgl_v8_port/README.md)
48+
* [Micropython](./docs/envs/use_with_micropython_cn.md)
4849

4950
## 支持的开发板
5051

mpy_support/README.md renamed to docs/envs/use_with_micropython.md

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Using with micropython
22

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-
3+
This is an example of how to integrate this library into micropython. It's written for an ESP32-S3, however it should be easy to adapt to different supported ESP-Chips. Please note, that you'll need at least 4mb of flash.
64

75
## Step-by-Step instructions
86

@@ -25,33 +23,36 @@ it should be easy to adapt to different supported ESP-Chips. Please note, that y
2523
```
2624

2725
2. Ensure, you can build a working firmware
28-
26+
2927
```bash
3028
make BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT -C ports/esp32
3129
pushd ports/esp32
3230
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
3331
popd
34-
popd
32+
popd
3533
```
3634
Now, test the board and ensure your build of micropython works.
3735

3836
3. Download ESP32_Display_Panel and it's dependencies
37+
3938
```bash
4039
git clone https://github.com/esp-arduino-libs/ESP32_Display_Panel.git
4140
git clone https://github.com/esp-arduino-libs/esp-lib-utils.git
4241
git clone https://github.com/esp-arduino-libs/ESP32_IO_Expander.git
4342
```
44-
43+
4544
4. Create a custom user-module definition
45+
4646
```bash
4747
cat > micropython.cmake << EOF
4848
include(~/esp32build/ESP32_Display_Panel/micropython.cmake)
4949
include(~/esp32build/esp-lib-utils/micropython.cmake)
5050
include(~/esp32build/ESP32_IO_Expander/micropython.cmake)
5151
EOF
5252
```
53-
53+
5454
5. Copy some header-files
55+
5556
```bash
5657
cp esp-idf/components/esp_lcd/include/esp_lcd_panel_commands.h ESP32_Display_Panel/mpy_support/
5758
cp esp-idf/components/esp_lcd/interface/esp_lcd_panel_interface.h ESP32_Display_Panel/mpy_support/
@@ -64,40 +65,46 @@ it should be easy to adapt to different supported ESP-Chips. Please note, that y
6465
```
6566
6667
6. Rebuild micropython to include the new modules
68+
6769
```bash
6870
pushd micropython
69-
make BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT USER_C_MODULES=~/esp32build/micropython.cmake -C ports/esp32
71+
make BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT USER_C_MODULES=~/esp32build/micropython.cmake -C ports/esp32
7072
pushd ports/esp32
7173
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
7274
popd
73-
popd
75+
popd
7476
```
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:
7877
79-
```csv
80-
factory, app, factory, 0x10000, 0x1F0000,
81-
vfs, data, fat, 0x200000, 0x200000,
78+
This may fail if your chip has a small flash size, in this case you have to increase the size of the application partition. E.g. for a 4mb flash chip edit *micropython/ports/esp32/partitions-4MiB.csv* and change the last two lines from:
79+
80+
```csv
81+
factory, app, factory, 0x10000, 0x1F0000,
82+
vfs, data, fat, 0x200000, 0x200000,
8283
```
83-
to
84-
```csv
85-
factory, app, factory, 0x10000, 0x2F0000,
86-
vfs, data, fat, 0x300000, 0x100000,
84+
85+
to
86+
87+
```csv
88+
factory, app, factory, 0x10000, 0x2F0000,
89+
vfs, data, fat, 0x300000, 0x100000,
8790
```
8891
8992
7. Test the module
90-
Connect to your board and run:
93+
94+
Connect to your board and run:
95+
9196
```python
92-
from esp_panel import Board
93-
board = Board()
94-
board.init()
97+
from esp_panel import Board
98+
board = Board()
99+
board.init()
95100
```
96-
board.init() should return False, as we yet have to define a board.
101+
102+
`board.init()` should return False, as we yet have to define a board.
97103
98104
8. Define your Board
99-
Edit ESP32_Display_Panel/mpy_support/esp_panel_mp_board.cpp.
100-
Add a Board definition:
105+
106+
Edit *ESP32_Display_Panel/mpy_support/esp_panel_mp_board.cpp*. Add a Board definition:
107+
101108
```c++
102109
const BoardConfig BOARD_EXTERNAL_CONFIG = {
103110
/* General */
@@ -142,40 +149,45 @@ it should be easy to adapt to different supported ESP-Chips. Please note, that y
142149
},
143150
};
144151
```
145-
Then replace the constructor
146-
```c++
147-
self->board = utils::make_shared<Board>()
152+
153+
Then replace the constructor
154+
155+
```c++
156+
self->board = utils::make_shared<Board>()
148157
```
149-
with
150-
```c++
151-
self->board = utils::make_shared<Board>(BOARD_EXTERNAL_CONFIG);
158+
159+
with
160+
161+
```c++
162+
self->board = utils::make_shared<Board>(BOARD_EXTERNAL_CONFIG);
152163
```
164+
153165
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.
157166
158-
10. Repeat Step 6 to rebuild micropython
167+
Edit *ESP32_Display_Panel/esp_panel_drivers_conf.h* and ensure, the drivers referenced in your board config are being
168+
build. **Warning**: `ESP_PANEL_DRIVERS_BUS_USE_ALL` does not seem to work. Set to 0 and manually include the bus driver
169+
you need. Same goes for `ESP_PANEL_DRIVERS_BUS_COMPILE_UNUSED_DRIVERS`.
170+
171+
10. Repeat **Step 6** to rebuild micropython
159172
160173
11. Test your display
174+
161175
Connect to your board and run:
176+
162177
```python
163178
from esp_panel import Board
164179
board = Board()
165180
board.init()
166181
board.begin()
167182
board.color_bar_test()
168183
```
169-
184+
170185
12. Profit! :)
171186
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-
187+
To include touch support, see *ESP32_Display_Panel/examples/arduino/board/board_dynamic_config/board_external_config.cpp* for an example touch definition.
175188
176189
## Known Pitfalls
177190
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.
191+
1. When `board.init()` returns false, likely your driver-definition in *esp_panel_drivers_conf.h* does not match.
192+
2. `board.begin()` crashes, if you rely on `ESP_PANEL_DRIVERS_BUS_USE_ALL`
193+
3. If you edit *ESP32_Display_Panel/esp_panel_drivers_conf.h*, also modify *ESP32_Display_Panel/mpy_support/esp_panel_mp_board.cpp* (like add or remove an empty line). Otherwise, changes to *esp_panel_drivers_conf.h* will not be recognized.

docs/envs/use_with_micropython_cn.md

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# 在 micropython 中使用
2+
3+
这是一个如何将此库集成到 micropython 的示例。它是为 ESP32-S3 编写的,但应该很容易适应不同的受支持的 ESP 芯片。请注意,您至少需要 4MB 的闪存。
4+
5+
## 逐步说明
6+
7+
1. 安装 IDF 和 micropython
8+
9+
```bash
10+
mkdir ~/esp32build
11+
pushd ~/esp32build
12+
git clone -b v5.2.2 --recursive https://github.com/espressif/esp-idf.git
13+
pushd esp-idf
14+
./install.sh esp32
15+
source export.sh
16+
popd
17+
git clone https://github.com/micropython/micropython.git
18+
pushd micropython
19+
git submodule update --init --recursive
20+
pushd mpy-cross
21+
make
22+
popd
23+
```
24+
25+
2. 确保您可以构建一个可工作的固件
26+
27+
```bash
28+
make BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT -C ports/esp32
29+
pushd ports/esp32
30+
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
31+
popd
32+
popd
33+
```
34+
现在,测试开发板并确保您构建的 micropython 可以正常工作。
35+
36+
3. 下载 ESP32_Display_Panel 及其依赖项
37+
38+
```bash
39+
git clone https://github.com/esp-arduino-libs/ESP32_Display_Panel.git
40+
git clone https://github.com/esp-arduino-libs/esp-lib-utils.git
41+
git clone https://github.com/esp-arduino-libs/ESP32_IO_Expander.git
42+
```
43+
44+
4. 创建自定义用户模块定义
45+
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. 复制一些头文件
55+
56+
```bash
57+
cp esp-idf/components/esp_lcd/include/esp_lcd_panel_commands.h ESP32_Display_Panel/mpy_support/
58+
cp esp-idf/components/esp_lcd/interface/esp_lcd_panel_interface.h ESP32_Display_Panel/mpy_support/
59+
cp esp-idf/components/esp_lcd/include/esp_lcd_panel_io.h ESP32_Display_Panel/mpy_support/
60+
cp esp-idf/components/esp_lcd/interface/esp_lcd_panel_io_interface.h ESP32_Display_Panel/mpy_support/
61+
cp esp-idf/components/esp_lcd/include/esp_lcd_panel_ops.h ESP32_Display_Panel/mpy_support/
62+
cp esp-idf/components/esp_lcd/include/esp_lcd_panel_rgb.h ESP32_Display_Panel/mpy_support/
63+
cp esp-idf/components/esp_lcd/include/esp_lcd_panel_vendor.h ESP32_Display_Panel/mpy_support/
64+
cp esp-idf/components/esp_lcd/include/esp_lcd_types.h ESP32_Display_Panel/mpy_support/
65+
```
66+
67+
6. 重新构建 micropython 以包含新模块
68+
69+
```bash
70+
pushd micropython
71+
make BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT USER_C_MODULES=~/esp32build/micropython.cmake -C ports/esp32
72+
pushd ports/esp32
73+
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
74+
popd
75+
popd
76+
```
77+
78+
如果您的芯片闪存大小较小,这可能会失败,在这种情况下,您必须增加应用程序分区的大小。例如,对于 4MB 闪存芯片,编辑 *micropython/ports/esp32/partitions-4MiB.csv* 并将最后两行从:
79+
80+
```csv
81+
factory, app, factory, 0x10000, 0x1F0000,
82+
vfs, data, fat, 0x200000, 0x200000,
83+
```
84+
85+
改为:
86+
87+
```csv
88+
factory, app, factory, 0x10000, 0x2F0000,
89+
vfs, data, fat, 0x300000, 0x100000,
90+
```
91+
92+
7. 测试模块
93+
94+
连接到您的开发板并运行:
95+
96+
```python
97+
from esp_panel import Board
98+
board = Board()
99+
board.init()
100+
```
101+
102+
`board.init()` 应该返回 False,因为我们还需要定义一个开发板。
103+
104+
8. 定义您的开发板
105+
106+
编辑 *ESP32_Display_Panel/mpy_support/esp_panel_mp_board.cpp*。添加一个开发板定义:
107+
108+
```c++
109+
const BoardConfig BOARD_EXTERNAL_CONFIG = {
110+
/* General */
111+
.name = "ESP_PANEL_BOARD_NAME",
112+
.lcd = BoardConfig::LCD_Config{
113+
.bus_config = esp_panel::drivers::BusSPI::Config{
114+
.host_id = 1,
115+
// Host
116+
.host = esp_panel::drivers::BusSPI::HostPartialConfig{
117+
.mosi_io_num = 6, //ESP_PANEL_BOARD_LCD_SPI_IO_MOSI,
118+
.miso_io_num = 8, //ESP_PANEL_BOARD_LCD_SPI_IO_MISO,
119+
.sclk_io_num = 7, //ESP_PANEL_BOARD_LCD_SPI_IO_SCK,
120+
},
121+
// Control Panel
122+
.control_panel = esp_panel::drivers::BusSPI::ControlPanelPartialConfig{
123+
.cs_gpio_num = 5, //ESP_PANEL_BOARD_LCD_SPI_IO_CS,
124+
.dc_gpio_num = 4, //ESP_PANEL_BOARD_LCD_SPI_IO_DC,
125+
.spi_mode = 0, //ESP_PANEL_BOARD_LCD_SPI_MODE,
126+
.pclk_hz = 40 * 1000 * 1000, //ESP_PANEL_BOARD_LCD_SPI_CLK_HZ,
127+
.lcd_cmd_bits = 8, //ESP_PANEL_BOARD_LCD_SPI_CMD_BITS,
128+
.lcd_param_bits = 8, //ESP_PANEL_BOARD_LCD_SPI_PARAM_BITS,
129+
},
130+
},
131+
.device_name = "ILI9341",
132+
.device_config = {
133+
// Device
134+
.device = esp_panel::drivers::LCD::DevicePartialConfig{
135+
.reset_gpio_num = 48, //ESP_PANEL_BOARD_LCD_RST_IO,
136+
.rgb_ele_order = 0, //ESP_PANEL_BOARD_LCD_COLOR_BGR_ORDER,
137+
.bits_per_pixel = 18, //ESP_PANEL_BOARD_LCD_COLOR_BITS, 16/18/24
138+
.flags_reset_active_high = 0, //ESP_PANEL_BOARD_LCD_RST_LEVEL,
139+
},
140+
// Vendor
141+
.vendor = esp_panel::drivers::LCD::VendorPartialConfig{
142+
.hor_res = 320, //ESP_PANEL_BOARD_WIDTH,
143+
.ver_res = 480, //ESP_PANEL_BOARD_HEIGHT,
144+
},
145+
},
146+
.pre_process = {
147+
.invert_color = 0, //ESP_PANEL_BOARD_LCD_COLOR_INEVRT_BIT,
148+
},
149+
},
150+
};
151+
```
152+
153+
然后替换构造函数
154+
155+
```c++
156+
self->board = utils::make_shared<Board>()
157+
```
158+
159+
160+
161+
```c++
162+
self->board = utils::make_shared<Board>(BOARD_EXTERNAL_CONFIG);
163+
```
164+
165+
9. 编辑 esp_panel_drivers_conf.h
166+
167+
编辑 *ESP32_Display_Panel/esp_panel_drivers_conf.h* 并确保在您的开发板配置中引用的驱动程序被构建。
168+
**警告**`ESP_PANEL_DRIVERS_BUS_USE_ALL` 似乎不起作用。设置为 0 并手动包含您需要的总线驱动程序。
169+
`ESP_PANEL_DRIVERS_BUS_COMPILE_UNUSED_DRIVERS` 也是如此。
170+
171+
10. 重复 **步骤 6** 重新构建 micropython
172+
173+
11. 测试您的显示屏
174+
175+
连接到您的开发板并运行:
176+
177+
```python
178+
from esp_panel import Board
179+
board = Board()
180+
board.init()
181+
board.begin()
182+
board.color_bar_test()
183+
```
184+
185+
12. 大功告成!:)
186+
187+
要包含触摸支持,请参阅 *ESP32_Display_Panel/examples/arduino/board/board_dynamic_config/board_external_config.cpp* 获取触摸定义示例。
188+
189+
## 已知陷阱
190+
191+
1. 当 `board.init()` 返回 false 时,很可能是您在 *esp_panel_drivers_conf.h* 中的驱动程序定义不匹配。
192+
2. 如果您依赖 `ESP_PANEL_DRIVERS_BUS_USE_ALL``board.begin()` 会崩溃。
193+
3. 如果您编辑 *ESP32_Display_Panel/esp_panel_drivers_conf.h*,还需要修改 *ESP32_Display_Panel/mpy_support/esp_panel_mp_board.cpp*(比如添加或删除一个空行)。否则,对 *esp_panel_drivers_conf.h* 的更改将不会被识别。

idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.0.2"
1+
version: "1.0.3"
22
description: ESP32_Display_Panel is a display driver and GUI porting library designed by Espressif specifically for ESP series SoCs (ESP32, ESP32-S3, ESP32-P4, etc.)
33
url: https://github.com/esp-arduino-libs/ESP32_Display_Panel
44
repository: https://github.com/esp-arduino-libs/ESP32_Display_Panel.git

0 commit comments

Comments
 (0)