1 /*
2  * Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
3  * Copyright (c) 2019 Nordic Semiconductor ASA
4  * Copyright (c) 2020 Teslabs Engineering S.L.
5  * Copyright (c) 2021 Krivorot Oleg <krivorot.oleg@gmail.com>
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 #ifndef ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9XXX_H_
10 #define ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9XXX_H_
11 
12 #include <drivers/gpio.h>
13 #include <drivers/spi.h>
14 #include <sys/util.h>
15 
16 /* Commands/registers. */
17 #define ILI9XXX_SWRESET 0x01
18 #define ILI9XXX_SLPOUT 0x11
19 #define ILI9XXX_DINVON 0x21
20 #define ILI9XXX_GAMSET 0x26
21 #define ILI9XXX_DISPOFF 0x28
22 #define ILI9XXX_DISPON 0x29
23 #define ILI9XXX_CASET 0x2a
24 #define ILI9XXX_PASET 0x2b
25 #define ILI9XXX_RAMWR 0x2c
26 #define ILI9XXX_MADCTL 0x36
27 #define ILI9XXX_PIXSET 0x3A
28 
29 /* MADCTL register fields. */
30 #define ILI9XXX_MADCTL_MY BIT(7U)
31 #define ILI9XXX_MADCTL_MX BIT(6U)
32 #define ILI9XXX_MADCTL_MV BIT(5U)
33 #define ILI9XXX_MADCTL_ML BIT(4U)
34 #define ILI9XXX_MADCTL_BGR BIT(3U)
35 #define ILI9XXX_MADCTL_MH BIT(2U)
36 
37 /* PIXSET register fields. */
38 #define ILI9XXX_PIXSET_RGB_18_BIT 0x60
39 #define ILI9XXX_PIXSET_RGB_16_BIT 0x50
40 #define ILI9XXX_PIXSET_MCU_18_BIT 0x06
41 #define ILI9XXX_PIXSET_MCU_16_BIT 0x05
42 
43 /** Command/data GPIO level for commands. */
44 #define ILI9XXX_CMD 1U
45 /** Command/data GPIO level for data. */
46 #define ILI9XXX_DATA 0U
47 
48 /** Sleep out time (ms), ref. 8.2.12 of ILI9XXX manual. */
49 #define ILI9XXX_SLEEP_OUT_TIME 120
50 
51 /** Reset pulse time (ms), ref 15.4 of ILI9XXX manual. */
52 #define ILI9XXX_RESET_PULSE_TIME 1
53 
54 /** Reset wait time (ms), ref 15.4 of ILI9XXX manual. */
55 #define ILI9XXX_RESET_WAIT_TIME 5
56 
57 struct ili9xxx_config {
58 	struct spi_dt_spec spi;
59 	struct gpio_dt_spec cmd_data;
60 	struct gpio_dt_spec reset;
61 	uint8_t pixel_format;
62 	uint16_t rotation;
63 	uint16_t x_resolution;
64 	uint16_t y_resolution;
65 	bool inversion;
66 	const void *regs;
67 	int (*regs_init_fn)(const struct device *dev);
68 };
69 
70 int ili9xxx_transmit(const struct device *dev, uint8_t cmd,
71 		     const void *tx_data, size_t tx_len);
72 
73 #endif /* ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9XXX_H_ */
74