diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2018-09-06 14:49:49 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2018-09-06 14:49:49 -0700 |
| commit | 1683eb913d5bfb4265df56bf286d9971185a3a82 (patch) | |
| tree | e536c26b316b688e48abb8f7233e706f8832ba76 /ports | |
| parent | 121903b6eeb9712cae86a24c5fe82cb7b144e504 (diff) | |
Minor tweaks based on feedback
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/atmel-samd/boards/hallowing_m0_express/board.c | 41 | ||||
| -rw-r--r-- | ports/atmel-samd/boards/hallowing_m0_express/pins.c | 2 | ||||
| -rw-r--r-- | ports/atmel-samd/common-hal/displayio/FourWire.c | 12 |
3 files changed, 34 insertions, 21 deletions
diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index 85bcaabc7..b47c5fbb2 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -27,14 +27,17 @@ #include "boards/board.h" #include "shared-bindings/displayio/FourWire.h" +#include "shared-module/displayio/mipi_constants.h" #include "tick.h" displayio_fourwire_obj_t board_display_obj; +#define DELAY 0x80 + uint8_t display_init_sequence[] = { - 0x01, 0, // SWRESET - 0x11, 0, // SLPOUT + 0x01, 0 | DELAY, 150, // SWRESET + 0x11, 0 | DELAY, 255, // SLPOUT 0xb1, 3, 0x01, 0x2C, 0x2D, // _FRMCTR1 0xb2, 3, 0x01, 0x2C, 0x2D, // 0xb3, 6, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D, @@ -60,36 +63,50 @@ uint8_t display_init_sequence[] = { 0x00, 0x00, 0x02, 0x10, 0x2a, 3, 0x02, 0x00, 0x81, // _CASET XSTART = 2, XEND = 129 0x2b, 3, 0x02, 0x00, 0x81, // _RASET XSTART = 2, XEND = 129 - 0x13, 0, // _NORON - 0x29, 0, // _DISPON + 0x13, 0 | DELAY, 10, // _NORON + 0x29, 0 | DELAY, 100, // _DISPON }; void board_init(void) { board_display_obj.base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(&board_display_obj, - &pin_PB23, &pin_PB22, &pin_PA28, &pin_PA01, &pin_PA27, - 128, 128, 2, 0, 16, 0x2a, 0x2b, 0x2c); + &pin_PB23, // Clock + &pin_PB22, // Data + &pin_PA28, // Command or data + &pin_PA01, // Chip select + &pin_PA27, // Reset + 128, // Width + 128, // Height + 2, // column start + 0, // row start + 16, // Color depth + MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command + MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command + MIPI_COMMAND_WRITE_MEMORY_START); // Write memory command uint32_t i = 0; common_hal_displayio_fourwire_begin_transaction(&board_display_obj); while (i < sizeof(display_init_sequence)) { uint8_t *cmd = display_init_sequence + i; uint8_t data_size = *(cmd + 1); + bool delay = (data_size & DELAY) != 0; + data_size &= ~DELAY; uint8_t *data = cmd + 2; common_hal_displayio_fourwire_send(&board_display_obj, true, cmd, 1); common_hal_displayio_fourwire_send(&board_display_obj, false, data, data_size); - if (*cmd == 0x01) { - uint64_t start = ticks_ms; - while (ticks_ms - start < 120) {} - } else if (*cmd == 0x11) { + if (delay) { + data_size++; + uint16_t delay_length_ms = *(cmd + 1 + data_size); + if (delay_length_ms == 255) { + delay_length_ms = 500; + } uint64_t start = ticks_ms; - while (ticks_ms - start < 500) {} + while (ticks_ms - start < delay_length_ms) {} } else { uint64_t start = ticks_ms; while (ticks_ms - start < 10) {} } i += 2 + data_size; - } common_hal_displayio_fourwire_end_transaction(&board_display_obj); } diff --git a/ports/atmel-samd/boards/hallowing_m0_express/pins.c b/ports/atmel-samd/boards/hallowing_m0_express/pins.c index 28c3d6a5c..7d4afc7a4 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/pins.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/pins.c @@ -58,6 +58,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, - { MP_ROM_QSTR(MP_QSTR_display), MP_ROM_PTR(&board_display_obj)} + { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&board_display_obj)} }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/common-hal/displayio/FourWire.c b/ports/atmel-samd/common-hal/displayio/FourWire.c index 033970c77..6c3b75a85 100644 --- a/ports/atmel-samd/common-hal/displayio/FourWire.c +++ b/ports/atmel-samd/common-hal/displayio/FourWire.c @@ -96,21 +96,17 @@ int32_t common_hal_displayio_fourwire_wait_for_frame(displayio_fourwire_obj_t* s return 0; } -static uint16_t swap(uint16_t x) { - return (x & 0x00ff) << 8 | x >> 8; -} - void displayio_fourwire_start_region_update(displayio_fourwire_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { // TODO(tannewt): Handle displays with single byte bounds. common_hal_displayio_fourwire_begin_transaction(self); uint16_t data[2]; common_hal_displayio_fourwire_send(self, true, &self->set_column_command, 1); - data[0] = swap(x0 + self->colstart); - data[1] = swap(x1-1 + self->colstart); + data[0] = __builtin_bswap16(x0 + self->colstart); + data[1] = __builtin_bswap16(x1-1 + self->colstart); common_hal_displayio_fourwire_send(self, false, (uint8_t*) data, 4); common_hal_displayio_fourwire_send(self, true, &self->set_row_command, 1); - data[0] = swap(y0 + 1 + self->rowstart); - data[1] = swap(y1 + self->rowstart); + data[0] = __builtin_bswap16(y0 + 1 + self->rowstart); + data[1] = __builtin_bswap16(y1 + self->rowstart); common_hal_displayio_fourwire_send(self, false, (uint8_t*) data, 4); common_hal_displayio_fourwire_send(self, true, &self->write_ram_command, 1); } |
