From f0435819287bdfae461621068cb88eea9e54aa71 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sat, 3 Oct 2020 10:14:19 +0200 Subject: [PATCH] Making the interface for low-level display drivers more general: now the pointer to framebuffer is returned as void *. Updated existing drivers and test code accordingly. --- openrtx/include/interfaces/lcd.h | 19 +++++++++---------- platform/drivers/display/HX83XX_md380.c | 4 ++-- platform/drivers/display/display_libSDL.c | 4 ++-- tests/platform/display_test_SDL.c | 2 +- tests/platform/x64_uC.c | 4 ++-- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/openrtx/include/interfaces/lcd.h b/openrtx/include/interfaces/lcd.h index 040f386d..c993ea6c 100644 --- a/openrtx/include/interfaces/lcd.h +++ b/openrtx/include/interfaces/lcd.h @@ -26,8 +26,8 @@ * *********************** HOW TO MANAGE FRAMEBUFFER ***************************** * - * This driver allocates the framebuffer as a block of memory addressed linearly - * as an array of SCREEN_HEIGHT*SCREEN_WIDTH 16-bit variables. + * This driver allocates the framebuffer as a block of linearly addressed memory + * equivalent to an array of SCREEN_HEIGHT*SCREEN_WIDTH elements. * With respect to it, screen is indexed in this way: * * (0,0) @@ -39,7 +39,7 @@ * y * * then to set the value of the pixel having coordinates (X,Y), framebuffer has - * to be indexed in this way buf[X + Y*SCREEN_WIDTH]. + * to be indexed in this way: buf[X + Y*SCREEN_WIDTH]. * */ @@ -101,19 +101,18 @@ void lcd_render(); bool lcd_renderingInProgress(); /** - * Get pointer to framebuffer. This buffer is addressed linearly and each - * location is a pixel whose color coding is RGB565. + * Get pointer to framebuffer. Being this a standard interface for all the + * low-level display drivers, this function returns a pointer to void: it's up + * to the caller performing the correct cast to one of the standard types used + * for color coding. * Changes to the framebuffer will not be reflected on the display until * lcd_render() or lcd_renderRows() are called. * - * IMPORTANT NOTE: to accomodate the display driver chip's needs, this buffer - * MUST be filled with values in big endian mode! A cleaner way to have the - * correct endianness, is to use GCC's builtin function __builtin_bswap16(). - * + * * WARNING: no bound check is performed! Do not call free() on the pointer * returned, doing so will destroy the framebuffer! * @return pointer to framebuffer. */ -uint16_t *lcd_getFrameBuffer(); +void *lcd_getFrameBuffer(); #endif /* LCD_H */ diff --git a/platform/drivers/display/HX83XX_md380.c b/platform/drivers/display/HX83XX_md380.c index 05f7d63e..29d5f3ba 100644 --- a/platform/drivers/display/HX83XX_md380.c +++ b/platform/drivers/display/HX83XX_md380.c @@ -441,7 +441,7 @@ bool lcd_renderingInProgress() return (pinValue == 0) ? 1 : 0; } -uint16_t *lcd_getFrameBuffer() +void *lcd_getFrameBuffer() { - return frameBuffer; + return (void *)(frameBuffer); } diff --git a/platform/drivers/display/display_libSDL.c b/platform/drivers/display/display_libSDL.c index ae30ab69..85c7bfe4 100644 --- a/platform/drivers/display/display_libSDL.c +++ b/platform/drivers/display/display_libSDL.c @@ -140,7 +140,7 @@ bool lcd_renderingInProgress() return inProgress; } -uint16_t *lcd_getFrameBuffer() +void *lcd_getFrameBuffer() { - return frameBuffer; + return (void *)(frameBuffer); } diff --git a/tests/platform/display_test_SDL.c b/tests/platform/display_test_SDL.c index 62b17ef9..d317e348 100644 --- a/tests/platform/display_test_SDL.c +++ b/tests/platform/display_test_SDL.c @@ -37,7 +37,7 @@ void drawRect(int x, int y, int width, int height, uint16_t color) { int x_max = x + width; int y_max = y + height; - uint16_t *buf = lcd_getFrameBuffer(); + uint16_t *buf = (uint16_t *)(lcd_getFrameBuffer()); for(int i=y; i < y_max; i++) { diff --git a/tests/platform/x64_uC.c b/tests/platform/x64_uC.c index d6e40d04..9e35f412 100644 --- a/tests/platform/x64_uC.c +++ b/tests/platform/x64_uC.c @@ -25,7 +25,7 @@ void drawRect(int x, int y, int width, int height, uint16_t color) int y_max = y + height; if(x_max > lcd_screenWidth()) x_max = lcd_screenWidth(); if(y_max > lcd_screenHeight()) y_max = lcd_screenHeight(); - uint16_t *buf = lcd_getFrameBuffer(); + uint16_t *buf = (uint16_t *)(lcd_getFrameBuffer()); for(int i=y; i < y_max; i++) { @@ -38,7 +38,7 @@ void drawRect(int x, int y, int width, int height, uint16_t color) void clearScreen() { - uint16_t *buf = lcd_getFrameBuffer(); + uint16_t *buf = (uint16_t *)(lcd_getFrameBuffer()); for(int i=0; i < lcd_screenHeight(); i++) {