From a0798c7887731b7f04349cfdb36e031ace49df08 Mon Sep 17 00:00:00 2001 From: ailurux Date: Wed, 22 Feb 2023 11:51:26 +1100 Subject: Software rotation for display --- src/drivers/display.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/drivers/display.cpp') diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp index 6ec82787..0ee02702 100644 --- a/src/drivers/display.cpp +++ b/src/drivers/display.cpp @@ -103,6 +103,9 @@ auto Display::create(GpioExpander* expander, display->driver_.draw_buf = &display->buffers_; display->driver_.hor_res = kDisplayWidth; display->driver_.ver_res = kDisplayHeight; + display->driver_.sw_rotate = 1; + display->driver_.rotated = LV_DISP_ROT_270; + display->driver_.antialiasing = 0; display->driver_.flush_cb = &FlushDataCallback; display->driver_.user_data = display.get(); -- cgit v1.2.3 From 0fce4fcc06a600aac6b0cb6fc1ef1ebb91bcdf27 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 8 Mar 2023 12:47:56 +1100 Subject: update to faceplate bodge --- src/drivers/display.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/drivers/display.cpp') diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp index 6ec82787..d3c2c923 100644 --- a/src/drivers/display.cpp +++ b/src/drivers/display.cpp @@ -60,7 +60,7 @@ auto Display::create(GpioExpander* expander, const displays::InitialisationData& init_data) -> std::unique_ptr { // First, turn on the LED backlight. - expander->set_pin(GpioExpander::DISPLAY_LED, 0); + expander->set_pin(GpioExpander::DISPLAY_LED, 1); expander->set_pin(GpioExpander::DISPLAY_POWER_ENABLE, 1); expander->Write(); @@ -118,6 +118,14 @@ Display::Display(GpioExpander* gpio, spi_device_handle_t handle) Display::~Display() {} void Display::SendInitialisationSequence(const uint8_t* data) { + // Reset the display manually to get it into a predictable state. + gpio_->set_pin(GpioExpander::DISPLAY_RESET, false); + gpio_->Write(); + vTaskDelay(pdMS_TO_TICKS(10)); + gpio_->set_pin(GpioExpander::DISPLAY_RESET, false); + gpio_->Write(); + vTaskDelay(pdMS_TO_TICKS(10)); + // Hold onto the bus for the entire sequence so that we're not interrupted // part way through. spi_device_acquire_bus(handle_, portMAX_DELAY); -- cgit v1.2.3 From a0ae39befe11c2a5a78ee5877cd5dd9cda90e27c Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 30 Mar 2023 09:31:08 +1100 Subject: Update pinouts for R3 --- src/drivers/display.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/drivers/display.cpp') diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp index e8ddb65e..d5c17744 100644 --- a/src/drivers/display.cpp +++ b/src/drivers/display.cpp @@ -28,6 +28,9 @@ static const uint8_t kDisplayWidth = 128 + 2; static const uint8_t kDisplayHeight = 160 + 1; static const uint8_t kTransactionQueueSize = 10; +static const gpio_num_t kDisplayDr = GPIO_NUM_33; +static const gpio_num_t kDisplayLedEn = GPIO_NUM_32; + /* * The size of each of our two display buffers. This is fundamentally a balance * between performance and memory usage. LVGL docs recommend a buffer 1/10th the @@ -59,10 +62,13 @@ extern "C" void FlushDataCallback(lv_disp_drv_t* disp_drv, auto Display::create(GpioExpander* expander, const displays::InitialisationData& init_data) -> std::unique_ptr { - // First, turn on the LED backlight. - expander->set_pin(GpioExpander::DISPLAY_LED, 1); - expander->set_pin(GpioExpander::DISPLAY_POWER_ENABLE, 1); - expander->Write(); + ESP_LOGI(kTag, "Init I/O pins"); + gpio_set_direction(kDisplayDr, GPIO_MODE_OUTPUT); + gpio_set_level(kDisplayDr, 0); + + // TODO: use pwm for the backlight. + gpio_set_direction(kDisplayLedEn, GPIO_MODE_OUTPUT); + gpio_set_level(kDisplayLedEn, 1); // Next, init the SPI device spi_device_interface_config_t spi_cfg = { @@ -122,7 +128,7 @@ Display::~Display() {} void Display::SendInitialisationSequence(const uint8_t* data) { // Reset the display manually to get it into a predictable state. - gpio_->set_pin(GpioExpander::DISPLAY_RESET, false); + gpio_->set_pin(GpioExpander::DISPLAY_RESET, true); gpio_->Write(); vTaskDelay(pdMS_TO_TICKS(10)); gpio_->set_pin(GpioExpander::DISPLAY_RESET, false); @@ -201,9 +207,7 @@ void Display::SendTransaction(TransactionType type, transaction.tx_buffer = data; } - // TODO(jacqueline): Move this to an on-board GPIO for speed. - gpio_->set_pin(GpioExpander::DISPLAY_DR, type); - gpio_->Write(); + gpio_set_level(kDisplayDr, type); // TODO(jacqueline): Handle these errors. esp_err_t ret = spi_device_polling_transmit(handle_, &transaction); -- cgit v1.2.3 From c93ed8efad85996e8ec3cec68bdc8feeae71b8fc Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 6 Apr 2023 16:18:04 +1000 Subject: fix some display issues --- src/drivers/display.cpp | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'src/drivers/display.cpp') diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp index d5c17744..b981ec33 100644 --- a/src/drivers/display.cpp +++ b/src/drivers/display.cpp @@ -30,6 +30,7 @@ static const uint8_t kTransactionQueueSize = 10; static const gpio_num_t kDisplayDr = GPIO_NUM_33; static const gpio_num_t kDisplayLedEn = GPIO_NUM_32; +static const gpio_num_t kDisplayCs = GPIO_NUM_22; /* * The size of each of our two display buffers. This is fundamentally a balance @@ -63,11 +64,37 @@ auto Display::create(GpioExpander* expander, const displays::InitialisationData& init_data) -> std::unique_ptr { ESP_LOGI(kTag, "Init I/O pins"); - gpio_set_direction(kDisplayDr, GPIO_MODE_OUTPUT); + gpio_config_t dr_config{ + .pin_bit_mask = 1ULL << kDisplayDr, + .mode = GPIO_MODE_OUTPUT, + .pull_up_en = GPIO_PULLUP_DISABLE, + .pull_down_en = GPIO_PULLDOWN_DISABLE, + .intr_type = GPIO_INTR_DISABLE, + }; + gpio_config(&dr_config); gpio_set_level(kDisplayDr, 0); + /* + gpio_config_t cs_config{ + .pin_bit_mask = 1ULL << kDisplayCs, + .mode = GPIO_MODE_OUTPUT, + .pull_up_en = GPIO_PULLUP_DISABLE, + .pull_down_en = GPIO_PULLDOWN_DISABLE, + .intr_type = GPIO_INTR_DISABLE, + }; + gpio_config(&cs_config); + gpio_set_level(kDisplayCs, 1); + */ + // TODO: use pwm for the backlight. - gpio_set_direction(kDisplayLedEn, GPIO_MODE_OUTPUT); + gpio_config_t led_config{ + .pin_bit_mask = 1ULL << kDisplayLedEn, + .mode = GPIO_MODE_OUTPUT, + .pull_up_en = GPIO_PULLUP_ENABLE, + .pull_down_en = GPIO_PULLDOWN_ENABLE, + .intr_type = GPIO_INTR_DISABLE, + }; + gpio_config(&led_config); gpio_set_level(kDisplayLedEn, 1); // Next, init the SPI device @@ -82,7 +109,7 @@ auto Display::create(GpioExpander* expander, .cs_ena_posttrans = 0, .clock_speed_hz = SPI_MASTER_FREQ_40M, .input_delay_ns = 0, - .spics_io_num = GPIO_NUM_22, + .spics_io_num = kDisplayCs, .flags = 0, .queue_size = kTransactionQueueSize, .pre_cb = NULL, @@ -128,16 +155,17 @@ Display::~Display() {} void Display::SendInitialisationSequence(const uint8_t* data) { // Reset the display manually to get it into a predictable state. - gpio_->set_pin(GpioExpander::DISPLAY_RESET, true); - gpio_->Write(); - vTaskDelay(pdMS_TO_TICKS(10)); gpio_->set_pin(GpioExpander::DISPLAY_RESET, false); gpio_->Write(); - vTaskDelay(pdMS_TO_TICKS(10)); + vTaskDelay(pdMS_TO_TICKS(1)); + gpio_->set_pin(GpioExpander::DISPLAY_RESET, true); + gpio_->Write(); + vTaskDelay(pdMS_TO_TICKS(1)); // Hold onto the bus for the entire sequence so that we're not interrupted // part way through. spi_device_acquire_bus(handle_, portMAX_DELAY); + // gpio_set_level(kDisplayCs, 0); // First byte of the data is the number of commands. for (int i = *(data++); i > 0; i--) { @@ -156,12 +184,15 @@ void Display::SendInitialisationSequence(const uint8_t* data) { } // Avoid hanging on to the bus whilst delaying. + // gpio_set_level(kDisplayCs, 1); spi_device_release_bus(handle_); vTaskDelay(pdMS_TO_TICKS(sleep_duration_ms)); spi_device_acquire_bus(handle_, portMAX_DELAY); + // gpio_set_level(kDisplayCs, 0); } } + // gpio_set_level(kDisplayCs, 1); spi_device_release_bus(handle_); } @@ -220,6 +251,7 @@ void Display::OnLvglFlush(lv_disp_drv_t* disp_drv, // Ideally we want to complete a single flush as quickly as possible, so grab // the bus for this entire transaction sequence. spi_device_acquire_bus(handle_, portMAX_DELAY); + // gpio_set_level(kDisplayCs, 0); // First we need to specify the rectangle of the display we're writing into. uint16_t data[2] = {0, 0}; @@ -239,6 +271,7 @@ void Display::OnLvglFlush(lv_disp_drv_t* disp_drv, SendCommandWithData(displays::ST77XX_RAMWR, reinterpret_cast(color_map), size * 2); + // gpio_set_level(kDisplayCs, 1); spi_device_release_bus(handle_); lv_disp_flush_ready(&driver_); -- cgit v1.2.3 From a1cef17c5bb66c453e4a8e83e52a56fe9173346c Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 12 Apr 2023 16:37:27 +1000 Subject: Leave the display reset pin alone; we don't need it --- src/drivers/display.cpp | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) (limited to 'src/drivers/display.cpp') diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp index b981ec33..56bd6e60 100644 --- a/src/drivers/display.cpp +++ b/src/drivers/display.cpp @@ -20,6 +20,7 @@ #include "display_init.hpp" #include "gpio_expander.hpp" +#include "soc/soc.h" static const char* kTag = "DISPLAY"; @@ -67,31 +68,19 @@ auto Display::create(GpioExpander* expander, gpio_config_t dr_config{ .pin_bit_mask = 1ULL << kDisplayDr, .mode = GPIO_MODE_OUTPUT, - .pull_up_en = GPIO_PULLUP_DISABLE, + .pull_up_en = GPIO_PULLUP_ENABLE, .pull_down_en = GPIO_PULLDOWN_DISABLE, .intr_type = GPIO_INTR_DISABLE, }; gpio_config(&dr_config); gpio_set_level(kDisplayDr, 0); - /* - gpio_config_t cs_config{ - .pin_bit_mask = 1ULL << kDisplayCs, - .mode = GPIO_MODE_OUTPUT, - .pull_up_en = GPIO_PULLUP_DISABLE, - .pull_down_en = GPIO_PULLDOWN_DISABLE, - .intr_type = GPIO_INTR_DISABLE, - }; - gpio_config(&cs_config); - gpio_set_level(kDisplayCs, 1); - */ - // TODO: use pwm for the backlight. gpio_config_t led_config{ .pin_bit_mask = 1ULL << kDisplayLedEn, .mode = GPIO_MODE_OUTPUT, .pull_up_en = GPIO_PULLUP_ENABLE, - .pull_down_en = GPIO_PULLDOWN_ENABLE, + .pull_down_en = GPIO_PULLDOWN_DISABLE, .intr_type = GPIO_INTR_DISABLE, }; gpio_config(&led_config); @@ -154,18 +143,9 @@ Display::Display(GpioExpander* gpio, spi_device_handle_t handle) Display::~Display() {} void Display::SendInitialisationSequence(const uint8_t* data) { - // Reset the display manually to get it into a predictable state. - gpio_->set_pin(GpioExpander::DISPLAY_RESET, false); - gpio_->Write(); - vTaskDelay(pdMS_TO_TICKS(1)); - gpio_->set_pin(GpioExpander::DISPLAY_RESET, true); - gpio_->Write(); - vTaskDelay(pdMS_TO_TICKS(1)); - // Hold onto the bus for the entire sequence so that we're not interrupted // part way through. spi_device_acquire_bus(handle_, portMAX_DELAY); - // gpio_set_level(kDisplayCs, 0); // First byte of the data is the number of commands. for (int i = *(data++); i > 0; i--) { @@ -184,15 +164,12 @@ void Display::SendInitialisationSequence(const uint8_t* data) { } // Avoid hanging on to the bus whilst delaying. - // gpio_set_level(kDisplayCs, 1); spi_device_release_bus(handle_); vTaskDelay(pdMS_TO_TICKS(sleep_duration_ms)); spi_device_acquire_bus(handle_, portMAX_DELAY); - // gpio_set_level(kDisplayCs, 0); } } - // gpio_set_level(kDisplayCs, 1); spi_device_release_bus(handle_); } @@ -251,7 +228,6 @@ void Display::OnLvglFlush(lv_disp_drv_t* disp_drv, // Ideally we want to complete a single flush as quickly as possible, so grab // the bus for this entire transaction sequence. spi_device_acquire_bus(handle_, portMAX_DELAY); - // gpio_set_level(kDisplayCs, 0); // First we need to specify the rectangle of the display we're writing into. uint16_t data[2] = {0, 0}; @@ -271,7 +247,6 @@ void Display::OnLvglFlush(lv_disp_drv_t* disp_drv, SendCommandWithData(displays::ST77XX_RAMWR, reinterpret_cast(color_map), size * 2); - // gpio_set_level(kDisplayCs, 1); spi_device_release_bus(handle_); lv_disp_flush_ready(&driver_); -- cgit v1.2.3 From 7083459cf3c62c32d0c039a4665e702d70a27bba Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 21 Apr 2023 15:27:57 +1000 Subject: wrap driver instance ownership + di in a class --- src/drivers/display.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/drivers/display.cpp') diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp index 56bd6e60..f8594a5a 100644 --- a/src/drivers/display.cpp +++ b/src/drivers/display.cpp @@ -63,7 +63,7 @@ extern "C" void FlushDataCallback(lv_disp_drv_t* disp_drv, auto Display::create(GpioExpander* expander, const displays::InitialisationData& init_data) - -> std::unique_ptr { + -> Display* { ESP_LOGI(kTag, "Init I/O pins"); gpio_config_t dr_config{ .pin_bit_mask = 1ULL << kDisplayDr, @@ -134,7 +134,7 @@ auto Display::create(GpioExpander* expander, ESP_LOGI(kTag, "Registering driver"); display->display_ = lv_disp_drv_register(&display->driver_); - return display; + return display.release(); } Display::Display(GpioExpander* gpio, spi_device_handle_t handle) -- cgit v1.2.3