LCDGFX LCD display driver  1.1.5
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-2021, 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 */
28 #ifndef _NANO_ENGINE_CORE_H_
29 #define _NANO_ENGINE_CORE_H_
30 
31 #include "tiler.h"
32 #include "canvas/canvas.h"
33 #include <stdint.h>
34 
41 #define ENGINE_DEFAULT_FPS (15)
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  BUTTON_C = 0B01000000,
63  BUTTON_CENTER = 0B10000000,
64 };
65 
70 {
71 protected:
76 
77 public:
84  static bool pressed(uint8_t buttons);
85 
92  static bool notPressed(uint8_t buttons);
93 
100  static bool clicked(uint8_t buttons);
101 
110  static uint8_t buttonsState()
111  {
112  return m_onButtons();
113  }
114 
119  static void connectCustomKeys(TNanoEngineGetButtons handler);
120 
126  static void connectZKeypad(uint8_t analogPin);
127 
132  static void connectArduboyKeys();
133 
142  static void connectKY40encoder(uint8_t pina_clk, uint8_t pinb_dt, int8_t pinc_sw = -1);
143 
157  static void connectGpioKeypad(const uint8_t *gpioKeys);
158 
164  static void connectWioKeypad();
165 
166 protected:
169 
171  static uint8_t m_lastButtons;
172 
174  static uint8_t m_newButtons;
175 
177  static void resetButtonsCache();
178 
179 private:
180  static uint8_t s_zkeypadPin;
181  static const uint8_t *s_gpioKeypadPins;
182  static uint8_t s_ky40_clk;
183  static uint8_t s_ky40_dt;
184  static uint8_t s_ky40_sw;
185  static uint8_t zkeypadButtons();
186  static uint8_t arduboyButtons();
187  static uint8_t gpioButtons();
188 #ifndef SDL_EMULATION
189  static uint8_t wioButtons();
190 #endif
191  static uint8_t ky40Buttons();
192 };
193 
197 
202 {
203 protected:
205  : NanoEngineInputs(){};
206 
210  void beginCore();
211 
212 public:
217  void setFrameRate(uint8_t fps);
218 
222  uint8_t getFrameRate()
223  {
224  return m_fps;
225  }
226 
233  uint8_t getCpuLoad()
234  {
235  return m_cpuLoad;
236  }
237 
241  bool nextFrame();
242 
248  {
249  m_loop = callback;
250  }
251 
252 protected:
254  uint16_t m_frameDurationMs = 1000 / ENGINE_DEFAULT_FPS;
256  uint8_t m_fps = ENGINE_DEFAULT_FPS;
258  uint8_t m_cpuLoad = 0;
260  uint32_t m_lastFrameTs = 0;
262  TLoopCallback m_loop = {nullptr};
263 };
264 
268 template <class C, class D> class NanoEngine: public NanoEngineCore, public NanoEngineTiler<C, D>
269 {
270 public:
274  explicit NanoEngine(D &display);
275 
282  void display();
283 
288  void begin();
289 
295  void notify(const char *str);
296 
297 protected:
298 };
299 
300 template <class C, class D>
302  : NanoEngineCore()
303  , NanoEngineTiler<C, D>(display)
304 {
305 }
306 
307 template <class C, class D> void NanoEngine<C, D>::display()
308 {
313 }
314 
315 template <class C, class D> void NanoEngine<C, D>::begin()
316 {
318 }
319 
320 template <class C, class D> void NanoEngine<C, D>::notify(const char *str)
321 {
323  lcd_delay(1000);
326 }
327 
332 #endif
static void resetButtonsCache()
uint8_t getFrameRate()
Definition: core.h:222
static uint8_t m_lastButtons
Definition: core.h:171
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:487
static void connectKY40encoder(uint8_t pina_clk, uint8_t pinb_dt, int8_t pinc_sw=-1)
Configures NanoEngine to use KY40 Rotary Encoder. Configures NanoEngine to use KY40 Rotary Encoder...
static bool clicked(uint8_t buttons)
Returns true if button was clicked and released. Returns true if button was clicked and released...
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 pressed. Returns true if button or speci...
void display()
refreshes content on oled display. Refreshes content on oled display. Call it, if you want to update ...
Definition: core.h:307
NanoEngine(D &display)
Definition: core.h:301
void loopCallback(TLoopCallback callback)
Definition: core.h:247
static void connectCustomKeys(TNanoEngineGetButtons handler)
uint16_t m_frameDurationMs
Definition: core.h:254
void begin()
Definition: core.h:315
void displayPopup(const char *msg)
prints popup message over display content prints popup message over display content ...
Definition: tiler.h:518
void refresh()
Definition: tiler.h:201
uint8_t m_cpuLoad
Definition: core.h:258
uint8_t getCpuLoad()
Definition: core.h:233
uint32_t m_lastFrameTs
Definition: core.h:260
static uint8_t buttonsState()
Returns bits of all pressed buttons.
Definition: core.h:110
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:320
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:75
#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.
static void connectWioKeypad()
Connects Wio keys to NanoEngine.
void(* TLoopCallback)(void)
Definition: core.h:47
void lcd_delay(unsigned long ms)
static uint8_t m_newButtons
Definition: core.h:174
static TNanoEngineGetButtons m_onButtons
Definition: core.h:168