1 /*
2  * Copyright (c) 2006-2022, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2021-12-28     unknow       copy by STemwin
9  */
10 #ifndef __DRV_LCD_H
11 #define __DRV_LCD_H
12 #include <rtthread.h>
13 #include "rtdevice.h"
14 #include <drv_common.h>
15 #ifdef PKG_USING_QRCODE
16 #include <qrcode.h>
17 #endif
18 
19 #define LCD_BASE ((uint32_t)(0x68000000 | 0x0003FFFE)) // A18 link to DCX
20 #define LCD ((LCD_CONTROLLER_TypeDef *)LCD_BASE)
21 #define LCD_W 240
22 #define LCD_H 240
23 
24 //LCD重要参数集
25 typedef struct
26 {
27     uint16_t width;         //LCD 宽度
28     uint16_t height;        //LCD 高度
29     uint16_t id;            //LCD ID
30     uint8_t  dir;           //横屏还是竖屏控制:0,竖屏;1,横屏。
31     uint16_t wramcmd;       //开始写gram指令
32     uint16_t setxcmd;       //设置x坐标指令
33     uint16_t setycmd;       //设置y坐标指令
34 }_lcd_dev;
35 
36 //LCD参数
37 extern _lcd_dev lcddev; //管理LCD重要参数
38 
39 typedef struct
40 {
41   volatile uint8_t _u8_REG;
42   volatile uint8_t RESERVED;
43   volatile uint8_t _u8_RAM;
44   volatile uint16_t _u16_RAM;
45 }LCD_CONTROLLER_TypeDef;
46 
47 
48 //POINT_COLOR
49 #define WHITE            0xFFFF
50 #define BLACK            0x0000
51 #define BLUE             0x001F
52 #define BRED             0XF81F
53 #define GRED             0XFFE0
54 #define GBLUE            0X07FF
55 #define RED              0xF800
56 #define MAGENTA          0xF81F
57 #define GREEN            0x07E0
58 #define CYAN             0x7FFF
59 #define YELLOW           0xFFE0
60 #define BROWN            0XBC40
61 #define BRRED            0XFC07
62 #define GRAY             0X8430
63 #define GRAY175          0XAD75
64 #define GRAY151          0X94B2
65 #define GRAY187          0XBDD7
66 #define GRAY240          0XF79E
67 
68 //扫描方向定义
69 #define L2R_U2D  0      //从左到右,从上到下
70 #define L2R_D2U  1      //从左到右,从下到上
71 #define R2L_U2D  2      //从右到左,从上到下
72 #define R2L_D2U  3      //从右到左,从下到上
73 
74 #define U2D_L2R  4      //从上到下,从左到右
75 #define U2D_R2L  5      //从上到下,从右到左
76 #define D2U_L2R  6      //从下到上,从左到右
77 #define D2U_R2L  7      //从下到上,从右到左
78 
79 int drv_lcd_init(void);
80 void lcd_clear(rt_uint16_t color);
81 void lcd_address_set(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2);
82 void lcd_set_color(rt_uint16_t back, rt_uint16_t fore);
83 
84 rt_uint16_t change_byte_order(rt_uint16_t word);
85 void lcd_draw_point(rt_uint16_t x, rt_uint16_t y);
86 void lcd_draw_circle(rt_uint16_t x0, rt_uint16_t y0, rt_uint8_t r);
87 void lcd_draw_line(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2);
88 void lcd_draw_rectangle(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2);
89 void lcd_fill(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_uint16_t y_end, rt_uint16_t color);
90 
91 void lcd_address_set(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2);
92 rt_err_t lcd_write_half_word(const rt_uint16_t da);
93 rt_err_t lcd_write_data_buffer(const void *send_buf, rt_size_t length);
94 
95 void lcd_show_num(rt_uint16_t x, rt_uint16_t y, rt_uint32_t num, rt_uint8_t len, rt_uint32_t size);
96 rt_err_t lcd_show_string(rt_uint16_t x, rt_uint16_t y, rt_uint32_t size, const char *fmt, ...);
97 rt_err_t lcd_show_image(rt_uint16_t x, rt_uint16_t y, rt_uint16_t length, rt_uint16_t wide, const rt_uint8_t *p);
98 #ifdef PKG_USING_QRCODE
99 rt_err_t lcd_show_qrcode(rt_uint16_t x, rt_uint16_t y, rt_uint8_t version, rt_uint8_t ecc, const char *data, rt_uint8_t enlargement);
100 #endif
101 
102 void lcd_enter_sleep(void);
103 void lcd_exit_sleep(void);
104 void lcd_display_on(void);
105 void lcd_display_off(void);
106 
107 void lcd_fill_array(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_uint16_t y_end, void *pcolor);
108 
109 #endif
110