Skip to content

Commit 06a3d15

Browse files
committed
Mostly-working-version with comments
1 parent 5a176c2 commit 06a3d15

File tree

7 files changed

+64
-30
lines changed

7 files changed

+64
-30
lines changed

shared-bindings/displayio/Display.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +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 column_and_page_addressing: Special quirk for SH1107, use upper/lower column set and page set
108+
//| :param bool SH1107_addressing: Special quirk for SH1107, use upper/lower column set and page set
109109
//| :param bool auto_refresh: Automatically refresh the screen
110110
//| :param int native_frames_per_second: Number of display refreshes per second that occur with the given init_sequence.
111111
//| :param bool backlight_on_high: If True, pulling the backlight pin high turns the backlight on."""
112112
//| ...
113113
//|
114-
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) {
115-
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 };
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 };
116124
static const mp_arg_t allowed_args[] = {
117125
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
118126
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -140,7 +148,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
140148
{ MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
141149
{ MP_QSTR_native_frames_per_second, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 60} },
142150
{ MP_QSTR_backlight_on_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
143-
{ MP_QSTR_column_and_page_addressing, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
151+
{ MP_QSTR_SH1107_addressing, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }
144152
};
145153
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
146154
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -183,7 +191,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
183191
args[ARG_auto_refresh].u_bool,
184192
args[ARG_native_frames_per_second].u_int,
185193
args[ARG_backlight_on_high].u_bool,
186-
args[ARG_column_and_page_addressing].u_bool
194+
args[ARG_SH1107_addressing].u_bool
187195
);
188196

189197
return self;

shared-bindings/displayio/Display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
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,
4848
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
49-
bool backlight_on_high, bool column_and_page_addressing);
49+
bool backlight_on_high, bool SH1107_addressing);
5050

5151
bool common_hal_displayio_display_show(displayio_display_obj_t* self,
5252
displayio_group_t* root_group);

