Skip to content

New quirk for sh1107 #3450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ TAGS
*.mo

.vscode
.idea

# Python Virtual Environments
####################
Expand Down
7 changes: 5 additions & 2 deletions shared-bindings/displayio/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,14 @@
//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism.
//| :param bool single_byte_bounds: Display column and row commands use single bytes
//| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this.
//| :param bool column_and_page_addressing: Special quirk for SH1107, use upper/lower column set and page set
//| :param bool auto_refresh: Automatically refresh the screen
//| :param int native_frames_per_second: Number of display refreshes per second that occur with the given init_sequence.
//| :param bool backlight_on_high: If True, pulling the backlight pin high turns the backlight on."""
//| ...
//|
STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_reverse_bytes_in_word, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high };
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_reverse_bytes_in_word, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high, ARG_column_and_page_addressing };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
Expand Down Expand Up @@ -139,6 +140,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
{ MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
{ MP_QSTR_native_frames_per_second, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 60} },
{ MP_QSTR_backlight_on_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
{ MP_QSTR_column_and_page_addressing, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
Expand Down Expand Up @@ -180,7 +182,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
args[ARG_data_as_commands].u_bool,
args[ARG_auto_refresh].u_bool,
args[ARG_native_frames_per_second].u_int,
args[ARG_backlight_on_high].u_bool
args[ARG_backlight_on_high].u_bool,
args[ARG_column_and_page_addressing].u_bool
);

return self;
Expand Down
3 changes: 2 additions & 1 deletion shared-bindings/displayio/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
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,
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 column_and_page_addressing);

bool common_hal_displayio_display_show(displayio_display_obj_t* self,
displayio_group_t* root_group);
Expand Down
8 changes: 6 additions & 2 deletions shared-module/displayio/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ 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 column_and_page_addressing) {
// Turn off auto-refresh as we init.
self->auto_refresh = false;
uint16_t ram_width = 0x100;
Expand All @@ -68,6 +69,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->column_and_page_addressing = column_and_page_addressing;

self->native_frames_per_second = native_frames_per_second;
self->native_ms_per_frame = 1000 / native_frames_per_second;
Expand Down Expand Up @@ -286,7 +288,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->column_and_page_addressing);

uint16_t subrectangle_size_bytes;
if (self->core.colorspace.depth >= 8) {
Expand Down
2 changes: 2 additions & 0 deletions shared-module/displayio/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ typedef struct {
bool auto_brightness;
bool updating_backlight;
bool backlight_on_high;
// new quirk for sh1107
bool column_and_page_addressing;
} displayio_display_obj_t;

void displayio_display_background(displayio_display_obj_t* self);
Expand Down
4 changes: 3 additions & 1 deletion shared-module/displayio/EPaperDisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, c
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);
}

uint8_t write_command = self->write_black_ram_command;
Expand Down
21 changes: 20 additions & 1 deletion shared-module/displayio/display_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,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 column_and_page_addressing) {
uint16_t x1 = area->x1;
uint16_t x2 = area->x2;
uint16_t y1 = area->y1;
Expand Down Expand Up @@ -253,8 +256,16 @@ 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 "column_and_page_addressing"
// Column lower command = 0x00, Column upper command = 0x10
if (column_and_page_addressing) {
data[0] = 0x00 | (x1 & 0x0F);
data[1] = 0x10 | (x1 >> 4);
data_length = 2;
}
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);
Expand Down Expand Up @@ -283,6 +294,14 @@ 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 "column_and_page_addressing"
// Page address command = 0xB0
if (column_and_page_addressing) {
data[0] = 0xB0 | (y1 & 0x07);
data_length = 1;
}
self->send(self->bus, data_type, chip_select, data, data_length);

self->send(self->bus, data_type, chip_select, data, data_length);
displayio_display_core_end_transaction(self);

Expand Down
5 changes: 4 additions & 1 deletion shared-module/displayio/display_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ 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 column_and_page_addressing);

void release_display_core(displayio_display_core_t* self);

Expand Down