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

Dependents:   Sensitive

Fork of PokittoLib by Jonne Valola

Committer:
spinal
Date:
Wed Oct 18 14:47:54 2017 +0000
Revision:
15:0bbe8f6fae32
Parent:
7:72f87b7c7400
direct lcd stuff used by sensitive

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 7:72f87b7c7400 1 /**************************************************************************/
Pokitto 7:72f87b7c7400 2 /*!
Pokitto 7:72f87b7c7400 3 @file HWButtons.cpp
Pokitto 7:72f87b7c7400 4 @author Jonne Valola
Pokitto 7:72f87b7c7400 5
Pokitto 7:72f87b7c7400 6 @section LICENSE
Pokitto 7:72f87b7c7400 7
Pokitto 7:72f87b7c7400 8 Software License Agreement (BSD License)
Pokitto 7:72f87b7c7400 9
Pokitto 7:72f87b7c7400 10 Copyright (c) 2016, Jonne Valola
Pokitto 7:72f87b7c7400 11 All rights reserved.
Pokitto 7:72f87b7c7400 12
Pokitto 7:72f87b7c7400 13 Redistribution and use in source and binary forms, with or without
Pokitto 7:72f87b7c7400 14 modification, are permitted provided that the following conditions are met:
Pokitto 7:72f87b7c7400 15 1. Redistributions of source code must retain the above copyright
Pokitto 7:72f87b7c7400 16 notice, this list of conditions and the following disclaimer.
Pokitto 7:72f87b7c7400 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 7:72f87b7c7400 18 notice, this list of conditions and the following disclaimer in the
Pokitto 7:72f87b7c7400 19 documentation and/or other materials provided with the distribution.
Pokitto 7:72f87b7c7400 20 3. Neither the name of the copyright holders nor the
Pokitto 7:72f87b7c7400 21 names of its contributors may be used to endorse or promote products
Pokitto 7:72f87b7c7400 22 derived from this software without specific prior written permission.
Pokitto 7:72f87b7c7400 23
Pokitto 7:72f87b7c7400 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 7:72f87b7c7400 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 7:72f87b7c7400 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 7:72f87b7c7400 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 7:72f87b7c7400 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 7:72f87b7c7400 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 7:72f87b7c7400 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 7:72f87b7c7400 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 7:72f87b7c7400 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 7:72f87b7c7400 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 7:72f87b7c7400 34 */
Pokitto 7:72f87b7c7400 35 /**************************************************************************/
Pokitto 7:72f87b7c7400 36
Pokitto 7:72f87b7c7400 37 #include "HWButtons.h"
Pokitto 7:72f87b7c7400 38 #include "PokittoCore.h"
Pokitto 7:72f87b7c7400 39 #include "PokittoSound.h"
Pokitto 7:72f87b7c7400 40 #include "PokittoDisplay.h"
Pokitto 7:72f87b7c7400 41
Pokitto 7:72f87b7c7400 42 Pokitto::Sound _s;
Pokitto 7:72f87b7c7400 43 Pokitto::Display _bd;
Pokitto 7:72f87b7c7400 44
Pokitto 7:72f87b7c7400 45 using namespace mbed;
Pokitto 7:72f87b7c7400 46
Pokitto 7:72f87b7c7400 47 InterruptIn ABtn(POK_BTN_A_PIN);
Pokitto 7:72f87b7c7400 48 InterruptIn BBtn(POK_BTN_B_PIN);
Pokitto 7:72f87b7c7400 49 InterruptIn CBtn(POK_BTN_C_PIN);
Pokitto 7:72f87b7c7400 50 InterruptIn UBtn(POK_BTN_UP_PIN);
Pokitto 7:72f87b7c7400 51 InterruptIn DBtn(POK_BTN_DOWN_PIN);
Pokitto 7:72f87b7c7400 52 InterruptIn LBtn(POK_BTN_LEFT_PIN);
Pokitto 7:72f87b7c7400 53 InterruptIn RBtn(POK_BTN_RIGHT_PIN);
Pokitto 7:72f87b7c7400 54
Pokitto 7:72f87b7c7400 55 #define BS_IDLE 0
Pokitto 7:72f87b7c7400 56 #define BS_DOWN 1
Pokitto 7:72f87b7c7400 57 #define BS_UP 2
Pokitto 7:72f87b7c7400 58
Pokitto 7:72f87b7c7400 59 uint8_t Pokitto::heldStates[NUM_BTN];
Pokitto 7:72f87b7c7400 60
Pokitto 7:72f87b7c7400 61 void APressed() { Pokitto::heldStates[BTN_A] = 1; }
Pokitto 7:72f87b7c7400 62 void AReleased() { Pokitto::heldStates[BTN_A] = 0; }
Pokitto 7:72f87b7c7400 63 void BPressed() { Pokitto::heldStates[BTN_B] = 1; }
Pokitto 7:72f87b7c7400 64 void BReleased() { Pokitto::heldStates[BTN_B] = 0; }
Pokitto 7:72f87b7c7400 65 void CPressed() { Pokitto::heldStates[BTN_C] = 1;}
Pokitto 7:72f87b7c7400 66 void CReleased() { Pokitto::heldStates[BTN_C] = 0; }
Pokitto 7:72f87b7c7400 67 void UPressed() { Pokitto::heldStates[BTN_UP] = 1; }
Pokitto 7:72f87b7c7400 68 void UReleased() { Pokitto::heldStates[BTN_UP] = 0; }
Pokitto 7:72f87b7c7400 69 void DPressed() { Pokitto::heldStates[BTN_DOWN] = 1; }
Pokitto 7:72f87b7c7400 70 void DReleased() { Pokitto::heldStates[BTN_DOWN] = 0; }
Pokitto 7:72f87b7c7400 71 void RPressed() {
Pokitto 7:72f87b7c7400 72 /* Hardware volume control */
Pokitto 7:72f87b7c7400 73 if (Pokitto::heldStates[BTN_C]) _s.volumeUp();
Pokitto 7:72f87b7c7400 74 else Pokitto::heldStates[BTN_RIGHT] = 1;
Pokitto 7:72f87b7c7400 75 }
Pokitto 7:72f87b7c7400 76 void RReleased() { Pokitto::heldStates[BTN_RIGHT] = 0; }
Pokitto 7:72f87b7c7400 77 void LPressed() {
Pokitto 7:72f87b7c7400 78 /* Hardware volume control */
Pokitto 7:72f87b7c7400 79 if (Pokitto::heldStates[BTN_C]) _s.volumeDown();
Pokitto 7:72f87b7c7400 80 else Pokitto::heldStates[BTN_LEFT] = 1;
Pokitto 7:72f87b7c7400 81 }
Pokitto 7:72f87b7c7400 82 void LReleased() { Pokitto::heldStates[BTN_LEFT] = 0; }
Pokitto 7:72f87b7c7400 83
Pokitto 7:72f87b7c7400 84 void Pokitto::initButtons() {
Pokitto 7:72f87b7c7400 85 ABtn.fall(&AReleased);
Pokitto 7:72f87b7c7400 86 ABtn.rise(&APressed);
Pokitto 7:72f87b7c7400 87 BBtn.fall(&BReleased);
Pokitto 7:72f87b7c7400 88 BBtn.rise(&BPressed);
Pokitto 7:72f87b7c7400 89 CBtn.fall(&CReleased);
Pokitto 7:72f87b7c7400 90 CBtn.rise(&CPressed);
Pokitto 7:72f87b7c7400 91 UBtn.fall(&UReleased);
Pokitto 7:72f87b7c7400 92 UBtn.rise(&UPressed);
Pokitto 7:72f87b7c7400 93 DBtn.fall(&DReleased);
Pokitto 7:72f87b7c7400 94 DBtn.rise(&DPressed);
Pokitto 7:72f87b7c7400 95 LBtn.fall(&LReleased);
Pokitto 7:72f87b7c7400 96 LBtn.rise(&LPressed);
Pokitto 7:72f87b7c7400 97 RBtn.fall(&RReleased);
Pokitto 7:72f87b7c7400 98 RBtn.rise(&RPressed);
Pokitto 7:72f87b7c7400 99 }
Pokitto 7:72f87b7c7400 100
Pokitto 7:72f87b7c7400 101 uint8_t Pokitto::Core::aBtn() {
Pokitto 7:72f87b7c7400 102 return Pokitto::heldStates[BTN_A];
Pokitto 7:72f87b7c7400 103 }
Pokitto 7:72f87b7c7400 104
Pokitto 7:72f87b7c7400 105 uint8_t Pokitto::Core::bBtn() {
Pokitto 7:72f87b7c7400 106 return Pokitto::heldStates[BTN_B];
Pokitto 7:72f87b7c7400 107 }
Pokitto 7:72f87b7c7400 108
Pokitto 7:72f87b7c7400 109 uint8_t Pokitto::Core::cBtn() {
Pokitto 7:72f87b7c7400 110 return Pokitto::heldStates[BTN_C];
Pokitto 7:72f87b7c7400 111 }
Pokitto 7:72f87b7c7400 112
Pokitto 7:72f87b7c7400 113 uint8_t Pokitto::Core::upBtn() {
Pokitto 7:72f87b7c7400 114 return Pokitto::heldStates[BTN_UP];
Pokitto 7:72f87b7c7400 115 }
Pokitto 7:72f87b7c7400 116 uint8_t Pokitto::Core::downBtn() {
Pokitto 7:72f87b7c7400 117 return Pokitto::heldStates[BTN_DOWN];
Pokitto 7:72f87b7c7400 118 }
Pokitto 7:72f87b7c7400 119
Pokitto 7:72f87b7c7400 120 uint8_t Pokitto::Core::leftBtn() {
Pokitto 7:72f87b7c7400 121 return Pokitto::heldStates[BTN_LEFT];
Pokitto 7:72f87b7c7400 122 }
Pokitto 7:72f87b7c7400 123 uint8_t Pokitto::Core::rightBtn() {
Pokitto 7:72f87b7c7400 124 return Pokitto::heldStates[BTN_RIGHT];
Pokitto 7:72f87b7c7400 125 }
Pokitto 7:72f87b7c7400 126