graphics_rgb565.c: small refactoring. Linux-demo: moved from display interface to graphics interface
This commit is contained in:
parent
94bece00c0
commit
52b4718deb
|
|
@ -128,6 +128,11 @@ void graphics_render();
|
|||
*/
|
||||
bool graphics_renderingInProgress();
|
||||
|
||||
/**
|
||||
* Makes the screen black.
|
||||
*/
|
||||
void graphics_clearScreen();
|
||||
|
||||
/**
|
||||
* Fills screen with the specified color.
|
||||
* @param color: border and fill color, in color_t format.
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@
|
|||
|
||||
#include "display.h"
|
||||
#include "graphics.h"
|
||||
#include <string.h>
|
||||
|
||||
#define COLOR_WHITE = {31, 63, 31}
|
||||
|
||||
typedef struct rgb565_t
|
||||
{
|
||||
|
|
@ -33,7 +36,7 @@ typedef struct rgb565_t
|
|||
|
||||
bool initialized = 0;
|
||||
uint16_t screen_width = 0;
|
||||
uint16_t screen_heigth = 0;
|
||||
uint16_t screen_height = 0;
|
||||
rgb565_t *buf;
|
||||
|
||||
void graphics_init()
|
||||
|
|
@ -41,7 +44,7 @@ void graphics_init()
|
|||
display_init();
|
||||
// Set global variables and framebuffer pointer
|
||||
screen_width = graphics_screenWidth();
|
||||
screen_heigth = graphics_screenHeight();
|
||||
screen_height = graphics_screenHeight();
|
||||
buf = (rgb565_t *)(display_getFrameBuffer());
|
||||
initialized = 1;
|
||||
}
|
||||
|
|
@ -82,7 +85,7 @@ bool graphics_renderingInProgress()
|
|||
return display_renderingInProgress();
|
||||
}
|
||||
|
||||
rgb565_t true2highColor(color_t true_color)
|
||||
rgb565_t _true2highColor(color_t true_color)
|
||||
{
|
||||
uint8_t high_r = true_color.r >> 3;
|
||||
uint8_t high_g = true_color.g >> 2;
|
||||
|
|
@ -91,12 +94,20 @@ rgb565_t true2highColor(color_t true_color)
|
|||
return high_color;
|
||||
}
|
||||
|
||||
void graphics_clearScreen()
|
||||
{
|
||||
if(!initialized)
|
||||
return;
|
||||
// Set the whole framebuffer to 0x00 = make the screen black
|
||||
memset(buf, 0x00, sizeof(rgb565_t) * screen_width * screen_height);
|
||||
}
|
||||
|
||||
void graphics_fillScreen(color_t color)
|
||||
{
|
||||
if(!initialized)
|
||||
return;
|
||||
rgb565_t color_565 = true2highColor(color);
|
||||
for(int y=0; y < screen_heigth; y++)
|
||||
rgb565_t color_565 = _true2highColor(color);
|
||||
for(int y=0; y < screen_height; y++)
|
||||
{
|
||||
for(int x=0; x < screen_width; x++)
|
||||
{
|
||||
|
|
@ -109,8 +120,8 @@ void graphics_drawLine(point_t start, point_t end, color_t color)
|
|||
{
|
||||
if(!initialized)
|
||||
return;
|
||||
rgb565_t color_565 = true2highColor(color);
|
||||
for(int y=0; y < screen_heigth; y++)
|
||||
rgb565_t color_565 = _true2highColor(color);
|
||||
for(int y=0; y < screen_height; y++)
|
||||
{
|
||||
for(int x=0; x < screen_width; x++)
|
||||
{
|
||||
|
|
@ -123,13 +134,11 @@ void graphics_drawRect(point_t start, uint16_t width, uint16_t height, color_t c
|
|||
{
|
||||
if(!initialized)
|
||||
return;
|
||||
rgb565_t color_565 = true2highColor(color);
|
||||
rgb565_t color_565 = _true2highColor(color);
|
||||
uint16_t x_max = start.x + width;
|
||||
if(x_max > (screen_width - 1))
|
||||
x_max = screen_width - 1;
|
||||
uint16_t y_max = start.y + height;
|
||||
if(y_max > (screen_heigth - 1))
|
||||
y_max = screen_heigth - 1;
|
||||
if(x_max > (screen_width - 1)) x_max = screen_width - 1;
|
||||
if(y_max > (screen_height - 1)) y_max = screen_height - 1;
|
||||
for(int y=start.y; y < y_max; y++)
|
||||
{
|
||||
for(int x=start.x; x < x_max; x++)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <SDL2/SDL.h>
|
||||
#undef main
|
||||
|
||||
#include "display.h"
|
||||
#include "graphics.h"
|
||||
|
||||
static OS_TCB App_TaskStartTCB;
|
||||
static CPU_STK_SIZE App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE];
|
||||
|
|
@ -19,36 +19,6 @@ static void gfxThread(void *arg);
|
|||
|
||||
static int running = 0;
|
||||
|
||||
void drawRect(int x, int y, int width, int height, uint16_t color)
|
||||
{
|
||||
int x_max = x + width;
|
||||
int y_max = y + height;
|
||||
if(x_max > display_screenWidth()) x_max = display_screenWidth();
|
||||
if(y_max > display_screenHeight()) y_max = display_screenHeight();
|
||||
uint16_t *buf = (uint16_t *)(display_getFrameBuffer());
|
||||
|
||||
for(int i=y; i < y_max; i++)
|
||||
{
|
||||
for(int j=x; j < x_max; j++)
|
||||
{
|
||||
buf[j + i*display_screenWidth()] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clearScreen()
|
||||
{
|
||||
uint16_t *buf = (uint16_t *)(display_getFrameBuffer());
|
||||
|
||||
for(int i=0; i < display_screenHeight(); i++)
|
||||
{
|
||||
for(int j=0; j < display_screenWidth(); j++)
|
||||
{
|
||||
buf[j + i*display_screenWidth()] = 0xFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
OS_ERR err;
|
||||
|
|
@ -91,7 +61,6 @@ int main (void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void App_TaskStart(void *p_arg)
|
||||
{
|
||||
|
||||
|
|
@ -117,24 +86,26 @@ static void gfxThread(void *arg)
|
|||
int pos = 0;
|
||||
SDL_Event eventListener;
|
||||
|
||||
display_init();
|
||||
graphics_init();
|
||||
|
||||
while(1)
|
||||
{
|
||||
SDL_PollEvent(&eventListener);
|
||||
if(eventListener.type == SDL_QUIT) break;
|
||||
|
||||
clearScreen();
|
||||
drawRect(0, pos, display_screenWidth(), 20, 0xF800);
|
||||
display_render();
|
||||
while(display_renderingInProgress()) ;
|
||||
graphics_clearScreen();
|
||||
point_t origin = {0, pos};
|
||||
color_t color_red = {255, 0, 0};
|
||||
graphics_drawRect(origin, display_screenWidth(), 20, color_red, 1);
|
||||
graphics_render();
|
||||
while(graphics_renderingInProgress()) ;
|
||||
pos += 20;
|
||||
if(pos > display_screenHeight() - 20) pos = 0;
|
||||
if(pos > graphics_screenHeight() - 20) pos = 0;
|
||||
|
||||
OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &os_err);
|
||||
}
|
||||
|
||||
running = 0;
|
||||
OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &os_err);
|
||||
display_terminate();
|
||||
graphics_terminate();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue