FabGL
ESP32 Display Controller and Graphics Library
TFTControllerGeneric.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
38#include <stdint.h>
39#include <stddef.h>
40
41#ifdef ARDUINO
42 #include "SPI.h"
43#endif
44
45#include "freertos/FreeRTOS.h"
46
47#include "driver/spi_master.h"
48
49#include "fabglconf.h"
50#include "fabutils.h"
51#include "displaycontroller.h"
52
53
54#define TFT_CASET 0x2A
55#define TFT_RASET 0x2B
56#define TFT_RAMWR 0x2C
57#define TFT_MADCTL 0x36
58
59
60
61namespace fabgl {
62
63
64
68enum class TFTOrientation {
69 Rotate0,
70 Rotate90,
71 Rotate180,
72 Rotate270,
73};
74
75
93class TFTController : public GenericBitmappedDisplayController {
94
95public:
96
97 // unwanted methods
98 TFTController(TFTController const&) = delete;
99 void operator=(TFTController const&) = delete;
100
102
104
122 #ifdef ARDUINO
123 void begin(SPIClass * spi, gpio_num_t DC, gpio_num_t RESX = GPIO_UNUSED, gpio_num_t CS = GPIO_UNUSED);
124 #endif
125
143 #ifdef ARDUINO
144 void begin(SPIClass * spi, int DC, int RESX = -1, int CS = -1);
145 #endif
146
166 void begin(int SCK, int MOSI, int DC, int RESX, int CS, int host);
167
179 void begin();
180
181 void end();
182
197 void setResolution(char const * modeline, int viewPortWidth = -1, int viewPortHeight = -1, bool doubleBuffered = false);
198
199 // abstract method of BitmappedDisplayController
201
202 // abstract method of BitmappedDisplayController
204
205 // abstract method of BitmappedDisplayController
207
208 virtual int colorsCount() { return 1 << 16; }
209
217 void setScreenCol(int value);
218
226 void setScreenRow(int value);
227
233 int screenCol() { return m_screenCol; }
234
240 int screenRow() { return m_screenRow; }
241
242 void readScreen(Rect const & rect, RGB888 * destBuf);
243
247 void reset() { hardReset(); softReset(); }
248
260 void setOrientation(TFTOrientation value, bool force = false);
261
269 void setReverseHorizontal(bool value);
270
271
272protected:
273
274 virtual void softReset() = 0;
275
276 virtual void setupOrientation();
277
278 // abstract method of BitmappedDisplayController
279 int getBitmapSavePixelSize() { return 2; }
280
281 void setupGPIO();
282
283 void hardReset();
284
285 void sendRefresh();
286
287 void sendScreenBuffer(Rect updateRect);
288 void writeCommand(uint8_t cmd);
289 void writeByte(uint8_t data);
290 void writeWord(uint16_t data);
291 void writeData(void * data, size_t size);
292
293 void SPIBegin();
294 void SPIEnd();
295
296 void SPIBeginWrite();
297 void SPIEndWrite();
298 void SPIWriteByte(uint8_t data);
299 void SPIWriteWord(uint16_t data);
300 void SPIWriteBuffer(void * data, size_t size);
301
302 void allocViewPort();
303 void freeViewPort();
304
305 static void updateTaskFunc(void * pvParameters);
306
307 // abstract method of BitmappedDisplayController
308 void setPixelAt(PixelDesc const & pixelDesc, Rect & updateRect);
309
310 // abstract method of BitmappedDisplayController
311 void clear(Rect & updateRect);
312
313 // abstract method of BitmappedDisplayController
314 void drawEllipse(Size const & size, Rect & updateRect);
315
316 void VScroll(int scroll, Rect & updateRect);
317
318 void HScroll(int scroll, Rect & updateRect);
319
320 // abstract method of BitmappedDisplayController
321 void drawGlyph(Glyph const & glyph, GlyphOptions glyphOptions, RGB888 penColor, RGB888 brushColor, Rect & updateRect);
322
323 // abstract method of BitmappedDisplayController
324 void swapBuffers();
325
326 // abstract method of BitmappedDisplayController
327 void invertRect(Rect const & rect, Rect & updateRect);
328
329 // abstract method of BitmappedDisplayController
330 void copyRect(Rect const & source, Rect & updateRect);
331
332 // abstract method of BitmappedDisplayController
333 void swapFGBG(Rect const & rect, Rect & updateRect);
334
335 // abstract method of BitmappedDisplayController
336 void absDrawLine(int X1, int Y1, int X2, int Y2, RGB888 color);
337
338 // abstract method of BitmappedDisplayController
339 void rawFillRow(int y, int x1, int x2, RGB888 color);
340
341 void rawFillRow(int y, int x1, int x2, uint16_t pattern);
342
343 void swapRows(int yA, int yB, int x1, int x2);
344
345 void rawInvertRow(int y, int x1, int x2);
346
347 // abstract method of BitmappedDisplayController
348 void rawDrawBitmap_Native(int destX, int destY, Bitmap const * bitmap, int X1, int Y1, int XCount, int YCount);
349
350 // abstract method of BitmappedDisplayController
351 void rawDrawBitmap_Mask(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
352
353 // abstract method of BitmappedDisplayController
354 void rawDrawBitmap_RGBA2222(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
355
356 // abstract method of BitmappedDisplayController
357 void rawDrawBitmap_RGBA8888(int destX, int destY, Bitmap const * bitmap, void * saveBackground, int X1, int Y1, int XCount, int YCount);
358
359
360 #ifdef ARDUINO
361 SPIClass * m_spi;
362 #endif
363
364 spi_host_device_t m_SPIHost;
365 gpio_num_t m_SCK;
366 gpio_num_t m_MOSI;
367 gpio_num_t m_DC;
368 gpio_num_t m_RESX;
369 gpio_num_t m_CS;
370
371 spi_device_handle_t m_SPIDevHandle;
372
373 uint16_t * * m_viewPort;
374
375 int16_t m_screenWidth;
376 int16_t m_screenHeight;
377 int16_t m_screenCol;
378 int16_t m_screenRow;
379
380 // view port size when rotation is 0 degrees
381 int16_t m_rot0ViewPortWidth;
382 int16_t m_rot0ViewPortHeight;
383
384 // maximum width and height the controller can handle (ie 240x320)
385 int16_t m_controllerWidth;
386 int16_t m_controllerHeight;
387
388 // offsets used on rotating
389 int16_t m_rotOffsetX;
390 int16_t m_rotOffsetY;
391
392 TaskHandle_t m_updateTaskHandle;
393
394 volatile int m_updateTaskFuncSuspended; // 0 = enabled, >0 suspended
395 volatile bool m_updateTaskRunning;
396
397 TFTOrientation m_orientation;
398 bool m_reverseHorizontal;
399
400};
401
402
403} // end of namespace
404
405
406
407
408
409
410
void setOrientation(TFTOrientation value, bool force=false)
Set display orientation and rotation.
void setScreenCol(int value)
Set initial left column of the viewport.
void suspendBackgroundPrimitiveExecution()
Suspends drawings.
void setReverseHorizontal(bool value)
Inverts horizontal axis.
void setResolution(char const *modeline, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)
Sets TFT resolution and viewport size.
void resumeBackgroundPrimitiveExecution()
Resumes drawings after suspendBackgroundPrimitiveExecution().
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.
int screenCol()
Gets initial left column of the viewport.
void begin()
Initializes TFT display controller.
void reset()
Performs display hardware and software.
void setScreenRow(int value)
Set initial top row of the viewport.
Base abstract class for TFT drivers with SPI connection.
uint8_t const * data
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.
TFTOrientation
This enum defines TFT orientation.
Represents a 24 bit RGB color.
Represents a rectangle.
Definition: fabutils.h:248