
DISP_8BPP = 0;
DISP_16BPP = 1;
 DISP_18BPP = 2;
---------lcd device ---------------------------------------------------------------
lua_lcd_info =
{
 176,			--disp_width;
 220,   		--disp_height;
 DISP_16BPP, 		--bpp;
 0,                 	--palette_support;
 0,                	--contrast_support;
 0,                    	--contrast_min;
 127,                    --contrast_max;
 80,                    	--contrast_default;
 1,                 	--backlight_support;
 0,                    	--backlight_min;
 100,                    --backlight_max;
 30,                   	--backlight_default;
 4,           		--lcd_type;
 0,                    	--phys_width;
 0                   	--phys_height;	
}
--lcd init config function
function lua_lcd_init()
return 1;
end

function lua_lcd_disp_data()
return 1;
end
------------------------------------------------------
--mdp update function
function Lua_lcdregcfg(Scrptr)
gpioex.mdpscrcfg(Scrptr,2,0x0A000000)
gpioex.mdpscrcfg(Scrptr,3,0x20000000)
gpioex.mdpscrcfg(Scrptr,4,0x0C000000);
gpioex.mdpscrcfg(Scrptr,5,0x20100000);
gpioex.mdpscrcfg(Scrptr,6,0x0B000000+0x21*2);	--
gpioex.mdpscrcfg(Scrptr,8,0x0B000000+0x44*2);	--
gpioex.mdpscrcfg(Scrptr,10,0x0B000000+0x45*2);	--
gpioex.mdpscrcfg(Scrptr,12,0x0B000000+0x22*2);	--
gpioex.mdpscrcfg(Scrptr,13,0x04000000);	--
return 1;
end

function Lua_lcdregcfg_gog(ScrPtr,lcdScrPtr,col_start,col_end,row_start,row_end)
--SET_LCD_FORMAT(0, 0x08);	
--#define SET_LCD_FORMAT(p1, p2) ((0x0F << 24) | (p1 << 8) | (p2)) 
gpioex.mdpscrcfg(ScrPtr,10,0x0F000000);
--SUBROUTINE
--#define SUBROUTINE            (0x03 << 24)
gpioex.mdpscrcfg(ScrPtr,14,0x03000000);
gpioex.mdpscrcfg(ScrPtr,15,lcdScrPtr);
--NOP
--#define NOP               (0x00 << 24)
gpioex.mdpscrcfg(ScrPtr,23,0x00000000);
--WAIT_JOB_DONE
--#define WAIT_JOB_DONE           (0x07 << 24)
gpioex.mdpscrcfg(ScrPtr,28,0x07000000);

-- value = ((0x0B << 24) | (p1 & 0x3FFFF))
gpioex.mdpscrcfg(lcdScrPtr,7,0x0E000000  + row_start*1024 + col_start*2);--
gpioex.mdpscrcfg(lcdScrPtr,9,0x0E000000  + col_end*1024 + col_start*2);	--
gpioex.mdpscrcfg(lcdScrPtr,11,0x0E000000  + row_end*1024 + row_start*2);--
return 1
end

function Lua_lcdregcfg_gov(ScrPtr,lcdScrPtr,col_start,col_end,row_start,row_end)
--SET_LCD_FORMAT(0, 0x08);	
--#define SET_LCD_FORMAT(p1, p2) ((0x0F << 24) | (p1 << 8) | (p2)) 
gpioex.mdpscrcfg(ScrPtr,28,0x0F000000);
--SUBROUTINE
--#define SUBROUTINE            (0x03 << 24)
gpioex.mdpscrcfg(ScrPtr,30,0x03000000);
gpioex.mdpscrcfg(ScrPtr,31,lcdScrPtr);
--NOP
--#define NOP               (0x00 << 24)
gpioex.mdpscrcfg(ScrPtr,41,0x00000000);
--WAIT_JOB_DONE
--#define WAIT_JOB_DONE           (0x07 << 24)
gpioex.mdpscrcfg(ScrPtr,43,0x07000000);

-- value = ((0x0B << 24) | (p1 & 0x3FFFF))
gpioex.mdpscrcfg(lcdScrPtr,7,0x0E000000  + row_start*1024 + col_start*2);	--
gpioex.mdpscrcfg(lcdScrPtr,9,0x0E000000  + col_end*1024 + col_start*2);	--
gpioex.mdpscrcfg(lcdScrPtr,11,0x0E000000  + row_end*1024 + row_start*2);	--

return 1
end

