Skip to content

Commit 0f5b4ff

Browse files
committed
Revert "code cleanup and some memory optimizations."
This reverts commit 8eed5c9.
1 parent 8eed5c9 commit 0f5b4ff

File tree

24 files changed

+638
-273
lines changed

24 files changed

+638
-273
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef _I2C_BUS_H_
2+
#define _I2C_BUS_H_
3+
4+
//local_includes
5+
#include "modlcd_bus.h"
6+
7+
// micropython includes
8+
#include "py/obj.h"
9+
#include "py/runtime.h"
10+
11+
12+
typedef struct _mp_lcd_i2c_bus_obj_t {
13+
mp_obj_base_t base;
14+
15+
mp_obj_t callback;
16+
17+
void *buf1;
18+
void *buf2;
19+
uint32_t buffer_flags;
20+
21+
bool trans_done;
22+
bool rgb565_byte_swap;
23+
24+
lcd_panel_io_t panel_io_handle;
25+
void *panel_io_config;
26+
void *bus_config;
27+
void *bus_handle;
28+
29+
int host;
30+
31+
} mp_lcd_i2c_bus_obj_t;
32+
33+
extern const mp_obj_type_t mp_lcd_i2c_bus_type;
34+
#endif /* _I2C_BUS_H_ */

ext_mod/lcd_bus/common_include/i80_bus.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
bool trans_done;
2727
bool rgb565_byte_swap;
2828

29-
uint8_t lane_count;
30-
3129
lcd_panel_io_t panel_io_handle;
3230

3331
void *panel_io_config;

ext_mod/lcd_bus/common_include/rgb_bus.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
bool trans_done;
2222
bool rgb565_byte_swap;
2323

24-
uint8_t lane_count;
25-
2624
lcd_panel_io_t panel_io_handle;
2725

2826
void *panel_io_config;

ext_mod/lcd_bus/common_include/spi_bus.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
bool trans_done;
2626
bool rgb565_byte_swap;
2727

28-
uint8_t lane_count;
29-
3028
lcd_panel_io_t panel_io_handle;
3129
void * panel_io_config;
3230

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// local includes
2+
#include "lcd_types.h"
3+
#include "modlcd_bus.h"
4+
#include "i2c_bus.h"
5+
6+
// micropython includes
7+
#include "py/obj.h"
8+
#include "py/runtime.h"
9+
10+
// stdlib includes
11+
#include <string.h>
12+
13+
14+
static mp_obj_t mp_lcd_i2c_bus_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
15+
{
16+
LCD_UNUSED(type);
17+
LCD_UNUSED(n_args);
18+
LCD_UNUSED(n_kw);
19+
LCD_UNUSED(all_args);
20+
21+
mp_raise_msg(&mp_type_NotImplementedError, MP_ERROR_TEXT("I2C display bus is not supported"));
22+
return mp_const_none;
23+
}
24+
25+
26+
MP_DEFINE_CONST_OBJ_TYPE(
27+
mp_lcd_i2c_bus_type,
28+
MP_QSTR_I2CBus,
29+
MP_TYPE_FLAG_NONE,
30+
make_new, mp_lcd_i2c_bus_make_new,
31+
locals_dict, (mp_obj_dict_t *)&mp_lcd_bus_locals_dict
32+
);
33+

ext_mod/lcd_bus/common_src/i80_bus.c

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
mp_lcd_err_t i80_tx_color(mp_obj_t obj, int lcd_cmd, void *color, size_t color_size, int x_start, int y_start, int x_end, int y_end);
8080
mp_lcd_err_t i80_del(mp_obj_t obj);
8181
mp_lcd_err_t i80_init(mp_obj_t obj, uint16_t width, uint16_t height, uint8_t bpp, uint32_t buffer_size, bool rgb565_byte_swap, uint8_t cmd_bits, uint8_t param_bits);
82+
mp_lcd_err_t i80_get_lane_count(mp_obj_t obj, uint8_t *lane_count);
8283

