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:
Mon Apr 02 22:37:22 2018 +0000
Revision:
36:771321e70814
Synced with Github repo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 36:771321e70814 1 /**************************************************************************/
Pokitto 36:771321e70814 2 /*!
Pokitto 36:771321e70814 3 @file HWSOUND.h
Pokitto 36:771321e70814 4 @author Jonne Valola
Pokitto 36:771321e70814 5
Pokitto 36:771321e70814 6 @section LICENSE
Pokitto 36:771321e70814 7
Pokitto 36:771321e70814 8 Software License Agreement (BSD License)
Pokitto 36:771321e70814 9
Pokitto 36:771321e70814 10 Copyright (c) 2016, Jonne Valola
Pokitto 36:771321e70814 11 All rights reserved.
Pokitto 36:771321e70814 12
Pokitto 36:771321e70814 13 Redistribution and use in source and binary forms, with or without
Pokitto 36:771321e70814 14 modification, are permitted provided that the following conditions are met:
Pokitto 36:771321e70814 15 1. Redistributions of source code must retain the above copyright
Pokitto 36:771321e70814 16 notice, this list of conditions and the following disclaimer.
Pokitto 36:771321e70814 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 36:771321e70814 18 notice, this list of conditions and the following disclaimer in the
Pokitto 36:771321e70814 19 documentation and/or other materials provided with the distribution.
Pokitto 36:771321e70814 20 3. Neither the name of the copyright holders nor the
Pokitto 36:771321e70814 21 names of its contributors may be used to endorse or promote products
Pokitto 36:771321e70814 22 derived from this software without specific prior written permission.
Pokitto 36:771321e70814 23
Pokitto 36:771321e70814 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 36:771321e70814 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 36:771321e70814 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 36:771321e70814 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 36:771321e70814 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 36:771321e70814 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 36:771321e70814 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 36:771321e70814 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 36:771321e70814 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 36:771321e70814 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 36:771321e70814 34 */
Pokitto 36:771321e70814 35 /**************************************************************************/
Pokitto 36:771321e70814 36 #ifndef HWSOUND_H
Pokitto 36:771321e70814 37 #define HWSOUND_H
Pokitto 36:771321e70814 38
Pokitto 36:771321e70814 39 #include "mbed.h"
Pokitto 36:771321e70814 40 #include "Pokitto_settings.h"
Pokitto 36:771321e70814 41
Pokitto 36:771321e70814 42 #define SPEAKER 3
Pokitto 36:771321e70814 43 #define BUFFER_SIZE 512*4 //*8 //*8 // 512 // was 512 (works really well with crabator) was 256
Pokitto 36:771321e70814 44
Pokitto 36:771321e70814 45 #define SBUFSIZE 512*4
Pokitto 36:771321e70814 46
Pokitto 36:771321e70814 47 #if POK_BOARDREV == 1
Pokitto 36:771321e70814 48 /** 2-layer board rev 1.3 **/
Pokitto 36:771321e70814 49 #define DAC0_PORT 1
Pokitto 36:771321e70814 50 #define DAC0_PIN 6
Pokitto 36:771321e70814 51 #define DAC1_PORT 1
Pokitto 36:771321e70814 52 #define DAC1_PIN 0
Pokitto 36:771321e70814 53 #define DAC2_PORT 1
Pokitto 36:771321e70814 54 #define DAC2_PIN 16
Pokitto 36:771321e70814 55 #define DAC3_PORT 0
Pokitto 36:771321e70814 56 #define DAC3_PIN 19
Pokitto 36:771321e70814 57 #define DAC4_PORT 0
Pokitto 36:771321e70814 58 #define DAC4_PIN 17
Pokitto 36:771321e70814 59 #define DAC5_PORT 1
Pokitto 36:771321e70814 60 #define DAC5_PIN 12
Pokitto 36:771321e70814 61 #define DAC6_PORT 1
Pokitto 36:771321e70814 62 #define DAC6_PIN 15
Pokitto 36:771321e70814 63 #define DAC7_PORT 1
Pokitto 36:771321e70814 64 #define DAC7_PIN 8
Pokitto 36:771321e70814 65 #else
Pokitto 36:771321e70814 66 /** 4-layer board rev 2.1 **/
Pokitto 36:771321e70814 67 #define DAC0_PORT 1
Pokitto 36:771321e70814 68 #define DAC0_PIN 28
Pokitto 36:771321e70814 69 #define DAC1_PORT 1
Pokitto 36:771321e70814 70 #define DAC1_PIN 29
Pokitto 36:771321e70814 71 #define DAC2_PORT 1
Pokitto 36:771321e70814 72 #define DAC2_PIN 30
Pokitto 36:771321e70814 73 #define DAC3_PORT 1
Pokitto 36:771321e70814 74 #define DAC3_PIN 31
Pokitto 36:771321e70814 75 /** has daniel made a mistake with dac ? **/
Pokitto 36:771321e70814 76 #define DAC4_PORT 2
Pokitto 36:771321e70814 77 #define DAC4_PIN 20
Pokitto 36:771321e70814 78 #define DAC5_PORT 2
Pokitto 36:771321e70814 79 #define DAC5_PIN 21
Pokitto 36:771321e70814 80 #define DAC6_PORT 2
Pokitto 36:771321e70814 81 #define DAC6_PIN 22
Pokitto 36:771321e70814 82 #define DAC7_PORT 2
Pokitto 36:771321e70814 83 #define DAC7_PIN 23
Pokitto 36:771321e70814 84
Pokitto 36:771321e70814 85 /** MASK FOR FASTER DAC **/
Pokitto 36:771321e70814 86 #define SET_MASK_DAC LPC_GPIO_PORT->MASK[1] = ~(0xF0078000); //mask P1_15...P1_18 and P1_28...P1_31
Pokitto 36:771321e70814 87 #define CLR_MASK_DAC LPC_GPIO_PORT->MASK[1] = 0; // all on
Pokitto 36:771321e70814 88
Pokitto 36:771321e70814 89 /* fixing wrong pins from daniel*/
Pokitto 36:771321e70814 90 #define SET_MASK_DAC_LO LPC_GPIO_PORT->MASK[1] = ~(0xF0000000); //mask P1_28...P1_31
Pokitto 36:771321e70814 91 #define CLR_MASK_DAC_LO LPC_GPIO_PORT->MASK[1] = 0; // all on
Pokitto 36:771321e70814 92 #define SET_MASK_DAC_HI LPC_GPIO_PORT->MASK[2] = ~(0xF00000); //mask P2_20...P2_23
Pokitto 36:771321e70814 93 #define CLR_MASK_DAC_HI LPC_GPIO_PORT->MASK[2] = 0; // all on
Pokitto 36:771321e70814 94
Pokitto 36:771321e70814 95 #endif
Pokitto 36:771321e70814 96
Pokitto 36:771321e70814 97 #define CLR_DAC0 LPC_GPIO_PORT->CLR[DAC0_PORT] = 1UL << DAC0_PIN;
Pokitto 36:771321e70814 98 #define SET_DAC0 LPC_GPIO_PORT->SET[DAC0_PORT] = 1UL << DAC0_PIN;
Pokitto 36:771321e70814 99 #define CLR_DAC1 LPC_GPIO_PORT->CLR[DAC1_PORT] = 1UL << DAC1_PIN;
Pokitto 36:771321e70814 100 #define SET_DAC1 LPC_GPIO_PORT->SET[DAC1_PORT] = 1UL << DAC1_PIN;
Pokitto 36:771321e70814 101 #define CLR_DAC2 LPC_GPIO_PORT->CLR[DAC2_PORT] = 1UL << DAC2_PIN;
Pokitto 36:771321e70814 102 #define SET_DAC2 LPC_GPIO_PORT->SET[DAC2_PORT] = 1UL << DAC2_PIN;
Pokitto 36:771321e70814 103 #define CLR_DAC3 LPC_GPIO_PORT->CLR[DAC3_PORT] = 1UL << DAC3_PIN;
Pokitto 36:771321e70814 104 #define SET_DAC3 LPC_GPIO_PORT->SET[DAC3_PORT] = 1UL << DAC3_PIN;
Pokitto 36:771321e70814 105 #define CLR_DAC4 LPC_GPIO_PORT->CLR[DAC4_PORT] = 1UL << DAC4_PIN;
Pokitto 36:771321e70814 106 #define SET_DAC4 LPC_GPIO_PORT->SET[DAC4_PORT] = 1UL << DAC4_PIN;
Pokitto 36:771321e70814 107 #define CLR_DAC5 LPC_GPIO_PORT->CLR[DAC5_PORT] = 1UL << DAC5_PIN;
Pokitto 36:771321e70814 108 #define SET_DAC5 LPC_GPIO_PORT->SET[DAC5_PORT] = 1UL << DAC5_PIN;
Pokitto 36:771321e70814 109 #define CLR_DAC6 LPC_GPIO_PORT->CLR[DAC6_PORT] = 1UL << DAC6_PIN;
Pokitto 36:771321e70814 110 #define SET_DAC6 LPC_GPIO_PORT->SET[DAC6_PORT] = 1UL << DAC6_PIN;
Pokitto 36:771321e70814 111 #define CLR_DAC7 LPC_GPIO_PORT->CLR[DAC7_PORT] = 1UL << DAC7_PIN;
Pokitto 36:771321e70814 112 #define SET_DAC7 LPC_GPIO_PORT->SET[DAC7_PORT] = 1UL << DAC7_PIN;
Pokitto 36:771321e70814 113
Pokitto 36:771321e70814 114 /** the output holder **/
Pokitto 36:771321e70814 115 extern uint16_t soundbyte;
Pokitto 36:771321e70814 116
Pokitto 36:771321e70814 117 namespace Pokitto {
Pokitto 36:771321e70814 118
Pokitto 36:771321e70814 119
Pokitto 36:771321e70814 120 /** stream output and status */
Pokitto 36:771321e70814 121 extern uint8_t streambyte, streamon, HWvolume;
Pokitto 36:771321e70814 122
Pokitto 36:771321e70814 123 extern float pwm2; //virtual pwm output
Pokitto 36:771321e70814 124
Pokitto 36:771321e70814 125 extern void soundInit();
Pokitto 36:771321e70814 126 extern void dac_write(uint8_t value);
Pokitto 36:771321e70814 127 extern uint8_t ampIsOn();
Pokitto 36:771321e70814 128 extern void ampEnable(uint8_t v);
Pokitto 36:771321e70814 129 extern void audio_IRQ();
Pokitto 36:771321e70814 130 extern void updateSDAudioStream();
Pokitto 36:771321e70814 131 extern uint8_t streamPaused();
Pokitto 36:771321e70814 132 extern void pauseStream();
Pokitto 36:771321e70814 133 extern void playStream();
Pokitto 36:771321e70814 134 extern int setHWvolume(uint8_t);
Pokitto 36:771321e70814 135 extern uint8_t getHWvolume();
Pokitto 36:771321e70814 136 extern void changeHWvolume(int8_t);
Pokitto 36:771321e70814 137
Pokitto 36:771321e70814 138 extern pwmout_t audiopwm;
Pokitto 36:771321e70814 139 extern uint8_t pokAmpIsOn();
Pokitto 36:771321e70814 140 extern void pokAmpEnable(uint8_t);
Pokitto 36:771321e70814 141
Pokitto 36:771321e70814 142 extern Ticker audio;
Pokitto 36:771321e70814 143
Pokitto 36:771321e70814 144 extern void update_SDAudioStream();
Pokitto 36:771321e70814 145 }
Pokitto 36:771321e70814 146
Pokitto 36:771321e70814 147
Pokitto 36:771321e70814 148 extern void pokSoundIRQ();
Pokitto 36:771321e70814 149 extern void pokSoundBufferedIRQ();
Pokitto 36:771321e70814 150
Pokitto 36:771321e70814 151 #if POK_STREAMING_MUSIC > 0
Pokitto 36:771321e70814 152 extern unsigned char buffers[][BUFFER_SIZE];
Pokitto 36:771321e70814 153 extern volatile int currentBuffer, oldBuffer;
Pokitto 36:771321e70814 154 extern volatile int bufindex, vol;
Pokitto 36:771321e70814 155 extern volatile unsigned char * currentPtr;
Pokitto 36:771321e70814 156 extern volatile unsigned char * endPtr;
Pokitto 36:771321e70814 157 extern int8_t streamvol;
Pokitto 36:771321e70814 158 extern uint32_t streamcounter;
Pokitto 36:771321e70814 159 extern uint8_t streamstep;
Pokitto 36:771321e70814 160 #endif
Pokitto 36:771321e70814 161
Pokitto 36:771321e70814 162 #endif //HWSOUND_H
Pokitto 36:771321e70814 163
Pokitto 36:771321e70814 164
Pokitto 36:771321e70814 165