From 3f5bc1227e91fa7d2cf4370eebfd8d16ef10df95 Mon Sep 17 00:00:00 2001 From: VeyPatch <126267034+VeyPatch@users.noreply.github.com> Date: Mon, 6 Jan 2025 10:41:32 +0100 Subject: [PATCH] Improve QP code --- .../halcyon_modules/hlc_tft_display/config.h | 1 - .../hlc_tft_display/hlc_tft_display.c | 38 ++++++++++--------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/users/halcyon_modules/hlc_tft_display/config.h b/users/halcyon_modules/hlc_tft_display/config.h index 13b3930f..ea8b79ef 100644 --- a/users/halcyon_modules/hlc_tft_display/config.h +++ b/users/halcyon_modules/hlc_tft_display/config.h @@ -13,7 +13,6 @@ #define LCD_DC_PIN GP16 #define LCD_SPI_DIVISOR 0 #define LCD_SPI_MODE 3 -#define LCD_WAIT_TIME 150 #define LCD_WIDTH 135 #define LCD_HEIGHT 240 #define LCD_ROTATION QP_ROTATION_0 diff --git a/users/halcyon_modules/hlc_tft_display/hlc_tft_display.c b/users/halcyon_modules/hlc_tft_display/hlc_tft_display.c index 6efd3d2d..06e594b0 100644 --- a/users/halcyon_modules/hlc_tft_display/hlc_tft_display.c +++ b/users/halcyon_modules/hlc_tft_display/hlc_tft_display.c @@ -32,7 +32,7 @@ static painter_font_handle_t Retron27; static painter_font_handle_t Retron27_underline; static painter_image_handle_t layer_number; -static uint16_t lcd_surface_fb[135*240]; +static uint8_t lcd_surface_fb[SURFACE_REQUIRED_BUFFER_BYTE_SIZE(135, 240, 16)]; int color_value = 0; @@ -249,26 +249,27 @@ void suspend_wakeup_init_kb(void) { // Called from halcyon.c bool module_post_init_kb(void) { - setPinOutput(LCD_RST_PIN); - writePinHigh(LCD_RST_PIN); - - // Initialise the LCD - lcd = qp_st7789_make_spi_device(LCD_WIDTH, LCD_HEIGHT, LCD_CS_PIN, LCD_DC_PIN, LCD_RST_PIN, LCD_SPI_DIVISOR, LCD_SPI_MODE); - qp_init(lcd, LCD_ROTATION); - qp_set_viewport_offsets(lcd, LCD_OFFSET_X, LCD_OFFSET_Y); - - // Initialise surface - lcd_surface = qp_make_rgb565_surface(LCD_WIDTH, LCD_HEIGHT, lcd_surface_fb); - qp_init(lcd_surface, LCD_ROTATION); - - // Turn on the LCD and clear the display - qp_power(lcd, true); - qp_rect(lcd, 0, 0, LCD_WIDTH - 1, LCD_HEIGHT - 1, HSV_BLACK, true); - qp_flush(lcd); - // Turn on backlight backlight_enable(); + // Make the devices + lcd = qp_st7789_make_spi_device(LCD_WIDTH, LCD_HEIGHT, LCD_CS_PIN, LCD_DC_PIN, LCD_RST_PIN, LCD_SPI_DIVISOR, LCD_SPI_MODE); + lcd_surface = qp_make_rgb565_surface(LCD_WIDTH, LCD_HEIGHT, lcd_surface_fb); + + // Initialise the LCD + qp_init(lcd, LCD_ROTATION); + qp_set_viewport_offsets(lcd, LCD_OFFSET_X, LCD_OFFSET_Y); + qp_clear(lcd); + qp_rect(lcd, 0, 0, LCD_WIDTH - 1, LCD_HEIGHT - 1, HSV_BLACK, true); + qp_power(lcd, true); + qp_flush(lcd); + + // Initialise the LCD surface + qp_init(lcd_surface, LCD_ROTATION); + qp_rect(lcd_surface, 0, 0, LCD_WIDTH - 1, LCD_HEIGHT - 1, HSV_BLACK, true); + qp_surface_draw(lcd_surface, lcd, 0, 0, 0); + qp_flush(lcd); + if(!module_post_init_user()) { return false; } return true; @@ -311,6 +312,7 @@ bool display_module_housekeeping_task_kb(bool second_display) { // Move surface to lcd qp_surface_draw(lcd_surface, lcd, 0, 0, 0); + qp_flush(lcd); return true; }