Skip to content

Commit 5ac3c36

Browse files
authored
Merge pull request adafruit#3450 from mdroberts1243/New_quirk_for_SH1107
New quirk for sh1107
2 parents 2ac2f62 + ef245ef commit 5ac3c36

File tree

26 files changed

+99
-29
lines changed

26 files changed

+99
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ TAGS
8080
*.mo
8181

8282
.vscode
83+
.idea
8384

8485
# Python Virtual Environments
8586
####################

ports/atmel-samd/boards/hallowing_m0_express/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ void board_init(void) {
110110
false, // data_as_commands
111111
true, // auto_refresh
112112
60, // native_frames_per_second
113-
true); // backlight_on_high
113+
true, // backlight_on_high
114+
false); // not SH1107
114115
}
115116

116117
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/hallowing_m4_express/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ void board_init(void) {
9191
false, // data_as_commands
9292
true, // auto_refresh
9393
60, // native_frames_per_second
94-
true); // backlight_on_high
94+
true, // backlight_on_high
95+
false); // not SH1107
9596
}
9697

9798
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/monster_m4sk/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ void board_init(void) {
9292
false, // data_as_commands
9393
true, // auto_refresh
9494
60, // native_frames_per_second
95-
true); // backlight_on_high
95+
true, // backlight_on_high
96+
false); // SH1107_addressing
9697
}
9798

9899
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/pewpew_m4/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ void board_init(void) {
143143
false, // data_as_commands
144144
false, // auto_refresh
145145
20, // native_frames_per_second
146-
true); // backlight_on_high
146+
true, // backlight_on_high
147+
false); // SH1107_addressing
147148
}
148149

149150
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/pybadge/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ void board_init(void) {
114114
false, // data_as_commands
115115
true, // auto_refresh
116116
60, // native_frames_per_second
117-
true); // backlight_on_high
117+
true, // backlight_on_high
118+
false); // SH1107_addressing
118119
}
119120

120121
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/pybadge_airlift/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ void board_init(void) {
9292
false, // data_as_commands
9393
true, // auto_refresh
9494
60, // native_frames_per_second
95-
true); // backlight_on_high
95+
true, // backlight_on_high
96+
false); // SH1107_addressing
9697
}
9798

9899
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/pygamer/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ void board_init(void) {
114114
false, // data_as_commands
115115
true, // auto_refresh
116116
60, // native_frames_per_second
117-
true); // backlight_on_high
117+
true, // backlight_on_high
118+
false); // SH1107_addressing
118119
}
119120

120121
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/pygamer_advance/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ void board_init(void) {
9292
false, // data_as_commands
9393
true, // auto_refresh
9494
60, // native_frames_per_second
95-
true); // backlight_on_high
95+
true, // backlight_on_high
96+
false); // SH1107_addressing
9697
}
9798

9899
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/pyportal/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ void board_init(void) {
100100
false, // data_as_commands
101101
true, // auto_refresh
102102
60, // native_frames_per_second
103-
true); // backlight_on_high
103+
true, // backlight_on_high
104+
false); // SH1107_addressing
104105
}
105106

106107
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/pyportal_titano/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ void board_init(void) {
117117
false, // data_as_commands
118118
true, // auto_refresh
119119
60, // native_frames_per_second
120-
true); // backlight_on_high
120+
true, // backlight_on_high
121+
false); // SH1107_addressing
121122
}
122123

123124
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/seeeduino_wio_terminal/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ void board_init(void) {
109109
false, // data_as_commands
110110
true, // auto_refresh
111111
60, // native_frames_per_second
112-
true); // backlight_on_high
112+
true, // backlight_on_high
113+
false); // SH1107_addressing
113114

114115
// Enabling the Power of the 40-pin at the back
115116
CTR_5V.base.type = &digitalio_digitalinout_type;

ports/atmel-samd/boards/ugame10/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ void board_init(void) {
111111
false, // data as commands
112112
true, // auto_refresh
113113
60, // native_frames_per_second
114-
true); // backlight_on_high
114+
true, // backlight_on_high
115+
false); // SH1107_addressing
115116
}
116117

117118
bool board_requests_safe_mode(void) {

ports/nrf/boards/clue_nrf52840_express/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ void board_init(void) {
9191
false, // data_as_commands
9292
true, // auto_refresh
9393
60, // native_frames_per_second
94-
true); // backlight_on_high
94+
true, // backlight_on_high
95+
false); // not SH1107
9596
}
9697

9798
bool board_requests_safe_mode(void) {

ports/nrf/boards/hiibot_bluefi/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ void board_init(void) {
9292
false, // data_as_commands
9393
true, // auto_refresh
9494
60, // native_frames_per_second
95-
true); // backlight_on_high
95+
true, // backlight_on_high
96+
false); // SH1107_addressing
9697
}
9798

