Skip to content

Commit 5cc426f

Browse files
committed
Adds support for passing CONFIG_* settings to the ESP32 build.
Places critical LVGL function in IRAM for faster execution. Changes SPI Bus
1 parent d5f6fe2 commit 5cc426f

File tree

6 files changed

+362
-206
lines changed

6 files changed

+362
-206
lines changed

builder/unix.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def parse_args(extra_args, lv_cflags, board):
3131
unix_argParser.add_argument(
3232
'--heap-size',
3333
dest='heap_size',
34-
help="heap size to use in bytes. Default is 4mb (4,194,304 bytes). "
35-
"Must be more than 100k (102,104 bytes)",
36-
default=4194304,
34+
help="heap size to use in bytes. Default is 8MiB (8,388,608 bytes). "
35+
"Must be more than 100KiB (102,104 bytes)",
36+
default=(2 ** 20) * 8,
3737
type=int,
3838
action='store'
3939
)
@@ -88,7 +88,7 @@ def build_commands(_, extra_args, script_dir, lv_cflags, board):
8888
)
8989
])
9090

91-
unix_cmd.extend(extra_args)
91+
# unix_cmd.extend(extra_args)
9292

9393
clean_cmd.extend(unix_cmd[:])
9494
clean_cmd[1] = 'clean'
@@ -98,6 +98,7 @@ def build_commands(_, extra_args, script_dir, lv_cflags, board):
9898

9999
submodules_cmd.extend(unix_cmd[:])
100100
submodules_cmd[1] = 'submodules'
101+
return extra_args
101102

102103

103104
def build_manifest(
@@ -174,15 +175,15 @@ def submodules():
174175
]
175176
_run(cmd_)
176177

177-
cmd_ = ['cd lib/SDL && git checkout release-2.30.2']
178+
cmd_ = ['cd lib/SDL && git checkout release-2.30.2']
178179
_run(cmd_)
179180

180181
return_code, _ = spawn(submodules_cmd)
181182
if return_code != 0:
182183
sys.exit(return_code)
183184

184185

185-
def compile(): # NOQA
186+
def compile(*args): # NOQA
186187
main_path = 'lib/micropython/ports/unix/main.c'
187188

188189
with open(main_path, 'rb') as f:
@@ -242,7 +243,10 @@ def compile(): # NOQA
242243

243244
build_sdl()
244245

245-
return_code, _ = spawn(compile_cmd)
246+
cmd_ = compile_cmd[:]
247+
cmd_.extend(list(args))
248+
249+
return_code, _ = spawn(cmd_)
246250
if return_code != 0:
247251
sys.exit(return_code)
248252

ext_mod/lcd_bus/esp32_include/spi_bus.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
//local_includes
55
#include "lcd_types.h"
6+
#include "../../../micropy_updates/common/mp_spi_common.h"
67

78
// esp-idf includes
89
#include "esp_lcd_panel_io.h"
@@ -34,7 +35,7 @@
3435
esp_lcd_spi_bus_handle_t bus_handle;
3536

3637
spi_host_device_t host;
37-
38+
machine_hw_spi_device_obj_t spi_device;
3839
} mp_lcd_spi_bus_obj_t;
3940

4041
extern const mp_obj_type_t mp_lcd_spi_bus_type;

ext_mod/lcd_bus/esp32_src/spi_bus.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ typedef struct _machine_hw_spi_obj_t {
6262
mp_lcd_err_t spi_del(mp_obj_t obj);
6363
mp_lcd_err_t 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);
6464
mp_lcd_err_t spi_get_lane_count(mp_obj_t obj, uint8_t *lane_count);
65+
void spi_deinit_callback(machine_hw_spi_device_obj_t *device);
6566

6667

6768
static mp_obj_t mp_lcd_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
@@ -105,11 +106,11 @@ static mp_obj_t mp_lcd_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args
105106
mp_lcd_spi_bus_obj_t *self = m_new_obj(mp_lcd_spi_bus_obj_t);
106107
self->base.type = &mp_lcd_spi_bus_type;
107108

108-
machine_hw_spi_obj_t *spi_bus = MP_OBJ_TO_PTR(args[ARG_spi_bus].u_obj);
109+
machine_hw_spi_bus_obj_t *spi_bus = MP_OBJ_TO_PTR(args[ARG_spi_bus].u_obj);
109110

110111
self->callback = mp_const_none;
111112

112-
self->host = (spi_host_device_t)spi_bus->spi_bus->host;
113+
self->host = (spi_host_device_t)spi_bus->host;
113114
self->panel_io_handle.panel_io = NULL;
114115
self->bus_handle = (esp_lcd_spi_bus_handle_t)self->host;
115116

@@ -129,6 +130,12 @@ static mp_obj_t mp_lcd_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args
129130
self->panel_io_handle.init = &spi_init;
130131
self->panel_io_handle.get_lane_count = &spi_get_lane_count;
131132

