Skip to content

Commit 8d836fa

Browse files
committed
Regular display fixes including refresh tweaks
1 parent 9993a99 commit 8d836fa

7 files changed

Lines changed: 35 additions & 19 deletions

File tree

shared-module/displayio/Display.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,23 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
6464
self->write_ram_command = write_ram_command;
6565
self->brightness_command = brightness_command;
6666
self->auto_brightness = auto_brightness;
67+
self->auto_refresh = auto_refresh;
68+
self->first_manual_refresh = !auto_refresh;
6769
self->data_as_commands = data_as_commands;
6870

6971
self->native_frames_per_second = native_frames_per_second;
7072
self->native_frame_time = 1000 / native_frames_per_second;
7173

7274
uint32_t i = 0;
73-
while (!displayio_display_core_begin_transaction(&self->core)) {
74-
RUN_BACKGROUND_TASKS;
75-
}
7675
while (i < init_sequence_len) {
7776
uint8_t *cmd = init_sequence + i;
7877
uint8_t data_size = *(cmd + 1);
7978
bool delay = (data_size & DELAY) != 0;
8079
data_size &= ~DELAY;
8180
uint8_t *data = cmd + 2;
81+
while (!displayio_display_core_begin_transaction(&self->core)) {
82+
RUN_BACKGROUND_TASKS;
83+
}
8284
if (self->data_as_commands) {
8385
uint8_t full_command[data_size + 1];
8486
full_command[0] = cmd[0];
@@ -88,6 +90,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
8890
self->core.send(self->core.bus, true, true, cmd, 1);
8991
self->core.send(self->core.bus, false, false, data, data_size);
9092
}
93+
self->core.end_transaction(self->core.bus);
9194
uint16_t delay_length_ms = 10;
9295
if (delay) {
9396
data_size++;
@@ -99,7 +102,6 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
99102
common_hal_time_delay_ms(delay_length_ms);
100103
i += 2 + data_size;
101104
}
102-
self->core.end_transaction(self->core.bus);
103105

104106
supervisor_start_terminal(width, height);
105107

@@ -192,9 +194,10 @@ STATIC const displayio_area_t* _get_refresh_areas(displayio_display_obj_t *self)
192194
if (self->core.full_refresh) {
193195
self->core.area.next = NULL;
194196
return &self->core.area;
195-
} else {
197+
} else if (self->core.current_group != NULL) {
196198
return displayio_group_get_refresh_areas(self->core.current_group, NULL);
197199
}
200+
return NULL;
198201
}
199202

200203
STATIC void _send_pixels(displayio_display_obj_t* self, uint8_t* pixels, uint32_t length) {
@@ -242,7 +245,7 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
242245
// Allocated and shared as a uint32_t array so the compiler knows the
243246
// alignment everywhere.
244247
uint32_t buffer[buffer_size];
245-
volatile uint32_t mask_length = (pixels_per_buffer / 32) + 1;
248+
uint32_t mask_length = (pixels_per_buffer / 32) + 1;
246249
uint32_t mask[mask_length];
247250
uint16_t remaining_rows = displayio_area_height(&clipped);
248251

@@ -311,7 +314,7 @@ uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t* self
311314
}
312315

