From 2d8080eada4f4756c33a693a5577f7e9b670274d Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Wed, 29 Jun 2022 10:32:11 +0100 Subject: [PATCH] UC8159: Timeout-based busy wait. --- drivers/uc8159/uc8159.cpp | 19 +++++++++++++++---- drivers/uc8159/uc8159.hpp | 14 ++++++++------ .../modules/picographics/picographics.cpp | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/uc8159/uc8159.cpp b/drivers/uc8159/uc8159.cpp index e07ef5c2..d55735bc 100644 --- a/drivers/uc8159/uc8159.cpp +++ b/drivers/uc8159/uc8159.cpp @@ -38,10 +38,19 @@ namespace pimoroni { }; bool UC8159::is_busy() { + if(BUSY == PIN_UNUSED) { + if(timeout > 0 && absolute_time_diff_us(get_absolute_time(), timeout) > 0) { + return true; + } else { + timeout = 0; + return false; + } + } return !gpio_get(BUSY); } - void UC8159::busy_wait() { + void UC8159::busy_wait(uint minimum_wait_ms) { + timeout = make_timeout_time_ms(minimum_wait_ms); while(is_busy()) { tight_loop_contents(); } @@ -137,15 +146,17 @@ namespace pimoroni { busy_wait(); command(PON); // turn on - busy_wait(); + busy_wait(200); command(DRF); // start display refresh - busy_wait(); + busy_wait(200); if(blocking) { - busy_wait(); + busy_wait(32 * 1000); command(POF); // turn off + } else { + timeout = make_timeout_time_ms(32 * 1000); } } diff --git a/drivers/uc8159/uc8159.hpp b/drivers/uc8159/uc8159.hpp index 01846e27..9177aa73 100644 --- a/drivers/uc8159/uc8159.hpp +++ b/drivers/uc8159/uc8159.hpp @@ -26,11 +26,13 @@ namespace pimoroni { // interface pins with our standard defaults where appropriate uint CS = SPI_BG_FRONT_CS; - uint DC = 27; + uint DC = 28; uint SCK = SPI_DEFAULT_SCK; uint MOSI = SPI_DEFAULT_MOSI; - uint BUSY = 26; - uint RESET = 25; + uint BUSY = PIN_UNUSED; + uint RESET = 27; + + absolute_time_t timeout = 0; public: enum colour : uint8_t { @@ -44,9 +46,9 @@ 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, 27, PIN_UNUSED}) {}; + 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, SPIPins pins, uint busy=26, uint reset=25) : + UC8159(uint16_t width, uint16_t height, SPIPins pins, uint busy=PIN_UNUSED, uint reset=27) : DisplayDriver(width, height, ROTATE_0), spi(pins.spi), CS(pins.cs), DC(pins.dc), SCK(pins.sck), MOSI(pins.mosi), BUSY(busy), RESET(reset) { @@ -58,7 +60,7 @@ namespace pimoroni { // Methods //-------------------------------------------------- public: - void busy_wait(); + void busy_wait(uint minimum_wait_ms=0); void reset(); void power_off(); diff --git a/micropython/modules/picographics/picographics.cpp b/micropython/modules/picographics/picographics.cpp index 78c73c85..153f4da8 100644 --- a/micropython/modules/picographics/picographics.cpp +++ b/micropython/modules/picographics/picographics.cpp @@ -186,7 +186,7 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size i2c_bus = (pimoroni::I2C *)(self->i2c->i2c); } else if (bus_type == BUS_SPI) { if(display == DISPLAY_INKY_FRAME) { - spi_bus = {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 27, PIN_UNUSED}; + spi_bus = {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 28, PIN_UNUSED}; } else if (display == DISPLAY_INKY_PACK) { spi_bus = {PIMORONI_SPI_DEFAULT_INSTANCE, SPI_BG_FRONT_CS, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, 20, PIN_UNUSED}; }