1 /*
2  * Copyright (c) 2018 PHYTEC Messtechnik GmbH
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Public Monochrome Character Framebuffer API
10  */
11 
12 #ifndef __CFB_H__
13 #define __CFB_H__
14 
15 #include <device.h>
16 #include <drivers/display.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /**
23  * @brief Display Drivers
24  * @addtogroup display_interfaces Display Drivers
25  * @{
26  * @}
27  */
28 
29 /**
30  * @brief Public Monochrome Character Framebuffer API
31  * @defgroup monochrome_character_framebuffer Monochrome Character Framebuffer
32  * @ingroup display_interfaces
33  * @{
34  */
35 
36 enum cfb_display_param {
37 	CFB_DISPLAY_HEIGH		= 0,
38 	CFB_DISPLAY_WIDTH,
39 	CFB_DISPLAY_PPT,
40 	CFB_DISPLAY_ROWS,
41 	CFB_DISPLAY_COLS,
42 };
43 
44 enum cfb_font_caps {
45 	CFB_FONT_MONO_VPACKED		= BIT(0),
46 	CFB_FONT_MONO_HPACKED		= BIT(1),
47 	CFB_FONT_MSB_FIRST		= BIT(2),
48 };
49 
50 struct cfb_font {
51 	const void *data;
52 	enum cfb_font_caps caps;
53 	uint8_t width;
54 	uint8_t height;
55 	uint8_t first_char;
56 	uint8_t last_char;
57 };
58 
59 /**
60  * @brief Macro for creating a font entry.
61  *
62  * @param _name   Name of the font entry.
63  * @param _width  Width of the font in pixels
64  * @param _height Height of the font in pixels.
65  * @param _caps   Font capabilities.
66  * @param _data   Raw data of the font.
67  * @param _fc     Character mapped to first font element.
68  * @param _lc     Character mapped to last font element.
69  */
70 #define FONT_ENTRY_DEFINE(_name, _width, _height, _caps, _data, _fc, _lc)      \
71 	static const STRUCT_SECTION_ITERABLE(cfb_font, _name) = {	       \
72 		.data = _data,						       \
73 		.caps = _caps,						       \
74 		.width = _width,					       \
75 		.height = _height,					       \
76 		.first_char = _fc,					       \
77 		.last_char = _lc,					       \
78 	}
79 
80 /**
81  * @brief Print a string into the framebuffer.
82  *
83  * @param dev Pointer to device structure for driver instance
84  * @param str String to print
85  * @param x Position in X direction of the beginning of the string
86  * @param y Position in Y direction of the beginning of the string
87  *
88  * @return 0 on success, negative value otherwise
89  */
90 int cfb_print(const struct device *dev, char *str, uint16_t x, uint16_t y);
91 
92 /**
93  * @brief Clear framebuffer.
94  *
95  * @param dev Pointer to device structure for driver instance
96  * @param clear_display Clear the display as well
97  *
98  * @return 0 on success, negative value otherwise
99  */
100 int cfb_framebuffer_clear(const struct device *dev, bool clear_display);
101 
102 /**
103  * @brief Invert Pixels.
104  *
105  * @param dev Pointer to device structure for driver instance
106  *
107  * @return 0 on success, negative value otherwise
108  */
109 int cfb_framebuffer_invert(const struct device *dev);
110 
111 /**
112  * @brief Finalize framebuffer and write it to display RAM,
113  * invert or reorder pixels if necessary.
114  *
115  * @param dev Pointer to device structure for driver instance
116  *
117  * @return 0 on success, negative value otherwise
118  */
119 int cfb_framebuffer_finalize(const struct device *dev);
120 
121 /**
122  * @brief Get display parameter.
123  *
124  * @param dev Pointer to device structure for driver instance
125  * @param cfb_display_param One of the display parameters
126  *
127  * @return Display parameter value
128  */
129 int cfb_get_display_parameter(const struct device *dev,
130 			      enum cfb_display_param);
131 
132 /**
133  * @brief Set font.
134  *
135  * @param dev Pointer to device structure for driver instance
136  * @param idx Font index
137  *
138  * @return 0 on success, negative value otherwise
139  */
140 int cfb_framebuffer_set_font(const struct device *dev, uint8_t idx);
141 
142 /**
143  * @brief Get font size.
144  *
145  * @param dev Pointer to device structure for driver instance
146  * @param idx Font index
147  * @param width Pointers to the variable where the font width will be stored.
148  * @param height Pointers to the variable where the font height will be stored.
149  *
150  * @return 0 on success, negative value otherwise
151  */
152 int cfb_get_font_size(const struct device *dev, uint8_t idx, uint8_t *width,
153 		      uint8_t *height);
154 
155 /**
156  * @brief Get number of fonts.
157  *
158  * @param dev Pointer to device structure for driver instance
159  *
160  * @return number of fonts
161  */
162 int cfb_get_numof_fonts(const struct device *dev);
163 
164 /**
165  * @brief Initialize Character Framebuffer.
166  *
167  * @param dev Pointer to device structure for driver instance
168  *
169  * @return 0 on success, negative value otherwise
170  */
171 int cfb_framebuffer_init(const struct device *dev);
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 /**
178  * @}
179  */
180 
181 #endif /* __CFB_H__ */
182