LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
lcd_il9163.inl
1 /*
2  MIT License
3 
4  Copyright 2019-2022 (C) Alexey Dynda
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23 */
24 /* !!! THIS FILE IS AUTO GENERATED !!! */
25 #include "lcd_hal/io.h"
26 #ifdef SDL_EMULATION
27 #include "sdl_core.h"
28 #endif
29 #include "nano_gfx_types.h"
30 
31 #ifndef CMD_ARG
32 #define CMD_ARG 0xFF
33 #endif
34 
36 {
37  lcduint_t rx = w ? (x + w - 1) : (m_base.width() - 1);
38  this->start();
39  setDataMode(0);
40  this->send(0x2A);
41  setDataMode(1); // According to datasheet all args must be passed in data mode
42  this->send(0);
43  // Take into account bug in il9163 controller
44  this->send(x + (m_rotation == 3 ? 32 : 0));
45  this->send(0);
46  this->send((rx < m_base.width() ? rx : (m_base.width() - 1)) + (m_rotation == 3 ? 32 : 0));
47  setDataMode(0);
48  this->send(0x2B);
49  setDataMode(1); // According to datasheet all args must be passed in data mode
50  this->send(0);
51  // Take into account bug in il9163 controller
52  this->send(y + (m_rotation == 2 ? 32 : 0));
53  this->send(0);
54  this->send(m_base.height() - 1 + (m_rotation == 2 ? 32 : 0));
55  setDataMode(0);
56  this->send(0x2C);
57  setDataMode(1);
58 }
59 
60 template <class I> void InterfaceIL9163<I>::nextBlock()
61 {
62 
63 }
64 
65 template <class I> void InterfaceIL9163<I>::endBlock()
66 {
67  this->stop();
68 }
69 
70 template <class I> void InterfaceIL9163<I>::setDataMode(uint8_t mode)
71 {
72  if ( m_dc >= 0 )
73  {
74  lcd_gpioWrite(m_dc, mode ? LCD_HIGH : LCD_LOW);
75  }
76 }
77 
78 template <class I> void InterfaceIL9163<I>::commandStart()
79 {
80  this->start();
81  if ( m_dc >= 0 )
82  setDataMode(0);
83  else
84  this->send(0x00);
85 }
86 
87 template <class I> void InterfaceIL9163<I>::setRotation(uint8_t rotation)
88 {
89  uint8_t ram_mode;
90  if ( (rotation ^ m_rotation) & 0x01 )
91  {
92  m_base.swapDimensions();
93  }
94  m_rotation = (rotation & 0x03);
95  this->start();
96  setDataMode(0);
97  this->send(0x28);
98  this->send(0x36);
99  setDataMode(1);
100  switch ( m_rotation )
101  {
102  case 0: // 0 degree CW
103  ram_mode = 0b00000000;
104  break;
105  case 1: // 90 degree CW
106  ram_mode = 0b01100000;
107  break;
108  case 2: // 180 degree CW
109  ram_mode = 0b11000000;
110  break;
111  default: // 270 degree CW
112  ram_mode = 0b10100000;
113  break;
114  }
115  this->send(ram_mode | m_rgb_bit);
116  setDataMode(0);
117  this->send(0x29);
118  this->stop();
119 }
120 
121 template <class I> void InterfaceIL9163<I>::normalMode()
122 {
123  this->start();
124  setDataMode(0);
125  this->send(0x20);
126  this->stop();
127 }
128 
129 template <class I> void InterfaceIL9163<I>::invertMode()
130 {
131  this->start();
132  setDataMode(0);
133  this->send(0x21);
134  this->stop();
135 }
136 
137 
139 // IL9163 basic 16-bit implementation
141 
142 template <class I> void DisplayIL9163x16<I>::beginDisplay()
143 {
144 }
145 
146 template <class I> void DisplayIL9163x16<I>::endDisplay()
147 {
148 }
149 
150 static const PROGMEM uint8_t s_IL9163_lcd128x128x16_initData[] = {
151 #ifdef SDL_EMULATION
152  SDL_LCD_IL9163, 0x00,
153  0x00, 0x00,
154 #endif
155 // 0x01, 0x00, // sw reset. not needed, we do hardware reset
156  0x11, 0x00, // exit sleep mode
157  0x3A, 0x01, 0x05, // set 16-bit pixel format
158  0x26, 0x01, 0x04, // set gamma curve: valid values 1, 2, 4, 8
159 // 0xF2, 0x01, 0x01, // enable gamma adjustment, 0 - to disable
160 // 0xE0, 15, 0x3F, 0x25, 0x1C,
161 // 0x1E, 0x20, 0x12,
162 // 0x2A, 0x90, 0x24,
163 // 0x11, 0x00, 0x00,
164 // 0x00, 0x00, 0x00, // positive gamma correction
165 // 0xE1, 15, 0x20, 0x20, 0x20,
166 // 0x20, 0x05, 0x00,
167 // 0x15, 0xA7, 0x3D,
168 // 0x18, 0x25, 0x2A,
169 // 0x2B, 0x2B, 0x3A, // negative gamma correction
170 // 0xB1, 0x02, 0x08, 0x08, // frame rate control 1, use by default
171 // 0xB4, 0x01, 0x07, // display inversion, use by default
172  0xC0, 0x02, 0x0A, 0x02, // power control 1
173  0xC1, 0x01, 0x02, // power control 2
174  0xC5, 0x02, 0x50, 0x5B, // vcom control 1
175  0xC7, 0x01, 0x40, // vcom offset
176 // 0x2A, 0x04, 0x00, 0x00, 0x00, 0x7F, // set column address, not needed.
177 // 0x2B, 0x04, 0x00, 0x00, 0x00, 0x9F, // set page address, not needed.
178  0x36, 0x01, 0b00000000, // Horizontal addressing mode
179  0x29, 0x00,
180 };
181 
183 // IL9163 basic 16-bit implementation
185 
187 {
188  ssd1306_resetController2(this->m_rstPin, 20);
189  this->m_w = 128;
190  this->m_h = 128;
191  // Give LCD some time to initialize. Refer to IL9163 datasheet
192  lcd_delay(120);
193  _configureSpiDisplay<I>(this->m_intf,
194  s_IL9163_lcd128x128x16_initData,
195  sizeof(s_IL9163_lcd128x128x16_initData));
196 
197 }
198 
200 {
201 }
202 
203 static const PROGMEM uint8_t s_IL9163_lcd128x160x16_initData[] = {
204 #ifdef SDL_EMULATION
205  SDL_LCD_IL9163, 0x00,
206  0b00000011, 0x00,
207 #endif
208 // 0x01, 0x00, // sw reset. not needed, we do hardware reset
209  0x11, 0x00, // exit sleep mode
210  0x3A, 0x01, 0x05, // set 16-bit pixel format
211  0x26, 0x01, 0x04, // set gamma curve: valid values 1, 2, 4, 8
212  0xC0, 0x02, 0x0A, 0x02, // power control 1
213  0xC1, 0x01, 0x02, // power control 2
214  0xC5, 0x02, 0x50, 0x5B, // vcom control 1
215  0xC7, 0x01, 0x40, // vcom offset
216  0x36, 0x01, 0b00000000, // Horizontal addressing mode
217  0x29, 0x00
218 };
219 
221 // IL9163 basic 16-bit implementation
223 
225 {
226  ssd1306_resetController2(this->m_rstPin, 20);
227  this->m_w = 128;
228  this->m_h = 160;
229  // Give LCD some time to initialize. Refer to IL9163 datasheet
230  lcd_delay(120);
231  _configureSpiDisplay<I>(this->m_intf,
232  s_IL9163_lcd128x160x16_initData,
233  sizeof(s_IL9163_lcd128x160x16_initData));
234 
235 }
236 
238 {
239 }
void beginController()
Basic IL9163 128x160x16 initialization.
Definition: lcd_il9163.inl:224
uint8_t lcduint_t
internal int type, used by the library.
Definition: canvas_types.h:79
void invertMode()
Switches display to inverted mode (sends INVON command).
Definition: lcd_il9163.inl:129
void lcd_gpioWrite(int pin, int level)
Writes value to gpio.
void endController()
Basic IL9163 deinitialization.
Definition: lcd_il9163.inl:237
void setDataMode(uint8_t mode)
Enables either data or command mode on SPI bus.
Definition: lcd_il9163.inl:70
SSD1306 HAL IO communication functions.
void ssd1306_resetController2(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
void setRotation(uint8_t rotation)
Sets screen orientation (rotation)
Definition: lcd_il9163.inl:87
void commandStart()
Starts communication with LCD display in command mode.
Definition: lcd_il9163.inl:78
void endBlock()
Closes data send operation to lcd display.
Definition: lcd_il9163.inl:65
void beginDisplay()
Basic IL9163 initialization.
Definition: lcd_il9163.inl:142
#define LCD_LOW
Constant corresponds to low level of gpio pin.
Definition: io.h:175
Basic structures of nano gfx library.
void startBlock(lcduint_t x, lcduint_t y, lcduint_t w)
Sets block in RAM of lcd display controller to write data to.
Definition: lcd_il9163.inl:35
void endDisplay()
Basic IL9163 deinitialization.
Definition: lcd_il9163.inl:146
void beginController()
Basic IL9163 128x128x16 initialization.
Definition: lcd_il9163.inl:186
void nextBlock()
Switches to the start of next RAM page for the block, specified by startBlock().
Definition: lcd_il9163.inl:60
void endController()
Basic IL9163 deinitialization.
Definition: lcd_il9163.inl:199
#define LCD_HIGH
Constant corresponds to high level of gpio pin.
Definition: io.h:177
void lcd_delay(unsigned long ms)
Forces current thread to sleeps for specified number of milliseconds.
void normalMode()
Switches display to normal (non-inverted) mode (sends INVOFF command).
Definition: lcd_il9163.inl:121