133+
self->spi_device.active = true;
134+
self->spi_device.base.type = &machine_hw_spi_device_type;
135+
self->spi_device.spi_bus = spi_bus;
136+
self->spi_device.deinit = &spi_deinit_callback;
137+
self->spi_device.user_data = self;
138+
132139
#if CONFIG_LCD_ENABLE_DEBUG_LOG
133140
printf("host=%d\n", self->host);
134141
printf("cs_gpio_num=%d\n", self->panel_io_config.cs_gpio_num);
@@ -145,18 +152,34 @@ static mp_obj_t mp_lcd_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args
145152
return MP_OBJ_FROM_PTR(self);
146153
}
147154

155+
void spi_deinit_callback(machine_hw_spi_device_obj_t *device)
156+
{
157+
mp_lcd_spi_bus_obj_t *self = (mp_lcd_spi_bus_obj_t *)device->user_data;
158+
spi_del(MP_OBJ_FROM_PTR(self));
159+
}
160+
148161

149162
mp_lcd_err_t spi_del(mp_obj_t obj)
150163
{
151164
mp_lcd_spi_bus_obj_t *self = (mp_lcd_spi_bus_obj_t *)obj;
152165
#if CONFIG_LCD_ENABLE_DEBUG_LOG
153166
printf("spi_del(self)\n");
154167
#endif
168+
169+
if (!self->spi_device.active) return ESP_OK;
170+
155171
mp_lcd_err_t ret = esp_lcd_panel_io_del(self->panel_io_handle.panel_io);
156172
if (ret != ESP_OK) {
157173
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("%d(esp_lcd_panel_io_del)"), ret);
158174
}
159175

176+
machine_hw_spi_bus_remove_device(&self->spi_device);
177+
self->spi_device.active = false;
178+
179+
if (self->spi_device.spi_bus->device_count == 0) {
180+
self->spi_device.spi_bus->deinit(self->spi_device.spi_bus);
181+
}
182+
160183
return ret;
161184
}
162185

@@ -168,6 +191,10 @@ mp_lcd_err_t spi_init(mp_obj_t obj, uint16_t width, uint16_t height, uint8_t bpp
168191
#endif
169192
mp_lcd_spi_bus_obj_t *self = (mp_lcd_spi_bus_obj_t *)obj;
170193

194+
if (self->spi_device.spi_bus->state == MP_SPI_STATE_STOPPED) {
195+
machine_hw_spi_bus_initilize(self->spi_device.spi_bus);
196+
}
197+
171198
if (bpp == 16) {
172199
self->rgb565_byte_swap = rgb565_byte_swap;
173200
} else {
@@ -190,6 +217,7 @@ mp_lcd_err_t spi_init(mp_obj_t obj, uint16_t width, uint16_t height, uint8_t bpp
190217
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("%d(esp_lcd_new_panel_io_spi)"), ret);
191218
}
192219

220+
machine_hw_spi_bus_add_device(&self->spi_device);
193221
return ret;
194222
}
195223

micropy_updates/common/mp_spi_common.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,25 @@
1212
MP_SPI_STATE_SENDING
1313
} mp_spi_state_t;
1414

15-
typedef struct _machine_hw_spi_bus_obj_t {
15+
typedef struct _machine_hw_spi_bus_obj_t machine_hw_spi_bus_obj_t;
16+
typedef struct _machine_hw_spi_device_obj_t machine_hw_spi_device_obj_t;
17+
18+
struct _machine_hw_spi_bus_obj_t {
19+
mp_obj_base_t base;
1620
uint8_t host;
1721
mp_obj_t sck;
1822
mp_obj_t mosi;
1923
mp_obj_t miso;
20-
int16_t active_devices;
24+
uint8_t device_count;
25+
machine_hw_spi_device_obj_t **devices;
2126
mp_spi_state_t state;
2227
const void *user_data;
23-
} machine_hw_spi_bus_obj_t;
24-
28+
void (*deinit)(machine_hw_spi_bus_obj_t *bus);
29+
};
2530

26-
typedef struct _machine_hw_spi_obj_t {
31+
struct _machine_hw_spi_device_obj_t {
2732
mp_obj_base_t base;
28-
uint32_t baudrate;
33+
uint32_t freq;
2934
uint8_t polarity;
3035
uint8_t phase;
3136
uint8_t bits;
@@ -34,7 +39,15 @@
3439
mp_obj_t cs;
3540
machine_hw_spi_bus_obj_t *spi_bus;
3641
void *user_data;
37-
} machine_hw_spi_obj_t;
42+
void (*deinit)(machine_hw_spi_device_obj_t *device);
43+
};
44+
45+
void machine_hw_spi_bus_initilize(machine_hw_spi_bus_obj_t *bus);
46+
void machine_hw_spi_bus_add_device(machine_hw_spi_device_obj_t *device);
47+
void machine_hw_spi_bus_remove_device(machine_hw_spi_device_obj_t *device);
48+
49+
extern const mp_obj_type_t machine_hw_spi_device_type;
50+
extern const mp_obj_type_t machine_hw_spi_bus_type;
3851

3952
#endif /* __MP_SPI_COMMON_H__ */
4053

0 commit comments

Comments
 (0)