PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PokittoCore.h Source File

PokittoCore.h

Go to the documentation of this file.
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 256
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   /** FPS */
00168   static uint32_t fps_counter;
00169   static bool fps_counter_updated;
00170 private:
00171   /** Time of next refresh */
00172   static uint32_t refreshtime;
00173 
00174   // DIRECT TO SCREEN
00175 public:
00176   /** Display Pokitto logo */
00177   static void showLogo();
00178   static void showWarning();
00179   static void setVolLimit();
00180 
00181 // BUTTON INPUT HANDLING
00182 public:
00183   static void initButtons();
00184   static void pollButtons();
00185   static uint8_t leftBtn();
00186   static uint8_t rightBtn();
00187   static uint8_t upBtn();
00188   static uint8_t downBtn();
00189   static uint8_t aBtn();
00190   static uint8_t bBtn();
00191   static uint8_t cBtn();
00192   static uint8_t leftHeld();
00193   static uint8_t rightHeld();
00194   static uint8_t upHeld();
00195   static uint8_t downHeld();
00196   static uint8_t aHeld();
00197   static uint8_t bHeld();
00198   static uint8_t cHeld();
00199 
00200   static uint8_t leftReleased();
00201   static uint8_t rightReleased();
00202   static uint8_t upReleased();
00203   static uint8_t downReleased();
00204   static uint8_t aReleased();
00205   static uint8_t bReleased();
00206   static uint8_t cReleased();
00207 
00208   // AUDIO RELATED
00209   static uint8_t ampIsOn();
00210   static void ampEnable(uint8_t);
00211   static uint8_t soundbyte;
00212 
00213   // GB RELATED
00214 public:
00215     static void readSettings();
00216     static void titleScreen(const char* name, const uint8_t *logo);
00217     static void titleScreen(const char* name);
00218     static void titleScreen(const uint8_t* logo);
00219     static void titleScreen();
00220     static bool update(bool useDirectMode=false, uint8_t updRectX=0, uint8_t updRectY=0, uint8_t updRectW=LCDWIDTH, uint8_t updRectH=LCDHEIGHT);
00221     static uint32_t frameCount;
00222     static int8_t menu(const char* const* items, uint8_t length);
00223     static char* filemenu(char*);
00224     static char* filemenu();
00225     static void keyboard(char* text, uint8_t length);
00226     static void popup(const char* text, uint8_t duration);
00227     static void setFrameRate(uint8_t fps);
00228     static uint8_t getFrameRate();  
00229     static void pickRandomSeed();
00230 
00231     static uint8_t getCpuLoad();
00232     static uint16_t getFreeRam();
00233 
00234     static bool collidePointRect(int16_t x1, int16_t y1 ,int16_t x2 ,int16_t y2, int16_t w, int16_t h);
00235     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);
00236     static bool collideBitmapBitmap(int16_t x1, int16_t y1, const uint8_t* b1, int16_t x2, int16_t y2, const uint8_t* b2);
00237 
00238 private:
00239     static uint8_t timePerFrame;
00240     static uint32_t nextFrameMillis;
00241     static void updatePopup();
00242     static const char* popupText;
00243     static uint8_t popupTimeLeft;
00244     static void displayBattery();
00245     static uint16_t frameDurationMicros;
00246     static uint32_t frameStartMicros, frameEndMicros;
00247     static uint8_t startMenuTimer;
00248     static int updateLoader(uint32_t,uint32_t);
00249     static uint32_t fps_refreshtime;
00250     static uint32_t fps_frameCount;
00251 
00252 public:
00253     static uint8_t volbar_visible;
00254     static void drawvolbar(int,int,int, bool);
00255     static void askLoader();
00256     static void jumpToLoader();
00257 };
00258 
00259 // this is the instance used by the system
00260 extern Core core;
00261 
00262 
00263 }
00264 
00265 #endif // POKITTOCORE_H
00266 
00267 
00268