LCDGFX LCD display driver  1.1.5
This library is developed to control SSD1306/SSD1325/SSD1327/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
lcd_ssd1351.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  commandStart();
39  this->send((m_rotation & 0x01) ? 0x75 : 0x15);
40  setDataMode(1); // According to datasheet all args must be passed in data mode
41  this->send(x + m_offset_x);
42  this->send( (rx < m_base.width() ? rx : (m_base.width() - 1)) + m_offset_x);
43  setDataMode(0);
44  this->send((m_rotation & 0x01) ? 0x15 : 0x75);
45  setDataMode(1); // According to datasheet all args must be passed in data mode
46  this->send( y + m_offset_y );
47  this->send( m_base.height() - 1 + m_offset_y);
48  setDataMode(0);
49  this->send(0x5C);
50  if ( m_dc >= 0 )
51  {
52  setDataMode(1);
53  }
54  else
55  {
56  this->stop();
57  this->start();
58  this->send(0x40);
59  }
60 }
61 
62 template <class I> void InterfaceSSD1351<I>::nextBlock()
63 {
64 
65 }
66 
67 template <class I> void InterfaceSSD1351<I>::endBlock()
68 {
69  this->stop();
70 }
71 
72 template <class I> void InterfaceSSD1351<I>::setDataMode(uint8_t mode)
73 {
74  if ( m_dc >= 0 )
75  {
76  lcd_gpioWrite(m_dc, mode ? LCD_HIGH : LCD_LOW);
77  }
78 }
79 
80 template <class I> void InterfaceSSD1351<I>::commandStart()
81 {
82  this->start();
83  if ( m_dc >= 0 )
84  setDataMode(0);
85  else
86  this->send(0x00);
87 }
88 
89 template <class I> void InterfaceSSD1351<I>::setRotation(uint8_t rotation)
90 {
91  uint8_t ram_mode;
92  if ( (rotation ^ m_rotation) & 0x01 )
93  {
94  m_base.swapDimensions();
95  lcduint_t temp = m_offset_x;
96  m_offset_x = m_offset_y;
97  m_offset_y = temp;
98  }
99  m_rotation = (rotation & 0x03);
100  this->start();
101  setDataMode(0);
102  this->send( 0xA0 );
103  switch ( m_rotation )
104  {
105  // NORMAL FULL COLOR MODE
106  case 0: // 0 degree CW
107  ram_mode = 0b00110000;
108  break;
109  case 1: // 90 degree CW
110  ram_mode = 0b00110011;
111  break;
112  case 2: // 180 degree CW
113  ram_mode = 0B00100010;
114  break;
115  case 3: // 270 degree CW
116  default:
117  ram_mode = 0b00100001;
118  break;
119  }
120  setDataMode(1); // According to datasheet all args must be passed in data mode
121  this->send( ram_mode | m_rgbMode );
122  this->stop();
123 
124 }
125 
126 template <class I> void InterfaceSSD1351<I>::setOffset(lcdint_t ox, lcdint_t oy)
127 {
128  if (m_rotation & 0x01)
129  {
130  m_offset_x = oy;
131  m_offset_y = ox;
132  }
133  else
134  {
135  m_offset_x = ox;
136  m_offset_y = oy;
137  }
138 }
139 
140 template <class I> void InterfaceSSD1351<I>::setRgbMode(uint8_t mode)
141 {
142  this->m_rgbMode = mode ? 0x04: 0x00;
143  this->setRotation( m_rotation );
144 }
145 
146 template <class I> void InterfaceSSD1351<I>::setContrast(uint8_t contrast)
147 {
148  commandStart();
149  this->send(0xC1); // set contrast for RGB
150  this->send(contrast);
151  this->send(contrast);
152  this->send(contrast);
153  this->stop();
154 }
155 
156 
158 // SSD1351 basic 16-bit implementation
160 
161 template <class I> void DisplaySSD1351x16<I>::beginDisplay()
162 {
163 }
164 
165 template <class I> void DisplaySSD1351x16<I>::endDisplay()
166 {
167 }
168 
169 static const PROGMEM uint8_t s_SSD1351_lcd128x128x16_initData[] = {
170 #ifdef SDL_EMULATION
171  SDL_LCD_SSD1351, 0x00,
172  0x00, 0x00,
173 #endif
174  0xFD, 0x01, 0x12, // Unlock
175  0xFD, 0x01, 0xB1, // Unlock
176  0xAE, 0x00, // SLEEP_ON
177  0xB3, 0x01, 0xF1, // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
178  0xCA, 0x01, 127, // Reset to default MUX. See datasheet
179  0xA0, 0x01, 0B00110100, // 16-bit rgb color mode
180  0xA1, 0x01, 0x00, // First line to start scanning from
181  0xA2, 0x01, 0x00, // Set display offset
182  0xB5, 0x01, 0x00, // GPIO OFF
183  0xAB, 0x01, 0x01, // Set function
184  0xB1, 0x01, 0x32, // Phase 1 and Phase 2 periods
185  0xBE, 0x01, 0x05, // Precharge
186  0xBB, 0x01, 0x17, // Precharge level
187  0xA6, 0x00, // Normal display
188  0xC1, 0x03, 0xC8, 0x80, 0xC8, // Contrast RED, GREEN, BLUE
189  0xC7, 0x01, 0x0F, // Master current
190  0xB4, 0x03, 0xA0, 0xB5, 0x55, // External VSL
191  0xB6, 0x01, 0x01, // Precharge second
192  0xAF, 0x01, // Disable power-safe mode
193  0xA6, 0x00, // Normal display
194 };
195 
197 // SSD1351 basic 16-bit implementation
199 
201 {
202  ssd1306_resetController2(this->m_rstPin, 20);
203  this->m_w = 128;
204  this->m_h = 128;
205  // Give LCD some time to initialize. Refer to SSD1351 datasheet
206  lcd_delay(0);
207  _configureSpiDisplay<I>(this->m_intf,
208  s_SSD1351_lcd128x128x16_initData,
209  sizeof(s_SSD1351_lcd128x128x16_initData));
210 
211 }
212 
214 {
215 }
216 
217 static const PROGMEM uint8_t s_SSD1351_lcd96x96x16_initData[] = {
218 #ifdef SDL_EMULATION
219  SDL_LCD_SSD1351, 0x00,
220  0x00, 0x00,
221 #endif
222  0xFD, 0x01, 0x12, // Unlock
223  0xFD, 0x01, 0xB1, // Unlock
224  0xAE, 0x00, // SLEEP_ON
225  0xB3, 0x01, 0xF1, // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
226  0xCA, 0x01, 127, // Reset to default MUX. See datasheet
227  0xA0, 0x01, 0B00110100, // 16-bit rgb color mode
228  0xA1, 0x01, 0x00, // First line to start scanning from
229  0xA2, 0x01, 0x10, // Set display offset
230  0xB5, 0x01, 0x00, // GPIO OFF
231  0xAB, 0x01, 0x01, // Set function
232  0xB1, 0x01, 0x32, // Phase 1 and Phase 2 periods
233  0xBE, 0x01, 0x05, // Precharge
234  0xBB, 0x01, 0x17, // Precharge level
235  0xA6, 0x00, // Normal display
236  0xC1, 0x03, 0x42, 0x3C, 0x6B, // Contrast RED, GREEN, BLUE
237  0xC7, 0x01, 0x0C, // Master current
238  0xB4, 0x03, 0xA0, 0xB5, 0x55, // External VSL
239  0xB6, 0x01, 0x01, // Precharge second
240  0xAF, 0x01, // Disable power-safe mode
241  0xA6, 0x00, // Normal display
242 };
243 
245 // SSD1351 basic 16-bit implementation
247 
249 {
250  ssd1306_resetController2(this->m_rstPin, 20);
251  this->m_w = 96;
252  this->m_h = 96;
253  // Give LCD some time to initialize. Refer to SSD1351 datasheet
254  lcd_delay(0);
255  _configureSpiDisplay<I>(this->m_intf,
256  s_SSD1351_lcd96x96x16_initData,
257  sizeof(s_SSD1351_lcd96x96x16_initData));
258 
259 }
260 
262 {
263 }
void setRotation(uint8_t rotation)
Sets screen orientation (rotation)
Definition: lcd_ssd1351.inl:89
void setRgbMode(uint8_t mode)
Sets RGB mode used by dispay controller.
uint8_t lcduint_t
Definition: canvas_types.h:79
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_ssd1351.inl:35
void lcd_gpioWrite(int pin, int level)
int8_t lcdint_t
Definition: canvas_types.h:77
void ssd1306_resetController2(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
#define LCD_LOW
Definition: io.h:175
void setDataMode(uint8_t mode)
Definition: lcd_ssd1351.inl:72
void setContrast(uint8_t contrast)
void setOffset(lcdint_t ox, lcdint_t oy)
Sets display offset in GDRAM memory.
#define LCD_HIGH
Definition: io.h:177
void lcd_delay(unsigned long ms)