diff --git a/openrtx/include/interfaces/display.h b/openrtx/include/interfaces/display.h index 3ba5c460..bfb72766 100644 --- a/openrtx/include/interfaces/display.h +++ b/openrtx/include/interfaces/display.h @@ -58,21 +58,6 @@ extern "C" { */ void display_init(); -/** - * 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 - * display_render() or display_renderRows() are called. - * - * - * WARNING: no bound check is performed! Do not call free() on the pointer - * returned, doing so will destroy the framebuffer! - * @return pointer to framebuffer. - */ -void *display_getFrameBuffer(); - /** * When called, this function terminates the display driver * and deallocates the framebuffer. @@ -81,18 +66,22 @@ void display_terminate(); /** * Copy a given section, between two given rows, of framebuffer content to the - * display. + * display. This function blocks the caller until render is completed. + * * @param startRow: first row of the framebuffer section to be copied * @param endRow: last row of the framebuffer section to be copied + * @param fb: pointer to frameBuffer. */ -void display_renderRows(uint8_t startRow, uint8_t endRow); +void display_renderRows(uint8_t startRow, uint8_t endRow, void *fb); /** * Copy framebuffer content to the display internal buffer, to be called * whenever there is need to update the display. * This function blocks the caller until render is completed. + * + * @param fb: pointer to framebuffer. */ -void display_render(); +void display_render(void *fb); /** * Set display contrast. diff --git a/openrtx/src/core/graphics.c b/openrtx/src/core/graphics.c index b841901b..1651f9ae 100644 --- a/openrtx/src/core/graphics.c +++ b/openrtx/src/core/graphics.c @@ -97,6 +97,7 @@ static const GFXfont fonts[] = { TomThumb, // 5pt */ #define PIXEL_T rgb565_t +#define FB_SIZE (CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH) typedef struct { @@ -125,6 +126,7 @@ static rgb565_t _true2highColor(color_t true_color) */ #define PIXEL_T uint8_t +#define FB_SIZE (((CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH) / 8 ) + 1) typedef enum { @@ -147,25 +149,14 @@ static bw_t _color2bw(color_t true_color) #error Please define a pixel format type into hwconfig.h or meson.build #endif - -static PIXEL_T *buf; -static uint16_t fbSize; +static PIXEL_T __attribute__((section(".bss.fb"))) framebuffer[FB_SIZE]; static char text[32]; + void gfx_init() { display_init(); - buf = (PIXEL_T *)(display_getFrameBuffer()); -// Calculate framebuffer size -#ifdef CONFIG_PIX_FMT_RGB565 - fbSize = CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH * sizeof(PIXEL_T); -#elif defined CONFIG_PIX_FMT_BW - fbSize = (CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH) / 8; - /* Compensate for eventual truncation error in division */ - if((fbSize * 8) < (CONFIG_SCREEN_HEIGHT * CONFIG_SCREEN_WIDTH)) fbSize += 1; - fbSize *= sizeof(uint8_t); -#endif // Clear text buffer memset(text, 0x00, 32); } @@ -177,12 +168,12 @@ void gfx_terminate() void gfx_renderRows(uint8_t startRow, uint8_t endRow) { - display_renderRows(startRow, endRow); + display_renderRows(startRow, endRow, framebuffer); } void gfx_render() { - display_render(); + display_render(framebuffer); } void gfx_clearRows(uint8_t startRow, uint8_t endRow) @@ -193,13 +184,13 @@ void gfx_clearRows(uint8_t startRow, uint8_t endRow) uint16_t start = startRow * CONFIG_SCREEN_WIDTH * sizeof(PIXEL_T); uint16_t height = endRow - startRow * CONFIG_SCREEN_WIDTH * sizeof(PIXEL_T); // Set the specified rows to 0x00 = make the screen black - memset(buf + start, 0x00, height); + memset(framebuffer + start, 0x00, height); } void gfx_clearScreen() { // Set the whole framebuffer to 0x00 = make the screen black - memset(buf, 0x00, fbSize); + memset(framebuffer, 0x00, FB_SIZE * sizeof(PIXEL_T)); } void gfx_fillScreen(color_t color) @@ -226,16 +217,16 @@ inline void gfx_setPixel(point_t pos, color_t color) { uint8_t alpha = color.alpha; rgb565_t new_pixel = _true2highColor(color); - rgb565_t old_pixel = buf[pos.x + pos.y*CONFIG_SCREEN_WIDTH]; + rgb565_t old_pixel = framebuffer[pos.x + pos.y*CONFIG_SCREEN_WIDTH]; rgb565_t pixel; pixel.r = ((255-alpha)*old_pixel.r+alpha*new_pixel.r)/255; pixel.g = ((255-alpha)*old_pixel.g+alpha*new_pixel.g)/255; pixel.b = ((255-alpha)*old_pixel.b+alpha*new_pixel.b)/255; - buf[pos.x + pos.y*CONFIG_SCREEN_WIDTH] = pixel; + framebuffer[pos.x + pos.y*CONFIG_SCREEN_WIDTH] = pixel; } else { - buf[pos.x + pos.y*CONFIG_SCREEN_WIDTH] = _true2highColor(color); + framebuffer[pos.x + pos.y*CONFIG_SCREEN_WIDTH] = _true2highColor(color); } #elif defined CONFIG_PIX_FMT_BW // Ignore more than half transparent pixels @@ -243,8 +234,8 @@ inline void gfx_setPixel(point_t pos, color_t color) { uint16_t cell = (pos.x + pos.y*CONFIG_SCREEN_WIDTH) / 8; uint16_t elem = (pos.x + pos.y*CONFIG_SCREEN_WIDTH) % 8; - buf[cell] &= ~(1 << elem); - buf[cell] |= (_color2bw(color) << elem); + framebuffer[cell] &= ~(1 << elem); + framebuffer[cell] |= (_color2bw(color) << elem); } #endif } diff --git a/platform/drivers/stubs/display_stub.c b/platform/drivers/stubs/display_stub.c index 8af19bdb..a41dd319 100644 --- a/platform/drivers/stubs/display_stub.c +++ b/platform/drivers/stubs/display_stub.c @@ -21,12 +21,6 @@ #include #include -#ifdef CONFIG_PIX_FMT_BW -static uint8_t frameBuffer[(((CONFIG_SCREEN_WIDTH * CONFIG_SCREEN_HEIGHT) / 8 ) + 1)]; -#else -static uint16_t frameBuffer[CONFIG_SCREEN_WIDTH * CONFIG_SCREEN_HEIGHT]; -#endif - void display_init() { @@ -38,15 +32,16 @@ void display_terminate() } -void display_renderRows(uint8_t startRow, uint8_t endRow) +void display_renderRows(uint8_t startRow, uint8_t endRow, void *fb) { (void) startRow; (void) endRow; + (void) fb; } -void display_render() +void display_render(void *fb) { - + (void) fb; } void *display_getFrameBuffer()