Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PokittoLib by
PokittoCore.h
00001 /**************************************************************************/ 00002 /*! 00003 @file PokittoCore.h 00004 @author Jonne Valola 00005 00006 @section LICENSE 00007 00008 Software License Agreement (BSD License) 00009 00010 Copyright (c) 2016, Jonne Valola 00011 All rights reserved. 00012 00013 Redistribution and use in source and binary forms, with or without 00014 modification, are permitted provided that the following conditions are met: 00015 1. Redistributions of source code must retain the above copyright 00016 notice, this list of conditions and the following disclaimer. 00017 2. Redistributions in binary form must reproduce the above copyright 00018 notice, this list of conditions and the following disclaimer in the 00019 documentation and/or other materials provided with the distribution. 00020 3. Neither the name of the copyright holders nor the 00021 names of its contributors may be used to endorse or promote products 00022 derived from this software without specific prior written permission. 00023 00024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 00025 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 00028 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00031 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 /**************************************************************************/ 00036 00037 #ifndef POKITTOCORE_H 00038 #define POKITTOCORE_H 00039 00040 #include <stdint.h> 00041 #include <math.h> 00042 #ifndef POK_SIM 00043 #include "pwmout_api.h" 00044 #include "HWButtons.h " 00045 #else 00046 #include "PokittoSimulator.h" 00047 #endif 00048 #if POK_USE_CONSOLE > 0 00049 #include "PokittoConsole.h " 00050 #endif // POK_USE_CONSOLE 00051 #if POK_ENABLE_SD > 0 00052 #include "PokittoDisk.h " 00053 #endif 00054 00055 #include "PokittoFonts.h " 00056 #include "PokittoPalettes.h" 00057 #include "PokittoDisplay.h " 00058 #include "PokittoButtons.h " 00059 #include "PokittoBattery.h " 00060 #include "PokittoBacklight.h " 00061 #include "PokittoSound.h " 00062 #include "PokittoFakeavr.h " 00063 00064 #define PALETTE_SIZE 16 00065 #define PI 3.141592741f 00066 00067 // For GB compatibility 00068 #if PROJ_GAMEBUINO > 0 00069 extern void setup(); 00070 extern void loop(); 00071 #endif // PROJ_GAMEBUINO 00072 00073 extern uint32_t* ptimer; // re-directed tick counter 00074 00075 namespace Pokitto { 00076 00077 /** Core class. 00078 * The Core class is a class consisting of static data and methods. 00079 * It handles the lowlevel hardware functions of the Pokitto. 00080 * It is declared as static to prevent several instances running at same time. 00081 * Example: 00082 * @code 00083 * // A simple "Hello World!" program with Pokitto 00084 * 00085 * #include "Pokitto.h" 00086 * 00087 * Pokitto::Core myApp; 00088 * 00089 * int main() { 00090 * myApp.begin(); // This starts up the console (the display, buttons etc.) 00091 * while(myApp.isRunning()) { 00092 * if(myApp.Update()) { 00093 * myApp.display.print("Hello World!"); 00094 * } 00095 * } 00096 * } 00097 * @endcode 00098 */ 00099 00100 class Core 00101 { 00102 public: 00103 /** Create a Core runtime instance 00104 */ 00105 Core(); 00106 00107 /** Backlight component of the Core runtime */ 00108 static Backlight backlight; 00109 /** Buttons component of the Core runtime */ 00110 static Buttons buttons; 00111 /** Battery component of the Core runtime */ 00112 static Battery battery; 00113 /** Sound component of the Core runtime */ 00114 static Sound sound; 00115 /** Display component of the Core runtime */ 00116 static Display display; 00117 00118 // EXCECUTION CONTROL 00119 public: 00120 /** Initialize runtime (use this one) */ 00121 static void begin(); 00122 /** Initialize runtime (deprecated, avoid) */ 00123 static void init(); 00124 /** Initialize runtime with options (deprecated, avoid) */ 00125 static void init(uint8_t); 00126 /** Return run state (1 = running, 0 = shutting down) */ 00127 static bool isRunning(); 00128 /** Stop running */ 00129 static void quit(); 00130 private: 00131 /** run_state is true as long as program is running */ 00132 static bool run_state; 00133 00134 public: 00135 // INITIALIZATION 00136 /** Initialize display */ 00137 static void initDisplay(); 00138 /** Initialize random generator */ 00139 static void initRandom(); 00140 /** Initialize GPIO */ 00141 static void initGPIO(); 00142 /** Initialize LCD */ 00143 static void initLCD(); 00144 /** Initialize Audio */ 00145 static void initAudio(); 00146 00147 00148 // DISPLAY 00149 public: 00150 /** Initialize backlight */ 00151 static void initBacklight(); 00152 00153 private: 00154 /** Backlight PWM pointer */ 00155 #ifndef POK_SIM 00156 static pwmout_t backlightpwm; 00157 #endif 00158 00159 // TIMEKEEPING 00160 public: 00161 /** Initialize runtime clock */ 00162 static void initClock(); 00163 /** Get value of time elapsed during program in milliseconds */ 00164 static uint32_t getTime(); 00165 /** Wait for n milliseconds */ 00166 static void wait(uint16_t); 00167 private: 00168 /** Time of next refresh */ 00169 static uint32_t refreshtime; 00170 00171 // DIRECT TO SCREEN 00172 public: 00173 /** Display Pokitto logo */ 00174 static void showLogo(); 00175 static void showWarning(); 00176 static void setVolLimit(); 00177 00178 // BUTTON INPUT HANDLING 00179 private: 00180 static uint8_t heldStates[]; 00181 public: 00182 static void initButtons(); 00183 static void pollButtons(); 00184 static uint8_t leftBtn(); 00185 static uint8_t rightBtn(); 00186 static uint8_t upBtn(); 00187 static uint8_t downBtn(); 00188 static uint8_t aBtn(); 00189 static uint8_t bBtn(); 00190 static uint8_t cBtn(); 00191 static uint8_t leftHeld(); 00192 static uint8_t rightHeld(); 00193 static uint8_t upHeld(); 00194 static uint8_t downHeld(); 00195 static uint8_t aHeld(); 00196 static uint8_t bHeld(); 00197 static uint8_t cHeld(); 00198 00199 static uint8_t leftReleased(); 00200 static uint8_t rightReleased(); 00201 static uint8_t upReleased(); 00202 static uint8_t downReleased(); 00203 static uint8_t aReleased(); 00204 static uint8_t bReleased(); 00205 static uint8_t cReleased(); 00206 00207 // AUDIO RELATED 00208 static uint8_t ampIsOn(); 00209 static void ampEnable(uint8_t); 00210 static uint8_t soundbyte; 00211 00212 // GB RELATED 00213 public: 00214 static void readSettings(); 00215 static void titleScreen(const char* name, const uint8_t *logo); 00216 static void titleScreen(const char* name); 00217 static void titleScreen(const uint8_t* logo); 00218 static void titleScreen(); 00219 static bool update(bool useDirectMode=false); 00220 static uint32_t frameCount; 00221 static int8_t menu(const char* const* items, uint8_t length); 00222 static char* filemenu(char*); 00223 static char* filemenu(); 00224 static void keyboard(char* text, uint8_t length); 00225 static void popup(const char* text, uint8_t duration); 00226 static void setFrameRate(uint8_t fps); 00227 static void pickRandomSeed(); 00228 00229 static uint8_t getCpuLoad(); 00230 static uint16_t getFreeRam(); 00231 00232 static bool collidePointRect(int16_t x1, int16_t y1 ,int16_t x2 ,int16_t y2, int16_t w, int16_t h); 00233 static bool collideRectRect(int16_t x1, int16_t y1, int16_t w1, int16_t h1 ,int16_t x2 ,int16_t y2, int16_t w2, int16_t h2); 00234 static bool collideBitmapBitmap(int16_t x1, int16_t y1, const uint8_t* b1, int16_t x2, int16_t y2, const uint8_t* b2); 00235 00236 private: 00237 static uint8_t timePerFrame; 00238 static uint32_t nextFrameMillis; 00239 static void updatePopup(); 00240 static const char* popupText; 00241 static uint8_t popupTimeLeft; 00242 static void displayBattery(); 00243 static uint16_t frameDurationMicros; 00244 static uint32_t frameStartMicros, frameEndMicros; 00245 static uint8_t startMenuTimer; 00246 public: 00247 static uint8_t volbar_visible; 00248 static void drawvolbar(int,int,int, bool); 00249 static void askLoader(); 00250 static void jumpToLoader(); 00251 }; 00252 00253 // this is the instance used by the system 00254 extern Core core; 00255 00256 00257 } 00258 00259 #endif // POKITTOCORE_H 00260 00261
Generated on Tue Jul 12 2022 18:08:12 by
1.7.2
