EPS32 ILI9341 初次接触彩屏

EPS32 ILI9341 初次接触彩屏,第1张

ESP的sdk外设spi中有lcd的例程,先是借鉴了网上的博友的代码,显示字符、汉字是可以了,但是不能满足界面显示的需求,还是根据它的例程,将各个API重写一遍,esp例程是用dma方式存数据,用来刷屏快速一点,话不多说,上代码

#define LCD_HOST    HSPI_HOST
#define DMA_CHAN    2
/* SPI Master example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include 

#define PIN_NUM_MISO 25
#define PIN_NUM_MOSI 23
#define PIN_NUM_CLK  19
#define PIN_NUM_CS   22

#define PIN_NUM_DC   21
#define PIN_NUM_RST  18
#define PIN_NUM_BCKL 5

#endif

//To speed up transfers, every SPI transfer sends a bunch of lines. This define specifies how many. More means more memory use,
//but less overhead for setting up / finishing transfers. Make sure 240 is dividable by this.
#define PARALLEL_LINES 16

/*
 The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct.
*/
typedef struct {
    uint8_t cmd;
    uint8_t data[16];
    uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds.
} lcd_init_cmd_t;

typedef enum {
    LCD_TYPE_ILI = 1,
    LCD_TYPE_ST,
    LCD_TYPE_MAX,
} type_lcd_t;

#define ILI9341_HEIGHT		240
#define ILI9341_WIDTH		320
#define WHITE				0xFFFF
#define	BLACK				0x0000
#define	RED					0xF800
#define YELLOW				0XFF00
#define GREEN				0x07E0
#define BLUE				0x001F
static spi_device_handle_t ili_spi;
#define BigtoLittle16(A)   (( ((uint16_t)(A) & 0xff00) >> 8) | \  
                            (((uint16_t)(A) & 0x00ff) << 8))   