9899
bool board_requests_safe_mode(void) {

ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ void board_init(void) {
9292
false, // data_as_commands
9393
true, // auto_refresh
9494
60, // native_frames_per_second
95-
true); // backlight_on_high
95+
true, // backlight_on_high
96+
false); // SH1107_addressing
9697
}
9798

9899
bool board_requests_safe_mode(void) {

ports/nrf/boards/ohs2020_badge/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ void board_init(void) {
9191
false, // data_as_commands
9292
true, // auto_refresh
9393
60, // native_frames_per_second
94-
false); // backlight_on_high
94+
false, // backlight_on_high
95+
false); // SH1107_addressing
9596
}
9697

9798
bool board_requests_safe_mode(void) {

ports/stm/boards/meowbit_v121/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ void board_init(void) {
111111
false, // data_as_commands
112112
true, // auto_refresh
113113
60, // native_frames_per_second
114-
true); // backlight_on_high
114+
true, // backlight_on_high
115+
false); // SH1107_addressing
115116
}
116117

117118
bool board_requests_safe_mode(void) {

shared-bindings/displayio/Display.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,22 @@
105105
//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism.
106106
//| :param bool single_byte_bounds: Display column and row commands use single bytes
107107
//| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this.
108+
//| :param bool SH1107_addressing: Special quirk for SH1107, use upper/lower column set and page set
108109
//| :param bool auto_refresh: Automatically refresh the screen
109110
//| :param int native_frames_per_second: Number of display refreshes per second that occur with the given init_sequence.
110111
//| :param bool backlight_on_high: If True, pulling the backlight pin high turns the backlight on."""
111112
//| ...
112113
//|
113-
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) {
114-
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 };
114+
STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args,
115+
const mp_obj_t *pos_args, mp_map_t *kw_args) {
116+
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart,
117+
ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row,
118+
ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_reverse_bytes_in_word,
119+
ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command,
120+
ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command,
121+
ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands,
122+
ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high,
123+
ARG_SH1107_addressing };
115124
static const mp_arg_t allowed_args[] = {
116125
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
117126
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -139,6 +148,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
139148
{ MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
140149
{ MP_QSTR_native_frames_per_second, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 60} },
141150
{ MP_QSTR_backlight_on_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
151+
{ MP_QSTR_SH1107_addressing, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }
142152
};
143153
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
144154
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -180,7 +190,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
180190
args[ARG_data_as_commands].u_bool,
181191
args[ARG_auto_refresh].u_bool,
182192
args[ARG_native_frames_per_second].u_int,
183-
args[ARG_backlight_on_high].u_bool
193+
args[ARG_backlight_on_high].u_bool,
194+
args[ARG_SH1107_addressing].u_bool
184195
);
185196

186197
return self;

shared-bindings/displayio/Display.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
4545
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll,
4646
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command,
4747
mp_float_t brightness, bool auto_brightness,
48-
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second, bool backlight_on_high);
48+
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
49+
bool backlight_on_high, bool SH1107_addressing);
4950

5051
bool common_hal_displayio_display_show(displayio_display_obj_t* self,
5152
displayio_group_t* root_group);

shared-module/_stage/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void render_stage(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
4545
area.y2 = y1;
4646
displayio_display_core_set_region_to_update(
4747
&display->core, display->set_column_command, display->set_row_command,
48-
NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area);
48+
NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area, display->SH1107_addressing);
4949

5050
while (!displayio_display_core_begin_transaction(&display->core)) {
5151
RUN_BACKGROUND_TASKS;

shared-module/displayio/Display.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
4848
uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll,
4949
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin,
5050
uint16_t brightness_command, mp_float_t brightness, bool auto_brightness,
51-
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second, bool backlight_on_high) {
51+
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
52+
bool backlight_on_high, bool SH1107_addressing) {
53+
5254
// Turn off auto-refresh as we init.
5355
self->auto_refresh = false;
5456
uint16_t ram_width = 0x100;
@@ -68,6 +70,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
6870
self->first_manual_refresh = !auto_refresh;
6971
self->data_as_commands = data_as_commands;
7072
self->backlight_on_high = backlight_on_high;
73+
self->SH1107_addressing = SH1107_addressing;
7174

7275
self->native_frames_per_second = native_frames_per_second;
7376
self->native_ms_per_frame = 1000 / native_frames_per_second;
@@ -240,11 +243,17 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
240243
if (!displayio_display_core_clip_area(&self->core, area, &clipped)) {
241244
return true;
242245
}
243-
uint16_t subrectangles = 1;
244246
uint16_t rows_per_buffer = displayio_area_height(&clipped);
245247
uint8_t pixels_per_word = (sizeof(uint32_t) * 8) / self->core.colorspace.depth;
246248
uint16_t pixels_per_buffer = displayio_area_size(&clipped);
247-
if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) {
249+
250+
uint16_t subrectangles = 1;
251+
// for SH1107 and other boundary constrained controllers
252+
// write one single row at a time
253+
if (self->SH1107_addressing) {
254+
subrectangles = rows_per_buffer; // vertical (column mode) write each separately (height times)
255+
rows_per_buffer = 1;
256+
} else if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) {
248257
rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped);
249258
if (rows_per_buffer == 0) {
250259
rows_per_buffer = 1;
@@ -286,7 +295,9 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
286295
}
287296
remaining_rows -= rows_per_buffer;
288297

