Skip to content

Commit 2fd873d

Browse files
committed
prefect: Optimize the call relationship between objects
Signed-off-by: lbuque <[email protected]>
1 parent c09cc5f commit 2fd873d

13 files changed

+383
-323
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Supported boards:
2727

2828
- [LILYGO T-DisplayS3](https://github.com/Xinyuan-LilyGO/T-Display-S3)
2929
- [LILYGO T-RGB](https://github.com/Xinyuan-LilyGO/T-RGB)
30-
- [LILYGO T-Displat](https://github.com/Xinyuan-LilyGO/TTGO-T-Display)
30+
- [LILYGO T-Display](https://github.com/Xinyuan-LilyGO/TTGO-T-Display)
3131

3232
## Documentation
3333

docs/en/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ esp32
4040

4141
.. note::
4242

43-
Please prepare esp-idf v4.4.2 before compiling
43+
Please prepare `esp-idf release/v4.4 <https://github.com/espressif/esp-idf/tree/release/v4.4>`_ before compiling
4444

4545
For more detailed compilation of esp32, please refer to https://github.com/micropython/micropython/tree/master/ports/esp32
4646

docs/en/lcd.ST7789.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Methods
3434

3535
Before calling this method, make sure the LCD panel has finished the reset stage by ST7789.reset().
3636

37-
.. method:: ST7789.bitmap(x_start, y_start, x_end, y_end, color_data)
37+
.. method:: ST7789.bitmap(x_start: int, y_start: int, x_end: int, y_end: int, color_data: bytes=None)
3838

3939
Draw bitmap on LCD panel.
4040

@@ -112,7 +112,7 @@ Methods
112112

113113
Deinitialize the LCD panel.
114114

115-
.. method:: rotation(r: int)
115+
.. method:: ST7789。rotation(r: int)
116116

117117
Set the rotates the logical display in a counter-clockwise direction.
118118

docs/zh_CN/index.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ esp32
4040

4141
.. note::
4242

43-
编译前请准备好esp-idf v4.4.2
43+
编译前请准备好`esp-idf release/v4.4 <https://github.com/espressif/esp-idf/tree/release/v4.4>`_
4444

45-
关于esp32更详细的编译说,请参考 https://github.com/micropython/micropython/tree/master/ports/esp32
45+
关于esp32更详细的编译说明,请参考 https://github.com/micropython/micropython/tree/master/ports/esp32
4646

4747
.. code-block:: shell
4848

docs/zh_CN/lcd.ST7789.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Methods
3434

3535
在调用此方法之前,请确保 LCD 面板已通过 RGB.reset() 完成重置阶段。
3636

37-
.. method:: ST7789.bitmap(x_start, y_start, x_end, y_end, color_data)
37+
.. method:: ST7789.bitmap(x_start: int, y_start: int, x_end: int, y_end: int, color_data: bytes=None)
3838

3939
在 LCD 面板上绘制位图。
4040

lcd/hal/esp32.c

+148-63
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "esp32.h"
22

3+
#include "spi_panel.h"
4+
#include "i80_panel.h"
5+
36
#include "esp_lcd_panel_io.h"
47
#include "esp_lcd_panel_vendor.h"
58
#include "esp_lcd_panel_ops.h"
@@ -10,84 +13,130 @@
1013

1114
#define DEBUG_printf(...) // mp_printf(&mp_plat_print, __VA_ARGS__);
1215

13-
void hal_lcd_spi_panel_construct(lcd_spi_panel_obj_t *self) {
14-
machine_hw_spi_obj_t *spi_obj = ((machine_hw_spi_obj_t *)self->spi_obj);
15-
// if (spi_obj == NULL) {
16-
// mp_raise_msg_varg(&mp_type_OSError, "null");
17-
// }
18-
// machine_hw_spi_deinit_internal(spi_obj);
19-
// spi_bus_config_t buscfg = {
20-
// .sclk_io_num = spi_obj->sck,
21-
// .mosi_io_num = spi_obj->mosi,
22-
// .miso_io_num = -1,
23-
// .quadwp_io_num = -1,
24-
// .quadhd_io_num = -1,
25-
// .max_transfer_sz = self->width * self->height * 2 + 8
26-
// };
27-
// esp_err_t ret = spi_bus_initialize(spi_obj->host, &buscfg, SPI_DMA_CH_AUTO);
28-
// if (ret != 0) {
29-
// mp_raise_msg_varg(&mp_type_OSError, "%d(spi_bus_initialize)", ret);
30-
// }
16+
void hal_lcd_spi_panel_construct(mp_obj_base_t *self) {
17+
lcd_spi_panel_obj_t *spi_panel_obj = (lcd_spi_panel_obj_t *)self;
18+
machine_hw_spi_obj_t *spi_obj = ((machine_hw_spi_obj_t *)spi_panel_obj->spi_obj);
19+
if (spi_obj->state == MACHINE_HW_SPI_STATE_INIT) {
20+
spi_obj->state = MACHINE_HW_SPI_STATE_DEINIT;
21+
machine_hw_spi_deinit_internal(spi_obj);
22+
}
23+
spi_bus_config_t buscfg = {
24+
.sclk_io_num = spi_obj->sck,
25+
.mosi_io_num = spi_obj->mosi,
26+
.miso_io_num = -1,
27+
.quadwp_io_num = -1,
28+
.quadhd_io_num = -1,
29+
#if CONFIG_ESP32_SPIRAM_SUPPORT
30+
.max_transfer_sz = spi_panel_obj->width * spi_panel_obj->height * 2 + 8,
31+
#else
32+
.max_transfer_sz = spi_panel_obj->width * 2 + 8,
33+
#endif
34+
};
35+
esp_err_t ret = spi_bus_initialize(spi_obj->host, &buscfg, SPI_DMA_CH_AUTO);
36+
if (ret != 0) {
37+
mp_raise_msg_varg(&mp_type_OSError, "%d(spi_bus_initialize)", ret);
38+
}
39+
spi_obj->state = MACHINE_HW_SPI_STATE_INIT;
3140

3241
esp_lcd_panel_io_spi_config_t io_config = {
33-
.dc_gpio_num = mp_hal_get_pin_obj(self->dc),
34-
.cs_gpio_num = mp_hal_get_pin_obj(self->cs),
35-
.pclk_hz = self->pclk,
36-
.lcd_cmd_bits = self->cmd_bits,
37-
.lcd_param_bits = self->param_bits,
42+
.dc_gpio_num = mp_hal_get_pin_obj(spi_panel_obj->dc),
43+
.cs_gpio_num = mp_hal_get_pin_obj(spi_panel_obj->cs),
44+
.pclk_hz = spi_panel_obj->pclk,
45+
.lcd_cmd_bits = spi_panel_obj->cmd_bits,
46+
.lcd_param_bits = spi_panel_obj->param_bits,
3847
.spi_mode = 0,
39-
.trans_queue_depth = 4,
48+
.trans_queue_depth = 10,
4049
};
4150

4251
// Attach the LCD to the SPI bus
43-
esp_err_t ret = esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)spi_obj->host, &io_config, &self->io_handle);
52+
ret = esp_lcd_new_panel_io_spi(
53+
(esp_lcd_spi_bus_handle_t)spi_obj->host,
54+
&io_config,
55+
&spi_panel_obj->io_handle
56+
);
4457
if (ret != 0) {
4558
mp_raise_msg_varg(&mp_type_OSError, "%d(esp_lcd_new_panel_io_spi)", ret);
4659
}
4760
}
4861

4962

50-
inline void hal_lcd_spi_panel_tx_param(lcd_spi_panel_obj_t *self, int lcd_cmd, const void *param, size_t param_size) {
63+
inline void hal_lcd_spi_panel_tx_param(
64+
mp_obj_base_t *self,
65+
int lcd_cmd,
66+
const void *param,
67+
size_t param_size
68+
) {
5169
DEBUG_printf("tx_param cmd: %x, param_size: %u\n", lcd_cmd, param_size);
52-
esp_lcd_panel_io_tx_param(self->io_handle, lcd_cmd, param, param_size);
70+
71+
lcd_spi_panel_obj_t *spi_panel_obj = (lcd_spi_panel_obj_t *)self;
72+
esp_lcd_panel_io_tx_param(spi_panel_obj->io_handle, lcd_cmd, param, param_size);
5373
}
5474

5575

56-
inline void hal_lcd_spi_panel_tx_color(lcd_spi_panel_obj_t *self, int lcd_cmd, const void *color, size_t color_size) {
76+
inline void hal_lcd_spi_panel_tx_color(
77+
mp_obj_base_t *self,
78+
int lcd_cmd,
79+
const void *color,
80+
size_t color_size
81+
) {
5782
DEBUG_printf("tx_color cmd: %x, color_size: %u\n", lcd_cmd, color_size);
58-
esp_lcd_panel_io_tx_color(self->io_handle, lcd_cmd, color, color_size);
83+
lcd_spi_panel_obj_t *spi_panel_obj = (lcd_spi_panel_obj_t *)self;
84+
85+
#if CONFIG_ESP32_SPIRAM_SUPPORT
86+
esp_lcd_panel_io_tx_color(spi_panel_obj->io_handle, lcd_cmd, color, color_size);
87+
#else
88+
size_t i = 0;
89+
esp_lcd_panel_io_tx_param(spi_panel_obj->io_handle, lcd_cmd, NULL, 0);
90+
91+
for (i = 0; i < (color_size / (spi_panel_obj->width * 2)); i++) {
92+
esp_lcd_panel_io_tx_color(
93+
spi_panel_obj->io_handle,
94+
-1,
95+
(const void *)&((const uint8_t *)color)[i * spi_panel_obj->width * 2],
96+
spi_panel_obj->width * 2
97+
);
98+
}
99+
esp_lcd_panel_io_tx_color(
100+
spi_panel_obj->io_handle,
101+
-1,
102+
(const void *)&((const uint8_t *)color)[i * spi_panel_obj->width * 2],
103+
color_size - (i * spi_panel_obj->width * 2)
104+
);
105+
#endif
59106
}
60107

61108

62-
inline void hal_lcd_spi_panel_deinit(lcd_spi_panel_obj_t *self) {
63-
esp_lcd_panel_io_del(self->io_handle);
109+
inline void hal_lcd_spi_panel_deinit(mp_obj_base_t *self) {
110+
lcd_spi_panel_obj_t *spi_panel_obj = (lcd_spi_panel_obj_t *)self;
111+
esp_lcd_panel_io_del(spi_panel_obj->io_handle);
64112
}
65113

66114

67-
void hal_lcd_i80_construct(lcd_i80_obj_t *self) {
115+
void hal_lcd_i80_construct(mp_obj_base_t *self) {
116+
lcd_i80_obj_t *i80_obj = (lcd_i80_obj_t *)self;
68117
esp_lcd_i80_bus_config_t bus_config = {
69-
.dc_gpio_num = mp_hal_get_pin_obj(self->dc),
70-
.wr_gpio_num = mp_hal_get_pin_obj(self->wr),
118+
.dc_gpio_num = mp_hal_get_pin_obj(i80_obj->dc),
119+
.wr_gpio_num = mp_hal_get_pin_obj(i80_obj->wr),
71120
.clk_src = LCD_CLK_SRC_PLL160M,
72121
.data_gpio_nums = {
73-
mp_hal_get_pin_obj(self->databus[0]),
74-
mp_hal_get_pin_obj(self->databus[1]),
75-
mp_hal_get_pin_obj(self->databus[2]),
76-
mp_hal_get_pin_obj(self->databus[3]),
77-
mp_hal_get_pin_obj(self->databus[4]),
78-
mp_hal_get_pin_obj(self->databus[5]),
79-
mp_hal_get_pin_obj(self->databus[6]),
80-
mp_hal_get_pin_obj(self->databus[7]),
122+
mp_hal_get_pin_obj(i80_obj->databus[0]),
123+
mp_hal_get_pin_obj(i80_obj->databus[1]),
124+
mp_hal_get_pin_obj(i80_obj->databus[2]),
125+
mp_hal_get_pin_obj(i80_obj->databus[3]),
126+
mp_hal_get_pin_obj(i80_obj->databus[4]),
127+
mp_hal_get_pin_obj(i80_obj->databus[5]),
128+
mp_hal_get_pin_obj(i80_obj->databus[6]),
129+
mp_hal_get_pin_obj(i80_obj->databus[7]),
81130
},
82-
.bus_width = self->bus_width,
83-
.max_transfer_bytes = self->width * self->height * sizeof(uint16_t)
131+
.bus_width = i80_obj->bus_width,
132+
.max_transfer_bytes = i80_obj->width * i80_obj->height * sizeof(uint16_t)
84133
};
85-
esp_err_t ret = esp_lcd_new_i80_bus(&bus_config, &self->i80_bus);
134+
esp_err_t ret = esp_lcd_new_i80_bus(&bus_config, &i80_obj->i80_bus);
86135
if (ret != 0) {
87136
mp_raise_msg_varg(&mp_type_OSError, "%d(esp_lcd_new_i80_bus)", ret);
88137
}
89138
esp_lcd_panel_io_i80_config_t io_config = {
90-
.pclk_hz = self->pclk,
139+
.pclk_hz = i80_obj->pclk,
91140
.trans_queue_depth = 10,
92141
.dc_levels = {
93142
.dc_idle_level = 0,
@@ -96,38 +145,53 @@ void hal_lcd_i80_construct(lcd_i80_obj_t *self) {
96145
.dc_data_level = 1,
97146
},
98147
.flags = {
99-
.swap_color_bytes = self->swap_color_bytes,
148+
.swap_color_bytes = i80_obj->swap_color_bytes,
100149
},
101-
.lcd_cmd_bits = self->cmd_bits,
102-
.lcd_param_bits = self->param_bits,
150+
.lcd_cmd_bits = i80_obj->cmd_bits,
151+
.lcd_param_bits = i80_obj->param_bits,
103152
};
104-
if (self->cs != MP_OBJ_NULL) {
105-
io_config.cs_gpio_num = mp_hal_get_pin_obj(self->cs);
153+
if (i80_obj->cs != MP_OBJ_NULL) {
154+
io_config.cs_gpio_num = mp_hal_get_pin_obj(i80_obj->cs);
106155
} else {
107156
io_config.cs_gpio_num = -1;
108157
}
109-
ret = esp_lcd_new_panel_io_i80(self->i80_bus, &io_config, &self->io_handle);
158+
ret = esp_lcd_new_panel_io_i80(i80_obj->i80_bus, &io_config, &i80_obj->io_handle);
110159
if (ret != 0) {
111160
mp_raise_msg_varg(&mp_type_OSError, "%d(esp_lcd_new_panel_io_i80)", ret);
112161
}
113162
}
114163

115164

116-
inline void hal_lcd_i80_tx_param(lcd_i80_obj_t *self, int lcd_cmd, const void *param, size_t param_size) {
165+
inline void hal_lcd_i80_tx_param(
166+
mp_obj_base_t *self,
167+
int lcd_cmd,
168+
const void *param,
169+
size_t param_size
170+
) {
117171
DEBUG_printf("tx_param cmd: %x, param_size: %u\n", lcd_cmd, param_size);
118-
esp_lcd_panel_io_tx_param(self->io_handle, lcd_cmd, param, param_size);
172+
173+
lcd_i80_obj_t *i80_obj = (lcd_i80_obj_t *)self;
174+
esp_lcd_panel_io_tx_param(i80_obj->io_handle, lcd_cmd, param, param_size);
119175
}
120176

121177

122-
inline void hal_lcd_i80_tx_color(lcd_i80_obj_t *self, int lcd_cmd, const void *color, size_t color_size) {
178+
inline void hal_lcd_i80_tx_color(
179+
mp_obj_base_t *self,
180+
int lcd_cmd,
181+
const void *color,
182+
size_t color_size
183+
) {
123184
DEBUG_printf("tx_color cmd: %x, color_size: %u\n", lcd_cmd, color_size);
124-
esp_lcd_panel_io_tx_color(self->io_handle, lcd_cmd, color, color_size);
185+
186+
lcd_i80_obj_t *i80_obj = (lcd_i80_obj_t *)self;
187+
esp_lcd_panel_io_tx_color(i80_obj->io_handle, lcd_cmd, color, color_size);
125188
}
126189

127190

128-
inline void hal_lcd_i80_deinit(lcd_i80_obj_t *self) {
129-
esp_lcd_panel_io_del(self->io_handle);
130-
esp_lcd_del_i80_bus(self->i80_bus);
191+
inline void hal_lcd_i80_deinit(mp_obj_base_t *self) {
192+
lcd_i80_obj_t *i80_obj = (lcd_i80_obj_t *)self;
193+
esp_lcd_panel_io_del(i80_obj->io_handle);
194+
esp_lcd_del_i80_bus(i80_obj->i80_bus);
131195
}
132196

133197

@@ -211,12 +275,30 @@ inline void hal_lcd_rgb_del(lcd_rgb_obj_t *self) {
211275
}
212276

213277

214-
inline void hal_lcd_rgb_bitmap(lcd_rgb_obj_t *self, int x_start, int y_start, int x_end, int y_end, const void *color_data) {
215-
esp_lcd_panel_draw_bitmap(self->panel_handle, x_start, y_start, x_end, y_end, color_data);
278+
inline void hal_lcd_rgb_bitmap(
279+
lcd_rgb_obj_t *self,
280+
int x_start,
281+
int y_start,
282+
int x_end,
283+
int y_end,
284+
const void *color_data
285+
) {
286+
esp_lcd_panel_draw_bitmap(
287+
self->panel_handle,
288+
x_start,
289+
y_start,
290+
x_end,
291+
y_end,
292+
color_data
293+
);
216294
}
217295

218296

219-
inline void hal_lcd_rgb_mirror(lcd_rgb_obj_t *self, bool mirror_x, bool mirror_y) {
297+
inline void hal_lcd_rgb_mirror(
298+
lcd_rgb_obj_t *self,
299+
bool mirror_x,
300+
bool mirror_y
301+
) {
220302
esp_lcd_panel_mirror(self->panel_handle, mirror_x, mirror_y);
221303
}
222304

@@ -231,7 +313,10 @@ inline void hal_lcd_rgb_set_gap(lcd_rgb_obj_t *self, int x_gap, int y_gap) {
231313
}
232314

233315

234-
inline void hal_lcd_rgb_invert_color(lcd_rgb_obj_t *self, bool invert_color_data) {
316+
inline void hal_lcd_rgb_invert_color(
317+
lcd_rgb_obj_t *self,
318+
bool invert_color_data
319+
) {
235320
esp_lcd_panel_invert_color(self->panel_handle, invert_color_data);
236321
}
237322

0 commit comments

Comments
 (0)