mikroSDK Reference Manual
lvgl_common.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 2024 MikroElektronika d.o.o.
4** Contact: https://www.mikroe.com/contact
5**
6** This file is part of the mikroSDK package
7**
8** Commercial License Usage
9**
10** Licensees holding valid commercial NECTO compilers AI licenses may use this
11** file in accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The MikroElektronika Company.
14** For licensing terms and conditions see
15** https://www.mikroe.com/legal/software-license-agreement.
16** For further information use the contact form at
17** https://www.mikroe.com/contact.
18**
19**
20** GNU Lesser General Public License Usage
21**
22** Alternatively, this file may be used for
23** non-commercial projects under the terms of the GNU Lesser
24** General Public License version 3 as published by the Free Software
25** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
26**
27** The above copyright notice and this permission notice shall be
28** included in all copies or substantial portions of the Software.
29**
30** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
32** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
35** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37**
38****************************************************************************/
44#ifdef __cplusplus
45extern "C"{
46#endif
47
48#ifndef _LVGL_COMMON_H_
49#define _LVGL_COMMON_H_
50
51#include "board.h"
52#include "drv_port.h"
53#include "ili9341_cmd.h"
54#include "ili9341_defines.h"
55#include "drv_digital_out.h"
56#include "touch_controller.h"
57
58#ifdef __GNUC__
59#include <me_built_in.h>
60#endif
61
62// quick fix to have proper tft data port passed on
63// TODO needs to be handled in SWMIKSDK-1550
64#ifdef TFT_LCD_PORT_UNDEFINED_TEMP_FIX
65#ifndef LCD_TFT_8BIT_CH0
66#define LCD_TFT_8BIT_CH0 TFT_8BIT_DATA_PORT_CH0
67#endif
68
69#ifndef LCD_TFT_CH0_8BIT_MASK
70#define LCD_TFT_CH0_8BIT_MASK TFT_8BIT_DATA_PORT_CH0_MASK
71#endif
72
73#ifndef LCD_TFT_16BIT_CH0
74#define LCD_TFT_16BIT_CH0 TFT_16BIT_DATA_PORT_CH0
75#endif
76
77#ifndef LCD_TFT_16BIT_CH0_MASK
78#define LCD_TFT_16BIT_CH0_MASK TFT_16BIT_DATA_PORT_CH0_MASK
79#endif
80
81#ifndef LCD_TFT_16BIT_CH1
82#define LCD_TFT_16BIT_CH1 TFT_16BIT_DATA_PORT_CH1
83#endif
84
85#ifndef LCD_TFT_16BIT_CH1_MASK
86#define LCD_TFT_16BIT_CH1_MASK TFT_16BIT_DATA_PORT_CH1_MASK
87#endif
88#endif
89// eof quick fix
90
104#define set_column() uint16_t start_column = act_x1; \
105 uint16_t end_column = act_x2;
106
108#define set_page() uint16_t start_page = act_y1; \
109 uint16_t end_page = act_y2;
110
112#define CS_HIGH (digital_out_high( &pin_cs ))
114#define CS_LOW (digital_out_low( &pin_cs ))
116#define WR_HIGH (digital_out_high( &pin_wr ))
118#define WR_LOW (digital_out_low( &pin_wr ))
120#define DC_HIGH (digital_out_high( &pin_dc ))
122#define DC_LOW (digital_out_low( &pin_dc ))
124#define display_deselect() (CS_HIGH)
125
127#define check_touchpad() (void)tp_press_detect(&tp); \
128 return (tp.touch.event != TP_EVENT_PRESS_NOT_DET);
131static digital_out_t pin_cs;
133static digital_out_t pin_wr;
135static digital_out_t pin_dc;
136
138static port_t port;
139
141static gl_driver_t display_driver;
142
144static tp_drv_t tp_interface;
145static tp_t tp;
146
152static inline void write_command(uint8_t command)
153{
154 CS_LOW;
155 DC_LOW;
156 port_write(&port, command);
157 WR_LOW;
158 WR_HIGH;
159 CS_HIGH;
160}
161
167static inline void write_param(uint8_t param)
168{
169 CS_LOW;
170 DC_HIGH;
171 port_write(&port, param);
172 WR_LOW;
173 WR_HIGH;
174 CS_HIGH;
175}
176
184static inline void data_8bit_write(uint16_t fill_data)
185{
186 uint32_t red_value = RED_OF( fill_data );
187 uint32_t green_value = GREEN_OF( fill_data );
188 uint32_t blue_value = BLUE_OF( fill_data );
189
190 port_write(&port, red_value);
191 WR_LOW;
192 WR_HIGH;
193 port_write(&port, green_value);
194 WR_LOW;
195 WR_HIGH;
196 port_write(&port, blue_value);
197}
198
206static inline void write_array_data(uint16_t *array, uint16_t length)
207{
208 uint32_t i;
209
210 for (i = 0; i < length; i++)
211 {
212 data_8bit_write(*array);
213 WR_LOW;
214 WR_HIGH;
215 array++;
216 }
217}
218
224static inline void display_configure(void)
225{
226 // Initialize control pins.
227 digital_out_init(&pin_cs, TFT_CS);
228 digital_out_init(&pin_dc, TFT_RS);
229 digital_out_init(&pin_wr, TFT_WR);
230
231 // Initialize data port.
232 // Note that MikroE TFT7 boards have only 8-bit connections.
233 port_init(&port, LCD_TFT_8BIT_CH0, LCD_TFT_CH0_8BIT_MASK, PIN_DIRECTION_DIGITAL_OUTPUT);
234
235 // Initialize touch controller.
236 touch_controller_init(&display_driver, TFT_MAX_BACKLIGHT);
237
238 // Initialize driver for future use.
239 gl_set_driver(&display_driver);
240}
241
250static inline void frame_start(uint32_t start_column, uint32_t end_column,
251 uint32_t start_page, uint32_t end_page)
252{
253 write_command( ILI9341_CMD_COLUMN_ADDRESS_SET );
254 write_param( Hi( start_column ) );
255 write_param( Lo( start_column ) );
256 write_param( Hi( end_column ) );
257 write_param( Lo( end_column ) );
258
259 write_command( ILI9341_CMD_PAGE_ADDRESS_SET );
260 write_param( Hi( start_page ) );
261 write_param( Lo( start_page ) );
262 write_param( Hi( end_page ) );
263 write_param( Lo( end_page ) );
264
265 write_command( ILI9341_CMD_MEMORY_WRITE );
266
267 CS_LOW;
268 DC_HIGH;
269}
270
277static inline void get_touch_coordinates(int16_t *x, int16_t *y)
278{
279 tp_touch_coord_t touch_item;
280
281 tp_press_coordinates(&tp, &touch_item);
282
283 (*x) = touch_item.coord_x;
284 (*y) = touch_item.coord_y;
285}
286
287 // tftgroupCommon
288 // compgroup
289
290#ifdef __cplusplus
291}
292#endif
293
294#endif // _LVGL_COMMON_H_
295// ------------------------------------------------------------------------- END
API for Digital output driver.
API for GPIO port driver.
@ PIN_DIRECTION_DIGITAL_OUTPUT
Definition drv_port.h:69
err_t digital_out_init(digital_out_t *out, pin_name_t name)
Initialize GPIO pin.
void gl_set_driver(gl_driver_t *driver)
Sets the driver to the active state and enables drawing on whole display.
err_t port_init(port_t *port, port_name_t name, port_size_t mask, pin_direction_t direction)
Initialize GPIO port.
err_t port_write(port_t *port, port_size_t value)
Write to port.
#define WR_LOW
Definition lvgl_common.h:118
#define DC_HIGH
Definition lvgl_common.h:120
#define DC_LOW
Definition lvgl_common.h:122
#define CS_HIGH
Definition lvgl_common.h:112
#define WR_HIGH
Definition lvgl_common.h:116
#define CS_LOW
Definition lvgl_common.h:114
tp_err_t tp_press_coordinates(tp_t *ctx, tp_touch_item_t *touch_item)
Touch Panel Pressure Coordinates Check Function.
Digital output driver context structure, consisted of the following fields :
Definition drv_digital_out.h:73
The context structure for storing driver configuration.
Definition gl_types.h:148
Port driver context structure, consisted of the following fields :
Definition drv_port.h:82
Touch Panel Driver Interface Items.
Definition tp.h:199
Touch Panel Context Object.
Definition tp.h:224
Touch Point Object Definition.
Definition tp.h:137
tp_coord_t coord_y
Definition tp.h:139
tp_coord_t coord_x
Definition tp.h:138
Touch controller middle layer API.
void touch_controller_init(gl_driver_t *display_driver, uint8_t backlight)
Initializes touch controller.