289-
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);
298+
displayio_display_core_set_region_to_update(&self->core, self->set_column_command,
299+
self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false,
300+
&subrectangle, self->SH1107_addressing);
290301

291302
uint16_t subrectangle_size_bytes;
292303
if (self->core.colorspace.depth >= 8) {

shared-module/displayio/Display.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ typedef struct {
6060
bool auto_brightness;
6161
bool updating_backlight;
6262
bool backlight_on_high;
63+
// new quirk for sh1107
64+
bool SH1107_addressing;
6365
} displayio_display_obj_t;
6466

6567
void displayio_display_background(displayio_display_obj_t* self);

shared-module/displayio/EPaperDisplay.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,11 @@ bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t* self, c
238238
for (uint8_t pass = 0; pass < passes; pass++) {
239239
uint16_t remaining_rows = displayio_area_height(&clipped);
240240

241+
// added false parameter at end for SH1107_addressing quirk
241242
if (self->set_row_window_command != NO_COMMAND) {
242-
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);
243+
displayio_display_core_set_region_to_update(&self->core, self->set_column_window_command,
244+
self->set_row_window_command, self->set_current_column_command, self->set_current_row_command,
245+
false, self->chip_select, &clipped, false);
243246
}
244247

245248
uint8_t write_command = self->write_black_ram_command;

shared-module/displayio/display_core.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ void displayio_display_core_end_transaction(displayio_display_core_t* self) {
208208
self->end_transaction(self->bus);
209209
}
210210

211-
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) {
211+
void displayio_display_core_set_region_to_update(displayio_display_core_t* self, uint8_t column_command,
212+
uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command,
213+
bool data_as_commands, bool always_toggle_chip_select,
214+
displayio_area_t* area, bool SH1107_addressing) {
212215
uint16_t x1 = area->x1;
213216
uint16_t x2 = area->x2;
214217
uint16_t y1 = area->y1;
@@ -253,8 +256,17 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
253256
data[data_length++] = x2 >> 8;
254257
data[data_length++] = x2 & 0xff;
255258
}
259+
// Quirk for SH1107 "SH1107_addressing"
260+
// Note... column is y! page is x!
261+
// Page address command = 0xB0
262+
if (SH1107_addressing) {
263+
// set the page to our x value
264+
data[0] = 0xB0 | (x1 & 0x0F);
265+
data_length = 1;
266+
}
256267
self->send(self->bus, data_type, chip_select, data, data_length);
257268
displayio_display_core_end_transaction(self);
269+
258270
if (set_current_column_command != NO_COMMAND) {
259271
uint8_t command = set_current_column_command;
260272
displayio_display_core_begin_transaction(self);
@@ -283,7 +295,16 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
283295
data[data_length++] = y2 >> 8;
284296
data[data_length++] = y2 & 0xff;
285297
}
298+
// Quirk for SH1107 "SH1107_addressing"
299+
// Note... column is y! page is x!
300+
// Column lower command = 0x00, Column upper command = 0x10
301+
if (SH1107_addressing) {
302+
data[0] = y1 & 0x0F; // 0x00 to 0x0F
303+
data[1] = (y1 >> 4 & 0x0F) | 0x10; // 0x10 to 0x17
304+
data_length = 2;
305+
}
286306
self->send(self->bus, data_type, chip_select, data, data_length);
307+
287308
displayio_display_core_end_transaction(self);
288309

289310
if (set_current_row_command != NO_COMMAND) {

shared-module/displayio/display_core.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ bool displayio_display_core_bus_free(displayio_display_core_t *self);
7474
bool displayio_display_core_begin_transaction(displayio_display_core_t* self);
7575
void displayio_display_core_end_transaction(displayio_display_core_t* self);
7676

77-
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);
77+
void displayio_display_core_set_region_to_update(displayio_display_core_t* self, uint8_t column_command,
78+
uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command,
79+
bool data_as_commands, bool always_toggle_chip_select,
80+
displayio_area_t* area, bool SH1107_addressing);
7881

7982
void release_display_core(displayio_display_core_t* self);
8083

0 commit comments

Comments
 (0)