Renamed 'lcd.h' to 'display.h' and updated the function names for low-level display driver.

replace/8f13b6d28a2b52971d5ddd753f855da3dfc38953
Silvano Seva 2020-10-03 10:31:06 +02:00 zatwierdzone przez Niccolò Izzo
rodzic f043581928
commit 638707a6aa
5 zmienionych plików z 61 dodań i 61 usunięć

Wyświetl plik

@ -15,8 +15,8 @@
* along with this program; if not, see <http://www.gnu.org/licenses/> *
***************************************************************************/
#ifndef LCD_H
#define LCD_H
#ifndef DISPLAY_H
#define DISPLAY_H
#include <stdint.h>
#include <stdbool.h>
@ -52,32 +52,32 @@
* prematurely, without configuring the display and the backlight timer. Thus, a
* dark screen can be symptom of failed allocation.
*/
void lcd_init();
void display_init();
/**
* When called, this function turns off backlight, shuts down backlight control
* and deallocates the framebuffer.
*/
void lcd_terminate();
void display_terminate();
/**
* Get screen width in pixels.
* @return screen with, in pixels.
*/
uint16_t lcd_screenWidth();
uint16_t display_screenWidth();
/**
* Get screen height in pixels.
* @return screen height, in pixels.
*/
uint16_t lcd_screenHeight();
uint16_t display_screenHeight();
/**
* Set screen backlight to a given level.
* @param level: backlight level, from 0 (backlight off) to 255 (backlight at
* full brightness).
*/
void lcd_setBacklightLevel(uint8_t level);
void display_setBacklightLevel(uint8_t level);
/**
* Copy a given section, between two given rows, of framebuffer content to the
@ -85,20 +85,20 @@ void lcd_setBacklightLevel(uint8_t level);
* @param startRow: first row of the framebuffer section to be copied
* @param endRow: last row of the framebuffer section to be copied
*/
void lcd_renderRows(uint8_t startRow, uint8_t endRow);
void display_renderRows(uint8_t startRow, uint8_t endRow);
/**
* Copy framebuffer content to the display internal buffer. To be called
* whenever there is need to update the display.
*/
void lcd_render();
void display_render();
/**
* Check if framebuffer is being copied to the screen or not, in which case it
* can be modified without problems.
* @return false if rendering is not in progress.
*/
bool lcd_renderingInProgress();
bool display_renderingInProgress();
/**
* Get pointer to framebuffer. Being this a standard interface for all the
@ -106,13 +106,13 @@ bool lcd_renderingInProgress();
* 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.
* 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 *lcd_getFrameBuffer();
void *display_getFrameBuffer();
#endif /* LCD_H */
#endif /* DISPLAY_H */

Wyświetl plik

@ -19,7 +19,7 @@
#include <stddef.h>
#include <stdlib.h>
#include "gpio.h"
#include "lcd.h"
#include "display.h"
#include "delays.h"
/* Defines for GPIO control, really ugly but useful. */
@ -103,7 +103,7 @@
#define SCREEN_HEIGHT 128
/*
* LCD framebuffer, allocated on the heap by lcd_init().
* LCD framebuffer, allocated on the heap by display_init().
* Pixel format is RGB565, 16 bit per pixel
*/
static uint16_t *frameBuffer;
@ -124,7 +124,7 @@ static inline __attribute__((__always_inline__)) void writeData(uint8_t val)
*((volatile uint8_t*) LCD_FSMC_ADDR_DATA) = val;
}
void lcd_init()
void display_init()
{
/* Allocate framebuffer, two bytes per pixel */
frameBuffer = (uint16_t *) malloc(SCREEN_WIDTH * SCREEN_HEIGHT * 2);
@ -353,7 +353,7 @@ void lcd_init()
gpio_setPin(CS);
}
void lcd_terminate()
void display_terminate()
{
/* Shut off backlight, FSMC and deallocate framebuffer */
gpio_setMode(GPIOC, 6, OUTPUT);
@ -366,22 +366,22 @@ void lcd_terminate()
}
}
uint16_t lcd_screenWidth()
uint16_t display_screenWidth()
{
return SCREEN_WIDTH;
}
uint16_t lcd_screenHeight()
uint16_t display_screenHeight()
{
return SCREEN_HEIGHT;
}
void lcd_setBacklightLevel(uint8_t level)
void display_setBacklightLevel(uint8_t level)
{
TIM8->CCR1 = level;
}
void lcd_renderRows(uint8_t startRow, uint8_t endRow)
void display_renderRows(uint8_t startRow, uint8_t endRow)
{
/*
@ -426,12 +426,12 @@ void lcd_renderRows(uint8_t startRow, uint8_t endRow)
| DMA_SxCR_EN; /* Start transfer */
}
void lcd_render()
void display_render()
{
lcd_renderRows(0, SCREEN_HEIGHT);
display_renderRows(0, SCREEN_HEIGHT);
}
bool lcd_renderingInProgress()
bool display_renderingInProgress()
{
/*
* Render is in progress if PD6 is low. Its value can be tested reading
@ -441,7 +441,7 @@ bool lcd_renderingInProgress()
return (pinValue == 0) ? 1 : 0;
}
void *lcd_getFrameBuffer()
void *display_getFrameBuffer()
{
return (void *)(frameBuffer);
}

Wyświetl plik

@ -24,7 +24,7 @@
* this driver.
*/
#include "lcd.h"
#include "display.h"
#include <stdio.h>
#include <string.h>
#include <SDL2/SDL.h>
@ -42,7 +42,7 @@ SDL_Surface *renderSurface;
uint16_t *frameBuffer;
bool inProgress;
void lcd_init()
void display_init()
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
@ -68,7 +68,7 @@ void lcd_init()
}
}
void lcd_terminate()
void display_terminate()
{
while(inProgress) { } /* Wait until current render finishes */
printf("Terminating SDL display emulator, goodbye!\n");
@ -77,22 +77,22 @@ void lcd_terminate()
SDL_Quit();
}
uint16_t lcd_screenWidth()
uint16_t display_screenWidth()
{
return SCREEN_WIDTH;
}
uint16_t lcd_screenHeight()
uint16_t display_screenHeight()
{
return SCREEN_HEIGHT;
}
void lcd_setBacklightLevel(uint8_t level)
void display_setBacklightLevel(uint8_t level)
{
printf("Backlight level set to %d\n", level);
}
void lcd_renderRows(uint8_t startRow, uint8_t endRow)
void display_renderRows(uint8_t startRow, uint8_t endRow)
{
Uint32 *pixels = (Uint32*)renderSurface->pixels;
inProgress = true;
@ -130,17 +130,17 @@ void lcd_renderRows(uint8_t startRow, uint8_t endRow)
SDL_UpdateWindowSurface(window);
}
void lcd_render()
void display_render()
{
lcd_renderRows(0, SCREEN_HEIGHT);
display_renderRows(0, SCREEN_HEIGHT);
}
bool lcd_renderingInProgress()
bool display_renderingInProgress()
{
return inProgress;
}
void *lcd_getFrameBuffer()
void *display_getFrameBuffer()
{
return (void *)(frameBuffer);
}

