summaryrefslogtreecommitdiff
path: root/shared-module/displayio
diff options
context:
space:
mode:
authorDave Astels <dastels@daveastels.com>2019-07-31 18:46:41 -0400
committerDave Astels <dastels@daveastels.com>2019-07-31 18:46:41 -0400
commitcd092df9d875d444cf110fc0a1dbb427b261bf8a (patch)
treee0d2da5d55335a485d75cd2ada2e3d70e9fb2ccc /shared-module/displayio
parent1f9cb44fa3a09996d042b7b9e01864bf2feac363 (diff)
parent366fdcce18e148a6828b7a7074e1e4198fca3595 (diff)
Merge remote-tracking branch 'adafruit/master' into displayio_fill_area
Diffstat (limited to 'shared-module/displayio')
-rw-r--r--shared-module/displayio/Display.c27
-rw-r--r--shared-module/displayio/Palette.h2
-rw-r--r--shared-module/displayio/TileGrid.c6
-rw-r--r--shared-module/displayio/__init__.c48
4 files changed, 49 insertions, 34 deletions
diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c
index 74a96fac2..1d8014575 100644
--- a/shared-module/displayio/Display.c
+++ b/shared-module/displayio/Display.c
@@ -44,7 +44,7 @@
void common_hal_displayio_display_construct(displayio_display_obj_t* self,
mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation,
- uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row,
+ uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte,
uint8_t set_column_command, uint8_t set_row_command,
uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len,
const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command, mp_float_t brightness, bool auto_brightness,
@@ -52,6 +52,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
self->colorspace.depth = color_depth;
self->colorspace.grayscale = grayscale;
self->colorspace.pixels_in_byte_share_row = pixels_in_byte_share_row;
+ self->colorspace.bytes_per_cell = bytes_per_cell;
+ self->colorspace.reverse_pixels_in_byte = reverse_pixels_in_byte;
self->set_column_command = set_column_command;
self->set_row_command = set_row_command;
self->write_ram_command = write_ram_command;
@@ -195,17 +197,25 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
common_hal_displayio_display_show(self, &circuitpython_splash);
}
-void common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) {
+bool common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) {
if (root_group == NULL) {
root_group = &circuitpython_splash;
}
if (root_group == self->current_group) {
- return;
+ return true;
+ }
+ if (root_group->in_group) {
+ return false;
+ }
+ if (self->current_group != NULL) {
+ self->current_group->in_group = false;
}
displayio_group_update_transform(root_group, &self->transform);
+ root_group->in_group = true;
self->current_group = root_group;
self->full_refresh = true;
common_hal_displayio_display_refresh_soon(self);
+ return true;
}
void common_hal_displayio_display_refresh_soon(displayio_display_obj_t* self) {
@@ -303,11 +313,11 @@ void displayio_display_set_region_to_update(displayio_display_obj_t* self, displ
if (self->colorspace.depth < 8) {
uint8_t pixels_per_byte = 8 / self->colorspace.depth;
if (self->colorspace.pixels_in_byte_share_row) {
- x1 /= pixels_per_byte;
- x2 /= pixels_per_byte;
+ x1 /= pixels_per_byte * self->colorspace.bytes_per_cell;
+ x2 /= pixels_per_byte * self->colorspace.bytes_per_cell;
} else {
- y1 /= pixels_per_byte;
- y2 /= pixels_per_byte;
+ y1 /= pixels_per_byte * self->colorspace.bytes_per_cell;
+ y2 /= pixels_per_byte * self->colorspace.bytes_per_cell;
}
}
@@ -322,7 +332,6 @@ void displayio_display_set_region_to_update(displayio_display_obj_t* self, displ
if (self->single_byte_bounds) {
data[data_length++] = x1 + self->colstart;
data[data_length++] = x2 - 1 + self->colstart;
- data_length += 2;
} else {
x1 += self->colstart;
x2 += self->colstart - 1;
@@ -417,7 +426,7 @@ bool displayio_display_clip_area(displayio_display_obj_t *self, const displayio_
// Expand the area if we have multiple pixels per byte and we need to byte
// align the bounds.
if (self->colorspace.depth < 8) {
- uint8_t pixels_per_byte = 8 / self->colorspace.depth;
+ uint8_t pixels_per_byte = 8 / self->colorspace.depth * self->colorspace.bytes_per_cell;
if (self->colorspace.pixels_in_byte_share_row) {
if (clipped->x1 % pixels_per_byte != 0) {
clipped->x1 -= clipped->x1 % pixels_per_byte;
diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h
index 19c05baf5..a917e2432 100644
--- a/shared-module/displayio/Palette.h
+++ b/shared-module/displayio/Palette.h
@@ -36,6 +36,8 @@ typedef struct {
uint8_t depth;
bool grayscale;
bool pixels_in_byte_share_row;
+ uint8_t bytes_per_cell;
+ bool reverse_pixels_in_byte;
uint8_t hue;
} _displayio_colorspace_t;
diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c
index 88873d3a9..fee2ae978 100644
--- a/shared-module/displayio/TileGrid.c
+++ b/shared-module/displayio/TileGrid.c
@@ -436,7 +436,11 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c
// asm("bkpt");
// }
}
- ((uint8_t*)buffer)[offset / pixels_per_byte] |= pixel << ((offset % pixels_per_byte) * colorspace->depth);
+ uint8_t shift = (offset % pixels_per_byte) * colorspace->depth;
+ if (colorspace->reverse_pixels_in_byte) {
+ shift = (pixels_per_byte - 1) * colorspace->depth - shift;
+ }
+ ((uint8_t*)buffer)[offset / pixels_per_byte] |= pixel << shift;
}
}
}
diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c
index 97060aaeb..8f6e650a1 100644
--- a/shared-module/displayio/__init__.c
+++ b/shared-module/displayio/__init__.c
@@ -209,35 +209,35 @@ void reset_displays(void) {
}
}
} else if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type) {
- displayio_i2cdisplay_obj_t* i2c = &displays[i].i2cdisplay_bus;
- if (((uint32_t) i2c->bus) < ((uint32_t) &displays) ||
- ((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
- // 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()) {
- continue;
- }
- #endif
- memcpy(&i2c->inline_bus, original_i2c, sizeof(busio_i2c_obj_t));
- i2c->bus = &i2c->inline_bus;
- // Check for other displays that use the same i2c bus and swap them too.
- for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) {
- if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type &&
- displays[i].i2cdisplay_bus.bus == original_i2c) {
- displays[i].i2cdisplay_bus.bus = &i2c->inline_bus;
- }
+ displayio_i2cdisplay_obj_t* i2c = &displays[i].i2cdisplay_bus;
+ if (((uint32_t) i2c->bus) < ((uint32_t) &displays) ||
+ ((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
+ // 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()) {
+ continue;
+ }
+ #endif
+ memcpy(&i2c->inline_bus, original_i2c, sizeof(busio_i2c_obj_t));
+ i2c->bus = &i2c->inline_bus;
+ // Check for other displays that use the same i2c bus and swap them too.
+ for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) {
+ if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type &&
+ displays[i].i2cdisplay_bus.bus == original_i2c) {
+ displays[i].i2cdisplay_bus.bus = &i2c->inline_bus;
}
}
}
- }
-
- for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
- if (displays[i].display.base.type == NULL) {
+ } else {
+ // Not an active display.
continue;
}
+
+ // Reset the displayed group. Only the first will get the terminal but
+ // that's ok.
displayio_display_obj_t* display = &displays[i].display;
display->auto_brightness = true;
common_hal_displayio_display_show(display, &circuitpython_splash);