PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Dependents: YATTT sd_map_test cPong SnowDemo ... more
PokittoLib
Library for programming Pokitto hardware
How to Use
- Import this library to online compiler (see button "import" on the right hand side
- DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
- Change My_settings.h according to your project
- Start coding!
POKITTO_CORE/PokittoButtons.h@0:e8b8f36b4505, 2017-09-18 (annotated)
- Committer:
- Pokitto
- Date:
- Mon Sep 18 11:47:51 2017 +0000
- Revision:
- 0:e8b8f36b4505
Initial;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pokitto | 0:e8b8f36b4505 | 1 | /**************************************************************************/ |
Pokitto | 0:e8b8f36b4505 | 2 | /*! |
Pokitto | 0:e8b8f36b4505 | 3 | @file PokittoButtons.h |
Pokitto | 0:e8b8f36b4505 | 4 | @author Jonne Valola |
Pokitto | 0:e8b8f36b4505 | 5 | |
Pokitto | 0:e8b8f36b4505 | 6 | @section LICENSE |
Pokitto | 0:e8b8f36b4505 | 7 | |
Pokitto | 0:e8b8f36b4505 | 8 | Software License Agreement (BSD License) |
Pokitto | 0:e8b8f36b4505 | 9 | |
Pokitto | 0:e8b8f36b4505 | 10 | Copyright (c) 2016, Jonne Valola |
Pokitto | 0:e8b8f36b4505 | 11 | All rights reserved. |
Pokitto | 0:e8b8f36b4505 | 12 | |
Pokitto | 0:e8b8f36b4505 | 13 | Redistribution and use in source and binary forms, with or without |
Pokitto | 0:e8b8f36b4505 | 14 | modification, are permitted provided that the following conditions are met: |
Pokitto | 0:e8b8f36b4505 | 15 | 1. Redistributions of source code must retain the above copyright |
Pokitto | 0:e8b8f36b4505 | 16 | notice, this list of conditions and the following disclaimer. |
Pokitto | 0:e8b8f36b4505 | 17 | 2. Redistributions in binary form must reproduce the above copyright |
Pokitto | 0:e8b8f36b4505 | 18 | notice, this list of conditions and the following disclaimer in the |
Pokitto | 0:e8b8f36b4505 | 19 | documentation and/or other materials provided with the distribution. |
Pokitto | 0:e8b8f36b4505 | 20 | 3. Neither the name of the copyright holders nor the |
Pokitto | 0:e8b8f36b4505 | 21 | names of its contributors may be used to endorse or promote products |
Pokitto | 0:e8b8f36b4505 | 22 | derived from this software without specific prior written permission. |
Pokitto | 0:e8b8f36b4505 | 23 | |
Pokitto | 0:e8b8f36b4505 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
Pokitto | 0:e8b8f36b4505 | 25 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Pokitto | 0:e8b8f36b4505 | 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Pokitto | 0:e8b8f36b4505 | 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY |
Pokitto | 0:e8b8f36b4505 | 28 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Pokitto | 0:e8b8f36b4505 | 29 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Pokitto | 0:e8b8f36b4505 | 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
Pokitto | 0:e8b8f36b4505 | 31 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Pokitto | 0:e8b8f36b4505 | 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Pokitto | 0:e8b8f36b4505 | 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Pokitto | 0:e8b8f36b4505 | 34 | */ |
Pokitto | 0:e8b8f36b4505 | 35 | /**************************************************************************/ |
Pokitto | 0:e8b8f36b4505 | 36 | |
Pokitto | 0:e8b8f36b4505 | 37 | |
Pokitto | 0:e8b8f36b4505 | 38 | #ifndef POKITTOBUTTONS_H |
Pokitto | 0:e8b8f36b4505 | 39 | #define POKITTOBUTTONS_H |
Pokitto | 0:e8b8f36b4505 | 40 | |
Pokitto | 0:e8b8f36b4505 | 41 | #include <stdint.h> |
Pokitto | 0:e8b8f36b4505 | 42 | #include "Pokitto_settings.h" |
Pokitto | 0:e8b8f36b4505 | 43 | #include "GBcompatibility.h" |
Pokitto | 0:e8b8f36b4505 | 44 | #include "PokittoGlobs.h" |
Pokitto | 0:e8b8f36b4505 | 45 | |
Pokitto | 0:e8b8f36b4505 | 46 | #ifndef POK_SIM |
Pokitto | 0:e8b8f36b4505 | 47 | #include "HWButtons.h" |
Pokitto | 0:e8b8f36b4505 | 48 | #define CHWLONGPRESSTIMEOUT 100 |
Pokitto | 0:e8b8f36b4505 | 49 | #else |
Pokitto | 0:e8b8f36b4505 | 50 | #include "PokittoSimulator.h" |
Pokitto | 0:e8b8f36b4505 | 51 | #define CHWLONGPRESSTIMEOUT 1000 |
Pokitto | 0:e8b8f36b4505 | 52 | #endif // POK_SIM |
Pokitto | 0:e8b8f36b4505 | 53 | |
Pokitto | 0:e8b8f36b4505 | 54 | |
Pokitto | 0:e8b8f36b4505 | 55 | namespace Pokitto { |
Pokitto | 0:e8b8f36b4505 | 56 | |
Pokitto | 0:e8b8f36b4505 | 57 | class Buttons { |
Pokitto | 0:e8b8f36b4505 | 58 | public: |
Pokitto | 0:e8b8f36b4505 | 59 | // Original functions |
Pokitto | 0:e8b8f36b4505 | 60 | static uint8_t buttons_state, buttons_held, buttons_released; |
Pokitto | 0:e8b8f36b4505 | 61 | static void initButtons(); |
Pokitto | 0:e8b8f36b4505 | 62 | static void pollButtons(); |
Pokitto | 0:e8b8f36b4505 | 63 | static uint8_t leftBtn(); |
Pokitto | 0:e8b8f36b4505 | 64 | static uint8_t rightBtn(); |
Pokitto | 0:e8b8f36b4505 | 65 | static uint8_t upBtn(); |
Pokitto | 0:e8b8f36b4505 | 66 | static uint8_t downBtn(); |
Pokitto | 0:e8b8f36b4505 | 67 | static uint8_t aBtn(); |
Pokitto | 0:e8b8f36b4505 | 68 | static uint8_t bBtn(); |
Pokitto | 0:e8b8f36b4505 | 69 | static uint8_t cBtn(); |
Pokitto | 0:e8b8f36b4505 | 70 | static uint8_t leftHeld(); |
Pokitto | 0:e8b8f36b4505 | 71 | static uint8_t rightHeld(); |
Pokitto | 0:e8b8f36b4505 | 72 | static uint8_t upHeld(); |
Pokitto | 0:e8b8f36b4505 | 73 | static uint8_t downHeld(); |
Pokitto | 0:e8b8f36b4505 | 74 | static uint8_t aHeld(); |
Pokitto | 0:e8b8f36b4505 | 75 | static uint8_t bHeld(); |
Pokitto | 0:e8b8f36b4505 | 76 | static uint8_t cHeld(); |
Pokitto | 0:e8b8f36b4505 | 77 | |
Pokitto | 0:e8b8f36b4505 | 78 | static uint8_t leftReleased(); |
Pokitto | 0:e8b8f36b4505 | 79 | static uint8_t rightReleased(); |
Pokitto | 0:e8b8f36b4505 | 80 | static uint8_t upReleased(); |
Pokitto | 0:e8b8f36b4505 | 81 | static uint8_t downReleased(); |
Pokitto | 0:e8b8f36b4505 | 82 | static uint8_t aReleased(); |
Pokitto | 0:e8b8f36b4505 | 83 | static uint8_t bReleased(); |
Pokitto | 0:e8b8f36b4505 | 84 | static uint8_t cReleased(); |
Pokitto | 0:e8b8f36b4505 | 85 | |
Pokitto | 0:e8b8f36b4505 | 86 | // GB compatibility functions |
Pokitto | 0:e8b8f36b4505 | 87 | static void begin(); |
Pokitto | 0:e8b8f36b4505 | 88 | static void update(); |
Pokitto | 0:e8b8f36b4505 | 89 | static bool pressed(uint8_t button); |
Pokitto | 0:e8b8f36b4505 | 90 | static bool released(uint8_t button); |
Pokitto | 0:e8b8f36b4505 | 91 | static bool held(uint8_t button, uint8_t time); |
Pokitto | 0:e8b8f36b4505 | 92 | static bool repeat(uint8_t button, uint8_t period); |
Pokitto | 0:e8b8f36b4505 | 93 | static uint8_t timeHeld(uint8_t button); |
Pokitto | 0:e8b8f36b4505 | 94 | static uint8_t pins[NUM_BTN]; |
Pokitto | 0:e8b8f36b4505 | 95 | static uint8_t states[NUM_BTN]; |
Pokitto | 0:e8b8f36b4505 | 96 | static uint8_t heldStates[NUM_BTN]; // additional, not GB based |
Pokitto | 0:e8b8f36b4505 | 97 | private: |
Pokitto | 0:e8b8f36b4505 | 98 | static uint16_t cHWLongPress; //forced hardware detection of C long press |
Pokitto | 0:e8b8f36b4505 | 99 | }; |
Pokitto | 0:e8b8f36b4505 | 100 | |
Pokitto | 0:e8b8f36b4505 | 101 | } |
Pokitto | 0:e8b8f36b4505 | 102 | |
Pokitto | 0:e8b8f36b4505 | 103 | #endif // POKITTOBUTTONS_H |
Pokitto | 0:e8b8f36b4505 | 104 | |
Pokitto | 0:e8b8f36b4505 | 105 | |
Pokitto | 0:e8b8f36b4505 | 106 | |
Pokitto | 0:e8b8f36b4505 | 107 | |
Pokitto | 0:e8b8f36b4505 | 108 | |
Pokitto | 0:e8b8f36b4505 | 109 |