1. Modify the file indention
2. Modify the license head
This commit is contained in:
parent
c0947d443a
commit
4b035622ce
@ -11,16 +11,16 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
rt_device_t device;
|
rt_device_t device;
|
||||||
|
|
||||||
printf("hello rt-thread\n");
|
printf("hello rt-thread\n");
|
||||||
|
|
||||||
#ifdef PKG_USING_GUIENGINE
|
#ifdef PKG_USING_GUIENGINE
|
||||||
device = rt_device_find("lcd");
|
device = rt_device_find("lcd");
|
||||||
if (device)
|
if (device)
|
||||||
{
|
{
|
||||||
rtgui_graphic_set_device(device);
|
rtgui_graphic_set_device(device);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,29 +6,29 @@
|
|||||||
|
|
||||||
int mnt_init(void)
|
int mnt_init(void)
|
||||||
{
|
{
|
||||||
rt_uint32_t tryCnt = 5;
|
rt_uint32_t tryCnt = 5;
|
||||||
rt_device_t dev;
|
rt_device_t dev;
|
||||||
|
|
||||||
while(tryCnt--)
|
while(tryCnt--)
|
||||||
{
|
{
|
||||||
dev = rt_device_find("sd0");
|
dev = rt_device_find("sd0");
|
||||||
if(dev != RT_NULL)
|
if(dev != RT_NULL)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rt_thread_mdelay(500);
|
rt_thread_mdelay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dfs_mount("sd0", "/", "elm", 0, 0) == 0)
|
if(dfs_mount("sd0", "/", "elm", 0, 0) == 0)
|
||||||
{
|
{
|
||||||
rt_kprintf("File System initialized!\n");
|
rt_kprintf("File System initialized!\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rt_kprintf("File System initialzation failed!\n");
|
rt_kprintf("File System initialzation failed!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
INIT_ENV_EXPORT(mnt_init);
|
INIT_ENV_EXPORT(mnt_init);
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,7 +27,7 @@ if GetDepend('RT_MINI2440_LCD_X35'):
|
|||||||
src += ['lcd_x35.c']
|
src += ['lcd_x35.c']
|
||||||
|
|
||||||
if GetDepend('PKG_USING_GUIENGINE'):
|
if GetDepend('PKG_USING_GUIENGINE'):
|
||||||
src += ['touch.c']
|
src += ['touch.c']
|
||||||
|
|
||||||
if GetDepend('RT_USING_SDIO'):
|
if GetDepend('RT_USING_SDIO'):
|
||||||
src += ['s3cmci.c']
|
src += ['s3cmci.c']
|
||||||
|
@ -34,81 +34,81 @@
|
|||||||
#define SCR_XSIZE LCD_WIDTH
|
#define SCR_XSIZE LCD_WIDTH
|
||||||
#define SCR_YSIZE LCD_HEIGHT
|
#define SCR_YSIZE LCD_HEIGHT
|
||||||
|
|
||||||
#define RT_HW_LCD_WIDTH LCD_WIDTH
|
#define RT_HW_LCD_WIDTH LCD_WIDTH
|
||||||
#define RT_HW_LCD_HEIGHT LCD_HEIGHT
|
#define RT_HW_LCD_HEIGHT LCD_HEIGHT
|
||||||
|
|
||||||
#define MVAL (13)
|
#define MVAL (13)
|
||||||
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
|
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
|
||||||
#define INVVDEN (1) //0=normal 1=inverted
|
#define INVVDEN (1) //0=normal 1=inverted
|
||||||
#define BSWP (0) //Byte swap control
|
#define BSWP (0) //Byte swap control
|
||||||
#define HWSWP (1) //Half word swap control
|
#define HWSWP (1) //Half word swap control
|
||||||
|
|
||||||
#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004)
|
#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004)
|
||||||
#define GPB1_TO_1() (GPBDAT |= 0x0002)
|
#define GPB1_TO_1() (GPBDAT |= 0x0002)
|
||||||
#define GPB1_TO_0() (GPBDAT &= 0xfffd)
|
#define GPB1_TO_0() (GPBDAT &= 0xfffd)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON1_MMODE (1<<7)
|
#define S3C2410_LCDCON1_MMODE (1<<7)
|
||||||
#define S3C2410_LCDCON1_DSCAN4 (0<<5)
|
#define S3C2410_LCDCON1_DSCAN4 (0<<5)
|
||||||
#define S3C2410_LCDCON1_STN4 (1<<5)
|
#define S3C2410_LCDCON1_STN4 (1<<5)
|
||||||
#define S3C2410_LCDCON1_STN8 (2<<5)
|
#define S3C2410_LCDCON1_STN8 (2<<5)
|
||||||
#define S3C2410_LCDCON1_TFT (3<<5)
|
#define S3C2410_LCDCON1_TFT (3<<5)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_STN1BPP (0<<1)
|
#define S3C2410_LCDCON1_STN1BPP (0<<1)
|
||||||
#define S3C2410_LCDCON1_STN2GREY (1<<1)
|
#define S3C2410_LCDCON1_STN2GREY (1<<1)
|
||||||
#define S3C2410_LCDCON1_STN4GREY (2<<1)
|
#define S3C2410_LCDCON1_STN4GREY (2<<1)
|
||||||
#define S3C2410_LCDCON1_STN8BPP (3<<1)
|
#define S3C2410_LCDCON1_STN8BPP (3<<1)
|
||||||
#define S3C2410_LCDCON1_STN12BPP (4<<1)
|
#define S3C2410_LCDCON1_STN12BPP (4<<1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_TFT1BPP (8<<1)
|
#define S3C2410_LCDCON1_TFT1BPP (8<<1)
|
||||||
#define S3C2410_LCDCON1_TFT2BPP (9<<1)
|
#define S3C2410_LCDCON1_TFT2BPP (9<<1)
|
||||||
#define S3C2410_LCDCON1_TFT4BPP (10<<1)
|
#define S3C2410_LCDCON1_TFT4BPP (10<<1)
|
||||||
#define S3C2410_LCDCON1_TFT8BPP (11<<1)
|
#define S3C2410_LCDCON1_TFT8BPP (11<<1)
|
||||||
#define S3C2410_LCDCON1_TFT16BPP (12<<1)
|
#define S3C2410_LCDCON1_TFT16BPP (12<<1)
|
||||||
#define S3C2410_LCDCON1_TFT24BPP (13<<1)
|
#define S3C2410_LCDCON1_TFT24BPP (13<<1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_ENVID (1)
|
#define S3C2410_LCDCON1_ENVID (1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_MODEMASK 0x1E
|
#define S3C2410_LCDCON1_MODEMASK 0x1E
|
||||||
|
|
||||||
#define S3C2410_LCDCON2_VBPD(x) ((x) << 24)
|
#define S3C2410_LCDCON2_VBPD(x) ((x) << 24)
|
||||||
#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14)
|
#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14)
|
||||||
#define S3C2410_LCDCON2_VFPD(x) ((x) << 6)
|
#define S3C2410_LCDCON2_VFPD(x) ((x) << 6)
|
||||||
#define S3C2410_LCDCON2_VSPW(x) ((x) << 0)
|
#define S3C2410_LCDCON2_VSPW(x) ((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF)
|
#define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF)
|
||||||
#define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF)
|
#define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF)
|
||||||
#define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F)
|
#define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F)
|
||||||
|
|
||||||
#define S3C2410_LCDCON3_HBPD(x) ((x) << 19)
|
#define S3C2410_LCDCON3_HBPD(x) ((x) << 19)
|
||||||
#define S3C2410_LCDCON3_WDLY(x) ((x) << 19)
|
#define S3C2410_LCDCON3_WDLY(x) ((x) << 19)
|
||||||
#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON3_HFPD(x) ((x) << 0)
|
#define S3C2410_LCDCON3_HFPD(x) ((x) << 0)
|
||||||
#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0)
|
#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F)
|
#define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F)
|
||||||
#define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF)
|
#define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF)
|
||||||
|
|
||||||
#define S3C2410_LCDCON4_MVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON4_MVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON4_HSPW(x) ((x) << 0)
|
#define S3C2410_LCDCON4_HSPW(x) ((x) << 0)
|
||||||
#define S3C2410_LCDCON4_WLH(x) ((x) << 0)
|
#define S3C2410_LCDCON4_WLH(x) ((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF)
|
#define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF)
|
||||||
|
|
||||||
#define S3C2410_LCDCON5_BPP24BL (1<<12)
|
#define S3C2410_LCDCON5_BPP24BL (1<<12)
|
||||||
#define S3C2410_LCDCON5_FRM565 (1<<11)
|
#define S3C2410_LCDCON5_FRM565 (1<<11)
|
||||||
#define S3C2410_LCDCON5_INVVCLK (1<<10)
|
#define S3C2410_LCDCON5_INVVCLK (1<<10)
|
||||||
#define S3C2410_LCDCON5_INVVLINE (1<<9)
|
#define S3C2410_LCDCON5_INVVLINE (1<<9)
|
||||||
#define S3C2410_LCDCON5_INVVFRAME (1<<8)
|
#define S3C2410_LCDCON5_INVVFRAME (1<<8)
|
||||||
#define S3C2410_LCDCON5_INVVD (1<<7)
|
#define S3C2410_LCDCON5_INVVD (1<<7)
|
||||||
#define S3C2410_LCDCON5_INVVDEN (1<<6)
|
#define S3C2410_LCDCON5_INVVDEN (1<<6)
|
||||||
#define S3C2410_LCDCON5_INVPWREN (1<<5)
|
#define S3C2410_LCDCON5_INVPWREN (1<<5)
|
||||||
#define S3C2410_LCDCON5_INVLEND (1<<4)
|
#define S3C2410_LCDCON5_INVLEND (1<<4)
|
||||||
#define S3C2410_LCDCON5_PWREN (1<<3)
|
#define S3C2410_LCDCON5_PWREN (1<<3)
|
||||||
#define S3C2410_LCDCON5_ENLEND (1<<2)
|
#define S3C2410_LCDCON5_ENLEND (1<<2)
|
||||||
#define S3C2410_LCDCON5_BSWP (1<<1)
|
#define S3C2410_LCDCON5_BSWP (1<<1)
|
||||||
#define S3C2410_LCDCON5_HWSWP (1<<0)
|
#define S3C2410_LCDCON5_HWSWP (1<<0)
|
||||||
#define S3C2410_LCDINT_FRSYNC (1<<1)
|
#define S3C2410_LCDINT_FRSYNC (1<<1)
|
||||||
|
|
||||||
static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
||||||
//static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
//static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
||||||
@ -127,123 +127,123 @@ static void lcd_power_enable(int invpwren, int pwren)
|
|||||||
|
|
||||||
static void lcd_envid_on_off(int onoff)
|
static void lcd_envid_on_off(int onoff)
|
||||||
{
|
{
|
||||||
if(onoff==1)
|
if(onoff==1)
|
||||||
/*ENVID=ON*/
|
/*ENVID=ON*/
|
||||||
LCDCON1|=1;
|
LCDCON1|=1;
|
||||||
else
|
else
|
||||||
/*ENVID Off*/
|
/*ENVID Off*/
|
||||||
LCDCON1 =LCDCON1 & 0x3fffe;
|
LCDCON1 =LCDCON1 & 0x3fffe;
|
||||||
}
|
}
|
||||||
|
|
||||||
//********************** BOARD LCD backlight ****************************
|
//********************** BOARD LCD backlight ****************************
|
||||||
static void LcdBkLtSet(rt_uint32_t HiRatio)
|
static void LcdBkLtSet(rt_uint32_t HiRatio)
|
||||||
{
|
{
|
||||||
#define FREQ_PWM1 1000
|
#define FREQ_PWM1 1000
|
||||||
if(!HiRatio)
|
if(!HiRatio)
|
||||||
{
|
{
|
||||||
GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1ÉèÖÃΪoutput
|
GPBCON = GPBCON & (~(3<<2)) | (1<<2) ;
|
||||||
GPBDAT &= ~(1<<1);
|
GPBDAT &= ~(1<<1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GPBCON = GPBCON & (~(3<<2)) | (2<<2) ;
|
GPBCON = GPBCON & (~(3<<2)) | (2<<2) ;
|
||||||
|
|
||||||
if( HiRatio > 100 ) HiRatio = 100 ;
|
if( HiRatio > 100 ) HiRatio = 100 ;
|
||||||
|
|
||||||
TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1
|
TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1
|
||||||
|
|
||||||
TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0
|
TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0
|
||||||
TCFG0 |= 15; //prescaler = 15+1
|
TCFG0 |= 15; //prescaler = 15+1
|
||||||
|
|
||||||
TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16
|
TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16
|
||||||
TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16
|
TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16
|
||||||
|
|
||||||
TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
|
TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
|
||||||
TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
|
TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
|
||||||
|
|
||||||
TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ;
|
TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ;
|
||||||
TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ;
|
TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RT-Thread Device Interface */
|
/* RT-Thread Device Interface */
|
||||||
static rt_err_t rt_lcd_init (rt_device_t dev)
|
static rt_err_t rt_lcd_init (rt_device_t dev)
|
||||||
{
|
{
|
||||||
GPB1_TO_OUT();
|
GPB1_TO_OUT();
|
||||||
GPB1_TO_1();
|
GPB1_TO_1();
|
||||||
|
|
||||||
GPCUP = 0x00000000;
|
GPCUP = 0x00000000;
|
||||||
GPCCON = 0xaaaa02a9;
|
GPCCON = 0xaaaa02a9;
|
||||||
|
|
||||||
GPDUP = 0x00000000;
|
GPDUP = 0x00000000;
|
||||||
GPDCON = 0xaaaaaaaa;
|
GPDCON = 0xaaaaaaaa;
|
||||||
|
|
||||||
#define M5D(n) ((n)&0x1fffff)
|
#define M5D(n) ((n)&0x1fffff)
|
||||||
#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer)
|
#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer)
|
||||||
LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
|
LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
|
||||||
LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0);
|
LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0);
|
||||||
LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0);
|
LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0);
|
||||||
LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0);
|
LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0);
|
||||||
#if !defined(LCD_CON5)
|
#if !defined(LCD_CON5)
|
||||||
#define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0))
|
#define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0))
|
||||||
#endif
|
#endif
|
||||||
LCDCON5 = LCD_CON5;
|
LCDCON5 = LCD_CON5;
|
||||||
|
|
||||||
LCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) << 0);
|
LCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) << 0);
|
||||||
LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
|
LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
|
||||||
LCDSADDR3 = LCD_WIDTH;
|
LCDSADDR3 = LCD_WIDTH;
|
||||||
|
|
||||||
LCDINTMSK |= (3);
|
LCDINTMSK |= (3);
|
||||||
LPCSEL &= (~7) ;
|
LPCSEL &= (~7) ;
|
||||||
TPAL=0;
|
TPAL=0;
|
||||||
|
|
||||||
LcdBkLtSet(70) ;
|
LcdBkLtSet(70) ;
|
||||||
lcd_power_enable(0, 1);
|
lcd_power_enable(0, 1);
|
||||||
lcd_envid_on_off(1);
|
lcd_envid_on_off(1);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
|
static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_POWERON:
|
case RTGRAPHIC_CTRL_POWERON:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_POWEROFF:
|
case RTGRAPHIC_CTRL_POWEROFF:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_GET_INFO:
|
case RTGRAPHIC_CTRL_GET_INFO:
|
||||||
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
|
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_SET_MODE:
|
case RTGRAPHIC_CTRL_SET_MODE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rt_hw_lcd_init(void)
|
int rt_hw_lcd_init(void)
|
||||||
{
|
{
|
||||||
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
|
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
|
||||||
if (lcd == RT_NULL)
|
if (lcd == RT_NULL)
|
||||||
return -RT_ERROR; /* no memory yet */
|
return -RT_ERROR; /* no memory yet */
|
||||||
|
|
||||||
_lcd_info.bits_per_pixel = 16;
|
_lcd_info.bits_per_pixel = 16;
|
||||||
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
||||||
_lcd_info.framebuffer = (void*)_rt_framebuffer;
|
_lcd_info.framebuffer = (void*)_rt_framebuffer;
|
||||||
_lcd_info.width = LCD_WIDTH;
|
_lcd_info.width = LCD_WIDTH;
|
||||||
_lcd_info.height = LCD_HEIGHT;
|
_lcd_info.height = LCD_HEIGHT;
|
||||||
|
|
||||||
/* init device structure */
|
/* init device structure */
|
||||||
lcd->type = RT_Device_Class_Unknown;
|
lcd->type = RT_Device_Class_Unknown;
|
||||||
lcd->init = rt_lcd_init;
|
lcd->init = rt_lcd_init;
|
||||||
lcd->open = RT_NULL;
|
lcd->open = RT_NULL;
|
||||||
lcd->close = RT_NULL;
|
lcd->close = RT_NULL;
|
||||||
lcd->control = rt_lcd_control;
|
lcd->control = rt_lcd_control;
|
||||||
lcd->user_data = (void*)&_lcd_info;
|
lcd->user_data = (void*)&_lcd_info;
|
||||||
|
|
||||||
/* register lcd device to RT-Thread */
|
/* register lcd device to RT-Thread */
|
||||||
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
|
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_BOARD_EXPORT(rt_hw_lcd_init);
|
INIT_BOARD_EXPORT(rt_hw_lcd_init);
|
||||||
|
@ -34,82 +34,82 @@
|
|||||||
#define SCR_XSIZE LCD_WIDTH
|
#define SCR_XSIZE LCD_WIDTH
|
||||||
#define SCR_YSIZE LCD_HEIGHT
|
#define SCR_YSIZE LCD_HEIGHT
|
||||||
|
|
||||||
#define RT_HW_LCD_WIDTH LCD_WIDTH
|
#define RT_HW_LCD_WIDTH LCD_WIDTH
|
||||||
#define RT_HW_LCD_HEIGHT LCD_HEIGHT
|
#define RT_HW_LCD_HEIGHT LCD_HEIGHT
|
||||||
|
|
||||||
#define MVAL (13)
|
#define MVAL (13)
|
||||||
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
|
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
|
||||||
#define INVVDEN (1) //0=normal 1=inverted
|
#define INVVDEN (1) //0=normal 1=inverted
|
||||||
#define BSWP (0) //Byte swap control
|
#define BSWP (0) //Byte swap control
|
||||||
#define HWSWP (1) //Half word swap control
|
#define HWSWP (1) //Half word swap control
|
||||||
|
|
||||||
#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004)
|
#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004)
|
||||||
#define GPB1_TO_1() (GPBDAT |= 0x0002)
|
#define GPB1_TO_1() (GPBDAT |= 0x0002)
|
||||||
#define GPB1_TO_0() (GPBDAT &= 0xfffd)
|
#define GPB1_TO_0() (GPBDAT &= 0xfffd)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON1_MMODE (1<<7)
|
#define S3C2410_LCDCON1_MMODE (1<<7)
|
||||||
#define S3C2410_LCDCON1_DSCAN4 (0<<5)
|
#define S3C2410_LCDCON1_DSCAN4 (0<<5)
|
||||||
#define S3C2410_LCDCON1_STN4 (1<<5)
|
#define S3C2410_LCDCON1_STN4 (1<<5)
|
||||||
#define S3C2410_LCDCON1_STN8 (2<<5)
|
#define S3C2410_LCDCON1_STN8 (2<<5)
|
||||||
#define S3C2410_LCDCON1_TFT (3<<5)
|
#define S3C2410_LCDCON1_TFT (3<<5)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_STN1BPP (0<<1)
|
#define S3C2410_LCDCON1_STN1BPP (0<<1)
|
||||||
#define S3C2410_LCDCON1_STN2GREY (1<<1)
|
#define S3C2410_LCDCON1_STN2GREY (1<<1)
|
||||||
#define S3C2410_LCDCON1_STN4GREY (2<<1)
|
#define S3C2410_LCDCON1_STN4GREY (2<<1)
|
||||||
#define S3C2410_LCDCON1_STN8BPP (3<<1)
|
#define S3C2410_LCDCON1_STN8BPP (3<<1)
|
||||||
#define S3C2410_LCDCON1_STN12BPP (4<<1)
|
#define S3C2410_LCDCON1_STN12BPP (4<<1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_TFT1BPP (8<<1)
|
#define S3C2410_LCDCON1_TFT1BPP (8<<1)
|
||||||
#define S3C2410_LCDCON1_TFT2BPP (9<<1)
|
#define S3C2410_LCDCON1_TFT2BPP (9<<1)
|
||||||
#define S3C2410_LCDCON1_TFT4BPP (10<<1)
|
#define S3C2410_LCDCON1_TFT4BPP (10<<1)
|
||||||
#define S3C2410_LCDCON1_TFT8BPP (11<<1)
|
#define S3C2410_LCDCON1_TFT8BPP (11<<1)
|
||||||
#define S3C2410_LCDCON1_TFT16BPP (12<<1)
|
#define S3C2410_LCDCON1_TFT16BPP (12<<1)
|
||||||
#define S3C2410_LCDCON1_TFT24BPP (13<<1)
|
#define S3C2410_LCDCON1_TFT24BPP (13<<1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_ENVID (1)
|
#define S3C2410_LCDCON1_ENVID (1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_MODEMASK 0x1E
|
#define S3C2410_LCDCON1_MODEMASK 0x1E
|
||||||
|
|
||||||
#define S3C2410_LCDCON2_VBPD(x) ((x) << 24)
|
#define S3C2410_LCDCON2_VBPD(x) ((x) << 24)
|
||||||
#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14)
|
#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14)
|
||||||
#define S3C2410_LCDCON2_VFPD(x) ((x) << 6)
|
#define S3C2410_LCDCON2_VFPD(x) ((x) << 6)
|
||||||
#define S3C2410_LCDCON2_VSPW(x) ((x) << 0)
|
#define S3C2410_LCDCON2_VSPW(x) ((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF)
|
#define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF)
|
||||||
#define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF)
|
#define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF)
|
||||||
#define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F)
|
#define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F)
|
||||||
|
|
||||||
#define S3C2410_LCDCON3_HBPD(x) ((x) << 19)
|
#define S3C2410_LCDCON3_HBPD(x) ((x) << 19)
|
||||||
#define S3C2410_LCDCON3_WDLY(x) ((x) << 19)
|
#define S3C2410_LCDCON3_WDLY(x) ((x) << 19)
|
||||||
#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON3_HFPD(x) ((x) << 0)
|
#define S3C2410_LCDCON3_HFPD(x) ((x) << 0)
|
||||||
#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0)
|
#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F)
|
#define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F)
|
||||||
#define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF)
|
#define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF)
|
||||||
|
|
||||||
#define S3C2410_LCDCON4_MVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON4_MVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON4_HSPW(x) ((x) << 0)
|
#define S3C2410_LCDCON4_HSPW(x) ((x) << 0)
|
||||||
#define S3C2410_LCDCON4_WLH(x) ((x) << 0)
|
#define S3C2410_LCDCON4_WLH(x) ((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF)
|
#define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF)
|
||||||
|
|
||||||
#define S3C2410_LCDCON5_BPP24BL (1<<12)
|
#define S3C2410_LCDCON5_BPP24BL (1<<12)
|
||||||
#define S3C2410_LCDCON5_FRM565 (1<<11)
|
#define S3C2410_LCDCON5_FRM565 (1<<11)
|
||||||
#define S3C2410_LCDCON5_INVVCLK (1<<10)
|
#define S3C2410_LCDCON5_INVVCLK (1<<10)
|
||||||
#define S3C2410_LCDCON5_INVVLINE (1<<9)
|
#define S3C2410_LCDCON5_INVVLINE (1<<9)
|
||||||
#define S3C2410_LCDCON5_INVVFRAME (1<<8)
|
#define S3C2410_LCDCON5_INVVFRAME (1<<8)
|
||||||
#define S3C2410_LCDCON5_INVVD (1<<7)
|
#define S3C2410_LCDCON5_INVVD (1<<7)
|
||||||
#define S3C2410_LCDCON5_INVVDEN (1<<6)
|
#define S3C2410_LCDCON5_INVVDEN (1<<6)
|
||||||
#define S3C2410_LCDCON5_INVPWREN (1<<5)
|
#define S3C2410_LCDCON5_INVPWREN (1<<5)
|
||||||
#define S3C2410_LCDCON5_INVLEND (1<<4)
|
#define S3C2410_LCDCON5_INVLEND (1<<4)
|
||||||
#define S3C2410_LCDCON5_PWREN (1<<3)
|
#define S3C2410_LCDCON5_PWREN (1<<3)
|
||||||
#define S3C2410_LCDCON5_ENLEND (1<<2)
|
#define S3C2410_LCDCON5_ENLEND (1<<2)
|
||||||
#define S3C2410_LCDCON5_BSWP (1<<1)
|
#define S3C2410_LCDCON5_BSWP (1<<1)
|
||||||
#define S3C2410_LCDCON5_HWSWP (1<<0)
|
#define S3C2410_LCDCON5_HWSWP (1<<0)
|
||||||
|
|
||||||
#define S3C2410_LCDINT_FRSYNC (1<<1)
|
#define S3C2410_LCDINT_FRSYNC (1<<1)
|
||||||
|
|
||||||
static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
||||||
//static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
//static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
||||||
@ -128,61 +128,61 @@ static void lcd_power_enable(int invpwren, int pwren)
|
|||||||
|
|
||||||
static void lcd_envid_on_off(int onoff)
|
static void lcd_envid_on_off(int onoff)
|
||||||
{
|
{
|
||||||
if(onoff==1)
|
if(onoff==1)
|
||||||
/*ENVID=ON*/
|
/*ENVID=ON*/
|
||||||
LCDCON1|=1;
|
LCDCON1|=1;
|
||||||
else
|
else
|
||||||
/*ENVID Off*/
|
/*ENVID Off*/
|
||||||
LCDCON1 =LCDCON1 & 0x3fffe;
|
LCDCON1 =LCDCON1 & 0x3fffe;
|
||||||
}
|
}
|
||||||
|
|
||||||
//********************** BOARD LCD backlight ****************************
|
//********************** BOARD LCD backlight ****************************
|
||||||
static void LcdBkLtSet(rt_uint32_t HiRatio)
|
static void LcdBkLtSet(rt_uint32_t HiRatio)
|
||||||
{
|
{
|
||||||
#define FREQ_PWM1 1000
|
#define FREQ_PWM1 1000
|
||||||
if(!HiRatio)
|
if(!HiRatio)
|
||||||
{
|
{
|
||||||
GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1ÉèÖÃΪoutput
|
GPBCON = GPBCON & (~(3<<2)) | (1<<2) ;
|
||||||
GPBDAT &= ~(1<<1);
|
GPBDAT &= ~(1<<1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GPBCON = GPBCON & (~(3<<2)) | (2<<2) ;
|
GPBCON = GPBCON & (~(3<<2)) | (2<<2) ;
|
||||||
|
|
||||||
if( HiRatio > 100 ) HiRatio = 100 ;
|
if( HiRatio > 100 ) HiRatio = 100 ;
|
||||||
|
|
||||||
TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1
|
TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1
|
||||||
|
|
||||||
TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0
|
TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0
|
||||||
TCFG0 |= 15; //prescaler = 15+1
|
TCFG0 |= 15; //prescaler = 15+1
|
||||||
|
|
||||||
TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16
|
TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16
|
||||||
TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16
|
TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16
|
||||||
|
|
||||||
TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
|
TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
|
||||||
TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
|
TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
|
||||||
|
|
||||||
TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ;
|
TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ;
|
||||||
TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ;
|
TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RT-Thread Device Interface */
|
/* RT-Thread Device Interface */
|
||||||
static rt_err_t rt_lcd_init (rt_device_t dev)
|
static rt_err_t rt_lcd_init (rt_device_t dev)
|
||||||
{
|
{
|
||||||
GPB1_TO_OUT();
|
GPB1_TO_OUT();
|
||||||
GPB1_TO_1();
|
GPB1_TO_1();
|
||||||
|
|
||||||
GPCUP = 0x00000000;
|
GPCUP = 0x00000000;
|
||||||
GPCCON = 0xaaaa02a9;
|
GPCCON = 0xaaaa02a9;
|
||||||
|
|
||||||
GPDUP = 0x00000000;
|
GPDUP = 0x00000000;
|
||||||
GPDCON = 0xaaaaaaaa;
|
GPDCON = 0xaaaaaaaa;
|
||||||
|
|
||||||
#define M5D(n) ((n)&0x1fffff)
|
#define M5D(n) ((n)&0x1fffff)
|
||||||
#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer)
|
#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer)
|
||||||
LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
|
LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
|
||||||
LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0);
|
LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0);
|
||||||
LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0);
|
LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0);
|
||||||
LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0);
|
LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0);
|
||||||
#if !defined(LCD_CON5)
|
#if !defined(LCD_CON5)
|
||||||
#define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0))
|
#define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0))
|
||||||
#endif
|
#endif
|
||||||
@ -192,59 +192,59 @@ static rt_err_t rt_lcd_init (rt_device_t dev)
|
|||||||
LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
|
LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
|
||||||
LCDSADDR3 = LCD_WIDTH;
|
LCDSADDR3 = LCD_WIDTH;
|
||||||
|
|
||||||
LCDINTMSK |= (3);
|
LCDINTMSK |= (3);
|
||||||
LPCSEL &= (~7) ;
|
LPCSEL &= (~7) ;
|
||||||
TPAL=0;
|
TPAL=0;
|
||||||
|
|
||||||
LcdBkLtSet(70) ;
|
LcdBkLtSet(70) ;
|
||||||
lcd_power_enable(0, 1);
|
lcd_power_enable(0, 1);
|
||||||
lcd_envid_on_off(1);
|
lcd_envid_on_off(1);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
|
static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_POWERON:
|
case RTGRAPHIC_CTRL_POWERON:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_POWEROFF:
|
case RTGRAPHIC_CTRL_POWEROFF:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_GET_INFO:
|
case RTGRAPHIC_CTRL_GET_INFO:
|
||||||
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
|
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_SET_MODE:
|
case RTGRAPHIC_CTRL_SET_MODE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rt_hw_lcd_init(void)
|
int rt_hw_lcd_init(void)
|
||||||
{
|
{
|
||||||
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
|
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
|
||||||
if (lcd == RT_NULL)
|
if (lcd == RT_NULL)
|
||||||
return -RT_ERROR; /* no memory yet */
|
return -RT_ERROR; /* no memory yet */
|
||||||
|
|
||||||
_lcd_info.bits_per_pixel = 16;
|
_lcd_info.bits_per_pixel = 16;
|
||||||
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
||||||
_lcd_info.framebuffer = (void*)_rt_framebuffer;
|
_lcd_info.framebuffer = (void*)_rt_framebuffer;
|
||||||
_lcd_info.width = LCD_WIDTH;
|
_lcd_info.width = LCD_WIDTH;
|
||||||
_lcd_info.height = LCD_HEIGHT;
|
_lcd_info.height = LCD_HEIGHT;
|
||||||
|
|
||||||
/* init device structure */
|
/* init device structure */
|
||||||
lcd->type = RT_Device_Class_Unknown;
|
lcd->type = RT_Device_Class_Unknown;
|
||||||
lcd->init = rt_lcd_init;
|
lcd->init = rt_lcd_init;
|
||||||
lcd->open = RT_NULL;
|
lcd->open = RT_NULL;
|
||||||
lcd->close = RT_NULL;
|
lcd->close = RT_NULL;
|
||||||
lcd->control = rt_lcd_control;
|
lcd->control = rt_lcd_control;
|
||||||
lcd->user_data = (void*)&_lcd_info;
|
lcd->user_data = (void*)&_lcd_info;
|
||||||
|
|
||||||
/* register lcd device to RT-Thread */
|
/* register lcd device to RT-Thread */
|
||||||
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
|
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_BOARD_EXPORT(rt_hw_lcd_init);
|
INIT_BOARD_EXPORT(rt_hw_lcd_init);
|
||||||
|
@ -34,82 +34,82 @@
|
|||||||
#define SCR_XSIZE LCD_WIDTH
|
#define SCR_XSIZE LCD_WIDTH
|
||||||
#define SCR_YSIZE LCD_HEIGHT
|
#define SCR_YSIZE LCD_HEIGHT
|
||||||
|
|
||||||
#define RT_HW_LCD_WIDTH LCD_WIDTH
|
#define RT_HW_LCD_WIDTH LCD_WIDTH
|
||||||
#define RT_HW_LCD_HEIGHT LCD_HEIGHT
|
#define RT_HW_LCD_HEIGHT LCD_HEIGHT
|
||||||
|
|
||||||
#define MVAL (13)
|
#define MVAL (13)
|
||||||
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
|
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
|
||||||
#define INVVDEN (1) //0=normal 1=inverted
|
#define INVVDEN (1) //0=normal 1=inverted
|
||||||
#define BSWP (0) //Byte swap control
|
#define BSWP (0) //Byte swap control
|
||||||
#define HWSWP (1) //Half word swap control
|
#define HWSWP (1) //Half word swap control
|
||||||
|
|
||||||
#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004)
|
#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004)
|
||||||
#define GPB1_TO_1() (GPBDAT |= 0x0002)
|
#define GPB1_TO_1() (GPBDAT |= 0x0002)
|
||||||
#define GPB1_TO_0() (GPBDAT &= 0xfffd)
|
#define GPB1_TO_0() (GPBDAT &= 0xfffd)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON1_MMODE (1<<7)
|
#define S3C2410_LCDCON1_MMODE (1<<7)
|
||||||
#define S3C2410_LCDCON1_DSCAN4 (0<<5)
|
#define S3C2410_LCDCON1_DSCAN4 (0<<5)
|
||||||
#define S3C2410_LCDCON1_STN4 (1<<5)
|
#define S3C2410_LCDCON1_STN4 (1<<5)
|
||||||
#define S3C2410_LCDCON1_STN8 (2<<5)
|
#define S3C2410_LCDCON1_STN8 (2<<5)
|
||||||
#define S3C2410_LCDCON1_TFT (3<<5)
|
#define S3C2410_LCDCON1_TFT (3<<5)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_STN1BPP (0<<1)
|
#define S3C2410_LCDCON1_STN1BPP (0<<1)
|
||||||
#define S3C2410_LCDCON1_STN2GREY (1<<1)
|
#define S3C2410_LCDCON1_STN2GREY (1<<1)
|
||||||
#define S3C2410_LCDCON1_STN4GREY (2<<1)
|
#define S3C2410_LCDCON1_STN4GREY (2<<1)
|
||||||
#define S3C2410_LCDCON1_STN8BPP (3<<1)
|
#define S3C2410_LCDCON1_STN8BPP (3<<1)
|
||||||
#define S3C2410_LCDCON1_STN12BPP (4<<1)
|
#define S3C2410_LCDCON1_STN12BPP (4<<1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_TFT1BPP (8<<1)
|
#define S3C2410_LCDCON1_TFT1BPP (8<<1)
|
||||||
#define S3C2410_LCDCON1_TFT2BPP (9<<1)
|
#define S3C2410_LCDCON1_TFT2BPP (9<<1)
|
||||||
#define S3C2410_LCDCON1_TFT4BPP (10<<1)
|
#define S3C2410_LCDCON1_TFT4BPP (10<<1)
|
||||||
#define S3C2410_LCDCON1_TFT8BPP (11<<1)
|
#define S3C2410_LCDCON1_TFT8BPP (11<<1)
|
||||||
#define S3C2410_LCDCON1_TFT16BPP (12<<1)
|
#define S3C2410_LCDCON1_TFT16BPP (12<<1)
|
||||||
#define S3C2410_LCDCON1_TFT24BPP (13<<1)
|
#define S3C2410_LCDCON1_TFT24BPP (13<<1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_ENVID (1)
|
#define S3C2410_LCDCON1_ENVID (1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_MODEMASK 0x1E
|
#define S3C2410_LCDCON1_MODEMASK 0x1E
|
||||||
|
|
||||||
#define S3C2410_LCDCON2_VBPD(x) ((x) << 24)
|
#define S3C2410_LCDCON2_VBPD(x) ((x) << 24)
|
||||||
#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14)
|
#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14)
|
||||||
#define S3C2410_LCDCON2_VFPD(x) ((x) << 6)
|
#define S3C2410_LCDCON2_VFPD(x) ((x) << 6)
|
||||||
#define S3C2410_LCDCON2_VSPW(x) ((x) << 0)
|
#define S3C2410_LCDCON2_VSPW(x) ((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF)
|
#define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF)
|
||||||
#define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF)
|
#define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF)
|
||||||
#define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F)
|
#define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F)
|
||||||
|
|
||||||
#define S3C2410_LCDCON3_HBPD(x) ((x) << 19)
|
#define S3C2410_LCDCON3_HBPD(x) ((x) << 19)
|
||||||
#define S3C2410_LCDCON3_WDLY(x) ((x) << 19)
|
#define S3C2410_LCDCON3_WDLY(x) ((x) << 19)
|
||||||
#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON3_HFPD(x) ((x) << 0)
|
#define S3C2410_LCDCON3_HFPD(x) ((x) << 0)
|
||||||
#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0)
|
#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F)
|
#define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F)
|
||||||
#define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF)
|
#define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF)
|
||||||
|
|
||||||
#define S3C2410_LCDCON4_MVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON4_MVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON4_HSPW(x) ((x) << 0)
|
#define S3C2410_LCDCON4_HSPW(x) ((x) << 0)
|
||||||
#define S3C2410_LCDCON4_WLH(x) ((x) << 0)
|
#define S3C2410_LCDCON4_WLH(x) ((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF)
|
#define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF)
|
||||||
|
|
||||||
#define S3C2410_LCDCON5_BPP24BL (1<<12)
|
#define S3C2410_LCDCON5_BPP24BL (1<<12)
|
||||||
#define S3C2410_LCDCON5_FRM565 (1<<11)
|
#define S3C2410_LCDCON5_FRM565 (1<<11)
|
||||||
#define S3C2410_LCDCON5_INVVCLK (1<<10)
|
#define S3C2410_LCDCON5_INVVCLK (1<<10)
|
||||||
#define S3C2410_LCDCON5_INVVLINE (1<<9)
|
#define S3C2410_LCDCON5_INVVLINE (1<<9)
|
||||||
#define S3C2410_LCDCON5_INVVFRAME (1<<8)
|
#define S3C2410_LCDCON5_INVVFRAME (1<<8)
|
||||||
#define S3C2410_LCDCON5_INVVD (1<<7)
|
#define S3C2410_LCDCON5_INVVD (1<<7)
|
||||||
#define S3C2410_LCDCON5_INVVDEN (1<<6)
|
#define S3C2410_LCDCON5_INVVDEN (1<<6)
|
||||||
#define S3C2410_LCDCON5_INVPWREN (1<<5)
|
#define S3C2410_LCDCON5_INVPWREN (1<<5)
|
||||||
#define S3C2410_LCDCON5_INVLEND (1<<4)
|
#define S3C2410_LCDCON5_INVLEND (1<<4)
|
||||||
#define S3C2410_LCDCON5_PWREN (1<<3)
|
#define S3C2410_LCDCON5_PWREN (1<<3)
|
||||||
#define S3C2410_LCDCON5_ENLEND (1<<2)
|
#define S3C2410_LCDCON5_ENLEND (1<<2)
|
||||||
#define S3C2410_LCDCON5_BSWP (1<<1)
|
#define S3C2410_LCDCON5_BSWP (1<<1)
|
||||||
#define S3C2410_LCDCON5_HWSWP (1<<0)
|
#define S3C2410_LCDCON5_HWSWP (1<<0)
|
||||||
|
|
||||||
#define S3C2410_LCDINT_FRSYNC (1<<1)
|
#define S3C2410_LCDINT_FRSYNC (1<<1)
|
||||||
|
|
||||||
volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
||||||
//volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
//volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
||||||
@ -128,124 +128,124 @@ static void lcd_power_enable(int invpwren, int pwren)
|
|||||||
|
|
||||||
static void lcd_envid_on_off(int onoff)
|
static void lcd_envid_on_off(int onoff)
|
||||||
{
|
{
|
||||||
if(onoff==1)
|
if(onoff==1)
|
||||||
/*ENVID=ON*/
|
/*ENVID=ON*/
|
||||||
LCDCON1|=1;
|
LCDCON1|=1;
|
||||||
else
|
else
|
||||||
/*ENVID Off*/
|
/*ENVID Off*/
|
||||||
LCDCON1 =LCDCON1 & 0x3fffe;
|
LCDCON1 =LCDCON1 & 0x3fffe;
|
||||||
}
|
}
|
||||||
|
|
||||||
//********************** BOARD LCD backlight ****************************
|
//********************** BOARD LCD backlight ****************************
|
||||||
static void LcdBkLtSet(rt_uint32_t HiRatio)
|
static void LcdBkLtSet(rt_uint32_t HiRatio)
|
||||||
{
|
{
|
||||||
#define FREQ_PWM1 1000
|
#define FREQ_PWM1 1000
|
||||||
if(!HiRatio)
|
if(!HiRatio)
|
||||||
{
|
{
|
||||||
GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1ÉèÖÃΪoutput
|
GPBCON = GPBCON & (~(3<<2)) | (1<<2) ;
|
||||||
GPBDAT &= ~(1<<1);
|
GPBDAT &= ~(1<<1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GPBCON = GPBCON & (~(3<<2)) | (2<<2) ;
|
GPBCON = GPBCON & (~(3<<2)) | (2<<2) ;
|
||||||
|
|
||||||
if( HiRatio > 100 ) HiRatio = 100 ;
|
if( HiRatio > 100 ) HiRatio = 100 ;
|
||||||
|
|
||||||
TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1
|
TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1
|
||||||
|
|
||||||
TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0
|
TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0
|
||||||
TCFG0 |= 15; //prescaler = 15+1
|
TCFG0 |= 15; //prescaler = 15+1
|
||||||
|
|
||||||
TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16
|
TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16
|
||||||
TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16
|
TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16
|
||||||
|
|
||||||
TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
|
TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
|
||||||
TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
|
TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
|
||||||
|
|
||||||
TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ;
|
TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ;
|
||||||
TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ;
|
TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RT-Thread Device Interface */
|
/* RT-Thread Device Interface */
|
||||||
static rt_err_t rt_lcd_init (rt_device_t dev)
|
static rt_err_t rt_lcd_init (rt_device_t dev)
|
||||||
{
|
{
|
||||||
GPB1_TO_OUT();
|
GPB1_TO_OUT();
|
||||||
GPB1_TO_1();
|
GPB1_TO_1();
|
||||||
|
|
||||||
GPCUP = 0x00000000;
|
GPCUP = 0x00000000;
|
||||||
GPCCON = 0xaaaa02a9;
|
GPCCON = 0xaaaa02a9;
|
||||||
|
|
||||||
GPDUP = 0x00000000;
|
GPDUP = 0x00000000;
|
||||||
GPDCON = 0xaaaaaaaa;
|
GPDCON = 0xaaaaaaaa;
|
||||||
|
|
||||||
#define M5D(n) ((n)&0x1fffff)
|
#define M5D(n) ((n)&0x1fffff)
|
||||||
#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer)
|
#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer)
|
||||||
LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
|
LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
|
||||||
LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0);
|
LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0);
|
||||||
LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0);
|
LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0);
|
||||||
LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0);
|
LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0);
|
||||||
|
|
||||||
#if !defined(LCD_CON5)
|
#if !defined(LCD_CON5)
|
||||||
#define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0))
|
#define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0))
|
||||||
#endif
|
#endif
|
||||||
LCDCON5 = LCD_CON5;
|
LCDCON5 = LCD_CON5;
|
||||||
|
|
||||||
LCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) << 0);
|
LCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) << 0);
|
||||||
LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
|
LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
|
||||||
LCDSADDR3 = LCD_WIDTH;
|
LCDSADDR3 = LCD_WIDTH;
|
||||||
|
|
||||||
LCDINTMSK |= (3);
|
LCDINTMSK |= (3);
|
||||||
LPCSEL &= (~7) ;
|
LPCSEL &= (~7) ;
|
||||||
TPAL=0;
|
TPAL=0;
|
||||||
|
|
||||||
LcdBkLtSet(70) ;
|
LcdBkLtSet(70) ;
|
||||||
lcd_power_enable(0, 1);
|
lcd_power_enable(0, 1);
|
||||||
lcd_envid_on_off(1);
|
lcd_envid_on_off(1);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
|
static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_POWERON:
|
case RTGRAPHIC_CTRL_POWERON:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_POWEROFF:
|
case RTGRAPHIC_CTRL_POWEROFF:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_GET_INFO:
|
case RTGRAPHIC_CTRL_GET_INFO:
|
||||||
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
|
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_SET_MODE:
|
case RTGRAPHIC_CTRL_SET_MODE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rt_hw_lcd_init(void)
|
int rt_hw_lcd_init(void)
|
||||||
{
|
{
|
||||||
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
|
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
|
||||||
if (lcd == RT_NULL)
|
if (lcd == RT_NULL)
|
||||||
return -RT_ERROR; /* no memory yet */
|
return -RT_ERROR; /* no memory yet */
|
||||||
|
|
||||||
_lcd_info.bits_per_pixel = 16;
|
_lcd_info.bits_per_pixel = 16;
|
||||||
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
||||||
_lcd_info.framebuffer = (void*)_rt_framebuffer;
|
_lcd_info.framebuffer = (void*)_rt_framebuffer;
|
||||||
_lcd_info.width = LCD_WIDTH;
|
_lcd_info.width = LCD_WIDTH;
|
||||||
_lcd_info.height = LCD_HEIGHT;
|
_lcd_info.height = LCD_HEIGHT;
|
||||||
|
|
||||||
/* init device structure */
|
/* init device structure */
|
||||||
lcd->type = RT_Device_Class_Unknown;
|
lcd->type = RT_Device_Class_Unknown;
|
||||||
lcd->init = rt_lcd_init;
|
lcd->init = rt_lcd_init;
|
||||||
lcd->open = RT_NULL;
|
lcd->open = RT_NULL;
|
||||||
lcd->close = RT_NULL;
|
lcd->close = RT_NULL;
|
||||||
lcd->control = rt_lcd_control;
|
lcd->control = rt_lcd_control;
|
||||||
lcd->user_data = (void*)&_lcd_info;
|
lcd->user_data = (void*)&_lcd_info;
|
||||||
|
|
||||||
/* register lcd device to RT-Thread */
|
/* register lcd device to RT-Thread */
|
||||||
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
|
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_BOARD_EXPORT(rt_hw_lcd_init);
|
INIT_BOARD_EXPORT(rt_hw_lcd_init);
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* File : lcd_t43.c
|
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||||
* This file is part of RT-Thread RTOS
|
|
||||||
* COPYRIGHT (C) 2010, RT-Thread Develop Team
|
|
||||||
*
|
*
|
||||||
* The license and distribution terms for this file may be
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
* found in the file LICENSE in this distribution or at
|
|
||||||
* http://www.rt-thread.org/license/LICENSE
|
|
||||||
*
|
*
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2020-04-12 Jonne first version from 4.3 inch lcd(480x272)
|
* 2020-04-12 Jonne first version from 4.3 inch lcd(480x272)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <s3c24x0.h>
|
#include <s3c24x0.h>
|
||||||
|
|
||||||
@ -36,79 +31,79 @@
|
|||||||
#define RT_HW_LCD_WIDTH LCD_WIDTH
|
#define RT_HW_LCD_WIDTH LCD_WIDTH
|
||||||
#define RT_HW_LCD_HEIGHT LCD_HEIGHT
|
#define RT_HW_LCD_HEIGHT LCD_HEIGHT
|
||||||
|
|
||||||
#define MVAL (13)
|
#define MVAL (13)
|
||||||
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
|
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
|
||||||
#define INVVDEN (1) //0=normal 1=inverted
|
#define INVVDEN (1) //0=normal 1=inverted
|
||||||
#define BSWP (0) //Byte swap control
|
#define BSWP (0) //Byte swap control
|
||||||
#define HWSWP (1) //Half word swap control
|
#define HWSWP (1) //Half word swap control
|
||||||
|
|
||||||
#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004)
|
#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004)
|
||||||
#define GPB1_TO_1() (GPBDAT |= 0x0002)
|
#define GPB1_TO_1() (GPBDAT |= 0x0002)
|
||||||
#define GPB1_TO_0() (GPBDAT &= 0xfffd)
|
#define GPB1_TO_0() (GPBDAT &= 0xfffd)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON1_MMODE (1<<7)
|
#define S3C2410_LCDCON1_MMODE (1<<7)
|
||||||
#define S3C2410_LCDCON1_DSCAN4 (0<<5)
|
#define S3C2410_LCDCON1_DSCAN4 (0<<5)
|
||||||
#define S3C2410_LCDCON1_STN4 (1<<5)
|
#define S3C2410_LCDCON1_STN4 (1<<5)
|
||||||
#define S3C2410_LCDCON1_STN8 (2<<5)
|
#define S3C2410_LCDCON1_STN8 (2<<5)
|
||||||
#define S3C2410_LCDCON1_TFT (3<<5)
|
#define S3C2410_LCDCON1_TFT (3<<5)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_STN1BPP (0<<1)
|
#define S3C2410_LCDCON1_STN1BPP (0<<1)
|
||||||
#define S3C2410_LCDCON1_STN2GREY (1<<1)
|
#define S3C2410_LCDCON1_STN2GREY (1<<1)
|
||||||
#define S3C2410_LCDCON1_STN4GREY (2<<1)
|
#define S3C2410_LCDCON1_STN4GREY (2<<1)
|
||||||
#define S3C2410_LCDCON1_STN8BPP (3<<1)
|
#define S3C2410_LCDCON1_STN8BPP (3<<1)
|
||||||
#define S3C2410_LCDCON1_STN12BPP (4<<1)
|
#define S3C2410_LCDCON1_STN12BPP (4<<1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_TFT1BPP (8<<1)
|
#define S3C2410_LCDCON1_TFT1BPP (8<<1)
|
||||||
#define S3C2410_LCDCON1_TFT2BPP (9<<1)
|
#define S3C2410_LCDCON1_TFT2BPP (9<<1)
|
||||||
#define S3C2410_LCDCON1_TFT4BPP (10<<1)
|
#define S3C2410_LCDCON1_TFT4BPP (10<<1)
|
||||||
#define S3C2410_LCDCON1_TFT8BPP (11<<1)
|
#define S3C2410_LCDCON1_TFT8BPP (11<<1)
|
||||||
#define S3C2410_LCDCON1_TFT16BPP (12<<1)
|
#define S3C2410_LCDCON1_TFT16BPP (12<<1)
|
||||||
#define S3C2410_LCDCON1_TFT24BPP (13<<1)
|
#define S3C2410_LCDCON1_TFT24BPP (13<<1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_ENVID (1)
|
#define S3C2410_LCDCON1_ENVID (1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_MODEMASK 0x1E
|
#define S3C2410_LCDCON1_MODEMASK 0x1E
|
||||||
|
|
||||||
#define S3C2410_LCDCON2_VBPD(x) ((x) << 24)
|
#define S3C2410_LCDCON2_VBPD(x) ((x) << 24)
|
||||||
#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14)
|
#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14)
|
||||||
#define S3C2410_LCDCON2_VFPD(x) ((x) << 6)
|
#define S3C2410_LCDCON2_VFPD(x) ((x) << 6)
|
||||||
#define S3C2410_LCDCON2_VSPW(x) ((x) << 0)
|
#define S3C2410_LCDCON2_VSPW(x) ((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF)
|
#define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF)
|
||||||
#define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF)
|
#define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF)
|
||||||
#define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F)
|
#define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F)
|
||||||
|
|
||||||
#define S3C2410_LCDCON3_HBPD(x) ((x) << 19)
|
#define S3C2410_LCDCON3_HBPD(x) ((x) << 19)
|
||||||
#define S3C2410_LCDCON3_WDLY(x) ((x) << 19)
|
#define S3C2410_LCDCON3_WDLY(x) ((x) << 19)
|
||||||
#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON3_HFPD(x) ((x) << 0)
|
#define S3C2410_LCDCON3_HFPD(x) ((x) << 0)
|
||||||
#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0)
|
#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F)
|
#define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F)
|
||||||
#define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF)
|
#define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF)
|
||||||
|
|
||||||
#define S3C2410_LCDCON4_MVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON4_MVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON4_HSPW(x) ((x) << 0)
|
#define S3C2410_LCDCON4_HSPW(x) ((x) << 0)
|
||||||
#define S3C2410_LCDCON4_WLH(x) ((x) << 0)
|
#define S3C2410_LCDCON4_WLH(x) ((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF)
|
#define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF)
|
||||||
|
|
||||||
#define S3C2410_LCDCON5_BPP24BL (1<<12)
|
#define S3C2410_LCDCON5_BPP24BL (1<<12)
|
||||||
#define S3C2410_LCDCON5_FRM565 (1<<11)
|
#define S3C2410_LCDCON5_FRM565 (1<<11)
|
||||||
#define S3C2410_LCDCON5_INVVCLK (1<<10)
|
#define S3C2410_LCDCON5_INVVCLK (1<<10)
|
||||||
#define S3C2410_LCDCON5_INVVLINE (1<<9)
|
#define S3C2410_LCDCON5_INVVLINE (1<<9)
|
||||||
#define S3C2410_LCDCON5_INVVFRAME (1<<8)
|
#define S3C2410_LCDCON5_INVVFRAME (1<<8)
|
||||||
#define S3C2410_LCDCON5_INVVD (1<<7)
|
#define S3C2410_LCDCON5_INVVD (1<<7)
|
||||||
#define S3C2410_LCDCON5_INVVDEN (1<<6)
|
#define S3C2410_LCDCON5_INVVDEN (1<<6)
|
||||||
#define S3C2410_LCDCON5_INVPWREN (1<<5)
|
#define S3C2410_LCDCON5_INVPWREN (1<<5)
|
||||||
#define S3C2410_LCDCON5_INVLEND (1<<4)
|
#define S3C2410_LCDCON5_INVLEND (1<<4)
|
||||||
#define S3C2410_LCDCON5_PWREN (1<<3)
|
#define S3C2410_LCDCON5_PWREN (1<<3)
|
||||||
#define S3C2410_LCDCON5_ENLEND (1<<2)
|
#define S3C2410_LCDCON5_ENLEND (1<<2)
|
||||||
#define S3C2410_LCDCON5_BSWP (1<<1)
|
#define S3C2410_LCDCON5_BSWP (1<<1)
|
||||||
#define S3C2410_LCDCON5_HWSWP (1<<0)
|
#define S3C2410_LCDCON5_HWSWP (1<<0)
|
||||||
|
|
||||||
#define S3C2410_LCDINT_FRSYNC (1<<1)
|
#define S3C2410_LCDINT_FRSYNC (1<<1)
|
||||||
|
|
||||||
static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
||||||
//static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
//static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
||||||
@ -127,61 +122,61 @@ static void lcd_power_enable(int invpwren, int pwren)
|
|||||||
|
|
||||||
static void lcd_envid_on_off(int onoff)
|
static void lcd_envid_on_off(int onoff)
|
||||||
{
|
{
|
||||||
if(onoff==1)
|
if(onoff==1)
|
||||||
/*ENVID=ON*/
|
/*ENVID=ON*/
|
||||||
LCDCON1|=1;
|
LCDCON1|=1;
|
||||||
else
|
else
|
||||||
/*ENVID Off*/
|
/*ENVID Off*/
|
||||||
LCDCON1 =LCDCON1 & 0x3fffe;
|
LCDCON1 =LCDCON1 & 0x3fffe;
|
||||||
}
|
}
|
||||||
|
|
||||||
//********************** BOARD LCD backlight ****************************
|
//********************** BOARD LCD backlight ****************************
|
||||||
static void LcdBkLtSet(rt_uint32_t HiRatio)
|
static void LcdBkLtSet(rt_uint32_t HiRatio)
|
||||||
{
|
{
|
||||||
#define FREQ_PWM1 1000
|
#define FREQ_PWM1 1000
|
||||||
if(!HiRatio)
|
if(!HiRatio)
|
||||||
{
|
{
|
||||||
GPBCON = GPBCON & (~(3<<2)) | (1<<2) ;
|
GPBCON = GPBCON & (~(3<<2)) | (1<<2) ;
|
||||||
GPBDAT &= ~(1<<1);
|
GPBDAT &= ~(1<<1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GPBCON = GPBCON & (~(3<<2)) | (2<<2) ;
|
GPBCON = GPBCON & (~(3<<2)) | (2<<2) ;
|
||||||
|
|
||||||
if( HiRatio > 100 ) HiRatio = 100 ;
|
if( HiRatio > 100 ) HiRatio = 100 ;
|
||||||
|
|
||||||
TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1
|
TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1
|
||||||
|
|
||||||
TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0
|
TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0
|
||||||
TCFG0 |= 15; //prescaler = 15+1
|
TCFG0 |= 15; //prescaler = 15+1
|
||||||
|
|
||||||
TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16
|
TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16
|
||||||
TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16
|
TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16
|
||||||
|
|
||||||
TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
|
TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
|
||||||
TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
|
TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
|
||||||
|
|
||||||
TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ;
|
TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ;
|
||||||
TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ;
|
TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RT-Thread Device Interface */
|
/* RT-Thread Device Interface */
|
||||||
static rt_err_t rt_lcd_init (rt_device_t dev)
|
static rt_err_t rt_lcd_init (rt_device_t dev)
|
||||||
{
|
{
|
||||||
GPB1_TO_OUT();
|
GPB1_TO_OUT();
|
||||||
GPB1_TO_1();
|
GPB1_TO_1();
|
||||||
|
|
||||||
GPCUP = 0x00000000;
|
GPCUP = 0x00000000;
|
||||||
GPCCON = 0xaaaa02a9;
|
GPCCON = 0xaaaa02a9;
|
||||||
|
|
||||||
GPDUP = 0x00000000;
|
GPDUP = 0x00000000;
|
||||||
GPDCON = 0xaaaaaaaa;
|
GPDCON = 0xaaaaaaaa;
|
||||||
|
|
||||||
#define M5D(n) ((n)&0x1fffff)
|
#define M5D(n) ((n)&0x1fffff)
|
||||||
#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer)
|
#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer)
|
||||||
LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
|
LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
|
||||||
LCDCON2 = ((LCD_UPPER_MARGIN - 1) << 24) | ((LCD_HEIGHT - 1) << 14) | ((LCD_LOWER_MARGIN - 1) << 6) | ((LCD_VSYNC_LEN - 1) << 0);
|
LCDCON2 = ((LCD_UPPER_MARGIN - 1) << 24) | ((LCD_HEIGHT - 1) << 14) | ((LCD_LOWER_MARGIN - 1) << 6) | ((LCD_VSYNC_LEN - 1) << 0);
|
||||||
LCDCON3 = ((LCD_RIGHT_MARGIN - 1) << 19) | ((LCD_WIDTH - 1) << 8) | ((LCD_LEFT_MARGIN - 1) << 0);
|
LCDCON3 = ((LCD_RIGHT_MARGIN - 1) << 19) | ((LCD_WIDTH - 1) << 8) | ((LCD_LEFT_MARGIN - 1) << 0);
|
||||||
LCDCON4 = (13 << 8) | ((LCD_HSYNC_LEN - 1) << 0);
|
LCDCON4 = (13 << 8) | ((LCD_HSYNC_LEN - 1) << 0);
|
||||||
#if !defined(LCD_CON5)
|
#if !defined(LCD_CON5)
|
||||||
#define LCD_CON5 ((1<<11) | (0<<10) | (1<<9) | (1<<8) | (1<<0))
|
#define LCD_CON5 ((1<<11) | (0<<10) | (1<<9) | (1<<8) | (1<<0))
|
||||||
#endif
|
#endif
|
||||||
@ -191,59 +186,59 @@ static rt_err_t rt_lcd_init (rt_device_t dev)
|
|||||||
LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
|
LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
|
||||||
LCDSADDR3 = LCD_WIDTH;
|
LCDSADDR3 = LCD_WIDTH;
|
||||||
|
|
||||||
LCDINTMSK |= (3);
|
LCDINTMSK |= (3);
|
||||||
LPCSEL &= (~7) ;
|
LPCSEL &= (~7) ;
|
||||||
TPAL=0;
|
TPAL=0;
|
||||||
|
|
||||||
LcdBkLtSet(70) ;
|
LcdBkLtSet(70) ;
|
||||||
lcd_power_enable(0, 1);
|
lcd_power_enable(0, 1);
|
||||||
lcd_envid_on_off(1);
|
lcd_envid_on_off(1);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
|
static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_POWERON:
|
case RTGRAPHIC_CTRL_POWERON:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_POWEROFF:
|
case RTGRAPHIC_CTRL_POWEROFF:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_GET_INFO:
|
case RTGRAPHIC_CTRL_GET_INFO:
|
||||||
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
|
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_SET_MODE:
|
case RTGRAPHIC_CTRL_SET_MODE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rt_hw_lcd_init(void)
|
int rt_hw_lcd_init(void)
|
||||||
{
|
{
|
||||||
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
|
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
|
||||||
if (lcd == RT_NULL)
|
if (lcd == RT_NULL)
|
||||||
return -RT_ERROR; /* no memory yet */
|
return -RT_ERROR; /* no memory yet */
|
||||||
|
|
||||||
_lcd_info.bits_per_pixel = 16;
|
_lcd_info.bits_per_pixel = 16;
|
||||||
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
||||||
_lcd_info.framebuffer = (void*)_rt_framebuffer;
|
_lcd_info.framebuffer = (void*)_rt_framebuffer;
|
||||||
_lcd_info.width = LCD_WIDTH;
|
_lcd_info.width = LCD_WIDTH;
|
||||||
_lcd_info.height = LCD_HEIGHT;
|
_lcd_info.height = LCD_HEIGHT;
|
||||||
|
|
||||||
/* init device structure */
|
/* init device structure */
|
||||||
lcd->type = RT_Device_Class_Unknown;
|
lcd->type = RT_Device_Class_Unknown;
|
||||||
lcd->init = rt_lcd_init;
|
lcd->init = rt_lcd_init;
|
||||||
lcd->open = RT_NULL;
|
lcd->open = RT_NULL;
|
||||||
lcd->close = RT_NULL;
|
lcd->close = RT_NULL;
|
||||||
lcd->control = rt_lcd_control;
|
lcd->control = rt_lcd_control;
|
||||||
lcd->user_data = (void*)&_lcd_info;
|
lcd->user_data = (void*)&_lcd_info;
|
||||||
|
|
||||||
/* register lcd device to RT-Thread */
|
/* register lcd device to RT-Thread */
|
||||||
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
|
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_BOARD_EXPORT(rt_hw_lcd_init);
|
INIT_BOARD_EXPORT(rt_hw_lcd_init);
|
||||||
|
@ -36,82 +36,82 @@
|
|||||||
#define SCR_XSIZE LCD_WIDTH
|
#define SCR_XSIZE LCD_WIDTH
|
||||||
#define SCR_YSIZE LCD_HEIGHT
|
#define SCR_YSIZE LCD_HEIGHT
|
||||||
|
|
||||||
#define RT_HW_LCD_WIDTH LCD_WIDTH
|
#define RT_HW_LCD_WIDTH LCD_WIDTH
|
||||||
#define RT_HW_LCD_HEIGHT LCD_HEIGHT
|
#define RT_HW_LCD_HEIGHT LCD_HEIGHT
|
||||||
|
|
||||||
#define MVAL (13)
|
#define MVAL (13)
|
||||||
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
|
#define MVAL_USED (0) //0=each frame 1=rate by MVAL
|
||||||
#define INVVDEN (1) //0=normal 1=inverted
|
#define INVVDEN (1) //0=normal 1=inverted
|
||||||
#define BSWP (0) //Byte swap control
|
#define BSWP (0) //Byte swap control
|
||||||
#define HWSWP (1) //Half word swap control
|
#define HWSWP (1) //Half word swap control
|
||||||
|
|
||||||
#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004)
|
#define GPB1_TO_OUT() (GPBUP &= 0xfffd, GPBCON &= 0xfffffff3, GPBCON |= 0x00000004)
|
||||||
#define GPB1_TO_1() (GPBDAT |= 0x0002)
|
#define GPB1_TO_1() (GPBDAT |= 0x0002)
|
||||||
#define GPB1_TO_0() (GPBDAT &= 0xfffd)
|
#define GPB1_TO_0() (GPBDAT &= 0xfffd)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON1_CLKVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON1_MMODE (1<<7)
|
#define S3C2410_LCDCON1_MMODE (1<<7)
|
||||||
#define S3C2410_LCDCON1_DSCAN4 (0<<5)
|
#define S3C2410_LCDCON1_DSCAN4 (0<<5)
|
||||||
#define S3C2410_LCDCON1_STN4 (1<<5)
|
#define S3C2410_LCDCON1_STN4 (1<<5)
|
||||||
#define S3C2410_LCDCON1_STN8 (2<<5)
|
#define S3C2410_LCDCON1_STN8 (2<<5)
|
||||||
#define S3C2410_LCDCON1_TFT (3<<5)
|
#define S3C2410_LCDCON1_TFT (3<<5)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_STN1BPP (0<<1)
|
#define S3C2410_LCDCON1_STN1BPP (0<<1)
|
||||||
#define S3C2410_LCDCON1_STN2GREY (1<<1)
|
#define S3C2410_LCDCON1_STN2GREY (1<<1)
|
||||||
#define S3C2410_LCDCON1_STN4GREY (2<<1)
|
#define S3C2410_LCDCON1_STN4GREY (2<<1)
|
||||||
#define S3C2410_LCDCON1_STN8BPP (3<<1)
|
#define S3C2410_LCDCON1_STN8BPP (3<<1)
|
||||||
#define S3C2410_LCDCON1_STN12BPP (4<<1)
|
#define S3C2410_LCDCON1_STN12BPP (4<<1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_TFT1BPP (8<<1)
|
#define S3C2410_LCDCON1_TFT1BPP (8<<1)
|
||||||
#define S3C2410_LCDCON1_TFT2BPP (9<<1)
|
#define S3C2410_LCDCON1_TFT2BPP (9<<1)
|
||||||
#define S3C2410_LCDCON1_TFT4BPP (10<<1)
|
#define S3C2410_LCDCON1_TFT4BPP (10<<1)
|
||||||
#define S3C2410_LCDCON1_TFT8BPP (11<<1)
|
#define S3C2410_LCDCON1_TFT8BPP (11<<1)
|
||||||
#define S3C2410_LCDCON1_TFT16BPP (12<<1)
|
#define S3C2410_LCDCON1_TFT16BPP (12<<1)
|
||||||
#define S3C2410_LCDCON1_TFT24BPP (13<<1)
|
#define S3C2410_LCDCON1_TFT24BPP (13<<1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_ENVID (1)
|
#define S3C2410_LCDCON1_ENVID (1)
|
||||||
|
|
||||||
#define S3C2410_LCDCON1_MODEMASK 0x1E
|
#define S3C2410_LCDCON1_MODEMASK 0x1E
|
||||||
|
|
||||||
#define S3C2410_LCDCON2_VBPD(x) ((x) << 24)
|
#define S3C2410_LCDCON2_VBPD(x) ((x) << 24)
|
||||||
#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14)
|
#define S3C2410_LCDCON2_LINEVAL(x) ((x) << 14)
|
||||||
#define S3C2410_LCDCON2_VFPD(x) ((x) << 6)
|
#define S3C2410_LCDCON2_VFPD(x) ((x) << 6)
|
||||||
#define S3C2410_LCDCON2_VSPW(x) ((x) << 0)
|
#define S3C2410_LCDCON2_VSPW(x) ((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF)
|
#define S3C2410_LCDCON2_GET_VBPD(x) ( ((x) >> 24) & 0xFF)
|
||||||
#define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF)
|
#define S3C2410_LCDCON2_GET_VFPD(x) ( ((x) >> 6) & 0xFF)
|
||||||
#define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F)
|
#define S3C2410_LCDCON2_GET_VSPW(x) ( ((x) >> 0) & 0x3F)
|
||||||
|
|
||||||
#define S3C2410_LCDCON3_HBPD(x) ((x) << 19)
|
#define S3C2410_LCDCON3_HBPD(x) ((x) << 19)
|
||||||
#define S3C2410_LCDCON3_WDLY(x) ((x) << 19)
|
#define S3C2410_LCDCON3_WDLY(x) ((x) << 19)
|
||||||
#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON3_HOZVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON3_HFPD(x) ((x) << 0)
|
#define S3C2410_LCDCON3_HFPD(x) ((x) << 0)
|
||||||
#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0)
|
#define S3C2410_LCDCON3_LINEBLANK(x)((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F)
|
#define S3C2410_LCDCON3_GET_HBPD(x) ( ((x) >> 19) & 0x7F)
|
||||||
#define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF)
|
#define S3C2410_LCDCON3_GET_HFPD(x) ( ((x) >> 0) & 0xFF)
|
||||||
|
|
||||||
#define S3C2410_LCDCON4_MVAL(x) ((x) << 8)
|
#define S3C2410_LCDCON4_MVAL(x) ((x) << 8)
|
||||||
#define S3C2410_LCDCON4_HSPW(x) ((x) << 0)
|
#define S3C2410_LCDCON4_HSPW(x) ((x) << 0)
|
||||||
#define S3C2410_LCDCON4_WLH(x) ((x) << 0)
|
#define S3C2410_LCDCON4_WLH(x) ((x) << 0)
|
||||||
|
|
||||||
#define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF)
|
#define S3C2410_LCDCON4_GET_HSPW(x) ( ((x) >> 0) & 0xFF)
|
||||||
|
|
||||||
#define S3C2410_LCDCON5_BPP24BL (1<<12)
|
#define S3C2410_LCDCON5_BPP24BL (1<<12)
|
||||||
#define S3C2410_LCDCON5_FRM565 (1<<11)
|
#define S3C2410_LCDCON5_FRM565 (1<<11)
|
||||||
#define S3C2410_LCDCON5_INVVCLK (1<<10)
|
#define S3C2410_LCDCON5_INVVCLK (1<<10)
|
||||||
#define S3C2410_LCDCON5_INVVLINE (1<<9)
|
#define S3C2410_LCDCON5_INVVLINE (1<<9)
|
||||||
#define S3C2410_LCDCON5_INVVFRAME (1<<8)
|
#define S3C2410_LCDCON5_INVVFRAME (1<<8)
|
||||||
#define S3C2410_LCDCON5_INVVD (1<<7)
|
#define S3C2410_LCDCON5_INVVD (1<<7)
|
||||||
#define S3C2410_LCDCON5_INVVDEN (1<<6)
|
#define S3C2410_LCDCON5_INVVDEN (1<<6)
|
||||||
#define S3C2410_LCDCON5_INVPWREN (1<<5)
|
#define S3C2410_LCDCON5_INVPWREN (1<<5)
|
||||||
#define S3C2410_LCDCON5_INVLEND (1<<4)
|
#define S3C2410_LCDCON5_INVLEND (1<<4)
|
||||||
#define S3C2410_LCDCON5_PWREN (1<<3)
|
#define S3C2410_LCDCON5_PWREN (1<<3)
|
||||||
#define S3C2410_LCDCON5_ENLEND (1<<2)
|
#define S3C2410_LCDCON5_ENLEND (1<<2)
|
||||||
#define S3C2410_LCDCON5_BSWP (1<<1)
|
#define S3C2410_LCDCON5_BSWP (1<<1)
|
||||||
#define S3C2410_LCDCON5_HWSWP (1<<0)
|
#define S3C2410_LCDCON5_HWSWP (1<<0)
|
||||||
|
|
||||||
#define S3C2410_LCDINT_FRSYNC (1<<1)
|
#define S3C2410_LCDINT_FRSYNC (1<<1)
|
||||||
|
|
||||||
static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
||||||
//static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
//static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
|
||||||
@ -130,61 +130,61 @@ static void lcd_power_enable(int invpwren, int pwren)
|
|||||||
|
|
||||||
static void lcd_envid_on_off(int onoff)
|
static void lcd_envid_on_off(int onoff)
|
||||||
{
|
{
|
||||||
if(onoff==1)
|
if(onoff==1)
|
||||||
/*ENVID=ON*/
|
/*ENVID=ON*/
|
||||||
LCDCON1|=1;
|
LCDCON1|=1;
|
||||||
else
|
else
|
||||||
/*ENVID Off*/
|
/*ENVID Off*/
|
||||||
LCDCON1 =LCDCON1 & 0x3fffe;
|
LCDCON1 =LCDCON1 & 0x3fffe;
|
||||||
}
|
}
|
||||||
|
|
||||||
//********************** BOARD LCD backlight ****************************
|
//********************** BOARD LCD backlight ****************************
|
||||||
static void LcdBkLtSet(rt_uint32_t HiRatio)
|
static void LcdBkLtSet(rt_uint32_t HiRatio)
|
||||||
{
|
{
|
||||||
#define FREQ_PWM1 1000
|
#define FREQ_PWM1 1000
|
||||||
if(!HiRatio)
|
if(!HiRatio)
|
||||||
{
|
{
|
||||||
GPBCON = GPBCON & (~(3<<2)) | (1<<2) ; //GPB1ÉèÖÃΪoutput
|
GPBCON = GPBCON & (~(3<<2)) | (1<<2) ;
|
||||||
GPBDAT &= ~(1<<1);
|
GPBDAT &= ~(1<<1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GPBCON = GPBCON & (~(3<<2)) | (2<<2) ;
|
GPBCON = GPBCON & (~(3<<2)) | (2<<2) ;
|
||||||
|
|
||||||
if( HiRatio > 100 ) HiRatio = 100 ;
|
if( HiRatio > 100 ) HiRatio = 100 ;
|
||||||
|
|
||||||
TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1
|
TCON = TCON & (~(0xf<<8)) ; // clear manual update bit, stop Timer1
|
||||||
|
|
||||||
TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0
|
TCFG0 &= 0xffffff00; // set Timer 0&1 prescaler 0
|
||||||
TCFG0 |= 15; //prescaler = 15+1
|
TCFG0 |= 15; //prescaler = 15+1
|
||||||
|
|
||||||
TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16
|
TCFG1 &= 0xffffff0f; // set Timer 1 MUX 1/16
|
||||||
TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16
|
TCFG1 |= 0x00000030; // set Timer 1 MUX 1/16
|
||||||
|
|
||||||
TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
|
TCNTB1 = ( 100000000>>8 )/FREQ_PWM1; //if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
|
||||||
TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
|
TCMPB1 = ( TCNTB1*(100-HiRatio))/100 ; //if set inverter on, when TCNT2<=TCMP2, TOUT is low, TCNT2>TCMP2, TOUT is high
|
||||||
|
|
||||||
TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ;
|
TCON = TCON & (~(0xf<<8)) | (0x0e<<8) ;
|
||||||
TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ;
|
TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RT-Thread Device Interface */
|
/* RT-Thread Device Interface */
|
||||||
static rt_err_t rt_lcd_init (rt_device_t dev)
|
static rt_err_t rt_lcd_init (rt_device_t dev)
|
||||||
{
|
{
|
||||||
GPB1_TO_OUT();
|
GPB1_TO_OUT();
|
||||||
GPB1_TO_1();
|
GPB1_TO_1();
|
||||||
|
|
||||||
GPCUP = 0x00000000;
|
GPCUP = 0x00000000;
|
||||||
GPCCON = 0xaaaa02a9;
|
GPCCON = 0xaaaa02a9;
|
||||||
|
|
||||||
GPDUP = 0x00000000;
|
GPDUP = 0x00000000;
|
||||||
GPDCON = 0xaaaaaaaa;
|
GPDCON = 0xaaaaaaaa;
|
||||||
|
|
||||||
#define M5D(n) ((n)&0x1fffff)
|
#define M5D(n) ((n)&0x1fffff)
|
||||||
#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer)
|
#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer)
|
||||||
LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
|
LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1);
|
||||||
LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0);
|
LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0);
|
||||||
LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0);
|
LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0);
|
||||||
LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0);
|
LCDCON4 = (13 << 8) | (LCD_HSYNC_LEN << 0);
|
||||||
|
|
||||||
#define LCD_CON5 (S3C2410_LCDCON5_FRM565 | S3C2410_LCDCON5_INVVDEN | S3C2410_LCDCON5_INVVFRAME | \
|
#define LCD_CON5 (S3C2410_LCDCON5_FRM565 | S3C2410_LCDCON5_INVVDEN | S3C2410_LCDCON5_INVVFRAME | \
|
||||||
S3C2410_LCDCON5_INVVLINE | S3C2410_LCDCON5_INVVCLK | S3C2410_LCDCON5_PWREN| S3C2410_LCDCON5_HWSWP)
|
S3C2410_LCDCON5_INVVLINE | S3C2410_LCDCON5_INVVCLK | S3C2410_LCDCON5_PWREN| S3C2410_LCDCON5_HWSWP)
|
||||||
@ -198,59 +198,59 @@ S3C2410_LCDCON5_INVVLINE | S3C2410_LCDCON5_INVVCLK | S3C2410_LCDCON5_PWREN| S3C2
|
|||||||
LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
|
LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
|
||||||
LCDSADDR3 = LCD_WIDTH;
|
LCDSADDR3 = LCD_WIDTH;
|
||||||
|
|
||||||
LCDINTMSK |= (3);
|
LCDINTMSK |= (3);
|
||||||
LPCSEL &= (~7) ;
|
LPCSEL &= (~7) ;
|
||||||
TPAL=0;
|
TPAL=0;
|
||||||
|
|
||||||
LcdBkLtSet(70) ;
|
LcdBkLtSet(70) ;
|
||||||
lcd_power_enable(0, 1);
|
lcd_power_enable(0, 1);
|
||||||
lcd_envid_on_off(1);
|
lcd_envid_on_off(1);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
|
static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_POWERON:
|
case RTGRAPHIC_CTRL_POWERON:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_POWEROFF:
|
case RTGRAPHIC_CTRL_POWEROFF:
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_GET_INFO:
|
case RTGRAPHIC_CTRL_GET_INFO:
|
||||||
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
|
rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
|
||||||
break;
|
break;
|
||||||
case RTGRAPHIC_CTRL_SET_MODE:
|
case RTGRAPHIC_CTRL_SET_MODE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rt_hw_lcd_init(void)
|
int rt_hw_lcd_init(void)
|
||||||
{
|
{
|
||||||
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
|
rt_device_t lcd = rt_malloc(sizeof(struct rt_device));
|
||||||
if (lcd == RT_NULL)
|
if (lcd == RT_NULL)
|
||||||
return -RT_ERROR; /* no memory yet */
|
return -RT_ERROR; /* no memory yet */
|
||||||
|
|
||||||
_lcd_info.bits_per_pixel = 16;
|
_lcd_info.bits_per_pixel = 16;
|
||||||
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
|
||||||
_lcd_info.framebuffer = (void*)_rt_framebuffer;
|
_lcd_info.framebuffer = (void*)_rt_framebuffer;
|
||||||
_lcd_info.width = LCD_WIDTH;
|
_lcd_info.width = LCD_WIDTH;
|
||||||
_lcd_info.height = LCD_HEIGHT;
|
_lcd_info.height = LCD_HEIGHT;
|
||||||
|
|
||||||
/* init device structure */
|
/* init device structure */
|
||||||
lcd->type = RT_Device_Class_Unknown;
|
lcd->type = RT_Device_Class_Unknown;
|
||||||
lcd->init = rt_lcd_init;
|
lcd->init = rt_lcd_init;
|
||||||
lcd->open = RT_NULL;
|
lcd->open = RT_NULL;
|
||||||
lcd->close = RT_NULL;
|
lcd->close = RT_NULL;
|
||||||
lcd->control = rt_lcd_control;
|
lcd->control = rt_lcd_control;
|
||||||
lcd->user_data = (void*)&_lcd_info;
|
lcd->user_data = (void*)&_lcd_info;
|
||||||
|
|
||||||
/* register lcd device to RT-Thread */
|
/* register lcd device to RT-Thread */
|
||||||
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
|
rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR);
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_BOARD_EXPORT(rt_hw_lcd_init);
|
INIT_BOARD_EXPORT(rt_hw_lcd_init);
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* File : s3cmci.c
|
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||||
* This file is part of RT-Thread RTOS
|
|
||||||
* COPYRIGHT (C) 2010, RT-Thread Develop Team
|
|
||||||
*
|
*
|
||||||
* The license and distribution terms for this file may be
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
* found in the file LICENSE in this distribution or at
|
|
||||||
* http://www.rt-thread.org/license/LICENSE
|
|
||||||
*
|
*
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
* 2020-04-15 Jonne first version for s3c2440 mmc controller
|
* 2020-04-15 Jonne first version for s3c2440 mmc controller
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <rtdevice.h>
|
#include <rtdevice.h>
|
||||||
|
@ -27,485 +27,485 @@
|
|||||||
#include "touch.h"
|
#include "touch.h"
|
||||||
|
|
||||||
/* ADCCON Register Bits */
|
/* ADCCON Register Bits */
|
||||||
#define S3C2410_ADCCON_ECFLG (1<<15)
|
#define S3C2410_ADCCON_ECFLG (1<<15)
|
||||||
#define S3C2410_ADCCON_PRSCEN (1<<14)
|
#define S3C2410_ADCCON_PRSCEN (1<<14)
|
||||||
#define S3C2410_ADCCON_PRSCVL(x) (((x)&0xFF)<<6)
|
#define S3C2410_ADCCON_PRSCVL(x) (((x)&0xFF)<<6)
|
||||||
#define S3C2410_ADCCON_PRSCVLMASK (0xFF<<6)
|
#define S3C2410_ADCCON_PRSCVLMASK (0xFF<<6)
|
||||||
#define S3C2410_ADCCON_SELMUX(x) (((x)&0x7)<<3)
|
#define S3C2410_ADCCON_SELMUX(x) (((x)&0x7)<<3)
|
||||||
#define S3C2410_ADCCON_MUXMASK (0x7<<3)
|
#define S3C2410_ADCCON_MUXMASK (0x7<<3)
|
||||||
#define S3C2410_ADCCON_STDBM (1<<2)
|
#define S3C2410_ADCCON_STDBM (1<<2)
|
||||||
#define S3C2410_ADCCON_READ_START (1<<1)
|
#define S3C2410_ADCCON_READ_START (1<<1)
|
||||||
#define S3C2410_ADCCON_ENABLE_START (1<<0)
|
#define S3C2410_ADCCON_ENABLE_START (1<<0)
|
||||||
#define S3C2410_ADCCON_STARTMASK (0x3<<0)
|
#define S3C2410_ADCCON_STARTMASK (0x3<<0)
|
||||||
|
|
||||||
/* ADCTSC Register Bits */
|
/* ADCTSC Register Bits */
|
||||||
#define S3C2410_ADCTSC_UD_SEN (1<<8) /* ghcstop add for s3c2440a */
|
#define S3C2410_ADCTSC_UD_SEN (1<<8) /* ghcstop add for s3c2440a */
|
||||||
#define S3C2410_ADCTSC_YM_SEN (1<<7)
|
#define S3C2410_ADCTSC_YM_SEN (1<<7)
|
||||||
#define S3C2410_ADCTSC_YP_SEN (1<<6)
|
#define S3C2410_ADCTSC_YP_SEN (1<<6)
|
||||||
#define S3C2410_ADCTSC_XM_SEN (1<<5)
|
#define S3C2410_ADCTSC_XM_SEN (1<<5)
|
||||||
#define S3C2410_ADCTSC_XP_SEN (1<<4)
|
#define S3C2410_ADCTSC_XP_SEN (1<<4)
|
||||||
#define S3C2410_ADCTSC_PULL_UP_DISABLE (1<<3)
|
#define S3C2410_ADCTSC_PULL_UP_DISABLE (1<<3)
|
||||||
#define S3C2410_ADCTSC_AUTO_PST (1<<2)
|
#define S3C2410_ADCTSC_AUTO_PST (1<<2)
|
||||||
#define S3C2410_ADCTSC_XY_PST(x) (((x)&0x3)<<0)
|
#define S3C2410_ADCTSC_XY_PST(x) (((x)&0x3)<<0)
|
||||||
|
|
||||||
/* ADCDAT0 Bits */
|
/* ADCDAT0 Bits */
|
||||||
#define S3C2410_ADCDAT0_UPDOWN (1<<15)
|
#define S3C2410_ADCDAT0_UPDOWN (1<<15)
|
||||||
#define S3C2410_ADCDAT0_AUTO_PST (1<<14)
|
#define S3C2410_ADCDAT0_AUTO_PST (1<<14)
|
||||||
#define S3C2410_ADCDAT0_XY_PST (0x3<<12)
|
#define S3C2410_ADCDAT0_XY_PST (0x3<<12)
|
||||||
#define S3C2410_ADCDAT0_XPDATA_MASK (0x03FF)
|
#define S3C2410_ADCDAT0_XPDATA_MASK (0x03FF)
|
||||||
|
|
||||||
/* ADCDAT1 Bits */
|
/* ADCDAT1 Bits */
|
||||||
#define S3C2410_ADCDAT1_UPDOWN (1<<15)
|
#define S3C2410_ADCDAT1_UPDOWN (1<<15)
|
||||||
#define S3C2410_ADCDAT1_AUTO_PST (1<<14)
|
#define S3C2410_ADCDAT1_AUTO_PST (1<<14)
|
||||||
#define S3C2410_ADCDAT1_XY_PST (0x3<<12)
|
#define S3C2410_ADCDAT1_XY_PST (0x3<<12)
|
||||||
#define S3C2410_ADCDAT1_YPDATA_MASK (0x03FF)
|
#define S3C2410_ADCDAT1_YPDATA_MASK (0x03FF)
|
||||||
|
|
||||||
#define WAIT4INT(x) (((x)<<8) | \
|
#define WAIT4INT(x) (((x)<<8) | \
|
||||||
S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
|
S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
|
||||||
S3C2410_ADCTSC_XY_PST(3))
|
S3C2410_ADCTSC_XY_PST(3))
|
||||||
|
|
||||||
#define AUTOPST (S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
|
#define AUTOPST (S3C2410_ADCTSC_YM_SEN | S3C2410_ADCTSC_YP_SEN | S3C2410_ADCTSC_XP_SEN | \
|
||||||
S3C2410_ADCTSC_AUTO_PST | S3C2410_ADCTSC_XY_PST(0))
|
S3C2410_ADCTSC_AUTO_PST | S3C2410_ADCTSC_XY_PST(0))
|
||||||
|
|
||||||
#define X_MIN 74
|
#define X_MIN 74
|
||||||
#define X_MAX 934
|
#define X_MAX 934
|
||||||
#define Y_MIN 920
|
#define Y_MIN 920
|
||||||
#define Y_MAX 89
|
#define Y_MAX 89
|
||||||
|
|
||||||
struct s3c2410ts
|
struct s3c2410ts
|
||||||
{
|
{
|
||||||
long xp;
|
long xp;
|
||||||
long yp;
|
long yp;
|
||||||
int count;
|
int count;
|
||||||
int shift;
|
int shift;
|
||||||
|
|
||||||
int delay;
|
int delay;
|
||||||
int presc;
|
int presc;
|
||||||
|
|
||||||
char phys[32];
|
char phys[32];
|
||||||
};
|
};
|
||||||
static struct s3c2410ts ts;
|
static struct s3c2410ts ts;
|
||||||
|
|
||||||
struct rtgui_touch_device
|
struct rtgui_touch_device
|
||||||
{
|
{
|
||||||
struct rt_device parent;
|
struct rt_device parent;
|
||||||
|
|
||||||
rt_timer_t poll_timer;
|
rt_timer_t poll_timer;
|
||||||
rt_uint16_t x, y;
|
rt_uint16_t x, y;
|
||||||
|
|
||||||
rt_bool_t calibrating;
|
rt_bool_t calibrating;
|
||||||
rt_touch_calibration_func_t calibration_func;
|
rt_touch_calibration_func_t calibration_func;
|
||||||
|
|
||||||
rt_touch_eventpost_func_t eventpost_func;
|
rt_touch_eventpost_func_t eventpost_func;
|
||||||
void *eventpost_param;
|
void *eventpost_param;
|
||||||
|
|
||||||
rt_uint16_t min_x, max_x;
|
rt_uint16_t min_x, max_x;
|
||||||
rt_uint16_t min_y, max_y;
|
rt_uint16_t min_y, max_y;
|
||||||
|
|
||||||
rt_uint16_t width;
|
rt_uint16_t width;
|
||||||
rt_uint16_t height;
|
rt_uint16_t height;
|
||||||
|
|
||||||
rt_bool_t first_down_report;
|
rt_bool_t first_down_report;
|
||||||
};
|
};
|
||||||
static struct rtgui_touch_device *touch = RT_NULL;
|
static struct rtgui_touch_device *touch = RT_NULL;
|
||||||
|
|
||||||
#ifdef PKG_USING_GUIENGINE
|
#ifdef PKG_USING_GUIENGINE
|
||||||
static void report_touch_input(int updown)
|
static void report_touch_input(int updown)
|
||||||
{
|
{
|
||||||
struct rtgui_event_mouse emouse;
|
struct rtgui_event_mouse emouse;
|
||||||
|
|
||||||
RTGUI_EVENT_MOUSE_BUTTON_INIT(&emouse);
|
RTGUI_EVENT_MOUSE_BUTTON_INIT(&emouse);
|
||||||
emouse.wid = RT_NULL;
|
emouse.wid = RT_NULL;
|
||||||
|
|
||||||
/* set emouse button */
|
/* set emouse button */
|
||||||
emouse.button = RTGUI_MOUSE_BUTTON_LEFT;
|
emouse.button = RTGUI_MOUSE_BUTTON_LEFT;
|
||||||
emouse.parent.sender = RT_NULL;
|
emouse.parent.sender = RT_NULL;
|
||||||
|
|
||||||
if (updown)
|
if (updown)
|
||||||
{
|
{
|
||||||
ts.xp = ts.xp / ts.count;
|
ts.xp = ts.xp / ts.count;
|
||||||
ts.yp = ts.yp / ts.count;;
|
ts.yp = ts.yp / ts.count;;
|
||||||
|
|
||||||
#ifdef TOUCH_SWAP_XY
|
#ifdef TOUCH_SWAP_XY
|
||||||
ts.xp = ts.xp + ts.yp;
|
ts.xp = ts.xp + ts.yp;
|
||||||
ts.yp = ts.xp - ts.yp;
|
ts.yp = ts.xp - ts.yp;
|
||||||
ts.xp = ts.xp - ts.yp;
|
ts.xp = ts.xp - ts.yp;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
||||||
{
|
{
|
||||||
touch->x = ts.xp;
|
touch->x = ts.xp;
|
||||||
touch->y = ts.yp;
|
touch->y = ts.yp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (touch->max_x > touch->min_x)
|
if (touch->max_x > touch->min_x)
|
||||||
{
|
{
|
||||||
touch->x = touch->width * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x);
|
touch->x = touch->width * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
touch->x = touch->width * ( touch->min_x - ts.xp ) / (touch->min_x-touch->max_x);
|
touch->x = touch->width * ( touch->min_x - ts.xp ) / (touch->min_x-touch->max_x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (touch->max_y > touch->min_y)
|
if (touch->max_y > touch->min_y)
|
||||||
{
|
{
|
||||||
touch->y = touch->height * ( ts.yp - touch->min_y ) / (touch->max_y-touch->min_y);
|
touch->y = touch->height * ( ts.yp - touch->min_y ) / (touch->max_y-touch->min_y);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
touch->y = touch->height * ( touch->min_y - ts.yp ) / (touch->min_y-touch->max_y);
|
touch->y = touch->height * ( touch->min_y - ts.yp ) / (touch->min_y-touch->max_y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emouse.x = touch->x;
|
emouse.x = touch->x;
|
||||||
emouse.y = touch->y;
|
emouse.y = touch->y;
|
||||||
if (touch->first_down_report == RT_TRUE)
|
if (touch->first_down_report == RT_TRUE)
|
||||||
{
|
{
|
||||||
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
|
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
|
||||||
emouse.button |= RTGUI_MOUSE_BUTTON_DOWN;
|
emouse.button |= RTGUI_MOUSE_BUTTON_DOWN;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
|
emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
|
||||||
emouse.button = 0;
|
emouse.button = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emouse.x = touch->x;
|
emouse.x = touch->x;
|
||||||
emouse.y = touch->y;
|
emouse.y = touch->y;
|
||||||
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
|
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
|
||||||
emouse.button |= RTGUI_MOUSE_BUTTON_UP;
|
emouse.button |= RTGUI_MOUSE_BUTTON_UP;
|
||||||
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
||||||
{
|
{
|
||||||
/* callback function */
|
/* callback function */
|
||||||
touch->calibration_func(emouse.x, emouse.y);
|
touch->calibration_func(emouse.x, emouse.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* rt_kprintf("touch %s: ts.x: %d, ts.y: %d\n", updown? "down" : "up",
|
/* rt_kprintf("touch %s: ts.x: %d, ts.y: %d\n", updown? "down" : "up",
|
||||||
touch->x, touch->y); */
|
touch->x, touch->y); */
|
||||||
|
|
||||||
/* send event to server */
|
/* send event to server */
|
||||||
if (touch->calibrating != RT_TRUE)
|
if (touch->calibrating != RT_TRUE)
|
||||||
{
|
{
|
||||||
rtgui_server_post_event((&emouse.parent), sizeof(emouse));
|
rtgui_server_post_event((&emouse.parent), sizeof(emouse));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void report_touch_input(int updown)
|
static void report_touch_input(int updown)
|
||||||
{
|
{
|
||||||
struct rt_touch_event touch_event;
|
struct rt_touch_event touch_event;
|
||||||
|
|
||||||
if (updown)
|
if (updown)
|
||||||
{
|
{
|
||||||
ts.xp = ts.xp / ts.count;
|
ts.xp = ts.xp / ts.count;
|
||||||
ts.yp = ts.yp / ts.count;
|
ts.yp = ts.yp / ts.count;
|
||||||
|
|
||||||
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
||||||
{
|
{
|
||||||
touch->x = ts.xp;
|
touch->x = ts.xp;
|
||||||
touch->y = ts.yp;
|
touch->y = ts.yp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (touch->max_x > touch->min_x)
|
if (touch->max_x > touch->min_x)
|
||||||
{
|
{
|
||||||
touch->x = touch->width * ( ts.xp - touch->min_x ) / (touch->max_x-touch->min_x);
|
touch->x = touch->width * ( ts.xp - touch->min_x ) / (touch->max_x-touch->min_x);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
touch->x = touch->width * ( touch->min_x - ts.xp ) / (touch->min_x-touch->max_x);
|
touch->x = touch->width * ( touch->min_x - ts.xp ) / (touch->min_x-touch->max_x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (touch->max_y > touch->min_y)
|
if (touch->max_y > touch->min_y)
|
||||||
{
|
{
|
||||||
touch->y = touch->height * ( ts.yp - touch->min_y ) / (touch->max_y-touch->min_y);
|
touch->y = touch->height * ( ts.yp - touch->min_y ) / (touch->max_y-touch->min_y);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
touch->y = touch->height * ( touch->min_y - ts.yp ) / (touch->min_y-touch->max_y);
|
touch->y = touch->height * ( touch->min_y - ts.yp ) / (touch->min_y-touch->max_y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
touch_event.x = touch->x;
|
touch_event.x = touch->x;
|
||||||
touch_event.y = touch->y;
|
touch_event.y = touch->y;
|
||||||
touch_event.pressed = 1;
|
touch_event.pressed = 1;
|
||||||
|
|
||||||
if (touch->first_down_report == RT_TRUE)
|
if (touch->first_down_report == RT_TRUE)
|
||||||
{
|
{
|
||||||
if (touch->calibrating != RT_TRUE && touch->eventpost_func)
|
if (touch->calibrating != RT_TRUE && touch->eventpost_func)
|
||||||
{
|
{
|
||||||
touch->eventpost_func(touch->eventpost_param, &touch_event);
|
touch->eventpost_func(touch->eventpost_param, &touch_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
touch_event.x = touch->x;
|
touch_event.x = touch->x;
|
||||||
touch_event.y = touch->y;
|
touch_event.y = touch->y;
|
||||||
touch_event.pressed = 0;
|
touch_event.pressed = 0;
|
||||||
|
|
||||||
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
|
||||||
{
|
{
|
||||||
/* callback function */
|
/* callback function */
|
||||||
touch->calibration_func(touch_event.x, touch_event.y);
|
touch->calibration_func(touch_event.x, touch_event.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (touch->calibrating != RT_TRUE && touch->eventpost_func)
|
if (touch->calibrating != RT_TRUE && touch->eventpost_func)
|
||||||
{
|
{
|
||||||
touch->eventpost_func(touch->eventpost_param, &touch_event);
|
touch->eventpost_func(touch->eventpost_param, &touch_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void touch_timer_fire(void *parameter)
|
static void touch_timer_fire(void *parameter)
|
||||||
{
|
{
|
||||||
rt_uint32_t data0;
|
rt_uint32_t data0;
|
||||||
rt_uint32_t data1;
|
rt_uint32_t data1;
|
||||||
int updown;
|
int updown;
|
||||||
|
|
||||||
data0 = ADCDAT0;
|
data0 = ADCDAT0;
|
||||||
data1 = ADCDAT1;
|
data1 = ADCDAT1;
|
||||||
|
|
||||||
updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
|
updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
|
||||||
|
|
||||||
if (updown)
|
if (updown)
|
||||||
{
|
{
|
||||||
if (ts.count != 0)
|
if (ts.count != 0)
|
||||||
{
|
{
|
||||||
report_touch_input(updown);
|
report_touch_input(updown);
|
||||||
}
|
}
|
||||||
|
|
||||||
ts.xp = 0;
|
ts.xp = 0;
|
||||||
ts.yp = 0;
|
ts.yp = 0;
|
||||||
ts.count = 0;
|
ts.count = 0;
|
||||||
|
|
||||||
ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST;
|
ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST;
|
||||||
ADCCON |= S3C2410_ADCCON_ENABLE_START;
|
ADCCON |= S3C2410_ADCCON_ENABLE_START;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void s3c2410_adc_stylus_action(void)
|
static void s3c2410_adc_stylus_action(void)
|
||||||
{
|
{
|
||||||
rt_uint32_t data0;
|
rt_uint32_t data0;
|
||||||
rt_uint32_t data1;
|
rt_uint32_t data1;
|
||||||
|
|
||||||
data0 = ADCDAT0;
|
data0 = ADCDAT0;
|
||||||
data1 = ADCDAT1;
|
data1 = ADCDAT1;
|
||||||
|
|
||||||
ts.xp += data0 & S3C2410_ADCDAT0_XPDATA_MASK;
|
ts.xp += data0 & S3C2410_ADCDAT0_XPDATA_MASK;
|
||||||
ts.yp += data1 & S3C2410_ADCDAT1_YPDATA_MASK;
|
ts.yp += data1 & S3C2410_ADCDAT1_YPDATA_MASK;
|
||||||
ts.count ++;
|
ts.count ++;
|
||||||
|
|
||||||
if (ts.count < (1<<ts.shift))
|
if (ts.count < (1<<ts.shift))
|
||||||
{
|
{
|
||||||
ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST;
|
ADCTSC = S3C2410_ADCTSC_PULL_UP_DISABLE | AUTOPST;
|
||||||
ADCCON |= S3C2410_ADCCON_ENABLE_START;
|
ADCCON |= S3C2410_ADCCON_ENABLE_START;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (touch->first_down_report)
|
if (touch->first_down_report)
|
||||||
{
|
{
|
||||||
report_touch_input(1);
|
report_touch_input(1);
|
||||||
ts.xp = 0;
|
ts.xp = 0;
|
||||||
ts.yp = 0;
|
ts.yp = 0;
|
||||||
ts.count = 0;
|
ts.count = 0;
|
||||||
touch->first_down_report = 0;
|
touch->first_down_report = 0;
|
||||||
}
|
}
|
||||||
/* start timer */
|
/* start timer */
|
||||||
rt_timer_start(touch->poll_timer);
|
rt_timer_start(touch->poll_timer);
|
||||||
ADCTSC = WAIT4INT(1);
|
ADCTSC = WAIT4INT(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBSRCPND |= BIT_SUB_ADC;
|
SUBSRCPND |= BIT_SUB_ADC;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void s3c2410_intc_stylus_updown(void)
|
static void s3c2410_intc_stylus_updown(void)
|
||||||
{
|
{
|
||||||
rt_uint32_t data0;
|
rt_uint32_t data0;
|
||||||
rt_uint32_t data1;
|
rt_uint32_t data1;
|
||||||
int updown;
|
int updown;
|
||||||
|
|
||||||
data0 = ADCDAT0;
|
data0 = ADCDAT0;
|
||||||
data1 = ADCDAT1;
|
data1 = ADCDAT1;
|
||||||
|
|
||||||
updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
|
updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));
|
||||||
|
|
||||||
/* rt_kprintf("stylus: %s\n", updown? "down" : "up"); */
|
/* rt_kprintf("stylus: %s\n", updown? "down" : "up"); */
|
||||||
|
|
||||||
if (updown)
|
if (updown)
|
||||||
{
|
{
|
||||||
touch_timer_fire(0);
|
touch_timer_fire(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* stop timer */
|
/* stop timer */
|
||||||
rt_timer_stop(touch->poll_timer);
|
rt_timer_stop(touch->poll_timer);
|
||||||
touch->first_down_report = RT_TRUE;
|
touch->first_down_report = RT_TRUE;
|
||||||
if (ts.xp >= 0 && ts.yp >= 0)
|
if (ts.xp >= 0 && ts.yp >= 0)
|
||||||
{
|
{
|
||||||
report_touch_input(updown);
|
report_touch_input(updown);
|
||||||
}
|
}
|
||||||
ts.count = 0;
|
ts.count = 0;
|
||||||
ADCTSC = WAIT4INT(0);
|
ADCTSC = WAIT4INT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBSRCPND |= BIT_SUB_TC;
|
SUBSRCPND |= BIT_SUB_TC;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rt_touch_handler(int irqno, void *param)
|
static void rt_touch_handler(int irqno, void *param)
|
||||||
{
|
{
|
||||||
if (SUBSRCPND & BIT_SUB_ADC)
|
if (SUBSRCPND & BIT_SUB_ADC)
|
||||||
{
|
{
|
||||||
/* INT_SUB_ADC */
|
/* INT_SUB_ADC */
|
||||||
s3c2410_adc_stylus_action();
|
s3c2410_adc_stylus_action();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SUBSRCPND & BIT_SUB_TC)
|
if (SUBSRCPND & BIT_SUB_TC)
|
||||||
{
|
{
|
||||||
/* INT_SUB_TC */
|
/* INT_SUB_TC */
|
||||||
s3c2410_intc_stylus_updown();
|
s3c2410_intc_stylus_updown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear interrupt */
|
/* clear interrupt */
|
||||||
INTPND |= (1ul << INTADC);
|
INTPND |= (1ul << INTADC);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RT-Thread Device Interface */
|
/* RT-Thread Device Interface */
|
||||||
static rt_err_t rtgui_touch_init(rt_device_t dev)
|
static rt_err_t rtgui_touch_init(rt_device_t dev)
|
||||||
{
|
{
|
||||||
/* init touch screen structure */
|
/* init touch screen structure */
|
||||||
rt_memset(&ts, 0, sizeof(struct s3c2410ts));
|
rt_memset(&ts, 0, sizeof(struct s3c2410ts));
|
||||||
|
|
||||||
ts.delay = 50000;
|
ts.delay = 50000;
|
||||||
ts.presc = 9;
|
ts.presc = 9;
|
||||||
ts.shift = 2;
|
ts.shift = 2;
|
||||||
ts.count = 0;
|
ts.count = 0;
|
||||||
ts.xp = ts.yp = 0;
|
ts.xp = ts.yp = 0;
|
||||||
|
|
||||||
ADCCON = S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(ts.presc);
|
ADCCON = S3C2410_ADCCON_PRSCEN | S3C2410_ADCCON_PRSCVL(ts.presc);
|
||||||
ADCDLY = ts.delay;
|
ADCDLY = ts.delay;
|
||||||
|
|
||||||
ADCTSC = WAIT4INT(0);
|
ADCTSC = WAIT4INT(0);
|
||||||
|
|
||||||
rt_hw_interrupt_install(INTADC, rt_touch_handler, RT_NULL , "INTADC");
|
rt_hw_interrupt_install(INTADC, rt_touch_handler, RT_NULL , "INTADC");
|
||||||
rt_hw_interrupt_umask(INTADC);
|
rt_hw_interrupt_umask(INTADC);
|
||||||
|
|
||||||
/* clear interrupt */
|
/* clear interrupt */
|
||||||
INTPND |= (1ul << INTADC);
|
INTPND |= (1ul << INTADC);
|
||||||
|
|
||||||
SUBSRCPND |= BIT_SUB_TC;
|
SUBSRCPND |= BIT_SUB_TC;
|
||||||
SUBSRCPND |= BIT_SUB_ADC;
|
SUBSRCPND |= BIT_SUB_ADC;
|
||||||
|
|
||||||
/* install interrupt handler */
|
/* install interrupt handler */
|
||||||
INTSUBMSK &= ~BIT_SUB_ADC;
|
INTSUBMSK &= ~BIT_SUB_ADC;
|
||||||
INTSUBMSK &= ~BIT_SUB_TC;
|
INTSUBMSK &= ~BIT_SUB_TC;
|
||||||
|
|
||||||
touch->first_down_report = RT_TRUE;
|
touch->first_down_report = RT_TRUE;
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t rtgui_touch_control(rt_device_t dev, int cmd, void *args)
|
static rt_err_t rtgui_touch_control(rt_device_t dev, int cmd, void *args)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case RT_TOUCH_CALIBRATION:
|
case RT_TOUCH_CALIBRATION:
|
||||||
touch->calibrating = RT_TRUE;
|
touch->calibrating = RT_TRUE;
|
||||||
touch->calibration_func = (rt_touch_calibration_func_t)args;
|
touch->calibration_func = (rt_touch_calibration_func_t)args;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RT_TOUCH_NORMAL:
|
case RT_TOUCH_NORMAL:
|
||||||
touch->calibrating = RT_FALSE;
|
touch->calibrating = RT_FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RT_TOUCH_CALIBRATION_DATA:
|
case RT_TOUCH_CALIBRATION_DATA:
|
||||||
{
|
{
|
||||||
struct calibration_data *data;
|
struct calibration_data *data;
|
||||||
|
|
||||||
data = (struct calibration_data *)args;
|
data = (struct calibration_data *)args;
|
||||||
|
|
||||||
/* update */
|
/* update */
|
||||||
touch->min_x = data->min_x;
|
touch->min_x = data->min_x;
|
||||||
touch->max_x = data->max_x;
|
touch->max_x = data->max_x;
|
||||||
touch->min_y = data->min_y;
|
touch->min_y = data->min_y;
|
||||||
touch->max_y = data->max_y;
|
touch->max_y = data->max_y;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
rt_kprintf("min_x = %d, max_x = %d, min_y = %d, max_y = %d\n",
|
rt_kprintf("min_x = %d, max_x = %d, min_y = %d, max_y = %d\n",
|
||||||
touch->min_x, touch->max_x, touch->min_y, touch->max_y);
|
touch->min_x, touch->max_x, touch->min_y, touch->max_y);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RT_TOUCH_EVENTPOST:
|
case RT_TOUCH_EVENTPOST:
|
||||||
touch->eventpost_func = (rt_touch_eventpost_func_t)args;
|
touch->eventpost_func = (rt_touch_eventpost_func_t)args;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RT_TOUCH_EVENTPOST_PARAM:
|
case RT_TOUCH_EVENTPOST_PARAM:
|
||||||
touch->eventpost_param = args;
|
touch->eventpost_param = args;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtgui_touch_hw_init(void)
|
int rtgui_touch_hw_init(void)
|
||||||
{
|
{
|
||||||
rt_err_t result = RT_FALSE;
|
rt_err_t result = RT_FALSE;
|
||||||
rt_device_t device = RT_NULL;
|
rt_device_t device = RT_NULL;
|
||||||
struct rt_device_graphic_info info;
|
struct rt_device_graphic_info info;
|
||||||
|
|
||||||
touch = (struct rtgui_touch_device *)rt_malloc(sizeof(struct rtgui_touch_device));
|
touch = (struct rtgui_touch_device *)rt_malloc(sizeof(struct rtgui_touch_device));
|
||||||
if (touch == RT_NULL)
|
if (touch == RT_NULL)
|
||||||
return -RT_ERROR; /* no memory yet */
|
return -RT_ERROR; /* no memory yet */
|
||||||
|
|
||||||
/* clear device structure */
|
/* clear device structure */
|
||||||
rt_memset(&(touch->parent), 0, sizeof(struct rt_device));
|
rt_memset(&(touch->parent), 0, sizeof(struct rt_device));
|
||||||
touch->calibrating = RT_FALSE;
|
touch->calibrating = RT_FALSE;
|
||||||
touch->min_x = X_MIN;
|
touch->min_x = X_MIN;
|
||||||
touch->max_x = X_MAX;
|
touch->max_x = X_MAX;
|
||||||
touch->min_y = Y_MIN;
|
touch->min_y = Y_MIN;
|
||||||
touch->max_y = Y_MAX;
|
touch->max_y = Y_MAX;
|
||||||
touch->eventpost_func = RT_NULL;
|
touch->eventpost_func = RT_NULL;
|
||||||
touch->eventpost_param = RT_NULL;
|
touch->eventpost_param = RT_NULL;
|
||||||
|
|
||||||
/* init device structure */
|
/* init device structure */
|
||||||
touch->parent.type = RT_Device_Class_Unknown;
|
touch->parent.type = RT_Device_Class_Unknown;
|
||||||
touch->parent.init = rtgui_touch_init;
|
touch->parent.init = rtgui_touch_init;
|
||||||
touch->parent.control = rtgui_touch_control;
|
touch->parent.control = rtgui_touch_control;
|
||||||
touch->parent.user_data = RT_NULL;
|
touch->parent.user_data = RT_NULL;
|
||||||
|
|
||||||
device = rt_device_find("lcd");
|
device = rt_device_find("lcd");
|
||||||
if (device == RT_NULL)
|
if (device == RT_NULL)
|
||||||
{
|
{
|
||||||
rt_kprintf("No lcd found\n");
|
rt_kprintf("No lcd found\n");
|
||||||
return -RT_ERROR; /* no this device */
|
return -RT_ERROR; /* no this device */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get graphic device info */
|
/* get graphic device info */
|
||||||
result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info);
|
result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info);
|
||||||
if (result != RT_EOK)
|
if (result != RT_EOK)
|
||||||
{
|
{
|
||||||
/* get device information failed */
|
/* get device information failed */
|
||||||
rt_kprintf("Get graphic device info failed\n");
|
rt_kprintf("Get graphic device info failed\n");
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
touch->width = info.width;
|
touch->width = info.width;
|
||||||
touch->height = info.height;
|
touch->height = info.height;
|
||||||
|
|
||||||
/* create 1/8 second timer */
|
/* create 1/8 second timer */
|
||||||
touch->poll_timer = rt_timer_create("touch", touch_timer_fire, RT_NULL,
|
touch->poll_timer = rt_timer_create("touch", touch_timer_fire, RT_NULL,
|
||||||
RT_TICK_PER_SECOND/8, RT_TIMER_FLAG_PERIODIC);
|
RT_TICK_PER_SECOND/8, RT_TIMER_FLAG_PERIODIC);
|
||||||
|
|
||||||
/* register touch device to RT-Thread */
|
/* register touch device to RT-Thread */
|
||||||
rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR);
|
rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT_PREV_EXPORT(rtgui_touch_hw_init);
|
INIT_PREV_EXPORT(rtgui_touch_hw_init);
|
||||||
|
@ -3,23 +3,23 @@
|
|||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
||||||
#define RT_TOUCH_NORMAL 0
|
#define RT_TOUCH_NORMAL 0
|
||||||
#define RT_TOUCH_CALIBRATION_DATA 1
|
#define RT_TOUCH_CALIBRATION_DATA 1
|
||||||
#define RT_TOUCH_CALIBRATION 2
|
#define RT_TOUCH_CALIBRATION 2
|
||||||
#define RT_TOUCH_EVENTPOST 3
|
#define RT_TOUCH_EVENTPOST 3
|
||||||
#define RT_TOUCH_EVENTPOST_PARAM 4
|
#define RT_TOUCH_EVENTPOST_PARAM 4
|
||||||
|
|
||||||
struct calibration_data
|
struct calibration_data
|
||||||
{
|
{
|
||||||
rt_uint16_t min_x, max_x;
|
rt_uint16_t min_x, max_x;
|
||||||
rt_uint16_t min_y, max_y;
|
rt_uint16_t min_y, max_y;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct rt_touch_event
|
struct rt_touch_event
|
||||||
{
|
{
|
||||||
rt_uint16_t x;
|
rt_uint16_t x;
|
||||||
rt_uint16_t y;
|
rt_uint16_t y;
|
||||||
int pressed;
|
int pressed;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*rt_touch_calibration_func_t)(rt_uint16_t x, rt_uint16_t y);
|
typedef void (*rt_touch_calibration_func_t)(rt_uint16_t x, rt_uint16_t y);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user