typedef struct 
{
       unsigned char Index[2];	
       char Msk[32];
}typFNT_GB16; 
const unsigned char ascll_1206[95][12]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
{0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x00,0x04,0x00,0x00},/*"!",1*/
{0x00,0x14,0x0A,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/
{0x00,0x00,0x14,0x14,0x3F,0x14,0x0A,0x3F,0x0A,0x0A,0x00,0x00},/*"#",3*/
{0x00,0x04,0x1E,0x15,0x05,0x06,0x0C,0x14,0x15,0x0F,0x04,0x00},/*"$",4*/
{0x00,0x00,0x12,0x15,0x0D,0x0A,0x14,0x2C,0x2A,0x12,0x00,0x00},/*"%",5*/
{0x00,0x00,0x04,0x0A,0x0A,0x1E,0x15,0x15,0x09,0x36,0x00,0x00},/*"&",6*/
{0x00,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
{0x00,0x20,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x20,0x00},/*"(",8*/
{0x00,0x02,0x04,0x08,0x08,0x08,0x08,0x08,0x08,0x04,0x02,0x00},/*")",9*/
{0x00,0x00,0x00,0x04,0x15,0x0E,0x0E,0x15,0x04,0x00,0x00,0x00},/*"*",10*/
{0x00,0x00,0x04,0x04,0x04,0x1F,0x04,0x04,0x04,0x00,0x00,0x00},/*"+",11*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x01},/*",",12*/
{0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",13*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00},/*".",14*/
{0x00,0x10,0x08,0x08,0x08,0x04,0x04,0x02,0x02,0x02,0x01,0x00},/*"/",15*/
{0x00,0x00,0x0E,0x11,0x11,0x11,0x11,0x11,0x11,0x0E,0x00,0x00},/*"0",16*/
{0x00,0x00,0x04,0x06,0x04,0x04,0x04,0x04,0x04,0x0E,0x00,0x00},/*"1",17*/
{0x00,0x00,0x0E,0x11,0x11,0x08,0x04,0x02,0x01,0x1F,0x00,0x00},/*"2",18*/
{0x00,0x00,0x0E,0x11,0x10,0x0C,0x10,0x10,0x11,0x0E,0x00,0x00},/*"3",19*/
{0x00,0x00,0x08,0x0C,0x0A,0x0A,0x09,0x1E,0x08,0x18,0x00,0x00},/*"4",20*/
{0x00,0x00,0x1F,0x01,0x01,0x0F,0x10,0x10,0x11,0x0E,0x00,0x00},/*"5",21*/
{0x00,0x00,0x0E,0x09,0x01,0x0F,0x11,0x11,0x11,0x0E,0x00,0x00},/*"6",22*/
{0x00,0x00,0x1F,0x09,0x08,0x04,0x04,0x04,0x04,0x04,0x00,0x00},/*"7",23*/
{0x00,0x00,0x0E,0x11,0x11,0x0E,0x11,0x11,0x11,0x0E,0x00,0x00},/*"8",24*/
{0x00,0x00,0x0E,0x11,0x11,0x11,0x1E,0x10,0x12,0x0E,0x00,0x00},/*"9",25*/
{0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x04,0x00,0x00},/*":",26*/
{0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x04,0x00},/*";",27*/
{0x00,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x00,0x00},/*"<",28*/
{0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x1F,0x00,0x00,0x00,0x00},/*"=",29*/
{0x00,0x02,0x04,0x08,0x10,0x20,0x10,0x08,0x04,0x02,0x00,0x00},/*">",30*/
{0x00,0x00,0x0E,0x11,0x11,0x08,0x04,0x04,0x00,0x04,0x00,0x00},/*"?",31*/
{0x00,0x00,0x0E,0x11,0x19,0x15,0x15,0x1D,0x01,0x1E,0x00,0x00},/*"@",32*/
{0x00,0x00,0x04,0x04,0x0C,0x0A,0x0A,0x1E,0x12,0x33,0x00,0x00},/*"A",33*/
{0x00,0x00,0x0F,0x12,0x12,0x0E,0x12,0x12,0x12,0x0F,0x00,0x00},/*"B",34*/
{0x00,0x00,0x1E,0x11,0x01,0x01,0x01,0x01,0x11,0x0E,0x00,0x00},/*"C",35*/
{0x00,0x00,0x0F,0x12,0x12,0x12,0x12,0x12,0x12,0x0F,0x00,0x00},/*"D",36*/
{0x00,0x00,0x1F,0x12,0x0A,0x0E,0x0A,0x02,0x12,0x1F,0x00,0x00},/*"E",37*/
{0x00,0x00,0x1F,0x12,0x0A,0x0E,0x0A,0x02,0x02,0x07,0x00,0x00},/*"F",38*/
{0x00,0x00,0x1C,0x12,0x01,0x01,0x39,0x11,0x12,0x0C,0x00,0x00},/*"G",39*/
{0x00,0x00,0x33,0x12,0x12,0x1E,0x12,0x12,0x12,0x33,0x00,0x00},/*"H",40*/
{0x00,0x00,0x1F,0x04,0x04,0x04,0x04,0x04,0x04,0x1F,0x00,0x00},/*"I",41*/
{0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x09,0x07,0x00},/*"J",42*/
{0x00,0x00,0x37,0x12,0x0A,0x06,0x0A,0x0A,0x12,0x37,0x00,0x00},/*"K",43*/
{0x00,0x00,0x07,0x02,0x02,0x02,0x02,0x02,0x22,0x3F,0x00,0x00},/*"L",44*/
{0x00,0x00,0x1B,0x1B,0x1B,0x1B,0x15,0x15,0x15,0x15,0x00,0x00},/*"M",45*/
{0x00,0x00,0x3B,0x12,0x16,0x16,0x1A,0x1A,0x12,0x17,0x00,0x00},/*"N",46*/
{0x00,0x00,0x0E,0x11,0x11,0x11,0x11,0x11,0x11,0x0E,0x00,0x00},/*"O",47*/
{0x00,0x00,0x0F,0x12,0x12,0x0E,0x02,0x02,0x02,0x07,0x00,0x00},/*"P",48*/
{0x00,0x00,0x0E,0x11,0x11,0x11,0x11,0x17,0x19,0x0E,0x18,0x00},/*"Q",49*/
{0x00,0x00,0x0F,0x12,0x12,0x0E,0x0A,0x12,0x12,0x37,0x00,0x00},/*"R",50*/
{0x00,0x00,0x1E,0x11,0x01,0x06,0x08,0x10,0x11,0x0F,0x00,0x00},/*"S",51*/
{0x00,0x00,0x1F,0x15,0x04,0x04,0x04,0x04,0x04,0x0E,0x00,0x00},/*"T",52*/
{0x00,0x00,0x33,0x12,0x12,0x12,0x12,0x12,0x12,0x0C,0x00,0x00},/*"U",53*/
{0x00,0x00,0x33,0x12,0x12,0x0A,0x0A,0x0C,0x04,0x04,0x00,0x00},/*"V",54*/
{0x00,0x00,0x15,0x15,0x15,0x0E,0x0A,0x0A,0x0A,0x0A,0x00,0x00},/*"W",55*/
{0x00,0x00,0x1B,0x0A,0x0A,0x04,0x04,0x0A,0x0A,0x1B,0x00,0x00},/*"X",56*/
{0x00,0x00,0x1B,0x0A,0x0A,0x04,0x04,0x04,0x04,0x0E,0x00,0x00},/*"Y",57*/
{0x00,0x00,0x1F,0x09,0x08,0x04,0x04,0x02,0x12,0x1F,0x00,0x00},/*"Z",58*/
{0x00,0x1C,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x1C,0x00},/*"[",59*/
{0x00,0x02,0x02,0x02,0x04,0x04,0x08,0x08,0x08,0x10,0x00,0x00},/*"\",60*/
{0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x0E,0x00},/*"]",61*/
{0x00,0x04,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F},/*"_",63*/
{0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/
{0x00,0x00,0x00,0x00,0x00,0x0C,0x12,0x1C,0x12,0x3C,0x00,0x00},/*"a",65*/
{0x00,0x00,0x03,0x02,0x02,0x0E,0x12,0x12,0x12,0x0E,0x00,0x00},/*"b",66*/
{0x00,0x00,0x00,0x00,0x00,0x1C,0x12,0x02,0x02,0x1C,0x00,0x00},/*"c",67*/
{0x00,0x00,0x18,0x10,0x10,0x1C,0x12,0x12,0x12,0x3C,0x00,0x00},/*"d",68*/
{0x00,0x00,0x00,0x00,0x00,0x0C,0x12,0x1E,0x02,0x1C,0x00,0x00},/*"e",69*/
{0x00,0x00,0x38,0x04,0x04,0x1E,0x04,0x04,0x04,0x1E,0x00,0x00},/*"f",70*/
{0x00,0x00,0x00,0x00,0x00,0x3C,0x12,0x0C,0x02,0x1E,0x22,0x1C},/*"g",71*/
{0x00,0x00,0x03,0x02,0x02,0x0E,0x12,0x12,0x12,0x37,0x00,0x00},/*"h",72*/
{0x00,0x00,0x04,0x00,0x00,0x06,0x04,0x04,0x04,0x0E,0x00,0x00},/*"i",73*/
{0x00,0x00,0x08,0x00,0x00,0x0C,0x08,0x08,0x08,0x08,0x08,0x07},/*"j",74*/
{0x00,0x00,0x03,0x02,0x02,0x3A,0x0A,0x0E,0x12,0x37,0x00,0x00},/*"k",75*/
{0x00,0x00,0x07,0x04,0x04,0x04,0x04,0x04,0x04,0x1F,0x00,0x00},/*"l",76*/
{0x00,0x00,0x00,0x00,0x00,0x0F,0x15,0x15,0x15,0x15,0x00,0x00},/*"m",77*/
{0x00,0x00,0x00,0x00,0x00,0x0F,0x12,0x12,0x12,0x37,0x00,0x00},/*"n",78*/
{0x00,0x00,0x00,0x00,0x00,0x0C,0x12,0x12,0x12,0x0C,0x00,0x00},/*"o",79*/
{0x00,0x00,0x00,0x00,0x00,0x0F,0x12,0x12,0x12,0x0E,0x02,0x07},/*"p",80*/
{0x00,0x00,0x00,0x00,0x00,0x1C,0x12,0x12,0x12,0x1C,0x10,0x38},/*"q",81*/
{0x00,0x00,0x00,0x00,0x00,0x1B,0x06,0x02,0x02,0x07,0x00,0x00},/*"r",82*/
{0x00,0x00,0x00,0x00,0x00,0x1E,0x02,0x0C,0x10,0x1E,0x00,0x00},/*"s",83*/
{0x00,0x00,0x00,0x04,0x04,0x0E,0x04,0x04,0x04,0x18,0x00,0x00},/*"t",84*/
{0x00,0x00,0x00,0x00,0x00,0x1B,0x12,0x12,0x12,0x3C,0x00,0x00},/*"u",85*/
{0x00,0x00,0x00,0x00,0x00,0x37,0x12,0x0A,0x0C,0x04,0x00,0x00},/*"v",86*/
{0x00,0x00,0x00,0x00,0x00,0x15,0x15,0x0E,0x0A,0x0A,0x00,0x00},/*"w",87*/
{0x00,0x00,0x00,0x00,0x00,0x1B,0x0A,0x04,0x0A,0x1B,0x00,0x00},/*"x",88*/
{0x00,0x00,0x00,0x00,0x00,0x37,0x12,0x0A,0x0C,0x04,0x04,0x03},/*"y",89*/
{0x00,0x00,0x00,0x00,0x00,0x1E,0x08,0x04,0x04,0x1E,0x00,0x00},/*"z",90*/
{0x00,0x18,0x08,0x08,0x08,0x04,0x08,0x08,0x08,0x08,0x18,0x00},/*"{",91*/
{0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08},/*"|",92*/
{0x00,0x06,0x04,0x04,0x04,0x08,0x04,0x04,0x04,0x04,0x06,0x00},/*"}",93*/
{0x02,0x25,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} /*"~",94*/
}; 
const unsigned char ascll_1608[95][16]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
{0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x18,0x18,0x00,0x00},/*"!",1*/
{0x00,0x48,0x6C,0x24,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/
{0x00,0x00,0x00,0x24,0x24,0x24,0x7F,0x12,0x12,0x12,0x7F,0x12,0x12,0x12,0x00,0x00},/*"#",3*/
{0x00,0x00,0x08,0x1C,0x2A,0x2A,0x0A,0x0C,0x18,0x28,0x28,0x2A,0x2A,0x1C,0x08,0x08},/*"$",4*/
{0x00,0x00,0x00,0x22,0x25,0x15,0x15,0x15,0x2A,0x58,0x54,0x54,0x54,0x22,0x00,0x00},/*"%",5*/
{0x00,0x00,0x00,0x0C,0x12,0x12,0x12,0x0A,0x76,0x25,0x29,0x11,0x91,0x6E,0x00,0x00},/*"&",6*/
{0x00,0x06,0x06,0x04,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
{0x00,0x40,0x20,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x10,0x10,0x20,0x40,0x00},/*"(",8*/
{0x00,0x02,0x04,0x08,0x08,0x10,0x10,0x10,0x10,0x10,0x10,0x08,0x08,0x04,0x02,0x00},/*")",9*/
{0x00,0x00,0x00,0x00,0x08,0x08,0x6B,0x1C,0x1C,0x6B,0x08,0x08,0x00,0x00,0x00,0x00},/*"*",10*/
{0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x7F,0x08,0x08,0x08,0x08,0x00,0x00,0x00},/*"+",11*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x04,0x03},/*",",12*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",13*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x00,0x00},/*".",14*/
{0x00,0x00,0x80,0x40,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,0x02,0x02,0x00},/*"/",15*/
{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"0",16*/
{0x00,0x00,0x00,0x08,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"1",17*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x20,0x20,0x10,0x08,0x04,0x42,0x7E,0x00,0x00},/*"2",18*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x20,0x18,0x20,0x40,0x40,0x42,0x22,0x1C,0x00,0x00},/*"3",19*/
{0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x22,0x7E,0x20,0x20,0x78,0x00,0x00},/*"4",20*/
{0x00,0x00,0x00,0x7E,0x02,0x02,0x02,0x1A,0x26,0x40,0x40,0x42,0x22,0x1C,0x00,0x00},/*"5",21*/
{0x00,0x00,0x00,0x38,0x24,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x24,0x18,0x00,0x00},/*"6",22*/
{0x00,0x00,0x00,0x7E,0x22,0x22,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00},/*"7",23*/	 
{0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00},/*"8",24*/
{0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x64,0x58,0x40,0x40,0x24,0x1C,0x00,0x00},/*"9",25*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00},/*":",26*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x04},/*";",27*/
{0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x00},/*"<",28*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},/*"=",29*/
{0x00,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00},/*">",30*/
{0x00,0x00,0x00,0x3C,0x42,0x42,0x46,0x40,0x20,0x10,0x10,0x00,0x18,0x18,0x00,0x00},/*"?",31*/
{0x00,0x00,0x00,0x1C,0x22,0x5A,0x55,0x55,0x55,0x55,0x2D,0x42,0x22,0x1C,0x00,0x00},/*"@",32*/
{0x00,0x00,0x00,0x08,0x08,0x18,0x14,0x14,0x24,0x3C,0x22,0x42,0x42,0xE7,0x00,0x00},/*"A",33*/
{0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x1E,0x22,0x42,0x42,0x42,0x22,0x1F,0x00,0x00},/*"B",34*/
{0x00,0x00,0x00,0x7C,0x42,0x42,0x01,0x01,0x01,0x01,0x01,0x42,0x22,0x1C,0x00,0x00},/*"C",35*/
{0x00,0x00,0x00,0x1F,0x22,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1F,0x00,0x00},/*"D",36*/
{0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x42,0x42,0x3F,0x00,0x00},/*"E",37*/
{0x00,0x00,0x00,0x3F,0x42,0x12,0x12,0x1E,0x12,0x12,0x02,0x02,0x02,0x07,0x00,0x00},/*"F",38*/
{0x00,0x00,0x00,0x3C,0x22,0x22,0x01,0x01,0x01,0x71,0x21,0x22,0x22,0x1C,0x00,0x00},/*"G",39*/
{0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"H",40*/
{0x00,0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"I",41*/
{0x00,0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x11,0x0F},/*"J",42*/
{0x00,0x00,0x00,0x77,0x22,0x12,0x0A,0x0E,0x0A,0x12,0x12,0x22,0x22,0x77,0x00,0x00},/*"K",43*/
{0x00,0x00,0x00,0x07,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x7F,0x00,0x00},/*"L",44*/
{0x00,0x00,0x00,0x77,0x36,0x36,0x36,0x36,0x2A,0x2A,0x2A,0x2A,0x2A,0x6B,0x00,0x00},/*"M",45*/
{0x00,0x00,0x00,0xE3,0x46,0x46,0x4A,0x4A,0x52,0x52,0x52,0x62,0x62,0x47,0x00,0x00},/*"N",46*/
{0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x22,0x1C,0x00,0x00},/*"O",47*/
{0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x42,0x3E,0x02,0x02,0x02,0x02,0x07,0x00,0x00},/*"P",48*/
{0x00,0x00,0x00,0x1C,0x22,0x41,0x41,0x41,0x41,0x41,0x4D,0x53,0x32,0x1C,0x60,0x00},/*"Q",49*/
{0x00,0x00,0x00,0x3F,0x42,0x42,0x42,0x3E,0x12,0x12,0x22,0x22,0x42,0xC7,0x00,0x00},/*"R",50*/
{0x00,0x00,0x00,0x7C,0x42,0x42,0x02,0x04,0x18,0x20,0x40,0x42,0x42,0x3E,0x00,0x00},/*"S",51*/
{0x00,0x00,0x00,0x7F,0x49,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00},/*"T",52*/
{0x00,0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"U",53*/
{0x00,0x00,0x00,0xE7,0x42,0x42,0x22,0x24,0x24,0x14,0x14,0x18,0x08,0x08,0x00,0x00},/*"V",54*/
{0x00,0x00,0x00,0x6B,0x49,0x49,0x49,0x49,0x55,0x55,0x36,0x22,0x22,0x22,0x00,0x00},/*"W",55*/
{0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x18,0x18,0x18,0x24,0x24,0x42,0xE7,0x00,0x00},/*"X",56*/
{0x00,0x00,0x00,0x77,0x22,0x22,0x14,0x14,0x08,0x08,0x08,0x08,0x08,0x1C,0x00,0x00},/*"Y",57*/
{0x00,0x00,0x00,0x7E,0x21,0x20,0x10,0x10,0x08,0x04,0x04,0x42,0x42,0x3F,0x00,0x00},/*"Z",58*/
{0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00},/*"[",59*/
{0x00,0x00,0x02,0x02,0x04,0x04,0x08,0x08,0x08,0x10,0x10,0x20,0x20,0x20,0x40,0x40},/*"\",60*/
{0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00},/*"]",61*/
{0x00,0x38,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF},/*"_",63*/
{0x00,0x06,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x78,0x44,0x42,0x42,0xFC,0x00,0x00},/*"a",65*/
{0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x26,0x1A,0x00,0x00},/*"b",66*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x44,0x02,0x02,0x02,0x44,0x38,0x00,0x00},/*"c",67*/
{0x00,0x00,0x00,0x60,0x40,0x40,0x40,0x78,0x44,0x42,0x42,0x42,0x64,0xD8,0x00,0x00},/*"d",68*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x02,0x02,0x42,0x3C,0x00,0x00},/*"e",69*/
{0x00,0x00,0x00,0xF0,0x88,0x08,0x08,0x7E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"f",70*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x22,0x22,0x1C,0x02,0x3C,0x42,0x42,0x3C},/*"g",71*/
{0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x3A,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"h",72*/
{0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"i",73*/
{0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x38,0x20,0x20,0x20,0x20,0x20,0x20,0x22,0x1E},/*"j",74*/
{0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x72,0x12,0x0A,0x16,0x12,0x22,0x77,0x00,0x00},/*"k",75*/
{0x00,0x00,0x00,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00},/*"l",76*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x92,0x92,0x92,0x92,0x92,0xB7,0x00,0x00},/*"m",77*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3B,0x46,0x42,0x42,0x42,0x42,0xE7,0x00,0x00},/*"n",78*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00},/*"o",79*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x26,0x42,0x42,0x42,0x22,0x1E,0x02,0x07},/*"p",80*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x44,0x42,0x42,0x42,0x44,0x78,0x40,0xE0},/*"q",81*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x4C,0x04,0x04,0x04,0x04,0x1F,0x00,0x00},/*"r",82*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x42,0x02,0x3C,0x40,0x42,0x3E,0x00,0x00},/*"s",83*/
{0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x3E,0x08,0x08,0x08,0x08,0x08,0x30,0x00,0x00},/*"t",84*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x42,0x42,0x42,0x42,0x62,0xDC,0x00,0x00},/*"u",85*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x08,0x08,0x00,0x00},/*"v",86*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xEB,0x49,0x49,0x55,0x55,0x22,0x22,0x00,0x00},/*"w",87*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x24,0x18,0x18,0x18,0x24,0x6E,0x00,0x00},/*"x",88*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE7,0x42,0x24,0x24,0x14,0x18,0x08,0x08,0x07},/*"y",89*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x22,0x10,0x08,0x08,0x44,0x7E,0x00,0x00},/*"z",90*/
{0x00,0xC0,0x20,0x20,0x20,0x20,0x20,0x10,0x20,0x20,0x20,0x20,0x20,0x20,0xC0,0x00},/*"{",91*/
{0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10},/*"|",92*/
{0x00,0x06,0x08,0x08,0x08,0x08,0x08,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x06,0x00},/*"}",93*/
{0x0C,0x32,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",94*/
}; 

//Place data into DRAM. Constant data gets placed into DROM by default, which is not accessible by DMA.

DRAM_ATTR static const lcd_init_cmd_t ili_init_cmds[]={
    /* Power contorl B, power control = 0, DC_ENA = 1 */
    {0xCF, {0x00, 0x83, 0X30}, 3},
    /* Power on sequence control,
     * cp1 keeps 1 frame, 1st frame enable
     * vcl = 0, ddvdh=3, vgh=1, vgl=2
     * DDVDH_ENH=1
     */
    {0xED, {0x64, 0x03, 0X12, 0X81}, 4},
    /* Driver timing control A,
     * non-overlap=default +1
     * EQ=default - 1, CR=default
     * pre-charge=default - 1
     */
    {0xE8, {0x85, 0x01, 0x79}, 3},
    /* Power control A, Vcore=1.6V, DDVDH=5.6V */
    {0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5},
    /* Pump ratio control, DDVDH=2xVCl */
    {0xF7, {0x20}, 1},
    /* Driver timing control, all=0 unit */
    {0xEA, {0x00, 0x00}, 2},
    /* Power control 1, GVDD=4.75V */
    {0xC0, {0x26}, 1},
    /* Power control 2, DDVDH=VCl*2, VGH=VCl*7, VGL=-VCl*3 */
    {0xC1, {0x11}, 1},
    /* VCOM control 1, VCOMH=4.025V, VCOML=-0.950V */
    {0xC5, {0x35, 0x3E}, 2},
    /* VCOM control 2, VCOMH=VMH-2, VCOML=VML-2 */
    {0xC7, {0xBE}, 1},
    /* Memory access contorl, MX=MY=0, MV=1, ML=0, BGR=1, MH=0 */
    {0x36, {0x28}, 1},
    /* Pixel format, 16bits/pixel for RGB/MCU interface */
    {0x3A, {0x55}, 1},
    /* Frame rate control, f=fosc, 70Hz fps */
    {0xB1, {0x00, 0x1B}, 2},
    /* Enable 3G, disabled */
    {0xF2, {0x08}, 1},
    /* Gamma set, curve 1 */
    {0x26, {0x01}, 1},
    /* Positive gamma correction */
    {0xE0, {0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0X87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00}, 15},
    /* Negative gamma correction */
    {0XE1, {0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F}, 15},
    /* Column address set, SC=0, EC=0xEF */
    {0x2A, {0x00, 0x00, 0x00, 0xEF}, 4},
    /* Page address set, SP=0, EP=0x013F */
    {0x2B, {0x00, 0x00, 0x01, 0x3f}, 4},
    /* Memory write */
    {0x2C, {0}, 0},
    /* Entry mode set, Low vol detect disabled, normal display */
    {0xB7, {0x07}, 1},
    /* Display function control */
    {0xB6, {0x0A, 0x82, 0x27, 0x00}, 4},
    /* Sleep out */
    {0x11, {0}, 0x80},
    /* Display on */
    {0x29, {0}, 0x80},
    {0, {0}, 0xff},
};

/* Send a command to the LCD. Uses spi_device_polling_transmit, which waits
 * until the transfer is complete.
 *
 * Since command transactions are usually small, they are handled in polling
 * mode for higher speed. The overhead of interrupt transactions is more than
 * just waiting for the transaction to complete.
 */
void lcd_cmd(spi_device_handle_t spi, const uint8_t cmd)
{
    esp_err_t ret;
    spi_transaction_t t;
    memset(&t, 0, sizeof(t));       //Zero out the transaction
    t.length=8;                     //Command is 8 bits
    t.tx_buffer=&cmd;               //The data is the cmd itself
    t.user=(void*)0;                //D/C needs to be set to 0
    ret=spi_device_polling_transmit(spi, &t);  //Transmit!
    assert(ret==ESP_OK);            //Should have had no issues.
}

/* Send data to the LCD. Uses spi_device_polling_transmit, which waits until the
 * transfer is complete.
 *
 * Since data transactions are usually small, they are handled in polling
 * mode for higher speed. The overhead of interrupt transactions is more than
 * just waiting for the transaction to complete.
 */
void lcd_data(spi_device_handle_t spi, const uint8_t *data, int len)
{
    esp_err_t ret;
    spi_transaction_t t;
    if (len==0) return;             //no need to send anything
    memset(&t, 0, sizeof(t));       //Zero out the transaction
    t.length=len*8;                 //Len is in bytes, transaction length is in bits.
    t.tx_buffer=data;               //Data
    t.user=(void*)1;                //D/C needs to be set to 1
    ret=spi_device_polling_transmit(spi, &t);  //Transmit!
    assert(ret==ESP_OK);            //Should have had no issues.
}

//This function is called (in irq context!) just before a transmission starts. It will
//set the D/C line to the value indicated in the user field.
void lcd_spi_pre_transfer_callback(spi_transaction_t *t)
{
    int dc=(int)t->user;
    gpio_set_level(PIN_NUM_DC, dc);
}

uint32_t lcd_get_id(spi_device_handle_t spi)
{
    //get_id cmd
    lcd_cmd(spi, 0x04);

    spi_transaction_t t;
    memset(&t, 0, sizeof(t));
    t.length=8*3;
    t.flags = SPI_TRANS_USE_RXDATA;
    t.user = (void*)1;

    esp_err_t ret = spi_device_polling_transmit(spi, &t);
    assert( ret == ESP_OK );

    return *(uint32_t*)t.rx_data;
}

//Initialize the display
void lcd_init(spi_device_handle_t spi)
{
    int cmd=0;
    const lcd_init_cmd_t* lcd_init_cmds;

    //Initialize non-SPI GPIOs
    gpio_set_direction(PIN_NUM_DC, GPIO_MODE_OUTPUT);
    gpio_set_direction(PIN_NUM_RST, GPIO_MODE_OUTPUT);
    gpio_set_direction(PIN_NUM_BCKL, GPIO_MODE_OUTPUT);

    //Reset the display
    gpio_set_level(PIN_NUM_RST, 0);
    vTaskDelay(100 / portTICK_RATE_MS);
    gpio_set_level(PIN_NUM_RST, 1);
    vTaskDelay(100 / portTICK_RATE_MS);

    //detect LCD type
    uint32_t lcd_id = lcd_get_id(ili_spi);
    int lcd_detected_type = 0;
    int lcd_type;

    printf("LCD ID: %08X\n", lcd_id);
    if ( lcd_id == 0 ) {
        //zero, ili
        lcd_detected_type = LCD_TYPE_ILI;
        printf("ILI9341 detected.\n");
    } 

#ifdef CONFIG_LCD_TYPE_AUTO
    lcd_type = lcd_detected_type;
#elif defined( CONFIG_LCD_TYPE_ST7789V )
    printf("kconfig: force CONFIG_LCD_TYPE_ST7789V.\n");
    lcd_type = LCD_TYPE_ST;
#elif defined( CONFIG_LCD_TYPE_ILI9341 )
    printf("kconfig: force CONFIG_LCD_TYPE_ILI9341.\n");
    lcd_type = LCD_TYPE_ILI;
#endif

    printf("LCD ILI9341 initialization.\n");
    lcd_init_cmds = ili_init_cmds;

    //Send all the commands
    while (lcd_init_cmds[cmd].databytes!=0xff) {
        lcd_cmd(ili_spi, lcd_init_cmds[cmd].cmd);
        lcd_data(ili_spi, lcd_init_cmds[cmd].data, lcd_init_cmds[cmd].databytes&0x1F);
        if (lcd_init_cmds[cmd].databytes&0x80) {
            vTaskDelay(100 / portTICK_RATE_MS);
			printf("cmd:%d %02x\n", cmd, lcd_init_cmds[cmd].cmd);
        }
        cmd++;
    }

    ///Enable backlight
    gpio_set_level(PIN_NUM_BCKL, 1);
}


/* To send a set of lines we have to send a command, 2 data bytes, another command, 2 more data bytes and another command
 * before sending the line data itself; a total of 6 transactions. (We can't put all of this in just one transaction
 * because the D/C line needs to be toggled in the middle.)
 * This routine queues these commands up as interrupt transactions so they get
 * sent faster (compared to calling spi_device_transmit several times), and at
 * the mean while the lines for next transactions can get calculated.
 */
 
static void send_point(spi_device_handle_t spi,int x0, int xpos, int y0, int ypos, uint16_t *linedata)
{
    esp_err_t ret;
    int x;
    //Transaction descriptors. Declared static so they're not allocated on the stack; we need this memory even when this
    //function is finished because the SPI driver needs access to it even while we're already calculating the next line.
    static spi_transaction_t trans[6];

    //In theory, it's better to initialize trans and data only once and hang on to the initialized
    //variables. We allocate them on the stack, so we need to re-init them each call.
    for (x=0; x<6; x++) {
        memset(&trans[x], 0, sizeof(spi_transaction_t));
        if ((x&1)==0) {
            //Even transfers are commands
            trans[x].length=8;
            trans[x].user=(void*)0;
        } else {
            //Odd transfers are data
            trans[x].length=8*4;
            trans[x].user=(void*)1;
        }
        trans[x].flags=SPI_TRANS_USE_TXDATA;
    }
    trans[0].tx_data[0]=0x2A;           //Column Address Set
    trans[1].tx_data[0]=x0>>8;              //Start Col High
    trans[1].tx_data[1]=x0&0xff;              //Start Col Low
    trans[1].tx_data[2]=xpos>>8;       //End Col High
    trans[1].tx_data[3]=xpos&0xff;     //End Col Low
    trans[2].tx_data[0]=0x2B;           //Page address set
    trans[3].tx_data[0]=y0>>8;        //Start page high
    trans[3].tx_data[1]=y0&0xff;      //start page low
    trans[3].tx_data[2]=ypos>>8;    //end page high
    trans[3].tx_data[3]=ypos&0xff;  //end page low
    trans[4].tx_data[0]=0x2C;           //memory write
    trans[5].tx_buffer=linedata;        //finally send the line data   
	trans[5].length=(xpos-x0)*2*8*(ypos-y0);          //Data length, in bits
	if(xpos-x0 == 0 || ypos-y0 == 0)
		trans[5].length = 16;


    trans[5].flags=0; //undo SPI_TRANS_USE_TXDATA flag

    //Queue all transactions.
    for (x=0; x<6; x++) {
        ret=spi_device_queue_trans(spi, &trans[x], portMAX_DELAY);
        assert(ret==ESP_OK);
    }

    //When we are here, the SPI driver is busy (in the background) getting the transactions sent. That happens
    //mostly using DMA, so the CPU doesn't have much to do here. We're not going to wait for the transaction to
    //finish because we may as well spend the time calculating the next line. When that is done, we can call
    //send_line_finish, which will wait for the transfers to be done and check their status.
}

static void send_lines(spi_device_handle_t spi, int ypos, uint16_t *linedata)
{
	send_point(spi, 0, 320, ypos, ypos+PARALLEL_LINES, linedata);
}
static void send_line_finish(spi_device_handle_t spi)
{
    spi_transaction_t *rtrans;
    esp_err_t ret;
    //Wait for all 6 transactions to be done and get back the results.
    for (int x=0; x<6; x++) {
        ret=spi_device_get_trans_result(spi, &rtrans, portMAX_DELAY);
        assert(ret==ESP_OK);
        //We could inspect rtrans now if we received any info back. The LCD is treated as write-only, though.
    }
}


void lcd_drawpoint(uint16_t x0, uint16_t y0, uint16_t color)
{
	uint16_t c = BigtoLittle16(color);
/*way one */
	send_point(ili_spi, x0, x0+1, y0, y0+1,&c);
	send_line_finish(ili_spi);
/*way two */
/*   lcd_setwindows(x0, y0, x0, y0);
    lcd_data(ili_spi, &c, 2);
	
*/
}

void lcd_drawline(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
	uint16_t 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_y;
	}

	if(delta_x > delta_y) {
		distance = delta_x;
	} else {
		distance = delta_y;
	}

	for(t = 0; t <= distance + 1; t++) {
		lcd_drawpoint(urow, ucol, BLACK);
		xerr += delta_x;
		yerr += delta_y;

		if(xerr > distance) {
			xerr -= distance;
			urow += incx;
		}
		if(yerr > distance) {
			yerr -= distance;
			ucol += incy;
		}

	}

}

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);
}

void lcd_fill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t color)
{
//	uint16_t i,j;			                    //way one 速度稍慢
//	uint16_t width=ex-sx+1; 		
//	uint16_t height=ey-sy+1;
//	uint16_t c = BigtoLittle16(color);
//	
//	lcd_setwindows(sx,sy,ex-1,ey-1);
//	for(i=0;i ex)
		{
			line[i] = b;
		}
		else
		{
			line[i] = c;
		}
		j++;
		if(j == 320)
			j = 0;
	}
	for(y = sy; y < ey; y+=PARALLEL_LINES ) {
		send_lines(ili_spi, y, line);
		send_line_finish(ili_spi);
	}
	free(line);
}


void lcd_clear(uint16_t color)
{
	uint16_t y, i;
	uint16_t c = BigtoLittle16(color);
	uint16_t *line;
	line=heap_caps_malloc(320*PARALLEL_LINES*sizeof(uint16_t), MALLOC_CAP_DMA);
	for(i = 0; i < 320*PARALLEL_LINES; i++)
		line[i] = c;

	for(y = 0; y < ILI9341_HEIGHT; y+=PARALLEL_LINES ) {
		send_lines(ili_spi, y, line);
		send_line_finish(ili_spi);
	}
	free(line);
}

/*
 * param (x,y)坐标
 * param fc:前置画笔颜色	
 * param bc:背景颜色
 * param num:数值
 * param size:字体大小
 * param mode: 0填充模式 1叠加模式
*/
void lcd_showchar(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t num, uint8_t size, uint8_t mode)
{
	uint8_t temp;
	uint8_t pos, t, n = 0;
	uint16_t x0 = x;
	uint16_t front_color = BigtoLittle16(fc);
	uint16_t back_color = BigtoLittle16(bc);
	num = num - ' ';
	lcd_setwindows( x, y, x+size/2-1, y+size-1);
	if(!mode)
	{
		for(pos = 0; pos < size; pos++)
		{
			if(size == 12)
			{
				temp = ascll_1206[num][pos];				//取模方式逐行式
			}
			else if(size == 16)
			{
				temp = ascll_1608[num][pos];
			}			
			else
			{
				printf("no font \n");
				return;
			}
			for(t = 0; t < size/2 ; t++)
			{
				if(temp&0x01)
				{
//					lcd_drawpoint(x+t, y+pos, fc);               //独立使用就可以
 					lcd_data(ili_spi, &front_color, 2);			//lcd_data 发送数据方式需与setwindows 搭配使用
				}
				else
				{
//					lcd_drawpoint(x+t, y+pos, bc);
					lcd_data(ili_spi, &back_color, 2);
				}
				temp >>= 1;
			}
				
		}
	}
	else
	{
		for(pos = 0; pos < size; pos++)
		{
			if(size == 12)
			{
				temp = ascll_1206[num][pos];				//取模方式逐行式
			}
			else if(size == 16)
			{
				temp = ascll_1608[num][pos];
			}		
			else
			{
				printf("no font \n");
				return;
			}
			for(t = 0; t < size/2 ; t++)
			{
				if(temp&0x01)
				{
					lcd_drawpoint(x+t, y+pos, fc);
				}

				temp >>= 1;
			}
				
		}		
	}
	lcd_setwindows( 0, 0, ILI9341_WIDTH-1, ILI9341_HEIGHT-1);

}
void lcd_showchar_2412(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t num, uint8_t mode)
{
	uint8_t temp;
	uint8_t pos, t, n = 0;
	uint16_t x0 = x;
	uint8_t size = 24;
	num = num - ' ';
	uint16_t front_color = BigtoLittle16(fc);
	uint16_t back_color = BigtoLittle16(bc);
	lcd_setwindows( x, y, x+size/2-1, y+size-1);
	if(!mode)
	{
		for(pos = 0; pos < size*2; pos++)
		{

			temp = ascll_2412[num][pos];
					
			for(t = 0; t < 8 ; t++)
			{
				if(temp&0x01)
				{
//					lcd_drawpoint(x, y, fc);
					lcd_data(ili_spi, &front_color, 2);   			
				}
				else
				{
//					lcd_drawpoint(x, y, bc);
					lcd_data(ili_spi, &back_color, 2);
				}
				temp >>= 1;
				x++;
				if(size == 24)
				{
					if(x - x0 == 12)
					{
						x = x0;
						y++;
						break;
					}
				}
			}
				
		}
	}
	else
	{
		for(pos = 0; pos < size; pos++)
		{

			temp = ascll_2412[num][pos];

			for(t = 0; t < 8 ; t++)
			{
				if(temp&0x01)
				{
					lcd_drawpoint(x, y, fc);
				}

				temp >>= 1;
				x++;
				if(size == 24)
				{
					if(x - x0 == 12)
					{
						x = x0;
						y++;
						break;
					}
				}



			}
				
		}		
	}
	lcd_setwindows( 0, 0, ILI9341_WIDTH-1, ILI9341_HEIGHT-1);

}
void lcd_showstring(uint16_t       x, uint16_t y, uint8_t *str, uint8_t size,  uint8_t mode)
{
	uint8_t *p = str;
	while((*p <= '~') && (*p >= ' '))
	{
		if((x > ILI9341_WIDTH - 1) ||  (y > ILI9341_HEIGHT - 1))
			return;
		lcd_showchar(x, y, WHITE,BLACK,  *p, size, mode);
		x += size/2;
		p++;

	}

}

const typFNT_GB16 tfont16[] ={
{"无", {0x00,0x00,0xFC,0x0F,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0xFE,0x3F,0x20,0x01,
0x20,0x01,0x20,0x01,0x10,0x01,0x10,0x01,0x08,0x21,0x04,0x21,0x02,0x3E,0x01,0x00}},/*"无",0*/
{"线", {0x08,0x0A,0x08,0x12,0x04,0x02,0x24,0x3A,0xA2,0x07,0x1F,0x02,0x08,0x7A,0xC4,0x07,
0x02,0x22,0x3F,0x12,0x02,0x0C,0x00,0x44,0x38,0x4A,0x07,0x51,0xC2,0x60,0x00,0x40}},/*"线",1*/
{"温", {0x00,0x00,0xC4,0x1F,0x48,0x10,0x48,0x10,0xC1,0x1F,0x42,0x10,0x42,0x10,0xC8,0x1F,
0x08,0x00,0xE4,0x3F,0x27,0x25,0x24,0x25,0x24,0x25,0x24,0x25,0xF4,0x7F,0x00,0x00}},/*"温",2*/
{"度", {0x80,0x00,0x00,0x01,0xFC,0x7F,0x44,0x04,0x44,0x04,0xFC,0x3F,0x44,0x04,0x44,0x04,
0xC4,0x07,0x04,0x00,0xF4,0x0F,0x24,0x08,0x42,0x04,0x82,0x03,0x61,0x0C,0x1C,0x70}},/*"度",3*/
{"测", {0x00,0x20,0xE4,0x23,0x28,0x22,0x28,0x2A,0xA1,0x2A,0xA2,0x2A,0xA2,0x2A,0xA8,0x2A,
0xA8,0x2A,0xA4,0x2A,0xA7,0x2A,0x84,0x20,0x44,0x21,0x44,0x22,0x24,0x28,0x10,0x10}},/*"测",4*/
{"量", {0x00,0x00,0xF8,0x0F,0x08,0x08,0xF8,0x0F,0x08,0x08,0xFF,0x7F,0x00,0x00,0xF8,0x0F,
0x88,0x08,0xF8,0x0F,0x88,0x08,0xF8,0x0F,0x80,0x00,0xF8,0x0F,0x80,0x00,0xFE,0x3F}},/*"量",5*/
{"数", {0x10,0x04,0x92,0x04,0x54,0x04,0x10,0x7C,0xFF,0x22,0x54,0x22,0x92,0x22,0x11,0x25,
0x08,0x14,0x7F,0x14,0x44,0x08,0x42,0x08,0x26,0x14,0x18,0x14,0x2C,0x22,0x43,0x41}},/*"数",6*/
{"据", {0x04,0x00,0xC4,0x3F,0x44,0x20,0x44,0x20,0xDF,0x3F,0x44,0x04,0x44,0x04,0xD4,0x7F,
0x4C,0x04,0x47,0x04,0x44,0x3F,0x44,0x21,0x44,0x21,0x24,0x21,0x25,0x3F,0x12,0x21}},/*"据",7*/

};
void gui_drawfont16(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str, uint8_t mode)
{
	uint8_t i,j;
	uint8_t temp;
	uint16_t k;
	uint16_t total_num;
	uint16_t x0 = x;
	uint16_t front_color = BigtoLittle16(fc);
	uint16_t back_color = BigtoLittle16(bc);
	total_num = sizeof(tfont16)/sizeof(typFNT_GB16);				//取模方式逐行式

	for(k = 0; k < total_num; k++)
	{
		if((tfont16[k].Index[0] == *str) && (tfont16[k].Index[1] == *(str+1)))
		{
			lcd_setwindows(x, y, x+16-1, y+16-1);
			for(i = 0; i < 16*2; i++)
			{
				temp = tfont16[k].Msk[i];
				for(j = 0; j < 8; j++)
				{
					if(!mode)
					{
						if(temp & 0x01)
						{
//							lcd_drawpoint(x, y, fc);
							lcd_data(ili_spi, &front_color, 2);   
						}
						else
						{
//							lcd_drawpoint(x, y, bc);	
							lcd_data(ili_spi, &back_color, 2);   
						}
					}
					else
					{
						if(temp & 0x01)
						{
							lcd_drawpoint(x, y, fc);
						}
					}
					temp >>= 1;
					x++;
					if(x-x0 ==16)
					{
						x=x0;
						y++;
						break;
					}
				}
	
			}

		}

	}
}
typedef struct 
{
       unsigned char Index[2];	
       char Msk[72];
}typFNT_GB24; 

const typFNT_GB24 tfont24[]=
{
{"无",{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xF8,0xFF,0x1F,0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x08,0x10,0xFE,0xFF,0x3F,0x00,0x2C,0x00,0x00,0x2C,0x00,0x00,0x24,0x00,0x00,0x24,0x00,0x00,0x26,0x00,0x00,0x22,0x20,0x00,0x23,0x20,0x80,0x21,0x20,0xC0,0x20,0x20,0x20,0x20,0x70,0x18,0xE0,0x3F,0x06,0x00,0x00,0x00,0x00,0x00}},/*"无",0*/
{"线",{0x00,0x00,0x00,0x00,0x20,0x00,0x60,0x60,0x01,0x60,0x60,0x06,0x20,0x60,0x0C,0x10,0x61,0x04,0x10,0x63,0x18,0x08,0xF1,0x3F,0x8C,0x6E,0x00,0xFE,0x60,0x00,0x44,0x60,0x10,0x20,0xE0,0x0F,0x30,0x5F,0x00,0x10,0x40,0x08,0xC8,0x41,0x0C,0x3C,0x40,0x06,0x08,0xC0,0x03,0x00,0x80,0x21,0xC0,0xC3,0x21,0x3E,0x30,0x23,0x0C,0x18,0x26,0x00,0x07,0x3C,0x00,0x00,0x38,0x00,0x00,0x00}},/*"线",1*/
{"数",{0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x04,0x30,0xFE,0x07,0x20,0x02,0x04,0x00,0x02,0x04,0x80,0xFE,0x07,0x82,0x02,0x04,0x4C,0x02,0x04,0x48,0x02,0x04,0x48,0xFE,0x07,0x20,0x02,0x04,0x20,0x00,0x00,0x20,0xFF,0x1F,0x20,0x91,0x08,0x10,0x91,0x08,0x1E,0x91,0x08,0x18,0x91,0x08,0x18,0x91,0x08,0x18,0x91,0x08,0x18,0x91,0x28,0xF8,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00}},/*"温",2*/
{"据",{0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x30,0x00,0x00,0x30,0x10,0xF0,0xFF,0x3F,0x10,0x02,0x01,0x10,0x04,0x03,0x10,0x04,0x11,0xF0,0xFF,0x3F,0x10,0x04,0x01,0x10,0x04,0x01,0x10,0xFC,0x01,0x10,0x04,0x01,0x10,0x00,0x00,0x98,0xFF,0x07,0x18,0x04,0x02,0x08,0x04,0x01,0x08,0x88,0x00,0x08,0x50,0x00,0x04,0x70,0x00,0x04,0x8C,0x03,0x02,0x03,0x7E,0xE0,0x00,0x10,0x00,0x00,0x00}},/*"度",3*/
{"测",{0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x10,0x90,0x7F,0x10,0xB0,0x61,0x10,0x80,0x61,0x10,0x80,0x6D,0x16,0x82,0x6D,0x12,0xCC,0x6D,0x12,0xC8,0x6D,0x12,0xC8,0x6D,0x12,0xA0,0x6D,0x12,0xA0,0x6D,0x12,0xA0,0x6D,0x12,0x90,0x65,0x12,0x90,0x65,0x12,0x9C,0x25,0x12,0x98,0x06,0x10,0x18,0x1A,0x10,0x18,0x23,0x10,0x18,0x61,0x10,0xD8,0x40,0x1C,0x20,0x00,0x18,0x00,0x00,0x00}},/*"测",4*/
{"量",{0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0x03,0x60,0x00,0x02,0xE0,0xFF,0x03,0x60,0x00,0x02,0x60,0x00,0x02,0xE0,0xFF,0x03,0x60,0x00,0x22,0xFE,0xFF,0x7F,0x00,0x00,0x00,0xE0,0xFF,0x07,0x20,0x18,0x06,0xE0,0xFF,0x07,0x20,0x18,0x06,0x20,0x18,0x06,0xE0,0xFF,0x07,0x20,0x18,0x06,0xF8,0xFF,0x0F,0x00,0x18,0x00,0x00,0x18,0x20,0xFE,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,0x00}},/*"量",5*/
{"温",{0x00,0x00,0x00,0x80,0x80,0x00,0x88,0x88,0x01,0x90,0x88,0x00,0xB0,0xC4,0x00,0x90,0x42,0x00,0xFC,0xDF,0x3F,0xC0,0x60,0x08,0xE0,0x63,0x08,0xA0,0x64,0x08,0x90,0x5C,0x0C,0x8C,0x50,0x0C,0x82,0x80,0x0C,0xC0,0x80,0x04,0xFE,0x8F,0x04,0x60,0x84,0x07,0x20,0x04,0x03,0x70,0x02,0x03,0x80,0x87,0x07,0x80,0xCD,0x0C,0x60,0x68,0x38,0x18,0x18,0x30,0x06,0x04,0x00,0x00,0x00,0x00}},/*"数",6*/
{"度",{0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x60,0xFC,0x1F,0x20,0x0C,0x18,0x20,0x0C,0x18,0x20,0x0D,0x18,0xFE,0xFF,0x1F,0x20,0x0C,0x19,0x20,0x04,0x01,0x20,0x06,0x01,0xA0,0xFD,0x3F,0x60,0x04,0x01,0x30,0x04,0x01,0x2E,0x04,0x01,0x24,0xF6,0x1F,0x20,0x12,0x18,0x20,0x12,0x18,0x20,0x11,0x18,0x20,0x11,0x18,0xA0,0xF0,0x1F,0x7C,0x10,0x18,0x30,0x10,0x08,0x00,0x00,0x00}},/*"据",7*/

};

void gui_drawfont24(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str, uint8_t mode)
{
	uint8_t i,j,n = 0;
	uint8_t temp;
	uint16_t k;
	uint16_t total_num;
	uint16_t x0 = x;
	total_num = sizeof(tfont24)/sizeof(typFNT_GB24);				//取模方式逐行式

	for(k = 0; k < total_num; k++)
	{
		if((tfont24[k].Index[0] == *str) && (tfont24[k].Index[1] == *(str+1)))
		{
			for(i = 0; i < 24*3; i++)
			{
				temp = tfont24[k].Msk[i];
				for(j = 0; j < 8; j++)
				{
					if(temp & 0x01)
					{
						lcd_drawpoint(x, y+n, fc);
					}
					else
					{
						lcd_drawpoint(x, y+n, bc);
					}
					temp >>= 1;
					x++;
					if(x-x0 == 24)
					{
						x=x0;
						y++;
						break;
					}
				}
	
			}

		}

	}

}
typedef struct 
{
       unsigned char Index[2];	
       char Msk[66];
}typFNT_GB22; 

const typFNT_GB24 tfont22[]=
{

{"无",{0x00,0x00,0x00,0x00,0x00,0x02,0xF8,0xFF,0x07,0x00,0x04,0x00,0x00,0x04,0x00,0x00,0x04,0x00,0x00,0x04,0x00,0x00,0x04,0x04,0xFE,0xFF,0x0F,0x00,0x14,0x00,0x00,0x16,0x00,0x00,0x12,0x00,0x00,0x12,0x00,0x00,0x13,0x00,0x00,0x11,0x00,0x80,0x11,0x08,0x80,0x10,0x08,0x40,0x10,0x08,0x30,0x10,0x18,0x08,0xF0,0x0F,0x06,0x00,0x00,0x00,0x00,0x00}},/*"无",0*/
{"线",{0x00,0x00,0x00,0x00,0x10,0x00,0x60,0x90,0x00,0x20,0x10,0x03,0x10,0x10,0x02,0x10,0x11,0x02,0x88,0x11,0x0F,0x84,0xFE,0x00,0x7E,0x10,0x00,0x64,0x10,0x04,0x20,0xF0,0x07,0x10,0x3F,0x00,0x08,0x20,0x02,0xFC,0x20,0x03,0x0C,0xA0,0x01,0x00,0xE0,0x00,0x00,0x63,0x08,0xF8,0xF0,0x08,0x0E,0x8C,0x09,0x00,0x03,0x0F,0x00,0x00,0x0C,0x00,0x00,0x00}},/*"线",1*/
{"数",{0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xFF,0x01,0x10,0x03,0x01,0x00,0x03,0x01,0x40,0x03,0x01,0x40,0xFF,0x01,0x42,0x03,0x01,0x2C,0x03,0x01,0x28,0xFF,0x03,0x20,0x03,0x03,0x20,0x00,0x00,0x90,0xFF,0x07,0x90,0x48,0x04,0x98,0x48,0x04,0x9C,0x48,0x04,0x88,0x48,0x04,0x88,0x48,0x04,0x88,0x48,0x04,0xE8,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0x00}},/*"温",2*/
{"据",{0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x18,0x00,0xF8,0xFF,0x0F,0x18,0x00,0x00,0x18,0x82,0x00,0x18,0x82,0x00,0xF8,0xFF,0x0F,0x18,0x82,0x00,0x18,0x82,0x00,0x18,0xFE,0x00,0x18,0x82,0x00,0x88,0xFF,0x01,0x08,0x82,0x01,0x08,0xC4,0x00,0x08,0x64,0x00,0x04,0x38,0x00,0x04,0x38,0x00,0x04,0xEC,0x00,0x82,0x83,0x1F,0x70,0x00,0x04,0x00,0x00,0x00}},/*"度",3*/
{"测",{0x00,0x00,0x00,0x00,0x00,0x04,0x98,0x3F,0x0C,0x90,0x10,0x0C,0x90,0x90,0x0C,0x80,0x90,0x0D,0x82,0x94,0x0D,0x84,0x94,0x0D,0xAC,0x94,0x0D,0xA0,0x94,0x0D,0xA0,0x94,0x0D,0x90,0x94,0x0D,0x90,0x96,0x0D,0x90,0x92,0x0D,0x9E,0x92,0x0D,0x08,0x86,0x0D,0x08,0x0B,0x0C,0x08,0x11,0x0C,0x88,0x30,0x0C,0x48,0x20,0x0F,0x20,0x00,0x04,0x00,0x00,0x00}},/*"测",4*/
{"量",{0x00,0x00,0x00,0xE0,0xFF,0x01,0x20,0x00,0x01,0xE0,0xFF,0x01,0x20,0x00,0x01,0xE0,0xFF,0x01,0x20,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0x1F,0xE0,0xFF,0x01,0x20,0x0C,0x01,0x20,0x0C,0x01,0xE0,0xFF,0x01,0x20,0x0C,0x01,0xE0,0xFF,0x01,0x20,0x0C,0x01,0xF8,0xFF,0x03,0x00,0x0C,0x00,0x00,0x0C,0x08,0xFE,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0x00}},/*"量",5*/
{"温",{0x00,0x00,0x00,0xC0,0x40,0x00,0xC0,0x44,0x00,0x98,0x64,0x00,0x90,0x22,0x00,0x90,0x21,0x08,0xFE,0xEF,0x1F,0xC0,0x30,0x06,0xA0,0x33,0x02,0x90,0x2E,0x02,0x88,0x24,0x02,0x44,0x20,0x02,0x40,0x40,0x02,0xFE,0x47,0x01,0x20,0x42,0x01,0x30,0x82,0x01,0x70,0x81,0x01,0x80,0x43,0x03,0x40,0x34,0x06,0x30,0x08,0x1C,0x0C,0x06,0x00,0x00,0x00,0x00}},/*"数",6*/
{"度",{0x00,0x00,0x00,0x30,0x00,0x00,0x20,0xFE,0x07,0x20,0x06,0x04,0x20,0x06,0x04,0xFE,0xFF,0x07,0x20,0x06,0x04,0x20,0x46,0x00,0x20,0xC7,0x00,0xE0,0x42,0x00,0x30,0xFE,0x0F,0x2C,0x42,0x00,0x26,0x42,0x00,0x20,0xFA,0x07,0x20,0x0B,0x04,0x20,0x09,0x04,0x20,0x09,0x04,0xA0,0x08,0x04,0xBC,0xF8,0x07,0x50,0x08,0x04,0x20,0x08,0x00,0x00,0x00,0x00}},/*"据",7*/

};

void gui_drawfont22(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str, uint8_t mode)
{
	uint8_t i,j,n = 0;
	uint8_t temp;
	uint16_t k;
	uint16_t total_num;
	uint16_t x0 = x;
	total_num = sizeof(tfont22)/sizeof(typFNT_GB22);				//取模方式逐行式

	for(k = 0; k < total_num; k++)
	{
		if((tfont22[k].Index[0] == *str) && (tfont22[k].Index[1] == *(str+1)))
		{
			lcd_setwindows(x, y, x+22-1, y+22-1);
			for(i = 0; i < 22*3; i++)
			{
				temp = tfont22[k].Msk[i];
				for(j = 0; j < 8; j++)
				{
					if(temp & 0x01)
					{
						lcd_drawpoint(x, y+n, fc);
					}
					else if((temp & 0x01) == 0 && !mode)
					{
						lcd_drawpoint(x, y+n, bc);
					}
					temp >>= 1;
					x++;
					if(x-x0 == 22)
					{
						x=x0;
						y++;
						break;
					}
				}
	
			}

		}

	}

}

void lcd_showmix_str(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str, uint8_t size, uint8_t mode)
{
	uint16_t x0 = x;
	uint8_t hz = 0;
	while(*str != 0)
	{
		if(!hz)
		{
			if(x > ILI9341_WIDTH - size/2 || y > ILI9341_HEIGHT - size )
				return;
			if(*str > 0x80)
			{
				hz = 1;
				continue;
			}
			else
			{
				if(*str == 0x0D) //换行符
				{
					y += size;
					x = x0;
					str++;
					continue;
				}
				else
				{
					lcd_showchar(x, y, fc, bc, *str, size, mode);
					x += size/2;
				}
			}
			str++;
		}
		else
		{
			if(x > ILI9341_WIDTH - size || y > ILI9341_HEIGHT - size )
				return;
			hz = 0;
			if(size == 16)
			{
				gui_drawfont16(x, y, fc, bc, str, mode);
			}
			else if(size == 24)
			{
				gui_drawfont24(x, y, fc, bc, str, mode);
			}
			else if(size == 22)
			{
				gui_drawfont22(x, y, fc, bc, str, mode);
			}
			else
			{
				printf(" no this chinese font \n");
			}
			str += 2;
			x += size;
		}

	}



}
//Simple routine to generate some patterns and send them to the LCD. Don't expect anything too
//impressive. Because the SPI driver handles transactions in the background, we can calculate the next line
//while the previous one is being sent.
static void display_pretty_colors(spi_device_handle_t spi)
{
    uint16_t *lines[2];
    //Allocate memory for the pixel buffers
    for (int i=0; i<2; i++) {
        lines[i]=heap_caps_malloc(320*PARALLEL_LINES*sizeof(uint16_t), MALLOC_CAP_DMA);
        assert(lines[i]!=NULL);
    }
    int frame=0;
    //Indexes of the line currently being sent to the LCD and the line we're calculating.
    int sending_line=-1;
    int calc_line=0;

    while(1) {
        frame++;
        for (int y=0; y<240; y+=PARALLEL_LINES) {
            //Calculate a line.
            pretty_effect_calc_lines(lines[calc_line], y, frame, PARALLEL_LINES);
            //Finish up the sending process of the previous line, if any
            if (sending_line!=-1) send_line_finish(spi);
            //Swap sending_line and calc_line
            sending_line=calc_line;
            calc_line=(calc_line==1)?0:1;
            //Send the line we currently calculated.
            send_lines(ili_spi, y, lines[sending_line]);
            //The line set is queued up for sending now; the actual sending happens in the
            //background. We can go on to calculate the next line set as long as we do not
            //touch line[sending_line]; the SPI sending process is still reading from that.
        }
    }
}

void lcd_setwindows(uint16_t x, uint16_t y, uint16_t xpos, uint16_t ypos)
{
	uint8_t x_buf[4] = {0};
	uint8_t y_buf[4] = {0};
	x_buf[0] = x>>8;
	x_buf[1] = 0x00FF&x;
	x_buf[2] = xpos>>8;
	x_buf[3] = 0x00FF&xpos;
	
	y_buf[0] = y>>8;
	y_buf[1] = 0x00FF&y;
	y_buf[2] = ypos>>8;
	y_buf[3] = 0x00FF&ypos;
		
	lcd_cmd(ili_spi, 0x2A);
	lcd_data(ili_spi, x_buf, 4);


	lcd_cmd(ili_spi, 0x2B);
	lcd_data(ili_spi, y_buf, 4);

	lcd_cmd(ili_spi, 0x2C);

}
void app_main(void)
{
    esp_err_t ret;
    
    spi_bus_config_t buscfg={
        .miso_io_num=PIN_NUM_MISO,
        .mosi_io_num=PIN_NUM_MOSI,
        .sclk_io_num=PIN_NUM_CLK,
        .quadwp_io_num=-1,
        .quadhd_io_num=-1,
        .max_transfer_sz=PARALLEL_LINES*320*2+8
    };
    spi_device_interface_config_t devcfg={		

        .clock_speed_hz=27*1000*1000,           //Clock out at 10 MHz		
        .mode=0,                                //SPI mode 0
        .spics_io_num=PIN_NUM_CS,               //CS pin
        .queue_size=7,                          //We want to be able to queue 7 transactions at a time
        .pre_cb=lcd_spi_pre_transfer_callback,  //Specify pre-transfer callback to handle D/C line
    };
    //Initialize the SPI bus
    ret=spi_bus_initialize(LCD_HOST, &buscfg, DMA_CHAN);
    ESP_ERROR_CHECK(ret);
    //Attach the LCD to the SPI bus
    ret=spi_bus_add_device(LCD_HOST, &devcfg, &ili_spi);
    ESP_ERROR_CHECK(ret);
    //Initialize the LCD
    lcd_init(ili_spi);
    //Initialize the effect displayed
//    ret=pretty_effect_init();
//    ESP_ERROR_CHECK(ret);
//
//    //Go do nice stuff.
//    display_pretty_colors(ili_spi);
//	
//	send_lines(ili_spi, 120, RED);
	
	lcd_clear(BLACK);

	vTaskDelay(1000);
	
	uint16_t i,j;
	lcd_showmix_str(116, 0, WHITE, BLACK, (uint8_t *)"无线温度测量数据", 16, 0);
	lcd_showmix_str(92, 32, WHITE, BLACK, (uint8_t *)"无线温度测量数据", 22, 0);
	lcd_showmix_str(84, 64, WHITE, BLACK, (uint8_t *)"无线温度测量数据", 24, 0);
	lcd_showmix_str(0,12,WHITE, BLACK, (uint8_t *)"无", 24, 0);
	lcd_showmix_str(24,0,WHITE, BLACK, (uint8_t *)"无", 16, 0);
	lcd_showmix_str(24,16,WHITE, BLACK, (uint8_t *)"无", 16, 0);
	lcd_showmix_str(24,32,WHITE, BLACK, (uint8_t *)"无", 16, 0);

	lcd_showmix_str(0,21+100,WHITE, BLACK, (uint8_t *)"无", 24, 0);
	lcd_showmix_str(24,0+100,WHITE, BLACK, (uint8_t *)"无", 22, 0);
	lcd_showmix_str(24,22+100,WHITE, BLACK, (uint8_t *)"无", 22, 0);
	lcd_showmix_str(24,44+100,WHITE, BLACK, (uint8_t *)"无", 22, 0);
	vTaskDelay(1000);
	lcd_clear(BLACK);

	vTaskDelay(1000);

	lcd_setwindows(0,0,8,8);
	uint8_t color = BigtoLittle16(RED);
	lcd_data(ili_spi, &color, 2);
	
//	vTaskDelay(1000);
//	lcd_clear(BLACK);
//	vTaskDelay(1000);
//	for(i = 0; i < 320;i+=16*3)
//	{
//		for(j = 0; j < 240 ;j+=16)
//		{		
//			lcd_showmix_str(i, j, BLUE, GREEN,(uint8_t *)"无线!!", 16,0);
//		}
//	}	
//	gui_drawfont16(0, 0, WHITE, RED, (uint8_t *)"无", 0);
//	vTaskDelay(1000);
//	for(i = 0; i < 320;i+=16)
//	{
//		for(j = 0; j < 240 ;j+=16)
//		{		
//			gui_drawfont16(i, j, WHITE, RED,(uint8_t *)"无", 0);
//		}
//	}
//	lcd_showstring(0, 16,(uint8_t *)"hello",16, 0);
//	vTaskDelay(1000);
//	lcd_clear(BLACK);
//	lcd_showstring(120, 16,(uint8_t *)"hello", 16, 0);
//	vTaskDelay(1000);
	
//	for(i = 0; i < 320;i+=32)
//	{
//		for(j = 0; j < 240 ;j+=16)
//		{		
//			lcd_showstring(i, j, (uint8_t *)"hello", 16, 0);
//		}
//	}

//	for(i = 0; i < 320;i+=8)
//	{
//		for(j = 0; j < 240 ;j+=16)
//		{		
//			lcd_showchar(i, j, BLACK, RED,'k', 16, 0);
//		}
//	}
	
//	lcd_clear(YELLOW);	
//	while(1)
//	{
//		lcd_clear(RED);
//		vTaskDelay(1000);
//		lcd_clear(GREEN);
//		vTaskDelay(1000);
//		lcd_clear(BLUE);
//		vTaskDelay(1000);
//	}
//	uint16_t i,j;
//	for(i = 0; i < 320;i++)
//	{
//		for(j = 0; j < 240 ;j++)
//		{
//			lcd_drawpoint(i, j, ~RED);
			vTaskDelay(1);
//		}
//
//	}

}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/717023.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存