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_HW/HWButtons.cpp@43:6183b12dd99c, 2018-05-01 (annotated)
- Committer:
- Pokitto
- Date:
- Tue May 01 18:42:56 2018 +0000
- Revision:
- 43:6183b12dd99c
- Child:
- 68:61a4ccb0a4b6
New volume control;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pokitto | 43:6183b12dd99c | 1 | /**************************************************************************/ |
Pokitto | 43:6183b12dd99c | 2 | /*! |
Pokitto | 43:6183b12dd99c | 3 | @file HWButtons.cpp |
Pokitto | 43:6183b12dd99c | 4 | @author Jonne Valola |
Pokitto | 43:6183b12dd99c | 5 | |
Pokitto | 43:6183b12dd99c | 6 | @section LICENSE |
Pokitto | 43:6183b12dd99c | 7 | |
Pokitto | 43:6183b12dd99c | 8 | Software License Agreement (BSD License) |
Pokitto | 43:6183b12dd99c | 9 | |
Pokitto | 43:6183b12dd99c | 10 | Copyright (c) 2016, Jonne Valola |
Pokitto | 43:6183b12dd99c | 11 | All rights reserved. |
Pokitto | 43:6183b12dd99c | 12 | |
Pokitto | 43:6183b12dd99c | 13 | Redistribution and use in source and binary forms, with or without |
Pokitto | 43:6183b12dd99c | 14 | modification, are permitted provided that the following conditions are met: |
Pokitto | 43:6183b12dd99c | 15 | 1. Redistributions of source code must retain the above copyright |
Pokitto | 43:6183b12dd99c | 16 | notice, this list of conditions and the following disclaimer. |
Pokitto | 43:6183b12dd99c | 17 | 2. Redistributions in binary form must reproduce the above copyright |
Pokitto | 43:6183b12dd99c | 18 | notice, this list of conditions and the following disclaimer in the |
Pokitto | 43:6183b12dd99c | 19 | documentation and/or other materials provided with the distribution. |
Pokitto | 43:6183b12dd99c | 20 | 3. Neither the name of the copyright holders nor the |
Pokitto | 43:6183b12dd99c | 21 | names of its contributors may be used to endorse or promote products |
Pokitto | 43:6183b12dd99c | 22 | derived from this software without specific prior written permission. |
Pokitto | 43:6183b12dd99c | 23 | |
Pokitto | 43:6183b12dd99c | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
Pokitto | 43:6183b12dd99c | 25 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Pokitto | 43:6183b12dd99c | 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Pokitto | 43:6183b12dd99c | 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY |
Pokitto | 43:6183b12dd99c | 28 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Pokitto | 43:6183b12dd99c | 29 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Pokitto | 43:6183b12dd99c | 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
Pokitto | 43:6183b12dd99c | 31 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Pokitto | 43:6183b12dd99c | 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Pokitto | 43:6183b12dd99c | 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Pokitto | 43:6183b12dd99c | 34 | */ |
Pokitto | 43:6183b12dd99c | 35 | /**************************************************************************/ |
Pokitto | 43:6183b12dd99c | 36 | |
Pokitto | 43:6183b12dd99c | 37 | #include "HWButtons.h" |
Pokitto | 43:6183b12dd99c | 38 | #include "PokittoCore.h" |
Pokitto | 43:6183b12dd99c | 39 | #include "PokittoSound.h" |
Pokitto | 43:6183b12dd99c | 40 | #include "PokittoDisplay.h" |
Pokitto | 43:6183b12dd99c | 41 | |
Pokitto | 43:6183b12dd99c | 42 | Pokitto::Sound _s; |
Pokitto | 43:6183b12dd99c | 43 | Pokitto::Display _bd; |
Pokitto | 43:6183b12dd99c | 44 | |
Pokitto | 43:6183b12dd99c | 45 | using namespace mbed; |
Pokitto | 43:6183b12dd99c | 46 | |
Pokitto | 43:6183b12dd99c | 47 | InterruptIn ABtn(POK_BTN_A_PIN); |
Pokitto | 43:6183b12dd99c | 48 | InterruptIn BBtn(POK_BTN_B_PIN); |
Pokitto | 43:6183b12dd99c | 49 | InterruptIn CBtn(POK_BTN_C_PIN); |
Pokitto | 43:6183b12dd99c | 50 | InterruptIn UBtn(POK_BTN_UP_PIN); |
Pokitto | 43:6183b12dd99c | 51 | InterruptIn DBtn(POK_BTN_DOWN_PIN); |
Pokitto | 43:6183b12dd99c | 52 | InterruptIn LBtn(POK_BTN_LEFT_PIN); |
Pokitto | 43:6183b12dd99c | 53 | InterruptIn RBtn(POK_BTN_RIGHT_PIN); |
Pokitto | 43:6183b12dd99c | 54 | |
Pokitto | 43:6183b12dd99c | 55 | #define BS_IDLE 0 |
Pokitto | 43:6183b12dd99c | 56 | #define BS_DOWN 1 |
Pokitto | 43:6183b12dd99c | 57 | #define BS_UP 2 |
Pokitto | 43:6183b12dd99c | 58 | |
Pokitto | 43:6183b12dd99c | 59 | uint8_t Pokitto::heldStates[NUM_BTN]; |
Pokitto | 43:6183b12dd99c | 60 | bool vol_control_clicked=false; |
Pokitto | 43:6183b12dd99c | 61 | |
Pokitto | 43:6183b12dd99c | 62 | void APressed() { |
Pokitto | 43:6183b12dd99c | 63 | Pokitto::heldStates[BTN_A] = 1; |
Pokitto | 43:6183b12dd99c | 64 | } |
Pokitto | 43:6183b12dd99c | 65 | void AReleased() { |
Pokitto | 43:6183b12dd99c | 66 | Pokitto::heldStates[BTN_A] = 0; |
Pokitto | 43:6183b12dd99c | 67 | } |
Pokitto | 43:6183b12dd99c | 68 | void BPressed() { Pokitto::heldStates[BTN_B] = 1; } |
Pokitto | 43:6183b12dd99c | 69 | void BReleased() { Pokitto::heldStates[BTN_B] = 0; } |
Pokitto | 43:6183b12dd99c | 70 | void CPressed() { |
Pokitto | 43:6183b12dd99c | 71 | Pokitto::heldStates[BTN_C] = 1; |
Pokitto | 43:6183b12dd99c | 72 | } |
Pokitto | 43:6183b12dd99c | 73 | void CReleased() { Pokitto::heldStates[BTN_C] = 0; } |
Pokitto | 43:6183b12dd99c | 74 | void UPressed() { Pokitto::heldStates[BTN_UP] = 1; } |
Pokitto | 43:6183b12dd99c | 75 | void UReleased() { Pokitto::heldStates[BTN_UP] = 0; } |
Pokitto | 43:6183b12dd99c | 76 | void DPressed() { Pokitto::heldStates[BTN_DOWN] = 1; } |
Pokitto | 43:6183b12dd99c | 77 | void DReleased() { Pokitto::heldStates[BTN_DOWN] = 0; } |
Pokitto | 43:6183b12dd99c | 78 | void RPressed() { |
Pokitto | 43:6183b12dd99c | 79 | /* Hardware volume control */ |
Pokitto | 43:6183b12dd99c | 80 | if (Pokitto::heldStates[BTN_C]) _s.volumeUp(); |
Pokitto | 43:6183b12dd99c | 81 | else Pokitto::heldStates[BTN_RIGHT] = 1; |
Pokitto | 43:6183b12dd99c | 82 | } |
Pokitto | 43:6183b12dd99c | 83 | void RReleased() { Pokitto::heldStates[BTN_RIGHT] = 0; } |
Pokitto | 43:6183b12dd99c | 84 | void LPressed() { |
Pokitto | 43:6183b12dd99c | 85 | /* Hardware volume control */ |
Pokitto | 43:6183b12dd99c | 86 | if (Pokitto::heldStates[BTN_C]) _s.volumeDown(); |
Pokitto | 43:6183b12dd99c | 87 | else Pokitto::heldStates[BTN_LEFT] = 1; |
Pokitto | 43:6183b12dd99c | 88 | } |
Pokitto | 43:6183b12dd99c | 89 | void LReleased() { Pokitto::heldStates[BTN_LEFT] = 0; } |
Pokitto | 43:6183b12dd99c | 90 | |
Pokitto | 43:6183b12dd99c | 91 | static inline void ClearPinInt(LPC_PIN_INT_T *pPININT, uint32_t pins) |
Pokitto | 43:6183b12dd99c | 92 | { |
Pokitto | 43:6183b12dd99c | 93 | pPININT->IST = pins; |
Pokitto | 43:6183b12dd99c | 94 | } |
Pokitto | 43:6183b12dd99c | 95 | |
Pokitto | 43:6183b12dd99c | 96 | void PIN_INT0_IRQHandler(void) |
Pokitto | 43:6183b12dd99c | 97 | { |
Pokitto | 43:6183b12dd99c | 98 | //Pokitto::heldStates[BTN_A] = 1 - Pokitto::heldStates[BTN_A]; |
Pokitto | 43:6183b12dd99c | 99 | //uint32_t pins = ((LPC_PIN_INT_T*)LPC_PININT)->FALL; |
Pokitto | 43:6183b12dd99c | 100 | //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<0)) Pokitto::heldStates[BTN_A] = 1; |
Pokitto | 43:6183b12dd99c | 101 | //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<0)) Pokitto::heldStates[BTN_A] = 0; |
Pokitto | 43:6183b12dd99c | 102 | Pokitto::heldStates[BTN_A]=ABtn.read(); |
Pokitto | 43:6183b12dd99c | 103 | ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(0)); |
Pokitto | 43:6183b12dd99c | 104 | } |
Pokitto | 43:6183b12dd99c | 105 | |
Pokitto | 43:6183b12dd99c | 106 | void PIN_INT1_IRQHandler(void) |
Pokitto | 43:6183b12dd99c | 107 | { |
Pokitto | 43:6183b12dd99c | 108 | //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<1)) Pokitto::heldStates[BTN_B] = 1; |
Pokitto | 43:6183b12dd99c | 109 | //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<1)) Pokitto::heldStates[BTN_B] = 0; |
Pokitto | 43:6183b12dd99c | 110 | Pokitto::heldStates[BTN_B]=BBtn.read(); |
Pokitto | 43:6183b12dd99c | 111 | ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(1)); |
Pokitto | 43:6183b12dd99c | 112 | } |
Pokitto | 43:6183b12dd99c | 113 | |
Pokitto | 43:6183b12dd99c | 114 | void PIN_INT2_IRQHandler(void) |
Pokitto | 43:6183b12dd99c | 115 | { |
Pokitto | 43:6183b12dd99c | 116 | //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<2)) Pokitto::heldStates[BTN_C] = 1; |
Pokitto | 43:6183b12dd99c | 117 | //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<2)) Pokitto::heldStates[BTN_C] = 0; |
Pokitto | 43:6183b12dd99c | 118 | Pokitto::heldStates[BTN_C]=CBtn.read(); |
Pokitto | 43:6183b12dd99c | 119 | ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(2)); |
Pokitto | 43:6183b12dd99c | 120 | } |
Pokitto | 43:6183b12dd99c | 121 | |
Pokitto | 43:6183b12dd99c | 122 | void PIN_INT3_IRQHandler(void) |
Pokitto | 43:6183b12dd99c | 123 | { |
Pokitto | 43:6183b12dd99c | 124 | //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<3)) Pokitto::heldStates[BTN_UP] = 1; |
Pokitto | 43:6183b12dd99c | 125 | //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<3)) Pokitto::heldStates[BTN_UP] = 0; |
Pokitto | 43:6183b12dd99c | 126 | Pokitto::heldStates[BTN_UP]=UBtn.read(); |
Pokitto | 43:6183b12dd99c | 127 | ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(3)); |
Pokitto | 43:6183b12dd99c | 128 | } |
Pokitto | 43:6183b12dd99c | 129 | |
Pokitto | 43:6183b12dd99c | 130 | void PIN_INT4_IRQHandler(void) |
Pokitto | 43:6183b12dd99c | 131 | { |
Pokitto | 43:6183b12dd99c | 132 | //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<4)) Pokitto::heldStates[BTN_DOWN] = 1; |
Pokitto | 43:6183b12dd99c | 133 | //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<4)) Pokitto::heldStates[BTN_DOWN] = 0; |
Pokitto | 43:6183b12dd99c | 134 | Pokitto::heldStates[BTN_DOWN]=DBtn.read(); |
Pokitto | 43:6183b12dd99c | 135 | ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(4)); |
Pokitto | 43:6183b12dd99c | 136 | } |
Pokitto | 43:6183b12dd99c | 137 | |
Pokitto | 43:6183b12dd99c | 138 | void PIN_INT5_IRQHandler(void) |
Pokitto | 43:6183b12dd99c | 139 | { |
Pokitto | 43:6183b12dd99c | 140 | /* Hardware volume control */ |
Pokitto | 43:6183b12dd99c | 141 | //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<5)) Pokitto::heldStates[BTN_LEFT] = 1; |
Pokitto | 43:6183b12dd99c | 142 | //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<5)) Pokitto::heldStates[BTN_LEFT] = 0; |
Pokitto | 43:6183b12dd99c | 143 | Pokitto::heldStates[BTN_C]=CBtn.read(); |
Pokitto | 43:6183b12dd99c | 144 | Pokitto::heldStates[BTN_LEFT]=LBtn.read(); |
Pokitto | 43:6183b12dd99c | 145 | if (Pokitto::heldStates[BTN_C] && Pokitto::heldStates[BTN_LEFT]) |
Pokitto | 43:6183b12dd99c | 146 | { |
Pokitto | 43:6183b12dd99c | 147 | if (!vol_control_clicked) _s.volumeDown(); |
Pokitto | 43:6183b12dd99c | 148 | Pokitto::heldStates[BTN_LEFT]=0; //do not do normal button operation |
Pokitto | 43:6183b12dd99c | 149 | vol_control_clicked=true; |
Pokitto | 43:6183b12dd99c | 150 | } else vol_control_clicked=false; |
Pokitto | 43:6183b12dd99c | 151 | |
Pokitto | 43:6183b12dd99c | 152 | ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(5)); |
Pokitto | 43:6183b12dd99c | 153 | } |
Pokitto | 43:6183b12dd99c | 154 | |
Pokitto | 43:6183b12dd99c | 155 | void PIN_INT6_IRQHandler(void) |
Pokitto | 43:6183b12dd99c | 156 | { |
Pokitto | 43:6183b12dd99c | 157 | /* Hardware volume control */ |
Pokitto | 43:6183b12dd99c | 158 | //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<6)) Pokitto::heldStates[BTN_RIGHT] = 1; |
Pokitto | 43:6183b12dd99c | 159 | //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<6)) Pokitto::heldStates[BTN_RIGHT] = 0; |
Pokitto | 43:6183b12dd99c | 160 | Pokitto::heldStates[BTN_C]=CBtn.read(); |
Pokitto | 43:6183b12dd99c | 161 | Pokitto::heldStates[BTN_RIGHT]=RBtn.read(); |
Pokitto | 43:6183b12dd99c | 162 | if (Pokitto::heldStates[BTN_C] && Pokitto::heldStates[BTN_RIGHT]) |
Pokitto | 43:6183b12dd99c | 163 | { |
Pokitto | 43:6183b12dd99c | 164 | if (!vol_control_clicked) _s.volumeUp(); |
Pokitto | 43:6183b12dd99c | 165 | Pokitto::heldStates[BTN_RIGHT]=0; //do not do normal button operation |
Pokitto | 43:6183b12dd99c | 166 | vol_control_clicked=true; |
Pokitto | 43:6183b12dd99c | 167 | } else vol_control_clicked=false; |
Pokitto | 43:6183b12dd99c | 168 | |
Pokitto | 43:6183b12dd99c | 169 | ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(6)); |
Pokitto | 43:6183b12dd99c | 170 | } |
Pokitto | 43:6183b12dd99c | 171 | |
Pokitto | 43:6183b12dd99c | 172 | |
Pokitto | 43:6183b12dd99c | 173 | void Pokitto::initButtons() { |
Pokitto | 43:6183b12dd99c | 174 | ABtn.fall(&AReleased); |
Pokitto | 43:6183b12dd99c | 175 | ABtn.rise(&APressed); |
Pokitto | 43:6183b12dd99c | 176 | BBtn.fall(&BReleased); |
Pokitto | 43:6183b12dd99c | 177 | BBtn.rise(&BPressed); |
Pokitto | 43:6183b12dd99c | 178 | CBtn.fall(&CReleased); |
Pokitto | 43:6183b12dd99c | 179 | CBtn.rise(&CPressed); |
Pokitto | 43:6183b12dd99c | 180 | UBtn.fall(&UReleased); |
Pokitto | 43:6183b12dd99c | 181 | UBtn.rise(&UPressed); |
Pokitto | 43:6183b12dd99c | 182 | DBtn.fall(&DReleased); |
Pokitto | 43:6183b12dd99c | 183 | DBtn.rise(&DPressed); |
Pokitto | 43:6183b12dd99c | 184 | LBtn.fall(&LReleased); |
Pokitto | 43:6183b12dd99c | 185 | LBtn.rise(&LPressed); |
Pokitto | 43:6183b12dd99c | 186 | RBtn.fall(&RReleased); |
Pokitto | 43:6183b12dd99c | 187 | RBtn.rise(&RPressed); |
Pokitto | 43:6183b12dd99c | 188 | NVIC_SetVector((IRQn_Type)(PIN_INT0_IRQn), (uint32_t)&PIN_INT0_IRQHandler); |
Pokitto | 43:6183b12dd99c | 189 | NVIC_SetVector((IRQn_Type)(PIN_INT1_IRQn), (uint32_t)&PIN_INT1_IRQHandler); |
Pokitto | 43:6183b12dd99c | 190 | NVIC_SetVector((IRQn_Type)(PIN_INT2_IRQn), (uint32_t)&PIN_INT2_IRQHandler); |
Pokitto | 43:6183b12dd99c | 191 | NVIC_SetVector((IRQn_Type)(PIN_INT3_IRQn), (uint32_t)&PIN_INT3_IRQHandler); |
Pokitto | 43:6183b12dd99c | 192 | NVIC_SetVector((IRQn_Type)(PIN_INT4_IRQn), (uint32_t)&PIN_INT4_IRQHandler); |
Pokitto | 43:6183b12dd99c | 193 | NVIC_SetVector((IRQn_Type)(PIN_INT5_IRQn), (uint32_t)&PIN_INT5_IRQHandler); |
Pokitto | 43:6183b12dd99c | 194 | NVIC_SetVector((IRQn_Type)(PIN_INT6_IRQn), (uint32_t)&PIN_INT6_IRQHandler); |
Pokitto | 43:6183b12dd99c | 195 | } |
Pokitto | 43:6183b12dd99c | 196 | |
Pokitto | 43:6183b12dd99c | 197 | uint8_t Pokitto::Core::aBtn() { |
Pokitto | 43:6183b12dd99c | 198 | return Pokitto::heldStates[BTN_A]; |
Pokitto | 43:6183b12dd99c | 199 | } |
Pokitto | 43:6183b12dd99c | 200 | |
Pokitto | 43:6183b12dd99c | 201 | uint8_t Pokitto::Core::bBtn() { |
Pokitto | 43:6183b12dd99c | 202 | return Pokitto::heldStates[BTN_B]; |
Pokitto | 43:6183b12dd99c | 203 | } |
Pokitto | 43:6183b12dd99c | 204 | |
Pokitto | 43:6183b12dd99c | 205 | uint8_t Pokitto::Core::cBtn() { |
Pokitto | 43:6183b12dd99c | 206 | return Pokitto::heldStates[BTN_C]; |
Pokitto | 43:6183b12dd99c | 207 | } |
Pokitto | 43:6183b12dd99c | 208 | |
Pokitto | 43:6183b12dd99c | 209 | uint8_t Pokitto::Core::upBtn() { |
Pokitto | 43:6183b12dd99c | 210 | return Pokitto::heldStates[BTN_UP]; |
Pokitto | 43:6183b12dd99c | 211 | } |
Pokitto | 43:6183b12dd99c | 212 | uint8_t Pokitto::Core::downBtn() { |
Pokitto | 43:6183b12dd99c | 213 | return Pokitto::heldStates[BTN_DOWN]; |
Pokitto | 43:6183b12dd99c | 214 | } |
Pokitto | 43:6183b12dd99c | 215 | |
Pokitto | 43:6183b12dd99c | 216 | uint8_t Pokitto::Core::leftBtn() { |
Pokitto | 43:6183b12dd99c | 217 | return Pokitto::heldStates[BTN_LEFT]; |
Pokitto | 43:6183b12dd99c | 218 | } |
Pokitto | 43:6183b12dd99c | 219 | uint8_t Pokitto::Core::rightBtn() { |
Pokitto | 43:6183b12dd99c | 220 | return Pokitto::heldStates[BTN_RIGHT]; |
Pokitto | 43:6183b12dd99c | 221 | } |
Pokitto | 43:6183b12dd99c | 222 |