SSD1306 OLED display driver  1.4.10
This library is developed to control SSD1306/SSD1331 RGB i2c/spi OLED displays and spi PCD8544 LED display
ssd1331_96x64.c
1 /*
2  MIT License
3 
4  Copyright (c) 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 */
24 
25 #include "ssd1331_96x64.h"
26 #include "lcd_common.h"
27 #include "ssd1331_commands.h"
28 #include "intf/ssd1306_interface.h"
29 #include "spi/ssd1306_spi.h"
30 #include "hal/io.h"
31 
32 static const PROGMEM uint8_t s_oled96x64_initData[] =
33 {
34  SSD1331_DISPLAYOFF, // display off
35  SSD1331_SEGREMAP, 0x00 | 0x20 | 0x10 | 0x02 | 0x01, /* 8-bit rgb color mode */
36  SSD1331_SETSTARTLINE, 0x00, // First line to start scanning from
37  SSD1331_SETDISPLAYOFFSET, 0x00, // Set display offset
38  SSD1331_NORMALDISPLAY,
39  SSD1331_SETMULTIPLEX, 63, // Reset to default MUX. See datasheet
40  SSD1331_SETMASTER, 0x8E, // Set master mode
41  SSD1331_POWERMODE, 0x0B, // Disable power-safe mode
42  SSD1331_SETPRECHARGE, 0x31, // Phase 1 and Phase 2 periods
43  SSD1331_CLOCKDIV, 0xF0, // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
44  SSD1331_PRECHARGEA, 0x64,
45  SSD1331_PRECHARGEB, 0x78,
46  SSD1331_PRECHARGELEVEL, 0x3A,
47  SSD1331_VCOMH, 0x3E,
48  SSD1331_MASTERCURRENT, 0x09,
49  SSD1331_CONTRASTA, 0x91, // RED
50  SSD1331_CONTRASTB, 0x50, // GREEN
51  SSD1331_CONTRASTC, 0x7D, // BLUE
52  SSD1331_DISPLAYON,
53 };
54 
55 static uint8_t s_column;
56 static uint8_t s_page;
57 static uint16_t s_color = 0xFF;
58 
59 static void ssd1331_setBlock(uint8_t x, uint8_t y, uint8_t w)
60 {
61  uint8_t rx = w ? (x + w - 1) : (s_displayWidth - 1);
62  s_column = x;
63  s_page = y;
65  ssd1306_sendByte(SSD1331_COLUMNADDR);
68  ssd1306_sendByte(SSD1331_ROWADDR);
69  ssd1306_sendByte(y<<3);
70  ssd1306_sendByte(((y<<3) + 7) < s_displayHeight ? ((y<<3) + 7) : (s_displayHeight - 1));
72 }
73 
74 static void ssd1331_nextPage(void)
75 {
77  ssd1331_setBlock(s_column,s_page+1,0);
79 }
80 
81 static void ssd1331_sendPixels(uint8_t data)
82 {
83  for (uint8_t i=8; i>0; i--)
84  {
85  if ( data & 0x01 )
86  {
87  ssd1306_sendByte( (uint8_t)s_color );
88  }
89  else
90  {
91  ssd1306_sendByte( 0B00000000 );
92  }
93  data >>= 1;
94  }
95 }
96 
97 void ssd1331_setColor(uint16_t color)
98 {
99  s_color = color;
100 }
101 
102 void ssd1331_setRgbColor(uint8_t r, uint8_t g, uint8_t b)
103 {
104  s_color = RGB_COLOR8(r,g,b);
105 }
106 
108 {
110  s_displayHeight = 64;
111  s_displayWidth = 96;
112  ssd1306_setRamBlock = ssd1331_setBlock;
113  ssd1306_nextRamPage = ssd1331_nextPage;
114  ssd1306_sendPixels = ssd1331_sendPixels;
115  for( uint8_t i=0; i<sizeof(s_oled96x64_initData); i++)
116  {
117  ssd1306_sendCommand(pgm_read_byte(&s_oled96x64_initData[i]));
118  }
119 }
120 
121 void ssd1331_96x64_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
122 {
123  if (rstPin >=0)
124  {
125  pinMode(rstPin, OUTPUT);
126  digitalWrite(rstPin, HIGH);
127  /* Wait at least 1ms after VCC is up for LCD */
128  delay(1);
129  /* Perform reset operation of LCD display */
130  digitalWrite(rstPin, LOW);
131  delay(10);
132  digitalWrite(rstPin, HIGH);
133  }
134  ssd1306_spiInit(cesPin, dcPin);
136 }
void ssd1331_96x64_init()
Inits 96x64 RGB OLED display (based on SSD1331 controller).
void(* ssd1306_sendByte)(uint8_t data)
void ssd1331_96x64_spi_init(int8_t rstPin, int8_t cesPin, int8_t dcPin)
Inits 96x64 RGB OLED display over spi (based on SSD1331 controller).
void ssd1331_setColor(uint16_t color)
Sets default color, generated by RGB_COLOR8 macros.
Definition: ssd1331_96x64.c:97
void ssd1306_sendCommand(uint8_t command)
void(* ssd1306_dataStart)(void)
#define RGB_COLOR8(r, g, b)
Definition: ssd1331_96x64.h:39
void(* ssd1306_endTransmission)(void)
void ssd1331_setRgbColor(uint8_t r, uint8_t g, uint8_t b)
Sets default color.
uint8_t g_lcd_type
Definition: ssd1306.c:40
uint8_t s_displayHeight
Definition: ssd1306.c:38
void(* ssd1306_commandStart)(void)
void(* ssd1306_setRamBlock)(uint8_t x, uint8_t y, uint8_t w)
void(* ssd1306_nextRamPage)(void)
void(* ssd1306_sendPixels)(uint8_t data)
void ssd1306_spiInit(int8_t cesPin, int8_t dcPin)
Definition: ssd1306_spi.c:38
uint8_t s_displayWidth
Definition: ssd1306.c:39