ADD FLASH(flash.h flash.cpp flash_def.h flash_cfg.h flash_sfdp.cpp)
ADD RunTimer(log.h ticks.h ticks.cpp) ADD sim_key form sdl
This commit is contained in:
@@ -118,7 +118,6 @@ extern "C" {
|
||||
/**
|
||||
* @brief LCD_Type_Define
|
||||
*/
|
||||
#define ST7735_1_8_inch_screen 0x00U
|
||||
#define ST7735_0_9_inch_screen 0x01U
|
||||
#define ST7735_1_8a_inch_screen 0x02U
|
||||
/**
|
||||
@@ -135,9 +134,13 @@ extern "C" {
|
||||
|
||||
|
||||
#define ST7735_DELAY 120
|
||||
#define ST7735_PANEL HannStar_Panel
|
||||
#define ST7735_TYPE ST7735_0_9_inch_screen
|
||||
#define ST7735_PANEL BOE_Panel
|
||||
#define ST7735_TYPE ST7735_1_8a_inch_screen
|
||||
|
||||
//#define ST7735_X_OFFSET 0
|
||||
//#define ST7735_Y_OFFSET 0
|
||||
//#define ST7735_X_OFFSET 0
|
||||
//#define ST7735_Y_OFFSET 0
|
||||
|
||||
#if ST7735_TYPE == ST7735_0_9_inch_screen //0.96 ST7735
|
||||
#if ST7735_PANEL == HannStar_Panel
|
||||
@@ -176,8 +179,11 @@ const uint8_t st7735initcmd[] = {
|
||||
3, ST7735_PWR_CTRL4, 0x8A, 0x2A,
|
||||
3, ST7735_PWR_CTRL5, 0x8A, 0xEE,
|
||||
2, ST7735_VCOMH_VCOML_CTRL1, 0x0E,
|
||||
#if ST7735_PANEL == HannStar_Panel
|
||||
1, ST7735_DISPLAY_INVERSION_ON,//HannStar_Panel
|
||||
// 1,ST7735_DISPLAY_INVERSION_OFF,//BOE_Panel
|
||||
#else
|
||||
1, ST7735_DISPLAY_INVERSION_OFF,//BOE_Panel
|
||||
#endif
|
||||
2, ST7735_COLOR_MODE, ST7735_FORMAT_RBG565,
|
||||
17, ST7735_PV_GAMMA_CTRL, 0x02, 0x1C, 0x07U, 0x12U, 0x37U, 0x32U, 0x29U, 0x2DU, 0x29U, 0x25U, 0x2BU, 0x39U,
|
||||
0x00U, 0x01U, 0x03U, 0x10U,
|
||||
|
@@ -283,6 +283,8 @@ void TFT_DrawRect(TFT_T *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2
|
||||
**/
|
||||
void TFT_DrawCircle(TFT_T *dev, uint16_t x, uint16_t y, uint16_t r);
|
||||
|
||||
void TFT_DrawArc(TFT_T *dev, uint16_t x0, uint16_t y0, uint16_t radius, int start_angle, int end_angle);
|
||||
|
||||
/**
|
||||
* @brief 在TFT显示屏上显示单个字符
|
||||
* @param dev: [输入] TFT设备结构体指针
|
||||
@@ -359,6 +361,17 @@ void TFT_ShowPic(TFT_T *dev, uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, T
|
||||
**/
|
||||
void TFT_DrawCross(TFT_T *dev, uint16_t x, uint16_t y, uint8_t r);
|
||||
|
||||
/**
|
||||
* @brief 在屏幕上绘制一个X字交叉线
|
||||
* @param dev: [输入] TFT设备指针
|
||||
* @param x: [输入] 十字交叉线中心点x坐标
|
||||
* @param y: [输入] 十字交叉线中心点y坐标
|
||||
* @param r: [输入] 十字交叉线长度的一半(即从中心点到横竖线的长度)
|
||||
* @return void
|
||||
* @example TFT_DrawCross(&tft_dev, 100, 80, 5);
|
||||
**/
|
||||
void TFT_DrawXCross(TFT_T *dev, uint16_t x, uint16_t y, uint8_t r);
|
||||
|
||||
/**
|
||||
* @brief 在屏幕上显示进度条
|
||||
* @param dev: [输入] TFT设备指针
|
||||
@@ -372,6 +385,17 @@ void TFT_DrawCross(TFT_T *dev, uint16_t x, uint16_t y, uint8_t r);
|
||||
**/
|
||||
void TFT_ShowBar(TFT_T *dev, uint16_t x, uint16_t y, uint16_t width, uint16_t height, float progress);
|
||||
|
||||
/**
|
||||
* @brief 绘制带圆角的矩形
|
||||
* @param dev: [输入] TFT设备指针
|
||||
* @param x: [输入] 矩形左上角x坐标
|
||||
* @param y: [输入] 矩形左上角y坐标
|
||||
* @param width: [输入] 矩形宽度
|
||||
* @param height: [输入] 矩形高度
|
||||
* @param radius: [输入] 圆角半径
|
||||
* @return void
|
||||
**/
|
||||
void TFT_DrawRoundedRect(TFT_T *dev, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t radius);
|
||||
|
||||
#ifdef LVGL_FONT
|
||||
|
||||
@@ -392,6 +416,19 @@ void TFT_DisplayString(TFT_T *dev, const lv_font_t *font, uint8_t *s, uint16_t x
|
||||
#endif
|
||||
|
||||
|
||||
#define ARGB_TO_RGB565(...) \
|
||||
_ARGB_TO_RGB565_NARG(__VA_ARGS__, _ARGB_TO_RGB565_4, _ARGB_TO_RGB565_1)(__VA_ARGS__)
|
||||
|
||||
#define _ARGB_TO_RGB565_NARG(...) _ARGB_TO_RGB565_NARG_(__VA_ARGS__, _ARGB_TO_RGB565_RSEQ_N())
|
||||
#define _ARGB_TO_RGB565_NARG_(...) _ARGB_TO_RGB565_ARG_N(__VA_ARGS__)
|
||||
|
||||
#define _ARGB_TO_RGB565_ARG_N(_1, _2, _3, _4, N, ...) N
|
||||
#define _ARGB_TO_RGB565_RSEQ_N() 4, 3, 2, 1, 0
|
||||
|
||||
#define _ARGB_TO_RGB565_1(argb) (((((argb) >> 8) & 0xF800) | (((argb) >> 5) & 0x07E0) | ((argb) >> 3) & 0x001F)
|
||||
|
||||
#define _ARGB_TO_RGB565_4(a, r, g, b) (((((a) & 0xFF) >> 3) << 11) | ((((r) & 0xFF) >> 2) << 5) | (((g) & 0xFF) >> 3))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
182
lib/tft/tft.cpp
182
lib/tft/tft.cpp
@@ -1,3 +1,4 @@
|
||||
#include <valarray>
|
||||
#include "tft.h"
|
||||
#include "ascii_font.h"
|
||||
|
||||
@@ -201,11 +202,11 @@ void TFT_FillColor(TFT_T *dev,TFT_Color_t color){
|
||||
dev->sendData(color.u8, 2);
|
||||
}
|
||||
|
||||
|
||||
#define swap_(a, b) (a=(a)+(b),b=(a)-(b),a=(a)-(b))
|
||||
|
||||
void TFT_DrawLine(TFT_T *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
|
||||
uint16_t i, k, k1, k2;
|
||||
if ((x1 < 0) || (x2 > dev->width) || (y1 < 0) || (y2 > dev->height) || (x1 > x2) || (y1 > y2))return;
|
||||
uint16_t i;
|
||||
if ((x1 < 0) || (x2 > dev->width) || (y1 < 0) || (y2 > dev->height))return;
|
||||
if (x1 == x2) //画竖线
|
||||
{
|
||||
for (i = 0; i < (y2 - y1); i++) {
|
||||
@@ -217,12 +218,50 @@ void TFT_DrawLine(TFT_T *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2
|
||||
TFT_SetPixel(dev, x1 + i, y1,POINT_COLOR);
|
||||
}
|
||||
} else //画斜线
|
||||
{
|
||||
k1 = y2 - y1;
|
||||
k2 = x2 - x1;
|
||||
k = k1 * 10 / k2;
|
||||
for (i = 0; i < (x2 - x1); i++) {
|
||||
TFT_SetPixel(dev, x1 + i, y1 + i * k / 10,POINT_COLOR);
|
||||
{//Bresenham算法
|
||||
int p, twoDy, twoDyMinusDx, s1, s2;
|
||||
int dx = abs(x2 - x1), dy = abs(y2 - y1);
|
||||
if (dy > dx) //斜率大于1
|
||||
{
|
||||
p = 2 * dx - dy;
|
||||
twoDy = 2 * dx;
|
||||
twoDyMinusDx = 2 * (dx - dy);
|
||||
if (y1 > y2)//斜率为负时 反转斜率
|
||||
{
|
||||
swap_(x1, x2);
|
||||
swap_(y1, y2);
|
||||
}
|
||||
s1 = x2 > x1 ? 1 : -1;
|
||||
TFT_SetPixel(dev, x1, y1, POINT_COLOR);
|
||||
while (y1 < y2) {
|
||||
y1++;
|
||||
if (p < 0) { p += twoDy; }
|
||||
else {
|
||||
x1 += s1;
|
||||
p += twoDyMinusDx;
|
||||
}
|
||||
TFT_SetPixel(dev, x1, y1, POINT_COLOR);
|
||||
}
|
||||
} else {
|
||||
p = 2 * dy - dx;
|
||||
twoDy = 2 * dy;
|
||||
twoDyMinusDx = 2 * (dy - dx);
|
||||
if (x1 > x2)//斜率为负时 反转斜率
|
||||
{
|
||||
swap_(x1, x2);
|
||||
swap_(y1, y2);
|
||||
}
|
||||
s2 = y2 > y1 ? 1 : -1;
|
||||
TFT_SetPixel(dev, x1, y1, POINT_COLOR);
|
||||
while (x1 < x2) {
|
||||
x1++;
|
||||
if (p < 0) { p += twoDy; }
|
||||
else {
|
||||
y1 += s2;
|
||||
p += twoDyMinusDx;
|
||||
}
|
||||
TFT_SetPixel(dev, x1, y1, POINT_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,29 +273,98 @@ void TFT_DrawRect(TFT_T *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2
|
||||
TFT_DrawLine(dev, x1, y2, x2, y2); // Bottom side
|
||||
}
|
||||
|
||||
void TFT_DrawCircle(TFT_T *dev, uint16_t x, uint16_t y, uint16_t r) {
|
||||
int a, b, num;
|
||||
a = 0;
|
||||
b = r;
|
||||
while (2 * b * b >= r * r) {
|
||||
TFT_SetPixel(dev, x + a, y - b,POINT_COLOR);
|
||||
TFT_SetPixel(dev, x - a, y - b,POINT_COLOR);
|
||||
TFT_SetPixel(dev, x - a, y + b,POINT_COLOR);
|
||||
TFT_SetPixel(dev, x + a, y + b,POINT_COLOR);
|
||||
TFT_SetPixel(dev, x + b, y + a,POINT_COLOR);
|
||||
TFT_SetPixel(dev, x + b, y - a,POINT_COLOR);
|
||||
TFT_SetPixel(dev, x - b, y - a,POINT_COLOR);
|
||||
TFT_SetPixel(dev, x - b, y + a,POINT_COLOR);
|
||||
void TFT_DrawCircle(TFT_T *dev, uint16_t x0, uint16_t y0, uint16_t radius) {
|
||||
int x = radius;
|
||||
int y = 0;
|
||||
int decision = 1 - x;
|
||||
|
||||
a++;
|
||||
num = (a * a + b * b) - r * r;//计算画的点离圆心的距离
|
||||
if (num > 0) {
|
||||
b--;
|
||||
a--;
|
||||
while (y <= x) {
|
||||
TFT_SetPixel(dev, x0 + x, y0 + y, POINT_COLOR);
|
||||
TFT_SetPixel(dev, x0 + y, y0 + x, POINT_COLOR);
|
||||
TFT_SetPixel(dev, x0 - y, y0 + x, POINT_COLOR);
|
||||
TFT_SetPixel(dev, x0 - x, y0 + y, POINT_COLOR);
|
||||
TFT_SetPixel(dev, x0 - x, y0 - y, POINT_COLOR);
|
||||
TFT_SetPixel(dev, x0 - y, y0 - x, POINT_COLOR);
|
||||
TFT_SetPixel(dev, x0 + y, y0 - x, POINT_COLOR);
|
||||
TFT_SetPixel(dev, x0 + x, y0 - y, POINT_COLOR);
|
||||
|
||||
y++;
|
||||
|
||||
if (decision <= 0) {
|
||||
decision += 2 * y + 1;
|
||||
} else {
|
||||
x--;
|
||||
decision += 2 * (y - x) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define PI 3.14159265359
|
||||
|
||||
#define PI 3.14159265359
|
||||
|
||||
//void TFT_DrawArc(TFT_T *dev, uint16_t x0, uint16_t y0, uint16_t radius, int start_angle, int end_angle) {
|
||||
// int x = radius;
|
||||
// int y = 0;
|
||||
// int decision = 1 - x;
|
||||
// int change = 4 * (1 - x);
|
||||
//
|
||||
// int angle = start_angle;
|
||||
//
|
||||
// while (y <= x) {
|
||||
// if (angle >= start_angle && angle <= end_angle) {
|
||||
// TFT_SetPixel(dev, x0 + x, y0 + y, POINT_COLOR);
|
||||
// TFT_SetPixel(dev, x0 + y, y0 + x, POINT_COLOR);
|
||||
// TFT_SetPixel(dev, x0 - y, y0 + x, POINT_COLOR);
|
||||
// TFT_SetPixel(dev, x0 - x, y0 + y, POINT_COLOR);
|
||||
// TFT_SetPixel(dev, x0 - x, y0 - y, POINT_COLOR);
|
||||
// TFT_SetPixel(dev, x0 - y, y0 - x, POINT_COLOR);
|
||||
// TFT_SetPixel(dev, x0 + y, y0 - x, POINT_COLOR);
|
||||
// TFT_SetPixel(dev, x0 + x, y0 - y, POINT_COLOR);
|
||||
// }
|
||||
//
|
||||
// if (decision <= 0) {
|
||||
// decision += 2 * y + 1;
|
||||
// change += 2;
|
||||
// } else {
|
||||
// x--;
|
||||
// decision += 2 * (y - x) + 1;
|
||||
// change += 4 * ((y - x) + 1);
|
||||
// }
|
||||
//
|
||||
// y++;
|
||||
// angle = (int)(0.5 + (atan((double)y / x) * 180.0 / PI));
|
||||
// }
|
||||
//}
|
||||
|
||||
#define PI 3.14159265359
|
||||
|
||||
void TFT_DrawArc(TFT_T *dev, uint16_t x, uint16_t y, uint16_t radius, int start_angle, int end_angle) {
|
||||
// 修复输入角度范围
|
||||
if (start_angle < 0) {
|
||||
start_angle = 0;
|
||||
} else if (start_angle > 360) {
|
||||
start_angle = 360;
|
||||
}
|
||||
if (end_angle < 0) {
|
||||
end_angle = 0;
|
||||
} else if (end_angle > 360) {
|
||||
end_angle = 360;
|
||||
}
|
||||
double angle;
|
||||
unsigned int cirx, ciry, lastX, lastY;
|
||||
cirx = x;
|
||||
ciry = y;
|
||||
|
||||
angle = start_angle;
|
||||
while (angle <= end_angle) {
|
||||
lastX = cirx + radius * sin(angle * PI / 180);
|
||||
lastY = ciry - radius * cos(angle * PI / 180);
|
||||
TFT_SetPixel(dev, lastX, lastY, POINT_COLOR);
|
||||
angle = angle + 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
void TFT_ShowChar(TFT_T *dev, uint16_t x, uint16_t y, uint8_t chr, uint16_t size,bool mode) {
|
||||
uint16_t i, m, temp, size2, chr1;
|
||||
uint16_t ys = y;
|
||||
@@ -446,6 +554,26 @@ void TFT_DrawCross(TFT_T *dev, uint16_t x, uint16_t y, uint8_t r) {
|
||||
TFT_DrawLine(dev, x, y - r, x, y + r);
|
||||
}
|
||||
|
||||
void TFT_DrawXCross(TFT_T *dev, uint16_t x, uint16_t y, uint8_t r) {
|
||||
TFT_DrawLine(dev, x - r, y - r, x + r, y + r);
|
||||
TFT_DrawLine(dev, x - r, y + r, x + r, y - r);
|
||||
}
|
||||
|
||||
void TFT_DrawRoundedRect(TFT_T *dev, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t radius) {
|
||||
// 画四条直线
|
||||
TFT_DrawLine(dev, x + radius, y, x + width - radius, y); // 上方横线
|
||||
TFT_DrawLine(dev, x + radius, y + height, x + width - radius, y + height); // 下方横线
|
||||
|
||||
TFT_DrawLine(dev, x, y + radius, x, y + height - radius); // 左侧竖线
|
||||
TFT_DrawLine(dev, x + width, y + radius, x + width, y + height - radius); // 右侧竖线
|
||||
|
||||
// 画四个圆角
|
||||
TFT_DrawArc(dev, x + radius, y + radius, radius, 270, 360); // 左上角
|
||||
TFT_DrawArc(dev, x + width - radius, y + radius, radius, 0, 90); // 右上角
|
||||
TFT_DrawArc(dev, x + width - radius, y + height - radius, radius, 90, 180); // 右下角
|
||||
TFT_DrawArc(dev, x + radius, y + height - radius, radius, 180, 270); // 左下角
|
||||
}
|
||||
|
||||
uint16_t invertRGB565(uint16_t color) {
|
||||
// 分离颜色分量
|
||||
uint8_t r = (color >> 11) & 0x1F; // 取出红色分量
|
||||
|
Reference in New Issue
Block a user