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