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 <zephyr/drivers/gpio.h>
13 #include <zephyr/drivers/spi.h>
14 #include <zephyr/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 enum madctl_cmd_set {
58 	CMD_SET_1,	/* Default for most of ILI9xxx display controllers */
59 	CMD_SET_2,	/* Used by ILI9342c */
60 };
61 
62 struct ili9xxx_quirks {
63 	enum madctl_cmd_set cmd_set;
64 };
65 
66 struct ili9xxx_config {
67 	const struct ili9xxx_quirks *quirks;
68 
69 	struct spi_dt_spec spi;
70 	struct gpio_dt_spec cmd_data;
71 	struct gpio_dt_spec reset;
72 	uint8_t pixel_format;
73 	uint16_t rotation;
74 	uint16_t x_resolution;
75 	uint16_t y_resolution;
76 	bool inversion;
77 	const void *regs;
78 	int (*regs_init_fn)(const struct device *dev);
79 };
80 
81 int ili9xxx_transmit(const struct device *dev, uint8_t cmd,
82 		     const void *tx_data, size_t tx_len);
83 
84 #endif /* ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9XXX_H_ */
85