feat: set color, show char
This commit is contained in:
parent
c6a568272f
commit
4573e7f17d
@ -105,7 +105,10 @@ typedef unsigned char uchar;
|
||||
|
||||
void LCD_RESET();
|
||||
void LCD_Init();
|
||||
void LCD_S_XY(uint16_t x, uint16_t y);
|
||||
void LCD_S_Rec(uint16_t xs, uint16_t xe, uint16_t ys, uint16_t ye);
|
||||
void LCD_D_Point(uint16_t x, uint16_t y, uint16_t color);
|
||||
void LCD_Clear(uint16_t color);
|
||||
void LCD_SetColor(uint16_t color);
|
||||
void LCD_SetBackColor(uint16_t color);
|
||||
void LCD_SetXY(uint16_t x, uint16_t y);
|
||||
void LCD_SetRec(uint16_t xs, uint16_t xe, uint16_t ys, uint16_t ye);
|
||||
void LCD_DrawPoint(uint16_t x, uint16_t y, uint16_t color);
|
||||
void LCD_Clear(uint16_t color);
|
||||
void LCD_ShowChar(uint16_t x, uint16_t y, uint8_t num, uint8_t size, uint8_t mode);
|
||||
|
67
src/tftlcd.c
67
src/tftlcd.c
@ -1,9 +1,10 @@
|
||||
#include "font.h"
|
||||
#include "systick.h"
|
||||
#include "tftlcd.h"
|
||||
|
||||
// 画笔颜色 背景颜色
|
||||
unsigned int POINT_COLOR = 0x0000, BACK_COLOR = 0xFFFF;
|
||||
unsigned int DeviceCode;
|
||||
uint16_t PEN_COLOR = 0x0000; // 画笔颜色
|
||||
uint16_t BACK_COLOR = 0xFFFF; // 背景颜色
|
||||
uint16_t DeviceCode; // 设备模式
|
||||
|
||||
void LCD_RESET() {
|
||||
LCD_RST_CLR;
|
||||
@ -204,16 +205,20 @@ void LCD_Init() {
|
||||
LCD_WR_REG(0x29); // Display on
|
||||
|
||||
LCD_BL_CLR; // Back Light On
|
||||
LCD_Clear(WHITE);
|
||||
LCD_Clear(BACK_COLOR);
|
||||
}
|
||||
|
||||
void LCD_S_XY(uint16_t x, uint16_t y) {
|
||||
void LCD_SetColor(uint16_t color) { PEN_COLOR = color; }
|
||||
|
||||
void LCD_SetBackColor(uint16_t color) { BACK_COLOR = color; }
|
||||
|
||||
void LCD_SetXY(uint16_t x, uint16_t y) {
|
||||
LCD_WR_REG_DATA_16BIT(LCD_PAGE_WR, x);
|
||||
LCD_WR_REG_DATA_16BIT(LCD_COL_WR, y);
|
||||
}
|
||||
|
||||
// Set a rectangle area
|
||||
void LCD_S_Rec(uint16_t xs, uint16_t xe, uint16_t ys, uint16_t ye) {
|
||||
void LCD_SetRec(uint16_t xs, uint16_t xe, uint16_t ys, uint16_t ye) {
|
||||
LCD_WR_REG(LCD_PAGE_WR);
|
||||
LCD_WR_DATA_16BIT(xs);
|
||||
LCD_WR_DATA_16BIT(xe);
|
||||
@ -223,18 +228,60 @@ void LCD_S_Rec(uint16_t xs, uint16_t xe, uint16_t ys, uint16_t ye) {
|
||||
LCD_WR_DATA_16BIT(ye);
|
||||
}
|
||||
|
||||
void LCD_D_Point(uint16_t x, uint16_t y, uint16_t color) {
|
||||
LCD_S_XY(x, y);
|
||||
void LCD_DrawPoint(uint16_t x, uint16_t y, uint16_t color) {
|
||||
LCD_SetXY(x, y);
|
||||
LCD_WR_REG_DATA_16BIT(LCD_RAM_WR, color);
|
||||
}
|
||||
|
||||
void LCD_Clear(uint16_t color) {
|
||||
LCD_S_Rec(0, LCD_W - 1, 0, LCD_H - 1);
|
||||
LCD_SetRec(0, LCD_W - 1, 0, LCD_H - 1);
|
||||
LCD_WR_REG(LCD_RAM_WR);
|
||||
for (uint32_t i = 0; i < LCD_W * LCD_H; i++) LCD_WR_DATA_16BIT(color);
|
||||
// for (uint16_t i = 0; i < LCD_W; i++)
|
||||
// for (uint16_t j = 0; j < LCD_H; j++) {
|
||||
// LCD_S_XY(i, j);
|
||||
// LCD_SetXY(i, j);
|
||||
// LCD_WR_REG_DATA_16BIT(LCD_RAM_WR, color);
|
||||
// }
|
||||
}
|
||||
|
||||
/*
|
||||
@brief Display a charactor on the position of (x,y)
|
||||
@param x x of the lower left of the character
|
||||
@param y y of the lower left of the character
|
||||
@param sign the charactor
|
||||
@param size size of the charactor, 12x06 or 16x08
|
||||
@param mode 0: non-overlap, 1: overlap
|
||||
*/
|
||||
void LCD_ShowChar(uint16_t x, uint16_t y, uint8_t sign, uint8_t size, uint8_t mode) {
|
||||
if (x > LCD_W || y > LCD_H) return;
|
||||
|
||||
uchar tmp;
|
||||
uint16_t x0 = x;
|
||||
const uchar *font;
|
||||
if (size == 12) font = &asc2_1206[0][0];
|
||||
else font = &asc2_1608[0][0];
|
||||
|
||||
sign = sign - ' ';
|
||||
if (!mode) { // non-overlap
|
||||
for (uint16_t px = 0; px < size; px++) {
|
||||
tmp = font[sign * size + px];
|
||||
for (uint16_t py = 0; py < size / 2; py++) {
|
||||
if (tmp & 0x01) LCD_DrawPoint(x, y, PEN_COLOR);
|
||||
else LCD_DrawPoint(x, y, BACK_COLOR);
|
||||
tmp >>= 1;
|
||||
x++;
|
||||
}
|
||||
x = x0;
|
||||
y++;
|
||||
}
|
||||
} else // overlap
|
||||
{
|
||||
for (uint16_t px = 0; px < size; px++) {
|
||||
tmp = font[sign * size + px];
|
||||
for (uint16_t py = 0; py < size / 2; py++) {
|
||||
if (tmp & 0x01) LCD_DrawPoint(x + py, y + px, PEN_COLOR);
|
||||
tmp >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user