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

Committer:
spinal
Date:
Sun Nov 18 15:47:54 2018 +0000
Revision:
64:6e6c6c2b664e
Parent:
43:6183b12dd99c
added fix for directrectangle()

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