diff --git a/bsp/mini4020/lcd.c b/bsp/mini4020/lcd.c new file mode 100644 index 0000000000..83cb801730 --- /dev/null +++ b/bsp/mini4020/lcd.c @@ -0,0 +1,66 @@ +#include "lcdc.h" +#include "rtthread.h" +#include "board.h" + +#include +#include +#include +#include +extern rt_err_t sep4020_lcd_init(void); +extern unsigned long pVideoBuffer; + + +struct rtgui_graphic_driver _rtgui_lcd_driver; + + +void radio_rtgui_init(void) +{ + rtgui_rect_t rect; +// rtgui_color_t c=0xff; + rtgui_system_server_init(); + + /* register dock panel */ + rect.x1 = 0; + rect.y1 = 0; + rect.x2 = 320; + rect.y2 = 25; + rtgui_panel_register("info", &rect); + rtgui_panel_set_nofocused("info"); + + /* register main panel */ + rect.x1 = 0; + rect.y1 = 25; + rect.x2 = 320; + rect.y2 = 240; + rtgui_panel_register("main", &rect); + rtgui_panel_set_default_focused("main"); + + + _rtgui_lcd_driver.name = "lcd"; + _rtgui_lcd_driver.byte_per_pixel = 2; + _rtgui_lcd_driver.width = 320; + _rtgui_lcd_driver.height = 240; + _rtgui_lcd_driver.draw_hline = lcd_draw_hline; + _rtgui_lcd_driver.draw_raw_hline = lcd_draw_raw_hline; + _rtgui_lcd_driver.draw_vline = lcd_draw_vline; + _rtgui_lcd_driver.get_pixel = lcd_get_pixel; + _rtgui_lcd_driver.set_pixel = lcd_set_pixel; + _rtgui_lcd_driver.screen_update = lcd_update; + _rtgui_lcd_driver.get_framebuffer = lcd_get_framebuffer; + + sep4020_lcd_init(); + + rt_memset((char*)pVideoBuffer,0xff,320*240*2); + // rt_memcpy((char*)pVideoBuffer,pic,320*240*2); //TESTING IMAGE + + + /* add lcd driver into graphic driver */ + rtgui_graphic_driver_add(&_rtgui_lcd_driver); + + + info_init(); + + + +} + diff --git a/bsp/mini4020/lcdc.c b/bsp/mini4020/lcdc.c new file mode 100644 index 0000000000..a64e9a5a5a --- /dev/null +++ b/bsp/mini4020/lcdc.c @@ -0,0 +1,111 @@ +#include "lcdc.h" +#include + + +#define writel(DATA,ADDRESS) *((volatile rt_off_t *) ADDRESS)= DATA; + + +unsigned long pVideoBuffer; + +rt_err_t sep4020_lcd_init(void) +{ + + pVideoBuffer =(unsigned long) rt_malloc(LCDWIDTH*LCDHEIGHT*2); + + + *(RP)GPIO_PORTC_SEL |= 0X0008; //Portc8设置为通用口 + *(RP)GPIO_PORTC_DIR &= (~0X0008); //Portc8设置为输出 + *(RP)GPIO_PORTC_DATA |= 0X0008; //Portc8输出高电平 + + + + writel(0x00000000,LCDC_LECR); //禁用LCDC + writel(pVideoBuffer,LCDC_SSA); //lcd数据帧的起始地址 + writel(YMAX | XMAX,LCDC_SIZE); + writel(TFT|COLOR|PBSIZE|BPIX|PIXPOL|FLMPOL|LPPOL|CLKPOL|OEPOL|END_SEL|ACD_SEL|ACD|PCD,LCDC_PCR); + writel(H_WIDTH|H_WAIT_1|H_WAIT_2,LCDC_HCR); + writel(V_WIDTH|PASS_FRAME_WAIT|V_WAIT_1|V_WAIT_2,LCDC_VCR); + writel(SCR|CC_EN|PW,LCDC_PWMR); + writel(BL|HM|TM,LCDC_DMACR); + writel(0x00000001,LCDC_LECR); //使能LCDC + writel(0x00000000,LCDC_LCDISREN); //中断在加载帧的最后一个或第一个数据时设置,到LCD之间会有一个延时 + + return RT_EOK; +} + + + void lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) +{ + unsigned short p; + + /* get color pixel */ + p = rtgui_color_to_565p(*c); + + + *(unsigned short *)(pVideoBuffer+2*y*LCDWIDTH+2*x)=p; +} + + +void lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) +{ + + *c = rtgui_color_from_565p( *(unsigned short *)(pVideoBuffer+2*y*LCDWIDTH+2*x)); +} + +void lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y) +{ + unsigned short p; + + /* get color pixel */ + p = rtgui_color_to_565p(*c); + + + while (x1 < x2) + { + *(unsigned short *)(pVideoBuffer+2*y*LCDWIDTH+2*x1)=p; + x1 ++; + + } +} + +void lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2) +{ + unsigned short p; + + /* get color pixel */ + p = rtgui_color_to_565p(*c); + + + while (y1 < y2) + { + + *(unsigned short *)(pVideoBuffer+2*y1*LCDWIDTH+2*x)=p; + y1 ++; + } +} + +void lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y) +{ + rt_uint16_t *ptr; + + /* get pixel */ + ptr = (rt_uint16_t*) pixels; + + + while (x1 < x2) + { + *(unsigned short *)(pVideoBuffer+2*y*LCDWIDTH+2*x1)=*ptr; + x1 ++; + ptr ++; + } +} + +void lcd_update(rtgui_rect_t *rect) +{ + /* nothing for none-DMA mode driver */ +} + +rt_uint8_t * lcd_get_framebuffer(void) +{ + return RT_NULL; /* no framebuffer driver */ +} diff --git a/bsp/mini4020/lcdc.h b/bsp/mini4020/lcdc.h new file mode 100644 index 0000000000..4b7edb3622 --- /dev/null +++ b/bsp/mini4020/lcdc.h @@ -0,0 +1,68 @@ +#ifndef LCD_GENERAL_H_INCLUDED +#define LCD_GENERAL_H_INCLUDED + +#include +#include +#include +#include + + +#define LCDWIDTH 320 +#define LCDHEIGHT 240 + +//Macro for SIZE register setting +#define XMAX ((LCDWIDTH/16) << 20) +#define YMAX (LCDHEIGHT) + +//Macro for PCR register setting +#define TFT ((U32)1 << 31) +#define COLOR (1 << 30) //1为色彩. +#define PBSIZE (0 << 28) +#define BPIX (4 << 25) //存储器中一个像素对应16bit +#define PIXPOL (0 << 24) //像素极性—设置像素的极性,高有效 //0<<24 +#define FLMPOL (1 << 23) //首行标志极性—设置首行标志的极性,低有效. +#define LPPOL (1 << 22) //行脉冲极性—设置行脉冲信号的极性,低有效. +#define CLKPOL (0 << 21) //LCD 移位时钟极性—设置LCD 移位时钟的有效沿的极性,下降延有效. +#define OEPOL (1 << 20) //输出使能极性—设置输出使能信号的极性,高有效. +#define END_SEL (0 << 18) //印第安格式选择,小印第安. +#define ACD_SEL (0 << 15) //ACD时钟源选择—选择晶向变换计数器的时钟,使用FLM 作为ACD 计数时钟 +#define ACD (0 << 8 ) //被动模式. +#define PCD (10) + +//Macro for HCR regiter setting //水平配置寄存器. +#define H_WIDTH ((U32)46 << 26) +#define H_WAIT_1 (20 << 8) +#define H_WAIT_2 (20) + +//Macro for VCR register setting //垂直配置寄存器. +#define V_WIDTH ((U32)10 << 26) +#define PASS_FRAME_WAIT (0 <<16) +#define V_WAIT_1 (3 << 8) +#define V_WAIT_2 (3) + +//Macro for LGPR register setting +#define GRAY (4) //灰度等级. + +//Macro for PWMR register setting +#define SCR (0 << 9) //时钟源选择.行脉冲. +#define CC_EN (0 << 8) //对比度控制使能,关. +#define PW (64) //输出脉冲数目, + +//Macro for DMACR register setting +#define BL ((U32)1 << 31) //固定长度. +#define HM (7 << 16) +#define TM (3) + +void lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y); +void lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y); +void lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y) ; +void lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2) ; +void lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y) ; +void lcd_update(rtgui_rect_t *rect); +rt_uint8_t * lcd_get_framebuffer(void); +rt_err_t sep4020_lcd_init(void); + + +#endif + +