From 6aa1bbd2713da87dd78e08482e1e4b186bb4f6ee Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 30 Sep 2022 20:13:25 +0100 Subject: [PATCH] UC8159: 0/180 degree rotation support. --- drivers/uc8159/uc8159.cpp | 14 +++++++++++--- drivers/uc8159/uc8159.hpp | 12 +++++------- micropython/modules/picographics/picographics.cpp | 4 ++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/uc8159/uc8159.cpp b/drivers/uc8159/uc8159.cpp index 257d6cdb..7f1fde21 100644 --- a/drivers/uc8159/uc8159.cpp +++ b/drivers/uc8159/uc8159.cpp @@ -96,9 +96,17 @@ namespace pimoroni { }; if (width == 600) { - command(PSR, {0xE3, 0x08}); + if (rotation == ROTATE_0) { + command(PSR, {0xE3, 0x08}); + } else { + command(PSR, {0xEF, 0x08}); + } } else { - command(PSR, {0xA3, 0x08}); + if (rotation == ROTATE_0) { + command(PSR, {0xA3, 0x08}); + } else { + command(PSR, {0xAF, 0x08}); + } } command(PWR, {0x37, 0x00, 0x23, 0x23}); command(PFS, {0x00}); @@ -171,7 +179,7 @@ namespace pimoroni { // are reversed. // Any garbage data will do. // 2px per byte, so we need width * 24 bytes - if(height == 400) { + if(height == 400 && rotation == ROTATE_0) { spi_write_blocking(spi, (uint8_t *)graphics->frame_buffer, width * 24); } graphics->frame_convert(PicoGraphics::PEN_P4, [this](void *buf, size_t length) { diff --git a/drivers/uc8159/uc8159.hpp b/drivers/uc8159/uc8159.hpp index 5cf3d12a..21f0d48f 100644 --- a/drivers/uc8159/uc8159.hpp +++ b/drivers/uc8159/uc8159.hpp @@ -16,8 +16,6 @@ namespace pimoroni { // Variables //-------------------------------------------------- private: - uint16_t width; - uint16_t height; spi_inst_t *spi = PIMORONI_SPI_DEFAULT_INSTANCE; // interface pins with our standard defaults where appropriate @@ -44,12 +42,12 @@ namespace pimoroni { CLEAN = 7 }; - UC8159(uint16_t width, uint16_t height) : UC8159(width, height, {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 28, PIN_UNUSED}) {}; + UC8159(uint16_t width, uint16_t height) : UC8159(width, height, ROTATE_0, {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 28, PIN_UNUSED}) {}; - UC8159(uint16_t width, uint16_t height, SPIPins pins, uint busy=PIN_UNUSED, uint reset=27) : - DisplayDriver(width, height, ROTATE_0), - width(width), - height(height), + UC8159(uint16_t width, uint16_t height, SPIPins pins, uint busy=PIN_UNUSED, uint reset=27) : UC8159(width, height, ROTATE_0, pins, busy, reset) {}; + + UC8159(uint16_t width, uint16_t height, Rotation rotation, SPIPins pins, uint busy=PIN_UNUSED, uint reset=27) : + DisplayDriver(width, height, rotation), spi(pins.spi), CS(pins.cs), DC(pins.dc), SCK(pins.sck), MOSI(pins.mosi), BUSY(busy), RESET(reset) { init(); diff --git a/micropython/modules/picographics/picographics.cpp b/micropython/modules/picographics/picographics.cpp index b3396409..7dfaf4ba 100644 --- a/micropython/modules/picographics/picographics.cpp +++ b/micropython/modules/picographics/picographics.cpp @@ -109,7 +109,7 @@ bool get_display_settings(PicoGraphicsDisplay display, int &width, int &height, width = 640; height = 400; bus_type = BUS_SPI; - if(rotate == -1) rotate = (int)Rotation::ROTATE_180; + if(rotate == -1) rotate = (int)Rotation::ROTATE_0; if(pen_type == -1) pen_type = PEN_P4; break; default: @@ -206,7 +206,7 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size if (display == DISPLAY_INKY_FRAME || display == DISPLAY_INKY_FRAME_4) { pen_type = PEN_3BIT; // FORCE to 3BIT // TODO grab BUSY and RESET from ARG_extra_pins - self->display = m_new_class(UC8159, width, height, spi_bus); + self->display = m_new_class(UC8159, width, height, (Rotation)rotate, spi_bus); } else if (display == DISPLAY_TUFTY_2040) { self->display = m_new_class(ST7789, width, height, (Rotation)rotate, parallel_bus);