function Lua_lcdregcfg_vdo(ScrPtr,lcdScrPtr,col_start,col_end,row_start,row_end)
--SET_LCD_FORMAT(0, 0x08);	
--#define SET_LCD_FORMAT(p1, p2) ((0x0F << 24) | (p1 << 8) | (p2)) 
gpioex.mdpscrcfg(ScrPtr,23,0x0F000000);
--SUBROUTINE
--#define SUBROUTINE            (0x03 << 24)
gpioex.mdpscrcfg(ScrPtr,30,0x03000000);
gpioex.mdpscrcfg(ScrPtr,31,lcdScrPtr);
--NOP
--#define NOP               (0x00 << 24)
gpioex.mdpscrcfg(ScrPtr,37,0x00000000);
--WAIT_JOB_DONE
--#define WAIT_JOB_DONE           (0x07 << 24)
gpioex.mdpscrcfg(ScrPtr,39,0x07000000);

-- value = ((0x0B << 24) | (p1 & 0x3FFFF))
gpioex.mdpscrcfg(lcdScrPtr,7,0x0E000000  + row_start*1024 + col_start*2);	--
gpioex.mdpscrcfg(lcdScrPtr,9,0x0E000000  + col_end*1024 + col_start*2);	--
gpioex.mdpscrcfg(lcdScrPtr,11,0x0E000000  + row_end*1024 + row_start*2);	--
return 1
end

--the parameter can't be change
function Lua_lcdregcfg_gfx(ScrPtr,lcdScrPtr,col_start,col_end,row_start,row_end)
--SET_LCD_FORMAT(0, 0x08);	
--#define SET_LCD_FORMAT(p1, p2) ((0x0F << 24) | (p1 << 8) | (p2)) 
gpioex.mdpscrcfg(ScrPtr,7,0x0F000000);
--SUBROUTINE
--#define SUBROUTINE            (0x03 << 24)
gpioex.mdpscrcfg(ScrPtr,14,0x03000000);
gpioex.mdpscrcfg(ScrPtr,15,lcdScrPtr);
--NOP
--#define NOP               (0x00 << 24)
gpioex.mdpscrcfg(ScrPtr,18,0x00000000);
--WAIT_JOB_DONE
--#define WAIT_JOB_DONE           (0x07 << 24)
gpioex.mdpscrcfg(ScrPtr,22,0x07000000);

-- value = ((0x0B << 24) | (p1 & 0x3FFFF))
gpioex.mdpscrcfg(lcdScrPtr,7,0x0E000000  + row_start*1024 + col_start*2);	--
gpioex.mdpscrcfg(lcdScrPtr,9,0x0E000000  + col_end*1024 + col_start*2);	--
gpioex.mdpscrcfg(lcdScrPtr,11,0x0E000000  + row_end*1024 + row_start*2);	--
return 1;

end

-----------lcd device ----------------------------------


--//error code for the lua operation
LUALIB_OP_NO_CALL 		=	0x0000
LUALIB_OP_SUCCESS 		=	0x0001
LUALIB_OP_PARAMETERS_INVALID 	=	0x0002
LUALIB_OP_FAILED 		=	0x0003

PM_OFF_CMD = 0;
PM_ON_CMD  = 1;
PM_VREG_BOOST_ID = 19;
PM_VOTE_VREG_BOOST_APP__LCD = 1;
PM_VREG_LP_WLAN_ID = 7;

SND_MUTE_UNMUTED = 0;
SND_MUTE_MUTED = 1;

function Lua_LCDBacklightOn_Main(Level)
gpio.funsel(18,1)		--config as alternate function
   if Level == 1 then 
        gpioex.ringer(4)	--config the backlight level   
   elseif Level == 2 then      
        gpioex.ringer(8)	--config the backlight level       
   elseif Level == 3 then       
        gpioex.ringer(15)	--config the backlight level
   elseif Level == 4 then       
        gpioex.ringer(30)	--config the backlight level               
   elseif Level == 5 then       
        gpioex.ringer(80)	--config the backlight level 
   else
        gpioex.ringer(6*Level)	--config the backlight level     
   end
return 1
end
	


function Lua_LCDBacklightOn_Sub()
return 1
end

function Lua_LCDBacklightOff_Main()
gpio.funsel(18,1)		--config as alternate function
return gpioex.ringer(0)		--config the backlight level
end

function Lua_LCDBacklightOff_Sub()
return 1
end

