Skip to content

Commit d9d7ef3

Browse files
committed
messing with SPI and rotation
1 parent 820cff5 commit d9d7ef3

File tree

7 files changed

+35
-81
lines changed

7 files changed

+35
-81
lines changed

api_drivers/py_api_drivers/frozen/display/display_driver_framework.py

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,6 @@
4545
class DisplayDriver:
4646
_INVON = 0x21
4747
_INVOFF = 0x20
48-
49-
# Default values of "power" and "backlight" are reversed logic! 0 means ON.
50-
# You can change this by setting backlight_on and power_on arguments.
51-
#
52-
# For the ESP32 the allocation of the frame buffers can be done one of 2
53-
# ways depending on what is wanted in terms of performance VS memory use
54-
# If a single frame buffer is used then using a DMA transfer is pointless
55-
# to do. The frame buffer in this casse can be allocated as simple as
56-
#
57-
# buf = bytearray(buffer_size)
58-
#
59-
# If the user wants to be able to specify if the frame buffer is to be
60-
# created in internal memory (SRAM) or in external memory (PSRAM/SPIRAM)
61-
# this can be done using the heap_caps module.
62-
#
63-
# internal memory:
64-
# buf = heap_caps.malloc(buffer_size, heap_caps.CAP_INTERNAL)
65-
#
66-
# external memory:
67-
# buf = heap_caps.malloc(buffer_size, heap_caps.CAP_SPIRAM)
68-
#
69-
# If wanting to use DMA memory then use the bitwise OR "|" operator to add
70-
# the DMA flag to the last parameter of the malloc function
71-
#
72-
# buf = heap_caps.malloc(
73-
# buffer_size, heap_caps.CAP_INTERNAL | heap_caps.CAP_DMA
74-
# )
75-
7648
_displays = []
7749

7850
@staticmethod
@@ -223,10 +195,7 @@ def __init__(
223195
f'Unable to allocate memory for frame buffer ({buf_size})'
224196
)
225197

226-
if frame_buffer2 is None and isinstance(data_bus, lcd_bus.SPIBus):
227-
buffer_size = data_bus.SPI_MAXIMUM_BUFFER_SIZE
228-
229-
elif isinstance(data_bus, lcd_bus.RGBBus):
198+
if isinstance(data_bus, lcd_bus.RGBBus):
230199
buffer_size = int(
231200
display_width *
232201
display_height *
@@ -287,8 +256,9 @@ def __init__(
287256

288257
self.set_default()
289258

259+
self._disp_drv.add_event_cb(self._on_size_change, lv.EVENT.RESOLUTION_CHANGED, None) # NOQA
260+
290261
self._displays.append(self)
291-
self._disp_drv.add_event_cb(self._on_size_change, lv.EVENT.RESOLUTION_CHANGED, None) # NOQA
292262

293263
def _on_size_change(self, _):
294264
rotation = self._disp_drv.get_rotation()

api_drivers/py_api_drivers/frozen/indev/_indev_base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ def __init__(self): # NOQA
3636
'Display driver needs to initilized before indev driver'
3737
)
3838

39-
self._width = self._orig_width = self._disp_drv.get_horizontal_resolution()
40-
self._height = self._orig_height = self._disp_drv.get_vertical_resolution()
41-
self._rotation = self._disp_drv.get_rotation()
39+
self._width = self._disp_drv.get_horizontal_resolution()
40+
self._height = self._disp_drv.get_vertical_resolution()
4241
self._current_state = self.RELEASED
4342

4443
indev_drv = lv.indev_create()

api_drivers/py_api_drivers/frozen/indev/pointer_framework.py

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ def __init__(self, touch_cal=None): # NOQA
2222
self._cal = touch_cal
2323

2424
self._set_type(lv.INDEV_TYPE.POINTER) # NOQA
25+
26+
self._orig_width = self._disp_drv.get_horizontal_resolution()
27+
self._orig_height = self._disp_drv.get_vertical_resolution()
28+
self._rotation = self._disp_drv.get_rotation()
29+
30+
if self._rotation in (lv.DISPLAY_ROTATION._90, lv.DISPLAY_ROTATION._270): # NOQA
31+
self._orig_height, self._orig_width = self._orig_width, self._orig_height # NOQA
32+
2533
self._disp_drv.add_event_cb(self._on_size_change, lv.EVENT.RESOLUTION_CHANGED, None) # NOQA
2634

2735
def _on_size_change(self, e):
@@ -57,16 +65,13 @@ def _read(self, drv, data): # NOQA
5765
if coords is None: # ignore no touch & multi touch
5866
if self._current_state != self.RELEASED:
5967
self._current_state = self.RELEASED
60-
res = True
61-
else:
62-
res = False
6368

6469
data.point.x = self._last_x
6570
data.point.y = self._last_y
6671
data.state = self._current_state
6772
# print("raw(x={0}, y={1}) point(x={2} y={3})".format(-1, -1, data.point.x, data.point.y)) # NOQA
6873
data.continue_reading = False
69-
return res
74+
return
7075

7176
state, x, y = coords
7277

@@ -91,43 +96,24 @@ def _read(self, drv, data): # NOQA
9196
xpos = _remap(x, left, right, 0, self._orig_width)
9297
ypos = _remap(y, top, bottom, 0, self._orig_height)
9398
elif rotation == lv.DISPLAY_ROTATION._90: # NOQA
94-
xpos = _remap(y, top, bottom, 0, self._orig_width)
95-
ypos = _remap(x, right, left, 0, self._orig_height)
96-
elif rotation == lv.DISPLAY_ROTATION._270: # NOQA
99+
xpos = _remap(y, bottom, top, 0, self._orig_height)
100+
ypos = _remap(x, left, right, 0, self._orig_width)
101+
elif rotation == lv.DISPLAY_ROTATION._180: # NOQA
97102
xpos = _remap(x, right, left, 0, self._orig_width)
98103
ypos = _remap(y, bottom, top, 0, self._orig_height)
99-
elif rotation == lv.DISPLAY_ROTATION._180: # NOQA
100-
xpos = _remap(y, bottom, top, 0, self._orig_width)
101-
ypos = _remap(x, left, right, 0, self._orig_height)
104+
elif rotation == lv.DISPLAY_ROTATION._270: # NOQA
105+
xpos = _remap(y, top, bottom, 0, self._orig_height)
106+
ypos = _remap(x, right, left, 0, self._orig_width)
102107
else:
103108
raise RuntimeError
104109

105110
self._last_x = xpos
106111
self._last_y = ypos
107112

108-
if state is not None:
109-
if self._current_state == state == self.RELEASED:
110-
res = False
111-
data.continue_reading = False
112-
else:
113-
res = True
114-
data.continue_reading = True
115-
116-
self._current_state = state
117-
118-
elif self._current_state == self.RELEASED:
119-
res = False
120-
data.continue_reading = False
121-
else:
122-
data.continue_reading = True
123-
res = True
124-
125113
data.state = self._current_state
126114
data.point.x = self._last_x
127115
data.point.y = self._last_y
128116

129-
return res
130-
131117
def get_vect(self, point):
132118
self._indev_drv.get_vect(point)
133119

builder/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ def process_output(myproc, out_to_screen, spinner, cmpl, out_queue):
312312
line += out
313313
if out == b'\n':
314314
line = _convert_line(line.strip())
315+
if not line:
316+
continue
317+
315318
out_queue.put(line)
316319

317320
if not spinner and out_to_screen:

builder/esp32.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def setup_idf_environ():
367367
env['IDF_PATH'] = idf_path
368368

369369
cmds = [
370-
[f'export "IDF_PATH={os.path.abspath(env["IDF_PATH"])}"'],
370+
[f'export "IDF_PATH={idf_path}"'],
371371
['cd', idf_path],
372372
['. ./export.sh'],
373373
['printenv']
@@ -660,6 +660,7 @@ def compile(): # NOQA
660660

661661
if not sys.platform.startswith('win'):
662662
cmds = [
663+
[f'export "IDF_PATH={os.path.abspath(env["IDF_PATH"])}"'],
663664
['cd', 'lib/esp-idf'],
664665
['. ./export.sh'],
665666
['cd ../..'],

ext_mod/lcd_bus/esp32_include/spi_bus.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
lcd_panel_io_t panel_io_handle;
3131
esp_lcd_panel_io_spi_config_t panel_io_config;
3232
spi_bus_config_t bus_config;
33-
spi_host_device_t bus_handle;
33+
esp_lcd_spi_bus_handle_t bus_handle;
34+
35+
int host;
3436

3537
} mp_lcd_spi_bus_obj_t;
3638

ext_mod/lcd_bus/esp32_src/spi_bus.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ STATIC mp_obj_t mp_lcd_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args
153153

154154
self->callback = mp_const_none;
155155

156-
self->bus_handle = (spi_host_device_t)host;
156+
self->host = host;
157+
self->bus_handle = (esp_lcd_spi_bus_handle_t)((uint32_t)host);
157158

158159
self->bus_config.sclk_io_num = clk;
159160
self->bus_config.mosi_io_num = mosi;
@@ -229,35 +230,27 @@ mp_lcd_err_t spi_init(mp_obj_t obj, uint16_t width, uint16_t height, uint8_t bpp
229230
}
230231

231232
size_t max_trans_size;
232-
uint8_t double_buffer;
233233

234234
if ((self->buffer_flags ^ MALLOC_CAP_DMA) && (self->buf2 != NULL)) {
235235
max_trans_size = SPI_LL_DMA_MAX_BIT_LEN / 8;
236-
double_buffer = 1;
237236
} else {
238237
max_trans_size = SPI_LL_CPU_MAX_BIT_LEN / 8;
239-
double_buffer = 0;
240238
}
241239

242240
if (buffer_size <= max_trans_size) {
243241
self->bus_config.max_transfer_sz = buffer_size;
244-
self->panel_io_config.trans_queue_depth = 1;
245-
} else if (double_buffer) {
246-
self->bus_config.max_transfer_sz = max_trans_size;
247-
self->panel_io_config.trans_queue_depth = buffer_size / max_trans_size;
248-
if ((float)self->panel_io_config.trans_queue_depth != ((float)buffer_size / (float)max_trans_size)) {
249-
self->panel_io_config.trans_queue_depth++;
250-
}
251242
} else {
252-
self->panel_io_config.trans_queue_depth = 10;
243+
self->bus_config.max_transfer_sz = max_trans_size;
253244
}
254245

255-
mp_lcd_err_t ret = spi_bus_initialize(self->bus_handle, &self->bus_config, SPI_DMA_CH_AUTO);
246+
self->panel_io_config.trans_queue_depth = 10;
247+
248+
mp_lcd_err_t ret = spi_bus_initialize(self->host, &self->bus_config, SPI_DMA_CH_AUTO);
256249
if (ret != 0) {
257250
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("%d(spi_bus_initialize)"), ret);
258251
}
259252

260-
ret = esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)self->bus_handle, &self->panel_io_config, &self->panel_io_handle.panel_io);
253+
ret = esp_lcd_new_panel_io_spi(self->bus_handle, &self->panel_io_config, &self->panel_io_handle.panel_io);
261254
if (ret != 0) {
262255
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("%d(esp_lcd_new_panel_io_spi)"), ret);
263256
}

0 commit comments

Comments
 (0)