FabGL
ESP32 Display Controller and Graphics Library
SSD1306Controller.h
Go to the documentation of this file.
1/*
2 Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3 Copyright (c) 2019-2022 Fabrizio Di Vittorio.
4 All rights reserved.
5
6
7* Please contact fdivitto2013@gmail.com if you need a commercial license.
8
9
10* This library and related software is available under GPL v3.
11
12 FabGL is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 FabGL is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26
27#pragma once
28
29
30
31#ifdef ARDUINO
32
33
41#include <stdint.h>
42#include <stddef.h>
43
44#include "freertos/FreeRTOS.h"
45
46#include "fabglconf.h"
47#include "fabutils.h"
48#include "displaycontroller.h"
49#include "comdrivers/tsi2c.h"
50
51
52
53
54namespace fabgl {
55
56
57
62 Normal,
65 Rotate180,
66};
67
68
92class SSD1306Controller : public GenericBitmappedDisplayController {
93
94public:
95
96 // unwanted methods
97 SSD1306Controller(SSD1306Controller const&) = delete;
98 void operator=(SSD1306Controller const&) = delete;
99
100
102
104
112 void begin(I2C * i2c, int address = 0x3C, gpio_num_t resetGPIO = GPIO_UNUSED);
113
123 void begin();
124
125 void end();
126
137 void setResolution(char const * modeline, int viewPortWidth = -1, int viewPortHeight = -1, bool doubleBuffered = false);
138
144 bool available() { return m_screenBuffer != nullptr; }
145
146 // abstract method of BitmappedDisplayController
148
149 // abstract method of BitmappedDisplayController
151
152 // abstract method of BitmappedDisplayController
154
155 virtual int colorsCount() { return 2; }
156
164 void setScreenCol(int value);
165
173 void setScreenRow(int value);
174
180 int screenCol() { return m_screenCol; }
181
187 int screenRow() { return m_screenRow; }
188
189 void readScreen(Rect const & rect, RGB888 * destBuf);
190
196 void invert(bool value);
197
209
210
211private:
212
213 // abstract method of BitmappedDisplayController
214 int getBitmapSavePixelSize() { return 1; }
215
216
217 bool SSD1306_sendData(uint8_t * buf, int count, uint8_t ctrl);
218 bool SSD1306_sendCmd(uint8_t c);
219 bool SSD1306_sendCmd(uint8_t c1, uint8_t c2);
220 bool SSD1306_sendCmd(uint8_t c1, uint8_t c2, uint8_t c3);
221
222 void SSD1306_hardReset();
223 bool SSD1306_softReset();
224
225 void SSD1306_sendScreenBuffer(Rect updateRect);
226
227 void sendRefresh();
228
229 void setupOrientation();
230
231 void allocScreenBuffer();
232
233 static void updateTaskFunc(void * pvParameters);
234
235 // abstract method of BitmappedDisplayController
236 void setPixelAt(PixelDesc const & pixelDesc, Rect & updateRect);
237
238 // abstract method of BitmappedDisplayController
239 void clear(Rect & updateRect);
240
241 // abstract method of BitmappedDisplayController
242 void drawEllipse(Size const & size, Rect & updateRect);
243
244 void VScroll(int scroll, Rect & updateRect);
245
246 void HScroll(int scroll, Rect & updateRect);
247
248 // abstract method of BitmappedDisplayController
249 void drawGlyph(Glyph const & glyph, GlyphOptions glyphOptions, RGB888 penColor, RGB888 brushColor, Rect & updateRect);
250
251 // abstract method of BitmappedDisplayController
252 void swapBuffers();
253
254 // abstract method of BitmappedDisplayController
255 void invertRect(Rect const & rect, Rect & updateRect);
256
257 // abstract method of BitmappedDisplayController
258 void copyRect(Rect const & source, Rect & updateRect);
259
260 // abstract method of BitmappedDisplayController
261 void swapFGBG(Rect const & rect, Rect & updateRect);
262
263 // abstract method of BitmappedDisplayController
264 void absDrawLine(int X1, int Y1, int X2, int Y2, RGB888 color);
265
266 // abstract method of BitmappedDisplayController
267 void rawFillRow(int y, int x1, int x2, RGB888 color);
268
269 void rawFillRow(int y, int x1, int x2, uint8_t pattern);
270
271 void rawInvertRow(int y, int x1, int x2);
272
273 // abstract method of BitmappedDisplayController
274 void rawDrawBitmap_Native(int destX, int destY, Bitmap const * bitmap, int X1, int Y1, int XCount, int YCount);
275
276 // abstract method of BitmappedDisplayController
277 void rawDrawBitmap_Mask(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
278
279 // abstract method of BitmappedDisplayController
280 void rawDrawBitmap_RGBA2222(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
281
282 // abstract method of BitmappedDisplayController
283 void rawDrawBitmap_RGBA8888(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
284
285 void rawCopyRow(int x1, int x2, int srcY, int dstY);
286
287
288 I2C * m_i2c;
289 uint8_t m_i2cAddress;
290 gpio_num_t m_resetGPIO;
291
292 uint8_t * m_screenBuffer;
293
294 int16_t m_screenWidth;
295 int16_t m_screenHeight;
296 int16_t m_screenCol;
297 int16_t m_screenRow;
298
299 TaskHandle_t m_updateTaskHandle;
300
301 volatile int m_updateTaskFuncSuspended; // 0 = enabled, >0 suspended
302 volatile bool m_updateTaskRunning;
303
304 SSD1306Orientation m_orientation;
305
306};
307
308
309} // end of namespace
310
311
312
313#endif // #ifdef ARDUINO
314
315
316
317
I2C class allows multiple tasks to communicate with I2C devices, serializing read/write jobs.
Definition: tsi2c.h:85
void setScreenCol(int value)
Set initial left column of the viewport.
void suspendBackgroundPrimitiveExecution()
Suspends drawings.
void invert(bool value)
Inverts display colors.
void setResolution(char const *modeline, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)
Sets SSD1306 resolution and viewport size.
void resumeBackgroundPrimitiveExecution()
Resumes drawings after suspendBackgroundPrimitiveExecution().
bool available()
Checks the SSD1306 device availability.
NativePixelFormat nativePixelFormat()
Represents the native pixel format used by this display.
int screenRow()
Gets initial top row of the viewport.
virtual int colorsCount()
Determines number of colors this display can provide.
void setOrientation(SSD1306Orientation value)
Set display orientation and rotation.
int screenCol()
Gets initial left column of the viewport.
void begin()
Initializes SSD1306.
void setScreenRow(int value)
Set initial top row of the viewport.
Display driver for SSD1306 based OLED display, with I2C connection.
This file contains fabgl::BitmappedDisplayController definition.
This file contains FabGL library configuration settings, like number of supported colors,...
int16_t X1
Definition: fabutils.h:0
int16_t Y2
Definition: fabutils.h:3
int16_t X2
Definition: fabutils.h:2
int16_t Y1
Definition: fabutils.h:1
This file contains some utility classes and functions.
NativePixelFormat
This enum defines the display controller native pixel format.
SSD1306Orientation
This enum defines SSD1306 orientation.
Represents a 24 bit RGB color.
Represents a rectangle.
Definition: fabutils.h:248
This file contains fabgl::I2C definition.