SSD1306 OLED display driver 1.7.8 This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays

lcd_common.h
Go to the documentation of this file.
1 /*
2 MIT License
3
4 Copyright (c) 2017-2018, 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 */
28 #ifndef _LCD_COMMON_H_
29 #define _LCD_COMMON_H_
30
31 #include "ssd1306_hal/io.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
50 typedef enum
51 {
53 LCD_TYPE_SSD1306,
55 LCD_TYPE_PCD8544,
57 LCD_TYPE_SH1106,
59 LCD_TYPE_SSD1331,
61 LCD_TYPE_CUSTOM,
62 } lcd_type_t;
63
69 typedef enum
70 {
75 LCD_MODE_NORMAL = 0,
76
82 LCD_MODE_SSD1306_COMPAT = 1,
83 } lcd_mode_t;
84
88 typedef struct
89 {
91 lcd_type_t type;
92
94 lcduint_t width;
95
97 lcduint_t height;
98
114 void (*set_block)(lcduint_t x, lcduint_t y, lcduint_t w);
115
122 void (*next_page)(void);
123
128 void (*send_pixels1)(uint8_t data);
129
135 void (*send_pixels_buffer1)(const uint8_t *buffer, uint16_t len);
136
142 void (*send_pixels8)(uint8_t data);
143
157 void (*set_mode)(lcd_mode_t mode);
158 } ssd1306_lcd_t;
159
163 extern ssd1306_lcd_t ssd1306_lcd;
164
169 #define s_displayHeight ssd1306_lcd.height
170
175 #define s_displayWidth ssd1306_lcd.width
176
181 #define g_lcd_type ssd1306_lcd.type
182
190 void ssd1306_sendData(uint8_t data) __attribute__ ((deprecated));
191
208 #define ssd1306_setRamBlock ssd1306_lcd.set_block
209
217 #define ssd1306_nextRamPage ssd1306_lcd.next_page
218
224 #define ssd1306_sendPixels ssd1306_lcd.send_pixels1
225
232 #define ssd1306_sendPixelsBuffer ssd1306_lcd.send_pixels_buffer1
233
240 #define ssd1306_sendPixel8 ssd1306_lcd.send_pixels8
241
253 void ssd1306_configureI2cDisplay(const uint8_t *config, uint8_t configSize);
254
268 void ssd1306_configureSpiDisplay(const uint8_t *config, uint8_t configSize);
269
283 void ssd1306_setMode(lcd_mode_t mode);
284
295 void ssd1306_resetController(int8_t rstPin, uint8_t delayMs);
296
309 #define SSD1306_COMPAT_SPI_BLOCK_8BIT_CMDS(column_cmd, row_cmd) \
310 static uint8_t __s_column; \
311 static uint8_t __s_page; \
312 static void set_block_compat(lcduint_t x, lcduint_t y, lcduint_t w) \
313 { \
314 uint8_t rx = w ? (x + w - 1) : (ssd1306_lcd.width - 1); \
315 __s_column = x; \
316 __s_page = y; \
317 ssd1306_intf.start(); \
318 ssd1306_spiDataMode(0); \
319 ssd1306_intf.send(column_cmd); \
320 ssd1306_intf.send(x); \
321 ssd1306_intf.send(rx < ssd1306_lcd.width ? rx : (ssd1306_lcd.width - 1)); \
322 ssd1306_intf.send(row_cmd); \
323 ssd1306_intf.send(y<<3); \
324 ssd1306_intf.send(((y<<3) + 7) < ssd1306_lcd.height ? ((y<<3) + 7) : (ssd1306_lcd.height - 1)); \
325 ssd1306_spiDataMode(1); \
326 } \
327 static void next_page_compat(void) \
328 { \
329 ssd1306_intf.stop(); \
330 set_block_compat(__s_column,__s_page+1,0); \
331 } \
332
333
345 #define CONTROLLER_NATIVE_SPI_BLOCK_8BIT_CMDS(column_cmd, row_cmd) \
346 static void set_block_native(lcduint_t x, lcduint_t y, lcduint_t w) \
347 { \
348 uint8_t rx = w ? (x + w - 1) : (ssd1306_lcd.width - 1); \
349 ssd1306_intf.start(); \
350 ssd1306_spiDataMode(0); \
351 ssd1306_intf.send(column_cmd); \
352 ssd1306_intf.send(x); \
353 ssd1306_intf.send(rx < ssd1306_lcd.width ? rx : (ssd1306_lcd.width - 1)); \
354 ssd1306_intf.send(row_cmd); \
355 ssd1306_intf.send(y); \
356 ssd1306_intf.send(ssd1306_lcd.height - 1); \
357 ssd1306_spiDataMode(1); \
358 } \
359 static void next_page_native(void) \
360 { \
361 } \
362
363
369 #define SSD1306_COMPAT_SEND_PIXELS_RGB8_CMDS() \
370 extern uint16_t ssd1306_color; \
371 static void send_pixels_compat(uint8_t data) \
372 { \
373 for (uint8_t i=8; i>0; i--) \
374 { \
375 if ( data & 0x01 ) \
376 { \
377 ssd1306_intf.send( (uint8_t)ssd1306_color ); \
378 } \
379 else \
380 { \
381 ssd1306_intf.send( 0B00000000 ); \
382 } \
383 data >>= 1; \
384 } \
385 } \
386 static void send_pixels_buffer_compat(const uint8_t *buffer, uint16_t len) \
387 { \
388 while(len--) \
389 { \
390 send_pixels_compat(*buffer); \
391 buffer++; \
392 } \
393 }
394
395
400 #ifdef __cplusplus
401 }
402 #endif
403
404 #endif /* _LCD_COMMON_H_ */
ssd1306_setMode
void ssd1306_setMode(lcd_mode_t mode)
Sets library display mode for direct draw functions.
Definition: lcd_common.c:74
ssd1306_configureSpiDisplay
void ssd1306_configureSpiDisplay(const uint8_t *config, uint8_t configSize)
Sends configuration being passed to lcd display spi controller.
Definition: lcd_common.c:52
ssd1306_lcd_t
Definition: lcd_common.h:88
LCD_MODE_NORMAL
Definition: lcd_common.h:75
ssd1306_configureI2cDisplay
void ssd1306_configureI2cDisplay(const uint8_t *config, uint8_t configSize)
Sends configuration being passed to lcd display i2c/spi controller.
Definition: lcd_common.c:41
LCD_TYPE_SSD1306
Definition: lcd_common.h:53
LCD_TYPE_PCD8544
Definition: lcd_common.h:55
io.h
lcd_mode_t
lcd_mode_t
Definition: lcd_common.h:69
ssd1306_resetController
void ssd1306_resetController(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
Definition: lcd_common.c:82
ssd1306_lcd
ssd1306_lcd_t ssd1306_lcd
Definition: lcd_common.c:32
LCD_MODE_SSD1306_COMPAT
Definition: lcd_common.h:82
ssd1306_lcd_t::height
lcduint_t height
Definition: lcd_common.h:97
LCD_TYPE_SH1106
Definition: lcd_common.h:57
ssd1306_sendData
void ssd1306_sendData(uint8_t data) __attribute__((deprecated))
Definition: lcd_common.c:34
LCD_TYPE_CUSTOM
Definition: lcd_common.h:61
ssd1306_lcd_t::width
lcduint_t width
Definition: lcd_common.h:94
lcd_type_t
lcd_type_t
Definition: lcd_common.h:50
ssd1306_lcd_t::type
lcd_type_t type
Definition: lcd_common.h:91
LCD_TYPE_SSD1331
Definition: lcd_common.h:59