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