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_ssd1331.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  uint8_t rx = w ? (x + w - 1) : (m_base.width() - 1);
38  this->start();
39  setDataMode(0);
40  this->send((m_rotation & 1) ? 0x75: 0x15);
41  this->send(x);
42  this->send(rx < m_base.width() ? rx : (m_base.width() - 1));
43  this->send((m_rotation & 1) ? 0x15: 0x75);
44  this->send(y);
45  this->send(m_base.height() - 1);
46  setDataMode(1);
47 }
48 
49 template <class I> void InterfaceSSD1331<I>::nextBlock()
50 {
51 
52 }
53 
54 template <class I> void InterfaceSSD1331<I>::endBlock()
55 {
56  this->stop();
57 }
58 
59 template <class I> void InterfaceSSD1331<I>::setDataMode(uint8_t mode)
60 {
61  if ( m_dc >= 0 )
62  {
63  lcd_gpioWrite(m_dc, mode ? LCD_HIGH : LCD_LOW);
64  }
65 }
66 
67 template <class I> void InterfaceSSD1331<I>::commandStart()
68 {
69  this->start();
70  if ( m_dc >= 0 )
71  setDataMode(0);
72  else
73  this->send(0x00);
74 }
75 
76 template <class I> void InterfaceSSD1331<I>::setRotation(uint8_t rotation)
77 {
78  uint8_t ram_mode;
79  if ( (rotation ^ m_rotation) & 0x01 )
80  {
81  m_base.swapDimensions();
82  }
83  m_rotation = rotation & 0x03;
84  this->start();
85  setDataMode(0);
86  this->send( 0xA0 );
87  switch ( m_rotation )
88  {
89  // NORMAL FULL COLOR MODE
90  case 0: // 0 degree CW
91  ram_mode = 0b00110010;
92  break;
93  case 1: // 90 degree CW
94  ram_mode = 0b00110001;
95  break;
96  case 2: // 180 degree CW
97  ram_mode = 0b00100000;
98  break;
99  case 3: // 270 degree CW
100  default:
101  ram_mode = 0b00100011;
102  break;
103  }
104  this->send( ram_mode | (m_bits == 16 ? 0x40: 0x00) );
105  this->stop();
106 }
107 
108 template <class I> void InterfaceSSD1331<I>::drawLine(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2, uint16_t color)
109 {
110  this->start();
111  setDataMode(0);
112  this->send( 0x21 );
113  this->send(x1);
114  this->send(y1);
115  this->send(x2);
116  this->send(y2);
117  this->send( (color & 0xF800) >> 10 );
118  this->send( (color & 0x07E0) >> 5 );
119  this->send( (color & 0x001F) << 1 );
120  this->stop();
121 }
122 
123 template <class I> void InterfaceSSD1331<I>::copyBlock(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t newLeft, uint8_t newTop)
124 {
125  this->start();
126  setDataMode(0);
127  this->send(0x23);
128  this->send(left);
129  this->send(top);
130  this->send(right);
131  this->send(bottom);
132  this->send(newLeft);
133  this->send(newTop);
134  this->stop();
135 }
136 
137 template <class I> void InterfaceSSD1331<I>::setContrast(uint8_t contrast)
138 {
139  commandStart();
140  this->send(0x81); // set contrast for Color A (Red)
141  this->send(contrast);
142  this->send(0x82); // set contrast for Color B (Green)
143  this->send(contrast);
144  this->send(0x83); // set contrast for Color C (Blue)
145  this->send(contrast);
146  this->stop();
147 }
148 
149 
151 // SSD1331 basic 8-bit implementation
153 
154 template <class I> void DisplaySSD1331x8<I>::beginDisplay()
155 {
156 }
157 
158 template <class I> void DisplaySSD1331x8<I>::endDisplay()
159 {
160 }
161 
162 static const PROGMEM uint8_t s_SSD1331_lcd96x64x8_initData[] = {
163 #ifdef SDL_EMULATION
164  SDL_LCD_SSD1331_X8, 0x00,
165  0x00, 0x00,
166 #endif
167  0xAE, 0x00, // display off
168  0xA0, 0x01, 0x20 | 0x10 | 0x02, /* 8-bit rgb color mode */
169  0xA1, 0x01, 0x00, // First line to start scanning from
170  0xA2, 0x01, 0x00, // Set display offset
171  0xA4, 0x00, // Normal display
172  0xA8, 0x01, 63, // Reset to default MUX. See datasheet
173  0xAD, 0x01, 0x8E, // Set master mode
174  0xB0, 0x01, 0x0B, // Disable power-safe mode
175  0xB1, 0x01, 0x31, // Precharge Phase 1 and Phase 2 periods
176  0xB3, 0x01, 0xF0, // CLOCKDIV 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
177  0x8A, 0x01, 0x64, // Precharge A
178  0x8B, 0x01, 0x78, // Precharge B
179  0xBB, 0x01, 0x3A, // Precharge level
180  0xBE, 0x01, 0x3E, // VCOM
181  0x87, 0x01, 0x09, // Master current
182  0x81, 0x01, 0x91, // RED
183  0x82, 0x01, 0x50, // GREEN
184  0x83, 0x01, 0x7D, // BLUE
185  0xAF, 0x00,
186 };
187 
189 // SSD1331 basic 8-bit implementation
191 
193 {
194  ssd1306_resetController2(this->m_rstPin, 10);
195  this->m_w = 96;
196  this->m_h = 64;
197  // Give LCD some time to initialize. Refer to SSD1331 datasheet
198  lcd_delay(0);
199  _configureSpiDisplayCmdModeOnly<I>(this->m_intf,
200  s_SSD1331_lcd96x64x8_initData,
201  sizeof(s_SSD1331_lcd96x64x8_initData));
202 
203 }
204 
206 {
207 }
209 // SSD1331 basic 16-bit implementation
211 
212 template <class I> void DisplaySSD1331x16<I>::beginDisplay()
213 {
214 }
215 
216 template <class I> void DisplaySSD1331x16<I>::endDisplay()
217 {
218 }
219 
220 static const PROGMEM uint8_t s_SSD1331_lcd96x64x16_initData[] = {
221 #ifdef SDL_EMULATION
222  SDL_LCD_SSD1331_X16, 0x00,
223  0x00, 0x00,
224 #endif
225  0xAE, 0x00, // display off
226  0xA0, 0x01, 0x40 | 0x20 | 0x10 | 0x02, /* 16-bit rgb color mode */
227  0xA1, 0x01, 0x00, // First line to start scanning from
228  0xA2, 0x01, 0x00, // Set display offset
229  0xA4, 0x00, // Normal display
230  0xA8, 0x01, 63, // Reset to default MUX. See datasheet
231  0xAD, 0x01, 0x8E, // Set master mode
232  0xB0, 0x01, 0x0B, // Disable power-safe mode
233  0xB1, 0x01, 0x31, // Phase 1 and Phase 2 periods
234  0xB3, 0x01, 0xF0, // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
235  0x8A, 0x01, 0x64, // Precharge A
236  0x8B, 0x01, 0x78, // Precharge B
237  0xBB, 0x01, 0x3A, // Precharge level
238  0xBE, 0x01, 0x3E, // VCOM
239  0x87, 0x01, 0x09, // Master current
240  0x81, 0x01, 0x91, // RED
241  0x82, 0x01, 0x50, // GREEN
242  0x83, 0x01, 0x7D, // BLUE
243  0xAF, 0x00,
244 };
245 
247 // SSD1331 basic 16-bit implementation
249 
251 {
252  ssd1306_resetController2(this->m_rstPin, 10);
253  this->m_w = 96;
254  this->m_h = 64;
255  // Give LCD some time to initialize. Refer to SSD1331 datasheet
256  lcd_delay(0);
257  _configureSpiDisplayCmdModeOnly<I>(this->m_intf,
258  s_SSD1331_lcd96x64x16_initData,
259  sizeof(s_SSD1331_lcd96x64x16_initData));
260 
261 }
262 
264 {
265 }
uint8_t lcduint_t
Definition: canvas_types.h:79
void lcd_gpioWrite(int pin, int level)
void setContrast(uint8_t contrast)
void copyBlock(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t newLeft, uint8_t newTop)
int8_t lcdint_t
Definition: canvas_types.h:77
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_ssd1331.inl:76
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_ssd1331.inl:35
void drawLine(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2, uint16_t color)
#define LCD_LOW
Definition: io.h:175
void setDataMode(uint8_t mode)
Definition: lcd_ssd1331.inl:59
#define LCD_HIGH
Definition: io.h:177
void lcd_delay(unsigned long ms)