1
1
/*
2
2
* Copyright (C) 2018 Koen Zandberg
3
+ * 2023 Gunar Schorcht
3
4
*
4
5
* This file is subject to the terms and conditions of the GNU Lesser
5
6
* General Public License v2.1. See the file LICENSE in the top level
14
15
* @brief Device driver implementation for the ili9341 display controller
15
16
*
16
17
* @author Koen Zandberg <[email protected] >
18
+ * @author Gunar Schorcht <[email protected] >
17
19
*
18
20
* @}
19
21
*/
22
24
#include <string.h>
23
25
#include "byteorder.h"
24
26
#include "periph/spi.h"
25
- #include "ztimer.h"
26
27
#include "kernel_defines.h"
28
+ #include "ztimer.h"
27
29
28
30
#include "ili9341.h"
29
31
#include "ili9341_internal.h"
33
35
#define ENABLE_DEBUG 0
34
36
#include "debug.h"
35
37
36
- static void _write_cmd (const lcd_t * dev , uint8_t cmd , const uint8_t * data ,
37
- size_t len )
38
- {
39
- gpio_clear (dev -> params -> dcx_pin );
40
- spi_transfer_byte (dev -> params -> spi , dev -> params -> cs_pin , len ? true : false, cmd );
41
- gpio_set (dev -> params -> dcx_pin );
42
- if (len ) {
43
- spi_transfer_bytes (dev -> params -> spi , dev -> params -> cs_pin , false, data ,
44
- NULL , len );
45
- }
46
- }
47
-
48
38
/* datasheet page 178, table converted to equation.
49
39
* gvdd in 1mv increments: 4850 = 4.85V */
50
40
static uint8_t _ili9341_calc_pwrctl1 (uint16_t gvdd )
@@ -66,125 +56,92 @@ static uint8_t _ili9341_calc_vml(int16_t vcoml)
66
56
static int _init (lcd_t * dev , const lcd_params_t * params )
67
57
{
68
58
assert (params -> lines >= 16 && params -> lines <= 320 && !(params -> lines & 0x7 ));
69
- dev -> params = params ;
70
- uint8_t command_params [4 ] = { 0 };
71
- gpio_init (dev -> params -> dcx_pin , GPIO_OUT );
72
- int res = spi_init_cs (dev -> params -> spi , dev -> params -> cs_pin );
73
- if (res != SPI_OK ) {
74
- DEBUG ("[ili9341] init: error initializing the CS pin [%i]\n" , res );
75
- return -1 ;
76
- }
77
59
78
- if (gpio_is_valid (dev -> params -> rst_pin )) {
79
- gpio_init (dev -> params -> rst_pin , GPIO_OUT );
80
- gpio_clear (dev -> params -> rst_pin );
81
- ztimer_sleep (ZTIMER_MSEC , 120 );
82
- gpio_set (dev -> params -> rst_pin );
83
- }
84
- ztimer_sleep (ZTIMER_MSEC , 120 );
60
+ uint8_t command_params [4 ] = { 0 };
85
61
86
62
/* Acquire once at release at the end */
87
- spi_acquire (dev -> params -> spi , dev -> params -> cs_pin , dev -> params -> spi_mode ,
88
- dev -> params -> spi_clk );
63
+ lcd_ll_acquire (dev );
89
64
90
65
/* Soft Reset */
91
- _write_cmd (dev , LCD_CMD_SWRESET , NULL , 0 );
66
+ lcd_ll_write_cmd (dev , LCD_CMD_SWRESET , NULL , 0 );
92
67
ztimer_sleep (ZTIMER_MSEC , 120 );
93
68
94
69
/* Display off */
95
- _write_cmd (dev , LCD_CMD_DISPOFF , NULL , 0 );
70
+ lcd_ll_write_cmd (dev , LCD_CMD_DISPOFF , NULL , 0 );
96
71
97
72
/* PWRCTL1/2 */
98
73
command_params [0 ] = _ili9341_calc_pwrctl1 (CONFIG_ILI9341_GVDD );
99
- _write_cmd (dev , LCD_CMD_PWCTRL1 , command_params , 1 );
74
+ lcd_ll_write_cmd (dev , LCD_CMD_PWCTRL1 , command_params , 1 );
100
75
101
76
command_params [0 ] = 0x10 ; /* PWRCTL 0 0 0 */
102
- _write_cmd (dev , LCD_CMD_PWCTRL2 , command_params , 1 );
77
+ lcd_ll_write_cmd (dev , LCD_CMD_PWCTRL2 , command_params , 1 );
103
78
104
79
/* VCOMCTL */
105
80
command_params [0 ] = _ili9341_calc_vmh (CONFIG_ILI9341_VCOMH );
106
81
command_params [1 ] = _ili9341_calc_vml (CONFIG_ILI9341_VCOML );
107
- _write_cmd (dev , LCD_CMD_VMCTRL1 , command_params , 2 );
82
+ lcd_ll_write_cmd (dev , LCD_CMD_VMCTRL1 , command_params , 2 );
108
83
109
84
command_params [0 ] = 0x86 ;
110
- _write_cmd (dev , LCD_CMD_VMCTRL2 , command_params , 1 );
85
+ lcd_ll_write_cmd (dev , LCD_CMD_VMCTRL2 , command_params , 1 );
111
86
112
87
/* Memory access CTL */
113
88
command_params [0 ] = dev -> params -> rotation ;
114
89
command_params [0 ] |= dev -> params -> rgb ? 0 : LCD_MADCTL_BGR ;
115
- _write_cmd (dev , LCD_CMD_MADCTL , command_params , 1 );
90
+ lcd_ll_write_cmd (dev , LCD_CMD_MADCTL , command_params , 1 );
116
91
117
92
/* Frame control */
118
93
command_params [0 ] = 0x00 ;
119
94
command_params [1 ] = 0x18 ;
120
- _write_cmd (dev , LCD_CMD_FRAMECTL1 , command_params , 2 );
95
+ lcd_ll_write_cmd (dev , LCD_CMD_FRAMECTL1 , command_params , 2 );
121
96
122
97
/* Display function control */
123
98
command_params [0 ] = 0x08 ;
124
99
command_params [1 ] = 0x82 ;
125
100
/* number of lines, see datasheet p. 166 (DISCTRL::NL) */
126
101
command_params [2 ] = (params -> lines >> 3 ) - 1 ;
127
- _write_cmd (dev , LCD_CMD_DFUNC , command_params , 3 );
102
+ lcd_ll_write_cmd (dev , LCD_CMD_DFUNC , command_params , 3 );
128
103
129
104
/* Pixel format */
130
105
command_params [0 ] = 0x55 ; /* 16 bit mode */
131
- _write_cmd (dev , LCD_CMD_PIXSET , command_params , 1 );
106
+ lcd_ll_write_cmd (dev , LCD_CMD_PIXSET , command_params , 1 );
132
107
133
108
command_params [0 ] = 0x01 ;
134
- _write_cmd (dev , LCD_CMD_GAMSET , command_params , 1 );
109
+ lcd_ll_write_cmd (dev , LCD_CMD_GAMSET , command_params , 1 );
135
110
136
111
/* Gamma correction */
137
112
{
138
113
static const uint8_t gamma_pos [] = {
139
114
0x0F , 0x31 , 0x2B , 0x0C , 0x0E , 0x08 , 0x4E , 0xF1 ,
140
115
0x37 , 0x07 , 0x10 , 0x03 , 0x0E , 0x09 , 0x00
141
116
};
142
- _write_cmd (dev , LCD_CMD_PGAMCTRL , gamma_pos ,
143
- sizeof (gamma_pos ));
117
+ lcd_ll_write_cmd (dev , LCD_CMD_PGAMCTRL , gamma_pos ,
118
+ sizeof (gamma_pos ));
144
119
}
145
120
{
146
121
static const uint8_t gamma_neg [] = {
147
122
0x00 , 0x0E , 0x14 , 0x03 , 0x11 , 0x07 , 0x31 , 0xC1 ,
148
123
0x48 , 0x08 , 0x0F , 0x0C , 0x31 , 0x36 , 0x0F
149
124
};
150
- _write_cmd (dev , LCD_CMD_NGAMCTRL , gamma_neg ,
151
- sizeof (gamma_neg ));
125
+ lcd_ll_write_cmd (dev , LCD_CMD_NGAMCTRL , gamma_neg ,
126
+ sizeof (gamma_neg ));
152
127
153
128
}
154
129
155
130
if (dev -> params -> inverted ) {
156
- _write_cmd (dev , LCD_CMD_DINVON , NULL , 0 );
131
+ lcd_ll_write_cmd (dev , LCD_CMD_DINVON , NULL , 0 );
157
132
}
158
133
/* Sleep out (turn off sleep mode) */
159
- _write_cmd (dev , LCD_CMD_SLPOUT , NULL , 0 );
134
+ lcd_ll_write_cmd (dev , LCD_CMD_SLPOUT , NULL , 0 );
160
135
/* Display on */
161
- _write_cmd (dev , LCD_CMD_DISPON , NULL , 0 );
162
- spi_release (dev -> params -> spi );
163
- return 0 ;
164
- }
136
+ lcd_ll_write_cmd (dev , LCD_CMD_DISPON , NULL , 0 );
165
137
166
- static void _set_area (const lcd_t * dev , uint16_t x1 , uint16_t x2 ,
167
- uint16_t y1 , uint16_t y2 )
168
- {
169
- be_uint16_t params [2 ];
170
-
171
- x1 += dev -> params -> offset_x ;
172
- x2 += dev -> params -> offset_x ;
173
- y1 += dev -> params -> offset_y ;
174
- y2 += dev -> params -> offset_y ;
175
-
176
- params [0 ] = byteorder_htons (x1 );
177
- params [1 ] = byteorder_htons (x2 );
178
-
179
- _write_cmd (dev , LCD_CMD_CASET , (uint8_t * )params ,
180
- sizeof (params ));
181
- params [0 ] = byteorder_htons (y1 );
182
- params [1 ] = byteorder_htons (y2 );
183
- _write_cmd (dev , LCD_CMD_PASET , (uint8_t * )params ,
184
- sizeof (params ));
138
+ /* Finally release the device */
139
+ lcd_ll_release (dev );
140
+
141
+ return 0 ;
185
142
}
186
143
187
144
const lcd_driver_t lcd_ili9341_driver = {
188
145
.init = _init ,
189
- .set_area = _set_area ,
146
+ .set_area = NULL , /* default implementation is used */
190
147
};
0 commit comments