function Lua_LCDOn_Main()
	gpioex.disp_cmd_out(0x10*2);
	gpioex.disp_data_out(0x00);
	gpioex.disp_cmd_out(0x11*2);
	gpioex.disp_data_out(0x00);
	gpioex.disp_cmd_out(0x12*2);
	gpioex.disp_data_out(0x00);
	gpioex.disp_cmd_out(0x13*2);
	gpioex.disp_data_out(0x00);
	gpioex.disp_cmd_out(0x13*2);
	gpioex.disp_data_out(0x11*1024+0x10*2);
	gpioex.disp_cmd_out(0x12*2);
	gpioex.disp_data_out(0x00*1024+0x08*2);
	gpioex.disp_cmd_out(0x10*2);
	gpioex.disp_data_out(0x41*1024+0x40*2);
	--delay 100ms
	gpioex.disp_cmd_out(0x10*2);
	gpioex.disp_data_out(0x00*1024+0x54*2);
	gpioex.disp_cmd_out(0x12*2);
	gpioex.disp_data_out(0x00*1024+0x13*2);
	gpioex.disp_cmd_out(0x10*2);
	gpioex.disp_data_out(0x41*1024+0x40*2);
	gpioex.disp_cmd_out(0x13*2);
	gpioex.disp_data_out(0x32*1024+0x10*2);
	
	gpioex.disp_cmd_out(0x07*2);
	gpioex.disp_data_out(0x00*1024+0x05*2);
	gpioex.disp_cmd_out(0x07*2);
	gpioex.disp_data_out(0x00*1024+0x25*2);
	gpioex.disp_cmd_out(0x07*2);
	gpioex.disp_data_out(0x00*1024+0x27*2);
	gpioex.disp_cmd_out(0x07*2);
	gpioex.disp_data_out(0x00*1024+0x37*2);
	
	gpioex.pm_vote_vreg_switch(PM_ON_CMD,PM_VREG_BOOST_ID,PM_VOTE_VREG_BOOST_APP__LCD);
	gpioex.pm_lp_mode_control(PM_OFF_CMD, PM_VREG_LP_WLAN_ID);
	for i=40000,1,-1 do
		gpioex.delay1f();
	end
return	1;
end

function Lua_LCDOn_Sub()
return 1
end

function Lua_LCDOff_Main()
	gpioex.disp_cmd_out(0x0B*2);
	gpioex.disp_data_out(0x00*1024+0x00*2);	
	gpioex.disp_cmd_out(0x07*2);
	gpioex.disp_data_out(0x00*1024+0x37*2);
	gpioex.disp_cmd_out(0x07*2);
	gpioex.disp_data_out(0x00*1024+0x27*2);
	gpioex.disp_cmd_out(0x07*2);
	gpioex.disp_data_out(0x00*1024+0x25*2);
	gpioex.disp_cmd_out(0x07*2);
	gpioex.disp_data_out(0x00*1024+0x05*2);
	gpioex.disp_cmd_out(0x07*2);
	gpioex.disp_data_out(0x00*1024+0x04*2);
	
	gpioex.disp_cmd_out(0x10*2);
	gpioex.disp_data_out(0x00*1024+0x00*2);
	gpioex.disp_cmd_out(0x11*2);
	gpioex.disp_data_out(0x00*1024+0x00*2);
	gpioex.disp_cmd_out(0x12*2);
	gpioex.disp_data_out(0x00*1024+0x00*2);
	gpioex.disp_cmd_out(0x13*2);
	gpioex.disp_data_out(0x00*1024+0x00*2);
	
	gpioex.pm_vote_vreg_switch(PM_OFF_CMD,PM_VREG_BOOST_ID,PM_VOTE_VREG_BOOST_APP__LCD);
	gpioex.pm_lp_mode_control(PM_ON_CMD, PM_VREG_LP_WLAN_ID);
return 1;
end

function Lua_LCDOff_Sub()
return 1
end

function Lua_FlashLightOn()
return gpioex.pm_flash_led(300);
end

function Lua_FlashLightOff()
return gpioex.pm_flash_led(0);
end

function Lua_EarPhoneOn()
return gpioex.snd_set_earphone(SND_MUTE_UNMUTED,SND_MUTE_UNMUTED)
end

function Lua_EarPhoneOff()
return gpioex.snd_set_earphone(SND_MUTE_MUTED,SND_MUTE_MUTED)
end

function Lua_KeyLightOn(Level)
return gpioex.pm_keypad_led(Level);
end

function Lua_KeyLightOff()
return gpioex.pm_keypad_led(0);
end

function Lua_VibOn()
return gpioex.vib_ctrl(3000);
end

function Lua_VibOff()
return gpioex.vib_ctrl(0);
end

function Lua_SpeakerOn()
return gpioex.snd_set_speaker(SND_MUTE_UNMUTED,SND_MUTE_UNMUTED);
end

function Lua_SpeakerOff()
return gpioex.snd_set_speaker(SND_MUTE_MUTED,SND_MUTE_MUTED);
end



function gpio_87_isr1()
--backlight on
gpioex.ringer(0)

return gpioex.int(87,0,0,gpio_87_isr2)

end

function gpio_87_isr2()
--backlight off
gpioex.ringer(10)

return gpioex.int(87,0,1,gpio_87_isr1)

end

--gpioex.int(87,0,1,gpio_87_isr1);

