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 #include <rtthread.h>
10 #include <rtdevice.h>
11 
12 #include "LPC177x_8x.h"
13 #include "lpc177x_8x_pinsel.h"
14 
15 #include "drv_glcd.h"
16 
17 #define RT_HW_LCD_WIDTH     480
18 #define RT_HW_LCD_HEIGHT    272
19 
20 static struct rt_device_graphic_info _lcd_info;
21 static struct rt_device  lcd;
22 
23 /* RT-Thread Device Interface */
rt_lcd_init(rt_device_t dev)24 static rt_err_t rt_lcd_init (rt_device_t dev)
25 {
26     PINSEL_ConfigPin(5, 4, 0);
27     LPC_GPIO5->DIR |= 1<<4;
28     LPC_GPIO5->CLR  = 1<<4;
29     LPC_GPIO5->SET  = 1<<4;
30 
31     /*Disable LCD controller*/
32     GLCD_Ctrl (FALSE);
33     /*Init LCD and copy picture in video RAM*/
34     GLCD_Init (_lcd_info.framebuffer);
35     /*Enable LCD*/
36     GLCD_Ctrl (TRUE);
37 
38     return RT_EOK;
39 }
40 
rt_lcd_control(rt_device_t dev,int cmd,void * args)41 static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
42 {
43     switch (cmd)
44     {
45     case RTGRAPHIC_CTRL_RECT_UPDATE:
46         break;
47     case RTGRAPHIC_CTRL_POWERON:
48         break;
49     case RTGRAPHIC_CTRL_POWEROFF:
50         break;
51     case RTGRAPHIC_CTRL_GET_INFO:
52         rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
53         break;
54     case RTGRAPHIC_CTRL_SET_MODE:
55         break;
56     }
57 
58     return RT_EOK;
59 }
60 
61 
62 /* LCD BL P5_4 */
rt_hw_lcd_init(void)63 void rt_hw_lcd_init(void)
64 {
65     rt_uint16_t * _rt_framebuffer = RT_NULL;
66 
67     // _rt_framebuffer = rt_malloc_align(sizeof(rt_uint16_t)*RT_HW_LCD_HEIGHT*RT_HW_LCD_WIDTH, 8);
68     // if (_rt_framebuffer == RT_NULL) return; /* no memory yet */
69 
70     _rt_framebuffer = (rt_uint16_t *)0xA0000000;
71 
72     _lcd_info.bits_per_pixel = 16;
73     _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
74     _lcd_info.framebuffer = (void*)_rt_framebuffer;
75     _lcd_info.width = RT_HW_LCD_WIDTH;
76     _lcd_info.height = RT_HW_LCD_HEIGHT;
77 
78     /* init device structure */
79     lcd.type = RT_Device_Class_Graphic;
80     lcd.init = rt_lcd_init;
81     lcd.open = RT_NULL;
82     lcd.close = RT_NULL;
83     lcd.control = rt_lcd_control;
84     lcd.user_data = (void*)&_lcd_info;
85 
86     /* register lcd device to RT-Thread */
87     rt_device_register(&lcd, "lcd", RT_DEVICE_FLAG_RDWR);
88 }
89 
lcd_fill(uint8_t * start,uint8_t * end,uint8_t pixel)90 void lcd_fill(uint8_t * start, uint8_t * end, uint8_t pixel)
91 {
92     while(start<end)
93     {
94         *start++ = pixel;
95     }
96 }
97 #ifdef RT_USING_FINSH
98 #include <finsh.h>
99 FINSH_FUNCTION_EXPORT(lcd_fill, lcd_fill  );
100 #endif
101