shared-module/displayio/Display.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
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,
5151
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
52-
bool backlight_on_high, bool column_and_page_addressing) {
52+
bool backlight_on_high, bool SH1107_addressing) {
53+
5354
// Turn off auto-refresh as we init.
5455
self->auto_refresh = false;
5556
uint16_t ram_width = 0x100;
@@ -69,7 +70,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
6970
self->first_manual_refresh = !auto_refresh;
7071
self->data_as_commands = data_as_commands;
7172
self->backlight_on_high = backlight_on_high;
72-
self->column_and_page_addressing = column_and_page_addressing;
73+
self->SH1107_addressing = SH1107_addressing;
7374

7475
self->native_frames_per_second = native_frames_per_second;
7576
self->native_ms_per_frame = 1000 / native_frames_per_second;
@@ -242,11 +243,23 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
242243
if (!displayio_display_core_clip_area(&self->core, area, &clipped)) {
243244
return true;
244245
}
245-
uint16_t subrectangles = 1;
246246
uint16_t rows_per_buffer = displayio_area_height(&clipped);
247247
uint8_t pixels_per_word = (sizeof(uint32_t) * 8) / self->core.colorspace.depth;
248248
uint16_t pixels_per_buffer = displayio_area_size(&clipped);
249-
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+
}
256+
257+
// Skip this recalculation of subrectangles if SH1107 (each subrectangle is a single row)
258+
// [mdroberts1243] I am worried/confused about the pixels_in_byte_share_row calculation though
259+
// since it makes sense to be on a byte boundary (actually a page boundary too)
260+
// seems to work as is though.
261+
if ((displayio_area_size(&clipped) > buffer_size * pixels_per_word)
262+
&& (!self->SH1107_addressing)) {
250263
rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped);
251264
if (rows_per_buffer == 0) {
252265
rows_per_buffer = 1;
@@ -283,14 +296,23 @@ STATIC bool _refresh_area(displayio_display_obj_t* self, const displayio_area_t*
283296
.x2 = clipped.x2,
284297
.y2 = clipped.y1 + rows_per_buffer * (j + 1)
285298
};
286-
if (remaining_rows < rows_per_buffer) {
299+
if (self->SH1107_addressing) {
300+
// one row only for SH1107 in vertical (column) mode
301+
subrectangle.y1 = clipped.y1 + j;
302+
subrectangle.y2 = clipped.y1 + (j + 1);
303+
};
304+
if ((remaining_rows < rows_per_buffer) && (!self->SH1107_addressing)) {
287305
subrectangle.y2 = subrectangle.y1 + remaining_rows;
288306
}
289-
remaining_rows -= rows_per_buffer;
307+
if (self->SH1107_addressing) {
308+
remaining_rows -= 1;
309+
} else {
310+
remaining_rows -= rows_per_buffer;
311+
}
290312

291313
displayio_display_core_set_region_to_update(&self->core, self->set_column_command,
292314
self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false,
293-
&subrectangle, self->column_and_page_addressing);
315+
&subrectangle, self->SH1107_addressing);
294316

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

shared-module/displayio/Display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ typedef struct {
6161
bool updating_backlight;
6262
bool backlight_on_high;
6363
// new quirk for sh1107
64-
bool column_and_page_addressing;
64+
bool SH1107_addressing;
6565
} displayio_display_obj_t;
6666

6767
void displayio_display_background(displayio_display_obj_t* self);

shared-module/displayio/EPaperDisplay.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ 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) {
242243
displayio_display_core_set_region_to_update(&self->core, self->set_column_window_command,
243244
self->set_row_window_command, self->set_current_column_command, self->set_current_row_command,

shared-module/displayio/display_core.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include <string.h>
4242

4343
#define DISPLAYIO_CORE_DEBUG(...) (void)0
44-
// #define DISPLAYIO_CORE_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
44+
//#define DISPLAYIO_CORE_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
4545

4646
void displayio_display_core_construct(displayio_display_core_t* self,
4747
mp_obj_t bus, uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation,
@@ -57,7 +57,7 @@ void displayio_display_core_construct(displayio_display_core_t* self,
5757
self->colstart = colstart;
5858
self->rowstart = rowstart;
5959
self->last_refresh = 0;
60-
60+
6161
// (framebufferdisplay already validated its 'bus' is a buffer-protocol object)
6262
if (bus) {
6363
if (MP_OBJ_IS_TYPE(bus, &displayio_parallelbus_type)) {
@@ -211,7 +211,7 @@ void displayio_display_core_end_transaction(displayio_display_core_t* self) {
211211
void displayio_display_core_set_region_to_update(displayio_display_core_t* self, uint8_t column_command,
212212
uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command,
213213
bool data_as_commands, bool always_toggle_chip_select,
214-
displayio_area_t* area, bool column_and_page_addressing) {
214+
displayio_area_t* area, bool SH1107_addressing) {
215215
uint16_t x1 = area->x1;
216216
uint16_t x2 = area->x2;
217217
uint16_t y1 = area->y1;
@@ -256,12 +256,13 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
256256
data[data_length++] = x2 >> 8;
257257
data[data_length++] = x2 & 0xff;
258258
}
259-
// Quirk for SH1107 "column_and_page_addressing"
260-
// Column lower command = 0x00, Column upper command = 0x10
261-
if (column_and_page_addressing) {
262-
data[0] = 0x00 | (x1 & 0x0F);
263-
data[1] = 0x10 | (x1 >> 4);
264-
data_length = 2;
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 & 0x07);
265+
data_length = 1;
265266
}
266267
self->send(self->bus, data_type, chip_select, data, data_length);
267268
displayio_display_core_end_transaction(self);
@@ -294,11 +295,13 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t* self,
294295
data[data_length++] = y2 >> 8;
295296
data[data_length++] = y2 & 0xff;
296297
}
297-
// Quirk for SH1107 "column_and_page_addressing"
298-
// Page address command = 0xB0
299-
if (column_and_page_addressing) {
300-
data[0] = 0xB0 | (y1 & 0x07);
301-
data_length = 1;
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;
302305
}
303306
self->send(self->bus, data_type, chip_select, data, data_length);
304307

@@ -319,7 +322,7 @@ void displayio_display_core_start_refresh(displayio_display_core_t* self) {
319322

320323
void displayio_display_core_finish_refresh(displayio_display_core_t* self) {
321324
if (self->current_group != NULL) {
322-
DISPLAYIO_CORE_DEBUG("displayiocore group_finish_refresh\n");
325+
// DISPLAYIO_CORE_DEBUG("displayiocore group_finish_refresh\n");
323326
displayio_group_finish_refresh(self->current_group);
324327
}
325328
self->full_refresh = false;

shared-module/displayio/display_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void displayio_display_core_end_transaction(displayio_display_core_t* self);
7777
void displayio_display_core_set_region_to_update(displayio_display_core_t* self, uint8_t column_command,
7878
uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command,
7979
bool data_as_commands, bool always_toggle_chip_select,
80-
displayio_area_t* area, bool column_and_page_addressing);
80+
displayio_area_t* area, bool SH1107_addressing);
8181

8282
void release_display_core(displayio_display_core_t* self);
8383

0 commit comments

Comments
 (0)