From 5d9ac78548c9d816ce52a1584ee149a1f842cd93 Mon Sep 17 00:00:00 2001 From: Fred Date: Fri, 4 Dec 2020 10:22:57 +0100 Subject: [PATCH] Fix GD77 display driver --- meson.build | 12 +++--- openrtx/src/graphics/graphics_bw.c | 1 + platform/drivers/display/UC1701_GD77.c | 54 +++++++++++++++++--------- platform/targets/GD77/hwconfig.h | 12 ++++++ platform/targets/GD77/platform.c | 26 +++++++++++++ 5 files changed, 81 insertions(+), 24 deletions(-) diff --git a/meson.build b/meson.build index ad4d4358..18b012d6 100644 --- a/meson.build +++ b/meson.build @@ -12,10 +12,10 @@ project('OpenRTX', 'c', ## OpenRTX -openrtx_src = ['openrtx/src/bootstrap.c'] - #'openrtx/src/state.c', - #'openrtx/src/ui.c', - #'openrtx/src/threads.c'] +openrtx_src = ['openrtx/src/bootstrap.c', + 'openrtx/src/state.c', + 'openrtx/src/ui.c', + 'openrtx/src/threads.c'] ## Replace main executable with platform test @@ -204,7 +204,9 @@ mduv380_def = def + stm32f405_def + {'PLATFORM_MDUV380': ''} ## Radioddity GD77 -gd77_src = src + mk22fn512_src + ['platform/targets/GD77/platform.c'] +gd77_src = src + mk22fn512_src + ['platform/targets/GD77/platform.c', + 'platform/drivers/display/UC1701_GD77.c', + 'openrtx/src/graphics/graphics_bw.c'] gd77_inc = inc + mk22fn512_inc + ['platform/targets/GD77'] gd77_def = def + mk22fn512_def + {'PLATFORM_GD77': ''} diff --git a/openrtx/src/graphics/graphics_bw.c b/openrtx/src/graphics/graphics_bw.c index 4b332801..b7391dc8 100644 --- a/openrtx/src/graphics/graphics_bw.c +++ b/openrtx/src/graphics/graphics_bw.c @@ -27,6 +27,7 @@ #include #include "display.h" #include "graphics.h" +#include "hwconfig.h" typedef enum { diff --git a/platform/drivers/display/UC1701_GD77.c b/platform/drivers/display/UC1701_GD77.c index 6bda7b21..4292f17a 100644 --- a/platform/drivers/display/UC1701_GD77.c +++ b/platform/drivers/display/UC1701_GD77.c @@ -91,10 +91,11 @@ void display_init() gpio_clearPin(LCD_CS); gpio_clearPin(LCD_RS); /* RS low -> command mode */ -// sendByteToController(0xE2); /* System Reset */ +// sendByteToController(0xE2); /* System Reset */ sendByteToController(0x2F); /* Voltage Follower On */ sendByteToController(0x81); /* Set Electronic Volume = 15 */ - sendByteToController(0x3F); /* Full contrast */ + /* TODO variable contrast */ + sendByteToController(0x15); /* Contrast */ sendByteToController(0xA2); /* Set Bias = 1/9 */ sendByteToController(0xA1); /* A0 Set SEG Direction */ sendByteToController(0xC0); /* Set COM Direction */ @@ -110,40 +111,55 @@ void display_terminate() } } +void display_renderRow(uint8_t row) +{ + /* magic stuff */ + uint8_t *buf = (frameBuffer + 128 * row); + for (uint8_t i = 0; i<16; i++) + { + uint8_t tmp[8] = {0}; + for (uint8_t j = 0; j < 8; j++) + { + uint8_t tmp_buf = buf[j*16 + i]; + int count = __builtin_popcount(tmp_buf); + while (count > 0) + { + int pos = __builtin_ctz(tmp_buf); + tmp[pos] |= 1UL << j; + tmp_buf &= ~(1 << pos); + count--; + } + } + for (uint8_t s = 0; s < 8; s++){ + sendByteToController(tmp[s]); + } + } +} + void display_renderRows(uint8_t startRow, uint8_t endRow) { - if(frameBuffer == NULL) return; - - uint8_t *rowPos = (frameBuffer + startRow * SCREEN_WIDTH); - - for(uint8_t row = startRow; row < endRow; row++) + for(uint8_t row = startRow; row < endRow; row++) { gpio_clearPin(LCD_RS); /* RS low -> command mode */ sendByteToController(0xB0 | row); /* Set Y position */ sendByteToController(0x10); /* Set X position */ sendByteToController(0x04); - gpio_setPin(LCD_RS); /* RS high -> data mode */ - - for(size_t x = 0; x < SCREEN_WIDTH; x++) - { - sendByteToController(*rowPos); - rowPos++; - } + display_renderRow(row); } + } void display_render() { - display_renderRows(0, SCREEN_HEIGHT); + gpio_clearPin(LCD_CS); + display_renderRows(0, SCREEN_HEIGHT / 8); + gpio_setPin(LCD_CS); } bool display_renderingInProgress() { - /* - * Rendering is in progress if display's chip select is low or a DMA - * transfer is in progress. - */ + return (gpio_readPin(LCD_CS) == 0); } void *display_getFrameBuffer() diff --git a/platform/targets/GD77/hwconfig.h b/platform/targets/GD77/hwconfig.h index 7148b8a8..c5ae76b0 100644 --- a/platform/targets/GD77/hwconfig.h +++ b/platform/targets/GD77/hwconfig.h @@ -27,4 +27,16 @@ #define GREEN_LED GPIOB,18 #define RED_LED GPIOC,14 +/* Screen dimensions */ +#define SCREEN_WIDTH 128 +#define SCREEN_HEIGHT 64 + +/* Display */ +#define LCD_BKLIGHT GPIOC,4 +#define LCD_CS GPIOC,8 +#define LCD_RST GPIOC,9 +#define LCD_RS GPIOC,10 +#define LCD_CLK GPIOC,11 +#define LCD_DAT GPIOC,12 + #endif diff --git a/platform/targets/GD77/platform.c b/platform/targets/GD77/platform.c index 92a82a20..182b1946 100644 --- a/platform/targets/GD77/platform.c +++ b/platform/targets/GD77/platform.c @@ -21,12 +21,30 @@ #include #include #include "hwconfig.h" +#include "rtc.h" + +curTime_t rtc_getTime() +{ + /* TODO */ + curTime_t t; + t.hour = 12; + t.minute = 12; + t.second = 12; + t.year = 2020; + t.day = 4; + t.month = 12; + t.date = 12; + return t; +} void platform_init() { /* Configure GPIOs */ gpio_setMode(GREEN_LED, OUTPUT); gpio_setMode(RED_LED, OUTPUT); + + gpio_setMode(LCD_BKLIGHT, OUTPUT); + gpio_clearPin(LCD_BKLIGHT); } void platform_terminate() @@ -112,4 +130,12 @@ void platform_beepStop() void platform_setBacklightLevel(uint8_t level) { /* TODO */ + if(level > 1) + { + gpio_setPin(LCD_BKLIGHT); + } + else + { + gpio_clearPin(LCD_BKLIGHT); + } }