SSD1306 OLED display driver  1.8.2
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-2019, 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 
65 {
66 protected:
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 
120 #ifndef DOXYGEN_SHOULD_SKIP_THIS
121 
129  static void connectKY40encoder(uint8_t pina_clk, uint8_t pinb_dt, int8_t pinc_sw = -1);
130 #endif
131 
145  static void connectGpioKeypad(const uint8_t *gpioKeys);
146 
147 protected:
150 
151 private:
152  static uint8_t s_zkeypadPin;
153  static const uint8_t * s_gpioKeypadPins;
154  static uint8_t s_ky40_clk;
155  static uint8_t s_ky40_dt;
156  static uint8_t s_ky40_sw;
157  static uint8_t zkeypadButtons();
158  static uint8_t arduboyButtons();
159  static uint8_t gpioButtons();
160  static uint8_t ky40Buttons();
161 };
162 
163 
167 
172 {
173 protected:
175 
176 public:
180  static void begin();
181 
186  static void setFrameRate(uint8_t fps);
187 
191  static uint8_t getFrameRate() { return m_fps; };
192 
199  static uint8_t getCpuLoad() { return m_cpuLoad; };
200 
204  static bool nextFrame();
205 
210  static void loopCallback(TLoopCallback callback) { m_loop = callback; };
211 
212 protected:
213 
215  static uint8_t m_frameDurationMs;
217  static uint8_t m_fps;
219  static uint8_t m_cpuLoad;
221  static uint32_t m_lastFrameTs;
224 };
225 
229 template<class C, uint8_t W, uint8_t H, uint8_t B>
231  public NanoEngineTiler<C,W,H,B>
232 {
233 public:
237  NanoEngine();
238 
245  static void display();
246 
251  static void begin();
252 
258  static void notify(const char *str);
259 
260 protected:
261 };
262 
263 template<class C, uint8_t W, uint8_t H, uint8_t B>
265  : NanoEngineCore(), NanoEngineTiler<C,W,H,B>()
266 {
267 }
268 
269 template<class C, uint8_t W, uint8_t H, uint8_t B>
271 {
272  m_lastFrameTs = millis();
274  m_cpuLoad = ((millis() - m_lastFrameTs)*100)/m_frameDurationMs;
275 }
276 
277 template<class C, uint8_t W, uint8_t H, uint8_t B>
279 {
281  if (C::BITS_PER_PIXEL > 1)
282  {
284  }
285 }
286 
287 template<class C, uint8_t W, uint8_t H, uint8_t B>
288 void NanoEngine<C,W,H,B>::notify(const char *str)
289 {
291  delay(1000);
292  m_lastFrameTs = millis();
294 }
295 
300 #endif
301 
void ssd1306_setMode(lcd_mode_t mode)
Sets library display mode for direct draw functions.
Definition: lcd_common.c:131
void(* TLoopCallback)(void)
Definition: core.h:44
static TLoopCallback m_loop
Definition: core.h:223
static void connectZKeypad(uint8_t analogPin)
Enables engine to use Z-Keypad. Enables engine to use Z-Keypad. Please refer to arkanoid example for ...
static void connectArduboyKeys()
Configures NanoEngine8 to use Arduboy keys layout. Configures NanoEngine8 to use Arduboy keys layout...
static bool pressed(uint8_t buttons)
Returns true if button or specific combination of buttons is not pressed. Returns true if button or s...
static uint8_t m_fps
Definition: core.h:217
static void refresh()
Definition: tiler.h:105
static void connectCustomKeys(TNanoEngineGetButtons handler)
static void begin()
Definition: core.h:278
uint8_t(* TNanoEngineGetButtons)(void)
Definition: core.h:41
static void begin()
static uint8_t m_cpuLoad
Definition: core.h:219
static uint32_t m_lastFrameTs
Definition: core.h:221
static uint8_t buttonsState()
Returns bits of all pressed buttons.
Definition: core.h:96
NanoEngine()
Definition: core.h:264
static uint8_t getFrameRate()
Definition: core.h:191
static uint8_t getCpuLoad()
Definition: core.h:199
static void displayBuffer()
refreshes content on oled display. Refreshes content on oled display. Call it, if you want to update ...
Definition: tiler.h:301
static void displayPopup(const char *msg)
prints popup message over display content prints popup message over display content ...
Definition: tiler.h:329
static bool notPressed(uint8_t buttons)
Returns true if button or specific combination of buttons is not pressed. Returns true if button or s...
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:288
NanoEngineInputs()
Definition: core.h:70
static void connectGpioKeypad(const uint8_t *gpioKeys)
Enables engine to use GPIO keys.
static uint8_t m_frameDurationMs
Definition: core.h:210
static void display()
refreshes content on oled display. Refreshes content on oled display. Call it, if you want to update ...
Definition: core.h:270
static TNanoEngineGetButtons m_onButtons
Definition: core.h:149