8384
void write_color8(mp_lcd_i80_bus_obj_t *self, void *color, size_t color_size);
8485
void write_color16(mp_lcd_i80_bus_obj_t *self, void *color, size_t color_size);
@@ -102,7 +103,22 @@
102103
enum {
103104
ARG_dc,
104105
ARG_wr,
105-
ARG_data_pins,
106+
ARG_data0,
107+
ARG_data1,
108+
ARG_data2,
109+
ARG_data3,
110+
ARG_data4,
111+
ARG_data5,
112+
ARG_data6,
113+
ARG_data7,
114+
ARG_data8,
115+
ARG_data9,
116+
ARG_data10,
117+
ARG_data11,
118+
ARG_data12,
119+
ARG_data13,
120+
ARG_data14,
121+
ARG_data15,
106122
ARG_cs,
107123
ARG_freq,
108124
ARG_dc_idle_high,
@@ -113,6 +129,7 @@
113129
ARG_param_bits,
114130
ARG_cs_active_high,
115131
ARG_reverse_color_bits,
132+
ARG_swap_color_bytes,
116133
ARG_pclk_active_low,
117134
ARG_pclk_idle_low,
118135
};
@@ -134,7 +151,22 @@
134151
const mp_arg_t make_new_args[] = {
135152
{ MP_QSTR_dc, MP_ARG_OBJ | MP_ARG_REQUIRED },
136153
{ MP_QSTR_wr, MP_ARG_OBJ | MP_ARG_REQUIRED },
137-
{ MP_QSTR_data_pins, MP_ARG_OBJ | MP_ARG_REQUIRED },
154+
{ MP_QSTR_data0, MP_ARG_OBJ | MP_ARG_REQUIRED },
155+
{ MP_QSTR_data1, MP_ARG_OBJ | MP_ARG_REQUIRED },
156+
{ MP_QSTR_data2, MP_ARG_OBJ | MP_ARG_REQUIRED },
157+
{ MP_QSTR_data3, MP_ARG_OBJ | MP_ARG_REQUIRED },
158+
{ MP_QSTR_data4, MP_ARG_OBJ | MP_ARG_REQUIRED },
159+
{ MP_QSTR_data5, MP_ARG_OBJ | MP_ARG_REQUIRED },
160+
{ MP_QSTR_data6, MP_ARG_OBJ | MP_ARG_REQUIRED },
161+
{ MP_QSTR_data7, MP_ARG_OBJ | MP_ARG_REQUIRED },
162+
{ MP_QSTR_data8, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
163+
{ MP_QSTR_data9, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
164+
{ MP_QSTR_data10, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
165+
{ MP_QSTR_data11, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
166+
{ MP_QSTR_data12, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
167+
{ MP_QSTR_data13, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
168+
{ MP_QSTR_data14, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
169+
{ MP_QSTR_data15, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
138170
{ MP_QSTR_cs, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = mp_const_none } },
139171
{ MP_QSTR_freq, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 10000000 } },
140172
{ MP_QSTR_dc_idle_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
@@ -143,6 +175,7 @@
143175
{ MP_QSTR_dc_data_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = true } },
144176
{ MP_QSTR_cs_active_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
145177
{ MP_QSTR_reverse_color_bits, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
178+
{ MP_QSTR_swap_color_bytes, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
146179
{ MP_QSTR_pclk_active_low, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
147180
{ MP_QSTR_pclk_idle_low, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } }
148181
};
@@ -186,15 +219,28 @@
186219
mp_hal_pin_write(self->bus_config.dc_gpio_num, self->panel_io_config.dc_levels.dc_data_level);
187220
mp_hal_pin_write(self->bus_config.wr_gpio_num, 0);
188221

189-
mp_obj_tuple_t *data_pins = (mp_obj_tuple_t *)MP_OBJ_TO_PTR(args[ARG_data_pins].u_obj);
190-
191-
for (size_t i = 0; i < data_pins->len; i++) {
192-
self->bus_config.data_gpio_nums[i] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(data_pins->items[i]);
222+
self->bus_config.data_gpio_nums[0] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data0].u_obj);
223+
self->bus_config.data_gpio_nums[1] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data1].u_obj);
224+
self->bus_config.data_gpio_nums[2] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data2].u_obj);
225+
self->bus_config.data_gpio_nums[3] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data3].u_obj);
226+
self->bus_config.data_gpio_nums[4] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data4].u_obj);
227+
self->bus_config.data_gpio_nums[5] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data5].u_obj);
228+
self->bus_config.data_gpio_nums[6] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data6].u_obj);
229+
self->bus_config.data_gpio_nums[7] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data7].u_obj);
230+
if (args[ARG_data8].u_obj == mp_const_none) {
231+
self->bus_config.bus_width = 8;
232+
} else {
233+
self->bus_config.data_gpio_nums[8] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data8].u_obj);
234+
self->bus_config.data_gpio_nums[9] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data9].u_obj);
235+
self->bus_config.data_gpio_nums[10] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data10].u_obj);
236+
self->bus_config.data_gpio_nums[11] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data11].u_obj);
237+
self->bus_config.data_gpio_nums[12] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data12].u_obj);
238+
self->bus_config.data_gpio_nums[13] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data13].u_obj);
239+
self->bus_config.data_gpio_nums[14] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data14].u_obj);
240+
self->bus_config.data_gpio_nums[15] = (mp_hal_pin_obj_t)mp_hal_get_pin_obj(args[ARG_data15].u_obj);
241+
self->bus_config.bus_width = 16;
193242
}
194243

195-
self->bus_config.bus_width = (size_t)data_pins->len;
196-
self->lane_count = (uint8_t)self->bus_config.bus_width;
197-
198244
mp_hal_pin_obj_t pin;
199245

200246
for ( uint8_t i = 0; i < self->bus_config.bus_width; i++) {
@@ -223,6 +269,7 @@
223269
self->panel_io_handle.rx_param = i80_rx_param;
224270
self->panel_io_handle.del = i80_del;
225271
self->panel_io_handle.init = i80_init;
272+
self->panel_io_handle.get_lane_count = i80_get_lane_count;
226273
#endif /* defined(mp_hal_pin_output) || defined(IDF_VER) */
227274

228275
return MP_OBJ_FROM_PTR(self);
@@ -390,6 +437,15 @@
390437
return LCD_OK;
391438
}
392439

