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 
148 // SSD1351 basic 16-bit implementation
150 
151 template <class I> void DisplaySSD1351x16<I>::beginDisplay()
152 {
153 }
154 
155 template <class I> void DisplaySSD1351x16<I>::endDisplay()
156 {
157 }
158 
159 static const PROGMEM uint8_t s_SSD1351_lcd128x128x16_initData[] = {
160 #ifdef SDL_EMULATION
161  SDL_LCD_SSD1351, 0x00,
162  0x00, 0x00,
163 #endif
164  0xFD, 0x01, 0x12, // Unlock
165  0xFD, 0x01, 0xB1, // Unlock
166  0xAE, 0x00, // SLEEP_ON
167  0xB3, 0x01, 0xF1, // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
168  0xCA, 0x01, 127, // Reset to default MUX. See datasheet
169  0xA0, 0x01, 0B00110100, // 16-bit rgb color mode
170  0xA1, 0x01, 0x00, // First line to start scanning from
171  0xA2, 0x01, 0x00, // Set display offset
172  0xB5, 0x01, 0x00, // GPIO OFF
173  0xAB, 0x01, 0x01, // Set function
174  0xB1, 0x01, 0x32, // Phase 1 and Phase 2 periods
175  0xBE, 0x01, 0x05, // Precharge
176  0xBB, 0x01, 0x17, // Precharge level
177  0xA6, 0x00, // Normal display
178  0xC1, 0x03, 0xC8, 0x80, 0xC8, // Contrast RED, GREEN, BLUE
179  0xC7, 0x01, 0x0F, // Master current
180  0xB4, 0x03, 0xA0, 0xB5, 0x55, // External VSL
181  0xB6, 0x01, 0x01, // Precharge second
182  0xAF, 0x01, // Disable power-safe mode
183  0xA6, 0x00, // Normal display
184 };
185 
187 // SSD1351 basic 16-bit implementation
189 
191 {
192  ssd1306_resetController2(this->m_rstPin, 20);
193  this->m_w = 128;
194  this->m_h = 128;
195  // Give LCD some time to initialize. Refer to SSD1351 datasheet
196  lcd_delay(0);
197  _configureSpiDisplay<I>(this->m_intf,
198  s_SSD1351_lcd128x128x16_initData,
199  sizeof(s_SSD1351_lcd128x128x16_initData));
200 
201 }
202 
204 {
205 }
206 
207 static const PROGMEM uint8_t s_SSD1351_lcd96x96x16_initData[] = {
208 #ifdef SDL_EMULATION
209  SDL_LCD_SSD1351, 0x00,
210  0x00, 0x00,
211 #endif
212  0xFD, 0x01, 0x12, // Unlock
213  0xFD, 0x01, 0xB1, // Unlock
214  0xAE, 0x00, // SLEEP_ON
215  0xB3, 0x01, 0xF1, // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
216  0xCA, 0x01, 127, // Reset to default MUX. See datasheet
217  0xA0, 0x01, 0B00110100, // 16-bit rgb color mode
218  0xA1, 0x01, 0x00, // First line to start scanning from
219  0xA2, 0x01, 0x10, // Set display offset
220  0xB5, 0x01, 0x00, // GPIO OFF
221  0xAB, 0x01, 0x01, // Set function
222  0xB1, 0x01, 0x32, // Phase 1 and Phase 2 periods
223  0xBE, 0x01, 0x05, // Precharge
224  0xBB, 0x01, 0x17, // Precharge level
225  0xA6, 0x00, // Normal display
226  0xC1, 0x03, 0x42, 0x3C, 0x6B, // Contrast RED, GREEN, BLUE
227  0xC7, 0x01, 0x0C, // Master current
228  0xB4, 0x03, 0xA0, 0xB5, 0x55, // External VSL
229  0xB6, 0x01, 0x01, // Precharge second
230  0xAF, 0x01, // Disable power-safe mode
231  0xA6, 0x00, // Normal display
232 };
233 
235 // SSD1351 basic 16-bit implementation
237 
239 {
240  ssd1306_resetController2(this->m_rstPin, 20);
241  this->m_w = 96;
242  this->m_h = 96;
243  // Give LCD some time to initialize. Refer to SSD1351 datasheet
244  lcd_delay(0);
245  _configureSpiDisplay<I>(this->m_intf,
246  s_SSD1351_lcd96x96x16_initData,
247  sizeof(s_SSD1351_lcd96x96x16_initData));
248 
249 }
250 
252 {
253 }
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 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)