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