【ST NUCLEO-U5A5ZJ-Q开发板测评】6、简单的移植一个GuiLite
<div class='showpostmsg'> 本帖最后由 chrisrh 于 2024-3-11 16:22 编辑<article data-content="[{"type":"block","id":"mSSt-1710137726904","name":"paragraph","data":{},"nodes":[{"type":"text","id":"Tz1b-1710137726901","leaves":[{"text":"基于SPI驱动的LCD,简单的移植GuiLite使用","marks":[]}]}],"state":{}},{"type":"block","id":"MRz1-1710141736024","name":"image","data":{"version":1,"url":"https://note.youdao.com/yws/res/b/WEBRESOURCEc1b4cb70551ad92d168fc166440dd1eb","width":673,"height":583,"fromIdentity":""},"nodes":[],"state":{"loading":false,"renderSource":"https://note.youdao.com/yws/res/b/WEBRESOURCEc1b4cb70551ad92d168fc166440dd1eb","initialSize":{"width":673,"height":583}}},{"type":"block","id":"clRv-1710141830393","name":"paragraph","data":{},"nodes":[{"type":"text","id":"HXvI-1710141830394","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"CkY0-1710141832198","name":"image","data":{"version":1,"url":"https://note.youdao.com/yws/res/4/WEBRESOURCE9936971f2a9e6828deea533392d90c14","width":850,"height":396,"fromIdentity":""},"nodes":[],"state":{"loading":false,"renderSource":"https://note.youdao.com/yws/res/4/WEBRESOURCE9936971f2a9e6828deea533392d90c14","initialSize":{"width":850,"height":396}}},{"type":"block","id":"Kw1t-1710141784394","name":"image","data":{"version":1,"url":"https://note.youdao.com/yws/res/7/WEBRESOURCE99959b2caed8f2ab6071c02b3ff58b97","width":592,"height":667,"fromIdentity":""},"nodes":[],"state":{"loading":false,"renderSource":"https://note.youdao.com/yws/res/7/WEBRESOURCE99959b2caed8f2ab6071c02b3ff58b97","initialSize":{"width":592,"height":667}}},{"type":"block","id":"j5Jc-1710138769195","name":"paragraph","data":{},"nodes":[{"type":"text","id":"vdBF-1710138769193","leaves":[{"text":"生成工程,添加LCD驱动代码","marks":[]}]}],"state":{}},{"type":"block","id":"mEO0-1710142460115","name":"heading","data":{"level":"h3","style":{}},"nodes":[{"type":"text","id":"ezac-1710142460114","leaves":[{"text":"main.h","marks":[]}]}],"state":{}},{"type":"block","id":"Kh8X-1710141868430","name":"paragraph","data":{},"nodes":[{"type":"text","id":"eMgo-1710141868429","leaves":[{"text":"在main.h中添加LCD-IO的宏定义","marks":[]}]}],"state":{}}]">
<p>基于SPI驱动的LCD,简单的移植GuiLite使用</p>
<p> </p>
<p> </p>
<p> </p>
<p>生成工程,添加LCD驱动代码</p>
<p>main.h</p>
<p>在main.h中添加LCD_IO的宏定义</p>
<pre>
<code class="language-cpp">#define LCD_BL_SETHAL_GPIO_WritePin(LCD_BL_GPIO_Port, LCD_BL_Pin, GPIO_PIN_SET)//BL
#define LCD_CS_SETHAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET)//CS
#define LCD_RS_SET HAL_GPIO_WritePin(LCD_DC_GPIO_Port, LCD_DC_Pin, GPIO_PIN_SET) //RS
#define LCD_RST_SET HAL_GPIO_WritePin(LCD_RST_GPIO_Port, LCD_RST_Pin, GPIO_PIN_SET)//RST
#define LCD_BL_CLRHAL_GPIO_WritePin(LCD_BL_GPIO_Port, LCD_BL_Pin, GPIO_PIN_RESET)//BL
#define LCD_CS_CLRHAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_RESET)//CS
#define LCD_RS_CLR HAL_GPIO_WritePin(LCD_DC_GPIO_Port, LCD_DC_Pin, GPIO_PIN_RESET)//RS
#define LCD_RST_CLR HAL_GPIO_WritePin(LCD_RST_GPIO_Port, LCD_RST_Pin, GPIO_PIN_RESET)//RST</code></pre>
<article data-content="[{"type":"block","id":"8GW5-1710138769377","name":"heading","data":{"level":"h3","style":{}},"nodes":[{"type":"text","id":"OfXz-1710138769375","leaves":[{"text":"lcd.h","marks":[]}]}],"state":{}},{"type":"block","id":"ToMC-1710142504198","name":"paragraph","data":{},"nodes":[{"type":"text","id":"1cpA-1710142504197","leaves":[{"text":"LCD的头文件lcd.h,之前把gui和test都扔这里面了,这次删去···","marks":[]}]}],"state":{}}]">
<p>lcd.h</p>
<p>LCD的头文件lcd.h,之前偷懒把gui和test都扔这里面了,程序太多了,这次删去···</p>
</article>
<pre>
<code class="language-cpp">#ifndef __LCD_H
#define __LCD_H
#include "stdlib.h"
#include "stm32u5xx_hal.h"
//LCD重要参数集
typedef struct
{
uint16_twidth; //LCD 宽度
uint16_theight; //LCD 高度
uint16_tid; //LCD ID
uint8_t dir; //横屏还是竖屏控制:0,竖屏;1,横屏。
uint16_twramcmd; //开始写gram指令
uint16_tsetxcmd; //设置x坐标指令
uint16_tsetycmd; //设置y坐标指令
uint8_t xoffset;
uint8_t yoffset;
}_lcd_dev;
//LCD参数
extern _lcd_dev lcddev; //管理LCD重要参数
/////////////////////////////////////用户配置区///////////////////////////////////
#define USE_HORIZONTAL 0 //定义液晶屏顺时针旋转方向 0-0度旋转,1-90度旋转,2-180度旋转,3-270度旋转
//////////////////////////////////////////////////////////////////////////////////
//定义LCD的尺寸
#define LCD_W 240
#define LCD_H 320
//TFTLCD部分外要调用的函数
extern uint16_tPOINT_COLOR;//默认红色
extern uint16_tBACK_COLOR; //背景颜色,默认为白色
/*-----------------LCD端口控制定义----------------*/
//QDtech全系列模块采用了三极管控制背光亮灭,用户也可以接PWM调节背光亮度
//直接操作寄存器可以提高LCD刷屏速率
//画笔颜色
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0XF81F
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40 //棕色
#define BRRED 0XFC07 //棕红色
#define GRAY 0X8430 //灰色
#define GRAY0 0xEF7D
#define GRAY1 0x8410 //灰色1 00000 000000 00000
#define GRAY2 0x4208
//GUI颜色
#define DARKBLUE 0X01CF //深蓝色
#define LIGHTBLUE 0X7D7C //浅蓝色
#define GRAYBLUE 0X5458 //灰蓝色
//以上三色为PANEL的颜色
#define LIGHTGREEN 0X841F //浅绿色
#define LIGHTGRAY 0XEF5B //浅灰色(PANNEL)
#define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色
#define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
#define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色)
/*----------SPI引脚控制----------------*/
void SPI_WriteByte(uint8_t Data);
void LCD_Init(void);
void LCD_DisplayOn(void);
void LCD_DisplayOff(void);
void LCD_Clear(uint16_t Color);
void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos);
void LCD_DrawPoint(uint16_t x,uint16_t y);//画点
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void LCD_SetWindows(uint16_t xStar, uint16_t yStar,uint16_t xEnd,uint16_t yEnd);
void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue);
void LCD_WR_DATA(uint8_t data);
void LCD_WriteRAM_Prepare(void);
void LCD_WriteRAM(uint16_t RGB_Code);
uint16_t LCD_ReadRAM(void);
uint16_t LCD_BGR2RGB(uint16_t c);
void LCD_SetParam(void);
void LCD_WriteData_16Bit(uint16_t Data);
void LCD_direction(uint8_t direction);
//////////////////////////////////////////////////////////////////
/*GUI*/
//////////////////////////////////////////////////////////////////
void GUI_DrawPoint(uint16_t x,uint16_t y,uint16_t color);
void LCD_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t color);
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void Draw_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2);
void Fill_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2);
void Draw_Circle(uint16_t x0,uint16_t y0,uint16_t fc,uint8_t r);
void gui_circle(int32_t xc, int32_t yc,uint16_t c,int32_t r, int32_t fill);
#endif
</code></pre>
<article data-content="[{"type":"block","id":"sJvY-1710138769553","name":"heading","data":{"level":"h3","style":{}},"nodes":[{"type":"text","id":"ZNh9-1710138769551","leaves":[{"text":"lcd.c","marks":[]}]}],"state":{}},{"type":"block","id":"dRVm-1710142480577","name":"paragraph","data":{},"nodes":[{"type":"text","id":"iWwZ-1710142480576","leaves":[{"text":"添加lcd.c","marks":[]}]}],"state":{}}]">
<p>lcd.c</p>
<p>添加lcd.c</p>
<pre>
<code class="language-cpp">#include "lcd.h"
#include "stdlib.h"
#include "string.h"
#include "main.h"
//#include "pic.h"
//#include "font.h"
//管理LCD重要参数
//默认为竖屏
_lcd_dev lcddev;
//画笔颜色,背景颜色
uint16_t POINT_COLOR = 0x0000,BACK_COLOR = 0xFFFF;
uint16_t DeviceCode;
uint16_t ColorTab={RED,GREEN,BLUE,YELLOW,BRED};
extern SPI_HandleTypeDef hspi1;
/*****************************************************************************
* <a href="home.php?mod=space&uid=32621" target="_blank">@name </a> :void LCD_WR_REG(u8 data)
* <a href="home.php?mod=space&uid=311857" target="_blank">@date </a> :2018-08-09
* <a href="home.php?mod=space&uid=665173" target="_blank">@FUNCTION </a> :Write an 8-bit command to the LCD screen
* @parameters :data:Command value to be written
* @retvalue :None
******************************************************************************/
void LCD_WR_REG(uint8_t data)
{
LCD_CS_CLR;
LCD_RS_CLR;
SPI_WriteByte(data);
LCD_CS_SET;
}
/*****************************************************************************
* @name :void LCD_WR_DATA(u8 data)
* @date :2018-08-09
* @function :Write an 8-bit data to the LCD screen
* @parameters :data:data value to be written
* @retvalue :None
******************************************************************************/
void LCD_WR_DATA(uint8_t data)
{
LCD_CS_CLR;
LCD_RS_SET;
SPI_WriteByte(data);
LCD_CS_SET;
}
/*****************************************************************************
* @name :void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue)
* @date :2018-08-09
* @function :Write data into registers
* @parameters :LCD_Reg:Register address
LCD_RegValue:Data to be written
* @retvalue :None
******************************************************************************/
void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
{
LCD_WR_REG(LCD_Reg);
LCD_WR_DATA(LCD_RegValue);
}
/*****************************************************************************
* @name :void LCD_WriteRAM_Prepare(void)
* @date :2018-08-09
* @function :Write GRAM
* @parameters :None
* @retvalue :None
******************************************************************************/
void LCD_WriteRAM_Prepare(void)
{
LCD_WR_REG(lcddev.wramcmd);
}
/*****************************************************************************
* @name :void Lcd_WriteData_16Bit(u16 Data)
* @date :2018-08-09
* @function :Write an 16-bit command to the LCD screen
* @parameters :Data:Data to be written
* @retvalue :None
******************************************************************************/
void LCD_WriteData_16Bit(uint16_t Data)
{
LCD_CS_CLR;
LCD_RS_SET;
SPI_WriteByte(Data>>8);
SPI_WriteByte(Data);
LCD_CS_SET;
}
/*****************************************************************************
* @name :void LCD_DrawPoint(u16 x,u16 y)
* @date :2018-08-09
* @function :Write a pixel data at a specified location
* @parameters :x:the x coordinate of the pixel
y:the y coordinate of the pixel
* @retvalue :None
******************************************************************************/
void LCD_DrawPoint(uint16_t x,uint16_t y)
{
LCD_SetCursor(x,y);//设置光标位置
LCD_WriteData_16Bit(POINT_COLOR);
}
/*****************************************************************************
* @name :void LCD_Clear(u16 Color)
* @date :2018-08-09
* @function :Full screen filled LCD screen
* @parameters :color:Filled color
* @retvalue :None
******************************************************************************/
void LCD_Clear(uint16_t Color)
{
uint32_t i,m;
LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);
LCD_CS_CLR;
LCD_RS_SET;
for(i=0;i<lcddev.height;i++)
{
for(m=0;m<lcddev.width;m++)
{
SPI_WriteByte(Color>>8);
SPI_WriteByte(Color);
}
}
LCD_CS_SET;
}
/*****************************************************************************
* @name :void LCD_GPIOInit(void)
* @date :2018-08-09
* @function :Initialization LCD screen GPIO
* @parameters :None
* @retvalue :None
******************************************************************************/
void LCD_GPIOInit(void)
{
// GPIO_InitTypeDefGPIO_InitStructure;
// __HAL_RCC_GPIOD_CLK_ENABLE(); //使能GPIOB时钟
//
// GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH; //高速
// GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; //推挽输出
// GPIO_InitStructure.Pull = GPIO_PULLUP; //上拉
//
// GPIO_InitStructure.Pin = LCD_BL_PIN;
// HAL_GPIO_Init(LCD_BL_PORT, &GPIO_InitStructure);//初始化BL引脚
//
// GPIO_InitStructure.Pin = LCD_CS_PIN;
// HAL_GPIO_Init(LCD_CS_PORT, &GPIO_InitStructure);//初始化CS引脚
//
// GPIO_InitStructure.Pin = LCD_RS_PIN;
// HAL_GPIO_Init(LCD_RS_PORT, &GPIO_InitStructure);//初始化RS引脚
//
// GPIO_InitStructure.Pin = LCD_RST_PIN;
// HAL_GPIO_Init(LCD_RST_PORT, &GPIO_InitStructure);//初始化RST引脚
//
//默认所有的引脚都拉高
LCD_BL_SET;
LCD_CS_SET;
LCD_RS_SET;
LCD_RST_SET;
}
/*****************************************************************************
* @name :void LCD_RESET(void)
* @date :2018-08-09
* @function :Reset LCD screen
* @parameters :None
* @retvalue :None
******************************************************************************/
void LCD_RESET(void)
{
LCD_RST_CLR;
HAL_Delay(20);
LCD_RST_SET;
HAL_Delay(20);
}
/*****************************************************************************
* @name :void LCD_RESET(void)
* @date :2018-08-09
* @function :Initialization LCD screen
* @parameters :None
* @retvalue :None
******************************************************************************/
void LCD_Init(void)
{
// SPI_GPIO_Init(); //硬件SPI1初始化
// SPI_SCLK_SET;
// SPI_MOSI_SET;
LCD_GPIOInit();//LCD GPIO初始化
LCD_RESET(); //LCD 复位
//************* ST7789 IPS初始化**********//
LCD_WR_REG(0x36);
LCD_WR_DATA(0x00);
LCD_WR_REG(0x3A);
LCD_WR_DATA(0x05);
LCD_WR_REG(0xB2);
LCD_WR_DATA(0x0C);
LCD_WR_DATA(0x0C);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x33);
LCD_WR_DATA(0x33);
LCD_WR_REG(0xB7);
LCD_WR_DATA(0x35);
LCD_WR_REG(0xBB);
LCD_WR_DATA(0x17);
LCD_WR_REG(0xC0);
LCD_WR_DATA(0x2C);
LCD_WR_REG(0xC2);
LCD_WR_DATA(0x01);
LCD_WR_REG(0xC3);
LCD_WR_DATA(0x12);
LCD_WR_REG(0xC4);
LCD_WR_DATA(0x20);
LCD_WR_REG(0xC6);
LCD_WR_DATA(0x0F);
LCD_WR_REG(0xD0);
LCD_WR_DATA(0xA4);
LCD_WR_DATA(0xA1);
LCD_WR_REG(0xE0);
LCD_WR_DATA(0xD0);
LCD_WR_DATA(0x04);
LCD_WR_DATA(0x0D);
LCD_WR_DATA(0x11);
LCD_WR_DATA(0x13);
LCD_WR_DATA(0x2B);
LCD_WR_DATA(0x3F);
LCD_WR_DATA(0x54);
LCD_WR_DATA(0x4C);
LCD_WR_DATA(0x18);
LCD_WR_DATA(0x0D);
LCD_WR_DATA(0x0B);
LCD_WR_DATA(0x1F);
LCD_WR_DATA(0x23);
LCD_WR_REG(0xE1);
LCD_WR_DATA(0xD0);
LCD_WR_DATA(0x04);
LCD_WR_DATA(0x0C);
LCD_WR_DATA(0x11);
LCD_WR_DATA(0x13);
LCD_WR_DATA(0x2C);
LCD_WR_DATA(0x3F);
LCD_WR_DATA(0x44);
LCD_WR_DATA(0x51);
LCD_WR_DATA(0x2F);
LCD_WR_DATA(0x1F);
LCD_WR_DATA(0x1F);
LCD_WR_DATA(0x20);
LCD_WR_DATA(0x23);
LCD_WR_REG(0x21);
LCD_WR_REG(0x11);
//Delay (120);
LCD_WR_REG(0x29);
LCD_direction(USE_HORIZONTAL);//设置LCD显示方向
LCD_BL_SET;//点亮背光
LCD_Clear(WHITE);//清全屏白色
}
/*****************************************************************************
* @name :void LCD_SetWindows(u16 xStar, u16 yStar,u16 xEnd,u16 yEnd)
* @date :2018-08-09
* @function :Setting LCD display window
* @parameters :xStar:the bebinning x coordinate of the LCD display window
yStar:the bebinning y coordinate of the LCD display window
xEnd:the endning x coordinate of the LCD display window
yEnd:the endning y coordinate of the LCD display window
* @retvalue :None
******************************************************************************/
void LCD_SetWindows(uint16_t xStar, uint16_t yStar,uint16_t xEnd,uint16_t yEnd)
{
LCD_WR_REG(lcddev.setxcmd);
LCD_WR_DATA((xStar+lcddev.xoffset)>>8);
LCD_WR_DATA(xStar+lcddev.xoffset);
LCD_WR_DATA((xEnd+lcddev.xoffset)>>8);
LCD_WR_DATA(xEnd+lcddev.xoffset);
LCD_WR_REG(lcddev.setycmd);
LCD_WR_DATA((yStar+lcddev.yoffset)>>8);
LCD_WR_DATA(yStar+lcddev.yoffset);
LCD_WR_DATA((yEnd+lcddev.yoffset)>>8);
LCD_WR_DATA(yEnd+lcddev.yoffset);
LCD_WriteRAM_Prepare(); //开始写入GRAM
}
/*****************************************************************************
* @name :void LCD_SetCursor(u16 Xpos, u16 Ypos)
* @date :2018-08-09
* @function :Set coordinate value
* @parameters :Xpos:thex coordinate of the pixel
Ypos:they coordinate of the pixel
* @retvalue :None
******************************************************************************/
void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
LCD_SetWindows(Xpos,Ypos,Xpos,Ypos);
}
/*****************************************************************************
* @name :void LCD_direction(u8 direction)
* @date :2018-08-09
* @function :Setting the display direction of LCD screen
* @parameters :direction:0-0 degree
1-90 degree
2-180 degree
3-270 degree
* @retvalue :None
******************************************************************************/
void LCD_direction(uint8_t direction)
{
lcddev.setxcmd=0x2A;
lcddev.setycmd=0x2B;
lcddev.wramcmd=0x2C;
lcddev.dir = direction%4;
switch(lcddev.dir){
case 0:
lcddev.width=LCD_W;
lcddev.height=LCD_H;
lcddev.xoffset=0;
lcddev.yoffset=0;
LCD_WriteReg(0x36,0);//BGR==1,MY==0,MX==0,MV==0
break;
case 1:
lcddev.width=LCD_H;
lcddev.height=LCD_W;
lcddev.xoffset=0;
lcddev.yoffset=0;
LCD_WriteReg(0x36,(1<<6)|(1<<5));//BGR==1,MY==1,MX==0,MV==1
break;
case 2:
lcddev.width=LCD_W;
lcddev.height=LCD_H;
lcddev.xoffset=0;
lcddev.yoffset=122;
LCD_WriteReg(0x36,(1<<6)|(1<<7));//BGR==1,MY==0,MX==0,MV==0
break;
case 3:
lcddev.width=LCD_H;
lcddev.height=LCD_W;
lcddev.xoffset=122;
lcddev.yoffset=0;
LCD_WriteReg(0x36,(1<<7)|(1<<5));//BGR==1,MY==1,MX==0,MV==1
break;
default:break;
}
}
/*****************************************************************************
* @name :voidSPI_WriteByte(u8 Data)
* @date :2018-08-09
* @function :Write a byte of data using STM32's Software SPI
* @parameters :Data:Data to be written
* @retvalue :None
******************************************************************************/
//void SPI_WriteByte(uint8_t Data)
//{
// uint8_t i=0;
// for(i=8;i>0;i--)
// {
// if(Data&0x80)
// SPI_MOSI_SET; //输出数据
// else
// SPI_MOSI_CLR;
// SPI_SCLK_CLR;
// SPI_SCLK_SET;
// Data<<=1;
// }
//}
void SPI_WriteByte(uint8_t Data)
{
HAL_SPI_Transmit(&hspi1,&Data,1,1);
// HAL_Delay(10);
}
//////////////////////////////////////////////////////////////////
/*GUI*/
//////////////////////////////////////////////////////////////////
/*******************************************************************
* @name :void GUI_DrawPoint(u16 x,u16 y,u16 color)
* @date :2018-08-09
* @function :draw a point in LCD screen
* @parameters :x:the x coordinate of the point
y:the y coordinate of the point
color:the color value of the point
* @retvalue :None
********************************************************************/
void GUI_DrawPoint(uint16_t x,uint16_t y,uint16_t color)
{
LCD_SetCursor(x,y);//设置光标位置
LCD_WriteData_16Bit(color);
}
/*******************************************************************
* @name :void LCD_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 color)
* @date :2018-08-09
* @function :fill the specified area
* @parameters :sx:the bebinning x coordinate of the specified area
sy:the bebinning y coordinate of the specified area
ex:the ending x coordinate of the specified area
ey:the ending y coordinate of the specified area
color:the filled color value
* @retvalue :None
********************************************************************/
void LCD_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t color)
{
uint16_t i,j;
uint16_t width=ex-sx+1; //得到填充的宽度
uint16_t height=ey-sy+1; //高度
LCD_SetWindows(sx,sy,ex,ey);//设置显示窗口
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
LCD_WriteData_16Bit(color); //写入数据
}
LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);//恢复窗口设置为全屏
}
/*******************************************************************
* @name :void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2)
* @date :2018-08-09
* @function :Draw a line between two points
* @parameters :x1:the bebinning x coordinate of the line
y1:the bebinning y coordinate of the line
x2:the ending x coordinate of the line
y2:the ending y coordinate of the line
* @retvalue :None
********************************************************************/
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
uint16_t t;
int32_t xerr=0,yerr=0,delta_x,delta_y,distance;
int32_t incx,incy,uRow,uCol;
delta_x=x2-x1; //计算坐标增量
delta_y=y2-y1;
uRow=x1;
uCol=y1;
if(delta_x>0)incx=1; //设置单步方向
else if(delta_x==0)incx=0;//垂直线
else {incx=-1;delta_x=-delta_x;}
if(delta_y>0)incy=1;
else if(delta_y==0)incy=0;//水平线
else{incy=-1;delta_y=-delta_y;}
if( delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴
else distance=delta_y;
for(t=0;t<=distance+1;t++ )//画线输出
{
LCD_DrawPoint(uRow,uCol);//画点
xerr+=delta_x ;
yerr+=delta_y ;
if(xerr>distance)
{
xerr-=distance;
uRow+=incx;
}
if(yerr>distance)
{
yerr-=distance;
uCol+=incy;
}
}
}
/*****************************************************************************
* @name :void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2)
* @date :2018-08-09
* @function :Draw a rectangle
* @parameters :x1:the bebinning x coordinate of the rectangle
y1:the bebinning y coordinate of the rectangle
x2:the ending x coordinate of the rectangle
y2:the ending y coordinate of the rectangle
* @retvalue :None
******************************************************************************/
void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
LCD_DrawLine(x1,y1,x2,y1);
LCD_DrawLine(x1,y1,x1,y2);
LCD_DrawLine(x1,y2,x2,y2);
LCD_DrawLine(x2,y1,x2,y2);
}
/*****************************************************************************
* @name :void Draw_Triangel(u16 x0,u16 y0,u16 x1,u16 y1,u16 x2,u16 y2)
* @date :2018-08-09
* @function :Draw a triangle at a specified position
* @parameters :x0:the bebinning x coordinate of the triangular edge
y0:the bebinning y coordinate of the triangular edge
x1:the vertex x coordinate of the triangular
y1:the vertex y coordinate of the triangular
x2:the ending x coordinate of the triangular edge
y2:the ending y coordinate of the triangular edge
* @retvalue :None
******************************************************************************/
void Draw_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)
{
LCD_DrawLine(x0,y0,x1,y1);
LCD_DrawLine(x1,y1,x2,y2);
LCD_DrawLine(x2,y2,x0,y0);
}
static void _swap(uint16_t *a, uint16_t *b)
{
uint16_t tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
/*****************************************************************************
* @name :void Fill_Triangel(u16 x0,u16 y0,u16 x1,u16 y1,u16 x2,u16 y2)
* @date :2018-08-09
* @function :filling a triangle at a specified position
* @parameters :x0:the bebinning x coordinate of the triangular edge
y0:the bebinning y coordinate of the triangular edge
x1:the vertex x coordinate of the triangular
y1:the vertex y coordinate of the triangular
x2:the ending x coordinate of the triangular edge
y2:the ending y coordinate of the triangular edge
* @retvalue :None
******************************************************************************/
void Fill_Triangel(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)
{
uint16_t a, b, y, last;
int dx01, dy01, dx02, dy02, dx12, dy12;
long sa = 0;
long sb = 0;
if (y0 > y1)
{
_swap(&y0,&y1);
_swap(&x0,&x1);
}
if (y1 > y2)
{
_swap(&y2,&y1);
_swap(&x2,&x1);
}
if (y0 > y1)
{
_swap(&y0,&y1);
_swap(&x0,&x1);
}
if(y0 == y2)
{
a = b = x0;
if(x1 < a)
{
a = x1;
}
else if(x1 > b)
{
b = x1;
}
if(x2 < a)
{
a = x2;
}
else if(x2 > b)
{
b = x2;
}
LCD_Fill(a,y0,b,y0,POINT_COLOR);
return;
}
dx01 = x1 - x0;
dy01 = y1 - y0;
dx02 = x2 - x0;
dy02 = y2 - y0;
dx12 = x2 - x1;
dy12 = y2 - y1;
if(y1 == y2)
{
last = y1;
}
else
{
last = y1-1;
}
for(y=y0; y<=last; y++)
{
a = x0 + sa / dy01;
b = x0 + sb / dy02;
sa += dx01;
sb += dx02;
if(a > b)
{
_swap(&a,&b);
}
LCD_Fill(a,y,b,y,POINT_COLOR);
}
sa = dx12 * (y - y1);
sb = dx02 * (y - y0);
for(; y<=y2; y++)
{
a = x1 + sa / dy12;
b = x0 + sb / dy02;
sa += dx12;
sb += dx02;
if(a > b)
{
_swap(&a,&b);
}
LCD_Fill(a,y,b,y,POINT_COLOR);
}
}
/*****************************************************************************
* @name :void _draw_circle_8(int xc, int yc, int x, int y, u16 c)
* @date :2018-08-09
* @function :8 symmetry circle drawing algorithm (internal call)
* @parameters :xc:the x coordinate of the Circular center
yc:the y coordinate of the Circular center
x:the x coordinate relative to the Circular center
y:the y coordinate relative to the Circular center
c:the color value of the circle
* @retvalue :None
******************************************************************************/
void _draw_circle_8(int32_t xc, int32_t yc, int32_t x, int32_t y, uint16_t c)
{
GUI_DrawPoint(xc + x, yc + y, c);
GUI_DrawPoint(xc - x, yc + y, c);
GUI_DrawPoint(xc + x, yc - y, c);
GUI_DrawPoint(xc - x, yc - y, c);
GUI_DrawPoint(xc + y, yc + x, c);
GUI_DrawPoint(xc - y, yc + x, c);
GUI_DrawPoint(xc + y, yc - x, c);
GUI_DrawPoint(xc - y, yc - x, c);
}
/*****************************************************************************
* @name :void gui_circle(int xc, int yc,u16 c,int r, int fill)
* @date :2018-08-09
* @function :Draw a circle of specified size at a specified location
* @parameters :xc:the x coordinate of the Circular center
yc:the y coordinate of the Circular center
r:Circular radius
fill:1-filling,0-no filling
* @retvalue :None
******************************************************************************/
void gui_circle(int32_t xc, int32_t yc,uint16_t c,int32_t r, int32_t fill)
{
int32_t x = 0, y = r, yi, d;
d = 3 - 2 * r;
if (fill)
{
// 如果填充(画实心圆)
while (x <= y) {
for (yi = x; yi <= y; yi++)
_draw_circle_8(xc, yc, x, yi, c);
if (d < 0) {
d = d + 4 * x + 6;
} else {
d = d + 4 * (x - y) + 10;
y--;
}
x++;
}
} else
{
// 如果不填充(画空心圆)
while (x <= y) {
_draw_circle_8(xc, yc, x, y, c);
if (d < 0) {
d = d + 4 * x + 6;
} else {
d = d + 4 * (x - y) + 10;
y--;
}
x++;
}
}
}
</code></pre>
<p> </p>
</article>
<article data-content="[{"type":"block","id":"oyKl-1710138769911","name":"heading","data":{"level":"h3","style":{}},"nodes":[{"type":"text","id":"nOBW-1710138769910","leaves":[{"text":"移植GuiLite","marks":[]}]}],"state":{}},{"type":"block","id":"tP6o-1710138770087","name":"paragraph","data":{},"nodes":[{"type":"text","id":"iear-1710138770085","leaves":[{"text":"","marks":[]}]},{"type":"inline","id":"DUst-1710142303617","name":"link","data":{"href":"https://gitee.com/idea4good"},"nodes":[{"type":"text","id":"C6o3-1710142303618","leaves":[{"text":"idea4good (idea4good) - Gitee.com","marks":[]}]}]},{"type":"text","id":"LMgi-1710142303621","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"wuvx-1710137780437","name":"paragraph","data":{},"nodes":[{"type":"text","id":"eRPt-1710137780436","leaves":[{"text":"①、下载GuiLiteSamples,进入待移植的项目,找到UIcode;","marks":[]}]}],"state":{}},{"type":"block","id":"d3uS-1710142613000","name":"image","data":{"version":1,"url":"https://note.youdao.com/yws/res/6/WEBRESOURCE4d1cd8acdddc25e9d1445d6e4763ddd6","width":625,"height":264,"fromIdentity":""},"nodes":[],"state":{"loading":false,"renderSource":"https://note.youdao.com/yws/res/6/WEBRESOURCE4d1cd8acdddc25e9d1445d6e4763ddd6","initialSize":{"width":625,"height":264}}},{"type":"block","id":"RciK-1710137781938","name":"paragraph","data":{},"nodes":[{"type":"text","id":"Zcz4-1710137781936","leaves":[{"text":"②、将需要移植的UIcode添加到工程中,添加UIcode.cpp和GuiLite.h到工程中","marks":[]}]}],"state":{}},{"type":"block","id":"YItw-1710142914987","name":"image","data":{"version":1,"url":"https://note.youdao.com/yws/res/5/WEBRESOURCE7d8cdffca9c4d8e9621a43a797306e65","width":163,"height":256,"fromIdentity":""},"nodes":[],"state":{"loading":false,"renderSource":"https://note.youdao.com/yws/res/5/WEBRESOURCE7d8cdffca9c4d8e9621a43a797306e65","initialSize":{"width":163,"height":256}}},{"type":"block","id":"Zwyv-1710142851388","name":"paragraph","data":{},"nodes":[{"type":"text","id":"rFvA-1710142851386","leaves":[{"text":"③、确认画点函数,GUI_DrawPoint(uint16_t x,uint16_t y,uint16_t color);","marks":[]}]}],"state":{}},{"type":"block","id":"pce3-1710142851629","name":"paragraph","data":{},"nodes":[{"type":"text","id":"Gdgr-1710142851628","leaves":[{"text":"然后在main.c中main函数前添加","marks":[]}]}],"state":{}}]">
<p><strong><span style="color:#e67e22;"><span style="font-size:18px;">移植GuiLite</span></span></strong></p>
<p><a href="https://gitee.com/idea4good">idea4good (idea4good) - Gitee.com</a></p>
<p>①、下载GuiLiteSamples,进入待移植的项目,找到UIcode;</p>
<p> </p>
<p>②、将需要移植的UIcode添加到工程中,添加UIcode.cpp和GuiLite.h到工程中</p>
<p> </p>
<p>③、确认画点函数,GUI_DrawPoint(uint16_t x,uint16_t y,uint16_t color);</p>
<p>然后在main.c中main函数前添加</p>
</article>
<pre>
<code class="language-cpp">void delay_ms(int ms)
{
HAL_Delay(ms);
}
//RGB888/RGB565
//Transfer GuiLite 32 bits color to your LCD color
#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8))
//Encapsulate your LCD driver:
void gfx_draw_pixel(int x, int y, unsigned int rgb)
{
GUI_DrawPoint(x, y, GL_RGB_32_to_16(rgb));
}
//Implement it, if you have more fast solution than drawing pixels one by one.
//void gfx_fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb){}
//UI entry
struct EXTERNAL_GFX_OP
{
void (*draw_pixel)(int x, int y, unsigned int rgb);
void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb);
} my_gfx_op;
extern void startHello3D(void* phy_fb, int width, int height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op);
</code></pre>
<article data-content="[{"type":"block","id":"cF81-1710137782296","name":"paragraph","data":{},"nodes":[{"type":"text","id":"uOj5-1710137782294","leaves":[{"text":"④、在while(1)前添加启动函数","marks":[]}]}],"state":{}}]">
<p>④、在while(1)前添加启动函数</p>
</article>
<pre>
<code class="language-cpp">LCD_Init();
my_gfx_op.draw_pixel = gfx_draw_pixel;
my_gfx_op.fill_rect = NULL;//gfx_fill_rect;
startHello3D(NULL, 240, 320, 2, &my_gfx_op);</code></pre>
<article data-content="[{"type":"block","id":"I59I-1710137782474","name":"paragraph","data":{},"nodes":[{"type":"text","id":"Roo3-1710137782473","leaves":[{"text":"运行并下载工程即可;","marks":[]}]}],"state":{}}]">
<p>运行并下载工程即可;</p>
</article>
<div>f58cd9c9b18039e9bd5fc615f739189c<br />
</div>
<p>93a64536b0e32024b864e3a3a5c8f84a</p>
<div></div>
<article data-content="[{"type":"block","id":"DgRK-1710137784429","name":"paragraph","data":{},"nodes":[{"type":"text","id":"0OlJ-1710137784428","leaves":[{"text":"没有开SPI_DMA,没有用硬件加速,单SPI驱动,比之前在L452Nucleo上的响应要快很多,","marks":[]}]}],"state":{}}]">
<p>没有开SPI_DMA,没有用硬件加速,单SPI驱动,比之前在L452Nucleo上SPI+DMA的响应要快很多,一方面可能是因为系统和spi的主频增加了,另一方面可能是U5的架构吧。后续试下SPI_DMA驱动的效果。</p>
</article>
<p> </p>
</article>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>GuiLite 这个库是新出来的?以前没听说过呢</p>
freebsder 发表于 2024-3-11 19:29
GuiLite 这个库是新出来的?以前没听说过呢
<p>应该有两年多了吧,较轻量和全平台,就一个GuiLite.h头文件,确实是大道至简的存在~</p>
<table>
<thead>
<tr>
<th>Processor</th>
<th>Disk/ROM space</th>
<th>Memory</th>
</tr>
</thead>
<tbody>
<tr>
<td>24 MHZ</td>
<td>29 KB</td>
<td>9 KB</td>
</tr>
</tbody>
</table>
chrisrh 发表于 2024-3-11 23:08
应该有两年多了吧,较轻量和全平台,就一个GuiLite.h头文件,确实是大道至简的存在~
Proc ...
<p>看了代码页,还有游戏,看起来渲染效率蛮高的。</p>
页:
[1]