Added drivers for 9.7" ePaper display

This commit is contained in:
Ace
2020-06-18 16:21:26 +02:00
parent 88adcb4e7f
commit 8e27116f3a
64 changed files with 45730 additions and 0 deletions

View File

@@ -0,0 +1,201 @@
#include "AsciiLib.h"
static uint8_t const AsciiLib[95][16] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
{0x00,0x00,0x00,0x18,0x3C,0x3C,0x3C,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00},/*"!",1*/
{0x00,0x00,0x00,0x66,0x66,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/
{0x00,0x00,0x00,0x36,0x36,0x7F,0x36,0x36,0x36,0x7F,0x36,0x36,0x00,0x00,0x00,0x00},/*"#",3*/
{0x00,0x18,0x18,0x3C,0x66,0x60,0x30,0x18,0x0C,0x06,0x66,0x3C,0x18,0x18,0x00,0x00},/*"$",4*/
{0x00,0x00,0x70,0xD8,0xDA,0x76,0x0C,0x18,0x30,0x6E,0x5B,0x1B,0x0E,0x00,0x00,0x00},/*"%",5*/
{0x00,0x00,0x00,0x38,0x6C,0x6C,0x38,0x60,0x6F,0x66,0x66,0x3B,0x00,0x00,0x00,0x00},/*"&",6*/
{0x00,0x00,0x00,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
{0x00,0x00,0x00,0x0C,0x18,0x18,0x30,0x30,0x30,0x30,0x30,0x18,0x18,0x0C,0x00,0x00},/*"(",8*/
{0x00,0x00,0x00,0x30,0x18,0x18,0x0C,0x0C,0x0C,0x0C,0x0C,0x18,0x18,0x30,0x00,0x00},/*")",9*/
{0x00,0x00,0x00,0x00,0x00,0x36,0x1C,0x7F,0x1C,0x36,0x00,0x00,0x00,0x00,0x00,0x00},/*"*",10*/
{0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00},/*"+",11*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x0C,0x18,0x00,0x00},/*",",12*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",13*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x00},/*".",14*/
{0x00,0x00,0x00,0x06,0x06,0x0C,0x0C,0x18,0x18,0x30,0x30,0x60,0x60,0x00,0x00,0x00},/*"/",15*/
{0x00,0x00,0x00,0x1E,0x33,0x37,0x37,0x33,0x3B,0x3B,0x33,0x1E,0x00,0x00,0x00,0x00},/*"0",16*/
{0x00,0x00,0x00,0x0C,0x1C,0x7C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x00,0x00,0x00,0x00},/*"1",17*/
{0x00,0x00,0x00,0x3C,0x66,0x66,0x06,0x0C,0x18,0x30,0x60,0x7E,0x00,0x00,0x00,0x00},/*"2",18*/
{0x00,0x00,0x00,0x3C,0x66,0x66,0x06,0x1C,0x06,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"3",19*/
{0x00,0x00,0x00,0x30,0x30,0x36,0x36,0x36,0x66,0x7F,0x06,0x06,0x00,0x00,0x00,0x00},/*"4",20*/
{0x00,0x00,0x00,0x7E,0x60,0x60,0x60,0x7C,0x06,0x06,0x0C,0x78,0x00,0x00,0x00,0x00},/*"5",21*/
{0x00,0x00,0x00,0x1C,0x18,0x30,0x7C,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"6",22*/
{0x00,0x00,0x00,0x7E,0x06,0x0C,0x0C,0x18,0x18,0x30,0x30,0x30,0x00,0x00,0x00,0x00},/*"7",23*/
{0x00,0x00,0x00,0x3C,0x66,0x66,0x76,0x3C,0x6E,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"8",24*/
{0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x3E,0x0C,0x18,0x38,0x00,0x00,0x00,0x00},/*"9",25*/
{0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x00},/*":",26*/
{0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x1C,0x1C,0x0C,0x18,0x00,0x00},/*";",27*/
{0x00,0x00,0x00,0x06,0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x06,0x00,0x00,0x00,0x00},/*"<",28*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"=",29*/
{0x00,0x00,0x00,0x60,0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x60,0x00,0x00,0x00,0x00},/*">",30*/
{0x00,0x00,0x00,0x3C,0x66,0x66,0x0C,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00},/*"?",31*/
{0x00,0x00,0x00,0x7E,0xC3,0xC3,0xCF,0xDB,0xDB,0xCF,0xC0,0x7F,0x00,0x00,0x00,0x00},/*"@",32*/
{0x00,0x00,0x00,0x18,0x3C,0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"A",33*/
{0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x7C,0x66,0x66,0x66,0x7C,0x00,0x00,0x00,0x00},/*"B",34*/
{0x00,0x00,0x00,0x3C,0x66,0x66,0x60,0x60,0x60,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"C",35*/
{0x00,0x00,0x00,0x78,0x6C,0x66,0x66,0x66,0x66,0x66,0x6C,0x78,0x00,0x00,0x00,0x00},/*"D",36*/
{0x00,0x00,0x00,0x7E,0x60,0x60,0x60,0x7C,0x60,0x60,0x60,0x7E,0x00,0x00,0x00,0x00},/*"E",37*/
{0x00,0x00,0x00,0x7E,0x60,0x60,0x60,0x7C,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x00},/*"F",38*/
{0x00,0x00,0x00,0x3C,0x66,0x66,0x60,0x60,0x6E,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"G",39*/
{0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"H",40*/
{0x00,0x00,0x00,0x3C,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00},/*"I",41*/
{0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"J",42*/
{0x00,0x00,0x00,0x66,0x66,0x6C,0x6C,0x78,0x6C,0x6C,0x66,0x66,0x00,0x00,0x00,0x00},/*"K",43*/
{0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x7E,0x00,0x00,0x00,0x00},/*"L",44*/
{0x00,0x00,0x00,0x63,0x63,0x77,0x6B,0x6B,0x6B,0x63,0x63,0x63,0x00,0x00,0x00,0x00},/*"M",45*/
{0x00,0x00,0x00,0x63,0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x63,0x00,0x00,0x00,0x00},/*"N",46*/
{0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"O",47*/
{0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x00},/*"P",48*/
{0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x0C,0x06,0x00,0x00},/*"Q",49*/
{0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x7C,0x6C,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"R",50*/
{0x00,0x00,0x00,0x3C,0x66,0x60,0x30,0x18,0x0C,0x06,0x66,0x3C,0x00,0x00,0x00,0x00},/*"S",51*/
{0x00,0x00,0x00,0x7E,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00},/*"T",52*/
{0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"U",53*/
{0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0x00,0x00},/*"V",54*/
{0x00,0x00,0x00,0x63,0x63,0x63,0x6B,0x6B,0x6B,0x36,0x36,0x36,0x00,0x00,0x00,0x00},/*"W",55*/
{0x00,0x00,0x00,0x66,0x66,0x34,0x18,0x18,0x2C,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"X",56*/
{0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x3C,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00},/*"Y",57*/
{0x00,0x00,0x00,0x7E,0x06,0x06,0x0C,0x18,0x30,0x60,0x60,0x7E,0x00,0x00,0x00,0x00},/*"Z",58*/
{0x00,0x00,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3C,0x00},/*"[",59*/
{0x00,0x00,0x00,0x60,0x60,0x30,0x30,0x18,0x18,0x0C,0x0C,0x06,0x06,0x00,0x00,0x00},/*"\",60*/
{0x00,0x00,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00},/*"]",61*/
{0x00,0x18,0x3C,0x66,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,0xFF,0x00},/*"_",63*/
{0x00,0x00,0x00,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",64*/
{0x00,0x00,0x00,0x00,0x00,0x3C,0x06,0x06,0x3E,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"a",65*/
{0x00,0x00,0x00,0x60,0x60,0x7C,0x66,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x00,0x00},/*"b",66*/
{0x00,0x00,0x00,0x00,0x00,0x3C,0x66,0x60,0x60,0x60,0x66,0x3C,0x00,0x00,0x00,0x00},/*"c",67*/
{0x00,0x00,0x00,0x06,0x06,0x3E,0x66,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"d",68*/
{0x00,0x00,0x00,0x00,0x00,0x3C,0x66,0x66,0x7E,0x60,0x60,0x3C,0x00,0x00,0x00,0x00},/*"e",69*/
{0x00,0x00,0x00,0x1E,0x30,0x30,0x30,0x7E,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00},/*"f",70*/
{0x00,0x00,0x00,0x00,0x00,0x3E,0x66,0x66,0x66,0x66,0x66,0x3E,0x06,0x06,0x7C,0x00},/*"g",71*/
{0x00,0x00,0x00,0x60,0x60,0x7C,0x66,0x66,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"h",72*/
{0x00,0x00,0x18,0x18,0x00,0x78,0x18,0x18,0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00},/*"i",73*/
{0x00,0x00,0x0C,0x0C,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x78,0x00},/*"j",74*/
{0x00,0x00,0x00,0x60,0x60,0x66,0x66,0x6C,0x78,0x6C,0x66,0x66,0x00,0x00,0x00,0x00},/*"k",75*/
{0x00,0x00,0x00,0x78,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00},/*"l",76*/
{0x00,0x00,0x00,0x00,0x00,0x7E,0x6B,0x6B,0x6B,0x6B,0x6B,0x63,0x00,0x00,0x00,0x00},/*"m",77*/
{0x00,0x00,0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"n",78*/
{0x00,0x00,0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"o",79*/
{0x00,0x00,0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x66,0x7C,0x60,0x60,0x60,0x00},/*"p",80*/
{0x00,0x00,0x00,0x00,0x00,0x3E,0x66,0x66,0x66,0x66,0x66,0x3E,0x06,0x06,0x06,0x00},/*"q",81*/
{0x00,0x00,0x00,0x00,0x00,0x66,0x6E,0x70,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x00},/*"r",82*/
{0x00,0x00,0x00,0x00,0x00,0x3E,0x60,0x60,0x3C,0x06,0x06,0x7C,0x00,0x00,0x00,0x00},/*"s",83*/
{0x00,0x00,0x00,0x30,0x30,0x7E,0x30,0x30,0x30,0x30,0x30,0x1E,0x00,0x00,0x00,0x00},/*"t",84*/
{0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"u",85*/
{0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0x00,0x00},/*"v",86*/
{0x00,0x00,0x00,0x00,0x00,0x63,0x6B,0x6B,0x6B,0x6B,0x36,0x36,0x00,0x00,0x00,0x00},/*"w",87*/
{0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00,0x00,0x00,0x00},/*"x",88*/
{0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x0C,0x18,0xF0,0x00},/*"y",89*/
{0x00,0x00,0x00,0x00,0x00,0x7E,0x06,0x0C,0x18,0x30,0x60,0x7E,0x00,0x00,0x00,0x00},/*"z",90*/
{0x00,0x00,0x00,0x0C,0x18,0x18,0x18,0x30,0x60,0x30,0x18,0x18,0x18,0x0C,0x00,0x00},/*"{",91*/
{0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00},/*"|",92*/
{0x00,0x00,0x00,0x30,0x18,0x18,0x18,0x0C,0x06,0x0C,0x18,0x18,0x18,0x30,0x00,0x00},/*"}",93*/
{0x00,0x00,0x00,0x71,0xDB,0x8E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",94*/
};
void GetASCIICode(uint8_t* pBuffer,uint8_t ASCII)
{
memcpy(pBuffer,AsciiLib[(ASCII - 32)] ,16);
}

View File

@@ -0,0 +1,10 @@
#ifndef __AsciiLib_H
#define __AsciiLib_H
#include <stdint.h>
#include <string.h>
void GetASCIICode(uint8_t* pBuffer,uint8_t ASCII);
#endif

Binary file not shown.

View File

@@ -0,0 +1,897 @@
#include "IT8951.h"
/*
extern IT8951DevInfo gstI80DevInfo;
extern uint8_t* gpFrameBuf; //Host Source Frame buffer
extern uint32_t gulImgBufAddr; //IT8951 Image buffer address
*/
//Global varivale
IT8951DevInfo gstI80DevInfo;
uint8_t* gpFrameBuf; //Host Source Frame buffer
uint32_t gulImgBufAddr; //IT8951 Image buffer address
//-----------------------------------------------------------
//Host controller function 1---Wait for host data Bus Ready
//-----------------------------------------------------------
void LCDWaitForReady()
{
uint8_t ulData = bcm2835_gpio_lev(HRDY);
while(ulData == 0)
{
ulData = bcm2835_gpio_lev(HRDY);
}
}
//-----------------------------------------------------------
//Host controller function 2---Write command code to host data Bus
//-----------------------------------------------------------
void LCDWriteCmdCode(uint16_t usCmdCode)
{
//Set Preamble for Write Command
uint16_t wPreamble = 0x6000;
LCDWaitForReady();
bcm2835_gpio_write(CS,LOW);
bcm2835_spi_transfer(wPreamble>>8);
bcm2835_spi_transfer(wPreamble);
LCDWaitForReady();
bcm2835_spi_transfer(usCmdCode>>8);
bcm2835_spi_transfer(usCmdCode);
bcm2835_gpio_write(CS,HIGH);
}
//-----------------------------------------------------------
//Host controller function 3---Write Data to host data Bus
//-----------------------------------------------------------
void LCDWriteData(uint16_t usData)
{
//Set Preamble for Write Data
uint16_t wPreamble = 0x0000;
LCDWaitForReady();
bcm2835_gpio_write(CS,LOW);
bcm2835_spi_transfer(wPreamble>>8);
bcm2835_spi_transfer(wPreamble);
LCDWaitForReady();
bcm2835_spi_transfer(usData>>8);
bcm2835_spi_transfer(usData);
bcm2835_gpio_write(CS,HIGH);
}
void LCDWriteNData(uint16_t* pwBuf, uint32_t ulSizeWordCnt)
{
uint32_t i;
uint16_t wPreamble = 0x0000;
LCDWaitForReady();
bcm2835_gpio_write(CS,LOW);
bcm2835_spi_transfer(wPreamble>>8);
bcm2835_spi_transfer(wPreamble);
LCDWaitForReady();
for(i=0;i<ulSizeWordCnt;i++)
{
bcm2835_spi_transfer(pwBuf[i]>>8);
bcm2835_spi_transfer(pwBuf[i]);
}
bcm2835_gpio_write(CS,HIGH);
}
//-----------------------------------------------------------
//Host controller function 4---Read Data from host data Bus
//-----------------------------------------------------------
uint16_t LCDReadData()
{
uint16_t wRData;
uint16_t wPreamble = 0x1000;
LCDWaitForReady();
bcm2835_gpio_write(CS,LOW);
bcm2835_spi_transfer(wPreamble>>8);
bcm2835_spi_transfer(wPreamble);
LCDWaitForReady();
wRData=bcm2835_spi_transfer(0x00);//dummy
wRData=bcm2835_spi_transfer(0x00);//dummy
LCDWaitForReady();
wRData = bcm2835_spi_transfer(0x00)<<8;
wRData |= bcm2835_spi_transfer(0x00);
bcm2835_gpio_write(CS,HIGH);
return wRData;
}
//-----------------------------------------------------------
// Read Burst N words Data
//-----------------------------------------------------------
void LCDReadNData(uint16_t* pwBuf, uint32_t ulSizeWordCnt)
{
uint32_t i;
uint16_t wPreamble = 0x1000;
LCDWaitForReady();
bcm2835_gpio_write(CS,LOW);
bcm2835_spi_transfer(wPreamble>>8);
bcm2835_spi_transfer(wPreamble);
LCDWaitForReady();
pwBuf[0]=bcm2835_spi_transfer(0x00);//dummy
pwBuf[0]=bcm2835_spi_transfer(0x00);//dummy
LCDWaitForReady();
for(i=0;i<ulSizeWordCnt;i++)
{
pwBuf[i] = bcm2835_spi_transfer(0x00)<<8;
pwBuf[i] |= bcm2835_spi_transfer(0x00);
}
bcm2835_gpio_write(CS,HIGH);
}
//-----------------------------------------------------------
//Host controller function 5---Write command to host data Bus with aruments
//-----------------------------------------------------------
void LCDSendCmdArg(uint16_t usCmdCode,uint16_t* pArg, uint16_t usNumArg)
{
uint16_t i;
//Send Cmd code
LCDWriteCmdCode(usCmdCode);
//Send Data
for(i=0;i<usNumArg;i++)
{
LCDWriteData(pArg[i]);
}
}
//-----------------------------------------------------------
//Host Cmd 1---SYS_RUN
//-----------------------------------------------------------
void IT8951SystemRun()
{
LCDWriteCmdCode(IT8951_TCON_SYS_RUN);
}
//-----------------------------------------------------------
//Host Cmd 2---STANDBY
//-----------------------------------------------------------
void IT8951StandBy()
{
LCDWriteCmdCode(IT8951_TCON_STANDBY);
}
//-----------------------------------------------------------
//Host Cmd 3---SLEEP
//-----------------------------------------------------------
void IT8951Sleep()
{
LCDWriteCmdCode(IT8951_TCON_SLEEP);
}
//-----------------------------------------------------------
//Host Cmd 4---REG_RD
//-----------------------------------------------------------
uint16_t IT8951ReadReg(uint16_t usRegAddr)
{
uint16_t usData;
//Send Cmd and Register Address
LCDWriteCmdCode(IT8951_TCON_REG_RD);
LCDWriteData(usRegAddr);
//Read data from Host Data bus
usData = LCDReadData();
return usData;
}
//-----------------------------------------------------------
//Host Cmd 5---REG_WR
//-----------------------------------------------------------
void IT8951WriteReg(uint16_t usRegAddr,uint16_t usValue)
{
//Send Cmd , Register Address and Write Value
LCDWriteCmdCode(IT8951_TCON_REG_WR);
LCDWriteData(usRegAddr);
LCDWriteData(usValue);
}
//-----------------------------------------------------------
//Host Cmd 6---MEM_BST_RD_T
//-----------------------------------------------------------
void IT8951MemBurstReadTrigger(uint32_t ulMemAddr , uint32_t ulReadSize)
{
uint16_t usArg[4];
//Setting Arguments for Memory Burst Read
usArg[0] = (uint16_t)(ulMemAddr & 0x0000FFFF); //addr[15:0]
usArg[1] = (uint16_t)( (ulMemAddr >> 16) & 0x0000FFFF ); //addr[25:16]
usArg[2] = (uint16_t)(ulReadSize & 0x0000FFFF); //Cnt[15:0]
usArg[3] = (uint16_t)( (ulReadSize >> 16) & 0x0000FFFF ); //Cnt[25:16]
//Send Cmd and Arg
LCDSendCmdArg(IT8951_TCON_MEM_BST_RD_T , usArg , 4);
}
//-----------------------------------------------------------
//Host Cmd 7---MEM_BST_RD_S
//-----------------------------------------------------------
void IT8951MemBurstReadStart()
{
LCDWriteCmdCode(IT8951_TCON_MEM_BST_RD_S);
}
//-----------------------------------------------------------
//Host Cmd 8---MEM_BST_WR
//-----------------------------------------------------------
void IT8951MemBurstWrite(uint32_t ulMemAddr , uint32_t ulWriteSize)
{
uint16_t usArg[4];
//Setting Arguments for Memory Burst Write
usArg[0] = (uint16_t)(ulMemAddr & 0x0000FFFF); //addr[15:0]
usArg[1] = (uint16_t)( (ulMemAddr >> 16) & 0x0000FFFF ); //addr[25:16]
usArg[2] = (uint16_t)(ulWriteSize & 0x0000FFFF); //Cnt[15:0]
usArg[3] = (uint16_t)( (ulWriteSize >> 16) & 0x0000FFFF ); //Cnt[25:16]
//Send Cmd and Arg
LCDSendCmdArg(IT8951_TCON_MEM_BST_WR , usArg , 4);
}
//-----------------------------------------------------------
//Host Cmd 9---MEM_BST_END
//-----------------------------------------------------------
void IT8951MemBurstEnd(void)
{
LCDWriteCmdCode(IT8951_TCON_MEM_BST_END);
}
//-----------------------------------------------------------
//Example of Memory Burst Write
//-----------------------------------------------------------
// ****************************************************************************************
// Function name: IT8951MemBurstWriteProc( )
//
// Description:
// IT8951 Burst Write procedure
//
// Arguments:
// uint32_t ulMemAddr: IT8951 Memory Target Address
// uint32_t ulWriteSize: Write Size (Unit: Word)
// uint8_t* pDestBuf - Buffer of Sent data
// Return Values:
// NULL.
// Note:
//
// ****************************************************************************************
void IT8951MemBurstWriteProc(uint32_t ulMemAddr , uint32_t ulWriteSize, uint16_t* pSrcBuf )
{
uint32_t i;
//Send Burst Write Start Cmd and Args
IT8951MemBurstWrite(ulMemAddr , ulWriteSize);
//Burst Write Data
for(i=0;i<ulWriteSize;i++)
{
LCDWriteData(pSrcBuf[i]);
}
//Send Burst End Cmd
IT8951MemBurstEnd();
}
// ****************************************************************************************
// Function name: IT8951MemBurstReadProc( )
//
// Description:
// IT8951 Burst Read procedure
//
// Arguments:
// uint32_t ulMemAddr: IT8951 Read Memory Address
// uint32_t ulReadSize: Read Size (Unit: Word)
// uint8_t* pDestBuf - Buffer for storing Read data
// Return Values:
// NULL.
// Note:
//
// ****************************************************************************************
void IT8951MemBurstReadProc(uint32_t ulMemAddr , uint32_t ulReadSize, uint16_t* pDestBuf )
{
//Send Burst Read Start Cmd and Args
IT8951MemBurstReadTrigger(ulMemAddr , ulReadSize);
//Burst Read Fire
IT8951MemBurstReadStart();
//Burst Read Request for SPI interface only
LCDReadNData(pDestBuf, ulReadSize);
//Send Burst End Cmd
IT8951MemBurstEnd(); //the same with IT8951MemBurstEnd()
}
//-----------------------------------------------------------
//Host Cmd 10---LD_IMG
//-----------------------------------------------------------
void IT8951LoadImgStart(IT8951LdImgInfo* pstLdImgInfo)
{
uint16_t usArg;
//Setting Argument for Load image start
usArg = (pstLdImgInfo->usEndianType << 8 )
|(pstLdImgInfo->usPixelFormat << 4)
|(pstLdImgInfo->usRotate);
//Send Cmd
LCDWriteCmdCode(IT8951_TCON_LD_IMG);
//Send Arg
LCDWriteData(usArg);
}
//-----------------------------------------------------------
//Host Cmd 11---LD_IMG_AREA
//-----------------------------------------------------------
void IT8951LoadImgAreaStart(IT8951LdImgInfo* pstLdImgInfo ,IT8951AreaImgInfo* pstAreaImgInfo)
{
uint16_t usArg[5];
//Setting Argument for Load image start
usArg[0] = (pstLdImgInfo->usEndianType << 8 )
|(pstLdImgInfo->usPixelFormat << 4)
|(pstLdImgInfo->usRotate);
usArg[1] = pstAreaImgInfo->usX;
usArg[2] = pstAreaImgInfo->usY;
usArg[3] = pstAreaImgInfo->usWidth;
usArg[4] = pstAreaImgInfo->usHeight;
//Send Cmd and Args
LCDSendCmdArg(IT8951_TCON_LD_IMG_AREA , usArg , 5);
}
//-----------------------------------------------------------
//Host Cmd 12---LD_IMG_END
//-----------------------------------------------------------
void IT8951LoadImgEnd(void)
{
LCDWriteCmdCode(IT8951_TCON_LD_IMG_END);
}
void GetIT8951SystemInfo(void* pBuf)
{
uint16_t* pusWord = (uint16_t*)pBuf;
IT8951DevInfo* pstDevInfo;
//Send I80 CMD
LCDWriteCmdCode(USDEF_I80_CMD_GET_DEV_INFO);
//Burst Read Request for SPI interface only
LCDReadNData(pusWord, sizeof(IT8951DevInfo)/2);//Polling HRDY for each words(2-bytes) if possible
//Show Device information of IT8951
pstDevInfo = (IT8951DevInfo*)pBuf;
printf("Panel(W,H) = (%d,%d)\r\n",
pstDevInfo->usPanelW, pstDevInfo->usPanelH );
printf("Image Buffer Address = %X\r\n",
pstDevInfo->usImgBufAddrL | (pstDevInfo->usImgBufAddrH << 16));
//Show Firmware and LUT Version
printf("FW Version = %s\r\n", (uint8_t*)pstDevInfo->usFWVersion);
printf("LUT Version = %s\r\n", (uint8_t*)pstDevInfo->usLUTVersion);
}
//-----------------------------------------------------------
//Initial function 2---Set Image buffer base address
//-----------------------------------------------------------
void IT8951SetImgBufBaseAddr(uint32_t ulImgBufAddr)
{
uint16_t usWordH = (uint16_t)((ulImgBufAddr >> 16) & 0x0000FFFF);
uint16_t usWordL = (uint16_t)( ulImgBufAddr & 0x0000FFFF);
//Write LISAR Reg
IT8951WriteReg(LISAR + 2 ,usWordH);
IT8951WriteReg(LISAR ,usWordL);
}
//-----------------------------------------------------------
// 3.6. Display Functions
//-----------------------------------------------------------
//-----------------------------------------------------------
//Display function 1---Wait for LUT Engine Finish
// Polling Display Engine Ready by LUTNo
//-----------------------------------------------------------
void IT8951WaitForDisplayReady()
{
//Check IT8951 Register LUTAFSR => NonZero Busy, 0 - Free
while(IT8951ReadReg(LUTAFSR));
}
//-----------------------------------------------------------
//Display function 2---Load Image Area process
//-----------------------------------------------------------
void IT8951HostAreaPackedPixelWrite(IT8951LdImgInfo* pstLdImgInfo,IT8951AreaImgInfo* pstAreaImgInfo)
{
uint32_t i,j;
//Source buffer address of Host
uint16_t* pusFrameBuf = (uint16_t*)pstLdImgInfo->ulStartFBAddr;
//Set Image buffer(IT8951) Base address
IT8951SetImgBufBaseAddr(pstLdImgInfo->ulImgBufBaseAddr);
//Send Load Image start Cmd
IT8951LoadImgAreaStart(pstLdImgInfo , pstAreaImgInfo);
//Host Write Data
for(j=0;j< pstAreaImgInfo->usHeight;j++)
{
for(i=0;i< pstAreaImgInfo->usWidth/2;i++)
{
//Write a Word(2-Bytes) for each time
LCDWriteData(*pusFrameBuf);
pusFrameBuf++;
}
}
//Send Load Img End Command
IT8951LoadImgEnd();
}
//-----------------------------------------------------------
//Display functions 3---Application for Display panel Area
//-----------------------------------------------------------
void IT8951DisplayArea(uint16_t usX, uint16_t usY, uint16_t usW, uint16_t usH, uint16_t usDpyMode)
{
//Send I80 Display Command (User defined command of IT8951)
LCDWriteCmdCode(USDEF_I80_CMD_DPY_AREA); //0x0034
//Write arguments
LCDWriteData(usX);
LCDWriteData(usY);
LCDWriteData(usW);
LCDWriteData(usH);
LCDWriteData(usDpyMode);
}
//Display Area with bitmap on EPD
//-----------------------------------------------------------
// Display Function 4---for Display Area for 1-bpp mode format
// the bitmap(1bpp) mode will be enable when Display
// and restore to Default setting (disable) after displaying finished
//-----------------------------------------------------------
void IT8951DisplayArea1bpp(uint16_t usX, uint16_t usY, uint16_t usW, uint16_t usH, uint16_t usDpyMode, uint8_t ucBGGrayVal, uint8_t ucFGGrayVal)
{
//Set Display mode to 1 bpp mode - Set 0x18001138 Bit[18](0x1800113A Bit[2])to 1
IT8951WriteReg(UP1SR+2, IT8951ReadReg(UP1SR+2) | (1<<2));
//Set BitMap color table 0 and 1 , => Set Register[0x18001250]:
//Bit[7:0]: ForeGround Color(G0~G15) for 1
//Bit[15:8]:Background Color(G0~G15) for 0
IT8951WriteReg(BGVR, (ucBGGrayVal<<8) | ucFGGrayVal);
//Display
IT8951DisplayArea( usX, usY, usW, usH, usDpyMode);
IT8951WaitForDisplayReady();
//Restore to normal mode
IT8951WriteReg(UP1SR+2, IT8951ReadReg(UP1SR+2) & ~(1<<2));
}
//-------------------------------------------------------------------------------------------------------------
// Command - 0x0037 for Display Base addr by User
// uint32_t ulDpyBufAddr - Host programmer need to indicate the Image buffer address of IT8951
// In current case, there is only one image buffer in IT8951 so far.
// So Please set the Image buffer address you got in initial stage.
// (gulImgBufAddr by Get device information 0x0302 command)
//
//-------------------------------------------------------------------------------------------------------------
void IT8951DisplayAreaBuf(uint16_t usX, uint16_t usY, uint16_t usW, uint16_t usH, uint16_t usDpyMode, uint32_t ulDpyBufAddr)
{
//Send I80 Display Command (User defined command of IT8951)
LCDWriteCmdCode(USDEF_I80_CMD_DPY_BUF_AREA); //0x0037
//Write arguments
LCDWriteData(usX);
LCDWriteData(usY);
LCDWriteData(usW);
LCDWriteData(usH);
LCDWriteData(usDpyMode);
LCDWriteData((uint16_t)ulDpyBufAddr); //Display Buffer Base address[15:0]
LCDWriteData((uint16_t)(ulDpyBufAddr>>16)); //Display Buffer Base address[26:16]
}
//-----------------------------------------------------------
//Test function 1---Software Initial
//-----------------------------------------------------------
uint8_t IT8951_Init()
{
if (!bcm2835_init())
{
printf("bcm2835_init error \n");
return 1;
}
bcm2835_spi_begin();
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); //default
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); //default
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_32); //default
bcm2835_gpio_fsel(CS, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(HRDY, BCM2835_GPIO_FSEL_INPT);
bcm2835_gpio_fsel(RESET, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_write(CS, HIGH);
printf("****** IT8951 ******\n");
bcm2835_gpio_write(RESET, LOW);
bcm2835_delay(100);
bcm2835_gpio_write(RESET, HIGH);
//Get Device Info
GetIT8951SystemInfo(&gstI80DevInfo);
gpFrameBuf = malloc(gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH);
if (!gpFrameBuf)
{
perror("malloc error!\n");
return 1;
}
gulImgBufAddr = gstI80DevInfo.usImgBufAddrL | (gstI80DevInfo.usImgBufAddrH << 16);
//Set to Enable I80 Packed mode
IT8951WriteReg(I80CPCR, 0x0001);
return 0;
}
void IT8951_Cancel()
{
free(gpFrameBuf);
bcm2835_spi_end();
bcm2835_close();
}
//-----------------------------------------------------------
//Test function 2---Example of Display Flow
//-----------------------------------------------------------
void IT8951DisplayExample()
{
IT8951LdImgInfo stLdImgInfo;
IT8951AreaImgInfo stAreaImgInfo;
//Prepare image
//Write pixel 0xF0(White) to Frame Buffer
memset(gpFrameBuf, 0xF0, gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH);
//Check TCon is free ? Wait TCon Ready (optional)
IT8951WaitForDisplayReady();
//--------------------------------------------------------------------------------------------
// initial display - Display white only
//--------------------------------------------------------------------------------------------
//Load Image and Display
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t)gpFrameBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP;
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
//Display Area ?V (x,y,w,h) with mode 0 for initial White to clear Panel
IT8951DisplayArea(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 0);
//--------------------------------------------------------------------------------------------
// Regular display - Display Any Gray colors with Mode 2 or others
//--------------------------------------------------------------------------------------------
//Preparing buffer to All black (8 bpp image)
//or you can create your image pattern here..
memset(gpFrameBuf, 0x00, gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH);
IT8951WaitForDisplayReady();
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t)gpFrameBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP;
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
//Display Area ?V (x,y,w,h) with mode 2 for fast gray clear mode - depends on current waveform
IT8951DisplayArea(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 2);
}
void IT8951DisplayExample2()
{
IT8951LdImgInfo stLdImgInfo;
IT8951AreaImgInfo stAreaImgInfo;
//--------------------------------------------------------------------------------------------
// Regular display - Display Any Gray colors with Mode 2 or others
//--------------------------------------------------------------------------------------------
//Preparing buffer to All black (8 bpp image)
//or you can create your image pattern here..
memset(gpFrameBuf , 0x00, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 1, 0x11, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 2, 0x22, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 3, 0x33, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 4, 0x44, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 5, 0x55, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 6, 0x66, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 7, 0x77, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 8, 0x88, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 9, 0x99, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 10, 0xaa, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 11, 0xbb, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 12, 0xcc, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 13, 0xdd, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 14, 0xee, 1200 * 51 * 1);
memset(gpFrameBuf+1200 * 51 * 15, 0xff, (1200*825)-(1200 * 51 * 15));
IT8951WaitForDisplayReady();
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t)gpFrameBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP;
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
//Display Area ?V (x,y,w,h) with mode 2 for fast gray clear mode - depends on current waveform
IT8951DisplayArea(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 2);
}
/*
extern const unsigned char pic[];
void IT8951DisplayExample3()
{
IT8951LdImgInfo stLdImgInfo;
IT8951AreaImgInfo stAreaImgInfo;
uint32_t i;
for (i = 0;i < 1200*825;i++)
{
gpFrameBuf[i] = pic[i];
}
IT8951WaitForDisplayReady();
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t)gpFrameBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP;
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = 1200;
stAreaImgInfo.usHeight = 825;
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
//Display Area ?V (x,y,w,h) with mode 2 for fast gray clear mode - depends on current waveform
IT8951DisplayArea(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 2);
}
*/
extern uint16_t bmp01[];
void IT8951_GUI_Example()
{
IT8951LdImgInfo stLdImgInfo;
IT8951AreaImgInfo stAreaImgInfo;
Point point[5];
//memset(gpFrameBuf, 0xff, gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH);
EPD_Clear(0xff);
EPD_DrawLine(100,100,200,200,0x40);
EPD_DrawLine(200,200,400,200,0x40);
EPD_DrawLine(400,200,400,400,0x40);
EPD_DrawLine(400,400,600,400,0x40);
EPD_DrawLine(600,600,800,800,0x40);
EPD_DrawLine(0,0,99,99,0x10);
EPD_DrawLine(801,801,1200,825,0x00);
EPD_DrawRect(500, 500, 100, 100, 0x00);
EPD_DrawCircle(700, 500, 100, 0x00);
point[0].X = 30;
point[0].Y = 40;
point[1].X = 40;
point[1].Y = 70;
point[2].X = 50;
point[2].Y = 90;
point[3].X = 90;
point[3].Y = 60;
point[4].X = 70;
point[4].Y = 20;
EPD_DrawPolygon(point,5,0x00);
EPD_DrawEllipse(800, 300, 100, 50, 0x00);
EPD_FillRect(300, 500, 100, 50, 0x00);
EPD_FillCircle(100, 500, 70,0x00);
EPD_Text(400,100, (uint8_t*)"hello world",0x00, 0xff);
EPD_Text(400,200, (uint8_t*)"yang weibiao",0x00, 0xff);
// EPD_DrawBitmap(0,0,bmp01);
//EPD_DrawMatrix(1,1,550,412,bmp01);
EPD_DrawMatrix(100,100,550,412,bmp01);
//<2F><>ʾͼ<CABE><CDBC>
//Show_bmp("16.bmp");
IT8951WaitForDisplayReady();
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t)gpFrameBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP;
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = 1200;
stAreaImgInfo.usHeight = 825;
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
//Display Area ?V (x,y,w,h) with mode 2 for fast gray clear mode - depends on current waveform
IT8951DisplayArea(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 2);
}
void IT8951_BMP_Example(uint32_t x, uint32_t y,char *path)
{
IT8951LdImgInfo stLdImgInfo;
IT8951AreaImgInfo stAreaImgInfo;
EPD_Clear(0xff);
//<2F><>ʾͼ<CABE><CDBC>
Show_bmp(x,y,path);
IT8951WaitForDisplayReady();
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t)gpFrameBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP;
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = 1200;
stAreaImgInfo.usHeight = 825;
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
//Display Area ?V (x,y,w,h) with mode 2 for fast gray clear mode - depends on current waveform
IT8951DisplayArea(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 2);
}
//-----------------------------------------------------------
// Load 1bpp image flow (must display with IT8951DisplayArea1bpp()
//-----------------------------------------------------------
void IT8951Load1bppImage(uint8_t* p1bppImgBuf, uint16_t usX, uint16_t usY, uint16_t usW, uint16_t usH)
{
IT8951LdImgInfo stLdImgInfo;
IT8951AreaImgInfo stAreaImgInfo;
//Setting Load image information
stLdImgInfo.ulStartFBAddr = (uint32_t) p1bppImgBuf;
stLdImgInfo.usEndianType = IT8951_LDIMG_L_ENDIAN;
stLdImgInfo.usPixelFormat = IT8951_8BPP; //we use 8bpp because IT8951 dose not support 1bpp mode for load image?Aso we use Load 8bpp mode ,but the transfer size needs to be reduced to Size/8
stLdImgInfo.usRotate = IT8951_ROTATE_0;
stLdImgInfo.ulImgBufBaseAddr = gulImgBufAddr;
//Set Load Area
stAreaImgInfo.usX = usX/8;
stAreaImgInfo.usY = usY;
stAreaImgInfo.usWidth = usW/8;//1bpp, Chaning Transfer size setting to 1/8X of 8bpp mode
stAreaImgInfo.usHeight = usH;
printf("IT8951HostAreaPackedPixelWrite [wait]\n\r");
//Load Image from Host to IT8951 Image Buffer
IT8951HostAreaPackedPixelWrite(&stLdImgInfo, &stAreaImgInfo);//Display function 2
}
//-----------------------------------------------------------
//Test function 3---Example of Display 1bpp Flow
//-----------------------------------------------------------
void IT8951Display1bppExample()
{
IT8951AreaImgInfo stAreaImgInfo;
//Prepare image
//Write pixel 0x00(Black) to Frame Buffer
//or you can create your image pattern here..
memset(gpFrameBuf, 0x00, (gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH)/8);//Host Frame Buffer(Source)
//Check TCon is free ? Wait TCon Ready (optional)
IT8951WaitForDisplayReady();
//Load Image and Display
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951Load1bppImage(gpFrameBuf, stAreaImgInfo.usX, stAreaImgInfo.usY, stAreaImgInfo.usWidth, stAreaImgInfo.usHeight);//Display function 4, Arg
//Display Area - (x,y,w,h) with mode 2 for Gray Scale
//e.g. if we want to set b0(Background color) for Black-0x00 , Set b1(Foreground) for White-0xFF
IT8951DisplayArea1bpp(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 0, 0x00, 0xFF);
}
void IT8951Display1bppExample2()
{
IT8951AreaImgInfo stAreaImgInfo;
//Prepare image
//Write pixel 0x00(Black) to Frame Buffer
//or you can create your image pattern here..
memset(gpFrameBuf, 0xff, (gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH)/8);//Host Frame Buffer(Source)
//Check TCon is free ? Wait TCon Ready (optional)
IT8951WaitForDisplayReady();
//Load Image and Display
//Set Load Area
stAreaImgInfo.usX = 0;
stAreaImgInfo.usY = 0;
stAreaImgInfo.usWidth = gstI80DevInfo.usPanelW;
stAreaImgInfo.usHeight = gstI80DevInfo.usPanelH;
//Load Image from Host to IT8951 Image Buffer
IT8951Load1bppImage(gpFrameBuf, stAreaImgInfo.usX, stAreaImgInfo.usY, stAreaImgInfo.usWidth, stAreaImgInfo.usHeight);//Display function 4, Arg
//Display Area - (x,y,w,h) with mode 2 for Gray Scale
//e.g. if we want to set b0(Background color) for Black-0x00 , Set b1(Foreground) for White-0xFF
IT8951DisplayArea1bpp(0,0, gstI80DevInfo.usPanelW, gstI80DevInfo.usPanelH, 0, 0x00, 0xFF);
}

View File

@@ -0,0 +1,168 @@
#ifndef _IT8951_H_
#define _IT8951_H_
#include <bcm2835.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "miniGUI.h"
#define CS 8
#define HRDY 24
#define RESET 17
//prototype of structure
//structure prototype 1
typedef struct IT8951LdImgInfo
{
uint16_t usEndianType; //little or Big Endian
uint16_t usPixelFormat; //bpp
uint16_t usRotate; //Rotate mode
uint32_t ulStartFBAddr; //Start address of source Frame buffer
uint32_t ulImgBufBaseAddr;//Base address of target image buffer
}IT8951LdImgInfo;
//structure prototype 2
typedef struct IT8951AreaImgInfo
{
uint16_t usX;
uint16_t usY;
uint16_t usWidth;
uint16_t usHeight;
}IT8951AreaImgInfo;
typedef struct
{
uint16_t usPanelW;
uint16_t usPanelH;
uint16_t usImgBufAddrL;
uint16_t usImgBufAddrH;
uint16_t usFWVersion[8]; //16 Bytes String
uint16_t usLUTVersion[8]; //16 Bytes String
}IT8951DevInfo;
//Built in I80 Command Code
#define IT8951_TCON_SYS_RUN 0x0001
#define IT8951_TCON_STANDBY 0x0002
#define IT8951_TCON_SLEEP 0x0003
#define IT8951_TCON_REG_RD 0x0010
#define IT8951_TCON_REG_WR 0x0011
#define IT8951_TCON_MEM_BST_RD_T 0x0012
#define IT8951_TCON_MEM_BST_RD_S 0x0013
#define IT8951_TCON_MEM_BST_WR 0x0014
#define IT8951_TCON_MEM_BST_END 0x0015
#define IT8951_TCON_LD_IMG 0x0020
#define IT8951_TCON_LD_IMG_AREA 0x0021
#define IT8951_TCON_LD_IMG_END 0x0022
//I80 User defined command code
#define USDEF_I80_CMD_DPY_AREA 0x0034
#define USDEF_I80_CMD_GET_DEV_INFO 0x0302
#define USDEF_I80_CMD_DPY_BUF_AREA 0x0037
//Panel
#define IT8951_PANEL_WIDTH 1024 //it Get Device information
#define IT8951_PANEL_HEIGHT 758
//Rotate mode
#define IT8951_ROTATE_0 0
#define IT8951_ROTATE_90 1
#define IT8951_ROTATE_180 2
#define IT8951_ROTATE_270 3
//Pixel mode , BPP - Bit per Pixel
#define IT8951_2BPP 0
#define IT8951_3BPP 1
#define IT8951_4BPP 2
#define IT8951_8BPP 3
//Waveform Mode
#define IT8951_MODE_0 0
#define IT8951_MODE_1 1
#define IT8951_MODE_2 2
#define IT8951_MODE_3 3
#define IT8951_MODE_4 4
//Endian Type
#define IT8951_LDIMG_L_ENDIAN 0
#define IT8951_LDIMG_B_ENDIAN 1
//Auto LUT
#define IT8951_DIS_AUTO_LUT 0
#define IT8951_EN_AUTO_LUT 1
//LUT Engine Status
#define IT8951_ALL_LUTE_BUSY 0xFFFF
//-----------------------------------------------------------------------
// IT8951 TCon Registers defines
//-----------------------------------------------------------------------
//Register Base Address
#define DISPLAY_REG_BASE 0x1000 //Register RW access for I80 only
//Base Address of Basic LUT Registers
#define LUT0EWHR (DISPLAY_REG_BASE + 0x00) //LUT0 Engine Width Height Reg
#define LUT0XYR (DISPLAY_REG_BASE + 0x40) //LUT0 XY Reg
#define LUT0BADDR (DISPLAY_REG_BASE + 0x80) //LUT0 Base Address Reg
#define LUT0MFN (DISPLAY_REG_BASE + 0xC0) //LUT0 Mode and Frame number Reg
#define LUT01AF (DISPLAY_REG_BASE + 0x114) //LUT0 and LUT1 Active Flag Reg
//Update Parameter Setting Register
#define UP0SR (DISPLAY_REG_BASE + 0x134) //Update Parameter0 Setting Reg
#define UP1SR (DISPLAY_REG_BASE + 0x138) //Update Parameter1 Setting Reg
#define LUT0ABFRV (DISPLAY_REG_BASE + 0x13C) //LUT0 Alpha blend and Fill rectangle Value
#define UPBBADDR (DISPLAY_REG_BASE + 0x17C) //Update Buffer Base Address
#define LUT0IMXY (DISPLAY_REG_BASE + 0x180) //LUT0 Image buffer X/Y offset Reg
#define LUTAFSR (DISPLAY_REG_BASE + 0x224) //LUT Status Reg (status of All LUT Engines)
#define BGVR (DISPLAY_REG_BASE + 0x250) //Bitmap (1bpp) image color table
//-------System Registers----------------
#define SYS_REG_BASE 0x0000
//Address of System Registers
#define I80CPCR (SYS_REG_BASE + 0x04)
//-------Memory Converter Registers----------------
#define MCSR_BASE_ADDR 0x0200
#define MCSR (MCSR_BASE_ADDR + 0x0000)
#define LISAR (MCSR_BASE_ADDR + 0x0008)
void InterfaceInit(void);
//void HostInit(void);
uint8_t IT8951_Init(void);
void IT8951_Cancel(void);
void IT8951DisplayExample(void);
void IT8951DisplayExample2(void);
void IT8951Display1bppExample2(void);
void IT8951DisplayExample3(void);
void IT8951_GUI_Example(void);
void IT8951_BMP_Example(uint32_t x, uint32_t y,char *path);
//temp
uint16_t IT8951ReadReg(uint16_t usRegAddr);
void IT8951SetImgBufBaseAddr(uint32_t ulImgBufAddr);
void LCDWaitForReady(void);
void GetIT8951SystemInfo(void* pBuf);
void gpio_i80_16b_cmd_out(uint16_t usCmd);
void GPIO_Configuration_Out(void);
void GPIO_Configuration_In(void);
void IT8951DisplayClear(void);
//uint16_t IT8951ReadReg(uint16_t usRegAddr);
void IT8951WriteReg(uint16_t usRegAddr,uint16_t usValue);
#endif

View File

@@ -0,0 +1,9 @@
SRCS=IT8951.c miniGUI.c main.c AsciiLib.c bmp.c
CC=gcc
TARGET=IT8951
$(TARGET):$(SRCS)
$(CC) -Wall $(SRCS) -o $(TARGET) -lbcm2835
clean:
rm -f $(TARGET)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
#include "IT8951.h"
int main (int argc, char *argv[])
{
/*
printf("ReadReg = 0x%x\n",IT8951ReadReg(LISAR));
IT8951WriteReg(LISAR,0x1234);
printf("ReadReg = 0x%x\n",IT8951ReadReg(LISAR));
*/
if(IT8951_Init())
{
printf("IT8951_Init error \n");
return 1;
}
//IT8951DisplayExample();
//IT8951DisplayExample2();
//IT8951DisplayExample3();
//printf("IT8951_GUI_Example\n");
//IT8951_GUI_Example();
if (argc != 4)
{
printf("Error: argc!=4.\n");
exit(1);
}
uint32_t x,y;
sscanf(argv[1],"%d",&x);
sscanf(argv[2],"%d",&y);
IT8951_BMP_Example(x,y,argv[3]);
IT8951_Cancel();
return 0;
}

View File

@@ -0,0 +1,690 @@
#include <string.h>
#include "miniGUI.h"
#include "AsciiLib.h"
extern IT8951DevInfo gstI80DevInfo;
extern uint8_t* gpFrameBuf; //Host Source Frame buffer
void EPD_Clear(uint8_t Color)
{
memset(gpFrameBuf, Color, gstI80DevInfo.usPanelW * gstI80DevInfo.usPanelH);
}
void EPD_DrawPixel(uint16_t x0, uint16_t y0, uint8_t color)
{
if(x0 < 0 || x0 >= gstI80DevInfo.usPanelW || y0 < 0 || y0 >= gstI80DevInfo.usPanelH)
return ;
/*
<09>Դ洦<D4B4><E6B4A6>
*/
gpFrameBuf[y0*gstI80DevInfo.usPanelW + x0] = color;
}
void EPD_DrawLine(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t color)
{
uint32_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0,
curpixel = 0;
deltax = ABS(x2 - x1); /* The difference between the x's */
deltay = ABS(y2 - y1); /* The difference between the y's */
x = x1; /* Start x off at the first pixel */
y = y1; /* Start y off at the first pixel */
if (x2 >= x1) /* The x-values are increasing */
{
xinc1 = 1;
xinc2 = 1;
}
else /* The x-values are decreasing */
{
xinc1 = -1;
xinc2 = -1;
}
if (y2 >= y1) /* The y-values are increasing */
{
yinc1 = 1;
yinc2 = 1;
}
else /* The y-values are decreasing */
{
yinc1 = -1;
yinc2 = -1;
}
if (deltax >= deltay) /* There is at least one x-value for every y-value */
{
xinc1 = 0; /* Don't change the x when numerator >= denominator */
yinc2 = 0; /* Don't change the y for every iteration */
den = deltax;
num = deltax / 2;
num_add = deltay;
num_pixels = deltax; /* There are more x-values than y-values */
}
else /* There is at least one y-value for every x-value */
{
xinc2 = 0; /* Don't change the x for every iteration */
yinc1 = 0; /* Don't change the y when numerator >= denominator */
den = deltay;
num = deltay / 2;
num_add = deltax;
num_pixels = deltay; /* There are more y-values than x-values */
}
for (curpixel = 0; curpixel <= num_pixels; curpixel++)
{
EPD_DrawPixel(x, y, color); /* Draw the current pixel */
num += num_add; /* Increase the numerator by the top of the fraction */
if (num >= den) /* Check if numerator >= denominator */
{
num -= den; /* Calculate the new numerator value */
x += xinc1; /* Change the x as appropriate */
y += yinc1; /* Change the y as appropriate */
}
x += xinc2; /* Change the x as appropriate */
y += yinc2; /* Change the y as appropriate */
}
}
void EPD_DrawRect(uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height,uint8_t color)
{
EPD_DrawLine(Xpos, Ypos, Xpos+Width, Ypos, color);
EPD_DrawLine(Xpos, Ypos, Xpos, Ypos+Height, color);
EPD_DrawLine(Xpos, Ypos+Height, Xpos+Width, Ypos+Height, color);
EPD_DrawLine(Xpos+Width, Ypos, Xpos+Width, Ypos+Height, color);
}
void EPD_DrawCircle(uint16_t Xpos,uint16_t Ypos,uint16_t Radius,uint8_t color)
{
int decision; /* Decision Variable */
uint32_t current_x; /* Current X Value */
uint32_t current_y; /* Current Y Value */
decision = 3 - (Radius << 1);
current_x = 0;
current_y = Radius;
while (current_x <= current_y)
{
EPD_DrawPixel((Xpos + current_x), (Ypos - current_y), color);
EPD_DrawPixel((Xpos - current_x), (Ypos - current_y), color);
EPD_DrawPixel((Xpos + current_y), (Ypos - current_x), color);
EPD_DrawPixel((Xpos - current_y), (Ypos - current_x), color);
EPD_DrawPixel((Xpos + current_x), (Ypos + current_y), color);
EPD_DrawPixel((Xpos - current_x), (Ypos + current_y), color);
EPD_DrawPixel((Xpos + current_y), (Ypos + current_x), color);
EPD_DrawPixel((Xpos - current_y), (Ypos + current_x), color);
if (decision < 0)
{
decision += (current_x << 2) + 6;
}
else
{
decision += ((current_x - current_y) << 2) + 10;
current_y--;
}
current_x++;
}
}
void EPD_DrawPolygon(pPoint Points,uint16_t PointCount,uint8_t color)
{
uint16_t x = 0, y = 0;
if(PointCount < 2)
{
return;
}
EPD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y,color);
while(--PointCount)
{
x = Points->X;
y = Points->Y;
Points++;
EPD_DrawLine(x, y, Points->X, Points->Y,color);
}
}
void EPD_DrawEllipse(uint16_t Xpos, uint16_t Ypos, uint16_t XRadius, uint16_t YRadius, uint8_t color)
{
int32_t x = 0, y = -YRadius, err = 2-2*XRadius, e2;
float k = 0, rad1 = 0, rad2 = 0;
rad1 = XRadius;
rad2 = YRadius;
k = (float)(rad2/rad1);
do {
EPD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos+y), color);
EPD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos+y), color);
EPD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos-y), color);
EPD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos-y), color);
e2 = err;
if (e2 <= x) {
err += ++x*2+1;
if (-y == x && e2 <= y) e2 = 0;
}
if (e2 > y) err += ++y*2+1;
}
while (y <= 0);
}
void EPD_FillRect(uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height,uint8_t color)
{
uint16_t i;
for (i=0;i<Height;i++)
{
EPD_DrawLine(Xpos, Ypos+i,Xpos+Width,Ypos+i,color);
}
}
void EPD_FillCircle(uint16_t Xpos,uint16_t Ypos,uint16_t Radius,uint8_t color)
{
int32_t decision; /* Decision Variable */
uint32_t current_x; /* Current X Value */
uint32_t current_y; /* Current Y Value */
decision = 3 - (Radius << 1);
current_x = 0;
current_y = Radius;
while (current_x <= current_y)
{
if(current_y > 0)
{
EPD_DrawLine(Xpos - current_y, Ypos + current_x,Xpos +current_y,Ypos + current_x,color);
EPD_DrawLine(Xpos - current_y, Ypos - current_x,Xpos + current_y, Ypos - current_x,color);
}
if(current_x > 0)
{
EPD_DrawLine(Xpos - current_x, Ypos - current_y,Xpos+current_x,Ypos - current_y,color);
EPD_DrawLine(Xpos - current_x, Ypos + current_y,Xpos+current_x,Ypos + current_y,color);
}
if (decision < 0)
{
decision += (current_x << 2) + 6;
}
else
{
decision += ((current_x - current_y) << 2) + 10;
current_y--;
}
current_x++;
}
EPD_DrawCircle(Xpos, Ypos, Radius,color);
}
void EPD_PutChar(uint16_t Xpos,uint16_t Ypos,uint8_t ASCI,uint8_t charColor,uint8_t bkColor )
{
uint16_t i, j;
uint8_t buffer[16], tmp_char;
GetASCIICode(buffer,ASCI);
for(i=0; i<16; i++)
{
tmp_char = buffer[i];
for(j=0; j<8; j++)
{
if(((tmp_char >> (7-j)) & 0x01) == 0x01)
{
EPD_DrawPixel(Xpos+j, Ypos+i, charColor);
}
else
{
EPD_DrawPixel(Xpos+j, Ypos+i, bkColor);
}
}
}
}
void EPD_Text(uint16_t Xpos,uint16_t Ypos,uint8_t *str,uint8_t Color,uint8_t bkColor)
{
uint8_t TempChar;
do
{
TempChar = *str++;
EPD_PutChar(Xpos, Ypos, TempChar, Color, bkColor);
if(Xpos < gstI80DevInfo.usPanelW - 8)
{
Xpos += 8;
}
else if (Ypos < gstI80DevInfo.usPanelH - 16)
{
Xpos = 0;
Ypos += 16;
}
else
{
Xpos = 0;
Ypos = 0;
}
}
while (*str != 0);
}
extern uint16_t bmp01[];
void EPD_DrawBitmap(uint16_t Xpos, uint16_t Ypos,uint16_t *bmp)
{
uint16_t i,j;
uint16_t R,G,B,temp;
double Gray;
for (j=0;j<412;j++)
{
for (i=0;i<550;i++)
{
temp = bmp[j*550+i];
R = (temp >> 11)<<3;
G = ((temp&0x07E0) >> 5)<<2;
B = (temp&0x01F)<<3;
Gray = (R*299 + G*587 + B*114 + 500) / 1000;
EPD_DrawPixel(i, j,(uint8_t)Gray);
}
}
}
void EPD_DrawMatrix(uint16_t Xpos, uint16_t Ypos,uint16_t Width, uint16_t High,const uint16_t* Matrix)
{
uint16_t i,j,x,y;
uint16_t R,G,B,temp;
double Gray;
for (y=0,j=Ypos;y<High;y++,j++)
{
for (x=0,i=Xpos;x<Width;x++,i++)
{
temp = Matrix[y*550+x];
R = (temp >> 11)<<3;
G = ((temp&0x07E0) >> 5)<<2;
B = (temp&0x001F) <<3;
Gray = (R*299 + G*587 + B*114 + 500) / 1000;
EPD_DrawPixel(i, j, Gray);
}
}
}
//<2F><>ʾBMPͼƬ<CDBC><C6AC><EFBFBD>ص<EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>
struct fb_var_screeninfo vinfo; // <20><>¼<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>޸ĵ<DEB8><C4B5><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint32_t fbfd = 0; // /dev/fb0 <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t *fbp = 0; // <20>ڴ<EFBFBD>ӳ<EFBFBD><D3B3>ָ<EFBFBD><D6B8>
uint8_t *bmp_dst_buf = NULL; // BMP Buffer
uint8_t *bmp_src_buf = NULL; // BMP Buffer
uint32_t bmp_width, bmp_height;
uint8_t bmp_BitCount;
uint32_t bytesPerLine;
uint32_t imageSize;
uint32_t skip;
PIXEL palette[256];
static void Bitmap_format_Matrix(uint8_t *dst,uint8_t *src)
{
uint32_t i,j,k;
uint8_t *psrc = src;
uint8_t *pdst = dst;
uint8_t *p = psrc;
uint8_t temp;
uint32_t count;
//<2F><><EFBFBD><EFBFBD>bmp<6D><EFBFBD>ǴӺ<C7B4><D3BA><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><E6A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
switch(bmp_BitCount)
{
case 1:
pdst += (bmp_width * bmp_height);
for(i=0;i<bmp_height;i++)
{
pdst -= bmp_width;
count = 0;
for (j=0;j<(bmp_width+7)/8;j++)
{
temp = p[j];
for (k=0;k<8;k++)
{
pdst[0]= ((temp & (0x80>>k)) >> (7-k));
count++;
pdst++;
if (count == bmp_width)
{
break;
}
}
}
pdst -= bmp_width;
p += bytesPerLine;
}
break;
case 4:
pdst += (bmp_width * bmp_height);
for(i=0;i<bmp_height;i++)
{
pdst -= bmp_width;
count = 0;
for (j=0;j<(bmp_width+1)/2;j++)
{
temp = p[j];
pdst[0]= ((temp & 0xf0) >> 4);
count++;
pdst++;
if (count == bmp_width)
{
break;
}
pdst[0] = temp & 0x0f;
count++;
pdst++;
if (count == bmp_width)
{
break;
}
}
pdst -= bmp_width;
p += bytesPerLine;
}
break;
case 8:
pdst += (bmp_width*bmp_height);
for(i=0;i<bmp_height;i++)
{
p = psrc+(i+1)*bytesPerLine;
p -= skip;
for(j=0;j<bmp_width;j++)
{
pdst -= 1;
p -= 1;
pdst[0] = p[0];
}
}
break;
case 16:
pdst += (bmp_width*bmp_height*2);
for(i=0;i<bmp_height;i++)
{
p = psrc+(i+1)*bytesPerLine;
p -= skip;
for(j=0;j<bmp_width;j++)
{
pdst -= 2;
p -= 2;
pdst[0] = p[1];
pdst[1] = p[0];
}
}
break;
case 24:
pdst += (bmp_width*bmp_height*3);
for(i=0;i<bmp_height;i++)
{
p = psrc+(i+1)*bytesPerLine;
p -= skip;
for(j=0;j<bmp_width;j++)
{
pdst -= 3;
p -= 3;
pdst[0] = p[2];
pdst[1] = p[1];
pdst[2] = p[0];
}
}
break;
case 32:
pdst += (bmp_width*bmp_height*4);
for(i=0;i<bmp_height;i++)
{
p = psrc+(i+1)*bmp_width*4;
for(j=0;j<bmp_width;j++)
{
pdst -= 4;
p -= 4;
pdst[0] = p[2];
pdst[1] = p[1];
pdst[2] = p[0];
pdst[3] = p[3];
}
}
break;
default:
break;
}
}
static void DrawMatrix(uint16_t Xpos, uint16_t Ypos,uint16_t Width, uint16_t High,const uint8_t* Matrix)
{
uint16_t i,j,x,y;
uint8_t R,G,B;
uint8_t temp1,temp2;
double Gray;
for (y=0,j=Ypos;y<High;y++,j++)
{
for (x=0,i=Xpos;x<Width;x++,i++)
{
switch(bmp_BitCount)
{
case 1:
case 4:
case 8:
R = palette[Matrix[(y*Width+x)]].red;
G = palette[Matrix[(y*Width+x)]].green;
B = palette[Matrix[(y*Width+x)]].blue;
break;
case 16:
temp1 = Matrix[(y*Width+x)*2];
temp2 = Matrix[(y*Width+x)*2+1];
R = (temp1 & 0x7c)<<1;
G = (((temp1 & 0x03) << 3 ) | ((temp2&0xe0) >> 5))<<3;
B = (temp2 & 0x1f)<<3;
break;
case 24:
R = Matrix[(y*Width+x)*3];
G = Matrix[(y*Width+x)*3+1];
B = Matrix[(y*Width+x)*3+2];
break;
case 32:
R = Matrix[(y*Width+x)*4];
G = Matrix[(y*Width+x)*4+1];
B = Matrix[(y*Width+x)*4+2];
break;
default:
break;
}
Gray = (R*299 + G*587 + B*114 + 500) / 1000;
EPD_DrawPixel(i, j, Gray);
}
}
}
uint8_t Show_bmp(uint32_t x, uint32_t y,char *path)
{
FILE *fp;//bmp<6D>ļ<EFBFBD>ָ<EFBFBD><D6B8>
BITMAPFILEHEADER FileHead;
BITMAPINFOHEADER InfoHead;
uint32_t total_length;
uint8_t *buf = NULL;
uint32_t ret = -1;
fp = fopen(path,"rb");
if (fp == NULL)
{
return(-1);
}
ret = fread(&FileHead, sizeof(BITMAPFILEHEADER),1, fp);
if (ret != 1)
{
printf("Read header error!\n");
fclose(fp);
return(-2);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>bmpͼ<70><CDBC>
if (FileHead.cfType != 0x4D42)//<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͣ<EFBFBD>"BM"(0x4D42)
{
printf("It's not a BMP file\n");
fclose(fp);
return(-3);
}
printf("\n*****************************************\n");
printf("BMP_cfSize:%d \n", FileHead.cfSize);
printf("BMP_cfoffBits:%d \n", FileHead.cfoffBits);
ret = fread((char *)&InfoHead, sizeof(BITMAPINFOHEADER),1, fp);
if (ret != 1)
{
printf("Read infoheader error!\n");
fclose(fp);
return(-4);
}
printf("BMP_ciSize:%d \n", InfoHead.ciSize);
printf("BMP_ciWidth:%d \n", InfoHead.ciWidth);
printf("BMP_ciHeight:%d \n", InfoHead.ciHeight);
printf("BMP_ciPlanes:%x \n", InfoHead.ciPlanes);
printf("BMP_ciBitCount:%x \n", InfoHead.ciBitCount);
printf("BMP_ciCompress:%x \n", InfoHead.ciCompress);
printf("BMP_ciSizeImage:%x \n", InfoHead.ciSizeImage);
printf("BMP_ciXPelsPerMeter:%x \n", InfoHead.ciXPelsPerMeter);
printf("BMP_ciYPelsPerMeter:%x \n", InfoHead.ciYPelsPerMeter);
printf("BMP_ciClrUsed:%x \n", InfoHead.ciClrUsed);
printf("BMP_ciClrImportant:%x \n", InfoHead.ciClrImportant);
printf("*****************************************\n\n");
total_length = FileHead.cfSize-FileHead.cfoffBits;
bytesPerLine=((InfoHead.ciWidth*InfoHead.ciBitCount+31)>>5)<<2;
imageSize=bytesPerLine*InfoHead.ciHeight;
skip=(4-((InfoHead.ciWidth*InfoHead.ciBitCount)>>3))&3;
printf("total_length:%d,%d\n", InfoHead.ciSizeImage,FileHead.cfSize-FileHead.cfoffBits);
printf("bytesPerLine = %d\n", bytesPerLine);
printf("imageSize = %d\n", imageSize);
printf("skip = %d\n", skip);
bmp_width = InfoHead.ciWidth;
bmp_height = InfoHead.ciHeight;
bmp_BitCount = InfoHead.ciBitCount;
bmp_src_buf = (uint8_t*)calloc(1,total_length);
if(bmp_src_buf == NULL){
printf("Load > malloc bmp out of memory!\n");
return -5;
}
bmp_dst_buf = (uint8_t*)calloc(1,total_length);
if(bmp_dst_buf == NULL){
printf("Load > malloc bmp out of memory!\n");
return -5;
}
//<2F><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
fseek(fp, FileHead.cfoffBits, SEEK_SET);
//ÿ<><C3BF><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
buf = bmp_src_buf;
while ((ret = fread(buf,1,total_length,fp)) >= 0)
{
if (ret == 0)
{
usleep(100);
continue;
}
buf = ((uint8_t*)buf) + ret;
total_length = total_length - ret;
if(total_length == 0)
break;
}
//<2F><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>԰<EFBFBD>
switch(bmp_BitCount)
{
case 1:
fseek(fp, 54, SEEK_SET);
ret = fread(palette,1,4*2,fp);
if (ret != 8)
{
printf("Error: fread != 8\n");
return -5;
}
bmp_dst_buf = (uint8_t*)calloc(1,InfoHead.ciWidth * InfoHead.ciHeight);
if(bmp_dst_buf == NULL)
{
printf("Load > malloc bmp out of memory!\n");
return -5;
}
break;
case 4:
fseek(fp, 54, SEEK_SET);
ret = fread(palette,1,4*16,fp);
if (ret != 64)
{
printf("Error: fread != 64\n");
return -5;
}
bmp_dst_buf = (uint8_t*)calloc(1,InfoHead.ciWidth * InfoHead.ciHeight);
if(bmp_dst_buf == NULL)
{
printf("Load > malloc bmp out of memory!\n");
return -5;
}
break;
case 8:
fseek(fp, 54, SEEK_SET);
ret = fread(palette,1,4*256,fp);
if (ret != 1024)
{
printf("Error: fread != 1024\n");
return -5;
}
break;
default:
break;
}
Bitmap_format_Matrix(bmp_dst_buf,bmp_src_buf);
DrawMatrix(x, y,InfoHead.ciWidth, InfoHead.ciHeight, bmp_dst_buf);
fclose(fp);
return(0);
}

View File

@@ -0,0 +1,73 @@
#ifndef _miniGUI_H_
#define _miniGUI_H_
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include "IT8951.h"
typedef struct
{
uint16_t X;
uint16_t Y;
}Point, *pPoint;
//14byte<74>ļ<EFBFBD>ͷ
typedef struct
{
uint16_t cfType;//<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͣ<EFBFBD>"BM"(0x4D42)
uint32_t cfSize;//<2F>ļ<EFBFBD><C4BC><EFBFBD>С<EFBFBD><D0A1><EFBFBD>ֽڣ<D6BD>
uint32_t cfReserved;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ0
uint32_t cfoffBits;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ͷ<EFBFBD><CDB7>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڣ<D6BD>
}__attribute__((packed)) BITMAPFILEHEADER;
//__attribute__((packed))<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǹ<EFBFBD><C7B8>߱<EFBFBD><DFB1><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD>
//40byte<74><65>Ϣͷ
typedef struct
{
uint32_t ciSize;//40
uint32_t ciWidth;//<2F><><EFBFBD><EFBFBD>
uint32_t ciHeight;//<2F>߶<EFBFBD>
uint16_t ciPlanes;//Ŀ<><C4BF><EFBFBD><EFBFBD><E8B1B8>λƽ<CEBB><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ1
uint16_t ciBitCount;//ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>λ<EFBFBD><CEBB>
uint32_t ciCompress;//ѹ<><D1B9>˵<EFBFBD><CBB5>
uint32_t ciSizeImage;//<2F><><EFBFBD>ֽڱ<D6BD>ʾ<EFBFBD><CABE>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
uint32_t ciXPelsPerMeter;//Ŀ<><C4BF><EFBFBD><EFBFBD><E8B1B8>ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><>
uint32_t ciYPelsPerMeter;//Ŀ<><C4BF><EFBFBD><EFBFBD>Ĵ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><>
uint32_t ciClrUsed;//λͼʹ<CDBC>õ<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>
uint32_t ciClrImportant;//ָ<><D6B8><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><30><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ҫ
}__attribute__((packed)) BITMAPINFOHEADER;
typedef struct
{
uint8_t blue;
uint8_t green;
uint8_t red;
uint8_t reserved;
}__attribute__((packed)) PIXEL;//<2F><>ɫģʽRGB
#define ABS(X) ((X) > 0 ? (X) : -(X))
void EPD_Clear(uint8_t Color);
void EPD_DrawPixel(uint16_t x0,uint16_t y0,uint8_t color);
void EPD_DrawLine(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t color);
void EPD_DrawRect(uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height,uint8_t color);
void EPD_DrawCircle(uint16_t Xpos,uint16_t Ypos,uint16_t Radius,uint8_t color);
void EPD_DrawPolygon(pPoint Points,uint16_t PointCount,uint8_t color);
void EPD_DrawEllipse(uint16_t Xpos,uint16_t Ypos,uint16_t XRadius,uint16_t YRadius,uint8_t color);
void EPD_FillRect(uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height,uint8_t color);
void EPD_FillCircle(uint16_t Xpos,uint16_t Ypos,uint16_t Radius,uint8_t color);
void EPD_PutChar(uint16_t Xpos,uint16_t Ypos,uint8_t ASCI,uint8_t charColor,uint8_t bkColor);
void EPD_Text(uint16_t Xpos,uint16_t Ypos,uint8_t *str,uint8_t Color,uint8_t bkColor);
void EPD_DrawBitmap(uint16_t Xpos, uint16_t Ypos,uint16_t *bmp);
void EPD_DrawMatrix(uint16_t Xpos, uint16_t Ypos,uint16_t Width, uint16_t High,const uint16_t* Matrix);
uint8_t Show_bmp(uint32_t x, uint32_t y,char *path);
#endif