forked from mrwastl/SmartMatrix
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSmartMatrix.h
More file actions
238 lines (202 loc) · 9.1 KB
/
SmartMatrix.h
File metadata and controls
238 lines (202 loc) · 9.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
* SmartMatrix Library - Main Header File for SmartMatrix Class
*
* Copyright (c) 2014 Louis Beaudoin (Pixelmatix)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SmartMatrix_h
#define SmartMatrix_h
#include "Arduino.h"
#include <stdint.h>
// include one of the MatrixHardware_*.h files here:
//#include "MatrixHardware_KitV1_32x32.h"
//#include "MatrixHardware_KitV1_16x32.h"
#include "MatrixHardware_KitV1_generic.h"
#ifndef DISABLE_FOREGROUND_FUNCTIONS
// scroll text
const int textLayerMaxStringLength = 50;
typedef enum ScrollMode {
wrapForward,
bounceForward,
bounceReverse,
stopped,
off,
wrapForwardFromLeft,
} ScrollMode;
#endif
// font
#include "MatrixFontCommon.h"
extern const bitmap_font apple3x5;
extern const bitmap_font apple5x7;
extern const bitmap_font apple6x10;
extern const bitmap_font apple8x13;
extern const bitmap_font gohufont6x11;
extern const bitmap_font gohufont6x11b;
typedef enum fontChoices {
font3x5,
font5x7,
font6x10,
font8x13,
gohufont11,
gohufont11b,
} fontChoices;
// color
typedef struct rgb24 {
uint8_t red;
uint8_t green;
uint8_t blue;
} rgb24;
#if COLOR_DEPTH_RGB > 24
#define color_chan_t uint16_t
#else
#define color_chan_t uint8_t
#endif
typedef enum colorCorrectionModes {
ccNone,
cc24,
cc12,
cc48
} colorCorrectionModes;
#define RGB24_ISEQUAL(a, b) ((a.red == b.red) && (a.green == b.green) && (a.blue == b.blue))
// config
typedef enum rotationDegrees {
rotation0,
rotation90,
rotation180,
rotation270
} rotationDegrees;
typedef struct screen_config {
rotationDegrees rotation;
uint16_t localWidth;
uint16_t localHeight;
} screen_config;
#define SMART_MATRIX_CAN_TRIPLE_BUFFER 1
class SmartMatrix {
public:
SmartMatrix(void);
void begin(void);
// drawing functions
void swapBuffers(bool copy = true);
void drawPixel(int16_t x, int16_t y, const rgb24& color);
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, const rgb24& color);
void drawFastVLine(int16_t x, int16_t y0, int16_t y1, const rgb24& color);
void drawFastHLine(int16_t x0, int16_t x1, int16_t y, const rgb24& color);
void drawCircle(int16_t x0, int16_t y0, uint16_t radius, const rgb24& color);
void fillCircle(int16_t x0, int16_t y0, uint16_t radius, const rgb24& outlineColor, const rgb24& fillColor);
void fillCircle(int16_t x0, int16_t y0, uint16_t radius, const rgb24& color);
void drawEllipse(int16_t x0, int16_t y0, uint16_t radiusX, uint16_t radiusY, const rgb24& color);
void drawTriangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, const rgb24& color);
void fillTriangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, const rgb24& fillColor);
void fillTriangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3,
const rgb24& outlineColor, const rgb24& fillColor);
void drawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, const rgb24& color);
void fillRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, const rgb24& color);
void fillRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, const rgb24& outlineColor, const rgb24& fillColor);
void drawRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t radius, const rgb24& outlineColor);
void fillRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t radius, const rgb24& fillColor);
void fillRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t radius,
const rgb24& outlineColor, const rgb24& fillColor);
void fillScreen(const rgb24& color);
void drawChar(int16_t x, int16_t y, const rgb24& charColor, char character);
void drawString(int16_t x, int16_t y, const rgb24& charColor, const char text[]);
void drawString(int16_t x, int16_t y, const rgb24& charColor, const rgb24& backColor, const char text[]);
void drawMonoBitmap(int16_t x, int16_t y, uint8_t width, uint8_t height, const rgb24& bitmapColor, const uint8_t *bitmap);
const rgb24 readPixel(int16_t x, int16_t y) const;
rgb24 *backBuffer(void);
void setBackBuffer(rgb24 *newBuffer);
rgb24 *getRealBackBuffer(void);
#ifndef DISABLE_FOREGROUND_FUNCTIONS
// scroll text
void scrollText(const char inputtext[], int numScrolls);
void setScrollMode(ScrollMode mode);
void setScrollSpeed(unsigned char pixels_per_second);
void setScrollFont(fontChoices newFont);
void setScrollColor(const rgb24 & newColor);
#define setScrollOffsetFromEdge setScrollOffsetFromTop // backwards compatibility
void setScrollOffsetFromTop(int offset);
void setScrollStartOffsetFromLeft(int offset);
void stopScrollText(void);
int getScrollStatus(void) const;
// foreground drawing
void clearForeground(void);
void setForegroundFont(fontChoices newFont);
void drawForegroundPixel(int16_t x, int16_t y, bool opaque = true);
void drawForegroundChar(int16_t x, int16_t y, char character, bool opaque = true);
void drawForegroundString(int16_t x, int16_t y, const char text [], bool opaque = true);
void drawForegroundMonoBitmap(int16_t x, int16_t y, uint8_t width, uint8_t height, uint8_t *bitmap, bool opaque = true);
void displayForegroundDrawing(bool waitUntilComplete = true);
#endif
// configuration
void setRotation(rotationDegrees rotation);
uint16_t getScreenWidth(void) const;
uint16_t getScreenHeight(void) const;
void setBrightness(uint8_t brightness);
void setBackgroundBrightness(uint8_t brightness);
void setColorCorrection(colorCorrectionModes mode);
void setFont(fontChoices newFont);
private:
// enable ISR access to private member variables
friend void rowCalculationISR(void);
friend void rowShiftCompleteISR(void);
// functions called by ISR
static void matrixCalculations(void);
// functions for refreshing
static void convertToHardwareXY(int16_t x, int16_t y, int16_t *hwx, int16_t *hwy);
static void loadMatrixBuffers(unsigned char currentRow);
static color_chan_t colorCorrection(uint8_t inputcolor);
static color_chan_t backgroundColorCorrection(uint8_t inputcolor);
static void getPixel(uint8_t hardwareX, uint8_t hardwareY, rgb24 *xyPixel);
static rgb24 *getRefreshRow(uint8_t y);
static void handleBufferSwap(void);
#ifndef DISABLE_FOREGROUND_FUNCTIONS
static void handleForegroundDrawingCopy(void);
static void updateForeground(void);
static bool getForegroundPixel(uint8_t x, uint8_t y, rgb24 *xyPixel);
static void redrawForeground(void);
#endif
// drawing functions not meant for user
void drawHardwareHLine(uint8_t x0, uint8_t x1, uint8_t y, const rgb24& color);
void drawHardwareVLine(uint8_t x, uint8_t y0, uint8_t y1, const rgb24& color);
void bresteepline(int16_t x3, int16_t y3, int16_t x4, int16_t y4, const rgb24& color);
void fillFlatSideTriangleInt(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, const rgb24& color);
static bool getBitmapPixelAtXY(uint8_t x, uint8_t y, uint8_t width, uint8_t height, const uint8_t *bitmap);
// configuration helper functions
static void calculateTimerLut(void);
static void calculateBackgroundLUT(void);
// color functions (replace with class and copy constructor?)
static void copyRgb24(rgb24 & dst, const rgb24 & src);
// configuration
static colorCorrectionModes _ccmode;
static screen_config screenConfig;
static volatile bool brightnessChange;
static int dimmingFactor;
static uint8_t backgroundBrightness;
static const int dimmingMaximum;
// keeping track of drawing buffers
static unsigned char currentDrawBuffer;
static unsigned char currentRefreshBuffer;
static volatile bool swapPending;
static volatile bool foregroundCopyPending;
static bool swapWithCopy;
// font
static bool getBitmapFontPixelAtXY(unsigned char letter, unsigned char x, unsigned char y, const bitmap_font *font);
const bitmap_font *fontLookup(fontChoices font) const;
static uint16_t getBitmapFontRowAtXY(unsigned char letter, unsigned char y, const bitmap_font *font);
};
#endif