Merge pull request #1751 from makermelissa/ssd1331

Allow parameter data to be treated as commands for the ssd1331
This commit is contained in:
Dan Halbert 2019-04-05 16:07:17 -04:00 committed by GitHub
commit df058c971f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 15 deletions

View File

@ -94,7 +94,8 @@ void board_init(void) {
display_init_sequence,
sizeof(display_init_sequence),
&pin_PA00,
false); // single_byte_bounds
false, // single_byte_bounds
false); // data_as_commands
common_hal_displayio_display_set_auto_brightness(display, true);
}

View File

@ -13,7 +13,7 @@ LONGINT_IMPL = MPZ
CIRCUITPY_I2CSLAVE = 0
CIRCUITPY_FREQUENCYIO = 0
CFLAGS_INLINE_LIMIT = 55
CFLAGS_INLINE_LIMIT = 50
CHIP_VARIANT = SAMD21G18A
CHIP_FAMILY = samd21

View File

@ -100,7 +100,8 @@ void board_init(void) {
display_init_sequence,
sizeof(display_init_sequence),
&pin_PA00,
false); // single_byte_bounds
false, // single_byte_bounds
false); // data_as_commands
common_hal_displayio_display_set_auto_brightness(display, true);
}

View File

@ -91,7 +91,8 @@ void board_init(void) {
display_init_sequence,
sizeof(display_init_sequence),
&pin_PB31,
false); // single_byte_bounds
false, // single_byte_bounds
false); // data_as_commands
common_hal_displayio_display_set_auto_brightness(display, true);
}

View File

@ -50,7 +50,7 @@
//| Most people should not use this class directly. Use a specific display driver instead that will
//| contain the initialization sequence at minimum.
//|
//| .. 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)
//| .. 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)
//|
//| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
//|
@ -92,9 +92,10 @@
//| :param int set_vertical_scroll: Command used to set the first row to show
//| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight
//| :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.
//|
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_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_single_byte_bounds };
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 };
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 },
@ -110,6 +111,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
{ MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} },
{ MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
{ MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
{ MP_QSTR_data_as_commands, 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);
@ -149,7 +151,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
args[ARG_write_ram_command].u_int,
args[ARG_set_vertical_scroll].u_int,
bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin),
args[ARG_single_byte_bounds].u_bool);
args[ARG_single_byte_bounds].u_bool,
args[ARG_data_as_commands].u_bool);
return self;
}

View File

@ -40,7 +40,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
mp_obj_t bus, uint16_t width, uint16_t height,
int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth,
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, bool single_byte_bounds);
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds,
bool data_as_commands);
int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self);

View File

@ -44,7 +44,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation,
uint16_t color_depth, 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, bool single_byte_bounds) {
const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds, bool data_as_commands) {
self->color_depth = color_depth;
self->set_column_command = set_column_command;
self->set_row_command = set_row_command;
@ -54,6 +54,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
self->colstart = colstart;
self->rowstart = rowstart;
self->auto_brightness = false;
self->data_as_commands = data_as_commands;
self->single_byte_bounds = single_byte_bounds;
if (MP_OBJ_IS_TYPE(bus, &displayio_parallelbus_type)) {
@ -82,7 +83,14 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
data_size &= ~DELAY;
uint8_t *data = cmd + 2;
self->send(self->bus, true, cmd, 1);
self->send(self->bus, false, data, data_size);
if (self->data_as_commands) {
// Loop through each parameter to force a CS toggle
for (uint32_t j=0; j < data_size; j++) {
self->send(self->bus, true, data + j, 1);
}
} else {
self->send(self->bus, false, data, data_size);
}
uint16_t delay_length_ms = 10;
if (delay) {
data_size++;
@ -214,30 +222,33 @@ void displayio_display_end_transaction(displayio_display_obj_t* self) {
void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
self->send(self->bus, true, &self->set_column_command, 1);
bool isCommand = self->data_as_commands;
if (self->single_byte_bounds) {
uint8_t data[2];
data[0] = x0 + self->colstart;
data[1] = x1 - 1 + self->colstart;
self->send(self->bus, false, (uint8_t*) data, 2);
self->send(self->bus, isCommand, (uint8_t*) data, 2);
} else {
uint16_t data[2];
data[0] = __builtin_bswap16(x0 + self->colstart);
data[1] = __builtin_bswap16(x1 - 1 + self->colstart);
self->send(self->bus, false, (uint8_t*) data, 4);
self->send(self->bus, isCommand, (uint8_t*) data, 4);
}
self->send(self->bus, true, &self->set_row_command, 1);
if (self->single_byte_bounds) {
uint8_t data[2];
data[0] = y0 + self->rowstart;
data[1] = y1 - 1 + self->rowstart;
self->send(self->bus, false, (uint8_t*) data, 2);
self->send(self->bus, isCommand, (uint8_t*) data, 2);
} else {
uint16_t data[2];
data[0] = __builtin_bswap16(y0 + self->rowstart);
data[1] = __builtin_bswap16(y1 - 1 + self->rowstart);
self->send(self->bus, false, (uint8_t*) data, 4);
self->send(self->bus, isCommand, (uint8_t*) data, 4);
}
if (!self->data_as_commands) {
self->send(self->bus, true, &self->write_ram_command, 1);
}
self->send(self->bus, true, &self->write_ram_command, 1);
}
bool displayio_display_frame_queued(displayio_display_obj_t* self) {

View File

@ -50,6 +50,7 @@ typedef struct {
int16_t colstart;
int16_t rowstart;
bool single_byte_bounds;
bool data_as_commands;
display_bus_begin_transaction begin_transaction;
display_bus_send send;
display_bus_end_transaction end_transaction;