summaryrefslogtreecommitdiff
path: root/shared-module/displayio/__init__.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2019-08-14 14:17:35 -0700
committerScott Shawcroft <scott@tannewt.org>2019-08-22 14:08:33 -0700
commitc247e7df9c043dc6a452a6cabc7bf232c0e9e085 (patch)
treef628b7596e7a1b8255fe9a891183c62ccc1858cf /shared-module/displayio/__init__.c
parentd37dd4d758dd2d2a63fd4c9b7989d60560fd4a25 (diff)
Begin refresh rework.
Diffstat (limited to 'shared-module/displayio/__init__.c')
-rw-r--r--shared-module/displayio/__init__.c149
1 files changed, 10 insertions, 139 deletions
diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c
index a8f888654..0ebed58c2 100644
--- a/shared-module/displayio/__init__.c
+++ b/shared-module/displayio/__init__.c
@@ -19,100 +19,11 @@
#include "supervisor/usb.h"
primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT];
-uint32_t frame_count = 0;
-bool refresh_area(displayio_display_obj_t* display, const displayio_area_t* area) {
- uint16_t buffer_size = 128; // In uint32_ts
+// Check for recursive calls to displayio_background.
+bool displayio_background_in_progress = false;
- displayio_area_t clipped;
- // Clip the area to the display by overlapping the areas. If there is no overlap then we're done.
- if (!displayio_display_clip_area(display, area, &clipped)) {
- return true;
- }
- uint16_t subrectangles = 1;
- uint16_t rows_per_buffer = displayio_area_height(&clipped);
- uint8_t pixels_per_word = (sizeof(uint32_t) * 8) / display->colorspace.depth;
- uint16_t pixels_per_buffer = displayio_area_size(&clipped);
- if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) {
- rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped);
- if (rows_per_buffer == 0) {
- rows_per_buffer = 1;
- }
- // If pixels are packed by column then ensure rows_per_buffer is on a byte boundary.
- if (display->colorspace.depth < 8 && !display->colorspace.pixels_in_byte_share_row) {
- uint8_t pixels_per_byte = 8 / display->colorspace.depth;
- if (rows_per_buffer % pixels_per_byte != 0) {
- rows_per_buffer -= rows_per_buffer % pixels_per_byte;
- }
- }
- subrectangles = displayio_area_height(&clipped) / rows_per_buffer;
- if (displayio_area_height(&clipped) % rows_per_buffer != 0) {
- subrectangles++;
- }
- pixels_per_buffer = rows_per_buffer * displayio_area_width(&clipped);
- buffer_size = pixels_per_buffer / pixels_per_word;
- if (pixels_per_buffer % pixels_per_word) {
- buffer_size += 1;
- }
- }
-
- // Allocated and shared as a uint32_t array so the compiler knows the
- // alignment everywhere.
- uint32_t buffer[buffer_size];
- volatile uint32_t mask_length = (pixels_per_buffer / 32) + 1;
- uint32_t mask[mask_length];
- uint16_t remaining_rows = displayio_area_height(&clipped);
-
- for (uint16_t j = 0; j < subrectangles; j++) {
- displayio_area_t subrectangle = {
- .x1 = clipped.x1,
- .y1 = clipped.y1 + rows_per_buffer * j,
- .x2 = clipped.x2,
- .y2 = clipped.y1 + rows_per_buffer * (j + 1)
- };
- if (remaining_rows < rows_per_buffer) {
- subrectangle.y2 = subrectangle.y1 + remaining_rows;
- }
- remaining_rows -= rows_per_buffer;
-
- displayio_display_begin_transaction(display);
- displayio_display_set_region_to_update(display, &subrectangle);
- displayio_display_end_transaction(display);
-
- uint16_t subrectangle_size_bytes;
- if (display->colorspace.depth >= 8) {
- subrectangle_size_bytes = displayio_area_size(&subrectangle) * (display->colorspace.depth / 8);
- } else {
- subrectangle_size_bytes = displayio_area_size(&subrectangle) / (8 / display->colorspace.depth);
- }
-
- for (uint16_t k = 0; k < mask_length; k++) {
- mask[k] = 0x00000000;
- }
- for (uint16_t k = 0; k < buffer_size; k++) {
- buffer[k] = 0x00000000;
- }
-
- displayio_display_fill_area(display, &subrectangle, mask, buffer);
-
- if (!displayio_display_begin_transaction(display)) {
- // Can't acquire display bus; skip the rest of the data. Try next display.
- return false;
- }
- displayio_display_send_pixels(display, (uint8_t*) buffer, subrectangle_size_bytes);
- displayio_display_end_transaction(display);
-
- // TODO(tannewt): Make refresh displays faster so we don't starve other
- // background tasks.
- usb_background();
- }
- return true;
-}
-
-// Check for recursive calls to displayio_refresh_displays.
-bool refresh_displays_in_progress = false;
-
-void displayio_refresh_displays(void) {
+void displayio_background(void) {
if (mp_hal_is_interrupted()) {
return;
}
@@ -121,12 +32,12 @@ void displayio_refresh_displays(void) {
return;
}
- if (refresh_displays_in_progress) {
+ if (displayio_background_in_progress) {
// Don't allow recursive calls to this routine.
return;
}
- refresh_displays_in_progress = true;
+ displayio_background_in_progress = true;
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
if (displays[i].display.base.type == NULL || displays[i].display.base.type == &mp_type_NoneType) {
@@ -134,54 +45,14 @@ void displayio_refresh_displays(void) {
continue;
}
if (displays[i].display.base.type == &displayio_display_type) {
- displayio_display_obj_t* display = &displays[i].display;
- displayio_display_update_backlight(display);
-
- // Time to refresh at specified frame rate?
- if (!displayio_display_frame_queued(display)) {
- // Too soon. Try next display.
- continue;
- }
- if (!displayio_display_begin_transaction(display)) {
- // Can't acquire display bus; skip updating this display. Try next display.
- continue;
- }
- displayio_display_end_transaction(display);
- displayio_display_start_refresh(display);
- const displayio_area_t* current_area = displayio_display_get_refresh_areas(display);
- while (current_area != NULL) {
- refresh_area(display, current_area);
- current_area = current_area->next;
- }
- displayio_display_finish_refresh(display);
- } else if (displays[i].epaper_display.base.type == &displayio_epaperdisplay_type) {
- displayio_epaperdisplay_obj_t* display = &displays[i].epaper_display;
- // Time to refresh at specified frame rate?
- if (!displayio_epaperdisplay_frame_queued(display)) {
- // Too soon. Try next display.
- continue;
- }
- if (!displayio_epaperdisplay_bus_free(display)) {
- // Can't acquire display bus; skip updating this display. Try next display.
- continue;
- }
- const displayio_area_t* current_area = displayio_epaperdisplay_get_refresh_areas(display);
- if (current_area == NULL) {
- continue;
- }
- displayio_epaperdisplay_start_refresh(display);
- while (current_area != NULL) {
- displayio_epaperdisplay_refresh_area(display, current_area);
- current_area = current_area->next;
- }
- displayio_epaperdisplay_finish_refresh(display);
+ displayio_display_background(&displays[i].display);
+ } else if (displays[i].epaperdisplay.base.type == &displayio_epaperdisplay_type) {
+ displayio_epaperdisplay_background(&displays[i].epaperdisplay);
}
-
- frame_count++;
}
// All done.
- refresh_displays_in_progress = false;
+ displayio_background_in_progress = false;
}
void common_hal_displayio_release_displays(void) {
@@ -245,7 +116,7 @@ void reset_displays(void) {
((uint32_t) i2c->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) {
busio_i2c_obj_t* original_i2c = i2c->bus;
#if BOARD_I2C
- // We don't need to move original_i2c if it is the board.SPI object because it is
+ // We don't need to move original_i2c if it is the board.I2C object because it is
// statically allocated already. (Doing so would also make it impossible to reference in
// a subsequent VM run.)
if (original_i2c == common_hal_board_get_i2c()) {