Wyświetl plik

@ -25,7 +25,7 @@
* the driver source file.
*/
#include "lcd.h"
#include "display.h"
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
@ -37,30 +37,30 @@ 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 = (uint16_t *)(lcd_getFrameBuffer());
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*lcd_screenWidth()] = color;
buf[j + i*display_screenWidth()] = color;
}
}
}
int main()
{
lcd_init();
lcd_setBacklightLevel(254);
display_init();
display_setBacklightLevel(254);
/* Horizontal red line */
drawRect(0, 10, lcd_screenWidth(), 20, 0xF800);
drawRect(0, 10, display_screenWidth(), 20, 0xF800);
/* Vertical blue line */
drawRect(10, 0, 20, lcd_screenHeight(), 0x001F);
drawRect(10, 0, 20, display_screenHeight(), 0x001F);
/* Vertical green line */
drawRect(80, 0, 20, lcd_screenHeight(), 0x07e0);
drawRect(80, 0, 20, display_screenHeight(), 0x07e0);
/*
* Use SDL event listener to check if window close button has been pressed,
@ -70,11 +70,11 @@ int main()
while(1)
{
lcd_render();
display_render();
SDL_PollEvent(&eventListener);
if(eventListener.type == SDL_QUIT) break;
}
lcd_terminate();
display_terminate();
return 0;
}

Wyświetl plik

@ -7,7 +7,7 @@
#include <SDL2/SDL.h>
#undef main
#include "lcd.h"
#include "display.h"
static OS_TCB App_TaskStartTCB;
static CPU_STK_SIZE App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE];
@ -23,28 +23,28 @@ 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 > lcd_screenWidth()) x_max = lcd_screenWidth();
if(y_max > lcd_screenHeight()) y_max = lcd_screenHeight();
uint16_t *buf = (uint16_t *)(lcd_getFrameBuffer());
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*lcd_screenWidth()] = color;
buf[j + i*display_screenWidth()] = color;
}
}
}
void clearScreen()
{
uint16_t *buf = (uint16_t *)(lcd_getFrameBuffer());
uint16_t *buf = (uint16_t *)(display_getFrameBuffer());
for(int i=0; i < lcd_screenHeight(); i++)
for(int i=0; i < display_screenHeight(); i++)
{
for(int j=0; j < lcd_screenWidth(); j++)
for(int j=0; j < display_screenWidth(); j++)
{
buf[j + i*lcd_screenWidth()] = 0xFFFF;
buf[j + i*display_screenWidth()] = 0xFFFF;
}
}
}
@ -117,7 +117,7 @@ static void gfxThread(void *arg)
int pos = 0;
SDL_Event eventListener;
lcd_init();
display_init();
while(1)
{
@ -125,16 +125,16 @@ static void gfxThread(void *arg)
if(eventListener.type == SDL_QUIT) break;
clearScreen();
drawRect(0, pos, lcd_screenWidth(), 20, 0xF800);
lcd_render();
while(lcd_renderingInProgress()) ;
drawRect(0, pos, display_screenWidth(), 20, 0xF800);
display_render();
while(display_renderingInProgress()) ;
pos += 20;
if(pos > lcd_screenHeight() - 20) pos = 0;
if(pos > display_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);
lcd_terminate();
display_terminate();
}