Skip to content

Commit d72d841

Browse files
committed
DOESN'T WORK and would break OnDiskBitmap if it did...
Expand displayio transactions In principle, we would like to use background SPI DMA so that pixels can be sent while new pixels are being calculated. This could potentially reduce frame time from ~252ms to ~185ms in my test (3.9fps to 5.4fps). However, a number of things stand in the way of this. In order for a background write to be useful, the bus has to remain owned by the displayio core. To end a transaction, the last background write has to finish. Thus, initial efforts didn't bear any fruit since immediately after every data chunk was sent, the transaction was ended. On the other hand, there's at least one difficult-to-change reason that it is this way: OnDiskBitmap. OnDiskBitmap is already a problem for bus locking and performance, but also the OnDiskBitmap _could_ be on the same SPI bus as the display, so you can't enter displayio_display_core_fill_area with the bus lock held. So .. our hands are tied by the system of displayio as it currently exists. There appears to be no way to incrementally evolve it to overlap pixel calculation & display bus writing. And anyway this patch as it is does not work, it never even initializes and clears the LCD.
1 parent 4556ec3 commit d72d841

File tree

4 files changed

+17
-27
lines changed

4 files changed

+17
-27
lines changed

shared-module/_stage/__init__.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ void render_stage(
4646
area.y1 = y0 * scale;
4747
area.x2 = x1 * scale;
4848
area.y2 = y1 * scale;
49+
while (!displayio_display_core_begin_transaction(&display->core)) {
50+
RUN_BACKGROUND_TASKS;
51+
}
4952
displayio_display_core_set_region_to_update(
5053
&display->core, display->set_column_command, display->set_row_command,
5154
NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area,
5255
display->SH1107_addressing);
5356

54-
while (!displayio_display_core_begin_transaction(&display->core)) {
55-
RUN_BACKGROUND_TASKS;
56-
}
5757
display->core.send(display->core.bus, DISPLAY_COMMAND,
5858
CHIP_SELECT_TOGGLE_EVERY_BYTE,
5959
&display->write_ram_command, 1);

shared-module/displayio/Display.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ STATIC bool _refresh_area(displayio_display_obj_t *self, const displayio_area_t
274274
uint32_t mask[mask_length];
275275
uint16_t remaining_rows = displayio_area_height(&clipped);
276276

277+
// Can't acquire display bus; skip the refresh
278+
if (!displayio_display_core_begin_transaction(&self->core)) {
279+
return false;
280+
}
281+
displayio_display_core_set_region_to_update(&self->core, self->set_column_command,
282+
self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false,
283+
&clipped, self->SH1107_addressing);
277284
for (uint16_t j = 0; j < subrectangles; j++) {
278285
displayio_area_t subrectangle = {
279286
.x1 = clipped.x1,
@@ -286,9 +293,6 @@ STATIC bool _refresh_area(displayio_display_obj_t *self, const displayio_area_t
286293
}
287294
remaining_rows -= rows_per_buffer;
288295

289-
displayio_display_core_set_region_to_update(&self->core, self->set_column_command,
290-
self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false,
291-
&subrectangle, self->SH1107_addressing);
292296

293297
uint16_t subrectangle_size_bytes;
294298
if (self->core.colorspace.depth >= 8) {
@@ -302,21 +306,16 @@ STATIC bool _refresh_area(displayio_display_obj_t *self, const displayio_area_t
302306

303307
displayio_display_core_fill_area(&self->core, &subrectangle, mask, buffer);
304308

305-
// Can't acquire display bus; skip the rest of the data.
306-
if (!displayio_display_core_bus_free(&self->core)) {
307-
return false;
308-
}
309309

310-
displayio_display_core_begin_transaction(&self->core);
311310
_send_pixels(self, (uint8_t *)buffer, subrectangle_size_bytes);
312-
displayio_display_core_end_transaction(&self->core);
313311

314312
// TODO(tannewt): Make refresh displays faster so we don't starve other
315313
// background tasks.
316314
#if CIRCUITPY_USB
317315
usb_background();
318316
#endif
319317
}
318+
displayio_display_core_end_transaction(&self->core);
320319
return true;
321320
}
322321

shared-module/displayio/EPaperDisplay.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ STATIC bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t *
281281
for (uint8_t pass = 0; pass < passes; pass++) {
282282
uint16_t remaining_rows = displayio_area_height(&clipped);
283283

284+
if (!displayio_display_core_begin_transaction(&self->core)) {
285+
// Can't acquire display bus; bail
286+
return false;
287+
}
288+
displayio_display_core_begin_transaction(&self->core);
284289
if (self->set_row_window_command != NO_COMMAND) {
285290
displayio_display_core_set_region_to_update(&self->core, self->set_column_window_command,
286291
self->set_row_window_command, self->set_current_column_command, self->set_current_row_command,
@@ -291,9 +296,7 @@ STATIC bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t *
291296
if (pass == 1) {
292297
write_command = self->write_color_ram_command;
293298
}
294-
displayio_display_core_begin_transaction(&self->core);
295299
self->core.send(self->core.bus, DISPLAY_COMMAND | self->chip_select, &write_command, 1);
296-
displayio_display_core_end_transaction(&self->core);
297300

298301
for (uint16_t j = 0; j < subrectangles; j++) {
299302
displayio_area_t subrectangle = {
@@ -335,19 +338,15 @@ STATIC bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t *
335338
}
336339
}
337340

338-
if (!displayio_display_core_begin_transaction(&self->core)) {
339-
// Can't acquire display bus; skip the rest of the data. Try next display.
340-
return false;
341-
}
342341
self->core.send(self->core.bus, DISPLAY_DATA | self->chip_select, (uint8_t *)buffer, subrectangle_size_bytes);
343-
displayio_display_core_end_transaction(&self->core);
344342

345343
// TODO(tannewt): Make refresh displays faster so we don't starve other
346344
// background tasks.
347345
#if CIRCUITPY_USB
348346
usb_background();
349347
#endif
350348
}
349+
displayio_display_core_end_transaction(&self->core);
351350
}
352351

353352
return true;

shared-module/displayio/display_core.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self,
251251
}
252252

253253
// Set column.
254-
displayio_display_core_begin_transaction(self);
255254
uint8_t data[5];
256255
data[0] = column_command;
257256
uint8_t data_length = 1;
@@ -282,19 +281,15 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self,
282281
}
283282

284283
self->send(self->bus, data_type | chip_select, data, data_length);
285-
displayio_display_core_end_transaction(self);
286284

287285
if (set_current_column_command != NO_COMMAND) {
288286
uint8_t command = set_current_column_command;
289-
displayio_display_core_begin_transaction(self);
290287
self->send(self->bus, DISPLAY_COMMAND | chip_select, &command, 1);
291288
self->send(self->bus, DISPLAY_DATA | chip_select, data, data_length / 2);
292-
displayio_display_core_end_transaction(self);
293289
}
294290

295291

296292
// Set row.
297-
displayio_display_core_begin_transaction(self);
298293
data[0] = row_command;
299294
data_length = 1;
300295
if (!data_as_commands) {
@@ -321,14 +316,11 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self,
321316
}
322317

323318
self->send(self->bus, data_type | chip_select, data, data_length);
324-
displayio_display_core_end_transaction(self);
325319

326320
if (set_current_row_command != NO_COMMAND) {
327321
uint8_t command = set_current_row_command;
328-
displayio_display_core_begin_transaction(self);
329322
self->send(self->bus, DISPLAY_COMMAND | chip_select, &command, 1);
330323
self->send(self->bus, DISPLAY_DATA | chip_select, data, data_length / 2);
331-
displayio_display_core_end_transaction(self);
332324
}
333325
}
334326

0 commit comments

Comments
 (0)