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-10-11     zmshahaha    move from <rtdef.h>
9  */
10 
11 #ifndef __GRAPHIC_H__
12 #define __GRAPHIC_H__
13 
14 #include <rtdef.h>
15 
16 /**
17  * cursor control command
18  */
19 #define RT_DEVICE_CTRL_CURSOR_SET_POSITION  0x10
20 #define RT_DEVICE_CTRL_CURSOR_SET_TYPE      0x11
21 
22 /**
23  * graphic device control command
24  */
25 #define RTGRAPHIC_CTRL_RECT_UPDATE      (RT_DEVICE_CTRL_BASE(Graphic) + 0)
26 #define RTGRAPHIC_CTRL_POWERON          (RT_DEVICE_CTRL_BASE(Graphic) + 1)
27 #define RTGRAPHIC_CTRL_POWEROFF         (RT_DEVICE_CTRL_BASE(Graphic) + 2)
28 #define RTGRAPHIC_CTRL_GET_INFO         (RT_DEVICE_CTRL_BASE(Graphic) + 3)
29 #define RTGRAPHIC_CTRL_SET_MODE         (RT_DEVICE_CTRL_BASE(Graphic) + 4)
30 #define RTGRAPHIC_CTRL_GET_EXT          (RT_DEVICE_CTRL_BASE(Graphic) + 5)
31 #define RTGRAPHIC_CTRL_SET_BRIGHTNESS   (RT_DEVICE_CTRL_BASE(Graphic) + 6)
32 #define RTGRAPHIC_CTRL_GET_BRIGHTNESS   (RT_DEVICE_CTRL_BASE(Graphic) + 7)
33 #define RTGRAPHIC_CTRL_GET_MODE         (RT_DEVICE_CTRL_BASE(Graphic) + 8)
34 #define RTGRAPHIC_CTRL_GET_STATUS       (RT_DEVICE_CTRL_BASE(Graphic) + 9)
35 #define RTGRAPHIC_CTRL_PAN_DISPLAY      (RT_DEVICE_CTRL_BASE(Graphic) + 10)
36 #define RTGRAPHIC_CTRL_WAIT_VSYNC       (RT_DEVICE_CTRL_BASE(Graphic) + 11)
37 
38 /* graphic device */
39 enum
40 {
41     RTGRAPHIC_PIXEL_FORMAT_MONO = 0,
42     RTGRAPHIC_PIXEL_FORMAT_GRAY4,
43     RTGRAPHIC_PIXEL_FORMAT_GRAY16,
44     RTGRAPHIC_PIXEL_FORMAT_RGB332,
45     RTGRAPHIC_PIXEL_FORMAT_RGB444,
46     RTGRAPHIC_PIXEL_FORMAT_RGB565,
47     RTGRAPHIC_PIXEL_FORMAT_RGB565P,
48     RTGRAPHIC_PIXEL_FORMAT_BGR565 = RTGRAPHIC_PIXEL_FORMAT_RGB565P,
49     RTGRAPHIC_PIXEL_FORMAT_RGB666,
50     RTGRAPHIC_PIXEL_FORMAT_RGB888,
51     RTGRAPHIC_PIXEL_FORMAT_BGR888,
52     RTGRAPHIC_PIXEL_FORMAT_ARGB888,
53     RTGRAPHIC_PIXEL_FORMAT_ABGR888,
54     RTGRAPHIC_PIXEL_FORMAT_RESERVED,
55 };
56 
57 /**
58  * build a pixel position according to (x, y) coordinates.
59  */
60 #define RTGRAPHIC_PIXEL_POSITION(x, y)  ((x << 16) | y)
61 
62 /**
63  * graphic device information structure
64  */
65 struct rt_device_graphic_info
66 {
67     rt_uint8_t  pixel_format;                           /**< graphic format */
68     rt_uint8_t  bits_per_pixel;                         /**< bits per pixel */
69     rt_uint16_t pitch;                                  /**< bytes per line */
70 
71     rt_uint16_t width;                                  /**< width of graphic device */
72     rt_uint16_t height;                                 /**< height of graphic device */
73 
74     rt_uint8_t *framebuffer;                            /**< frame buffer */
75     rt_uint32_t smem_len;                               /**< allocated frame buffer size */
76 };
77 
78 /**
79  * rectangle information structure
80  */
81 struct rt_device_rect_info
82 {
83     rt_uint16_t x;                                      /**< x coordinate */
84     rt_uint16_t y;                                      /**< y coordinate */
85     rt_uint16_t width;                                  /**< width */
86     rt_uint16_t height;                                 /**< height */
87 };
88 
89 /**
90  * graphic operations
91  */
92 struct rt_device_graphic_ops
93 {
94     void (*set_pixel) (const char *pixel, int x, int y);
95     void (*get_pixel) (char *pixel, int x, int y);
96 
97     void (*draw_hline)(const char *pixel, int x1, int x2, int y);
98     void (*draw_vline)(const char *pixel, int x, int y1, int y2);
99 
100     void (*blit_line) (const char *pixel, int x, int y, rt_size_t size);
101 };
102 #define rt_graphix_ops(device)          ((struct rt_device_graphic_ops *)(device->user_data))
103 
104 #endif /* __GRAPHIC_H__ */
105