summaryrefslogtreecommitdiff
path: root/shared-module/displayio
diff options
context:
space:
mode:
Diffstat (limited to 'shared-module/displayio')
-rw-r--r--shared-module/displayio/Bitmap.c26
-rw-r--r--shared-module/displayio/ColorConverter.c33
-rw-r--r--shared-module/displayio/ColorConverter.h1
-rw-r--r--shared-module/displayio/Display.c62
-rw-r--r--shared-module/displayio/Display.h10
-rw-r--r--shared-module/displayio/EPaperDisplay.c64
-rw-r--r--shared-module/displayio/EPaperDisplay.h6
-rw-r--r--shared-module/displayio/FourWire.c7
-rw-r--r--shared-module/displayio/I2CDisplay.c8
-rw-r--r--shared-module/displayio/OnDiskBitmap.c5
-rw-r--r--shared-module/displayio/Palette.c5
-rw-r--r--shared-module/displayio/Palette.h1
-rw-r--r--shared-module/displayio/Shape.c78
-rw-r--r--shared-module/displayio/Shape.h5
-rw-r--r--shared-module/displayio/TileGrid.c14
-rw-r--r--shared-module/displayio/__init__.c47
-rw-r--r--shared-module/displayio/__init__.h10
-rw-r--r--shared-module/displayio/display_core.c43
-rw-r--r--shared-module/displayio/display_core.h8
19 files changed, 343 insertions, 90 deletions
diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c
index 8bcda6086..d1942efc7 100644
--- a/shared-module/displayio/Bitmap.c
+++ b/shared-module/displayio/Bitmap.c
@@ -105,6 +105,32 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t
return 0;
}
+void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source,
+ int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none) {
+ // Copy complete "source" bitmap into "self" bitmap at location x,y in the "self"
+ // Add a boolean to determine if all values are copied, or only if non-zero
+ // If skip_value is encountered in the source bitmap, it will not be copied.
+ // If skip_value is `None`, then all pixels are copied.
+
+ if (self->read_only) {
+ mp_raise_RuntimeError(translate("Read-only object"));
+ }
+
+ // simplest version - use internal functions for get/set pixels
+ for (int16_t i=0; i < (x2-x1) ; i++) {
+ if ( (x+i >= 0) && (x+i < self->width) ) {
+ for (int16_t j=0; j < (y2-y1) ; j++){
+ if ((y+j >= 0) && (y+j < self->height) ) {
+ uint32_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j);
+ if ( (skip_index_none) || (value != skip_index) ) { // write if skip_value_none is True
+ common_hal_displayio_bitmap_set_pixel(self, x+i, y+j, value);
+ }
+ }
+ }
+ }
+ }
+}
+
void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value) {
if (self->read_only) {
mp_raise_RuntimeError(translate("Read-only object"));
diff --git a/shared-module/displayio/ColorConverter.c b/shared-module/displayio/ColorConverter.c
index c2c3214aa..40dcd9d16 100644
--- a/shared-module/displayio/ColorConverter.c
+++ b/shared-module/displayio/ColorConverter.c
@@ -27,6 +27,9 @@
#include "shared-bindings/displayio/ColorConverter.h"
#include "py/misc.h"
+#include "py/runtime.h"
+
+#define NO_TRANSPARENT_COLOR (0x1000000)
uint32_t displayio_colorconverter_dither_noise_1 (uint32_t n)
{
@@ -41,6 +44,7 @@ uint32_t displayio_colorconverter_dither_noise_2(uint32_t x, uint32_t y) {
void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self, bool dither) {
self->dither = dither;
+ self->transparent_color = NO_TRANSPARENT_COLOR;
}
uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888) {
@@ -54,7 +58,7 @@ uint8_t displayio_colorconverter_compute_luma(uint32_t color_rgb888) {
uint32_t r8 = (color_rgb888 >> 16);
uint32_t g8 = (color_rgb888 >> 8) & 0xff;
uint32_t b8 = color_rgb888 & 0xff;
- return (r8 * 19) / 255 + (g8 * 182) / 255 + (b8 + 54) / 255;
+ return (r8 * 19 + g8 * 182 + b8 * 54) / 255;
}
uint8_t displayio_colorconverter_compute_chroma(uint32_t color_rgb888) {
@@ -128,9 +132,27 @@ bool common_hal_displayio_colorconverter_get_dither(displayio_colorconverter_t*
return self->dither;
}
+void common_hal_displayio_colorconverter_make_transparent(displayio_colorconverter_t* self, uint32_t transparent_color) {
+ if (self->transparent_color != NO_TRANSPARENT_COLOR) {
+ mp_raise_RuntimeError(translate("Only one color can be transparent at a time"));
+ }
+ self->transparent_color = transparent_color;
+}
+
+void common_hal_displayio_colorconverter_make_opaque(displayio_colorconverter_t* self, uint32_t transparent_color) {
+ (void) transparent_color;
+ // NO_TRANSPARENT_COLOR will never equal a valid color
+ self->transparent_color = NO_TRANSPARENT_COLOR;
+}
+
void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, const displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color) {
uint32_t pixel = input_pixel->pixel;
+ if (self->transparent_color == pixel) {
+ output_color->opaque = false;
+ return;
+ }
+
if (self->dither){
uint8_t randr = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x,input_pixel->tile_y));
uint8_t randg = (displayio_colorconverter_dither_noise_2(input_pixel->tile_x+33,input_pixel->tile_y));
@@ -146,9 +168,9 @@ void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _d
g8 = MIN(255,g8 + (randg&0x03));
} else {
int bitmask = 0xFF >> colorspace->depth;
- b8 = MIN(255,b8 + (randb&bitmask));
- r8 = MIN(255,r8 + (randr&bitmask));
- g8 = MIN(255,g8 + (randg&bitmask));
+ b8 = MIN(255,b8 + (randb & bitmask));
+ r8 = MIN(255,r8 + (randr & bitmask));
+ g8 = MIN(255,g8 + (randg & bitmask));
}
pixel = r8 << 16 | g8 << 8 | b8;
}
@@ -177,7 +199,8 @@ void displayio_colorconverter_convert(displayio_colorconverter_t *self, const _d
return;
} else if (colorspace->grayscale && colorspace->depth <= 8) {
uint8_t luma = displayio_colorconverter_compute_luma(pixel);
- output_color->pixel = luma >> (8 - colorspace->depth);
+ size_t bitmask = (1 << colorspace->depth) - 1;
+ output_color->pixel = (luma >> colorspace->grayscale_bit) & bitmask;
output_color->opaque = true;
return;
}
diff --git a/shared-module/displayio/ColorConverter.h b/shared-module/displayio/ColorConverter.h
index 10b1604a4..b402625ef 100644
--- a/shared-module/displayio/ColorConverter.h
+++ b/shared-module/displayio/ColorConverter.h
@@ -36,6 +36,7 @@
typedef struct {
mp_obj_base_t base;
bool dither;
+ uint32_t transparent_color;
} displayio_colorconverter_t;
bool displayio_colorconverter_needs_refresh(displayio_colorconverter_t *self);
diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c
index a3d877f1a..7c8c9280b 100644
--- a/shared-module/displayio/Display.c
+++ b/shared-module/displayio/Display.c
@@ -48,7 +48,9 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
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,
- bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second, bool backlight_on_high) {
+ bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
+ bool backlight_on_high, bool SH1107_addressing) {
+
// Turn off auto-refresh as we init.
self->auto_refresh = false;
uint16_t ram_width = 0x100;
@@ -68,6 +70,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
self->first_manual_refresh = !auto_refresh;
self->data_as_commands = data_as_commands;
self->backlight_on_high = backlight_on_high;
+ self->SH1107_addressing = SH1107_addressing;
self->native_frames_per_second = native_frames_per_second;
self->native_ms_per_frame = 1000 / native_frames_per_second;
@@ -104,21 +107,19 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
i += 2 + data_size;
}
- supervisor_start_terminal(width, height);
-
// Always set the backlight type in case we're reusing memory.
self->backlight_inout.base.type = &mp_type_NoneType;
if (backlight_pin != NULL && common_hal_mcu_pin_is_free(backlight_pin)) {
// Avoid PWM types and functions when the module isn't enabled
#if (CIRCUITPY_PULSEIO)
- pwmout_result_t result = common_hal_pulseio_pwmout_construct(&self->backlight_pwm, backlight_pin, 0, 50000, false);
+ pwmout_result_t result = common_hal_pwmio_pwmout_construct(&self->backlight_pwm, backlight_pin, 0, 50000, false);
if (result != PWMOUT_OK) {
self->backlight_inout.base.type = &digitalio_digitalinout_type;
common_hal_digitalio_digitalinout_construct(&self->backlight_inout, backlight_pin);
common_hal_never_reset_pin(backlight_pin);
} else {
- self->backlight_pwm.base.type = &pulseio_pwmout_type;
- common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm);
+ self->backlight_pwm.base.type = &pwmio_pwmout_type;
+ common_hal_pwmio_pwmout_never_reset(&self->backlight_pwm);
}
#else
// Otherwise default to digital
@@ -137,7 +138,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
// Set the group after initialization otherwise we may send pixels while we delay in
// initialization.
common_hal_displayio_display_show(self, &circuitpython_splash);
- self->auto_refresh = auto_refresh;
+ common_hal_displayio_display_set_auto_refresh(self, auto_refresh);
}
bool common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) {
@@ -173,14 +174,14 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self,
// Avoid PWM types and functions when the module isn't enabled
#if (CIRCUITPY_PULSEIO)
- bool ispwm = (self->backlight_pwm.base.type == &pulseio_pwmout_type) ? true : false;
+ bool ispwm = (self->backlight_pwm.base.type == &pwmio_pwmout_type) ? true : false;
#else
bool ispwm = false;
#endif
if (ispwm) {
#if (CIRCUITPY_PULSEIO)
- common_hal_pulseio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t) (0xffff * brightness));
+ common_hal_pwmio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t) (0xffff * brightness));
ok = true;
#else
ok = false;
@@ -240,11 +241,17 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
if (!displayio_display_core_clip_area(&self->core, 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) / self->core.colorspace.depth;
uint16_t pixels_per_buffer = displayio_area_size(&clipped);
- if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) {
+
+ uint16_t subrectangles = 1;
+ // for SH1107 and other boundary constrained controllers
+ // write one single row at a time
+ if (self->SH1107_addressing) {
+ subrectangles = rows_per_buffer; // vertical (column mode) write each separately (height times)
+ rows_per_buffer = 1;
+ } else 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;
@@ -286,7 +293,9 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
}
remaining_rows -= rows_per_buffer;
- displayio_display_core_set_region_to_update(&self->core, self->set_column_command, self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false, &subrectangle);
+ displayio_display_core_set_region_to_update(&self->core, self->set_column_command,
+ self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false,
+ &subrectangle, self->SH1107_addressing);
uint16_t subrectangle_size_bytes;
if (self->core.colorspace.depth >= 8) {
@@ -317,11 +326,10 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
}
STATIC void _refresh_display(displayio_display_obj_t* self) {
- if (!displayio_display_core_bus_free(&self->core)) {
- // Can't acquire display bus; skip updating this display. Try next display.
+ if (!displayio_display_core_start_refresh(&self->core)) {
+ // A refresh on this bus is already in progress. Try next display.
return;
}
- displayio_display_core_start_refresh(&self->core);
const displayio_area_t* current_area = _get_refresh_areas(self);
while (current_area != NULL) {
_refresh_area(self, current_area);
@@ -339,8 +347,10 @@ void common_hal_displayio_display_set_rotation(displayio_display_obj_t* self, in
self->core.height = tmp;
}
displayio_display_core_set_rotation(&self->core, rotation);
- supervisor_stop_terminal();
- supervisor_start_terminal(self->core.width, self->core.height);
+ if (self == &displays[0].display) {
+ supervisor_stop_terminal();
+ supervisor_start_terminal(self->core.width, self->core.height);
+ }
if (self->core.current_group != NULL) {
displayio_group_update_transform(self->core.current_group, &self->core.transform);
}
@@ -352,7 +362,7 @@ uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t* self
bool common_hal_displayio_display_refresh(displayio_display_obj_t* self, uint32_t target_ms_per_frame, uint32_t maximum_ms_per_real_frame) {
- if (!self->auto_refresh && !self->first_manual_refresh) {
+ if (!self->auto_refresh && !self->first_manual_refresh && (target_ms_per_frame != 0xffffffff) ) {
uint64_t current_time = supervisor_ticks_ms64();
uint32_t current_ms_since_real_refresh = current_time - self->core.last_refresh;
// Test to see if the real frame time is below our minimum.
@@ -383,6 +393,13 @@ bool common_hal_displayio_display_get_auto_refresh(displayio_display_obj_t* self
void common_hal_displayio_display_set_auto_refresh(displayio_display_obj_t* self,
bool auto_refresh) {
self->first_manual_refresh = !auto_refresh;
+ if (auto_refresh != self->auto_refresh) {
+ if (auto_refresh) {
+ supervisor_enable_tick();
+ } else {
+ supervisor_disable_tick();
+ }
+ }
self->auto_refresh = auto_refresh;
}
@@ -409,11 +426,12 @@ void displayio_display_background(displayio_display_obj_t* self) {
}
void release_display(displayio_display_obj_t* self) {
+ common_hal_displayio_display_set_auto_refresh(self, false);
release_display_core(&self->core);
#if (CIRCUITPY_PULSEIO)
- if (self->backlight_pwm.base.type == &pulseio_pwmout_type) {
- common_hal_pulseio_pwmout_reset_ok(&self->backlight_pwm);
- common_hal_pulseio_pwmout_deinit(&self->backlight_pwm);
+ if (self->backlight_pwm.base.type == &pwmio_pwmout_type) {
+ common_hal_pwmio_pwmout_reset_ok(&self->backlight_pwm);
+ common_hal_pwmio_pwmout_deinit(&self->backlight_pwm);
} else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) {
common_hal_digitalio_digitalinout_deinit(&self->backlight_inout);
}
@@ -423,7 +441,7 @@ void release_display(displayio_display_obj_t* self) {
}
void reset_display(displayio_display_obj_t* self) {
- self->auto_refresh = true;
+ common_hal_displayio_display_set_auto_refresh(self, true);
self->auto_brightness = true;
common_hal_displayio_display_show(self, NULL);
}
diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h
index 8adaf597f..cc9cd54c4 100644
--- a/shared-module/displayio/Display.h
+++ b/shared-module/displayio/Display.h
@@ -29,7 +29,9 @@
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/displayio/Group.h"
-#include "shared-bindings/pulseio/PWMOut.h"
+#if CIRCUITPY_PWMIO
+#include "shared-bindings/pwmio/PWMOut.h"
+#endif
#include "shared-module/displayio/area.h"
#include "shared-module/displayio/display_core.h"
@@ -39,7 +41,9 @@ typedef struct {
displayio_display_core_t core;
union {
digitalio_digitalinout_obj_t backlight_inout;
- pulseio_pwmout_obj_t backlight_pwm;
+ #if CIRCUITPY_PWMIO
+ pwmio_pwmout_obj_t backlight_pwm;
+ #endif
};
uint64_t last_backlight_refresh;
uint64_t last_refresh_call;
@@ -56,6 +60,8 @@ typedef struct {
bool auto_brightness;
bool updating_backlight;
bool backlight_on_high;
+ // new quirk for sh1107
+ bool SH1107_addressing;
} displayio_display_obj_t;
void displayio_display_background(displayio_display_obj_t* self);
diff --git a/shared-module/displayio/EPaperDisplay.c b/shared-module/displayio/EPaperDisplay.c
index 6a55687b9..3fb37ff21 100644
--- a/shared-module/displayio/EPaperDisplay.c
+++ b/shared-module/displayio/EPaperDisplay.c
@@ -43,13 +43,14 @@
#include <string.h>
void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t* self,
- mp_obj_t bus, uint8_t* start_sequence, uint16_t start_sequence_len, uint8_t* stop_sequence, uint16_t stop_sequence_len,
+ mp_obj_t bus, const uint8_t* start_sequence, uint16_t start_sequence_len,
+ const uint8_t* stop_sequence, uint16_t stop_sequence_len,
uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height,
int16_t colstart, int16_t rowstart, uint16_t rotation,
uint16_t set_column_window_command, uint16_t set_row_window_command,
uint16_t set_current_column_command, uint16_t set_current_row_command,
uint16_t write_black_ram_command, bool black_bits_inverted, uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color, uint16_t refresh_display_command, mp_float_t refresh_time,
- const mcu_pin_obj_t* busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool chip_select) {
+ const mcu_pin_obj_t* busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool chip_select, bool grayscale) {
if (highlight_color != 0x000000) {
self->core.colorspace.tricolor = true;
self->core.colorspace.tricolor_hue = displayio_colorconverter_compute_hue(highlight_color);
@@ -72,6 +73,7 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t*
self->refreshing = false;
self->milliseconds_per_frame = seconds_per_frame * 1000;
self->chip_select = chip_select ? CHIP_SELECT_TOGGLE_EVERY_BYTE : CHIP_SELECT_UNTOUCHED;
+ self->grayscale = grayscale;
self->start_sequence = start_sequence;
self->start_sequence_len = start_sequence_len;
@@ -90,8 +92,6 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t*
// TODO: Clear
}
- supervisor_start_terminal(width, height);
-
// Set the group after initialization otherwise we may send pixels while we delay in
// initialization.
common_hal_displayio_epaperdisplay_show(self, &circuitpython_splash);
@@ -134,14 +134,15 @@ STATIC void wait_for_busy(displayio_epaperdisplay_obj_t* self) {
}
}
-STATIC void send_command_sequence(displayio_epaperdisplay_obj_t* self, bool should_wait_for_busy, uint8_t* sequence, uint32_t sequence_len) {
+STATIC void send_command_sequence(displayio_epaperdisplay_obj_t* self,
+ bool should_wait_for_busy, const uint8_t* sequence, uint32_t sequence_len) {
uint32_t i = 0;
while (i < sequence_len) {
- uint8_t *cmd = sequence + i;
+ const uint8_t *cmd = sequence + i;
uint8_t data_size = *(cmd + 1);
bool delay = (data_size & DELAY) != 0;
data_size &= ~DELAY;
- uint8_t *data = cmd + 2;
+ const uint8_t *data = cmd + 2;
displayio_display_core_begin_transaction(&self->core);
self->core.send(self->core.bus, DISPLAY_COMMAND, self->chip_select, cmd, 1);
self->core.send(self->core.bus, DISPLAY_DATA, self->chip_select, data, data_size);
@@ -187,6 +188,7 @@ void displayio_epaperdisplay_finish_refresh(displayio_epaperdisplay_obj_t* self)
displayio_display_core_begin_transaction(&self->core);
self->core.send(self->core.bus, DISPLAY_COMMAND, self->chip_select, &self->refresh_display_command, 1);
displayio_display_core_end_transaction(&self->core);
+ supervisor_enable_tick();
self->refreshing = true;
displayio_display_core_finish_refresh(&self->core);
@@ -196,6 +198,29 @@ mp_obj_t common_hal_displayio_epaperdisplay_get_bus(displayio_epaperdisplay_obj_
return self->core.bus;
}
+void common_hal_displayio_epaperdisplay_set_rotation(displayio_epaperdisplay_obj_t* self, int rotation){
+ bool transposed = (self->core.rotation == 90 || self->core.rotation == 270);
+ bool will_transposed = (rotation == 90 || rotation == 270);
+ if(transposed != will_transposed) {
+ int tmp = self->core.width;
+ self->core.width = self->core.height;
+ self->core.height = tmp;
+ }
+ displayio_display_core_set_rotation(&self->core, rotation);
+ if (self == &displays[0].epaper_display) {
+ supervisor_stop_terminal();
+ supervisor_start_terminal(self->core.width, self->core.height);
+ }
+ if (self->core.current_group != NULL) {
+ displayio_group_update_transform(self->core.current_group, &self->core.transform);
+ }
+}
+
+uint16_t common_hal_displayio_epaperdisplay_get_rotation(displayio_epaperdisplay_obj_t* self){
+ return self->core.rotation;
+}
+
+
bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, const displayio_area_t* area) {
uint16_t buffer_size = 128; // In uint32_ts
@@ -231,14 +256,16 @@ bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, c
uint32_t mask[mask_length];
uint8_t passes = 1;
- if (self->core.colorspace.tricolor) {
+ if (self->core.colorspace.tricolor || self->grayscale) {
passes = 2;
}
for (uint8_t pass = 0; pass < passes; pass++) {
uint16_t remaining_rows = displayio_area_height(&clipped);
if (self->set_row_window_command != NO_COMMAND) {
- displayio_display_core_set_region_to_update(&self->core, self->set_column_window_command, self->set_row_window_command, self->set_current_column_command, self->set_current_row_command, false, self->chip_select, &clipped);
+ displayio_display_core_set_region_to_update(&self->core, self->set_column_window_command,
+ self->set_row_window_command, self->set_current_column_command, self->set_current_row_command,
+ false, self->chip_select, &clipped, false /* SH1107_addressing */);
}
uint8_t write_command = self->write_black_ram_command;
@@ -268,8 +295,13 @@ bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, c
memset(buffer, 0, buffer_size * sizeof(buffer[0]));
self->core.colorspace.grayscale = true;
+ self->core.colorspace.grayscale_bit = 7;
if (pass == 1) {
- self->core.colorspace.grayscale = false;
+ if (self->grayscale) { // 4-color grayscale
+ self->core.colorspace.grayscale_bit = 6;
+ } else { // Tri-color
+ self->core.colorspace.grayscale = false;
+ }
}
displayio_display_core_fill_area(&self->core, &subrectangle, mask, buffer);
@@ -301,6 +333,7 @@ bool common_hal_displayio_epaperdisplay_refresh(displayio_epaperdisplay_obj_t* s
if (self->refreshing && self->busy.base.type == &digitalio_digitalinout_type) {
if (common_hal_digitalio_digitalinout_get_value(&self->busy) != self->busy_state) {
+ supervisor_disable_tick();
self->refreshing = false;
// Run stop sequence but don't wait for busy because busy is set when sleeping.
send_command_sequence(self, false, self->stop_sequence, self->stop_sequence_len);
@@ -342,6 +375,7 @@ void displayio_epaperdisplay_background(displayio_epaperdisplay_obj_t* self) {
refresh_done = supervisor_ticks_ms64() - self->core.last_refresh > self->refresh_time;
}
if (refresh_done) {
+ supervisor_disable_tick();
self->refreshing = false;
// Run stop sequence but don't wait for busy because busy is set when sleeping.
send_command_sequence(self, false, self->stop_sequence, self->stop_sequence_len);
@@ -349,9 +383,15 @@ void displayio_epaperdisplay_background(displayio_epaperdisplay_obj_t* self) {
}
}
+bool common_hal_displayio_epaperdisplay_get_busy(displayio_epaperdisplay_obj_t* self) {
+ displayio_epaperdisplay_background(self);
+ return self->refreshing;
+}
+
void release_epaperdisplay(displayio_epaperdisplay_obj_t* self) {
if (self->refreshing) {
wait_for_busy(self);
+ supervisor_disable_tick();
self->refreshing = false;
// Run stop sequence but don't wait for busy because busy is set when sleeping.
send_command_sequence(self, false, self->stop_sequence, self->stop_sequence_len);
@@ -365,8 +405,8 @@ void release_epaperdisplay(displayio_epaperdisplay_obj_t* self) {
void displayio_epaperdisplay_collect_ptrs(displayio_epaperdisplay_obj_t* self) {
displayio_display_core_collect_ptrs(&self->core);
- gc_collect_ptr(self->start_sequence);
- gc_collect_ptr(self->stop_sequence);
+ gc_collect_ptr((void *) self->start_sequence);
+ gc_collect_ptr((void *) self->stop_sequence);
}
bool maybe_refresh_epaperdisplay(void) {
diff --git a/shared-module/displayio/EPaperDisplay.h b/shared-module/displayio/EPaperDisplay.h
index d08bed546..d0668ff44 100644
--- a/shared-module/displayio/EPaperDisplay.h
+++ b/shared-module/displayio/EPaperDisplay.h
@@ -29,7 +29,6 @@
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/displayio/Group.h"
-#include "shared-bindings/pulseio/PWMOut.h"
#include "shared-module/displayio/area.h"
#include "shared-module/displayio/display_core.h"
@@ -39,9 +38,9 @@ typedef struct {
displayio_display_core_t core;
digitalio_digitalinout_obj_t busy;
uint32_t milliseconds_per_frame;
- uint8_t* start_sequence;
+ const uint8_t* start_sequence;
uint32_t start_sequence_len;
- uint8_t* stop_sequence;
+ const uint8_t* stop_sequence;
uint32_t stop_sequence_len;
uint16_t refresh_time;
uint16_t set_column_window_command;
@@ -56,6 +55,7 @@ typedef struct {
bool black_bits_inverted;
bool color_bits_inverted;
bool refreshing;
+ bool grayscale;
display_chip_select_behavior_t chip_select;
} displayio_epaperdisplay_obj_t;
diff --git a/shared-module/displayio/FourWire.c b/shared-module/displayio/FourWire.c
index 17e8cfa1d..e993f2480 100644
--- a/shared-module/displayio/FourWire.c
+++ b/shared-module/displayio/FourWire.c
@@ -85,9 +85,9 @@ bool common_hal_displayio_fourwire_reset(mp_obj_t obj) {
return false;
}
common_hal_digitalio_digitalinout_set_value(&self->reset, false);
- common_hal_time_delay_ms(1);
+ common_hal_mcu_delay_us(1000);
common_hal_digitalio_digitalinout_set_value(&self->reset, true);
- common_hal_time_delay_ms(1);
+ common_hal_mcu_delay_us(1000);
return true;
}
@@ -111,7 +111,8 @@ bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t obj) {
return true;
}
-void common_hal_displayio_fourwire_send(mp_obj_t obj, display_byte_type_t data_type, display_chip_select_behavior_t chip_select, uint8_t *data, uint32_t data_length) {
+void common_hal_displayio_fourwire_send(mp_obj_t obj, display_byte_type_t data_type,
+ display_chip_select_behavior_t chip_select, const uint8_t *data, uint32_t data_length) {
displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj);
common_hal_digitalio_digitalinout_set_value(&self->command, data_type == DISPLAY_DATA);
if (chip_select == CHIP_SELECT_TOGGLE_EVERY_BYTE) {
diff --git a/shared-module/displayio/I2CDisplay.c b/shared-module/displayio/I2CDisplay.c
index 0c8f2e69a..cc811e83d 100644
--- a/shared-module/displayio/I2CDisplay.c
+++ b/shared-module/displayio/I2CDisplay.c
@@ -53,6 +53,7 @@ void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self,
// Probe the bus to see if a device acknowledges the given address.
if (!common_hal_busio_i2c_probe(i2c, device_address)) {
+ self->base.type = &mp_type_NoneType;
mp_raise_ValueError_varg(translate("Unable to find I2C Display at %x"), device_address);
}
@@ -71,7 +72,9 @@ void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) {
common_hal_busio_i2c_deinit(self->bus);
}
- common_hal_reset_pin(self->reset.pin);
+ if (self->reset.base.type == &digitalio_digitalinout_type) {
+ common_hal_digitalio_digitalinout_deinit(&self->reset);
+ }
}
bool common_hal_displayio_i2cdisplay_reset(mp_obj_t obj) {
@@ -100,7 +103,8 @@ bool common_hal_displayio_i2cdisplay_begin_transaction(mp_obj_t obj) {
return common_hal_busio_i2c_try_lock(self->bus);
}
-void common_hal_displayio_i2cdisplay_send(mp_obj_t obj, display_byte_type_t data_type, display_chip_select_behavior_t chip_select, uint8_t *data, uint32_t data_length) {
+void common_hal_displayio_i2cdisplay_send(mp_obj_t obj, display_byte_type_t data_type,
+ display_chip_select_behavior_t chip_select, const uint8_t *data, uint32_t data_length) {
displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj);
if (data_type == DISPLAY_COMMAND) {
uint8_t command_bytes[2 * data_length];
diff --git a/shared-module/displayio/OnDiskBitmap.c b/shared-module/displayio/OnDiskBitmap.c
index 993fc03de..c1a0ddeb7 100644
--- a/shared-module/displayio/OnDiskBitmap.c
+++ b/shared-module/displayio/OnDiskBitmap.c
@@ -57,7 +57,7 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self,
uint32_t compression = read_word(bmp_header, 15);
uint32_t number_of_colors = read_word(bmp_header, 23);
- bool indexed = ((bits_per_pixel <= 8) && (number_of_colors != 0));
+ bool indexed = bits_per_pixel <= 8;
self->bitfield_compressed = (compression == 3);
self->bits_per_pixel = bits_per_pixel;
self->width = read_word(bmp_header, 9);
@@ -75,6 +75,9 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self,
self->b_bitmask = 0x1f;
}
} else if (indexed && self->bits_per_pixel != 1) {
+ if (number_of_colors == 0) {
+ number_of_colors = 1 << bits_per_pixel;
+ }
uint16_t palette_size = number_of_colors * sizeof(uint32_t);
uint16_t palette_offset = 0xe + header_size;
diff --git a/shared-module/displayio/Palette.c b/shared-module/displayio/Palette.c
index 1ef03aab4..ba5ff665c 100644
--- a/shared-module/displayio/Palette.c
+++ b/shared-module/displayio/Palette.c
@@ -35,10 +35,12 @@ void common_hal_displayio_palette_construct(displayio_palette_t* self, uint16_t
void common_hal_displayio_palette_make_opaque(displayio_palette_t* self, uint32_t palette_index) {
self->colors[palette_index].transparent = false;
+ self->needs_refresh = true;
}
void common_hal_displayio_palette_make_transparent(displayio_palette_t* self, uint32_t palette_index) {
self->colors[palette_index].transparent = true;
+ self->needs_refresh = true;
}
uint32_t common_hal_displayio_palette_get_len(displayio_palette_t* self) {
@@ -81,7 +83,8 @@ bool displayio_palette_get_color(displayio_palette_t *self, const _displayio_col
uint8_t pixel_hue = self->colors[palette_index].hue;
displayio_colorconverter_compute_tricolor(colorspace, pixel_hue, luma, color);
} else if (colorspace->grayscale) {
- *color = self->colors[palette_index].luma >> (8 - colorspace->depth);
+ size_t bitmask = (1 << colorspace->depth) - 1;
+ *color = (self->colors[palette_index].luma >> colorspace->grayscale_bit) & bitmask;
} else {
uint16_t packed = self->colors[palette_index].rgb565;
if (colorspace->reverse_bytes_in_word) {
diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h
index da72f250f..993912cc5 100644
--- a/shared-module/displayio/Palette.h
+++ b/shared-module/displayio/Palette.h
@@ -37,6 +37,7 @@ typedef struct {
uint8_t bytes_per_cell;
uint8_t tricolor_hue;
uint8_t tricolor_luma;
+ uint8_t grayscale_bit; // The lowest grayscale bit. Normally 8 - depth.
bool grayscale;
bool tricolor;
bool pixels_in_byte_share_row;
diff --git a/shared-module/displayio/Shape.c b/shared-module/displayio/Shape.c
index ab9ca735b..b94a392bc 100644
--- a/shared-module/displayio/Shape.c
+++ b/shared-module/displayio/Shape.c
@@ -29,6 +29,7 @@
#include <string.h>
#include "py/runtime.h"
+#include "py/misc.h"
void common_hal_displayio_shape_construct(displayio_shape_t *self, uint32_t width,
uint32_t height, bool mirror_x, bool mirror_y) {
@@ -37,37 +38,77 @@ void common_hal_displayio_shape_construct(displayio_shape_t *self, uint32_t widt
self->width = width;
if (self->mirror_x) {
width /= 2;
- width += self->width % 2 - 1;
+ width += self->width % 2;
}
self->half_width = width;
self->height = height;
if (self->mirror_y) {
height /= 2;
- height += self->height % 2 - 1;
+ height += self->height % 2;
}
self->half_height = height;
self->data = m_malloc(height * sizeof(uint32_t), false);
- for (uint16_t i = 0; i <= height; i++) {
+
+ for (uint16_t i = 0; i < height; i++) {
self->data[2 * i] = 0;
self->data[2 * i + 1] = width;
}
+
+ self->dirty_area.x1=0;
+ self->dirty_area.x2=width;
+ self->dirty_area.y1=0;
+ self->dirty_area.y2=height;
}
void common_hal_displayio_shape_set_boundary(displayio_shape_t *self, uint16_t y, uint16_t start_x, uint16_t end_x) {
- if (y < 0 || y >= self->height || (self->mirror_y && y > self->half_height)) {
+ if (y < 0 || y >= self->height || (self->mirror_y && y >= self->half_height)) {
mp_raise_ValueError(translate("y value out of bounds"));
}
- if (start_x < 0 || start_x > self->width || end_x < 0 || end_x > self->width) {
+ if (start_x < 0 || start_x >= self->width || end_x < 0 || end_x >= self->width) {
mp_raise_ValueError(translate("x value out of bounds"));
}
- uint16_t half_width = self->width / 2 - 1 + self->width % 2;
- if (self->mirror_x && (start_x > half_width || end_x > half_width)) {
- mp_raise_ValueError_varg(translate("Maximum x value when mirrored is %d"), half_width);
+ if (self->mirror_x && (start_x >= self->half_width || end_x >= self->half_width)) {
+ mp_raise_ValueError_varg(translate("Maximum x value when mirrored is %d"), self->half_width);
+ }
+
+ uint16_t lower_x, upper_x, lower_y, upper_y;
+
+ // find x-boundaries for updating based on current data and start_x, end_x, and mirror_x
+ lower_x = MIN(start_x, self->data[2 * y]);
+
+ if (self->mirror_x) {
+ upper_x = self->width - lower_x + 1; // dirty rectangles are treated with max value exclusive
+ } else {
+ upper_x = MAX(end_x, self->data[2 * y + 1]) + 1; // dirty rectangles are treated with max value exclusive
+ }
+
+ // find y-boundaries based on y and mirror_y
+ lower_y = y;
+
+ if (self->mirror_y) {
+ upper_y = self->height - lower_y + 1; // dirty rectangles are treated with max value exclusive
+ } else {
+ upper_y = y + 1; // dirty rectangles are treated with max value exclusive
}
- self->data[2 * y] = start_x;
+
+ self->data[2 * y] = start_x; // update the data array with the new boundaries
self->data[2 * y + 1] = end_x;
+
+ if (self->dirty_area.x1 == self->dirty_area.x2) { // Dirty region is empty
+ self->dirty_area.x1 = lower_x;
+ self->dirty_area.x2 = upper_x;
+ self->dirty_area.y1 = lower_y;
+ self->dirty_area.y2 = upper_y;
+
+ } else { // Dirty region is not empty
+ self->dirty_area.x1 = MIN(lower_x, self->dirty_area.x1);
+ self->dirty_area.x2 = MAX(upper_x, self->dirty_area.x2);
+
+ self->dirty_area.y1 = MIN(lower_y, self->dirty_area.y1);
+ self->dirty_area.y2 = MAX(upper_y, self->dirty_area.y2);
+ }
}
uint32_t common_hal_displayio_shape_get_pixel(void *obj, int16_t x, int16_t y) {
@@ -75,10 +116,10 @@ uint32_t common_hal_displayio_shape_get_pixel(void *obj, int16_t x, int16_t y) {
if (x >= self->width || x < 0 || y >= self->height || y < 0) {
return 0;
}
- if (self->mirror_x && x > self->half_width) {
- x = self->width - 1 - x;
+ if (self->mirror_x && x >= self->half_width) {
+ x = self->width - x - 1;
}
- if (self->mirror_y && y > self->half_height) {
+ if (self->mirror_y && y >= self->half_height) {
y = self->height - y - 1;
}
uint16_t start_x = self->data[2 * y];
@@ -88,3 +129,16 @@ uint32_t common_hal_displayio_shape_get_pixel(void *obj, int16_t x, int16_t y) {
}
return 1;
}
+
+displayio_area_t* displayio_shape_get_refresh_areas(displayio_shape_t *self, displayio_area_t* tail) {
+ if (self->dirty_area.x1 == self->dirty_area.x2) {
+ return tail;
+ }
+ self->dirty_area.next = tail;
+ return &self->dirty_area;
+}
+
+void displayio_shape_finish_refresh(displayio_shape_t *self) {
+ self->dirty_area.x1 = 0;
+ self->dirty_area.x2 = 0;
+}
diff --git a/shared-module/displayio/Shape.h b/shared-module/displayio/Shape.h
index ca054fe00..e59ad586e 100644
--- a/shared-module/displayio/Shape.h
+++ b/shared-module/displayio/Shape.h
@@ -31,6 +31,7 @@
#include <stdint.h>
#include "py/obj.h"
+#include "shared-module/displayio/area.h"
typedef struct {
mp_obj_base_t base;
@@ -41,6 +42,10 @@ typedef struct {
uint16_t* data;
bool mirror_x;
bool mirror_y;
+ displayio_area_t dirty_area;
} displayio_shape_t;
+void displayio_shape_finish_refresh(displayio_shape_t *self);
+displayio_area_t* displayio_shape_get_refresh_areas(displayio_shape_t *self, displayio_area_t* tail);
+
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_SHAPE_H
diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c
index 2766cbecd..19ea10e55 100644
--- a/shared-module/displayio/TileGrid.c
+++ b/shared-module/displayio/TileGrid.c
@@ -83,10 +83,16 @@ bool common_hal_displayio_tilegrid_get_hidden(displayio_tilegrid_t* self) {
void common_hal_displayio_tilegrid_set_hidden(displayio_tilegrid_t* self, bool hidden) {
self->hidden = hidden;
+ if(!hidden){
+ self->full_change = true;
+ }
}
void displayio_tilegrid_set_hidden_by_parent(displayio_tilegrid_t *self, bool hidden) {
self->hidden_by_parent = hidden;
+ if(!hidden){
+ self->full_change = true;
+ }
}
bool displayio_tilegrid_get_previous_area(displayio_tilegrid_t *self, displayio_area_t* area) {
@@ -499,7 +505,7 @@ void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self) {
if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_bitmap_type)) {
displayio_bitmap_finish_refresh(self->bitmap);
} else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_shape_type)) {
- // TODO: Support shape changes.
+ displayio_shape_finish_refresh(self->bitmap);
} else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_ondiskbitmap_type)) {
// OnDiskBitmap changes will trigger a complete reload so no need to
// track changes.
@@ -543,6 +549,12 @@ displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *sel
self->full_change = true;
}
}
+ } else if (MP_OBJ_IS_TYPE(self->bitmap, &displayio_shape_type)) {
+ displayio_area_t* refresh_area = displayio_shape_get_refresh_areas(self->bitmap, tail);
+ if (refresh_area != tail) {
+ displayio_area_copy(refresh_area, &self->dirty_area);
+ self->partial_change = true;
+ }
}
self->full_change = self->full_change ||
diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c
index c898bbb98..a9bb3b21b 100644
--- a/shared-module/displayio/__init__.c
+++ b/shared-module/displayio/__init__.c
@@ -19,14 +19,19 @@
#include "supervisor/spi_flash_api.h"
#include "py/mpconfig.h"
+#if CIRCUITPY_SHARPDISPLAY
+#include "shared-bindings/sharpdisplay/SharpMemoryFramebuffer.h"
+#include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h"
+#endif
+
primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT];
#if CIRCUITPY_RGBMATRIX
-STATIC bool any_display_uses_this_rgbmatrix(rgbmatrix_rgbmatrix_obj_t* pm) {
+STATIC bool any_display_uses_this_framebuffer(mp_obj_base_t *obj) {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
- if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) {
+ if (displays[i].display_base.type == &framebufferio_framebufferdisplay_type) {
framebufferio_framebufferdisplay_obj_t* display = &displays[i].framebuffer_display;
- if (display->framebuffer == pm) {
+ if (display->framebuffer == obj) {
return true;
}
}
@@ -35,8 +40,6 @@ STATIC bool any_display_uses_this_rgbmatrix(rgbmatrix_rgbmatrix_obj_t* pm) {
}
#endif
-// Check for recursive calls to displayio_background.
-bool displayio_background_in_progress = false;
void displayio_background(void) {
if (mp_hal_is_interrupted()) {
@@ -47,12 +50,6 @@ void displayio_background(void) {
return;
}
- if (displayio_background_in_progress) {
- // Don't allow recursive calls to this routine.
- return;
- }
-
- 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) {
@@ -70,8 +67,6 @@ void displayio_background(void) {
}
}
- // All done.
- displayio_background_in_progress = false;
}
void common_hal_displayio_release_displays(void) {
@@ -102,10 +97,14 @@ void common_hal_displayio_release_displays(void) {
common_hal_displayio_i2cdisplay_deinit(&displays[i].i2cdisplay_bus);
} else if (bus_type == &displayio_parallelbus_type) {
common_hal_displayio_parallelbus_deinit(&displays[i].parallel_bus);
-#if CIRCUITPY_FRAMEBUFFERIO
+#if CIRCUITPY_RGBMATRIX
} else if (bus_type == &rgbmatrix_RGBMatrix_type) {
common_hal_rgbmatrix_rgbmatrix_deinit(&displays[i].rgbmatrix);
#endif
+#if CIRCUITPY_SHARPDISPLAY
+ } else if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) {
+ common_hal_sharpdisplay_framebuffer_deinit(&displays[i].sharpdisplay);
+#endif
}
displays[i].fourwire_bus.base.type = &mp_type_NoneType;
}
@@ -170,10 +169,15 @@ void reset_displays(void) {
#if CIRCUITPY_RGBMATRIX
} else if (displays[i].rgbmatrix.base.type == &rgbmatrix_RGBMatrix_type) {
rgbmatrix_rgbmatrix_obj_t * pm = &displays[i].rgbmatrix;
- if(!any_display_uses_this_rgbmatrix(pm)) {
+ if(!any_display_uses_this_framebuffer(&pm->base)) {
common_hal_rgbmatrix_rgbmatrix_deinit(pm);
}
#endif
+#if CIRCUITPY_SHARPDISPLAY
+ } else if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) {
+ sharpdisplay_framebuffer_obj_t * sharp = &displays[i].sharpdisplay;
+ common_hal_sharpdisplay_framebuffer_reset(sharp);
+#endif
} else {
// Not an active display bus.
continue;
@@ -190,9 +194,7 @@ void reset_displays(void) {
common_hal_displayio_epaperdisplay_show(display, NULL);
#if CIRCUITPY_FRAMEBUFFERIO
} else if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) {
- framebufferio_framebufferdisplay_obj_t* display = &displays[i].framebuffer_display;
- display->auto_refresh = true;
- common_hal_framebufferio_framebufferdisplay_show(display, NULL);
+ framebufferio_framebufferdisplay_reset(&displays[i].framebuffer_display);
#endif
}
}
@@ -205,6 +207,11 @@ void displayio_gc_collect(void) {
rgbmatrix_rgbmatrix_collect_ptrs(&displays[i].rgbmatrix);
}
#endif
+#if CIRCUITPY_SHARPDISPLAY
+ if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) {
+ common_hal_sharpdisplay_framebuffer_collect_ptrs(&displays[i].sharpdisplay);
+ }
+#endif
if (displays[i].display.base.type == NULL) {
continue;
@@ -377,8 +384,8 @@ primary_display_t *allocate_display_or_raise(void) {
}
primary_display_t *allocate_display_bus(void) {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
- mp_const_obj_t display_type = displays[i].display.base.type;
- if (display_type == NULL || display_type == &mp_type_NoneType) {
+ mp_const_obj_t display_bus_type = displays[i].bus_base.type;
+ if (display_bus_type == NULL || display_bus_type == &mp_type_NoneType) {
return &displays[i];
}
}
diff --git a/shared-module/displayio/__init__.h b/shared-module/displayio/__init__.h
index 9eb10c28b..44ad5a9a9 100644
--- a/shared-module/displayio/__init__.h
+++ b/shared-module/displayio/__init__.h
@@ -36,18 +36,28 @@
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/displayio/I2CDisplay.h"
#include "shared-bindings/displayio/ParallelBus.h"
+#if CIRCUITPY_RGBMATRIX
#include "shared-bindings/rgbmatrix/RGBMatrix.h"
+#endif
+#if CIRCUITPY_SHARPDISPLAY
+#include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h"
+#endif
typedef struct {
union {
+ mp_obj_base_t bus_base;
displayio_fourwire_obj_t fourwire_bus;
displayio_i2cdisplay_obj_t i2cdisplay_bus;
displayio_parallelbus_obj_t parallel_bus;
#if CIRCUITPY_RGBMATRIX
rgbmatrix_rgbmatrix_obj_t rgbmatrix;
#endif
+#if CIRCUITPY_SHARPDISPLAY
+ sharpdisplay_framebuffer_obj_t sharpdisplay;
+#endif
};
union {
+ mp_obj_base_t display_base;
displayio_display_obj_t display;
displayio_epaperdisplay_obj_t epaper_display;
#if CIRCUITPY_FRAMEBUFFERIO
diff --git a/shared-module/displayio/display_core.c b/shared-module/displayio/display_core.c
index 43f2d1937..57d33b565 100644
--- a/shared-module/displayio/display_core.c
+++ b/shared-module/displayio/display_core.c
@@ -48,6 +48,7 @@ void displayio_display_core_construct(displayio_display_core_t* self,
uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word) {
self->colorspace.depth = color_depth;
self->colorspace.grayscale = grayscale;
+ self->colorspace.grayscale_bit = 8 - color_depth;
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;
@@ -85,7 +86,10 @@ void displayio_display_core_construct(displayio_display_core_t* self,
self->bus = bus;
- supervisor_start_terminal(width, height);
+ // (offsetof core is equal in all display types)
+ if (self == &displays[0].display.core) {
+ supervisor_start_terminal(width, height);
+ }
self->width = width;
self->height = height;
@@ -197,7 +201,7 @@ bool displayio_display_core_get_dither(displayio_display_core_t* self){
}
bool displayio_display_core_bus_free(displayio_display_core_t *self) {
- return self->bus_free(self->bus);
+ return !self->bus || self->bus_free(self->bus);
}
bool displayio_display_core_begin_transaction(displayio_display_core_t* self) {
@@ -208,7 +212,10 @@ void displayio_display_core_end_transaction(displayio_display_core_t* self) {
self->end_transaction(self->bus);
}
-void displayio_display_core_set_region_to_update(displayio_display_core_t* self, uint8_t column_command, uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command, bool data_as_commands, bool always_toggle_chip_select, displayio_area_t* area) {
+void displayio_display_core_set_region_to_update(displayio_display_core_t* self, uint8_t column_command,
+ uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command,
+ bool data_as_commands, bool always_toggle_chip_select,
+ displayio_area_t* area, bool SH1107_addressing) {
uint16_t x1 = area->x1;
uint16_t x2 = area->x2;
uint16_t y1 = area->y1;
@@ -253,8 +260,17 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
data[data_length++] = x2 >> 8;
data[data_length++] = x2 & 0xff;
}
+ // Quirk for SH1107 "SH1107_addressing"
+ // Note... column is y! page is x!
+ // Page address command = 0xB0
+ if (SH1107_addressing) {
+ // set the page to our x value
+ data[0] = 0xB0 | (x1 & 0x0F);
+ data_length = 1;
+ }
self->send(self->bus, data_type, chip_select, data, data_length);
displayio_display_core_end_transaction(self);
+
if (set_current_column_command != NO_COMMAND) {
uint8_t command = set_current_column_command;
displayio_display_core_begin_transaction(self);
@@ -283,7 +299,16 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
data[data_length++] = y2 >> 8;
data[data_length++] = y2 & 0xff;
}
+ // Quirk for SH1107 "SH1107_addressing"
+ // Note... column is y! page is x!
+ // Column lower command = 0x00, Column upper command = 0x10
+ if (SH1107_addressing) {
+ data[0] = y1 & 0x0F; // 0x00 to 0x0F
+ data[1] = (y1 >> 4 & 0x0F) | 0x10; // 0x10 to 0x17
+ data_length = 2;
+ }
self->send(self->bus, data_type, chip_select, data, data_length);
+
displayio_display_core_end_transaction(self);
if (set_current_row_command != NO_COMMAND) {
@@ -295,8 +320,17 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
}
}
-void displayio_display_core_start_refresh(displayio_display_core_t* self) {
+bool displayio_display_core_start_refresh(displayio_display_core_t* self) {
+ if (!displayio_display_core_bus_free(self)) {
+ // Can't acquire display bus; skip updating this display. Try next display.
+ return false;
+ }
+ if (self->refresh_in_progress) {
+ return false;
+ }
+ self->refresh_in_progress = true;
self->last_refresh = supervisor_ticks_ms64();
+ return true;
}
void displayio_display_core_finish_refresh(displayio_display_core_t* self) {
@@ -305,6 +339,7 @@ void displayio_display_core_finish_refresh(displayio_display_core_t* self) {
displayio_group_finish_refresh(self->current_group);
}
self->full_refresh = false;
+ self->refresh_in_progress = false;
self->last_refresh = supervisor_ticks_ms64();
}
diff --git a/shared-module/displayio/display_core.h b/shared-module/displayio/display_core.h
index e4fd62d4a..fe6cb6f3f 100644
--- a/shared-module/displayio/display_core.h
+++ b/shared-module/displayio/display_core.h
@@ -54,6 +54,7 @@ typedef struct {
int16_t colstart;
int16_t rowstart;
bool full_refresh; // New group means we need to refresh the whole display.
+ bool refresh_in_progress;
} displayio_display_core_t;
void displayio_display_core_construct(displayio_display_core_t* self,
@@ -74,11 +75,14 @@ bool displayio_display_core_bus_free(displayio_display_core_t *self);
bool displayio_display_core_begin_transaction(displayio_display_core_t* self);
void displayio_display_core_end_transaction(displayio_display_core_t* self);
-void displayio_display_core_set_region_to_update(displayio_display_core_t* self, uint8_t column_command, uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command, bool data_as_commands, bool always_toggle_chip_select, displayio_area_t* area);
+void displayio_display_core_set_region_to_update(displayio_display_core_t* self, uint8_t column_command,
+ uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command,
+ bool data_as_commands, bool always_toggle_chip_select,
+ displayio_area_t* area, bool SH1107_addressing);
void release_display_core(displayio_display_core_t* self);
-void displayio_display_core_start_refresh(displayio_display_core_t* self);
+bool displayio_display_core_start_refresh(displayio_display_core_t* self);
void displayio_display_core_finish_refresh(displayio_display_core_t* self);
void displayio_display_core_collect_ptrs(displayio_display_core_t* self);