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 all 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
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/hallowing_m0_express/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // not SH1107
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/hallowing_m4_express/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // not SH1107
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/monster_m4sk/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/pewpew_m4/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ void board_init(void) {
false, // data_as_commands
false, // auto_refresh
20, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/pybadge/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/pybadge_airlift/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/pygamer/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/pygamer_advance/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/pyportal/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/pyportal_titano/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/seeeduino_wio_terminal/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing

// Enabling the Power of the 40-pin at the back
CTR_5V.base.type = &digitalio_digitalinout_type;
Expand Down
3 changes: 2 additions & 1 deletion ports/atmel-samd/boards/ugame10/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void board_init(void) {
false, // data as commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/nrf/boards/clue_nrf52840_express/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // not SH1107
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/nrf/boards/hiibot_bluefi/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/nrf/boards/ohs2020_badge/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
false); // backlight_on_high
false, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
3 changes: 2 additions & 1 deletion ports/stm/boards/meowbit_v121/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void board_init(void) {
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true); // backlight_on_high
true, // backlight_on_high
false); // SH1107_addressing
}

bool board_requests_safe_mode(void) {
Expand Down
17 changes: 14 additions & 3 deletions shared-bindings/displayio/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,22 @@
//| :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 SH1107_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 };
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,
ARG_SH1107_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 +148,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_SH1107_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 +190,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_SH1107_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 SH1107_addressing);

bool common_hal_displayio_display_show(displayio_display_obj_t* self,
displayio_group_t* root_group);
Expand Down
2 changes: 1 addition & 1 deletion shared-module/_stage/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
area.y2 = y1;
displayio_display_core_set_region_to_update(
&display->core, display->set_column_command, display->set_row_command,
NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area);
NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area, display->SH1107_addressing);

while (!displayio_display_core_begin_transaction(&display->core)) {
RUN_BACKGROUND_TASKS;
Expand Down
19 changes: 15 additions & 4 deletions shared-module/displayio/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -240,11 +243,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;
Expand Down Expand Up @@ -286,7 +295,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) {
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 SH1107_addressing;
} displayio_display_obj_t;

void displayio_display_background(displayio_display_obj_t* self);
Expand Down
5 changes: 4 additions & 1 deletion shared-module/displayio/EPaperDisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,11 @@ bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, c
for (uint8_t pass = 0; pass < passes; pass++) {
uint16_t remaining_rows = displayio_area_height(&clipped);

// added false parameter at end for SH1107_addressing quirk
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
23 changes: 22 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 SH1107_addressing) {
uint16_t x1 = area->x1;
uint16_t x2 = area->x2;
uint16_t y1 = area->y1;
Expand Down Expand Up @@ -253,8 +256,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);
Expand Down Expand Up @@ -283,7 +295,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) {
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 SH1107_addressing);

void release_display_core(displayio_display_core_t* self);

Expand Down