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

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Wed Dec 25 23:59:52 2019 +0000
Revision:
71:531419862202
Parent:
67:068fa6345036
Changed Mode2 C++ refresh code (graphical errors)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 43:6183b12dd99c 1 /**************************************************************************/
Pokitto 43:6183b12dd99c 2 /*!
Pokitto 43:6183b12dd99c 3 @file HWSOUND.h
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 #ifndef HWSOUND_H
Pokitto 43:6183b12dd99c 37 #define HWSOUND_H
Pokitto 43:6183b12dd99c 38
Pokitto 43:6183b12dd99c 39 #include "mbed.h"
Pokitto 43:6183b12dd99c 40 #include "Pokitto_settings.h"
Pokitto 43:6183b12dd99c 41
Pokitto 43:6183b12dd99c 42 #define SPEAKER 3
Pokitto 67:068fa6345036 43 #if POK_HIGH_RAM == HIGH_RAM_MUSIC
Pokitto 67:068fa6345036 44 #define BUFFER_SIZE 256*4
Pokitto 67:068fa6345036 45 #define SBUFSIZE 256*4
Pokitto 67:068fa6345036 46 #else
Pokitto 67:068fa6345036 47 #define BUFFER_SIZE 512*4 //*8 //*8 // 512 // was 512 (works really well with crabator) was 256
Pokitto 67:068fa6345036 48 #define SBUFSIZE 512*4
Pokitto 67:068fa6345036 49 #endif
Pokitto 43:6183b12dd99c 50
Pokitto 43:6183b12dd99c 51 #if POK_BOARDREV == 1
Pokitto 43:6183b12dd99c 52 /** 2-layer board rev 1.3 **/
Pokitto 43:6183b12dd99c 53 #define DAC0_PORT 1
Pokitto 43:6183b12dd99c 54 #define DAC0_PIN 6
Pokitto 43:6183b12dd99c 55 #define DAC1_PORT 1
Pokitto 43:6183b12dd99c 56 #define DAC1_PIN 0
Pokitto 43:6183b12dd99c 57 #define DAC2_PORT 1
Pokitto 43:6183b12dd99c 58 #define DAC2_PIN 16
Pokitto 43:6183b12dd99c 59 #define DAC3_PORT 0
Pokitto 43:6183b12dd99c 60 #define DAC3_PIN 19
Pokitto 43:6183b12dd99c 61 #define DAC4_PORT 0
Pokitto 43:6183b12dd99c 62 #define DAC4_PIN 17
Pokitto 43:6183b12dd99c 63 #define DAC5_PORT 1
Pokitto 43:6183b12dd99c 64 #define DAC5_PIN 12
Pokitto 43:6183b12dd99c 65 #define DAC6_PORT 1
Pokitto 43:6183b12dd99c 66 #define DAC6_PIN 15
Pokitto 43:6183b12dd99c 67 #define DAC7_PORT 1
Pokitto 43:6183b12dd99c 68 #define DAC7_PIN 8
Pokitto 43:6183b12dd99c 69 #else
Pokitto 43:6183b12dd99c 70 /** 4-layer board rev 2.1 **/
Pokitto 43:6183b12dd99c 71 #define DAC0_PORT 1
Pokitto 43:6183b12dd99c 72 #define DAC0_PIN 28
Pokitto 43:6183b12dd99c 73 #define DAC1_PORT 1
Pokitto 43:6183b12dd99c 74 #define DAC1_PIN 29
Pokitto 43:6183b12dd99c 75 #define DAC2_PORT 1
Pokitto 43:6183b12dd99c 76 #define DAC2_PIN 30
Pokitto 43:6183b12dd99c 77 #define DAC3_PORT 1
Pokitto 43:6183b12dd99c 78 #define DAC3_PIN 31
Pokitto 43:6183b12dd99c 79 /** has daniel made a mistake with dac ? **/
Pokitto 43:6183b12dd99c 80 #define DAC4_PORT 2
Pokitto 43:6183b12dd99c 81 #define DAC4_PIN 20
Pokitto 43:6183b12dd99c 82 #define DAC5_PORT 2
Pokitto 43:6183b12dd99c 83 #define DAC5_PIN 21
Pokitto 43:6183b12dd99c 84 #define DAC6_PORT 2
Pokitto 43:6183b12dd99c 85 #define DAC6_PIN 22
Pokitto 43:6183b12dd99c 86 #define DAC7_PORT 2
Pokitto 43:6183b12dd99c 87 #define DAC7_PIN 23
Pokitto 43:6183b12dd99c 88
Pokitto 43:6183b12dd99c 89 /** MASK FOR FASTER DAC **/
Pokitto 43:6183b12dd99c 90 #define SET_MASK_DAC LPC_GPIO_PORT->MASK[1] = ~(0xF0078000); //mask P1_15...P1_18 and P1_28...P1_31
Pokitto 43:6183b12dd99c 91 #define CLR_MASK_DAC LPC_GPIO_PORT->MASK[1] = 0; // all on
Pokitto 43:6183b12dd99c 92
Pokitto 43:6183b12dd99c 93 /* fixing wrong pins from daniel*/
Pokitto 43:6183b12dd99c 94 #define SET_MASK_DAC_LO LPC_GPIO_PORT->MASK[1] = ~(0xF0000000); //mask P1_28...P1_31
Pokitto 43:6183b12dd99c 95 #define CLR_MASK_DAC_LO LPC_GPIO_PORT->MASK[1] = 0; // all on
Pokitto 43:6183b12dd99c 96 #define SET_MASK_DAC_HI LPC_GPIO_PORT->MASK[2] = ~(0xF00000); //mask P2_20...P2_23
Pokitto 43:6183b12dd99c 97 #define CLR_MASK_DAC_HI LPC_GPIO_PORT->MASK[2] = 0; // all on
Pokitto 43:6183b12dd99c 98
Pokitto 43:6183b12dd99c 99 #endif
Pokitto 43:6183b12dd99c 100
Pokitto 43:6183b12dd99c 101 #define CLR_DAC0 LPC_GPIO_PORT->CLR[DAC0_PORT] = 1UL << DAC0_PIN;
Pokitto 43:6183b12dd99c 102 #define SET_DAC0 LPC_GPIO_PORT->SET[DAC0_PORT] = 1UL << DAC0_PIN;
Pokitto 43:6183b12dd99c 103 #define CLR_DAC1 LPC_GPIO_PORT->CLR[DAC1_PORT] = 1UL << DAC1_PIN;
Pokitto 43:6183b12dd99c 104 #define SET_DAC1 LPC_GPIO_PORT->SET[DAC1_PORT] = 1UL << DAC1_PIN;
Pokitto 43:6183b12dd99c 105 #define CLR_DAC2 LPC_GPIO_PORT->CLR[DAC2_PORT] = 1UL << DAC2_PIN;
Pokitto 43:6183b12dd99c 106 #define SET_DAC2 LPC_GPIO_PORT->SET[DAC2_PORT] = 1UL << DAC2_PIN;
Pokitto 43:6183b12dd99c 107 #define CLR_DAC3 LPC_GPIO_PORT->CLR[DAC3_PORT] = 1UL << DAC3_PIN;
Pokitto 43:6183b12dd99c 108 #define SET_DAC3 LPC_GPIO_PORT->SET[DAC3_PORT] = 1UL << DAC3_PIN;
Pokitto 43:6183b12dd99c 109 #define CLR_DAC4 LPC_GPIO_PORT->CLR[DAC4_PORT] = 1UL << DAC4_PIN;
Pokitto 43:6183b12dd99c 110 #define SET_DAC4 LPC_GPIO_PORT->SET[DAC4_PORT] = 1UL << DAC4_PIN;
Pokitto 43:6183b12dd99c 111 #define CLR_DAC5 LPC_GPIO_PORT->CLR[DAC5_PORT] = 1UL << DAC5_PIN;
Pokitto 43:6183b12dd99c 112 #define SET_DAC5 LPC_GPIO_PORT->SET[DAC5_PORT] = 1UL << DAC5_PIN;
Pokitto 43:6183b12dd99c 113 #define CLR_DAC6 LPC_GPIO_PORT->CLR[DAC6_PORT] = 1UL << DAC6_PIN;
Pokitto 43:6183b12dd99c 114 #define SET_DAC6 LPC_GPIO_PORT->SET[DAC6_PORT] = 1UL << DAC6_PIN;
Pokitto 43:6183b12dd99c 115 #define CLR_DAC7 LPC_GPIO_PORT->CLR[DAC7_PORT] = 1UL << DAC7_PIN;
Pokitto 43:6183b12dd99c 116 #define SET_DAC7 LPC_GPIO_PORT->SET[DAC7_PORT] = 1UL << DAC7_PIN;
Pokitto 43:6183b12dd99c 117
Pokitto 43:6183b12dd99c 118 /** the output holder **/
Pokitto 43:6183b12dd99c 119 extern uint16_t soundbyte;
Pokitto 43:6183b12dd99c 120
Pokitto 43:6183b12dd99c 121
Pokitto 43:6183b12dd99c 122 namespace Pokitto {
Pokitto 43:6183b12dd99c 123
Pokitto 43:6183b12dd99c 124 /** stream output and status */
Pokitto 43:6183b12dd99c 125 extern uint8_t streambyte, streamon, HWvolume;
Pokitto 43:6183b12dd99c 126
Pokitto 43:6183b12dd99c 127 extern float pwm2; //virtual pwm output
Pokitto 43:6183b12dd99c 128 extern void soundInit();
Pokitto 67:068fa6345036 129 extern void soundInit(uint8_t);
Pokitto 43:6183b12dd99c 130 extern void dac_write(uint8_t value);
Pokitto 43:6183b12dd99c 131 extern uint8_t ampIsOn();
Pokitto 43:6183b12dd99c 132 extern void ampEnable(uint8_t v);
Pokitto 43:6183b12dd99c 133 extern void audio_IRQ();
Pokitto 43:6183b12dd99c 134 extern void updateSDAudioStream();
Pokitto 43:6183b12dd99c 135 extern uint8_t streamPaused();
Pokitto 43:6183b12dd99c 136 extern void pauseStream();
Pokitto 43:6183b12dd99c 137 extern void playStream();
Pokitto 43:6183b12dd99c 138 extern int setHWvolume(uint8_t);
Pokitto 43:6183b12dd99c 139 extern uint8_t getHWvolume();
Pokitto 43:6183b12dd99c 140 extern void changeHWvolume(int8_t);
Pokitto 43:6183b12dd99c 141
Pokitto 43:6183b12dd99c 142 extern pwmout_t audiopwm;
Pokitto 43:6183b12dd99c 143 extern uint8_t pokAmpIsOn();
Pokitto 43:6183b12dd99c 144 extern void pokAmpEnable(uint8_t);
Pokitto 43:6183b12dd99c 145
Pokitto 43:6183b12dd99c 146 extern Ticker audio;
Pokitto 43:6183b12dd99c 147
Pokitto 43:6183b12dd99c 148 extern void update_SDAudioStream();
Pokitto 43:6183b12dd99c 149 }
Pokitto 43:6183b12dd99c 150
Pokitto 43:6183b12dd99c 151
Pokitto 43:6183b12dd99c 152 extern void pokSoundIRQ();
Pokitto 43:6183b12dd99c 153 extern void pokSoundBufferedIRQ();
Pokitto 43:6183b12dd99c 154
Pokitto 43:6183b12dd99c 155 #if POK_STREAMING_MUSIC > 0
Pokitto 67:068fa6345036 156 #if POK_HIGH_RAM == HIGH_RAM_MUSIC
Pokitto 67:068fa6345036 157 extern unsigned char *buffers[];
Pokitto 67:068fa6345036 158 #else
Pokitto 43:6183b12dd99c 159 extern unsigned char buffers[][BUFFER_SIZE];
Pokitto 67:068fa6345036 160 #endif
Pokitto 43:6183b12dd99c 161 extern volatile int currentBuffer, oldBuffer;
Pokitto 43:6183b12dd99c 162 extern volatile int bufindex, vol;
Pokitto 43:6183b12dd99c 163 extern volatile unsigned char * currentPtr;
Pokitto 43:6183b12dd99c 164 extern volatile unsigned char * endPtr;
Pokitto 43:6183b12dd99c 165 extern int8_t streamvol;
Pokitto 43:6183b12dd99c 166 extern uint32_t streamcounter;
Pokitto 43:6183b12dd99c 167 extern uint8_t streamstep;
Pokitto 43:6183b12dd99c 168 #endif
Pokitto 43:6183b12dd99c 169
Pokitto 43:6183b12dd99c 170 #endif //HWSOUND_H
Pokitto 43:6183b12dd99c 171
Pokitto 43:6183b12dd99c 172
Pokitto 43:6183b12dd99c 173