Skip to content

Commit 8f1fc6c

Browse files
author
Melissa LeBlanc-Williams
committed
Added option to easily treat SPI parameter data as commands
1 parent b5bc8b3 commit 8f1fc6c

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

shared-bindings/displayio/Display.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
//| Most people should not use this class directly. Use a specific display driver instead that will
5151
//| contain the initialization sequence at minimum.
5252
//|
53-
//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, single_byte_bounds=False)
53+
//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, single_byte_bounds=False, data_as_commands=False)
5454
//|
5555
//| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
5656
//|
@@ -92,9 +92,10 @@
9292
//| :param int set_vertical_scroll: Command used to set the first row to show
9393
//| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight
9494
//| :param bool single_byte_bounds: Display column and row commands use single bytes
95+
//| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this.
9596
//|
9697
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) {
97-
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_single_byte_bounds };
98+
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_single_byte_bounds, ARG_data_as_commands };
9899
static const mp_arg_t allowed_args[] = {
99100
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
100101
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -110,6 +111,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
110111
{ MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} },
111112
{ MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
112113
{ MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
114+
{ MP_QSTR_data_as_commands, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
113115
};
114116
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
115117
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -149,7 +151,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
149151
args[ARG_write_ram_command].u_int,
150152
args[ARG_set_vertical_scroll].u_int,
151153
bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin),
152-
args[ARG_single_byte_bounds].u_bool);
154+
args[ARG_single_byte_bounds].u_bool,
155+
args[ARG_data_as_commands].u_bool);
153156

154157
return self;
155158
}

shared-bindings/displayio/Display.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
4040
mp_obj_t bus, uint16_t width, uint16_t height,
4141
int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth,
4242
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll,
43-
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds);
43+
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds,
44+
bool data_as_commands);
4445

4546
int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self);
4647

shared-module/displayio/Display.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
4444
mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation,
4545
uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command,
4646
uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len,
47-
const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds) {
47+
const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds, bool data_as_commands) {
4848
self->color_depth = color_depth;
4949
self->set_column_command = set_column_command;
5050
self->set_row_command = set_row_command;
@@ -54,6 +54,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
5454
self->colstart = colstart;
5555
self->rowstart = rowstart;
5656
self->auto_brightness = false;
57+
self->data_as_commands = data_as_commands;
5758
self->single_byte_bounds = single_byte_bounds;
5859

5960
if (MP_OBJ_IS_TYPE(bus, &displayio_parallelbus_type)) {
@@ -82,7 +83,13 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
8283
data_size &= ~DELAY;
8384
uint8_t *data = cmd + 2;
8485
self->send(self->bus, true, cmd, 1);
85-
self->send(self->bus, false, data, data_size);
86+
if (self->data_as_commands) {
87+
for (uint32_t j=0; j < data_size; j++) {
88+
self->send(self->bus, true, data + j, 1);
89+
}
90+
} else {
91+
self->send(self->bus, false, data, data_size);
92+
}
8693
uint16_t delay_length_ms = 10;
8794
if (delay) {
8895
data_size++;
@@ -214,30 +221,33 @@ void displayio_display_end_transaction(displayio_display_obj_t* self) {
214221
void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
215222

216223
self->send(self->bus, true, &self->set_column_command, 1);
224+
bool isCommand = self->data_as_commands;
217225
if (self->single_byte_bounds) {
218226
uint8_t data[2];
219227
data[0] = x0 + self->colstart;
220228
data[1] = x1 - 1 + self->colstart;
221-
self->send(self->bus, false, (uint8_t*) data, 2);
229+
self->send(self->bus, isCommand, (uint8_t*) data, 2);
222230
} else {
223231
uint16_t data[2];
224232
data[0] = __builtin_bswap16(x0 + self->colstart);
225233
data[1] = __builtin_bswap16(x1 - 1 + self->colstart);
226-
self->send(self->bus, false, (uint8_t*) data, 4);
234+
self->send(self->bus, isCommand, (uint8_t*) data, 4);
227235
}
228236
self->send(self->bus, true, &self->set_row_command, 1);
229237
if (self->single_byte_bounds) {
230238
uint8_t data[2];
231239
data[0] = y0 + self->rowstart;
232240
data[1] = y1 - 1 + self->rowstart;
233-
self->send(self->bus, false, (uint8_t*) data, 2);
241+
self->send(self->bus, isCommand, (uint8_t*) data, 2);
234242
} else {
235243
uint16_t data[2];
236244
data[0] = __builtin_bswap16(y0 + self->rowstart);
237245
data[1] = __builtin_bswap16(y1 - 1 + self->rowstart);
238-
self->send(self->bus, false, (uint8_t*) data, 4);
246+
self->send(self->bus, isCommand, (uint8_t*) data, 4);
247+
}
248+
if (!self->data_as_commands) {
249+
self->send(self->bus, true, &self->write_ram_command, 1);
239250
}
240-
self->send(self->bus, true, &self->write_ram_command, 1);
241251
}
242252

243253
bool displayio_display_frame_queued(displayio_display_obj_t* self) {

shared-module/displayio/Display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef struct {
5050
int16_t colstart;
5151
int16_t rowstart;
5252
bool single_byte_bounds;
53+
bool data_as_commands;
5354
display_bus_begin_transaction begin_transaction;
5455
display_bus_send send;
5556
display_bus_end_transaction end_transaction;

0 commit comments

Comments
 (0)