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.

This commit is contained in:
Silvano Seva 2020-10-03 10:14:19 +02:00 committed by Niccolò Izzo
parent ad8d89cd3e
commit f043581928
5 changed files with 16 additions and 17 deletions

View File

@ -26,8 +26,8 @@
* *
*********************** HOW TO MANAGE FRAMEBUFFER ***************************** *********************** HOW TO MANAGE FRAMEBUFFER *****************************
* *
* This driver allocates the framebuffer as a block of memory addressed linearly * This driver allocates the framebuffer as a block of linearly addressed memory
* as an array of SCREEN_HEIGHT*SCREEN_WIDTH 16-bit variables. * equivalent to an array of SCREEN_HEIGHT*SCREEN_WIDTH elements.
* With respect to it, screen is indexed in this way: * With respect to it, screen is indexed in this way:
* *
* (0,0) * (0,0)
@ -39,7 +39,7 @@
* y * y
* *
* then to set the value of the pixel having coordinates (X,Y), framebuffer has * 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(); bool lcd_renderingInProgress();
/** /**
* Get pointer to framebuffer. This buffer is addressed linearly and each * Get pointer to framebuffer. Being this a standard interface for all the
* location is a pixel whose color coding is RGB565. * 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 * Changes to the framebuffer will not be reflected on the display until
* lcd_render() or lcd_renderRows() are called. * 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 * WARNING: no bound check is performed! Do not call free() on the pointer
* returned, doing so will destroy the framebuffer! * returned, doing so will destroy the framebuffer!
* @return pointer to framebuffer. * @return pointer to framebuffer.
*/ */
uint16_t *lcd_getFrameBuffer(); void *lcd_getFrameBuffer();
#endif /* LCD_H */ #endif /* LCD_H */

View File

@ -441,7 +441,7 @@ bool lcd_renderingInProgress()
return (pinValue == 0) ? 1 : 0; return (pinValue == 0) ? 1 : 0;
} }
uint16_t *lcd_getFrameBuffer() void *lcd_getFrameBuffer()
{ {
return frameBuffer; return (void *)(frameBuffer);
} }

View File

@ -140,7 +140,7 @@ bool lcd_renderingInProgress()
return inProgress; return inProgress;
} }
uint16_t *lcd_getFrameBuffer() void *lcd_getFrameBuffer()
{ {
return frameBuffer; return (void *)(frameBuffer);
} }

View File

@ -37,7 +37,7 @@ void drawRect(int x, int y, int width, int height, uint16_t color)
{ {
int x_max = x + width; int x_max = x + width;
int y_max = y + height; 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++) for(int i=y; i < y_max; i++)
{ {

View File

@ -25,7 +25,7 @@ void drawRect(int x, int y, int width, int height, uint16_t color)
int y_max = y + height; int y_max = y + height;
if(x_max > lcd_screenWidth()) x_max = lcd_screenWidth(); if(x_max > lcd_screenWidth()) x_max = lcd_screenWidth();
if(y_max > lcd_screenHeight()) y_max = lcd_screenHeight(); 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++) 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() void clearScreen()
{ {
uint16_t *buf = lcd_getFrameBuffer(); uint16_t *buf = (uint16_t *)(lcd_getFrameBuffer());
for(int i=0; i < lcd_screenHeight(); i++) for(int i=0; i < lcd_screenHeight(); i++)
{ {