LCDGFX LCD display driver  1.0.2
This library is developed to control SSD1306/SSD1325/SSD1327/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/canvas.h"
34 
41 #define ENGINE_DEFAULT_FPS (30)
42 
44 typedef uint8_t (*TNanoEngineGetButtons)(void);
45 
47 typedef void (*TLoopCallback)(void);
48 
52 
53 enum
54 {
55  BUTTON_NONE = 0B00000000,
56  BUTTON_DOWN = 0B00000001,
57  BUTTON_LEFT = 0B00000010,
58  BUTTON_RIGHT = 0B00000100,
59  BUTTON_UP = 0B00001000,
60  BUTTON_A = 0B00010000,
61  BUTTON_B = 0B00100000,
62 };
63 
68 {
69 protected:
74 public:
81  static bool pressed(uint8_t buttons);
82 
89  static bool notPressed(uint8_t buttons);
90 
99  static uint8_t buttonsState()
100  {
101  return m_onButtons();
102  }
103 
108  static void connectCustomKeys(TNanoEngineGetButtons handler);
109 
115  static void connectZKeypad(uint8_t analogPin);
116 
121  static void connectArduboyKeys();
122 
123 #ifndef DOXYGEN_SHOULD_SKIP_THIS
124 
132  static void connectKY40encoder(uint8_t pina_clk, uint8_t pinb_dt, int8_t pinc_sw = -1);
133 #endif
134 
148  static void connectGpioKeypad(const uint8_t *gpioKeys);
149 
150 protected:
153 
154 private:
155  static uint8_t s_zkeypadPin;
156  static const uint8_t * s_gpioKeypadPins;
157  static uint8_t s_ky40_clk;
158  static uint8_t s_ky40_dt;
159  static uint8_t s_ky40_sw;
160  static uint8_t zkeypadButtons();
161  static uint8_t arduboyButtons();
162  static uint8_t gpioButtons();
163  static uint8_t ky40Buttons();
164 };
165 
166 
170 
175 {
176 protected:
178 
179 public:
183  void begin();
184 
189  void setFrameRate(uint8_t fps);
190 
194  uint8_t getFrameRate() { return m_fps; };
195 
202  uint8_t getCpuLoad() { return m_cpuLoad; };
203 
207  bool nextFrame();
208 
213  void loopCallback(TLoopCallback callback) { m_loop = callback; };
214 
215 protected:
216 
218  uint8_t m_frameDurationMs = 1000/ENGINE_DEFAULT_FPS;
220  uint8_t m_fps = ENGINE_DEFAULT_FPS;
222  uint8_t m_cpuLoad = 0;
224  uint32_t m_lastFrameTs;
226  TLoopCallback m_loop = nullptr;
227 };
228 
232 template<class C, class D>
234  public NanoEngineTiler<C,D>
235 {
236 public:
240  NanoEngine(D &display);
241 
248  void display();
249 
254  void begin();
255 
261  void notify(const char *str);
262 
263 protected:
264 };
265 
266 template<class C, class D>
268  : NanoEngineCore(), NanoEngineTiler<C,D>(display)
269 {
270 }
271 
272 template<class C, class D>
274 {
278 }
279 
280 template<class C, class D>
282 {
284 }
285 
286 template<class C, class D>
287 void NanoEngine<C,D>::notify(const char *str)
288 {
290  lcd_delay(1000);
293 }
294 
299 #endif
300 
uint8_t getFrameRate()
Definition: core.h:194
static void connectZKeypad(uint8_t analogPin)
Enables engine to use Z-Keypad. Enables engine to use Z-Keypad. Please refer to arkanoid example for ...
void displayBuffer() __attribute__((noinline))
refreshes content on oled display. Refreshes content on oled display. Call it, if you want to update ...
Definition: tiler.h:468
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...
void display()
refreshes content on oled display. Refreshes content on oled display. Call it, if you want to update ...
Definition: core.h:273
NanoEngine(D &display)
Definition: core.h:267
void loopCallback(TLoopCallback callback)
Definition: core.h:213
static void connectCustomKeys(TNanoEngineGetButtons handler)
void begin()
Definition: core.h:281
void displayPopup(const char *msg)
prints popup message over display content prints popup message over display content ...
Definition: tiler.h:499
void refresh()
Definition: tiler.h:194
uint8_t m_cpuLoad
Definition: core.h:222
uint8_t getCpuLoad()
Definition: core.h:202
uint32_t m_lastFrameTs
Definition: core.h:224
static uint8_t buttonsState()
Returns bits of all pressed buttons.
Definition: core.h:99
uint32_t lcd_millis(void)
void notify(const char *str)
shows notification to a user for 1 seconds Shows notification to a user for 1 seconds ...
Definition: core.h:287
static bool notPressed(uint8_t buttons)
Returns true if button or specific combination of buttons is not pressed. Returns true if button or s...
NanoEngineInputs()
Definition: core.h:73
#define ENGINE_DEFAULT_FPS
Definition: core.h:41
uint8_t(* TNanoEngineGetButtons)(void)
Definition: core.h:44
static void connectGpioKeypad(const uint8_t *gpioKeys)
Enables engine to use GPIO keys.
void(* TLoopCallback)(void)
Definition: core.h:47
uint8_t m_frameDurationMs
Definition: core.h:218
void lcd_delay(unsigned long ms)
static TNanoEngineGetButtons m_onButtons
Definition: core.h:152