Skip to content

Commit df058c9

Browse files
authored
Merge pull request #1751 from makermelissa/ssd1331
Allow parameter data to be treated as commands for the ssd1331
2 parents b9e3781 + 36b1010 commit df058c9

File tree

8 files changed

+34
-15
lines changed

8 files changed

+34
-15
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ void board_init(void) {
9494
display_init_sequence,
9595
sizeof(display_init_sequence),
9696
&pin_PA00,
97-
false); // single_byte_bounds
97+
false, // single_byte_bounds
98+
false); // data_as_commands
9899
common_hal_displayio_display_set_auto_brightness(display, true);
99100
}
100101

ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LONGINT_IMPL = MPZ
1313
CIRCUITPY_I2CSLAVE = 0
1414
CIRCUITPY_FREQUENCYIO = 0
1515

16-
CFLAGS_INLINE_LIMIT = 55
16+
CFLAGS_INLINE_LIMIT = 50
1717

1818
CHIP_VARIANT = SAMD21G18A
1919
CHIP_FAMILY = samd21

ports/atmel-samd/boards/pybadge/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
display_init_sequence,
101101
sizeof(display_init_sequence),
102102
&pin_PA00,
103-
false); // single_byte_bounds
103+
false, // single_byte_bounds
104+
false); // data_as_commands
104105
common_hal_displayio_display_set_auto_brightness(display, true);
105106
}
106107

ports/atmel-samd/boards/pyportal/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
display_init_sequence,
9292
sizeof(display_init_sequence),
9393
&pin_PB31,
94-
false); // single_byte_bounds
94+
false, // single_byte_bounds
95+
false); // data_as_commands
9596

9697
common_hal_displayio_display_set_auto_brightness(display, true);
9798
}

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: 18 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,14 @@ 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+
// Loop through each parameter to force a CS toggle
88+
for (uint32_t j=0; j < data_size; j++) {
89+
self->send(self->bus, true, data + j, 1);
90+
}
91+
} else {
92+
self->send(self->bus, false, data, data_size);
93+
}
8694
uint16_t delay_length_ms = 10;
8795
if (delay) {
8896
data_size++;
@@ -214,30 +222,33 @@ void displayio_display_end_transaction(displayio_display_obj_t* self) {
214222
void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
215223

216224
self->send(self->bus, true, &self->set_column_command, 1);
225+
bool isCommand = self->data_as_commands;
217226
if (self->single_byte_bounds) {
218227
uint8_t data[2];
219228
data[0] = x0 + self->colstart;
220229
data[1] = x1 - 1 + self->colstart;
221-
self->send(self->bus, false, (uint8_t*) data, 2);
230+
self->send(self->bus, isCommand, (uint8_t*) data, 2);
222231
} else {
223232
uint16_t data[2];
224233
data[0] = __builtin_bswap16(x0 + self->colstart);
225234
data[1] = __builtin_bswap16(x1 - 1 + self->colstart);
226-
self->send(self->bus, false, (uint8_t*) data, 4);
235+
self->send(self->bus, isCommand, (uint8_t*) data, 4);
227236
}
228237
self->send(self->bus, true, &self->set_row_command, 1);
229238
if (self->single_byte_bounds) {
230239
uint8_t data[2];
231240
data[0] = y0 + self->rowstart;
232241
data[1] = y1 - 1 + self->rowstart;
233-
self->send(self->bus, false, (uint8_t*) data, 2);
242+
self->send(self->bus, isCommand, (uint8_t*) data, 2);
234243
} else {
235244
uint16_t data[2];
236245
data[0] = __builtin_bswap16(y0 + self->rowstart);
237246
data[1] = __builtin_bswap16(y1 - 1 + self->rowstart);
238-
self->send(self->bus, false, (uint8_t*) data, 4);
247+
self->send(self->bus, isCommand, (uint8_t*) data, 4);
248+
}
249+
if (!self->data_as_commands) {
250+
self->send(self->bus, true, &self->write_ram_command, 1);
239251
}
240-
self->send(self->bus, true, &self->write_ram_command, 1);
241252
}
242253

243254
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)