PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Embed:
(wiki syntax)
Show/hide line numbers
HWButtons.cpp
Go to the documentation of this file.
00001 /**************************************************************************/ 00002 /*! 00003 @file HWButtons.cpp 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 #include "HWButtons.h " 00038 #include "PokittoCore.h " 00039 #include "PokittoSound.h " 00040 #include "PokittoDisplay.h " 00041 00042 Pokitto::Sound _s; 00043 Pokitto::Display _bd; 00044 00045 using namespace mbed; 00046 00047 InterruptIn ABtn(POK_BTN_A_PIN); 00048 InterruptIn BBtn(POK_BTN_B_PIN); 00049 InterruptIn CBtn(POK_BTN_C_PIN); 00050 InterruptIn UBtn(POK_BTN_UP_PIN); 00051 InterruptIn DBtn(POK_BTN_DOWN_PIN); 00052 InterruptIn LBtn(POK_BTN_LEFT_PIN); 00053 InterruptIn RBtn(POK_BTN_RIGHT_PIN); 00054 00055 #define BS_IDLE 0 00056 #define BS_DOWN 1 00057 #define BS_UP 2 00058 00059 uint8_t Pokitto::heldStates[NUM_BTN]; 00060 bool vol_control_clicked=false; 00061 00062 void APressed() { 00063 Pokitto::heldStates[BTN_A] = 1; 00064 } 00065 void AReleased() { 00066 Pokitto::heldStates[BTN_A] = 0; 00067 } 00068 void BPressed() { Pokitto::heldStates[BTN_B] = 1; } 00069 void BReleased() { Pokitto::heldStates[BTN_B] = 0; } 00070 void CPressed() { 00071 Pokitto::heldStates[BTN_C] = 1; 00072 } 00073 void CReleased() { Pokitto::heldStates[BTN_C] = 0; } 00074 void UPressed() { Pokitto::heldStates[BTN_UP] = 1; } 00075 void UReleased() { Pokitto::heldStates[BTN_UP] = 0; } 00076 void DPressed() { Pokitto::heldStates[BTN_DOWN] = 1; } 00077 void DReleased() { Pokitto::heldStates[BTN_DOWN] = 0; } 00078 void RPressed() { 00079 /* Hardware volume control */ 00080 if (Pokitto::heldStates[BTN_C]) _s.volumeUp(); 00081 else Pokitto::heldStates[BTN_RIGHT] = 1; 00082 } 00083 void RReleased() { Pokitto::heldStates[BTN_RIGHT] = 0; } 00084 void LPressed() { 00085 /* Hardware volume control */ 00086 if (Pokitto::heldStates[BTN_C]) _s.volumeDown(); 00087 else Pokitto::heldStates[BTN_LEFT] = 1; 00088 } 00089 void LReleased() { Pokitto::heldStates[BTN_LEFT] = 0; } 00090 00091 static inline void ClearPinInt(LPC_PIN_INT_T *pPININT, uint32_t pins) 00092 { 00093 pPININT->IST = pins; 00094 } 00095 00096 void PIN_INT0_IRQHandler(void) 00097 { 00098 //Pokitto::heldStates[BTN_A] = 1 - Pokitto::heldStates[BTN_A]; 00099 //uint32_t pins = ((LPC_PIN_INT_T*)LPC_PININT)->FALL; 00100 //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<0)) Pokitto::heldStates[BTN_A] = 1; 00101 //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<0)) Pokitto::heldStates[BTN_A] = 0; 00102 Pokitto::heldStates[BTN_A]=ABtn.read(); 00103 ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(0)); 00104 } 00105 00106 void PIN_INT1_IRQHandler(void) 00107 { 00108 //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<1)) Pokitto::heldStates[BTN_B] = 1; 00109 //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<1)) Pokitto::heldStates[BTN_B] = 0; 00110 Pokitto::heldStates[BTN_B]=BBtn.read(); 00111 ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(1)); 00112 } 00113 00114 void PIN_INT2_IRQHandler(void) 00115 { 00116 //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<2)) Pokitto::heldStates[BTN_C] = 1; 00117 //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<2)) Pokitto::heldStates[BTN_C] = 0; 00118 Pokitto::heldStates[BTN_C]=CBtn.read(); 00119 ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(2)); 00120 } 00121 00122 void PIN_INT3_IRQHandler(void) 00123 { 00124 //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<3)) Pokitto::heldStates[BTN_UP] = 1; 00125 //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<3)) Pokitto::heldStates[BTN_UP] = 0; 00126 Pokitto::heldStates[BTN_UP]=UBtn.read(); 00127 ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(3)); 00128 } 00129 00130 void PIN_INT4_IRQHandler(void) 00131 { 00132 //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<4)) Pokitto::heldStates[BTN_DOWN] = 1; 00133 //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<4)) Pokitto::heldStates[BTN_DOWN] = 0; 00134 Pokitto::heldStates[BTN_DOWN]=DBtn.read(); 00135 ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(4)); 00136 } 00137 00138 void PIN_INT5_IRQHandler(void) 00139 { 00140 /* Hardware volume control */ 00141 //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<5)) Pokitto::heldStates[BTN_LEFT] = 1; 00142 //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<5)) Pokitto::heldStates[BTN_LEFT] = 0; 00143 Pokitto::heldStates[BTN_C]=CBtn.read(); 00144 Pokitto::heldStates[BTN_LEFT]=LBtn.read(); 00145 if (Pokitto::heldStates[BTN_C] && Pokitto::heldStates[BTN_LEFT]) 00146 { 00147 if (!vol_control_clicked) _s.volumeDown(); 00148 Pokitto::heldStates[BTN_LEFT]=0; //do not do normal button operation 00149 vol_control_clicked=true; 00150 } else vol_control_clicked=false; 00151 00152 ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(5)); 00153 } 00154 00155 void PIN_INT6_IRQHandler(void) 00156 { 00157 /* Hardware volume control */ 00158 //if ((((LPC_PIN_INT_T*)LPC_PININT)->RISE)&(1<<6)) Pokitto::heldStates[BTN_RIGHT] = 1; 00159 //else if ((((LPC_PIN_INT_T*)LPC_PININT)->FALL)&(1<<6)) Pokitto::heldStates[BTN_RIGHT] = 0; 00160 Pokitto::heldStates[BTN_C]=CBtn.read(); 00161 Pokitto::heldStates[BTN_RIGHT]=RBtn.read(); 00162 if (Pokitto::heldStates[BTN_C] && Pokitto::heldStates[BTN_RIGHT]) 00163 { 00164 if (!vol_control_clicked) _s.volumeUp(); 00165 Pokitto::heldStates[BTN_RIGHT]=0; //do not do normal button operation 00166 vol_control_clicked=true; 00167 } else vol_control_clicked=false; 00168 00169 ClearPinInt((LPC_PIN_INT_T *)LPC_PININT, PININTCH(6)); 00170 } 00171 00172 00173 void Pokitto::initButtons() { 00174 ABtn.fall(&AReleased); 00175 ABtn.rise(&APressed); 00176 BBtn.fall(&BReleased); 00177 BBtn.rise(&BPressed); 00178 CBtn.fall(&CReleased); 00179 CBtn.rise(&CPressed); 00180 UBtn.fall(&UReleased); 00181 UBtn.rise(&UPressed); 00182 DBtn.fall(&DReleased); 00183 DBtn.rise(&DPressed); 00184 LBtn.fall(&LReleased); 00185 LBtn.rise(&LPressed); 00186 RBtn.fall(&RReleased); 00187 RBtn.rise(&RPressed); 00188 NVIC_SetVector((IRQn_Type)(PIN_INT0_IRQn), (uint32_t)&PIN_INT0_IRQHandler); 00189 NVIC_SetVector((IRQn_Type)(PIN_INT1_IRQn), (uint32_t)&PIN_INT1_IRQHandler); 00190 NVIC_SetVector((IRQn_Type)(PIN_INT2_IRQn), (uint32_t)&PIN_INT2_IRQHandler); 00191 NVIC_SetVector((IRQn_Type)(PIN_INT3_IRQn), (uint32_t)&PIN_INT3_IRQHandler); 00192 NVIC_SetVector((IRQn_Type)(PIN_INT4_IRQn), (uint32_t)&PIN_INT4_IRQHandler); 00193 NVIC_SetVector((IRQn_Type)(PIN_INT5_IRQn), (uint32_t)&PIN_INT5_IRQHandler); 00194 NVIC_SetVector((IRQn_Type)(PIN_INT6_IRQn), (uint32_t)&PIN_INT6_IRQHandler); 00195 } 00196 00197 uint8_t Pokitto::Core::aBtn() { 00198 return Pokitto::heldStates[BTN_A]; 00199 } 00200 00201 uint8_t Pokitto::Core::bBtn() { 00202 return Pokitto::heldStates[BTN_B]; 00203 } 00204 00205 uint8_t Pokitto::Core::cBtn() { 00206 return Pokitto::heldStates[BTN_C]; 00207 } 00208 00209 uint8_t Pokitto::Core::upBtn() { 00210 return Pokitto::heldStates[BTN_UP]; 00211 } 00212 uint8_t Pokitto::Core::downBtn() { 00213 return Pokitto::heldStates[BTN_DOWN]; 00214 } 00215 00216 uint8_t Pokitto::Core::leftBtn() { 00217 return Pokitto::heldStates[BTN_LEFT]; 00218 } 00219 uint8_t Pokitto::Core::rightBtn() { 00220 return Pokitto::heldStates[BTN_RIGHT]; 00221 } 00222
Generated on Tue Jul 12 2022 21:03:50 by 1.7.2