313316
void common_hal_displayio_display_refresh(displayio_display_obj_t* self, uint32_t target_frame_time, uint32_t maximum_frame_time) {
314-
if (!self->auto_refresh) {
317+
if (!self->auto_refresh && !self->first_manual_refresh) {
315318
uint64_t current_time = ticks_ms;
316319
uint32_t current_frame_time = current_time - self->core.last_refresh;
317320
// Test to see if the real frame time is below our minimum.
@@ -332,6 +335,7 @@ void common_hal_displayio_display_refresh(displayio_display_obj_t* self, uint32_
332335
#endif
333336
}
334337
}
338+
self->first_manual_refresh = false;
335339
_refresh_display(self);
336340
}
337341

@@ -341,6 +345,7 @@ bool common_hal_displayio_display_get_auto_refresh(displayio_display_obj_t* self
341345

342346
void common_hal_displayio_display_set_auto_refresh(displayio_display_obj_t* self,
343347
bool auto_refresh) {
348+
self->first_manual_refresh = !auto_refresh;
344349
self->auto_refresh = auto_refresh;
345350
}
346351

@@ -376,6 +381,12 @@ void release_display(displayio_display_obj_t* self) {
376381
}
377382
}
378383

384+
void reset_display(displayio_display_obj_t* self) {
385+
self->auto_refresh = true;
386+
self->auto_brightness = true;
387+
common_hal_displayio_display_show(self, NULL);
388+
}
389+
379390
void displayio_display_collect_ptrs(displayio_display_obj_t* self) {
380391
displayio_display_core_collect_ptrs(&self->core);
381392
}

shared-module/displayio/Display.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ typedef struct {
5151
uint8_t set_row_command;
5252
uint8_t write_ram_command;
5353
bool auto_refresh;
54+
bool first_manual_refresh;
5455
bool data_as_commands;
5556
bool auto_brightness;
5657
bool updating_backlight;
5758
} displayio_display_obj_t;
5859

5960
void displayio_display_background(displayio_display_obj_t* self);
6061
void release_display(displayio_display_obj_t* self);
62+
void reset_display(displayio_display_obj_t* self);
6163

6264
void displayio_display_collect_ptrs(displayio_display_obj_t* self);
6365

shared-module/displayio/EPaperDisplay.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ bool common_hal_displayio_epaperdisplay_show(displayio_epaperdisplay_obj_t* self
102102
}
103103

104104
const displayio_area_t* displayio_epaperdisplay_get_refresh_areas(displayio_epaperdisplay_obj_t *self) {
105-
const displayio_area_t* first_area;
106105
if (self->core.full_refresh) {
107-
first_area = &self->core.area;
108-
} else {
106+
self->core.area.next = NULL;
107+
return &self->core.area;
108+
}
109+
const displayio_area_t* first_area = NULL;
110+
if (self->core.current_group != NULL) {
109111
first_area = displayio_group_get_refresh_areas(self->core.current_group, NULL);
110112
}
111113
if (first_area != NULL && self->set_row_window_command == NO_COMMAND) {

shared-module/displayio/TileGrid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ uint8_t common_hal_displayio_tilegrid_get_tile(displayio_tilegrid_t *self, uint1
207207

208208
void common_hal_displayio_tilegrid_set_tile(displayio_tilegrid_t *self, uint16_t x, uint16_t y, uint8_t tile_index) {
209209
if (tile_index >= self->tiles_in_bitmap) {
210-
mp_raise_ValueError(translate("Tile value out of bounds"));
210+
mp_raise_ValueError(translate("Tile index out of bounds"));
211211
}
212212
uint8_t* tiles = self->tiles;
213213
if (self->inline_tiles) {

shared-module/displayio/TileGrid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef struct {
4343
uint16_t pixel_width;
4444
uint16_t pixel_height;
4545
uint16_t bitmap_width_in_tiles;;
46-
uint8_t tiles_in_bitmap;
46+
uint16_t tiles_in_bitmap;
4747
uint16_t width_in_tiles;
4848
uint16_t height_in_tiles;
4949
uint16_t tile_width;

shared-module/displayio/__init__.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ void reset_displays(void) {
143143
// Reset the displayed group. Only the first will get the terminal but
144144
// that's ok.
145145
if (displays[i].display.base.type == &displayio_display_type) {
146-
displayio_display_obj_t* display = &displays[i].display;
147-
display->auto_brightness = true;
148-
common_hal_displayio_display_show(display, NULL);
146+
reset_display(&displays[i].display);
149147
} else if (displays[i].epaper_display.base.type == &displayio_epaperdisplay_type) {
150148
displayio_epaperdisplay_obj_t* display = &displays[i].epaper_display;
151149
common_hal_displayio_epaperdisplay_show(display, NULL);

shared-module/displayio/display_core.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ void displayio_display_core_construct(displayio_display_core_t* self,
8282

8383
self->width = width;
8484
self->height = height;
85-
self->ram_width = width;
86-
self->ram_height = height;
85+
self->ram_width = ram_width;
86+
self->ram_height = ram_height;
8787
rotation = rotation % 360;
8888
self->transform.x = 0;
8989
self->transform.y = 0;
@@ -206,7 +206,7 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
206206
data[0] = column_command;
207207
uint8_t data_length = 1;
208208
if (!data_as_commands) {
209-
self->send(self->bus, true, true, data, 1);
209+
self->send(self->bus, true, false, data, 1);
210210
data_length = 0;
211211
}
212212
if (self->ram_width < 0x100) {
@@ -227,11 +227,14 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
227227
self->send(self->bus, false, always_toggle_chip_select, data, data_length / 2);
228228
}
229229

230+
displayio_display_core_end_transaction(self);
231+
displayio_display_core_begin_transaction(self);
232+
230233
// Set row.
231234
data[0] = row_command;
232235
data_length = 1;
233236
if (!data_as_commands) {
234-
self->send(self->bus, true, true, data, 1);
237+
self->send(self->bus, true, false, data, 1);
235238
data_length = 0;
236239
}
237240
if (self->ram_height < 0x100) {

0 commit comments

Comments
 (0)