SSD1306 OLED display driver 1.7.8 This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays

core.h
Go to the documentation of this file.
1 /*
2 MIT License
3
4 Copyright (c) 2018, 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 */
29 #ifndef _NANO_ENGINE_CORE_H_
30 #define _NANO_ENGINE_CORE_H_
31
32 #include "tiler.h"
33 #include "canvas.h"
34
41 typedef uint8_t (*TNanoEngineGetButtons)(void);
42
44 typedef void (*TLoopCallback)(void);
45
49
50 enum
51 {
52 BUTTON_NONE = 0B00000000,
53 BUTTON_DOWN = 0B00000001,
54 BUTTON_LEFT = 0B00000010,
55 BUTTON_RIGHT = 0B00000100,
56 BUTTON_UP = 0B00001000,
57 BUTTON_A = 0B00010000,
58 BUTTON_B = 0B00100000,
59 };
60
64 class NanoEngineInputs
65 {
66 protected:
70 NanoEngineInputs() {};
71 public:
78 static bool pressed(uint8_t buttons);
79
86 static bool notPressed(uint8_t buttons);
87
96 static uint8_t buttonsState()
97 {
98 return m_onButtons();
99 }
100
105 static void connectCustomKeys(TNanoEngineGetButtons handler);
106
112 static void connectZKeypad(uint8_t analogPin);
113
118 static void connectArduboyKeys();
119
133 static void connectGpioKeypad(const uint8_t *gpioKeys);
134
135 protected:
137 static TNanoEngineGetButtons m_onButtons;
138
139 private:
140 static uint8_t s_zkeypadPin;
141 static const uint8_t * s_gpioKeypadPins;
142 static uint8_t zkeypadButtons();
143 static uint8_t arduboyButtons();
144 static uint8_t gpioButtons();
145 };
146
147
151
155 class NanoEngineCore: public NanoEngineInputs
156 {
157 protected:
158 NanoEngineCore(): NanoEngineInputs() {};
159
160 public:
164 static void begin();
165
170 static void setFrameRate(uint8_t fps);
171
175 static uint8_t getFrameRate() { return m_fps; };
176
183 static uint8_t getCpuLoad() { return m_cpuLoad; };
184
188 static bool nextFrame();
189
194 static void loopCallback(TLoopCallback callback) { m_loop = callback; };
195
196 protected:
197
199 static uint8_t m_frameDurationMs;
201 static uint8_t m_fps;
203 static uint8_t m_cpuLoad;
205 static uint32_t m_lastFrameTs;
207 static TLoopCallback m_loop;
208 };
209
213 template<class C, uint8_t W, uint8_t H, uint8_t B>
214 class NanoEngine: public NanoEngineCore,
215 public NanoEngineTiler<C,W,H,B>
216 {
217 public:
221 NanoEngine();
222
229 static void display();
230
235 static void begin();
236
242 static void notify(const char *str);
243
244 protected:
245 };
246
247 template<class C, uint8_t W, uint8_t H, uint8_t B>
248 NanoEngine<C,W,H,B>::NanoEngine()
249 : NanoEngineCore(), NanoEngineTiler<C,W,H,B>()
250 {
251 }
252
253 template<class C, uint8_t W, uint8_t H, uint8_t B>
254 void NanoEngine<C,W,H,B>::display()
255 {
256 m_lastFrameTs = millis();
257 NanoEngineTiler<C,W,H,B>::displayBuffer();
258 m_cpuLoad = ((millis() - m_lastFrameTs)*100)/m_frameDurationMs;
259 }
260
261 template<class C, uint8_t W, uint8_t H, uint8_t B>
262 void NanoEngine<C,W,H,B>::begin()
263 {
264 NanoEngineCore::begin();
265 if (C::BITS_PER_PIXEL > 1)
266 {
267 ssd1306_setMode(LCD_MODE_NORMAL);
268 }
269 }
270
271 template<class C, uint8_t W, uint8_t H, uint8_t B>
272 void NanoEngine<C,W,H,B>::notify(const char *str)
273 {
274 NanoEngineTiler<C,W,H,B>::displayPopup(str);
275 delay(1000);
276 m_lastFrameTs = millis();
277 NanoEngineTiler<C,W,H,B>::refresh();
278 }
279
284 #endif
285
ssd1306_setMode
void ssd1306_setMode(lcd_mode_t mode)
Sets library display mode for direct draw functions.
Definition: lcd_common.c:74
NanoEngineInputs
Definition: core.h:64
TLoopCallback
void(* TLoopCallback)(void)
Definition: core.h:44
NanoEngineCore::m_loop
static TLoopCallback m_loop
Definition: core.h:207
NanoEngineInputs::connectZKeypad
static void connectZKeypad(uint8_t analogPin)
Enables engine to use Z-Keypad. Enables engine to use Z-Keypad. Please refer to arkanoid example for ...
NanoEngineCore::loopCallback
static void loopCallback(TLoopCallback callback)
Definition: core.h:194
NanoEngine
Definition: core.h:214
LCD_MODE_NORMAL
Definition: lcd_common.h:75
NanoEngineCore
Definition: core.h:155
NanoEngineInputs::connectArduboyKeys
static void connectArduboyKeys()
Configures NanoEngine8 to use Arduboy keys layout. Configures NanoEngine8 to use Arduboy keys layout...
NanoEngineInputs::pressed
static bool pressed(uint8_t buttons)
Returns true if button or specific combination of buttons is not pressed. Returns true if button or s...
NanoEngineCore::m_fps
static uint8_t m_fps
Definition: core.h:201
NanoEngineTiler::refresh
static void refresh()
Definition: tiler.h:105
NanoEngineCore::setFrameRate
static void setFrameRate(uint8_t fps)
canvas.h
NanoEngineInputs::connectCustomKeys
static void connectCustomKeys(TNanoEngineGetButtons handler)
NanoEngine::begin
static void begin()
Definition: core.h:262
TNanoEngineGetButtons
uint8_t(* TNanoEngineGetButtons)(void)
Definition: core.h:41
NanoEngineCore::begin
static void begin()
NanoEngineCore::m_cpuLoad
static uint8_t m_cpuLoad
Definition: core.h:203
NanoEngineCore::m_lastFrameTs
static uint32_t m_lastFrameTs
Definition: core.h:205
NanoEngineInputs::buttonsState
static uint8_t buttonsState()
Returns bits of all pressed buttons.
Definition: core.h:96
NanoEngineTiler
Definition: tiler.h:80
NanoEngine::NanoEngine
NanoEngine()
Definition: core.h:248
NanoEngineCore::getFrameRate
static uint8_t getFrameRate()
Definition: core.h:175
NanoEngineCore::getCpuLoad
static uint8_t getCpuLoad()
Definition: core.h:183
NanoEngineTiler::displayBuffer
static void displayBuffer()
refreshes content on oled display. Refreshes content on oled display. Call it, if you want to update ...
Definition: tiler.h:301
NanoEngineTiler::displayPopup
static void displayPopup(const char *msg)
prints popup message over display content prints popup message over display content ...
Definition: tiler.h:329
NanoEngineInputs::notPressed
static bool notPressed(uint8_t buttons)
Returns true if button or specific combination of buttons is not pressed. Returns true if button or s...
NanoEngine::notify
static void notify(const char *str)
shows notification to a user for 1 seconds Shows notification to a user for 1 seconds ...
Definition: core.h:272
NanoEngineInputs::NanoEngineInputs
NanoEngineInputs()
Definition: core.h:70
NanoEngineInputs::connectGpioKeypad
static void connectGpioKeypad(const uint8_t *gpioKeys)
Enables engine to use GPIO keys.
tiler.h
NanoEngineCore::m_frameDurationMs
static uint8_t m_frameDurationMs
Definition: core.h:194
NanoEngine::display
static void display()
refreshes content on oled display. Refreshes content on oled display. Call it, if you want to update ...
Definition: core.h:254
NanoEngineCore::nextFrame
static bool nextFrame()
NanoEngineInputs::m_onButtons
static TNanoEngineGetButtons m_onButtons
Definition: core.h:137