- 学习目标
- 学习内容
- define LED_ON GPIO_ResetBits(GPIOA,GPIO_Pin_15)
- define LED_OFF GPIO_SetBits(GPIOA,GPIO_Pin_15)
- define OLED_SCLK_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_0)//SDC
- define OLED_SCLK_Set() GPIO_SetBits(GPIOA,GPIO_Pin_0)
- define OLED_SDIN_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_1)//SDA
- define OLED_SDIN_Set() GPIO_SetBits(GPIOA,GPIO_Pin_1)
- define OLED_RST_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_2)//RES
- define OLED_RST_Set() GPIO_SetBits(GPIOA,GPIO_Pin_2)
- define OLED_DC_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_3)//DC
- define OLED_DC_Set() GPIO_SetBits(GPIOA,GPIO_Pin_3)
- define OLED_CS_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_4)//CS
- define OLED_CS_Set() GPIO_SetBits(GPIOA,GPIO_Pin_4)
- define OLED_BLK_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_5)//BLK
- define OLED_BLK_Set() GPIO_SetBits(GPIOA,GPIO_Pin_5)
- ifndef __LCD_H
- define __LCD_H
- include “iot_gpio.h”
- include “iot_gpio_ex.h”
- include “iot_spi.h”
- define USE_HORIZONTAL 0 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏
- if USE_HORIZONTAL==0||USE_HORIZONTAL==1
- define LCD_W 240
- define LCD_H 240
- else
- define LCD_W 240
- define LCD_H 240
- endif
- define u8 unsigned char
- define u16 unsigned int
- define u32 unsigned long
- define SDC IOT_IO_NAME_6
- define SDIN IOT_IO_NAME_8
- define RST IOT_IO_NAME_5
- define DC IOT_IO_NAME_7
- define SDC_FUNC IOT_GPIO_FUNC_GPIO_6_SPI0_CK
- define SDIN_FUNC IOT_GPIO_FUNC_GPIO_8_SPI0_TXD
- define RST_FUNC IOT_GPIO_FUNC_GPIO_5_GPIO
- define DC_FUNC IOT_GPIO_FUNC_GPIO_7_GPIO
- define LCD_PIN_INIT() \
- define ST7789_SPI_INIT() \
- define OLED_SCLK_Set() IoTGpioSetOutputVal(SDC, 1)
- define OLED_SCLK_Clr() IoTGpioSetOutputVal(SDC, 0)
- define OLED_SDIN_Set() IoTGpioSetOutputVal(SDIN, 1);
- define OLED_SDIN_Clr() IoTGpioSetOutputVal(SDIN, 0);
- define OLED_RST_Set() IoTGpioSetOutputVal(RST, 1);
- define OLED_RST_Clr() IoTGpioSetOutputVal(RST, 0);
- define OLED_DC_Set() IoTGpioSetOutputVal(DC, 1);
- define OLED_DC_Clr() IoTGpioSetOutputVal(DC, 0);
- define OLED_CMD 0 //写命令
- define OLED_DATA 1 //写数据
- 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 DARKBLUE 0X01CF //深蓝色
- define LIGHTBLUE 0X7D7C //浅蓝色
- define GRAYBLUE 0X5458 //灰蓝色
- define LIGHTGREEN 0X841F //浅绿色
- define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色
- define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
- define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色)
- endif
- include “lcd_st7789.h”
- define LV_HOR_RES_MAX (240)
- define LV_VER_RES_MAX (240)
- if 1
- ifndef LV_PORT_DISP_H
- define LV_PORT_DISP_H
- ifdef __cplusplus
- endif
- include “lvgl/lvgl.h”
- ifdef __cplusplus
- endif
- endif /LV_PORT_DISP_TEMPL_H/
- endif /Disable/Enable content/
- 练习题
学习目标
- 体会移植流程
-
学习内容
ST7789屏幕驱动
原理图
引脚对应关系: OLED_SCL: GP06
- OLED_SDA: GP08
- OLED_RST: GP05
- OLED_DC: GP07
驱动获取
通过购买渠道获取相关资料:
解压,选择对应的文件夹,我们选择串口,因为我们采用的是单线SPI进行数据传输的。
接着选择可参考的例程,由于我们需要的平台是鸿蒙的,没有提供对应平台的示例代码,因此我们需要通过其他平台的驱动进行移植,我们任选一个即可,在此,我选择的是stm32平台的。
打开分析后,大致可以得出结论:lcd.c
和lcd.h
是驱动文件,有oledfont.h
和bmp.h
这两个文件依赖移植准备
- 将
lcd.h
拷贝到项目中,进行重命名,修改为lcd_st7789.h
- 将
lcd.c
拷贝到项目中,进行重命名,修改为lcd_st7789.c
- 将
oledfont.h
拷贝到项目中 - 将
bmp.h
拷贝到项目中 将官方示例逻辑拷贝到自己项目中,如下:
u8 i, m;
float t = 0;
delay_init(); // 延时函数初始化
NVIC_Configuration(); // 设置NVIC中断分组2:2位抢占优先级,2位响应优先级
Lcd_Init(); // 初始化OLED
LCD_Clear(WHITE);
BACK_COLOR = WHITE;
LED_ON;
while (1)
{
LCD_ShowChinese(10, 0, 0, 32, RED); // 中
LCD_ShowChinese(45, 0, 1, 32, RED); // 景
LCD_ShowChinese(80, 0, 2, 32, RED); // 园
LCD_ShowChinese(115, 0, 3, 32, RED); // 电
LCD_ShowChinese(150, 0, 4, 32, RED); // 子
LCD_ShowChinese(10, 75, 0, 16, RED); // 中
LCD_ShowChinese(45, 75, 1, 16, RED); // 景
LCD_ShowChinese(80, 75, 2, 16, RED); // 园
LCD_ShowChinese(115, 75, 3, 16, RED); // 电
LCD_ShowChinese(150, 75, 4, 16, RED); // 子
LCD_ShowString(10, 35, "2.4 TFT SPI 240*320", RED);
LCD_ShowString(10, 55, "LCD_W:", RED);
LCD_ShowNum(70, 55, LCD_W, 3, RED);
LCD_ShowString(110, 55, "LCD_H:", RED);
LCD_ShowNum(160, 55, LCD_H, 3, RED);
for (i = 0; i < 5; i++)
{
for (m = 0; m < 6; m++)
{
LCD_ShowPicture(0 + m * 40, 120 + i * 40, 39 + m * 40, 159 + i * 40);
}
}
while (1)
{
LCD_ShowNum1(80, 95, t, 5, RED);
t += 0.01;
}
}
驱动初始化修改
lcd_st7789.h
中include
问题。
- 删除
#include "sys.h"
#include "stdlib.h"
引用 - 添加引脚定义:
#define SDC IOT_IO_NAME_6
#define SDIN IOT_IO_NAME_8
#define RST IOT_IO_NAME_5
#define DC IOT_IO_NAME_7
引入gpio相关的头
#include "iot_gpio.h"
#include "iot_gpio_ex.h"
当前平台,gpio功能调用修改 ```c //————————-测试LED端口定义————————
define LED_ON GPIO_ResetBits(GPIOA,GPIO_Pin_15)
define LED_OFF GPIO_SetBits(GPIOA,GPIO_Pin_15)
//————————-OLED端口定义————————
define OLED_SCLK_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_0)//SDC
define OLED_SCLK_Set() GPIO_SetBits(GPIOA,GPIO_Pin_0)
define OLED_SDIN_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_1)//SDA
define OLED_SDIN_Set() GPIO_SetBits(GPIOA,GPIO_Pin_1)
define OLED_RST_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_2)//RES
define OLED_RST_Set() GPIO_SetBits(GPIOA,GPIO_Pin_2)
define OLED_DC_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_3)//DC
define OLED_DC_Set() GPIO_SetBits(GPIOA,GPIO_Pin_3)
define OLED_CS_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_4)//CS
define OLED_CS_Set() GPIO_SetBits(GPIOA,GPIO_Pin_4)
define OLED_BLK_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_5)//BLK
define OLED_BLK_Set() GPIO_SetBits(GPIOA,GPIO_Pin_5)
```c
#define SDC_FUNC IOT_GPIO_FUNC_GPIO_6_GPIO
#define SDIN_FUNC IOT_GPIO_FUNC_GPIO_8_GPIO
#define RST_FUNC IOT_GPIO_FUNC_GPIO_5_GPIO
#define DC_FUNC IOT_GPIO_FUNC_GPIO_7_GPIO
#define OLED_SCLK_Set() IoTGpioSetOutputVal(SDC, 1)
#define OLED_SCLK_Clr() IoTGpioSetOutputVal(SDC, 0)
#define OLED_SDIN_Set() IoTGpioSetOutputVal(SDIN, 1);
#define OLED_SDIN_Clr() IoTGpioSetOutputVal(SDIN, 0);
#define OLED_RST_Set() IoTGpioSetOutputVal(RST, 1);
#define OLED_RST_Clr() IoTGpioSetOutputVal(RST, 0);
#define OLED_DC_Set() IoTGpioSetOutputVal(DC, 1);
#define OLED_DC_Clr() IoTGpioSetOutputVal(DC, 0);
- 去掉当前原理图中没有设计的引脚功能定义
- 修改
delay_ms
实现,替换为usleep#include <unistd.h>
....
usleep(ms * 1000);
- 修改
编写当前平台GPIO初始化逻辑
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE); //使能A端口时钟
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//速度50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化GPIOA
GPIO_SetBits(GPIOA,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_15);
#define LCD_PIN_INIT() \
IoTGpioInit(SDC); \
IoTGpioSetFunc(SDC, SDC_FUNC); \
IoTGpioSetDir(SDC, IOT_GPIO_DIR_OUT); \
IoTGpioInit(SDIN); \
IoTGpioSetFunc(SDIN, SDIN_FUNC); \
IoTGpioSetDir(SDIN, IOT_GPIO_DIR_OUT); \
IoTGpioInit(RST); \
IoTGpioSetFunc(RST, RST_FUNC); \
IoTGpioSetDir(RST, IOT_GPIO_DIR_OUT); \
IoTGpioInit(DC); \
IoTGpioSetFunc(DC, DC_FUNC); \
IoTGpioSetDir(DC, IOT_GPIO_DIR_OUT);
在
Lcd_init()
中调用GPIO初始化void Lcd_Init(void)
{
LCD_PIN_INIT();
......
}
注释
lcd_st7789.c
中没有用到的gpio调用。// OLED_CS_Clr();
......
// OLED_CS_Set();
......
// OLED_BLK_Set();
-
移植出现的问题
当编译通过,烧录运行后,发现屏幕无法显示。
需要怀疑的问题: 移植过程中,GPIO是否初始化正确。
- 示例代码是否有编写。
以上为代码级别的问题,确保无误后,需要怀疑结构性问题。
- 当前移植的驱动,是通过gpio引脚,发送高低电平的方式,模拟spi协议进行LCD屏幕控制。
也就是当前移植的驱动为软实现,软实现受到当前执行效率的限制,可能无法达到屏幕驱动的速率。
SPI硬实现
修改引脚功能
#define SDC_FUNC IOT_GPIO_FUNC_GPIO_6_SPI0_CK
#define SDIN_FUNC IOT_GPIO_FUNC_GPIO_8_SPI0_TXD
SPI初始化
#define ST7789_SPI_INIT() \
IoTSpiCfgInitParam param; \
param.isSlave = 0; \
IoTSpiCfgBasicInfo info; \
info.cpol = IOT_SPI_CFG_CLOCK_CPOL_1; \
info.cpha = IOT_SPI_CFG_CLOCK_CPHA_1; \
info.framMode = IOT_SPI_CFG_FRAM_MODE_MOTOROLA; \
info.dataWidth = IOT_SPI_CFG_DATA_WIDTH_E_8BIT; \
info.endian = IOT_SPI_CFG_ENDIAN_LITTLE; \
info.pad = 31; \
info.freq = 40000000; \
IoTSpiInit(0, param, &info);
在
lcd_st7789.c
的Lcd_init()
初始化中调用void Lcd_Init(void)
{
LCD_PIN_INIT();
LCD_SPI_INIT();
......
}
修改
LCD_Writ_Bus
函数如下void LCD_Writ_Bus(u8 dat)
{
// u8 i;
// // OLED_CS_Clr();
// for(i=0;i<8;i++)
// {
// OLED_SCLK_Clr();
// if(dat&0x80)
// {OLED_SDIN_Set();}
// else
// {OLED_SDIN_Clr();}
// OLED_SCLK_Set();
// dat<<=1;
// }
// // OLED_CS_Set();
IoTSpiHostWrite(0, &dat, 1);
}
完整代码
```c
ifndef __LCD_H
define __LCD_H
include “iot_gpio.h”
include “iot_gpio_ex.h”
include “iot_spi.h”
define USE_HORIZONTAL 0 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏
if USE_HORIZONTAL==0||USE_HORIZONTAL==1
define LCD_W 240
define LCD_H 240
else
define LCD_W 240
define LCD_H 240
endif
define u8 unsigned char
define u16 unsigned int
define u32 unsigned long
define SDC IOT_IO_NAME_6
define SDIN IOT_IO_NAME_8
define RST IOT_IO_NAME_5
define DC IOT_IO_NAME_7
define SDC_FUNC IOT_GPIO_FUNC_GPIO_6_SPI0_CK
define SDIN_FUNC IOT_GPIO_FUNC_GPIO_8_SPI0_TXD
define RST_FUNC IOT_GPIO_FUNC_GPIO_5_GPIO
define DC_FUNC IOT_GPIO_FUNC_GPIO_7_GPIO
define LCD_PIN_INIT() \
IoTGpioInit(SDC); \
IoTGpioSetFunc(SDC, SDC_FUNC); \
IoTGpioSetDir(SDC, IOT_GPIO_DIR_OUT); \
IoTGpioInit(SDIN); \
IoTGpioSetFunc(SDIN, SDIN_FUNC); \
IoTGpioSetDir(SDIN, IOT_GPIO_DIR_OUT); \
IoTGpioInit(RST); \
IoTGpioSetFunc(RST, RST_FUNC); \
IoTGpioSetDir(RST, IOT_GPIO_DIR_OUT); \
IoTGpioInit(DC); \
IoTGpioSetFunc(DC, DC_FUNC); \
IoTGpioSetDir(DC, IOT_GPIO_DIR_OUT);
define ST7789_SPI_INIT() \
IoTSpiCfgInitParam param; \
param.isSlave = 0; \
IoTSpiCfgBasicInfo info; \
info.cpol = IOT_SPI_CFG_CLOCK_CPOL_1; \
info.cpha = IOT_SPI_CFG_CLOCK_CPHA_1; \
info.framMode = IOT_SPI_CFG_FRAM_MODE_MOTOROLA; \
info.dataWidth = IOT_SPI_CFG_DATA_WIDTH_E_8BIT; \
info.endian = IOT_SPI_CFG_ENDIAN_LITTLE; \
info.pad = 31; \
info.freq = 40000000; \
IoTSpiInit(0, param, &info);
define OLED_SCLK_Set() IoTGpioSetOutputVal(SDC, 1)
define OLED_SCLK_Clr() IoTGpioSetOutputVal(SDC, 0)
define OLED_SDIN_Set() IoTGpioSetOutputVal(SDIN, 1);
define OLED_SDIN_Clr() IoTGpioSetOutputVal(SDIN, 0);
define OLED_RST_Set() IoTGpioSetOutputVal(RST, 1);
define OLED_RST_Clr() IoTGpioSetOutputVal(RST, 0);
define OLED_DC_Set() IoTGpioSetOutputVal(DC, 1);
define OLED_DC_Clr() IoTGpioSetOutputVal(DC, 0);
define OLED_CMD 0 //写命令
define OLED_DATA 1 //写数据
extern u16 BACK_COLOR; //背景色
void LCD_Writ_Bus(u8 dat); void LCD_WR_DATA8(u8 dat); void LCD_WR_DATA(u16 dat); void LCD_WR_REG(u8 dat); void LCD_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2); void Lcd_Init(void); void LCD_Clear(u16 Color); void LCD_ShowChinese(u16 x,u16 y,u8 index,u8 size,u16 color); void LCD_DrawPoint(u16 x,u16 y,u16 color); void LCD_DrawPoint_big(u16 x,u16 y,u16 colory); void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color); void LCD_DrawLine(u16 x1,u16 y1,u16 x2,u16 y2,u16 color); void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2,u16 color); void Draw_Circle(u16 x0,u16 y0,u8 r,u16 color); void LCD_ShowChar(u16 x,u16 y,u8 num,u8 mode,u16 color); void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 color); u32 mypow(u8 m,u8 n); void LCD_ShowNum(u16 x,u16 y,u16 num,u8 len,u16 color); void LCD_ShowNum1(u16 x,u16 y,float num,u8 len,u16 color); void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2);
//画笔颜色
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 //灰色
//GUI颜色
define DARKBLUE 0X01CF //深蓝色
define LIGHTBLUE 0X7D7C //浅蓝色
define GRAYBLUE 0X5458 //灰蓝色
//以上三色为PANEL的颜色
define LIGHTGREEN 0X841F //浅绿色
define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色
define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色)
endif
```c
#include "lcd_st7789.h"
#include "oledfont.h"
#include <unistd.h>
#include "bmp.h"
u16 BACK_COLOR; //背景色
/******************************************************************************
函数说明:LCD串行数据写入函数
入口数据:dat 要写入的串行数据
返回值: 无
******************************************************************************/
void LCD_Writ_Bus(u8 dat)
{
// u8 i;
// //OLED_CS_Clr();
// for(i=0;i<8;i++)
// {
// OLED_SCLK_Clr();
// if(dat&0x80) {
// OLED_SDIN_Set();
// }
// else {
// OLED_SDIN_Clr();
// }
// OLED_SCLK_Set();
// dat<<=1;
// }
// //OLED_CS_Set();
IoTSpiHostWrite(0, &dat, 1);
}
/******************************************************************************
函数说明:LCD写入数据
入口数据:dat 写入的数据
返回值: 无
******************************************************************************/
void LCD_WR_DATA8(u8 dat)
{
OLED_DC_Set();//写数据
LCD_Writ_Bus(dat);
}
/******************************************************************************
函数说明:LCD写入数据
入口数据:dat 写入的数据
返回值: 无
******************************************************************************/
void LCD_WR_DATA(u16 dat)
{
OLED_DC_Set();//写数据
LCD_Writ_Bus(dat>>8);
LCD_Writ_Bus(dat);
}
/******************************************************************************
函数说明:LCD写入命令
入口数据:dat 写入的命令
返回值: 无
******************************************************************************/
void LCD_WR_REG(u8 dat)
{
OLED_DC_Clr();//写命令
LCD_Writ_Bus(dat);
}
/******************************************************************************
函数说明:设置起始和结束地址
入口数据:x1,x2 设置列的起始和结束地址
y1,y2 设置行的起始和结束地址
返回值: 无
******************************************************************************/
void LCD_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2)
{
if(USE_HORIZONTAL==0)
{
LCD_WR_REG(0x2a);//列地址设置
LCD_WR_DATA(x1);
LCD_WR_DATA(x2);
LCD_WR_REG(0x2b);//行地址设置
LCD_WR_DATA(y1);
LCD_WR_DATA(y2);
LCD_WR_REG(0x2c);//储存器写
}
else if(USE_HORIZONTAL==1)
{
LCD_WR_REG(0x2a);//列地址设置
LCD_WR_DATA(x1);
LCD_WR_DATA(x2);
LCD_WR_REG(0x2b);//行地址设置
LCD_WR_DATA(y1+80);
LCD_WR_DATA(y2+80);
LCD_WR_REG(0x2c);//储存器写
}
else if(USE_HORIZONTAL==2)
{
LCD_WR_REG(0x2a);//列地址设置
LCD_WR_DATA(x1);
LCD_WR_DATA(x2);
LCD_WR_REG(0x2b);//行地址设置
LCD_WR_DATA(y1);
LCD_WR_DATA(y2);
LCD_WR_REG(0x2c);//储存器写
}
else
{
LCD_WR_REG(0x2a);//列地址设置
LCD_WR_DATA(x1+80);
LCD_WR_DATA(x2+80);
LCD_WR_REG(0x2b);//行地址设置
LCD_WR_DATA(y1);
LCD_WR_DATA(y2);
LCD_WR_REG(0x2c);//储存器写
}
}
/******************************************************************************
函数说明:LCD初始化函数
入口数据:无
返回值: 无
******************************************************************************/
void Lcd_Init(void)
{
LCD_PIN_INIT();
LCD_SPI_INIT();
OLED_RST_Clr();
usleep(20 * 1000);
OLED_RST_Set();
usleep(20 * 1000);
// OLED_BLK_Set();
//************* Start Initial Sequence **********//
LCD_WR_REG(0x36);
if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x00);
else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC0);
else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x70);
else LCD_WR_DATA8(0xA0);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_REG(0xB2);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x33);
LCD_WR_DATA8(0x33);
LCD_WR_REG(0xB7);
LCD_WR_DATA8(0x35);
LCD_WR_REG(0xBB);
LCD_WR_DATA8(0x37);
LCD_WR_REG(0xC0);
LCD_WR_DATA8(0x2C);
LCD_WR_REG(0xC2);
LCD_WR_DATA8(0x01);
LCD_WR_REG(0xC3);
LCD_WR_DATA8(0x12);
LCD_WR_REG(0xC4);
LCD_WR_DATA8(0x20);
LCD_WR_REG(0xC6);
LCD_WR_DATA8(0x0F);
LCD_WR_REG(0xD0);
LCD_WR_DATA8(0xA4);
LCD_WR_DATA8(0xA1);
LCD_WR_REG(0xE0);
LCD_WR_DATA8(0xD0);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x2B);
LCD_WR_DATA8(0x3F);
LCD_WR_DATA8(0x54);
LCD_WR_DATA8(0x4C);
LCD_WR_DATA8(0x18);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0B);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x23);
LCD_WR_REG(0xE1);
LCD_WR_DATA8(0xD0);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x2C);
LCD_WR_DATA8(0x3F);
LCD_WR_DATA8(0x44);
LCD_WR_DATA8(0x51);
LCD_WR_DATA8(0x2F);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x20);
LCD_WR_DATA8(0x23);
LCD_WR_REG(0x21);
LCD_WR_REG(0x11);
//Delay (120);
LCD_WR_REG(0x29);
}
/******************************************************************************
函数说明:LCD清屏函数
入口数据:无
返回值: 无
******************************************************************************/
void LCD_Clear(u16 Color)
{
u16 i,j;
LCD_Address_Set(0,0,LCD_W-1,LCD_H-1);
for(i=0;i<LCD_W;i++)
{
for (j=0;j<LCD_H;j++)
{
LCD_WR_DATA(Color);
}
}
}
/******************************************************************************
函数说明:LCD显示汉字
入口数据:x,y 起始坐标
index 汉字的序号
size 字号
返回值: 无
******************************************************************************/
void LCD_ShowChinese(u16 x,u16 y,u8 index,u8 size,u16 color)
{
u8 i,j;
u8 *temp,size1;
if(size==16){temp=Hzk16;}//选择字号
if(size==32){temp=Hzk32;}
LCD_Address_Set(x,y,x+size-1,y+size-1); //设置一个汉字的区域
size1=size*size/8;//一个汉字所占的字节
temp+=index*size1;//写入的起始位置
for(j=0;j<size1;j++)
{
for(i=0;i<8;i++)
{
if((*temp&(1<<i))!=0)//从数据的低位开始读
{
LCD_WR_DATA(color);//点亮
}
else
{
LCD_WR_DATA(BACK_COLOR);//不点亮
}
}
temp++;
}
}
/******************************************************************************
函数说明:LCD显示汉字
入口数据:x,y 起始坐标
返回值: 无
******************************************************************************/
void LCD_DrawPoint(u16 x,u16 y,u16 color)
{
LCD_Address_Set(x,y,x,y);//设置光标位置
LCD_WR_DATA(color);
}
/******************************************************************************
函数说明:LCD画一个大的点
入口数据:x,y 起始坐标
返回值: 无
******************************************************************************/
void LCD_DrawPoint_big(u16 x,u16 y,u16 color)
{
LCD_Fill(x-1,y-1,x+1,y+1,color);
}
/******************************************************************************
函数说明:在指定区域填充颜色
入口数据:xsta,ysta 起始坐标
xend,yend 终止坐标
返回值: 无
******************************************************************************/
void LCD_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color)
{
u16 i,j;
LCD_Address_Set(xsta,ysta,xend,yend); //设置光标位置
for(i=ysta;i<=yend;i++)
{
for(j=xsta;j<=xend;j++)LCD_WR_DATA(color);//设置光标位置
}
}
/******************************************************************************
函数说明:画线
入口数据:x1,y1 起始坐标
x2,y2 终止坐标
返回值: 无
******************************************************************************/
void LCD_DrawLine(u16 x1,u16 y1,u16 x2,u16 y2,u16 color)
{
u16 t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int 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_x;}
if(delta_x>delta_y)distance=delta_x; //选取基本增量坐标轴
else distance=delta_y;
for(t=0;t<distance+1;t++)
{
LCD_DrawPoint(uRow,uCol,color);//画点
xerr+=delta_x;
yerr+=delta_y;
if(xerr>distance)
{
xerr-=distance;
uRow+=incx;
}
if(yerr>distance)
{
yerr-=distance;
uCol+=incy;
}
}
}
/******************************************************************************
函数说明:画矩形
入口数据:x1,y1 起始坐标
x2,y2 终止坐标
返回值: 无
******************************************************************************/
void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2,u16 color)
{
LCD_DrawLine(x1,y1,x2,y1,color);
LCD_DrawLine(x1,y1,x1,y2,color);
LCD_DrawLine(x1,y2,x2,y2,color);
LCD_DrawLine(x2,y1,x2,y2,color);
}
/******************************************************************************
函数说明:画圆
入口数据:x0,y0 圆心坐标
r 半径
返回值: 无
******************************************************************************/
void Draw_Circle(u16 x0,u16 y0,u8 r,u16 color)
{
int a,b;
int di;
a=0;b=r;
while(a<=b)
{
LCD_DrawPoint(x0-b,y0-a,color); //3
LCD_DrawPoint(x0+b,y0-a,color); //0
LCD_DrawPoint(x0-a,y0+b,color); //1
LCD_DrawPoint(x0-a,y0-b,color); //2
LCD_DrawPoint(x0+b,y0+a,color); //4
LCD_DrawPoint(x0+a,y0-b,color); //5
LCD_DrawPoint(x0+a,y0+b,color); //6
LCD_DrawPoint(x0-b,y0+a,color); //7
a++;
if((a*a+b*b)>(r*r))//判断要画的点是否过远
{
b--;
}
}
}
/******************************************************************************
函数说明:显示字符
入口数据:x,y 起点坐标
num 要显示的字符
mode 1叠加方式 0非叠加方式
返回值: 无
******************************************************************************/
void LCD_ShowChar(u16 x,u16 y,u8 num,u8 mode,u16 color)
{
u8 temp;
u8 pos,t;
u16 x0=x;
if(x>LCD_W-16||y>LCD_H-16)return; //设置窗口
num=num-' ';//得到偏移后的值
LCD_Address_Set(x,y,x+8-1,y+16-1); //设置光标位置
if(!mode) //非叠加方式
{
for(pos=0;pos<16;pos++)
{
temp=asc2_1608[(u16)num*16+pos]; //调用1608字体
for(t=0;t<8;t++)
{
if(temp&0x01)LCD_WR_DATA(color);
else LCD_WR_DATA(BACK_COLOR);
temp>>=1;
x++;
}
x=x0;
y++;
}
}else//叠加方式
{
for(pos=0;pos<16;pos++)
{
temp=asc2_1608[(u16)num*16+pos]; //调用1608字体
for(t=0;t<8;t++)
{
if(temp&0x01)LCD_DrawPoint(x+t,y+pos,color);//画一个点
temp>>=1;
}
}
}
}
/******************************************************************************
函数说明:显示字符串
入口数据:x,y 起点坐标
*p 字符串起始地址
返回值: 无
******************************************************************************/
void LCD_ShowString(u16 x,u16 y,const u8 *p,u16 color)
{
while(*p!='\0')
{
if(x>LCD_W-16){x=0;y+=16;}
if(y>LCD_H-16){y=x=0;LCD_Clear(RED);}
LCD_ShowChar(x,y,*p,0,color);
x+=8;
p++;
}
}
/******************************************************************************
函数说明:显示数字
入口数据:m底数,n指数
返回值: 无
******************************************************************************/
u32 mypow(u8 m,u8 n)
{
u32 result=1;
while(n--)result*=m;
return result;
}
/******************************************************************************
函数说明:显示数字
入口数据:x,y 起点坐标
num 要显示的数字
len 要显示的数字个数
返回值: 无
******************************************************************************/
void LCD_ShowNum(u16 x,u16 y,u16 num,u8 len,u16 color)
{
u8 t,temp;
u8 enshow=0;
for(t=0;t<len;t++)
{
temp=(num/mypow(10,len-t-1))%10;
if(enshow==0&&t<(len-1))
{
if(temp==0)
{
LCD_ShowChar(x+8*t,y,' ',0,color);
continue;
}else enshow=1;
}
LCD_ShowChar(x+8*t,y,temp+48,0,color);
}
}
/******************************************************************************
函数说明:显示小数
入口数据:x,y 起点坐标
num 要显示的小数
len 要显示的数字个数
返回值: 无
******************************************************************************/
void LCD_ShowNum1(u16 x,u16 y,float num,u8 len,u16 color)
{
u8 t,temp;
u8 enshow=0;
u16 num1;
num1=num*100;
for(t=0;t<len;t++)
{
temp=(num1/mypow(10,len-t-1))%10;
if(t==(len-2))
{
LCD_ShowChar(x+8*(len-2),y,'.',0,color);
t++;
len+=1;
}
LCD_ShowChar(x+8*t,y,temp+48,0,color);
}
}
/******************************************************************************
函数说明:显示40x40图片
入口数据:x,y 起点坐标
返回值: 无
******************************************************************************/
void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2)
{
int i;
LCD_Address_Set(x1,y1,x2,y2);
for(i=0;i<1600;i++)
{
LCD_WR_DATA8(image[i*2+1]);
LCD_WR_DATA8(image[i*2]);
}
}
//////////////////////////////////////////////////////////////////////////////////
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
//中景园电子
//店铺地址:http://shop73023976.taobao.com/?spm=2013.1.0.0.M4PqC2
//
// 文 件 名 : main.c
// 版 本 号 : v2.0
// 作 者 : HuangKai
// 生成日期 : 2014-0101
// 最近修改 :
// 功能描述 : OLED 4接口演示例程(stm32系列)
// 说明:
// ----------------------------------------------------------------
// GND 电源地
// VCC 接5V或3.3v电源
// D0 接CLK(SCL)
// D1 接MOSI(SDA)
// RES 接PD4
// DC 接PD5
// CS 接PD3
// ----------------------------------------------------------------
// 修改历史 :
// 日 期 :
// 作 者 : HuangKai
// 修改内容 : 创建文件
//版权所有,盗版必究。
//Copyright(C) 中景园电子2014/3/16
//All rights reserved
//******************************************************************************/
#ifndef __BMP_H
#define __BMP_H
#define u8 unsigned char
const u8 image[]={ /* 0X00,0X10,0X28,0X00,0X28,0X00,0X01,0X1B,*/
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0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,0X82,0XD8,0XC3,0XB0,0X04,0X81,
0X45,0X61,0X46,0X51,0X86,0X49,0X86,0X49,0X46,0X41,0X45,0X41,0X45,0X41,0X45,0X41,
0X05,0X49,0X04,0X61,0X82,0X90,0X41,0XB0,0X00,0XD0,0X00,0XC8,0X00,0XA8,0X00,0XA8,
0X00,0XB8,0X41,0X58,0X82,0X10,0X82,0X10,0XB2,0X94,0XBE,0XF7,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XBE,0XF7,0XCF,0X7B,0X82,0X10,0X04,0X21,0X86,0X29,0X86,0X41,0X04,0X99,
0X40,0XE8,0X41,0XF8,0X86,0XF9,0XCB,0XFA,0X49,0XFA,0X82,0XF8,0X00,0XF8,0X00,0XF0,
0X00,0XE8,0X41,0XD8,0X41,0XD0,0X41,0XC0,0X41,0XC0,0X41,0XC0,0X41,0XC0,0X41,0XC8,
0X00,0XD0,0X00,0XE0,0X00,0XE0,0X00,0XD8,0X00,0XD0,0X00,0XB8,0X00,0XA8,0X41,0X88,
0X82,0X48,0X82,0X10,0X82,0X10,0X00,0X00,0X45,0X29,0X79,0XCE,0XFF,0XFF,0XFF,0XFF,
0XBE,0XF7,0XF3,0X9C,0X82,0X10,0XC3,0X18,0X45,0X29,0X86,0X31,0XC7,0X31,0X30,0X7C,
0XF3,0XDC,0X86,0XE1,0X00,0XF0,0X00,0XF8,0X41,0XF8,0X41,0XF8,0X00,0XF8,0X00,0XF8,
0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,
0X00,0XE8,0X00,0XE0,0X00,0XE0,0X00,0XD8,0X00,0XC8,0X41,0XA0,0X8A,0X9A,0X0C,0X63,
0X04,0X11,0X82,0X10,0X82,0X10,0X41,0X08,0X00,0X00,0X4D,0X6B,0X7D,0XEF,0XFF,0XFF,
0XFB,0XDE,0X08,0X42,0X42,0X10,0X45,0X29,0X86,0X31,0X86,0X31,0X49,0X4A,0X38,0XBE,
0XFF,0XFF,0X38,0XD6,0X86,0XA9,0X00,0XC8,0X00,0XE0,0X00,0XF0,0X00,0XF8,0X00,0XF8,
0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF8,0X00,0XF0,0X00,0XF0,
0X00,0XE8,0X00,0XE0,0X00,0XD0,0XC3,0X98,0X8A,0X8A,0XB2,0XA4,0XBA,0XC6,0XF7,0XB5,
0X08,0X42,0X41,0X08,0X82,0X10,0X41,0X08,0X00,0X00,0X45,0X29,0XF7,0XBD,0XFF,0XFF,
0X71,0X8C,0X41,0X08,0X04,0X21,0X45,0X29,0X86,0X31,0X86,0X31,0X0C,0X63,0X3C,0XE7,
0XFF,0XFF,0X79,0XD6,0X46,0XB9,0X00,0XE0,0X42,0XC8,0X82,0XA8,0X82,0XB0,0X41,0XD8,
0X82,0XE8,0X82,0XF0,0X41,0XE8,0X41,0XE8,0X41,0XE8,0X41,0XF0,0X41,0XE8,0X41,0XD8,
0X04,0XC1,0X08,0X92,0X4D,0X8B,0X34,0XA5,0XFB,0XC6,0XFB,0XD6,0XBA,0XCE,0X3C,0XE7,
0X30,0X84,0XC3,0X18,0X41,0X08,0X41,0X08,0X00,0X00,0X41,0X08,0XCF,0X7B,0X7D,0XEF,
0X49,0X4A,0X00,0X00,0X04,0X21,0X45,0X29,0X46,0X31,0X86,0X31,0X30,0X84,0XFF,0XFF,
0XFF,0XF7,0XF7,0XDD,0X09,0XDA,0X83,0XF8,0X01,0XF0,0X42,0XC0,0X82,0X98,0X49,0X9A,
0XF3,0XB4,0XF3,0XCC,0X71,0XBC,0X8E,0XBB,0X8E,0XBB,0X30,0XBC,0X71,0XBC,0XF3,0XBC,
0XB6,0XBD,0XFB,0XCE,0XBE,0XE7,0X7D,0XE7,0X3B,0XDF,0XBA,0XD6,0X79,0XCE,0XFB,0XDE,
0X75,0XAD,0X86,0X31,0X41,0X08,0X41,0X08,0X00,0X00,0X00,0X00,0X49,0X4A,0XFB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2,0XBB,0X22,0XB4,0X82,0XA3,0X42,0X93,0XC3,0X7A,
0X85,0X62,0X0B,0X63,0X71,0X84,0XB6,0XB5,0X79,0XCE,0X79,0XC6,0XB5,0XAD,0X70,0X94,
0X4A,0X8B,0X06,0X83,0X04,0X93,0X04,0X9B,0X43,0X9B,0X43,0X9B,0X43,0X93,0X04,0X83,
0X08,0X73,0X8D,0X73,0XB3,0X94,0X79,0XCE,0X7D,0XEF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X3C,0XDF,0X38,0XBE,
0X75,0XB5,0X33,0XA5,0X33,0XA5,0XF3,0X9C,0XF3,0X9C,0XF3,0X9C,0XF3,0X94,0XF3,0X9C,
0X35,0XA5,0XF8,0XBD,0XFB,0XDE,0XBE,0XF7,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X7E,0XEF,
0XBB,0XD6,0XF8,0XBD,0XB6,0XAD,0X75,0XAD,0X34,0XA5,0X33,0X9D,0X34,0X9D,0X35,0XA5,
0XB7,0XAD,0X79,0XC6,0X3C,0XE7,0XBE,0XF7,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
};
#endif
#ifndef __OLEDFONT_H
#define __OLEDFONT_H
//常用ASCII表
//偏移量32
//ASCII字符集
//偏移量32
//大小:12*6
#define u8 unsigned char
#define u16 unsigned int
#define u32 unsigned long
/************************************6*8的点阵************************************/
/****************************************32*32的点阵************************************/
u8 Hzk32[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x01,0x00,
0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,
0x10,0x80,0x01,0x0C,0xF0,0xFF,0xFF,0x0F,0x30,0x80,0x01,0x04,0x30,0x80,0x01,0x04,
0x30,0x80,0x01,0x04,0x30,0x80,0x01,0x04,0x30,0x80,0x01,0x04,0x30,0x80,0x01,0x04,
0x30,0x80,0x01,0x04,0x30,0x80,0x01,0x04,0xF0,0xFF,0xFF,0x07,0x30,0x80,0x01,0x04,
0x30,0x80,0x01,0x04,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,
0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,
0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,/*"中",0*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,
0x00,0xFF,0xFF,0x01,0x00,0x03,0x80,0x01,0x00,0x03,0x80,0x01,0x00,0xFF,0xFF,0x01,
0x00,0x03,0x80,0x01,0x00,0x03,0x80,0x01,0x00,0xFF,0xFF,0x01,0x00,0x81,0x81,0x00,
0x00,0x00,0x03,0x00,0x00,0x00,0x03,0x1C,0xFC,0xFF,0xFF,0x3F,0x00,0x00,0x40,0x00,
0x00,0x03,0xC0,0x01,0x00,0xFF,0xFF,0x01,0x00,0x03,0xC0,0x00,0x00,0x03,0xC0,0x00,
0x00,0x03,0xC0,0x00,0x00,0xFF,0xFF,0x00,0x00,0x01,0x41,0x00,0x00,0x04,0x01,0x00,
0x00,0x0E,0x71,0x00,0x00,0x07,0x81,0x01,0x80,0x01,0x01,0x07,0x60,0x00,0x01,0x0E,
0x18,0x98,0x01,0x1C,0x04,0xE0,0x01,0x18,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,/*"景",1*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xF0,0xFF,0xFF,0x1F,
0x30,0x00,0x00,0x0C,0x30,0x00,0x00,0x0C,0x30,0x00,0x10,0x0C,0x30,0xFE,0x3F,0x0C,
0x30,0x04,0x00,0x0C,0x30,0x00,0x00,0x0C,0x30,0x00,0x00,0x0C,0x30,0x00,0x00,0x0C,
0x30,0x00,0xC0,0x0C,0xF0,0xFF,0xFF,0x0D,0x30,0x30,0x06,0x0E,0x30,0x30,0x06,0x0C,
0x30,0x10,0x06,0x0C,0x30,0x10,0x06,0x0C,0x30,0x10,0x06,0x0C,0x30,0x18,0x86,0x0C,
0x30,0x18,0x86,0x0C,0x30,0x08,0x06,0x0D,0x30,0x0C,0x86,0x0D,0x30,0x06,0xEE,0x0F,
0x30,0x02,0xFC,0x0D,0x30,0x01,0x00,0x0C,0xF0,0x00,0x00,0x0C,0x30,0x00,0x00,0x0C,
0xF0,0xFF,0xFF,0x0F,0x30,0x00,0x00,0x0C,0x10,0x00,0x00,0x04,0x00,0x00,0x00,0x00,/*"园",2*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0xC0,0x01,0x00,
0x00,0xC0,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0xC0,0x00,0x00,
0xE0,0xFF,0xFF,0x03,0x60,0xC0,0x00,0x03,0x60,0xC0,0x00,0x03,0x60,0xC0,0x00,0x03,
0x60,0xC0,0x00,0x03,0x60,0xC0,0x00,0x03,0x60,0xC0,0x00,0x03,0xE0,0xFF,0xFF,0x03,
0x60,0xC0,0x00,0x03,0x60,0xC0,0x00,0x03,0x60,0xC0,0x00,0x03,0x60,0xC0,0x00,0x03,
0x60,0xC0,0x00,0x03,0xE0,0xFF,0xFF,0x03,0x60,0xC0,0x00,0x01,0x60,0xC0,0x00,0x00,
0x00,0xC0,0x00,0x08,0x00,0xC0,0x00,0x10,0x00,0xC0,0x00,0x10,0x00,0xC0,0x00,0x18,
0x00,0xC0,0x01,0x38,0x00,0x80,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"电",3*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xC0,0xFF,0xFF,0x07,0x00,0x00,0x80,0x07,0x00,0x00,0xC0,0x00,0x00,0x00,0x60,0x00,
0x00,0x00,0x18,0x00,0x00,0x00,0x0C,0x00,0x00,0x80,0x03,0x00,0x00,0x80,0x03,0x00,
0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x08,0x00,0x80,0x01,0x1C,0xFC,0xFF,0xFF,0x3F,
0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,
0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,
0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,
0x00,0xFC,0x01,0x00,0x00,0xE0,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,/*"子",4*/};
const u8 asc2_1608[1520]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x18,0x18,0x00,0x00,
0x00,0x48,0x6C,0x24,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x24,0x24,0x24,0x7F,0x12,0x12,0x12,0x7F,0x12,0x12,0x12,0x00,0x00,
0x00,0x00,0x08,0x1C,0x2A,0x2A,0x0A,0x0C,0x18,0x28,0x28,0x2A,0x2A,0x1C,0x08,0x08,
0x00,0x00,0x00,0x22,0x25,0x15,0x15,0x15,0x2A,0x58,0x54,0x54,0x54,0x22,0x00,0x00,
0x00,0x00,0x00,0x0C,0x12,0x12,0x12,0x0A,0x76,0x25,0x29,0x11,0x91,0x6E,0x00,0x00,
0x00,0x06,0x06,0x04,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00,
0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00,
0x00,0x00,0x00,0x00,0x08,0x08,0x6B,0x1C,0x1C,0x6B,0x08,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x08,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x04,0x03,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00,
0x00,0x00,0x80,0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,0x02,0x02,0x00,
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
0x00,0x00,0x00,0x08,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00,
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x20,0x20,0x10,0x08,0x04,0x42,0x7E,0x00,0x00,
0x00,0x00,0x00,0x3C,0x42,0x42,0x20,0x18,0x20,0x40,0x40,0x42,0x22,0x1C,0x00,0x00,
0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x22,0x7E,0x20,0x20,0x78,0x00,0x00,
0x00,0x00,0x00,0x7E,0x02,0x02,0x02,0x1A,0x26,0x40,0x40,0x42,0x22,0x1C,0x00,0x00,
0x00,0x00,0x00,0x38,0x24,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x24,0x18,0x00,0x00,
0x00,0x00,0x00,0x7E,0x22,0x22,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00,
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x64,0x58,0x40,0x40,0x24,0x1C,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x04,
0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00,
0x00,0x00,0x00,0x3C,0x42,0x42,0x46,0x40,0x20,0x10,0x10,0x00,0x18,0x18,0x00,0x00,
0x00,0x00,0x00,0x1C,0x22,0x5A,0x55,0x55,0x55,0x55,0x2D,0x42,0x22,0x1C,0x00,0x00,
0x00,0x00,0x00,0x08,0x08,0x18,0x14,0x14,0x24,0x3C,0x22,0x42,0x42,0xE7,0x00,0x00,
0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x1E,0x22,0x42,0x42,0x42,0x22,0x1F,0x00,0x00,
0x00,0x00,0x00,0x7C,0x42,0x42,0x01,0x01,0x01,0x01,0x01,0x42,0x22,0x1C,0x00,0x00,
0x00,0x00,0x00,0x1F,0x22,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1F,0x00,0x00,
0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x42,0x42,0x3F,0x00,0x00,
0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x02,0x02,0x07,0x00,0x00,
0x00,0x00,0x00,0x3C,0x22,0x22,0x01,0x01,0x01,0x71,0x21,0x22,0x22,0x1C,0x00,0x00,
0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,
0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00,
0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x11,0x0F,
0x00,0x00,0x00,0x77,0x22,0x12,0x0A,0x0E,0x0A,0x12,0x12,0x22,0x22,0x77,0x00,0x00,
0x00,0x00,0x00,0x07,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x7F,0x00,0x00,
0x00,0x00,0x00,0x77,0x36,0x36,0x36,0x36,0x2A,0x2A,0x2A,0x2A,0x2A,0x6B,0x00,0x00,
0x00,0x00,0x00,0xE3,0x46,0x46,0x4A,0x4A,0x52,0x52,0x52,0x62,0x62,0x47,0x00,0x00,
0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x22,0x1C,0x00,0x00,
0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x42,0x3E,0x02,0x02,0x02,0x02,0x07,0x00,0x00,
0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x4D,0x53,0x32,0x1C,0x60,0x00,
0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x3E,0x12,0x12,0x22,0x22,0x42,0xC7,0x00,0x00,
0x00,0x00,0x00,0x7C,0x42,0x42,0x02,0x04,0x18,0x20,0x40,0x42,0x42,0x3E,0x00,0x00,
0x00,0x00,0x00,0x7F,0x49,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00,
0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,
0x00,0x00,0x00,0xE7,0x42,0x42,0x22,0x24,0x24,0x14,0x14,0x18,0x08,0x08,0x00,0x00,
0x00,0x00,0x00,0x6B,0x49,0x49,0x49,0x49,0x55,0x55,0x36,0x22,0x22,0x22,0x00,0x00,
0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00,
0x00,0x00,0x00,0x77,0x22,0x22,0x14,0x14,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00,
0x00,0x00,0x00,0x7E,0x21,0x20,0x10,0x10,0x08,0x04,0x04,0x42,0x42,0x3F,0x00,0x00,
0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00,
0x00,0x00,0x02,0x02,0x04,0x04,0x08,0x08,0x08,0x10,0x10,0x20,0x20,0x20,0x40,0x40,
0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00,
0x00,0x38,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0x00,0x06,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x78,0x44,0x42,0x42,0xFC,0x00,0x00,
0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x26,0x1A,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x02,0x02,0x02,0x44,0x38,0x00,0x00,
0x00,0x00,0x00,0x60,0x40,0x40,0x40,0x78,0x44,0x42,0x42,0x42,0x64,0xD8,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x02,0x02,0x42,0x3C,0x00,0x00,
0x00,0x00,0x00,0xF0,0x88,0x08,0x08,0x7E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x22,0x22,0x1C,0x02,0x3C,0x42,0x42,0x3C,
0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,
0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00,
0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x38,0x20,0x20,0x20,0x20,0x20,0x20,0x22,0x1E,
0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x72,0x12,0x0A,0x16,0x12,0x22,0x77,0x00,0x00,
0x00,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x92,0x92,0x92,0x92,0x92,0xB7,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3B,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x26,0x42,0x42,0x42,0x22,0x1E,0x02,0x07,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x44,0x42,0x42,0x42,0x44,0x78,0x40,0xE0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x4C,0x04,0x04,0x04,0x04,0x1F,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x42,0x02,0x3C,0x40,0x42,0x3E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x3E,0x08,0x08,0x08,0x08,0x08,0x30,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x42,0x42,0x42,0x42,0x62,0xDC,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x08,0x08,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEB,0x49,0x49,0x55,0x55,0x22,0x22,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x24,0x18,0x18,0x18,0x24,0x6E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x18,0x08,0x08,0x07,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x22,0x10,0x08,0x08,0x44,0x7E,0x00,0x00,
0x00,0xC0,0x20,0x20,0x20,0x20,0x20,0x10,0x20,0x20,0x20,0x20,0x20,0x20,0xC0,0x00,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
0x00,0x06,0x08,0x08,0x08,0x08,0x08,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x06,0x00,
0x0C,0x32,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
u8 Hzk16[]={
0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xFC,0x1F,0x84,0x10,0x84,0x10,0x84,0x10,
0x84,0x10,0x84,0x10,0xFC,0x1F,0x84,0x10,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,/*"中",0*/
0xF8,0x0F,0x08,0x08,0xF8,0x0F,0x08,0x08,0xF8,0x0F,0x80,0x00,0xFF,0x7F,0x00,0x00,
0xF8,0x0F,0x08,0x08,0x08,0x08,0xF8,0x0F,0x80,0x00,0x84,0x10,0xA2,0x20,0x40,0x00,/*"景",1*/
0x00,0x00,0xFE,0x3F,0x02,0x20,0xF2,0x27,0x02,0x20,0x02,0x20,0xFA,0x2F,0x22,0x21,
0x22,0x21,0x22,0x21,0x12,0x29,0x12,0x29,0x0A,0x2E,0x02,0x20,0xFE,0x3F,0x02,0x20,/*"园",2*/
0x80,0x00,0x80,0x00,0x80,0x00,0xFC,0x1F,0x84,0x10,0x84,0x10,0x84,0x10,0xFC,0x1F,
0x84,0x10,0x84,0x10,0x84,0x10,0xFC,0x1F,0x84,0x50,0x80,0x40,0x80,0x40,0x00,0x7F,/*"电",3*/
0x00,0x00,0xFE,0x1F,0x00,0x08,0x00,0x04,0x00,0x02,0x80,0x01,0x80,0x00,0xFF,0x7F,
0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xA0,0x00,0x40,0x00,/*"子",4*/
0x10,0x08,0xB8,0x08,0x0F,0x09,0x08,0x09,0x08,0x08,0xBF,0x08,0x08,0x09,0x1C,0x09,
0x2C,0x08,0x0A,0x78,0xCA,0x0F,0x09,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,/*"科",5*/
0x08,0x04,0x08,0x04,0x08,0x04,0xC8,0x7F,0x3F,0x04,0x08,0x04,0x08,0x04,0xA8,0x3F,
0x18,0x21,0x0C,0x11,0x0B,0x12,0x08,0x0A,0x08,0x04,0x08,0x0A,0x8A,0x11,0x64,0x60,/*"技",6*/
};
#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "cmsis_os2.h"
#include "ohos_init.h"
#include "lcd_st7789.h"
static void show(void)
{
u8 i, m;
float t = 0;
Lcd_Init(); // 初始化OLED
LCD_Clear(WHITE);
BACK_COLOR = WHITE;
while (1)
{
LCD_ShowChinese(10, 0, 0, 32, RED); // 中
LCD_ShowChinese(45, 0, 1, 32, RED); // 景
LCD_ShowChinese(80, 0, 2, 32, RED); // 园
LCD_ShowChinese(115, 0, 3, 32, RED); // 电
LCD_ShowChinese(150, 0, 4, 32, RED); // 子
LCD_ShowChinese(10, 75, 0, 16, RED); // 中
LCD_ShowChinese(45, 75, 1, 16, RED); // 景
LCD_ShowChinese(80, 75, 2, 16, RED); // 园
LCD_ShowChinese(115, 75, 3, 16, RED); // 电
LCD_ShowChinese(150, 75, 4, 16, RED); // 子
LCD_ShowString(10, 35, "2.4 TFT SPI 240*320", RED);
LCD_ShowString(10, 55, "LCD_W:", RED);
LCD_ShowNum(70, 55, LCD_W, 3, RED);
LCD_ShowString(110, 55, "LCD_H:", RED);
LCD_ShowNum(160, 55, LCD_H, 3, RED);
for (i = 0; i < 5; i++)
{
for (m = 0; m < 6; m++)
{
LCD_ShowPicture(0 + m * 40, 120 + i * 40, 39 + m * 40, 159 + i * 40);
}
}
while (1)
{
LCD_ShowNum1(80, 95, t, 5, RED);
t += 0.01;
}
}
}
static void main(void)
{
osThreadAttr_t attr;
attr.name = "st7789";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = 1024 * 8;
attr.priority = 25;
// Create the Thread1 task
if (osThreadNew((osThreadFunc_t)show, NULL, &attr) == NULL)
{
printf("Failed to create say hello Thread!\n");
}
}
APP_FEATURE_INIT(main);
OHOS移植LVGL流程
LVGL源码下载
此案例采用lvgl 8.2.0版本,源码下载地址:https://github.com/lvgl/lvgl
首先,切换lvgl版本,如下图所示:
切换完成后,版本信息不再是master
而是v8.2.0
,接着就可以下载这个版本了。如下图:
LVGL子系统构建
来到开发板目录,当前开发板目录为device/board/itcast/genkipi/
,我们之前已经在这个开发板中,构建了services
子集服务。我们可以把LVGL放到这个子集中去。
构建流程如下:
- 在services下新建
LVGL
文件夹。并且新建BUILD.gn
- 在
LVGL
目录下新建lvgl
和lvgl_driver
目录,并且在每个目录创建BUILD.gn
文件 编辑几个
BUILD.gn
文件group("LVGL") {
deps = [
"lvgl",
"lvgl_driver"
]
}
static_library("lvgl") {
sources = [
]
include_dirs = [
]
}
static_library("lvgl_driver") {
sources = [
]
include_dirs = [
]
}
group("genkipi_services") {
deps = [
"wifi:genkipi_wifi",
"LVGL"
]
}
LVGL源码移植
将
lvgl-8.2.0
源码文件夹下的src
,example
,lvgl.h
,lv_conf_template.h
拷贝到services/LVGL/lvgl
目录中。- 编辑
lvgl/BUILD.gn
,将src
下的c文件配置到sources中去。 ```c static_library(“lvgl”) { sources = [ “src\core\lv_disp.c”, “src\core\lv_event.c”, “src\core\lv_group.c”, “src\core\lv_indev.c”, “src\core\lv_indev_scroll.c”, “src\core\lv_obj.c”, “src\core\lv_obj_class.c”, “src\core\lv_obj_draw.c”, “src\core\lv_obj_pos.c”, “src\core\lv_obj_scroll.c”, “src\core\lv_obj_style.c”, “src\core\lv_obj_style_gen.c”, “src\core\lv_obj_tree.c”, “src\core\lv_refr.c”, “src\core\lv_theme.c”, “src\draw\lv_draw.c”, “src\draw\lv_draw_arc.c”, “src\draw\lv_draw_img.c”, “src\draw\lv_draw_label.c”, “src\draw\lv_draw_line.c”, “src\draw\lv_draw_mask.c”, “src\draw\lv_draw_rect.c”, “src\draw\lv_draw_triangle.c”, “src\draw\lv_img_buf.c”, “src\draw\lv_img_cache.c”, “src\draw\lv_img_decoder.c”, “src\draw\nxp_pxp\lv_gpu_nxp_pxp.c”, “src\draw\nxp_pxp\lv_gpu_nxp_pxp_osa.c”, “src\draw\nxp_vglite\lv_gpu_nxp_vglite.c”, “src\draw\sdl\lv_draw_sdl.c”, “src\draw\sdl\lv_draw_sdl_arc.c”, “src\draw\sdl\lv_draw_sdl_bg.c”, “src\draw\sdl\lv_draw_sdl_composite.c”, “src\draw\sdl\lv_draw_sdl_img.c”, “src\draw\sdl\lv_draw_sdl_label.c”, “src\draw\sdl\lv_draw_sdl_line.c”, “src\draw\sdl\lv_draw_sdl_mask.c”, “src\draw\sdl\lv_draw_sdl_polygon.c”, “src\draw\sdl\lv_draw_sdl_rect.c”, “src\draw\sdl\lv_draw_sdl_stack_blur.c”, “src\draw\sdl\lv_draw_sdl_texture_cache.c”, “src\draw\sdl\lv_draw_sdl_utils.c”, “src\draw\stm32_dma2d\lv_gpu_stm32_dma2d.c”, “src\draw\sw\lv_draw_sw.c”, “src\draw\sw\lv_draw_sw_arc.c”, “src\draw\sw\lv_draw_sw_blend.c”, “src\draw\sw\lv_draw_sw_dither.c”, “src\draw\sw\lv_draw_sw_gradient.c”, “src\draw\sw\lv_draw_sw_img.c”, “src\draw\sw\lv_draw_sw_letter.c”, “src\draw\sw\lv_draw_sw_line.c”, “src\draw\sw\lv_draw_sw_polygon.c”, “src\draw\sw\lv_draw_sw_rect.c”, “src\extra\layouts\flex\lv_flex.c”, “src\extra\layouts\grid\lv_grid.c”, “src\extra\libs\bmp\lv_bmp.c”, “src\extra\libs\ffmpeg\lv_ffmpeg.c”, “src\extra\libs\freetype\lv_freetype.c”, “src\extra\libs\fsdrv\lv_fs_fatfs.c”, “src\extra\libs\fsdrv\lv_fs_posix.c”, “src\extra\libs\fsdrv\lv_fs_stdio.c”, “src\extra\libs\fsdrv\lv_fs_win32.c”, “src\extra\libs\gif\gifdec.c”, “src\extra\libs\gif\lv_gif.c”, “src\extra\libs\png\lodepng.c”, “src\extra\libs\png\lv_png.c”, “src\extra\libs\qrcode\lv_qrcode.c”, “src\extra\libs\qrcode\qrcodegen.c”, “src\extra\libs\rlottie\lv_rlottie.c”, “src\extra\libs\sjpg\lv_sjpg.c”, “src\extra\libs\sjpg\tjpgd.c”, “src\extra\lv_extra.c”, “src\extra\others\gridnav\lv_gridnav.c”, “src\extra\others\monkey\lv_monkey.c”, “src\extra\others\snapshot\lv_snapshot.c”, “src\extra\themes\basic\lv_theme_basic.c”, “src\extra\themes\default\lv_theme_default.c”, “src\extra\themes\mono\lv_theme_mono.c”, “src\extra\widgets\animimg\lv_animimg.c”, “src\extra\widgets\calendar\lv_calendar.c”, “src\extra\widgets\calendar\lv_calendar_header_arrow.c”, “src\extra\widgets\calendar\lv_calendar_header_dropdown.c”, “src\extra\widgets\chart\lv_chart.c”, “src\extra\widgets\colorwheel\lv_colorwheel.c”, “src\extra\widgets\imgbtn\lv_imgbtn.c”, “src\extra\widgets\keyboard\lv_keyboard.c”, “src\extra\widgets\led\lv_led.c”, “src\extra\widgets\list\lv_list.c”, “src\extra\widgets\menu\lv_menu.c”, “src\extra\widgets\meter\lv_meter.c”, “src\extra\widgets\msgbox\lv_msgbox.c”, “src\extra\widgets\span\lv_span.c”, “src\extra\widgets\spinbox\lv_spinbox.c”, “src\extra\widgets\spinner\lv_spinner.c”, “src\extra\widgets\tabview\lv_tabview.c”, “src\extra\widgets\tileview\lv_tileview.c”, “src\extra\widgets\win\lv_win.c”, “src\font\lv_font.c”, “src\font\lv_font_dejavu_16_persian_hebrew.c”, “src\font\lv_font_fmt_txt.c”, “src\font\lv_font_loader.c”, “src\font\lv_font_montserrat_10.c”, “src\font\lv_font_montserrat_12.c”, “src\font\lv_font_montserrat_12_subpx.c”, “src\font\lv_font_montserrat_14.c”, “src\font\lv_font_montserrat_16.c”, “src\font\lv_font_montserrat_18.c”, “src\font\lv_font_montserrat_20.c”, “src\font\lv_font_montserrat_22.c”, “src\font\lv_font_montserrat_24.c”, “src\font\lv_font_montserrat_26.c”, “src\font\lv_font_montserrat_28.c”, “src\font\lv_font_montserrat_28_compressed.c”, “src\font\lv_font_montserrat_30.c”, “src\font\lv_font_montserrat_32.c”, “src\font\lv_font_montserrat_34.c”, “src\font\lv_font_montserrat_36.c”, “src\font\lv_font_montserrat_38.c”, “src\font\lv_font_montserrat_40.c”, “src\font\lv_font_montserrat_42.c”, “src\font\lv_font_montserrat_44.c”, “src\font\lv_font_montserrat_46.c”, “src\font\lv_font_montserrat_48.c”, “src\font\lv_font_montserrat_8.c”, “src\font\lv_font_simsun_16_cjk.c”, “src\font\lv_font_unscii_16.c”, “src\font\lv_font_unscii_8.c”, “src\hal\lv_hal_disp.c”, “src\hal\lv_hal_indev.c”, “src\hal\lv_hal_tick.c”, “src\misc\lv_anim.c”, “src\misc\lv_anim_timeline.c”, “src\misc\lv_area.c”, “src\misc\lv_async.c”, “src\misc\lv_bidi.c”, “src\misc\lv_color.c”, “src\misc\lv_fs.c”, “src\misc\lv_gc.c”, “src\misc\lv_ll.c”, “src\misc\lv_log.c”, “src\misc\lv_lru.c”, “src\misc\lv_math.c”, “src\misc\lv_mem.c”, “src\misc\lv_printf.c”, “src\misc\lv_style.c”, “src\misc\lv_style_gen.c”, “src\misc\lv_templ.c”, “src\misc\lv_timer.c”, “src\misc\lv_tlsf.c”, “src\misc\lv_txt.c”, “src\misc\lv_txt_ap.c”, “src\misc\lv_utils.c”, “src\widgets\lv_arc.c”, “src\widgets\lv_bar.c”, “src\widgets\lv_btn.c”, “src\widgets\lv_btnmatrix.c”, “src\widgets\lv_canvas.c”, “src\widgets\lv_checkbox.c”, “src\widgets\lv_dropdown.c”, “src\widgets\lv_img.c”, “src\widgets\lv_label.c”, “src\widgets\lv_line.c”, “src\widgets\lv_objx_templ.c”, “src\widgets\lv_roller.c”, “src\widgets\lv_slider.c”, “src\widgets\lv_switch.c”, “src\widgets\lv_table.c”, “src\widgets\lv_textarea.c”, ] include_dirs = [ ] }
3. 拷贝`lvgl\lv_conf_template.h`文件,放到`LVGL`目录中,并且重命名为`lv_conf.h`
<a name="CWa7B"></a>
#### ST7789驱动移植
<a name="J0Syr"></a>
##### 裁剪驱动
将ST7789驱动(`lcd_st7789.h`和`lcd_st7789.c`)拷贝到`lvgl_driver`目录下。<br />对驱动进行裁剪,我们在开发过程中,只会用到填充点函数作为LVGL的底层操作,所以,其他绘制函数都可以剔除掉。<br />裁剪的原则:
1. 剔除不用的函数
2. 防止函数和文件重名
裁剪后的代码为:
```c
#ifndef __LVGL_LCD_ST7789_H__
#define __LVGL_LCD_ST7789_H__
#include "iot_gpio.h"
#include "iot_gpio_ex.h"
#include "iot_spi.h"
#define USE_HORIZONTAL 0 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏
#if USE_HORIZONTAL==0||USE_HORIZONTAL==1
#define ST7789_W 240
#define ST7789_H 240
#else
#define ST7789_W 240
#define ST7789_H 240
#endif
#define u8 unsigned char
#define u16 unsigned int
#define u32 unsigned long
#define SDC IOT_IO_NAME_6
#define SDIN IOT_IO_NAME_8
#define RST IOT_IO_NAME_5
#define DC IOT_IO_NAME_7
#define SDC_FUNC IOT_GPIO_FUNC_GPIO_6_SPI0_CK
#define SDIN_FUNC IOT_GPIO_FUNC_GPIO_8_SPI0_TXD
#define RST_FUNC IOT_GPIO_FUNC_GPIO_5_GPIO
#define DC_FUNC IOT_GPIO_FUNC_GPIO_7_GPIO
#define ST7789_PIN_INIT() \
IoTGpioInit(SDC); \
IoTGpioSetFunc(SDC, SDC_FUNC); \
IoTGpioSetDir(SDC, IOT_GPIO_DIR_OUT); \
IoTGpioInit(SDIN); \
IoTGpioSetFunc(SDIN, SDIN_FUNC); \
IoTGpioSetDir(SDIN, IOT_GPIO_DIR_OUT); \
IoTGpioInit(RST); \
IoTGpioSetFunc(RST, RST_FUNC); \
IoTGpioSetDir(RST, IOT_GPIO_DIR_OUT); \
IoTGpioInit(DC); \
IoTGpioSetFunc(DC, DC_FUNC); \
IoTGpioSetDir(DC, IOT_GPIO_DIR_OUT);
#define ST7789_SPI_INIT() \
IoTSpiCfgInitParam param; \
param.isSlave = 0; \
IoTSpiCfgBasicInfo info; \
info.cpol = IOT_SPI_CFG_CLOCK_CPOL_1; \
info.cpha = IOT_SPI_CFG_CLOCK_CPHA_1; \
info.framMode = IOT_SPI_CFG_FRAM_MODE_MOTOROLA; \
info.dataWidth = IOT_SPI_CFG_DATA_WIDTH_E_8BIT; \
info.endian = IOT_SPI_CFG_ENDIAN_LITTLE; \
info.pad = 31; \
info.freq = 40000000; \
IoTSpiInit(0, param, &info);
#define OLED_SCLK_Set() IoTGpioSetOutputVal(SDC, 1)
#define OLED_SCLK_Clr() IoTGpioSetOutputVal(SDC, 0)
#define OLED_SDIN_Set() IoTGpioSetOutputVal(SDIN, 1);
#define OLED_SDIN_Clr() IoTGpioSetOutputVal(SDIN, 0);
#define OLED_RST_Set() IoTGpioSetOutputVal(RST, 1);
#define OLED_RST_Clr() IoTGpioSetOutputVal(RST, 0);
#define OLED_DC_Set() IoTGpioSetOutputVal(DC, 1);
#define OLED_DC_Clr() IoTGpioSetOutputVal(DC, 0);
#define OLED_CMD 0 //写命令
#define OLED_DATA 1 //写数据
// extern u16 BACK_COLOR; //背景色
void ST7789_Writ_Bus(u8 dat);
void ST7789_WR_DATA8(u8 dat);
void ST7789_WR_DATA(u16 dat);
void ST7789_WR_REG(u8 dat);
void ST7789_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2);
void ST7789_Init(void);
void ST7789_Clear(u16 Color);
void ST7789_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color);
//画笔颜色
#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 //灰色
//GUI颜色
#define DARKBLUE 0X01CF //深蓝色
#define LIGHTBLUE 0X7D7C //浅蓝色
#define GRAYBLUE 0X5458 //灰蓝色
//以上三色为PANEL的颜色
#define LIGHTGREEN 0X841F //浅绿色
#define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色
#define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
#define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色)
#endif
#include "lcd_st7789.h"
#include <unistd.h>
// u16 BACK_COLOR; //背景色
/******************************************************************************
函数说明:LCD串行数据写入函数
入口数据:dat 要写入的串行数据
返回值: 无
******************************************************************************/
void ST7789_Writ_Bus(u8 dat)
{
// u8 i;
// //OLED_CS_Clr();
// for(i=0;i<8;i++)
// {
// OLED_SCLK_Clr();
// if(dat&0x80) {
// OLED_SDIN_Set();
// }
// else {
// OLED_SDIN_Clr();
// }
// OLED_SCLK_Set();
// dat<<=1;
// }
// //OLED_CS_Set();
IoTSpiHostWrite(0, &dat, 1);
}
/******************************************************************************
函数说明:LCD写入数据
入口数据:dat 写入的数据
返回值: 无
******************************************************************************/
void ST7789_WR_DATA8(u8 dat)
{
OLED_DC_Set();//写数据
ST7789_Writ_Bus(dat);
}
/******************************************************************************
函数说明:LCD写入数据
入口数据:dat 写入的数据
返回值: 无
******************************************************************************/
void ST7789_WR_DATA(u16 dat)
{
OLED_DC_Set();//写数据
ST7789_Writ_Bus(dat>>8);
ST7789_Writ_Bus(dat);
}
/******************************************************************************
函数说明:LCD写入命令
入口数据:dat 写入的命令
返回值: 无
******************************************************************************/
void ST7789_WR_REG(u8 dat)
{
OLED_DC_Clr();//写命令
ST7789_Writ_Bus(dat);
}
/******************************************************************************
函数说明:设置起始和结束地址
入口数据:x1,x2 设置列的起始和结束地址
y1,y2 设置行的起始和结束地址
返回值: 无
******************************************************************************/
void ST7789_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2)
{
if(USE_HORIZONTAL==0)
{
ST7789_WR_REG(0x2a);//列地址设置
ST7789_WR_DATA(x1);
ST7789_WR_DATA(x2);
ST7789_WR_REG(0x2b);//行地址设置
ST7789_WR_DATA(y1);
ST7789_WR_DATA(y2);
ST7789_WR_REG(0x2c);//储存器写
}
else if(USE_HORIZONTAL==1)
{
ST7789_WR_REG(0x2a);//列地址设置
ST7789_WR_DATA(x1);
ST7789_WR_DATA(x2);
ST7789_WR_REG(0x2b);//行地址设置
ST7789_WR_DATA(y1+80);
ST7789_WR_DATA(y2+80);
ST7789_WR_REG(0x2c);//储存器写
}
else if(USE_HORIZONTAL==2)
{
ST7789_WR_REG(0x2a);//列地址设置
ST7789_WR_DATA(x1);
ST7789_WR_DATA(x2);
ST7789_WR_REG(0x2b);//行地址设置
ST7789_WR_DATA(y1);
ST7789_WR_DATA(y2);
ST7789_WR_REG(0x2c);//储存器写
}
else
{
ST7789_WR_REG(0x2a);//列地址设置
ST7789_WR_DATA(x1+80);
ST7789_WR_DATA(x2+80);
ST7789_WR_REG(0x2b);//行地址设置
ST7789_WR_DATA(y1);
ST7789_WR_DATA(y2);
ST7789_WR_REG(0x2c);//储存器写
}
}
/******************************************************************************
函数说明:LCD初始化函数
入口数据:无
返回值: 无
******************************************************************************/
void ST7789_Init(void)
{
ST7789_PIN_INIT();
ST7789_SPI_INIT();
OLED_RST_Clr();
usleep(20 * 1000);
OLED_RST_Set();
usleep(20 * 1000);
// OLED_BLK_Set();
//************* Start Initial Sequence **********//
ST7789_WR_REG(0x36);
if(USE_HORIZONTAL==0)ST7789_WR_DATA8(0x00);
else if(USE_HORIZONTAL==1)ST7789_WR_DATA8(0xC0);
else if(USE_HORIZONTAL==2)ST7789_WR_DATA8(0x70);
else ST7789_WR_DATA8(0xA0);
ST7789_WR_REG(0x3A);
ST7789_WR_DATA8(0x05);
ST7789_WR_REG(0xB2);
ST7789_WR_DATA8(0x0C);
ST7789_WR_DATA8(0x0C);
ST7789_WR_DATA8(0x00);
ST7789_WR_DATA8(0x33);
ST7789_WR_DATA8(0x33);
ST7789_WR_REG(0xB7);
ST7789_WR_DATA8(0x35);
ST7789_WR_REG(0xBB);
ST7789_WR_DATA8(0x37);
ST7789_WR_REG(0xC0);
ST7789_WR_DATA8(0x2C);
ST7789_WR_REG(0xC2);
ST7789_WR_DATA8(0x01);
ST7789_WR_REG(0xC3);
ST7789_WR_DATA8(0x12);
ST7789_WR_REG(0xC4);
ST7789_WR_DATA8(0x20);
ST7789_WR_REG(0xC6);
ST7789_WR_DATA8(0x0F);
ST7789_WR_REG(0xD0);
ST7789_WR_DATA8(0xA4);
ST7789_WR_DATA8(0xA1);
ST7789_WR_REG(0xE0);
ST7789_WR_DATA8(0xD0);
ST7789_WR_DATA8(0x04);
ST7789_WR_DATA8(0x0D);
ST7789_WR_DATA8(0x11);
ST7789_WR_DATA8(0x13);
ST7789_WR_DATA8(0x2B);
ST7789_WR_DATA8(0x3F);
ST7789_WR_DATA8(0x54);
ST7789_WR_DATA8(0x4C);
ST7789_WR_DATA8(0x18);
ST7789_WR_DATA8(0x0D);
ST7789_WR_DATA8(0x0B);
ST7789_WR_DATA8(0x1F);
ST7789_WR_DATA8(0x23);
ST7789_WR_REG(0xE1);
ST7789_WR_DATA8(0xD0);
ST7789_WR_DATA8(0x04);
ST7789_WR_DATA8(0x0C);
ST7789_WR_DATA8(0x11);
ST7789_WR_DATA8(0x13);
ST7789_WR_DATA8(0x2C);
ST7789_WR_DATA8(0x3F);
ST7789_WR_DATA8(0x44);
ST7789_WR_DATA8(0x51);
ST7789_WR_DATA8(0x2F);
ST7789_WR_DATA8(0x1F);
ST7789_WR_DATA8(0x1F);
ST7789_WR_DATA8(0x20);
ST7789_WR_DATA8(0x23);
ST7789_WR_REG(0x21);
ST7789_WR_REG(0x11);
//Delay (120);
ST7789_WR_REG(0x29);
}
/******************************************************************************
函数说明:LCD清屏函数
入口数据:无
返回值: 无
******************************************************************************/
void ST7789_Clear(u16 Color)
{
u16 i,j;
ST7789_Address_Set(0,0,ST7789_W-1,ST7789_H-1);
for(i=0;i<ST7789_W;i++)
{
for (j=0;j<ST7789_H;j++)
{
ST7789_WR_DATA(Color);
}
}
}
/******************************************************************************
函数说明:在指定区域填充颜色
入口数据:xsta,ysta 起始坐标
xend,yend 终止坐标
返回值: 无
******************************************************************************/
void ST7789_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color)
{
u16 i,j;
ST7789_Address_Set(xsta,ysta,xend,yend); //设置光标位置
for(i=ysta;i<=yend;i++)
{
for(j=xsta;j<=xend;j++)ST7789_WR_DATA(color);//设置光标位置
}
}
lvgl驱动接口移植
将lvgl/examples/porting/lv_port_disp_template.h
和lvgl/examples/porting/lv_port_disp_template.c
这个个模板文件拷贝到lv_driver
目录中来,并且重新命名为:lv_port_disp.h
和lv_port_disp.c
将lcd_st7789.c
和lv_port_disp.c
配置到BUILD.gn
中
static_library("lvgl_driver") {
sources = [
"lcd_st7789.c",
"lv_port_disp.c"
]
include_dirs = [
"//base/iothardware/peripheral/interfaces/inner_api",
"../../../iot_hardware_hals/include",
]
}
LVGL与ST7789驱动对接
lvgl_driver配置
开放
lv_port_disp.h
和lv_port_disp.c
,lv_conf.h
的编译标识#if 1
增加引用路径。增加上一级目录。用
..
表示include_dirs = [
"..",
]
修改
lv_port_disp.c
引用,将#include "../../lvgl.h"
改为如下:#include "lvgl/lvgl.h"
lv_port_disp对接
配置驱动头文件引入,并且定义屏幕大小 ```c
include “lcd_st7789.h”
/*
修改
disp_init
函数,初始化st7789屏幕static void disp_init(void)
{
ST7789_Init();
}
配置
lv_port_disp_init
函数,配置一种缓存绘制方式,我们选择单缓冲
: ```c / Example for 1) / static lv_disp_draw_buf_t draw_buf_dsc_1; static lv_color_t draw_buf_1[LV_HOR_RES_MAX 10]; /A buffer for 10 rows/ lv_disp_draw_buf_init(&draw_buf_dsc_1, draw_buf_1, NULL, LV_HOR_RES_MAX 10); /Initialize the display buffer/
// / Example for 2) / // static lv_disp_draw_buf_t draw_buf_dsc_2; // static lv_color_t buf_2_1[MY_DISP_HOR_RES 10]; /A buffer for 10 rows/ // static lv_color_t buf_2_2[MY_DISP_HOR_RES 10]; /An other buffer for 10 rows/ // lv_disp_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_2, MY_DISP_HOR_RES 10); /Initialize the display buffer*/
// / Example for 3) also set disp_drv.full_refresh = 1 below/ // static lv_disp_draw_buf_t draw_buf_dsc_3; // static lv_color_t buf_3_1[MY_DISP_HOR_RES MY_DISP_VER_RES]; /A screen sized buffer/ // static lv_color_t buf_3_2[MY_DISP_HOR_RES MY_DISP_VER_RES]; /Another screen sized buffer/ // lv_disp_draw_buf_init(&draw_buf_dsc_3, buf_3_1, buf_3_2, MY_DISP_VER_RES LV_VER_RES_MAX); /Initialize the display buffer*/
- 只开启单缓冲
4. 配置`disp_flush`函数,配置屏幕点颜色填充逻辑:
```c
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
ST7789_Fill(area->x1, area->y1, area->x2, area->y2, color_p);
/*IMPORTANT!!!
*Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp_drv);
}
修改
ST7789_Fill
实现// void ST7789_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color);
void ST7789_Fill(u16 xsta, u16 ysta, u16 xend, u16 yend, u16 *color);
void ST7789_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,uint16_t *color)
{
// u16 i,j;
// ST7789_Address_Set(xsta,ysta,xend,yend); //设置光标位置
// for(i=ysta;i<=yend;i++)
// {
// for(j=xsta;j<=xend;j++)ST7789_WR_DATA(*color);//设置光标位置
// }
uint32_t size = 0;
ST7789_Address_Set(xsta,ysta,xend,yend);
size = ((xend - xsta) + 1) * ((yend - ysta) + 1)*2;
OLED_DC_Set();
IoTSpiHostWrite(0, (uint8_t*) color, size);
}
完整代码
```c /**
- @file lv_port_disp.h /
/Copy this file as “lv_port_disp.h” and set this value to “1” to enable content/
if 1
ifndef LV_PORT_DISP_H
define LV_PORT_DISP_H
ifdef __cplusplus
extern “C” {
endif
/*
/*
- DEFINES */
/**
- TYPEDEFS **/
/**
- GLOBAL PROTOTYPES **/ void lv_port_disp_init(void);
/**
- MACROS **/
ifdef __cplusplus
} /extern “C”/
endif
endif /LV_PORT_DISP_TEMPL_H/
endif /Disable/Enable content/
```c
/**
* @file lv_port_disp.c
*
*/
/*Copy this file as "lv_port_disp.c" and set this value to "1" to enable content*/
#if 1
/*********************
* INCLUDES
*********************/
#include "lv_port_disp.h"
#include "lvgl/lvgl.h"
#include "lcd_st7789.h"
/*********************
* DEFINES
*********************/
#define LV_HOR_RES_MAX (240)
#define LV_VER_RES_MAX (240)
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void disp_init(void);
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
//static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
// const lv_area_t * fill_area, lv_color_t color);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_port_disp_init(void)
{
/*-------------------------
* Initialize your display
* -----------------------*/
disp_init();
/*-----------------------------
* Create a buffer for drawing
*----------------------------*/
/**
* LVGL requires a buffer where it internally draws the widgets.
* Later this buffer will passed to your display driver's `flush_cb` to copy its content to your display.
* The buffer has to be greater than 1 display row
*
* There are 3 buffering configurations:
* 1. Create ONE buffer:
* LVGL will draw the display's content here and writes it to your display
*
* 2. Create TWO buffer:
* LVGL will draw the display's content to a buffer and writes it your display.
* You should use DMA to write the buffer's content to the display.
* It will enable LVGL to draw the next part of the screen to the other buffer while
* the data is being sent form the first buffer. It makes rendering and flushing parallel.
*
* 3. Double buffering
* Set 2 screens sized buffers and set disp_drv.full_refresh = 1.
* This way LVGL will always provide the whole rendered screen in `flush_cb`
* and you only need to change the frame buffer's address.
*/
/* Example for 1) */
static lv_disp_draw_buf_t draw_buf_dsc_1;
static lv_color_t buf_1[LV_HOR_RES_MAX * 10]; /*A buffer for 10 rows*/
lv_disp_draw_buf_init(&draw_buf_dsc_1, buf_1, NULL, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/
// /* Example for 2) */
// static lv_disp_draw_buf_t draw_buf_dsc_2;
// static lv_color_t buf_2_1[MY_DISP_HOR_RES * 10]; /*A buffer for 10 rows*/
// static lv_color_t buf_2_2[MY_DISP_HOR_RES * 10]; /*An other buffer for 10 rows*/
// lv_disp_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_2, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/
// /* Example for 3) also set disp_drv.full_refresh = 1 below*/
// static lv_disp_draw_buf_t draw_buf_dsc_3;
// static lv_color_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*A screen sized buffer*/
// static lv_color_t buf_3_2[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*Another screen sized buffer*/
// lv_disp_draw_buf_init(&draw_buf_dsc_3, buf_3_1, buf_3_2, MY_DISP_VER_RES * LV_VER_RES_MAX); /*Initialize the display buffer*/
/*-----------------------------------
* Register the display in LVGL
*----------------------------------*/
static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
/*Set up the functions to access to your display*/
/*Set the resolution of the display*/
disp_drv.hor_res = LV_HOR_RES_MAX;
disp_drv.ver_res = LV_VER_RES_MAX;
/*Used to copy the buffer's content to the display*/
disp_drv.flush_cb = disp_flush;
/*Set a display buffer*/
disp_drv.draw_buf = &draw_buf_dsc_1;
/*Required for Example 3)*/
//disp_drv.full_refresh = 1
/* Fill a memory array with a color if you have GPU.
* Note that, in lv_conf.h you can enable GPUs that has built-in support in LVGL.
* But if you have a different GPU you can use with this callback.*/
//disp_drv.gpu_fill_cb = gpu_fill;
/*Finally register the driver*/
lv_disp_drv_register(&disp_drv);
}
/**********************
* STATIC FUNCTIONS
**********************/
/*Initialize your display and the required peripherals.*/
static void disp_init(void)
{
ST7789_Init();
}
/*Flush the content of the internal buffer the specific area on the display
*You can use DMA or any hardware acceleration to do this operation in the background but
*'lv_disp_flush_ready()' has to be called when finished.*/
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
ST7789_Fill(area->x1, area->y1, area->x2, area->y2, color_p);
// ST7789_LCD_Color_Fill(area->x1,area->y1,area->x2,area->y2,color_p);
// ST7789_LCD_Color_Fill(area->x1,area->y1,area->x2,area->y2,color_565);
/*IMPORTANT!!!
*Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp_drv);
}
/*OPTIONAL: GPU INTERFACE*/
/*If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color*/
//static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
// const lv_area_t * fill_area, lv_color_t color)
//{
// /*It's an example code which should be done by your GPU*/
// int32_t x, y;
// dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
//
// for(y = fill_area->y1; y <= fill_area->y2; y++) {
// for(x = fill_area->x1; x <= fill_area->x2; x++) {
// dest_buf[x] = color;
// }
// dest_buf+=dest_width; /*Go to the next line*/
// }
//}
#else /*Enable this file at the top*/
/*This dummy typedef exists purely to silence -Wpedantic.*/
typedef int keep_pedantic_happy;
#endif
#ifndef __LVGL_LCD_ST7789_H__
#define __LVGL_LCD_ST7789_H__
#include "iot_gpio.h"
#include "iot_gpio_ex.h"
#include "iot_spi.h"
#include <stdint.h>
#define USE_HORIZONTAL 0 // 设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏
#if USE_HORIZONTAL == 0 || USE_HORIZONTAL == 1
#define ST7789_W 240
#define ST7789_H 240
#else
#define ST7789_W 240
#define ST7789_H 240
#endif
// #define u8 unsigned char
// #define u16 unsigned int
// #define u32 unsigned long
#define u8 uint8_t
#define u16 uint16_t
#define u32 uint32_t
#define SDC IOT_IO_NAME_6
#define SDIN IOT_IO_NAME_8
#define RST IOT_IO_NAME_5
#define DC IOT_IO_NAME_7
#define SDC_FUNC IOT_GPIO_FUNC_GPIO_6_SPI0_CK
#define SDIN_FUNC IOT_GPIO_FUNC_GPIO_8_SPI0_TXD
#define RST_FUNC IOT_GPIO_FUNC_GPIO_5_GPIO
#define DC_FUNC IOT_GPIO_FUNC_GPIO_7_GPIO
#define ST7789_PIN_INIT() \
IoTGpioInit(SDC); \
IoTGpioSetFunc(SDC, SDC_FUNC); \
IoTGpioSetDir(SDC, IOT_GPIO_DIR_OUT); \
IoTGpioInit(SDIN); \
IoTGpioSetFunc(SDIN, SDIN_FUNC); \
IoTGpioSetDir(SDIN, IOT_GPIO_DIR_OUT); \
IoTGpioInit(RST); \
IoTGpioSetFunc(RST, RST_FUNC); \
IoTGpioSetDir(RST, IOT_GPIO_DIR_OUT); \
IoTGpioInit(DC); \
IoTGpioSetFunc(DC, DC_FUNC); \
IoTGpioSetDir(DC, IOT_GPIO_DIR_OUT);
#define ST7789_SPI_INIT() \
IoTSpiCfgInitParam param; \
param.isSlave = 0; \
IoTSpiCfgBasicInfo info; \
info.cpol = IOT_SPI_CFG_CLOCK_CPOL_1; \
info.cpha = IOT_SPI_CFG_CLOCK_CPHA_1; \
info.framMode = IOT_SPI_CFG_FRAM_MODE_MOTOROLA; \
info.dataWidth = IOT_SPI_CFG_DATA_WIDTH_E_8BIT; \
info.endian = IOT_SPI_CFG_ENDIAN_LITTLE; \
info.pad = 31; \
info.freq = 40000000; \
IoTSpiInit(0, param, &info);
#define OLED_SCLK_Set() IoTGpioSetOutputVal(SDC, 1)
#define OLED_SCLK_Clr() IoTGpioSetOutputVal(SDC, 0)
#define OLED_SDIN_Set() IoTGpioSetOutputVal(SDIN, 1);
#define OLED_SDIN_Clr() IoTGpioSetOutputVal(SDIN, 0);
#define OLED_RST_Set() IoTGpioSetOutputVal(RST, 1);
#define OLED_RST_Clr() IoTGpioSetOutputVal(RST, 0);
#define OLED_DC_Set() IoTGpioSetOutputVal(DC, 1);
#define OLED_DC_Clr() IoTGpioSetOutputVal(DC, 0);
#define OLED_CMD 0 // 写命令
#define OLED_DATA 1 // 写数据
// extern u16 BACK_COLOR; //背景色
void ST7789_Writ_Bus(u8 dat);
void ST7789_WR_DATA8(u8 dat);
void ST7789_WR_DATA(u16 dat);
void ST7789_WR_REG(u8 dat);
void ST7789_Address_Set(u16 x1, u16 y1, u16 x2, u16 y2);
void ST7789_Init(void);
void ST7789_Clear(u16 Color);
// void ST7789_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,u16 color);
void ST7789_Fill(u16 xsta, u16 ysta, u16 xend, u16 yend, u16 *color);
// 画笔颜色
#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 // 灰色
// GUI颜色
#define DARKBLUE 0X01CF // 深蓝色
#define LIGHTBLUE 0X7D7C // 浅蓝色
#define GRAYBLUE 0X5458 // 灰蓝色
// 以上三色为PANEL的颜色
#define LIGHTGREEN 0X841F // 浅绿色
#define LGRAY 0XC618 // 浅灰色(PANNEL),窗体背景色
#define LGRAYBLUE 0XA651 // 浅灰蓝色(中间层颜色)
#define LBBLUE 0X2B12 // 浅棕蓝色(选择条目的反色)
#endif
#include "lcd_st7789.h"
#include <unistd.h>
// u16 BACK_COLOR; //背景色
/******************************************************************************
函数说明:LCD串行数据写入函数
入口数据:dat 要写入的串行数据
返回值: 无
******************************************************************************/
void ST7789_Writ_Bus(u8 dat)
{
// u8 i;
// //OLED_CS_Clr();
// for(i=0;i<8;i++)
// {
// OLED_SCLK_Clr();
// if(dat&0x80) {
// OLED_SDIN_Set();
// }
// else {
// OLED_SDIN_Clr();
// }
// OLED_SCLK_Set();
// dat<<=1;
// }
// //OLED_CS_Set();
IoTSpiHostWrite(0, &dat, 1);
}
/******************************************************************************
函数说明:LCD写入数据
入口数据:dat 写入的数据
返回值: 无
******************************************************************************/
void ST7789_WR_DATA8(u8 dat)
{
OLED_DC_Set();//写数据
ST7789_Writ_Bus(dat);
}
/******************************************************************************
函数说明:LCD写入数据
入口数据:dat 写入的数据
返回值: 无
******************************************************************************/
void ST7789_WR_DATA(u16 dat)
{
OLED_DC_Set();//写数据
ST7789_Writ_Bus(dat>>8);
ST7789_Writ_Bus(dat);
}
/******************************************************************************
函数说明:LCD写入命令
入口数据:dat 写入的命令
返回值: 无
******************************************************************************/
void ST7789_WR_REG(u8 dat)
{
OLED_DC_Clr();//写命令
ST7789_Writ_Bus(dat);
}
/******************************************************************************
函数说明:设置起始和结束地址
入口数据:x1,x2 设置列的起始和结束地址
y1,y2 设置行的起始和结束地址
返回值: 无
******************************************************************************/
void ST7789_Address_Set(u16 x1,u16 y1,u16 x2,u16 y2)
{
if(USE_HORIZONTAL==0)
{
ST7789_WR_REG(0x2a);//列地址设置
ST7789_WR_DATA(x1);
ST7789_WR_DATA(x2);
ST7789_WR_REG(0x2b);//行地址设置
ST7789_WR_DATA(y1);
ST7789_WR_DATA(y2);
ST7789_WR_REG(0x2c);//储存器写
}
else if(USE_HORIZONTAL==1)
{
ST7789_WR_REG(0x2a);//列地址设置
ST7789_WR_DATA(x1);
ST7789_WR_DATA(x2);
ST7789_WR_REG(0x2b);//行地址设置
ST7789_WR_DATA(y1+80);
ST7789_WR_DATA(y2+80);
ST7789_WR_REG(0x2c);//储存器写
}
else if(USE_HORIZONTAL==2)
{
ST7789_WR_REG(0x2a);//列地址设置
ST7789_WR_DATA(x1);
ST7789_WR_DATA(x2);
ST7789_WR_REG(0x2b);//行地址设置
ST7789_WR_DATA(y1);
ST7789_WR_DATA(y2);
ST7789_WR_REG(0x2c);//储存器写
}
else
{
ST7789_WR_REG(0x2a);//列地址设置
ST7789_WR_DATA(x1+80);
ST7789_WR_DATA(x2+80);
ST7789_WR_REG(0x2b);//行地址设置
ST7789_WR_DATA(y1);
ST7789_WR_DATA(y2);
ST7789_WR_REG(0x2c);//储存器写
}
}
/******************************************************************************
函数说明:LCD初始化函数
入口数据:无
返回值: 无
******************************************************************************/
void ST7789_Init(void)
{
ST7789_PIN_INIT();
ST7789_SPI_INIT();
OLED_RST_Clr();
usleep(20 * 1000);
OLED_RST_Set();
usleep(20 * 1000);
// OLED_BLK_Set();
//************* Start Initial Sequence **********//
ST7789_WR_REG(0x36);
if(USE_HORIZONTAL==0)ST7789_WR_DATA8(0x00);
else if(USE_HORIZONTAL==1)ST7789_WR_DATA8(0xC0);
else if(USE_HORIZONTAL==2)ST7789_WR_DATA8(0x70);
else ST7789_WR_DATA8(0xA0);
ST7789_WR_REG(0x3A);
ST7789_WR_DATA8(0x05);
ST7789_WR_REG(0xB2);
ST7789_WR_DATA8(0x0C);
ST7789_WR_DATA8(0x0C);
ST7789_WR_DATA8(0x00);
ST7789_WR_DATA8(0x33);
ST7789_WR_DATA8(0x33);
ST7789_WR_REG(0xB7);
ST7789_WR_DATA8(0x35);
ST7789_WR_REG(0xBB);
ST7789_WR_DATA8(0x37);
ST7789_WR_REG(0xC0);
ST7789_WR_DATA8(0x2C);
ST7789_WR_REG(0xC2);
ST7789_WR_DATA8(0x01);
ST7789_WR_REG(0xC3);
ST7789_WR_DATA8(0x12);
ST7789_WR_REG(0xC4);
ST7789_WR_DATA8(0x20);
ST7789_WR_REG(0xC6);
ST7789_WR_DATA8(0x0F);
ST7789_WR_REG(0xD0);
ST7789_WR_DATA8(0xA4);
ST7789_WR_DATA8(0xA1);
ST7789_WR_REG(0xE0);
ST7789_WR_DATA8(0xD0);
ST7789_WR_DATA8(0x04);
ST7789_WR_DATA8(0x0D);
ST7789_WR_DATA8(0x11);
ST7789_WR_DATA8(0x13);
ST7789_WR_DATA8(0x2B);
ST7789_WR_DATA8(0x3F);
ST7789_WR_DATA8(0x54);
ST7789_WR_DATA8(0x4C);
ST7789_WR_DATA8(0x18);
ST7789_WR_DATA8(0x0D);
ST7789_WR_DATA8(0x0B);
ST7789_WR_DATA8(0x1F);
ST7789_WR_DATA8(0x23);
ST7789_WR_REG(0xE1);
ST7789_WR_DATA8(0xD0);
ST7789_WR_DATA8(0x04);
ST7789_WR_DATA8(0x0C);
ST7789_WR_DATA8(0x11);
ST7789_WR_DATA8(0x13);
ST7789_WR_DATA8(0x2C);
ST7789_WR_DATA8(0x3F);
ST7789_WR_DATA8(0x44);
ST7789_WR_DATA8(0x51);
ST7789_WR_DATA8(0x2F);
ST7789_WR_DATA8(0x1F);
ST7789_WR_DATA8(0x1F);
ST7789_WR_DATA8(0x20);
ST7789_WR_DATA8(0x23);
ST7789_WR_REG(0x21);
ST7789_WR_REG(0x11);
//Delay (120);
ST7789_WR_REG(0x29);
}
/******************************************************************************
函数说明:LCD清屏函数
入口数据:无
返回值: 无
******************************************************************************/
void ST7789_Clear(u16 Color)
{
u16 i,j;
ST7789_Address_Set(0,0,ST7789_W-1,ST7789_H-1);
for(i=0;i<ST7789_W;i++)
{
for (j=0;j<ST7789_H;j++)
{
ST7789_WR_DATA(Color);
}
}
}
/******************************************************************************
函数说明:在指定区域填充颜色
入口数据:xsta,ysta 起始坐标
xend,yend 终止坐标
返回值: 无
******************************************************************************/
void ST7789_Fill(u16 xsta,u16 ysta,u16 xend,u16 yend,uint16_t *color)
{
// u16 i,j;
// ST7789_Address_Set(xsta,ysta,xend,yend); //设置光标位置
// for(i=ysta;i<=yend;i++)
// {
// for(j=xsta;j<=xend;j++)ST7789_WR_DATA(*color);//设置光标位置
// }
uint32_t size = 0;
ST7789_Address_Set(xsta,ysta,xend,yend);
size = ((xend - xsta) + 1) * ((yend - ysta) + 1)*2;
OLED_DC_Set();
IoTSpiHostWrite(0, (uint8_t*) color, size);
}
测试逻辑
最小运行逻辑
#include "lvgl.h"
#include "lv_conf.h"
#include "lv_port_disp.h"
static void first_screen(){
//创建桌面
lv_obj_t * obj = lv_obj_create(lv_scr_act());
}
static void start() {
//lvgl初始化
lv_init();
//lvgl显示接口
lv_port_disp_init();
first_screen();
while(1)
{
usleep(5000);
lv_timer_handler();
}
}
练习题
- 完成lvgl的移植