440+
441+
mp_lcd_err_t i80_get_lane_count(mp_obj_t obj, uint8_t *lane_count)
442+
{
443+
mp_lcd_i80_bus_obj_t *self = MP_OBJ_TO_PTR(obj);
444+
*lane_count = (uint8_t)self->bus_config.bus_width;
445+
return LCD_OK;
446+
}
447+
448+
393449
/* transfer functions */
394450
void write_color8(mp_lcd_i80_bus_obj_t *self, void *color, size_t color_size)
395451
{

ext_mod/lcd_bus/common_src/spi_bus.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
/* forward declarations */
7777
mp_lcd_err_t s_spi_del(mp_obj_t obj);
7878
mp_lcd_err_t s_spi_init(mp_obj_t obj, uint16_t width, uint16_t height, uint8_t bpp, uint32_t buffer_size, bool rgb565_byte_swap, uint8_t cmd_bits, uint8_t param_bits);
79+
mp_lcd_err_t s_spi_get_lane_count(mp_obj_t obj, uint8_t *lane_count);
7980
mp_lcd_err_t s_spi_rx_param(mp_obj_t obj, int lcd_cmd, void *param, size_t param_size);
8081
mp_lcd_err_t s_spi_tx_param(mp_obj_t obj, int lcd_cmd, void *param, size_t param_size);
8182
mp_lcd_err_t s_spi_tx_color(mp_obj_t obj, int lcd_cmd, void *color, size_t color_size, int x_start, int y_start, int x_end, int y_end);
@@ -142,7 +143,7 @@
142143
}
143144

144145
self->callback = mp_const_none;
145-
self->lane_count = 1;
146+
146147
self->host = (int)self->spi_bus->spi_bus->host;
147148

148149
self->panel_io_config.cs_gpio = args[ARG_cs].u_obj;
@@ -164,6 +165,7 @@
164165
self->panel_io_handle.tx_param = s_spi_tx_param;
165166
self->panel_io_handle.rx_param = s_spi_rx_param;
166167
self->panel_io_handle.tx_color = s_spi_tx_color;
168+
self->panel_io_handle.get_lane_count = s_spi_get_lane_count;
167169

168170
#endif /* !defined(IDF_VER) */
169171

@@ -228,6 +230,14 @@
228230
}
229231

230232

233+
mp_lcd_err_t s_spi_get_lane_count(mp_obj_t obj, uint8_t *lane_count)
234+
{
235+
LCD_UNUSED(obj);
236+
*lane_count = 1;
237+
return LCD_OK;
238+
}
239+
240+
231241
mp_lcd_err_t s_spi_rx_param(mp_obj_t obj, int lcd_cmd, void *param, size_t param_size)
232242
{
233243
mp_lcd_spi_bus_obj_t *self = MP_OBJ_TO_PTR(obj);

ext_mod/lcd_bus/esp32_include/dsi_bus.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
bool trans_done;
3434
bool rgb565_byte_swap;
3535

36-
uint8_t lane_count;
37-
3836
lcd_panel_io_t panel_io_handle;
3937

4038
esp_lcd_dbi_io_config_t panel_io_config;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef _ESP32_I2C_BUS_H_
2+
#define _ESP32_I2C_BUS_H_
3+
4+
//local_includes
5+
#include "lcd_types.h"
6+
7+
// esp-idf includes
8+
#include "esp_lcd_panel_io.h"
9+
#include "driver/i2c.h"
10+
11+
// micropython includes
12+
#include "mphalport.h"
13+
#include "py/obj.h"
14+
#include "py/objarray.h"
15+
16+
typedef struct _mp_lcd_i2c_bus_obj_t {
17+
mp_obj_base_t base;
18+
19+
mp_obj_t callback;
20+
21+
void *buf1;
22+
void *buf2;
23+
uint32_t buffer_flags;
24+
25+
bool trans_done;
26+
bool rgb565_byte_swap;
27+
28+
lcd_panel_io_t panel_io_handle;
29+
esp_lcd_panel_io_i2c_config_t panel_io_config;
30+
i2c_config_t bus_config;
31+
esp_lcd_i2c_bus_handle_t bus_handle;
32+
33+
int host;
34+
35+
} mp_lcd_i2c_bus_obj_t;
36+
37+
extern const mp_obj_type_t mp_lcd_i2c_bus_type;
38+
#endif /* _ESP32_I2C_BUS_H_ */

ext_mod/lcd_bus/esp32_include/i80_bus.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929
bool trans_done;
3030
bool rgb565_byte_swap;
3131

32-
uint8_t lane_count;
33-
3432
lcd_panel_io_t panel_io_handle;
3533

36-
esp_lcd_panel_io_i80_config_t *panel_io_config;
37-
esp_lcd_i80_bus_config_t *bus_config;
34+
esp_lcd_panel_io_i80_config_t panel_io_config;
35+
esp_lcd_i80_bus_config_t bus_config;
3836
esp_lcd_i80_bus_handle_t bus_handle;
3937
} mp_lcd_i80_bus_obj_t;
4038

0 commit comments

Comments
 (0)