Solo Controller Documentation 1.0
Documentation for the Solo Controller
 
Loading...
Searching...
No Matches
Canvas.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file Canvas.h
3 * @brief Defines higher level TFT graphics functionality
4 * @details
5 * The LT7683 chip can create multiple canvass for holding graphics. Callers
6 * can place graphics onto the canvass and they can use the graphics engine
7 * of the LT7683 chip to draw geometric shape. When ready, the caller can
8 * then signify which canvas is to be diplayed within the TFT window. The
9 * Canvas class provides a higher level interface to the LT7683 chip,
10 * provides methods for creating, managing, and using canvass.
11 ******************************************************************************/
12
13#ifndef Canvas_DEFINED
14#define Canvas_DEFINED
15
16#include "Common.h"
17
18/******************************************************************************/
19/*** ***/
20/*** Class Definition: Canvas ***/
21/*** ***/
22/******************************************************************************
23 * @brief Provides higher level TFT graphic functionality used by the menu system
24 * @details
25 * The LT7683 chip can create multiple canvass for holding graphics. Callers
26 * can place graphics onto the canvass and they can use the graphics engine
27 * of the LT7683 chip to draw geometric shapes. When ready, the caller can
28 * then signify which canvas is to be diplayed within the TFT window. The
29 * Canvas class provides a higher level interface to the LT7683 chip,
30 * providing methods for creating, managing, and using these canvass.
31 ******************************************************************************/
32class Canvas
33{
34
35 const uint16_t _width; // Width of the canvas
36 const uint16_t _height; // Height of the canvas
37 const uint32_t _DRAM_address; // Starting address for the canvas in Display RAM
38
39 static uint32_t _nextDRAM_Address; // Keeps track of the next available location in DRAM
40
41protected:
47 void _validate(void) const;
48
49public:
53
57 Canvas(void) : Canvas(false) {};
58
63 Canvas(bool temporary);
64
71 Canvas(uint16_t width, uint16_t height, bool temporary = false);
72
78 ~Canvas(void) = default;
79
84
93 virtual void loadImage(void) const
94 {
95 // validate that the width of the image is a multiple of 4.
96 _validate();
97 };
98
104 void setActive(void) const;
105
111 void setMainWindow(void) const;
112
117
124 inline uint16_t width(void) const
125 {
126 return _width;
127 };
128
135 inline uint16_t height(void) const
136 {
137 return _height;
138 };
139
146 inline uint32_t address(void) const
147 {
148 return _DRAM_address;
149 }
150
155
164 static void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
165
171 inline void clear(void)
172 {
173 clear(Black);
174 }
175
180 inline void clear(uint16_t color)
181 {
182 setActive();
184 }
185
194 void solidFill(uint16_t x0, uint16_t y0, uint16_t width, uint16_t height, uint16_t color) const;
195
205 void text(uint16_t x0, uint16_t y0, uint16_t fColor, uint16_t bColor, const char *text, bool small = false) const;
206
215 void drawSquare(unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1, unsigned short color) const;
216
221
226 void BTE_CopyFrom(const Canvas &source) const;
227
234 void BTE_CopyFrom(const Canvas &source, uint16_t DT_x0, uint16_t DT_y0) const;
235
251 void BTE_ROP(const Canvas &S0, uint16_t S0_x0, uint16_t S0_y0,
252 const Canvas &S1, uint16_t S1_x0, uint16_t S1_y0,
253 uint16_t DT_x0, uint16_t DT_y0, uint16_t DT_width, uint16_t DT_height,
254 uint8_t ROP, bool S1_OpacityOn = false) const;
255
266 inline void BTE_CopyFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
267 {
268 const uint8_t ROP = 0x0C; // DT = S0 (source)
269 BTE_ROP(source, Src_x0, Src_y0, source, Src_x0, Src_y0, DT_x0, DT_y0, width, height, ROP);
270 };
271
282 inline void BTE_AddImageFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0,
283 uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
284 {
285 const uint8_t ROP = 0x0E; // DT = S0 + S1 (source)
286 // Assumes that this object is both S0 and DT
287 BTE_ROP(*this, DT_x0, DT_y0, source, Src_x0, Src_y0, DT_x0, DT_y0, width, height, ROP, false);
288 };
289
300 inline void BTE_AddTransparantImageFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
301 {
302 const uint8_t ROP = 0x0E; // DT = S0 + S1 (source)
303 // Assumes that this object is both S0 and DT
304 BTE_ROP(*this, DT_x0, DT_y0, source, Src_x0, Src_y0, DT_x0, DT_y0, width, height, ROP, true);
305 };
306
308
314 static inline void BL_ON(void)
315 {
316 digitalWrite(TFT_BL, HIGH);
317 };
318
324 static inline void BL_OFF(void)
325 {
326 digitalWrite(TFT_BL, LOW);
327 };
328
334 static inline uint32_t nextAddress(void)
335 {
336 return _nextDRAM_Address;
337 }
338
339protected:
345 void BTE_SetAsS0(uint16_t x0, uint16_t y0) const;
346
352 void BTE_SetAsS1(uint16_t x0, uint16_t y0) const;
353
359 void BTE_SetAsDT(uint16_t x0, uint16_t y0) const;
360};
361
362/******************************************************************************/
363/*** ***/
364/*** Class Definition: ROM_Canvas ***/
365/*** ***/
366/******************************************************************************
367 * @brief A variation of the Canvas class that can load imagery from Flash ROM
368 * @details
369 * Note that this class assumes that the imagery in Flash ROM is in
370 * 16 bpp color format.
371 ******************************************************************************/
372class ROM_Canvas : public Canvas
373{
374
375 uint32_t _ROM_Address; // Starting address of the image in Flash ROM
376
377public:
379 ROM_Canvas(void) = delete;
380
385 ROM_Canvas(ROM_Image image);
386
392 ~ROM_Canvas(void) = default;
393
399 void loadImage(void) const override;
400};
401
402/******************************************************************************/
403/*** ***/
404/*** Class Definition: DRAM_Canvas ***/
405/*** ***/
406/******************************************************************************
407 * @brief Variation of the Canvas class that can copy imagery from
408 * another canvas
409 ******************************************************************************/
410class DRAM_Canvas : public Canvas
411{
412
413 const Canvas &_srcCanvas; // Canvas containing the source imagery
414 const Block_Image _imgBlock; // The image block within _srcCanvas that is
415 // to be copied over
416
417public:
419 DRAM_Canvas(void) = delete;
420
425 DRAM_Canvas(const Canvas &srcCanvas);
426
432 DRAM_Canvas(const Canvas &srcCanvas, const Block_Image imgBlock);
433
439 ~DRAM_Canvas(void) = default;
440
446 void loadImage(void) const override;
447};
448
449/******************************************************************************/
450/*** ***/
451/*** Support Functions ***/
452/*** ***/
453/******************************************************************************/
454
458template <typename T>
459inline T nearest4(T num)
460{
461 return static_cast<T>(ceil(num / 4.0) * 4);
462};
463
464#endif
#define TFT_BL
Backlight pin used by the TFT.
Definition Common.h:19
#define Black
Definition TFTM070A1.h:56
#define LCD_YSIZE_TFT
Definition TFTM070A1.h:25
#define LCD_XSIZE_TFT
Definition TFTM070A1.h:24
Definition Canvas.h:33
static void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color)
Draws a line onto the display.
Definition Canvas.cpp:132
~Canvas(void)=default
Default destructor.
void clear(uint16_t color)
Erases the canvas, setting all pixels to the specified color.
Definition Canvas.h:180
void BTE_ROP(const Canvas &S0, uint16_t S0_x0, uint16_t S0_y0, const Canvas &S1, uint16_t S1_x0, uint16_t S1_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t DT_width, uint16_t DT_height, uint8_t ROP, bool S1_OpacityOn=false) const
Gneralized ROP operation. This assumes that object calling this method is the destimation DT canvas.
Definition Canvas.cpp:85
void clear(void)
Erases the canvas, setting all pixels to Black.
Definition Canvas.h:171
void setActive(void) const
Sets this canvas as both the active canvas and active window.
Definition Canvas.cpp:31
void setMainWindow(void) const
Sets this canvas as the Main Window, displaying it in the TFT.
Definition Canvas.cpp:42
static void BL_OFF(void)
Turns the TFT backlight off.
Definition Canvas.h:324
Canvas(void)
Default constructor sets canvass to the full size of the display.
Definition Canvas.h:57
void BTE_SetAsDT(uint16_t x0, uint16_t y0) const
Sets the location of the destination (DT) image for the BTE engine.
Definition Canvas.cpp:66
void BTE_SetAsS0(uint16_t x0, uint16_t y0) const
Sets the location of the S0 source image for the BTE engine.
Definition Canvas.cpp:50
static uint32_t nextAddress(void)
Location in DRAM whether the next image Canvas will be placed.
Definition Canvas.h:334
uint16_t width(void) const
Accessor method providing the canvas width.
Definition Canvas.h:124
void BTE_AddImageFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
Adds an opacity encoded image from source to the image on this canvas.
Definition Canvas.h:282
void BTE_AddTransparantImageFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
Adds an opacity encoded image from source to the image on this canvas.
Definition Canvas.h:300
uint16_t height(void) const
Accessor method providing the canvas height.
Definition Canvas.h:135
void BTE_CopyFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
Uses BTE engine to copy imagery from source canvas to this one.
Definition Canvas.h:266
void drawSquare(unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1, unsigned short color) const
Draws an unfilled square.
Definition Canvas.cpp:172
void BTE_SetAsS1(uint16_t x0, uint16_t y0) const
Sets the location of the S1 source image for the BTE engine.
Definition Canvas.cpp:58
void BTE_CopyFrom(const Canvas &source) const
Uses BTE engine to copy entire image from source canvas to this one.
Definition Canvas.cpp:75
void _validate(void) const
Protected method used to validate that the images used to create this canvas are appropriately size.
Definition Canvas.cpp:185
void solidFill(uint16_t x0, uint16_t y0, uint16_t width, uint16_t height, uint16_t color) const
Draws a filled square onto the canvas.
Definition Canvas.cpp:140
uint32_t address(void) const
Accessor method providing the canvas' starting address in DRAM.
Definition Canvas.h:146
virtual void loadImage(void) const
Loads imagery onto the canvas.
Definition Canvas.h:93
void text(uint16_t x0, uint16_t y0, uint16_t fColor, uint16_t bColor, const char *text, bool small=false) const
Draws text onto the canvas.
Definition Canvas.cpp:155
static void BL_ON(void)
Turns the TFT backlight on.
Definition Canvas.h:314
void loadImage(void) const override
Loads the image from Flash ROM onto this Canvas.
Definition Canvas.cpp:242
~DRAM_Canvas(void)=default
Default destructor.
~ROM_Canvas(void)=default
Default destructor.
void loadImage(void) const override
Loads the image from Flash ROM onto this Canvas.
Definition Canvas.cpp:205
Structure to define sub-images. Generally associated with a ROM_Image.
Definition Common.h:52
Structure to define the size and location of an image in Flash.
Definition Common.h:44