1 /*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 */
9
10 #include "lcdc.h"
11 #include <sep4020.h>
12
13 #define writel(DATA,ADDRESS) *((volatile rt_off_t *) ADDRESS)= DATA;
14
15 unsigned long pVideoBuffer;
16
17
sep4020_lcd_init(void)18 rt_err_t sep4020_lcd_init(void)
19 {
20 pVideoBuffer =(unsigned long)rt_malloc(LCDWIDTH * LCDHEIGHT * 2);
21
22 *(RP)GPIO_PORTC_SEL |= 0X0008; //Portc8设置为通用口
23 *(RP)GPIO_PORTC_DIR &= (~0X0008); //Portc8设置为输出
24 *(RP)GPIO_PORTC_DATA |= 0X0008; //Portc8输出高电平
25
26 writel(0x00000000,LCDC_LECR); //禁用LCDC
27 writel(pVideoBuffer,LCDC_SSA); //lcd数据帧的起始地址
28 writel(YMAX | XMAX,LCDC_SIZE);
29 writel(TFT|COLOR|PBSIZE|BPIX|PIXPOL|FLMPOL|LPPOL|CLKPOL|OEPOL|END_SEL|ACD_SEL|ACD|PCD,LCDC_PCR);
30 writel(H_WIDTH|H_WAIT_1|H_WAIT_2,LCDC_HCR);
31 writel(V_WIDTH|PASS_FRAME_WAIT|V_WAIT_1|V_WAIT_2,LCDC_VCR);
32 writel(SCR|CC_EN|PW,LCDC_PWMR);
33 writel(BL|HM|TM,LCDC_DMACR);
34 writel(0x00000001,LCDC_LECR); //使能LCDC
35 writel(0x00000000,LCDC_LCDISREN); //中断在加载帧的最后一个或第一个数据时设置,到LCD之间会有一个延时
36
37 return RT_EOK;
38 }
39
lcd_set_pixel(rtgui_color_t * c,int x,int y)40 void lcd_set_pixel(rtgui_color_t *c, int x, int y)
41 {
42 unsigned short p;
43
44 /* get color pixel */
45 p = rtgui_color_to_565p(*c);
46
47 *(unsigned short *)(pVideoBuffer + 2*y*LCDWIDTH + 2*x) = p;
48 }
49
lcd_get_pixel(rtgui_color_t * c,int x,int y)50 void lcd_get_pixel(rtgui_color_t *c, int x, int y)
51 {
52 *c = rtgui_color_from_565p( *(unsigned short *)(pVideoBuffer+2*y*LCDWIDTH+2*x));
53 }
54
lcd_draw_hline(rtgui_color_t * c,int x1,int x2,int y)55 void lcd_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
56 {
57 unsigned short p;
58
59 /* get color pixel */
60 p = rtgui_color_to_565p(*c);
61
62 while (x1 < x2)
63 {
64 *(unsigned short *)(pVideoBuffer+2*y*LCDWIDTH+2*x1)=p;
65 x1 ++;
66 }
67 }
68
lcd_draw_vline(rtgui_color_t * c,int x,int y1,int y2)69 void lcd_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
70 {
71 unsigned short p;
72
73 /* get color pixel */
74 p = rtgui_color_to_565p(*c);
75
76 while (y1 < y2)
77 {
78 *(unsigned short *)(pVideoBuffer+2*y1*LCDWIDTH+2*x)=p;
79 y1 ++;
80 }
81 }
82
lcd_draw_raw_hline(rt_uint8_t * pixels,int x1,int x2,int y)83 void lcd_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
84 {
85 rt_uint16_t *ptr;
86
87 /* get pixel */
88 ptr = (rt_uint16_t*) pixels;
89
90 while (x1 < x2)
91 {
92 *(unsigned short *)(pVideoBuffer+2*y*LCDWIDTH+2*x1)=*ptr;
93 x1 ++;
94 ptr ++;
95 }
96 }
97
lcd_update(rtgui_rect_t * rect)98 void lcd_update(rtgui_rect_t *rect)
99 {
100 /* nothing for none-DMA mode driver */
101 }
102
lcd_get_framebuffer(void)103 rt_uint8_t *lcd_get_framebuffer(void)
104 {
105 return RT_NULL; /* no framebuffer driver */
106 }
107