SSD1306 OLED display driver  1.7.13
This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
ssd1306_16bit.c
1 /*
2  MIT License
3 
4  Copyright (c) 2018-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 */
24 
25 #include "ssd1306_16bit.h"
26 #include "intf/ssd1306_interface.h"
27 #include "lcd/lcd_common.h"
28 #include "ssd1306_hal/io.h"
29 
30 extern uint16_t ssd1306_color;
31 extern uint8_t s_ssd1306_invertByte;
32 extern lcduint_t ssd1306_cursorX;
33 extern lcduint_t ssd1306_cursorY;
35 #ifdef CONFIG_SSD1306_UNICODE_ENABLE
36 extern uint8_t g_ssd1306_unicode;
37 #endif
38 
39 void ssd1306_setRgbColor16(uint8_t r, uint8_t g, uint8_t b)
40 {
41  ssd1306_color = RGB_COLOR16(r,g,b);
42 }
43 
44 void ssd1306_drawBufferFast16(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *data)
45 {
46  uint32_t count = (w * h) << 1;
47  ssd1306_lcd.set_block(x, y, w);
48  while (count--)
49  {
50  ssd1306_intf.send( *data );
51  data++;
52  }
54 }
55 
56 // IMPORTANT: ALL 16-BIT OLED DISPLAYS SUPPORT 8-BIT DIRECT DRAW FUNCTIONS
57 // REFER TO ssd1306_8bit.c
58 // 16-BIT DIRECT DRAW FUNCTIONS ARE NOT FULLY IMPLEMENTED. ANY HELP IS WELCOME.
59 
60 void ssd1306_drawMonoBuffer16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap)
61 {
62  uint8_t bit = 1;
63  uint16_t blackColor = s_ssd1306_invertByte ? ssd1306_color : 0x00;
64  uint16_t color = s_ssd1306_invertByte ? 0x00 : ssd1306_color;
65  ssd1306_lcd.set_block(xpos, ypos, w);
66  while (h--)
67  {
68  lcduint_t wx = w;
69  while (wx--)
70  {
71  uint8_t data = *bitmap;
72  if ( data & bit )
73  ssd1306_lcd.send_pixels16( color );
74  else
75  ssd1306_lcd.send_pixels16( blackColor );
76  bitmap++;
77  }
78  bit <<= 1;
79  if (bit == 0)
80  {
81  bit = 1;
82  }
83  else
84  {
85  bitmap -= w;
86  }
87  }
89 }
90 
91 void ssd1306_fillScreen16(uint16_t fill_Data)
92 {
93  ssd1306_lcd.set_block(0, 0, 0);
94  uint32_t count = (uint32_t)ssd1306_lcd.width * (uint32_t)ssd1306_lcd.height;
95  while (count--)
96  {
97  ssd1306_lcd.send_pixels16( fill_Data );
98  }
100 }
101 
103 {
104  ssd1306_fillScreen16( 0x0000 );
105 }
106 
107 void ssd1306_putPixel16(lcdint_t x, lcdint_t y)
108 {
109  ssd1306_lcd.set_block(x, y, 0);
110  ssd1306_lcd.send_pixels16( ssd1306_color );
111  ssd1306_intf.stop();
112 }
113 
114 void ssd1306_putColorPixel16(lcdint_t x, lcdint_t y, uint16_t color)
115 {
116  ssd1306_lcd.set_block(x, y, 0);
117  ssd1306_lcd.send_pixels16( color );
118  ssd1306_intf.stop();
119 }
120 
121 void ssd1306_drawVLine16(lcdint_t x1, lcdint_t y1, lcdint_t y2)
122 {
123  ssd1306_lcd.set_block(x1, y1, 1);
124  while (y1<=y2)
125  {
126  ssd1306_lcd.send_pixels16( ssd1306_color );
127  y1++;
128  }
129  ssd1306_intf.stop();
130 }
131 
132 void ssd1306_drawHLine16(lcdint_t x1, lcdint_t y1, lcdint_t x2)
133 {
134  ssd1306_lcd.set_block(x1, y1, 0);
135  while (x1 < x2)
136  {
137  ssd1306_lcd.send_pixels16( ssd1306_color );
138  x1++;
139  }
140  ssd1306_intf.stop();
141 }
142 
143 void ssd1306_drawLine16(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2)
144 {
145  lcduint_t dx = x1 > x2 ? (x1 - x2): (x2 - x1);
146  lcduint_t dy = y1 > y2 ? (y1 - y2): (y2 - y1);
147  lcduint_t err = 0;
148  if (dy > dx)
149  {
150  if (y1 > y2)
151  {
152  ssd1306_swap_data(x1, x2, lcdint_t);
153  ssd1306_swap_data(y1, y2, lcdint_t);
154  }
155  for(; y1<=y2; y1++)
156  {
157  err += dx;
158  if (err >= dy)
159  {
160  err -= dy;
161  x1 < x2 ? x1++: x1--;
162  }
163  ssd1306_putPixel16( x1, y1 );
164  }
165  }
166  else
167  {
168  if (x1 > x2)
169  {
170  ssd1306_swap_data(x1, x2, lcdint_t);
171  ssd1306_swap_data(y1, y2, lcdint_t);
172  }
173  for(; x1<=x2; x1++)
174  {
175  err += dy;
176  if (err >= dx)
177  {
178  err -= dx;
179  if (y1 < y2) y1++; else y1--;
180  }
181  ssd1306_putPixel16( x1, y1 );
182  }
183  }
184 }
185 
186 void ssd1306_drawRect16(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2)
187 {
188  ssd1306_drawHLine16(x1,y1,x2);
189  ssd1306_drawHLine16(x1,y2,x2);
190  ssd1306_drawVLine16(x1,y1,y2);
191  ssd1306_drawVLine16(x2,y1,y2);
192 }
193 
194 void ssd1306_fillRect16(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2)
195 {
196  if (y1 > y2)
197  {
198  ssd1306_swap_data(y1, y2, lcdint_t);
199  }
200  if (x1 > x2)
201  {
202  ssd1306_swap_data(x1, x2, lcdint_t);
203  }
204  ssd1306_lcd.set_block(x1, y1, x2 - x1 + 1);
205  uint16_t count = (x2 - x1 + 1) * (y2 - y1 + 1);
206  while (count--)
207  {
208  ssd1306_lcd.send_pixels16( ssd1306_color );
209  }
210  ssd1306_intf.stop();
211 }
212 
213 void ssd1306_drawMonoBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap)
214 {
215  uint8_t bit = 1;
216  uint16_t blackColor = s_ssd1306_invertByte ? ssd1306_color : 0x00;
217  uint16_t color = s_ssd1306_invertByte ? 0x00 : ssd1306_color;
218  ssd1306_lcd.set_block(xpos, ypos, w);
219  while (h--)
220  {
221  lcduint_t wx = w;
222  while ( wx-- )
223  {
224  uint8_t data = pgm_read_byte( bitmap );
225  if ( data & bit )
226  ssd1306_lcd.send_pixels16( color );
227  else
228  ssd1306_lcd.send_pixels16( blackColor );
229  bitmap++;
230  }
231  bit <<= 1;
232  if ( bit == 0 )
233  {
234  bit = 1;
235  }
236  else
237  {
238  bitmap -= w;
239  }
240  }
241  ssd1306_intf.stop();
242 }
243 
244 void ssd1306_drawBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap)
245 {
246  ssd1306_lcd.set_block(xpos, ypos, w);
247  uint32_t count = (w) * (h);
248  while (count--)
249  {
250  ssd1306_lcd.send_pixels16( (pgm_read_byte( &bitmap[0] ) << 8) | pgm_read_byte( &bitmap[1] ) );
251  bitmap += 2;
252  }
253  ssd1306_intf.stop();
254 }
255 
#define RGB_COLOR16(r, g, b)
void ssd1306_fillScreen16(uint16_t fill_Data)
Definition: ssd1306_16bit.c:91
void(* send)(uint8_t data)
void ssd1306_drawBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap)
void ssd1306_drawRect16(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2)
void ssd1306_putColorPixel16(lcdint_t x, lcdint_t y, uint16_t color)
void(* send_pixels16)(uint16_t data)
Sends RGB pixel encoded in 5-6-5 format to OLED driver. Sends RGB pixel encoded in 5-6-5 format to OL...
Definition: lcd_common.h:149
void(* set_block)(lcduint_t x, lcduint_t y, lcduint_t w)
Sets block in RAM of lcd display controller to write data to.
Definition: lcd_common.h:114
void ssd1306_drawMonoBuffer16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap)
Definition: ssd1306_16bit.c:60
void ssd1306_setRgbColor16(uint8_t r, uint8_t g, uint8_t b)
Sets default color.
Definition: ssd1306_16bit.c:39
void ssd1306_drawBufferFast16(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *data)
Definition: ssd1306_16bit.c:44
ssd1306_lcd_t ssd1306_lcd
Definition: lcd_common.c:32
void ssd1306_fillRect16(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2)
void ssd1306_putPixel16(lcdint_t x, lcdint_t y)
ssd1306_interface_t ssd1306_intf
lcduint_t height
Definition: lcd_common.h:97
SFixedFontInfo s_fixedFont
Definition: tiler.h:44
void ssd1306_drawHLine16(lcdint_t x1, lcdint_t y1, lcdint_t x2)
void ssd1306_clearScreen16(void)
lcduint_t width
Definition: lcd_common.h:94
void ssd1306_drawMonoBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap)
#define ssd1306_swap_data(a, b, type)
Definition: io.h:69
void ssd1306_drawVLine16(lcdint_t x1, lcdint_t y1, lcdint_t y2)