SSD1306 OLED display driver  1.8.2
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-2019, 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 {
62 } lcd_type_t;
63 
69 typedef enum
70 {
76 
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 
149  void (*send_pixels16)(uint16_t data);
150 
164  void (*set_mode)(lcd_mode_t mode);
165 } ssd1306_lcd_t;
166 
171 
176 #define s_displayHeight ssd1306_lcd.height
177 
182 #define s_displayWidth ssd1306_lcd.width
183 
188 #define g_lcd_type ssd1306_lcd.type
189 
197 void ssd1306_sendData(uint8_t data) __attribute__ ((deprecated));
198 
215 #define ssd1306_setRamBlock ssd1306_lcd.set_block
216 
224 #define ssd1306_nextRamPage ssd1306_lcd.next_page
225 
231 #define ssd1306_sendPixels ssd1306_lcd.send_pixels1
232 
239 #define ssd1306_sendPixelsBuffer ssd1306_lcd.send_pixels_buffer1
240 
247 #define ssd1306_sendPixel8 ssd1306_lcd.send_pixels8
248 
260 void ssd1306_configureI2cDisplay(const uint8_t *config, uint8_t configSize);
261 
275 void ssd1306_configureSpiDisplay(const uint8_t *config, uint8_t configSize);
276 
289 void ssd1306_configureSpiDisplay2(const uint8_t *config, uint8_t configSize);
290 
304 void ssd1306_setMode(lcd_mode_t mode);
305 
316 void ssd1306_resetController(int8_t rstPin, uint8_t delayMs);
317 
330 #define SSD1306_COMPAT_SPI_BLOCK_8BIT_CMDS(column_cmd, row_cmd) \
331  static uint8_t __s_column; \
332  static uint8_t __s_page; \
333  static void set_block_compat(lcduint_t x, lcduint_t y, lcduint_t w) \
334  { \
335  uint8_t rx = w ? (x + w - 1) : (ssd1306_lcd.width - 1); \
336  __s_column = x; \
337  __s_page = y; \
338  ssd1306_intf.start(); \
339  ssd1306_spiDataMode(0); \
340  ssd1306_intf.send(column_cmd); \
341  ssd1306_intf.send(x); \
342  ssd1306_intf.send(rx < ssd1306_lcd.width ? rx : (ssd1306_lcd.width - 1)); \
343  ssd1306_intf.send(row_cmd); \
344  ssd1306_intf.send(y<<3); \
345  ssd1306_intf.send(((y<<3) + 7) < ssd1306_lcd.height ? ((y<<3) + 7) : (ssd1306_lcd.height - 1)); \
346  ssd1306_spiDataMode(1); \
347  } \
348  static void next_page_compat(void) \
349  { \
350  ssd1306_intf.stop(); \
351  set_block_compat(__s_column,__s_page+1,0); \
352  } \
353 
354 
366 #define CONTROLLER_NATIVE_SPI_BLOCK_8BIT_CMDS(column_cmd, row_cmd) \
367  static void set_block_native(lcduint_t x, lcduint_t y, lcduint_t w) \
368  { \
369  uint8_t rx = w ? (x + w - 1) : (ssd1306_lcd.width - 1); \
370  ssd1306_intf.start(); \
371  ssd1306_spiDataMode(0); \
372  ssd1306_intf.send(column_cmd); \
373  ssd1306_intf.send(x); \
374  ssd1306_intf.send(rx < ssd1306_lcd.width ? rx : (ssd1306_lcd.width - 1)); \
375  ssd1306_intf.send(row_cmd); \
376  ssd1306_intf.send(y); \
377  ssd1306_intf.send(ssd1306_lcd.height - 1); \
378  ssd1306_spiDataMode(1); \
379  } \
380  static void next_page_native(void) \
381  { \
382  } \
383 
384 
390 #define SSD1306_COMPAT_SEND_PIXELS_RGB8_CMDS() \
391  extern uint16_t ssd1306_color; \
392  static void send_pixels_compat(uint8_t data) \
393  { \
394  for (uint8_t i=8; i>0; i--) \
395  { \
396  if ( data & 0x01 ) \
397  { \
398  ssd1306_intf.send( (uint8_t)ssd1306_color ); \
399  } \
400  else \
401  { \
402  ssd1306_intf.send( 0B00000000 ); \
403  } \
404  data >>= 1; \
405  } \
406  } \
407  static void send_pixels_buffer_compat(const uint8_t *buffer, uint16_t len) \
408  { \
409  while(len--) \
410  { \
411  send_pixels_compat(*buffer); \
412  buffer++; \
413  } \
414  }
415 
422 #define SSD1306_COMPAT_SEND_PIXELS_RGB16_CMDS() \
423  extern uint16_t ssd1306_color; \
424  static void send_pixels_compat16(uint8_t data) \
425  { \
426  for (uint8_t i=8; i>0; i--) \
427  { \
428  if ( data & 0x01 ) \
429  { \
430  ssd1306_intf.send( (uint8_t)(ssd1306_color >> 8 ) ); \
431  ssd1306_intf.send( (uint8_t)(ssd1306_color & 0xFF) ); \
432  } \
433  else \
434  { \
435  ssd1306_intf.send( 0B00000000 ); \
436  ssd1306_intf.send( 0B00000000 ); \
437  } \
438  data >>= 1; \
439  } \
440  } \
441  static void send_pixels_buffer_compat16(const uint8_t *buffer, uint16_t len) \
442  { \
443  while(len--) \
444  { \
445  send_pixels_compat16(*buffer); \
446  buffer++; \
447  } \
448  }
449 
450 
455 #ifdef __cplusplus
456 }
457 #endif
458 
459 #endif /* _LCD_COMMON_H_ */
void ssd1306_configureSpiDisplay2(const uint8_t *config, uint8_t configSize)
Sends configuration being passed to lcd display spi controller.
Definition: lcd_common.c:75
void ssd1306_setMode(lcd_mode_t mode)
Sets library display mode for direct draw functions.
Definition: lcd_common.c:131
void ssd1306_configureSpiDisplay(const uint8_t *config, uint8_t configSize)
Sends configuration being passed to lcd display spi controller.
Definition: lcd_common.c:53
void ssd1306_configureI2cDisplay(const uint8_t *config, uint8_t configSize)
Sends configuration being passed to lcd display i2c/spi controller.
Definition: lcd_common.c:42
lcd_mode_t
Definition: lcd_common.h:69
void ssd1306_resetController(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
Definition: lcd_common.c:139
ssd1306_lcd_t ssd1306_lcd
Definition: lcd_common.c:33
lcduint_t height
Definition: lcd_common.h:97
void ssd1306_sendData(uint8_t data) __attribute__((deprecated))
Definition: lcd_common.c:35
lcduint_t width
Definition: lcd_common.h:94
lcd_type_t
Definition: lcd_common.h:50
lcd_type_t type
Definition: lcd_common.h:91