1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2023-05-23     Chushicheng  the first version.
9  */
10 
11 #ifndef DRV_ST7796_H__
12 #define DRV_ST7796_H__
13 
14 #include <rtdevice.h>
15 
16 #define LCD_DEVICE_NAME  "st7796"
17 typedef enum
18 {
19     ST7796_DIR_0   = 0x08U,
20     ST7796_DIR_90  = 0x68U,
21     ST7796_DIR_180 = 0xC8U,
22     ST7796_DIR_270 = 0xA8U,
23 } st7796_direction_t;
24 
25 typedef enum
26 {
27     ST7796_RGB444 = 3,
28     ST7796_RGB565 = 5,
29     ST7796_RGB666 = 6,
30     ST7796_RGB888 = 7
31 } st7796_pixfmt_t;
32 
33 typedef struct
34 {
35     rt_err_t (*reset_cb)(void *handle);
36     rt_err_t (*backlight_cb)(void *handle, rt_uint8_t on);
37     rt_err_t (*write_cmd_cb)(void *handle, rt_uint8_t *cmd, rt_uint8_t len);
38     rt_err_t (*write_data_cb)(void *handle, void *data, rt_uint32_t len);
39 } st7796_cb_t;
40 
41 typedef struct
42 {
43     st7796_direction_t direction;
44     st7796_pixfmt_t pix_fmt;
45     rt_uint8_t inversion;
46     rt_uint8_t bgr_mode;
47     uint8_t mirrored;
48 } st7796_config_t;
49 
50 typedef struct
51 {
52     void *user_data;
53     st7796_cb_t cb;
54     st7796_config_t config;
55 } st7796_lcd_t;
56 
57 typedef struct
58 {
59     struct rt_device            parent;
60     st7796_lcd_t                st7796;
61     struct rt_spi_device        *spi_dev;
62 } st7796_t;
63 
64 void lcd_load(rt_uint16_t x_start, rt_uint16_t x_end, rt_uint16_t y_start, rt_uint16_t y_end, void *data);
65 int drv_st7796_init(void);
66 
67 #endif /* DRV_ST7796_H__ */
68 
69