--[[
ģƣILI 9341оƬ
ģ鹦ܣʼоƬ
ģ޸ʱ䣺2018.01.09
]]

--[[
ע⣺ļãӲʹõǱ׼SPIţLCDרõSPI
dispĿǰ֧SPIӿڵӲͼ£
Airģ			LCD
GND-------------
SPI_CS----------Ƭѡ
SPI_CLK---------ʱ
SPI_DO----------
SPI_DI----------/ѡ
VDDIO-----------Դ
UART1_CTS-------λ
ע⣺Air202ڵĿ壬UART1CTSRTS˿ӡ
]]

module(...,package.seeall)

--[[
init
  ʼLCD
  
ֵ
]]
local function init()
	local para =
	{
		width = 240, --ֱʿȣ128أûĲ޸
		height = 320, --ֱʸ߶ȣ160أûĲ޸
		bpp = 16, --λȣ֧16λ
		bus = disp.BUS_SPI, --׼SPIӿ
		xoffset = 0, --Xƫ
		yoffset = 0, --Yƫ
		freq = 13000000, --spiʱƵʣ֧110K13M11000013000000֮11000013000000
		hwfillcolor = 0xFFFFFF, --ɫɫ
		pinrst = pio.P0_3, --resetλ
		pinrs = pio.P0_12, --rs/ѡ
		--ʼ
		--ǰֽڱʾͣ0001ʾʱ00000002ʾ0003ʾ
		--ʱֽͣڱʾʱʱ䣨λ룩
		--ֵֽͣ
		--ֽͣݵֵ
		initcmd =
		{
			0x11,
			0x00010078,
			0xCF,
			0x00030000,
			0x00030099,
			0x00030030,
			0xED,
			0x00030064,
			0x00030003,
			0x00030012,
			0x00030081,
			0xCB,
			0x00030039,
			0x0003002C,
			0x00030000,
			0x00030034,
			0x00030002,
			0xEA,
			0x00030000,
			0x00030000,
			0xE8,
			0x00030085,
			0x00030000,
			0x00030078,
			0xC0,
			0x00030023,
			0xC1,
			0x00030012,
			0xC2,
			0x00030011,
			0xC5,
			0x00030040,
			0x00030030,
			0xC7,
			0x000300A9,
			0x3A,
			0x00030055,
			0x36,
			0x00030008,
			0xB1,
			0x00030000,
			0x00030018,
			0xB6,
			0x0003000A,
			0x000300A2,
			0xF2,
			0x00030000,
			0xF7,
			0x00030020,
			0x26,
			0x00030001,
			0xE0,
			0x0003001F,
			0x00030024,
			0x00030023,
			0x0003000B,
			0x0003000F,
			0x00030008,
			0x00030050,
			0x000300D8,
			0x0003003B,
			0x00030008,
			0x0003000A,
			0x00030000,
			0x00030000,
			0x00030000,
			0x00030000,
			0xE1,
			0x00030000,
			0x0003001B,
			0x0003001C,
			0x00030004,
			0x00030010,
			0x00030007,
			0x0003002F,
			0x00030027,
			0x00030044,
			0x00030007,
			0x00030015,
			0x0003000F,
			0x0003003F,
			0x0003003F,
			0x0003001F,			
			0x29,
		},
		--
		sleepcmd = {
			0x10,
		},
		--
		wakecmd = {
			0x11,
		}
	}
	disp.init(para)
	disp.clear()
	disp.update()
end

--SPIŵĵѹ
pmd.ldoset(6,pmd.LDO_VMMC)
init()

--򿪱
--ʵʹʱûԼlcdƷʽӱƴ
--UART1 RTS/GPIO2LCDı
pio.pin.setdir(pio.OUTPUT,pio.P0_2)
pio.pin.setval(1,pio.P0_2)
