使用 OneOS 及其图形框架、LVGL库、GUI-Guider 绘制界面部属到战舰板上
使用我之前做的OneOS、LVGL和GUI-Guider对接的程序:https://gitee.com/pomin-163/OneOS.git
下载下来,这个仓库支持正点原子的2.8寸屏幕,不支持4.3寸的屏幕,这里修改一下Kconfig和SConscript编译脚本并且适配一下驱动
先编写一个atk_tflcd35510的C文件和H文件
头文件
#ifndef _ATK_TFLCD9341_H_
#define _ATK_TFLCD9341_H_
#include <board.h>
#include <drv_cfg.h>
#define L2R_U2D 0
#define L2R_D2U 1
#define R2L_U2D 2
#define R2L_D2U 3
#define U2D_L2R 4
#define U2D_R2L 5
#define D2U_L2R 6
#define D2U_R2L 7
#define DFT_SCAN_DIR L2R_U2D
struct atk_lcd_info
{
os_uint16_t width;
os_uint16_t height;
os_uint16_t id;
os_uint8_t dir;
os_uint16_t wramcmd;
os_uint16_t setxcmd;
os_uint16_t setycmd;
};
struct atk_lcd_mem
{
volatile os_uint16_t reg;
volatile os_uint16_t ram;
};
#define LCD_BASE ((os_uint32_t)(0x6C000000 | 0x000007FE))
#endif
源代码文件
#include <board.h>
#include <os_memory.h>
#include <graphic/graphic.h>
#include <shell.h>
#include <string.h>
#include <clocksource.h>
#include <dlog.h>
#include "atk_tflcd9341.h"
#define DBG_TAG "LCD"
struct atk_lcd
{
os_graphic_t graphic;
};
struct atk_lcd_info lcd_dev = {
.dir = 0,
.width = OS_GRAPHIC_LCD_WIDTH,
.height = OS_GRAPHIC_LCD_HEIGHT,
.wramcmd = 0X2C00,
.setxcmd = 0X2A00,
.setycmd = 0X2B00,
};
struct atk_lcd_mem *lcd = (struct atk_lcd_mem *)LCD_BASE;
#define delay_us(x) os_clocksource_ndelay(1000*x);
#define lcddev lcd_dev
#define LCD_WR_REG(x) __LCD_WR_REG(x)
#define LCD_WR_DATA(x) __LCD_WR_DATA(x)
#define LCD_WriteReg(...) __LCD_WriteReg(__VA_ARGS__)
#define LCD_RD_DATA(x) __LCD_RD_DATA(x)
static void __LCD_WR_REG(os_uint16_t regval)
{
os_clocksource_ndelay(1000);
lcd->reg = regval;
}
static void __LCD_WR_DATA(os_uint16_t data)
{
os_clocksource_ndelay(1000);
lcd->ram = data;
}
static os_uint16_t __LCD_RD_DATA(void)
{
os_uint16_t ram;
ram = lcd->ram;
return ram;
}
static void __LCD_WriteReg(os_uint16_t LCD_Reg, os_uint16_t LCD_RegValue)
{
lcd->reg = LCD_Reg;
lcd->ram = LCD_RegValue;
}
static void __LCD_WriteRAM_Prepare(void)
{
lcd->reg = lcd_dev.wramcmd;
}
static void lcd_set_cursor(os_uint16_t Xpos, os_uint16_t Ypos)
{
LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(Xpos>>8);
LCD_WR_REG(lcddev.setxcmd+1);LCD_WR_DATA(Xpos&0XFF);
LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(Ypos>>8);
LCD_WR_REG(lcddev.setycmd+1);LCD_WR_DATA(Ypos&0XFF);
}
static void lcd_clear(os_uint32_t color)
{
os_uint32_t index = 0;
os_uint32_t totalpoint = lcd_dev.width;
totalpoint *= lcd_dev.height;
lcd_set_cursor(0x00, 0x0000);
__LCD_WriteRAM_Prepare();
for (index = 0; index < totalpoint; index++)
{
lcd->ram = color;
}
}
static void lcd_fill_color(os_uint16_t sx, os_uint16_t sy, os_uint16_t ex, os_uint16_t ey, os_uint32_t color)
{
os_uint16_t i, j;
os_uint16_t xlen = 0;
xlen = ex - sx + 1;
for (i = sy; i <= ey; i++)
{
lcd_set_cursor(sx, i);
__LCD_WriteRAM_Prepare();
for (j = 0; j < xlen; j++)
{
lcd->ram = color;
}
}
}
static void lcd_read_id(void)
{
LCD_WR_REG(0XDA00);
lcddev.id=LCD_RD_DATA();
LCD_WR_REG(0XDB00);
lcddev.id=LCD_RD_DATA();
lcddev.id<<=8;
LCD_WR_REG(0XDC00);
lcddev.id|=LCD_RD_DATA();
if(lcddev.id==0x8000)lcddev.id=0x5510;
LOG_I(DBG_TAG, "lcd id:0x%x", lcd_dev.id);
}
static void lcd_scan_direction(os_uint8_t dir)
{
os_uint16_t regval = 0;
os_uint16_t dirreg = 0;
os_uint16_t temp;
switch (dir)
{
case L2R_U2D:
regval |= (0 << 7) | (0 << 6) | (0 << 5);
break;
case L2R_D2U:
regval |= (1 << 7) | (0 << 6) | (0 << 5);
break;
case R2L_U2D:
regval |= (0 << 7) | (1 << 6) | (0 << 5);
break;
case R2L_D2U:
regval |= (1 << 7) | (1 << 6) | (0 << 5);
break;
case U2D_L2R:
regval |= (0 << 7) | (0 << 6) | (1 << 5);
break;
case U2D_R2L:
regval |= (0 << 7) | (1 << 6) | (1 << 5);
break;
case D2U_L2R:
regval |= (1 << 7) | (0 << 6) | (1 << 5);
break;
case D2U_R2L:
regval |= (1 << 7) | (1 << 6) | (1 << 5);
break;
}
dirreg = 0x3600;
regval = 0x0;
__LCD_WriteReg(dirreg, regval);
if (regval & 0x20)
{
if (lcd_dev.width < lcd_dev.height)
{
temp = lcd_dev.width;
lcd_dev.width = lcd_dev.height;
lcd_dev.height = temp;
}
}
else
{
if (lcd_dev.width > lcd_dev.height)
{
temp = lcd_dev.width;
lcd_dev.width = lcd_dev.height;
lcd_dev.height = temp;
}
}
LCD_WR_REG(lcddev.setxcmd);LCD_WR_DATA(0);
LCD_WR_REG(lcddev.setxcmd+1);LCD_WR_DATA(0);
LCD_WR_REG(lcddev.setxcmd+2);LCD_WR_DATA((lcddev.width-1)>>8);
LCD_WR_REG(lcddev.setxcmd+3);LCD_WR_DATA((lcddev.width-1)&0XFF);
LCD_WR_REG(lcddev.setycmd);LCD_WR_DATA(0);
LCD_WR_REG(lcddev.setycmd+1);LCD_WR_DATA(0);
LCD_WR_REG(lcddev.setycmd+2);LCD_WR_DATA((lcddev.height-1)>>8);
LCD_WR_REG(lcddev.setycmd+3);LCD_WR_DATA((lcddev.height-1)&0XFF);
}
static void lcd_display_direction(os_uint8_t dir)
{
lcd_dev.dir = dir;
if (dir == 0)
{
lcd_dev.width = 480;
lcd_dev.height = 800;
}
else
{
lcd_dev.width = 800;
lcd_dev.height = 480;
}
lcd_scan_direction(DFT_SCAN_DIR);
}
static void lcd_init(void)
{
LCD_WriteReg(0xF000,0x55);
LCD_WriteReg(0xF001,0xAA);
LCD_WriteReg(0xF002,0x52);
LCD_WriteReg(0xF003,0x08);
LCD_WriteReg(0xF004,0x01);
LCD_WriteReg(0xB000,0x0D);
LCD_WriteReg(0xB001,0x0D);
LCD_WriteReg(0xB002,0x0D);
LCD_WriteReg(0xB600,0x34);
LCD_WriteReg(0xB601,0x34);
LCD_WriteReg(0xB602,0x34);
LCD_WriteReg(0xB100,0x0D);
LCD_WriteReg(0xB101,0x0D);
LCD_WriteReg(0xB102,0x0D);
LCD_WriteReg(0xB700,0x34);
LCD_WriteReg(0xB701,0x34);
LCD_WriteReg(0xB702,0x34);
LCD_WriteReg(0xB200,0x00);
LCD_WriteReg(0xB201,0x00);
LCD_WriteReg(0xB202,0x00);
LCD_WriteReg(0xB800,0x24);
LCD_WriteReg(0xB801,0x24);
LCD_WriteReg(0xB802,0x24);
LCD_WriteReg(0xBF00,0x01);
LCD_WriteReg(0xB300,0x0F);
LCD_WriteReg(0xB301,0x0F);
LCD_WriteReg(0xB302,0x0F);
LCD_WriteReg(0xB900,0x34);
LCD_WriteReg(0xB901,0x34);
LCD_WriteReg(0xB902,0x34);
LCD_WriteReg(0xB500,0x08);
LCD_WriteReg(0xB501,0x08);
LCD_WriteReg(0xB502,0x08);
LCD_WriteReg(0xC200,0x03);
LCD_WriteReg(0xBA00,0x24);
LCD_WriteReg(0xBA01,0x24);
LCD_WriteReg(0xBA02,0x24);
LCD_WriteReg(0xBC00,0x00);
LCD_WriteReg(0xBC01,0x78);
LCD_WriteReg(0xBC02,0x00);
LCD_WriteReg(0xBD00,0x00);
LCD_WriteReg(0xBD01,0x78);
LCD_WriteReg(0xBD02,0x00);
LCD_WriteReg(0xBE00,0x00);
LCD_WriteReg(0xBE01,0x64);
LCD_WriteReg(0xD100,0x00);
LCD_WriteReg(0xD101,0x33);
LCD_WriteReg(0xD102,0x00);
LCD_WriteReg(0xD103,0x34);
LCD_WriteReg(0xD104,0x00);
LCD_WriteReg(0xD105,0x3A);
LCD_WriteReg(0xD106,0x00);
LCD_WriteReg(0xD107,0x4A);
LCD_WriteReg(0xD108,0x00);
LCD_WriteReg(0xD109,0x5C);
LCD_WriteReg(0xD10A,0x00);
LCD_WriteReg(0xD10B,0x81);
LCD_WriteReg(0xD10C,0x00);
LCD_WriteReg(0xD10D,0xA6);
LCD_WriteReg(0xD10E,0x00);
LCD_WriteReg(0xD10F,0xE5);
LCD_WriteReg(0xD110,0x01);
LCD_WriteReg(0xD111,0x13);
LCD_WriteReg(0xD112,0x01);
LCD_WriteReg(0xD113,0x54);
LCD_WriteReg(0xD114,0x01);
LCD_WriteReg(0xD115,0x82);
LCD_WriteReg(0xD116,0x01);
LCD_WriteReg(0xD117,0xCA);
LCD_WriteReg(0xD118,0x02);
LCD_WriteReg(0xD119,0x00);
LCD_WriteReg(0xD11A,0x02);
LCD_WriteReg(0xD11B,0x01);
LCD_WriteReg(0xD11C,0x02);
LCD_WriteReg(0xD11D,0x34);
LCD_WriteReg(0xD11E,0x02);
LCD_WriteReg(0xD11F,0x67);
LCD_WriteReg(0xD120,0x02);
LCD_WriteReg(0xD121,0x84);
LCD_WriteReg(0xD122,0x02);
LCD_WriteReg(0xD123,0xA4);
LCD_WriteReg(0xD124,0x02);
LCD_WriteReg(0xD125,0xB7);
LCD_WriteReg(0xD126,0x02);
LCD_WriteReg(0xD127,0xCF);
LCD_WriteReg(0xD128,0x02);
LCD_WriteReg(0xD129,0xDE);
LCD_WriteReg(0xD12A,0x02);
LCD_WriteReg(0xD12B,0xF2);
LCD_WriteReg(0xD12C,0x02);
LCD_WriteReg(0xD12D,0xFE);
LCD_WriteReg(0xD12E,0x03);
LCD_WriteReg(0xD12F,0x10);
LCD_WriteReg(0xD130,0x03);
LCD_WriteReg(0xD131,0x33);
LCD_WriteReg(0xD132,0x03);
LCD_WriteReg(0xD133,0x6D);
LCD_WriteReg(0xD200,0x00);
LCD_WriteReg(0xD201,0x33);
LCD_WriteReg(0xD202,0x00);
LCD_WriteReg(0xD203,0x34);
LCD_WriteReg(0xD204,0x00);
LCD_WriteReg(0xD205,0x3A);
LCD_WriteReg(0xD206,0x00);
LCD_WriteReg(0xD207,0x4A);
LCD_WriteReg(0xD208,0x00);
LCD_WriteReg(0xD209,0x5C);
LCD_WriteReg(0xD20A,0x00);
LCD_WriteReg(0xD20B,0x81);
LCD_WriteReg(0xD20C,0x00);
LCD_WriteReg(0xD20D,0xA6);
LCD_WriteReg(0xD20E,0x00);
LCD_WriteReg(0xD20F,0xE5);
LCD_WriteReg(0xD210,0x01);
LCD_WriteReg(0xD211,0x13);
LCD_WriteReg(0xD212,0x01);
LCD_WriteReg(0xD213,0x54);
LCD_WriteReg(0xD214,0x01);
LCD_WriteReg(0xD215,0x82);
LCD_WriteReg(0xD216,0x01);
LCD_WriteReg(0xD217,0xCA);
LCD_WriteReg(0xD218,0x02);
LCD_WriteReg(0xD219,0x00);
LCD_WriteReg(0xD21A,0x02);
LCD_WriteReg(0xD21B,0x01);
LCD_WriteReg(0xD21C,0x02);
LCD_WriteReg(0xD21D,0x34);
LCD_WriteReg(0xD21E,0x02);
LCD_WriteReg(0xD21F,0x67);
LCD_WriteReg(0xD220,0x02);
LCD_WriteReg(0xD221,0x84);
LCD_WriteReg(0xD222,0x02);
LCD_WriteReg(0xD223,0xA4);
LCD_WriteReg(0xD224,0x02);
LCD_WriteReg(0xD225,0xB7);
LCD_WriteReg(0xD226,0x02);
LCD_WriteReg(0xD227,0xCF);
LCD_WriteReg(0xD228,0x02);
LCD_WriteReg(0xD229,0xDE);
LCD_WriteReg(0xD22A,0x02);
LCD_WriteReg(0xD22B,0xF2);
LCD_WriteReg(0xD22C,0x02);
LCD_WriteReg(0xD22D,0xFE);
LCD_WriteReg(0xD22E,0x03);
LCD_WriteReg(0xD22F,0x10);
LCD_WriteReg(0xD230,0x03);
LCD_WriteReg(0xD231,0x33);
LCD_WriteReg(0xD232,0x03);
LCD_WriteReg(0xD233,0x6D);
LCD_WriteReg(0xD300,0x00);
LCD_WriteReg(0xD301,0x33);
LCD_WriteReg(0xD302,0x00);
LCD_WriteReg(0xD303,0x34);
LCD_WriteReg(0xD304,0x00);
LCD_WriteReg(0xD305,0x3A);
LCD_WriteReg(0xD306,0x00);
LCD_WriteReg(0xD307,0x4A);
LCD_WriteReg(0xD308,0x00);
LCD_WriteReg(0xD309,0x5C);
LCD_WriteReg(0xD30A,0x00);
LCD_WriteReg(0xD30B,0x81);
LCD_WriteReg(0xD30C,0x00);
LCD_WriteReg(0xD30D,0xA6);
LCD_WriteReg(0xD30E,0x00);
LCD_WriteReg(0xD30F,0xE5);
LCD_WriteReg(0xD310,0x01);
LCD_WriteReg(0xD311,0x13);
LCD_WriteReg(0xD312,0x01);
LCD_WriteReg(0xD313,0x54);
LCD_WriteReg(0xD314,0x01);
LCD_WriteReg(0xD315,0x82);
LCD_WriteReg(0xD316,0x01);
LCD_WriteReg(0xD317,0xCA);
LCD_WriteReg(0xD318,0x02);
LCD_WriteReg(0xD319,0x00);
LCD_WriteReg(0xD31A,0x02);
LCD_WriteReg(0xD31B,0x01);
LCD_WriteReg(0xD31C,0x02);
LCD_WriteReg(0xD31D,0x34);
LCD_WriteReg(0xD31E,0x02);
LCD_WriteReg(0xD31F,0x67);
LCD_WriteReg(0xD320,0x02);
LCD_WriteReg(0xD321,0x84);
LCD_WriteReg(0xD322,0x02);
LCD_WriteReg(0xD323,0xA4);
LCD_WriteReg(0xD324,0x02);
LCD_WriteReg(0xD325,0xB7);
LCD_WriteReg(0xD326,0x02);
LCD_WriteReg(0xD327,0xCF);
LCD_WriteReg(0xD328,0x02);
LCD_WriteReg(0xD329,0xDE);
LCD_WriteReg(0xD32A,0x02);
LCD_WriteReg(0xD32B,0xF2);
LCD_WriteReg(0xD32C,0x02);
LCD_WriteReg(0xD32D,0xFE);
LCD_WriteReg(0xD32E,0x03);
LCD_WriteReg(0xD32F,0x10);
LCD_WriteReg(0xD330,0x03);
LCD_WriteReg(0xD331,0x33);
LCD_WriteReg(0xD332,0x03);
LCD_WriteReg(0xD333,0x6D);
LCD_WriteReg(0xD400,0x00);
LCD_WriteReg(0xD401,0x33);
LCD_WriteReg(0xD402,0x00);
LCD_WriteReg(0xD403,0x34);
LCD_WriteReg(0xD404,0x00);
LCD_WriteReg(0xD405,0x3A);
LCD_WriteReg(0xD406,0x00);
LCD_WriteReg(0xD407,0x4A);
LCD_WriteReg(0xD408,0x00);
LCD_WriteReg(0xD409,0x5C);
LCD_WriteReg(0xD40A,0x00);
LCD_WriteReg(0xD40B,0x81);
LCD_WriteReg(0xD40C,0x00);
LCD_WriteReg(0xD40D,0xA6);
LCD_WriteReg(0xD40E,0x00);
LCD_WriteReg(0xD40F,0xE5);
LCD_WriteReg(0xD410,0x01);
LCD_WriteReg(0xD411,0x13);
LCD_WriteReg(0xD412,0x01);
LCD_WriteReg(0xD413,0x54);
LCD_WriteReg(0xD414,0x01);
LCD_WriteReg(0xD415,0x82);
LCD_WriteReg(0xD416,0x01);
LCD_WriteReg(0xD417,0xCA);
LCD_WriteReg(0xD418,0x02);
LCD_WriteReg(0xD419,0x00);
LCD_WriteReg(0xD41A,0x02);
LCD_WriteReg(0xD41B,0x01);
LCD_WriteReg(0xD41C,0x02);
LCD_WriteReg(0xD41D,0x34);
LCD_WriteReg(0xD41E,0x02);
LCD_WriteReg(0xD41F,0x67);
LCD_WriteReg(0xD420,0x02);
LCD_WriteReg(0xD421,0x84);
LCD_WriteReg(0xD422,0x02);
LCD_WriteReg(0xD423,0xA4);
LCD_WriteReg(0xD424,0x02);
LCD_WriteReg(0xD425,0xB7);
LCD_WriteReg(0xD426,0x02);
LCD_WriteReg(0xD427,0xCF);
LCD_WriteReg(0xD428,0x02);
LCD_WriteReg(0xD429,0xDE);
LCD_WriteReg(0xD42A,0x02);
LCD_WriteReg(0xD42B,0xF2);
LCD_WriteReg(0xD42C,0x02);
LCD_WriteReg(0xD42D,0xFE);
LCD_WriteReg(0xD42E,0x03);
LCD_WriteReg(0xD42F,0x10);
LCD_WriteReg(0xD430,0x03);
LCD_WriteReg(0xD431,0x33);
LCD_WriteReg(0xD432,0x03);
LCD_WriteReg(0xD433,0x6D);
LCD_WriteReg(0xD500,0x00);
LCD_WriteReg(0xD501,0x33);
LCD_WriteReg(0xD502,0x00);
LCD_WriteReg(0xD503,0x34);
LCD_WriteReg(0xD504,0x00);
LCD_WriteReg(0xD505,0x3A);
LCD_WriteReg(0xD506,0x00);
LCD_WriteReg(0xD507,0x4A);
LCD_WriteReg(0xD508,0x00);
LCD_WriteReg(0xD509,0x5C);
LCD_WriteReg(0xD50A,0x00);
LCD_WriteReg(0xD50B,0x81);
LCD_WriteReg(0xD50C,0x00);
LCD_WriteReg(0xD50D,0xA6);
LCD_WriteReg(0xD50E,0x00);
LCD_WriteReg(0xD50F,0xE5);
LCD_WriteReg(0xD510,0x01);
LCD_WriteReg(0xD511,0x13);
LCD_WriteReg(0xD512,0x01);
LCD_WriteReg(0xD513,0x54);
LCD_WriteReg(0xD514,0x01);
LCD_WriteReg(0xD515,0x82);
LCD_WriteReg(0xD516,0x01);
LCD_WriteReg(0xD517,0xCA);
LCD_WriteReg(0xD518,0x02);
LCD_WriteReg(0xD519,0x00);
LCD_WriteReg(0xD51A,0x02);
LCD_WriteReg(0xD51B,0x01);
LCD_WriteReg(0xD51C,0x02);
LCD_WriteReg(0xD51D,0x34);
LCD_WriteReg(0xD51E,0x02);
LCD_WriteReg(0xD51F,0x67);
LCD_WriteReg(0xD520,0x02);
LCD_WriteReg(0xD521,0x84);
LCD_WriteReg(0xD522,0x02);
LCD_WriteReg(0xD523,0xA4);
LCD_WriteReg(0xD524,0x02);
LCD_WriteReg(0xD525,0xB7);
LCD_WriteReg(0xD526,0x02);
LCD_WriteReg(0xD527,0xCF);
LCD_WriteReg(0xD528,0x02);
LCD_WriteReg(0xD529,0xDE);
LCD_WriteReg(0xD52A,0x02);
LCD_WriteReg(0xD52B,0xF2);
LCD_WriteReg(0xD52C,0x02);
LCD_WriteReg(0xD52D,0xFE);
LCD_WriteReg(0xD52E,0x03);
LCD_WriteReg(0xD52F,0x10);
LCD_WriteReg(0xD530,0x03);
LCD_WriteReg(0xD531,0x33);
LCD_WriteReg(0xD532,0x03);
LCD_WriteReg(0xD533,0x6D);
LCD_WriteReg(0xD600,0x00);
LCD_WriteReg(0xD601,0x33);
LCD_WriteReg(0xD602,0x00);
LCD_WriteReg(0xD603,0x34);
LCD_WriteReg(0xD604,0x00);
LCD_WriteReg(0xD605,0x3A);
LCD_WriteReg(0xD606,0x00);
LCD_WriteReg(0xD607,0x4A);
LCD_WriteReg(0xD608,0x00);
LCD_WriteReg(0xD609,0x5C);
LCD_WriteReg(0xD60A,0x00);
LCD_WriteReg(0xD60B,0x81);
LCD_WriteReg(0xD60C,0x00);
LCD_WriteReg(0xD60D,0xA6);
LCD_WriteReg(0xD60E,0x00);
LCD_WriteReg(0xD60F,0xE5);
LCD_WriteReg(0xD610,0x01);
LCD_WriteReg(0xD611,0x13);
LCD_WriteReg(0xD612,0x01);
LCD_WriteReg(0xD613,0x54);
LCD_WriteReg(0xD614,0x01);
LCD_WriteReg(0xD615,0x82);
LCD_WriteReg(0xD616,0x01);
LCD_WriteReg(0xD617,0xCA);
LCD_WriteReg(0xD618,0x02);
LCD_WriteReg(0xD619,0x00);
LCD_WriteReg(0xD61A,0x02);
LCD_WriteReg(0xD61B,0x01);
LCD_WriteReg(0xD61C,0x02);
LCD_WriteReg(0xD61D,0x34);
LCD_WriteReg(0xD61E,0x02);
LCD_WriteReg(0xD61F,0x67);
LCD_WriteReg(0xD620,0x02);
LCD_WriteReg(0xD621,0x84);
LCD_WriteReg(0xD622,0x02);
LCD_WriteReg(0xD623,0xA4);
LCD_WriteReg(0xD624,0x02);
LCD_WriteReg(0xD625,0xB7);
LCD_WriteReg(0xD626,0x02);
LCD_WriteReg(0xD627,0xCF);
LCD_WriteReg(0xD628,0x02);
LCD_WriteReg(0xD629,0xDE);
LCD_WriteReg(0xD62A,0x02);
LCD_WriteReg(0xD62B,0xF2);
LCD_WriteReg(0xD62C,0x02);
LCD_WriteReg(0xD62D,0xFE);
LCD_WriteReg(0xD62E,0x03);
LCD_WriteReg(0xD62F,0x10);
LCD_WriteReg(0xD630,0x03);
LCD_WriteReg(0xD631,0x33);
LCD_WriteReg(0xD632,0x03);
LCD_WriteReg(0xD633,0x6D);
LCD_WriteReg(0xF000,0x55);
LCD_WriteReg(0xF001,0xAA);
LCD_WriteReg(0xF002,0x52);
LCD_WriteReg(0xF003,0x08);
LCD_WriteReg(0xF004,0x00);
LCD_WriteReg(0xB100, 0xCC);
LCD_WriteReg(0xB101, 0x00);
LCD_WriteReg(0xB600,0x05);
LCD_WriteReg(0xB700,0x70);
LCD_WriteReg(0xB701,0x70);
LCD_WriteReg(0xB800,0x01);
LCD_WriteReg(0xB801,0x03);
LCD_WriteReg(0xB802,0x03);
LCD_WriteReg(0xB803,0x03);
LCD_WriteReg(0xBC00,0x02);
LCD_WriteReg(0xBC01,0x00);
LCD_WriteReg(0xBC02,0x00);
LCD_WriteReg(0xC900,0xD0);
LCD_WriteReg(0xC901,0x02);
LCD_WriteReg(0xC902,0x50);
LCD_WriteReg(0xC903,0x50);
LCD_WriteReg(0xC904,0x50);
LCD_WriteReg(0x3500,0x00);
LCD_WriteReg(0x3A00,0x55);
LCD_WR_REG(0x1100);
delay_us(120);
LCD_WR_REG(0x2900);
lcd_display_direction(0);
lcd_clear(0xFFFF);
}
static void lcd_back_light_set(os_uint8_t on)
{
os_pin_mode(BSP_ATK9341_BL_PIN, PIN_MODE_OUTPUT);
if (on)
os_pin_write(BSP_ATK9341_BL_PIN, 1);
else
os_pin_write(BSP_ATK9341_BL_PIN, 0);
}
void lcd_fill_window(os_uint16_t sx, os_uint16_t sy, os_uint16_t ex, os_uint16_t ey, os_uint16_t *data)
{
os_uint16_t height, width;
os_uint16_t i, j;
width = ex - sx + 1;
height = ey - sy + 1;
for (i = 0; i < height; i++)
{
lcd_set_cursor(sx, sy + i);
__LCD_WriteRAM_Prepare();
for (j = 0; j < width; j++)
{
lcd->ram = data[i * width + j];
}
}
}
static void atk_tflcd9341_display_area(struct os_device *dev, os_graphic_area_t *area)
{
os_uint16_t color;
if (area->buffer)
{
lcd_fill_window(area->x, area->y, area->x + area->w - 1, area->y + area->h - 1, (os_uint16_t *)area->buffer);
}
else
{
color = OS_COLOR_TO16(area->color);
lcd_fill_color(area->x, area->y, area->x + area->w - 1, area->y + area->h - 1, color);
}
}
const static struct os_graphic_ops ops = {
.display_on = OS_NULL,
.display_area = atk_tflcd9341_display_area,
.frame_flush = OS_NULL,
};
static void __os_hw_lcd_init(void)
{
lcd_back_light_set(1);
lcd_read_id();
lcd_init();
}
static int os_hw_lcd_init(void)
{
struct atk_lcd *lcd;
lcd = os_calloc(1, sizeof(struct atk_lcd));
OS_ASSERT(lcd);
__os_hw_lcd_init();
lcd->graphic.ops = &ops;
os_graphic_register("lcd", &lcd->graphic);
LOG_I(DBG_TAG, "atk tflcd9341 found.");
return OS_EOK;
}
OS_DEVICE_INIT(os_hw_lcd_init, OS_INIT_SUBLEVEL_LOW);
修改SConscript 文件,加入NT35510驱动的支持
Import('OS_ROOT')
from build_tools import *
objs = []
pwd = PresentDir()
src = ['graphic.c']
if IsDefined('OS_USING_DSI'):
src += ['dsi.c']
if IsDefined('BSP_USING_OTM8009A'):
src += ['otm8009a.c']
if IsDefined('BSP_USING_ILI9341'):
src += ['ili9341.c']
if IsDefined('OS_USING_ST7789VW'):
src += ['st7789vw.c']
if IsDefined('BSP_USING_ATKTFLCD9341'):
src += ['atk_tflcd9341.c']
if IsDefined('BSP_USING_ATKTFLCD35510'):
src += ['atk_tflcd35510.c']
objs = AddCodeGroup('graphic', src, depend = ['OS_USING_GRAPHIC'], CPPPATH = [pwd])
list = os.listdir(pwd)
for d in list:
path = os.path.join(pwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
Return('objs')
修改Kconfig文件,加入NT35510驱动的支持
menu "Graphic"
config OS_USING_GRAPHIC
bool "Using graphic devices"
default n
if OS_USING_GRAPHIC
config OS_GRAPHIC_LCD_WIDTH
int "Graphic width"
default 240
config OS_GRAPHIC_LCD_HEIGHT
int "Graphic height"
default 240
choice
prompt "Graphic format"
default OS_GRAPHIC_LCD_FORMAT_RGB565
config OS_GRAPHIC_LCD_FORMAT_RGB565
bool "RGB565"
config OS_GRAPHIC_LCD_FORMAT_RGB888
bool "RGB888"
config OS_GRAPHIC_LCD_FORMAT_ARGB8888
bool "ARGB8888"
endchoice
config OS_GRAPHIC_DRAW_ENABLE
bool "Enable draw functions"
default n
config OS_GRAPHIC_GPU_ENABLE
bool "Enable hardware accelerator"
default n
config OS_USING_DSI
bool "Use DSI"
default n
if OS_USING_DSI
config OS_USING_DSI_RST
int "dsi rst io"
default 159
endif
config BSP_USING_OTM8009A
bool "Use otm8009a"
default n
if OS_USING_DSI && BSP_USING_OTM8009A
config BSP_OTM8009A_DSI_CHANNEL
int "otm8009a DSI channel id"
default 0
endif
menuconfig BSP_USING_ILI9341
bool "Enable ili9341"
default n
if BSP_USING_ILI9341
config BSP_ILI9341_SPI_BUS_NAME
string "ili9341 spi bus name"
default "spi5"
config BSP_ILI9341_SPI_CS
int "ili9341 spi cs io"
default 34
config BSP_ILI9341_WRX
int "ili9341 wrx io"
default 61
endif
menuconfig OS_USING_ST7789VW
bool "Use st7789vw"
select OS_USING_SPI
select BSP_USING_SPI
default n
if OS_USING_ST7789VW
config OS_ST7789VW_SPI_BUS_NAME
string "st7789vw spi bus name"
default "spi1"
config OS_ST7789VW_SPI_BUS_MODE
int "st7789vw spi bus mode"
default 0
config OS_ST7789VW_SPI_CS_PIN
int "st7789vw spi cs pin"
default 62
config OS_ST7789VW_PWR_PIN
int "st7789vw power pin"
default 4
config OS_ST7789VW_PWR_PIN_ACTIVE
int "st7789vw power pin active level"
default 1
config OS_ST7789VW_DC_PIN
int "st7789vw dc pin"
default 59
config OS_ST7789VW_RES_PIN
int "st7789vw reset pin"
default 6
endif
menuconfig BSP_USING_ATKTFLCD9341
bool "Enable atk_tflcd9341"
default n
if BSP_USING_ATKTFLCD9341
config BSP_ATK9341_BL_PIN
int "atk_tflcd9341 backlight pin"
default "16"
endif
menuconfig BSP_USING_ATKTFLCD35510
bool "Enable atk_tflcd35510"
default n
if BSP_USING_ATKTFLCD35510
config BSP_ATK9341_BL_PIN
int "atk_tflcd35510 backlight pin"
default "16"
endif
menuconfig BSP_USING_ATKRGBLCD
bool "Enable atk_rgblcd"
default n
if BSP_USING_ATKRGBLCD
config BSP_ATKRGB_BL_PIN
int "atk_rgblcd backlight pin"
default "21"
endif
endif
endmenu
menuconfig设置为NT35510的屏幕驱动,屏幕宽为480高为800
编译烧录到开发板,适配成功