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

Dependents:   Sensitive

Fork of PokittoLib by Jonne Valola

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HWSound.h Source File

HWSound.h

00001 /**************************************************************************/
00002 /*!
00003     @file     HWSOUND.h
00004     @author   Jonne Valola
00005 
00006     @section LICENSE
00007 
00008     Software License Agreement (BSD License)
00009 
00010     Copyright (c) 2016, Jonne Valola
00011     All rights reserved.
00012 
00013     Redistribution and use in source and binary forms, with or without
00014     modification, are permitted provided that the following conditions are met:
00015     1. Redistributions of source code must retain the above copyright
00016     notice, this list of conditions and the following disclaimer.
00017     2. Redistributions in binary form must reproduce the above copyright
00018     notice, this list of conditions and the following disclaimer in the
00019     documentation and/or other materials provided with the distribution.
00020     3. Neither the name of the copyright holders nor the
00021     names of its contributors may be used to endorse or promote products
00022     derived from this software without specific prior written permission.
00023 
00024     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
00025     EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
00028     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00033     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 */
00035 /**************************************************************************/
00036 #ifndef HWSOUND_H
00037 #define HWSOUND_H
00038 
00039 #include "mbed.h"
00040 #include "Pokitto_settings.h "
00041 
00042 #define SPEAKER 3
00043 #define BUFFER_SIZE 512*4 //*8 //*8 // 512 // was 512 (works really well with crabator) was 256
00044 
00045 #if POK_BOARDREV == 1
00046  /** 2-layer board rev 1.3 **/
00047  #define DAC0_PORT   1
00048  #define DAC0_PIN    6
00049  #define DAC1_PORT   1
00050  #define DAC1_PIN    0
00051  #define DAC2_PORT   1
00052  #define DAC2_PIN    16
00053  #define DAC3_PORT   0
00054  #define DAC3_PIN    19
00055  #define DAC4_PORT   0
00056  #define DAC4_PIN    17
00057  #define DAC5_PORT   1
00058  #define DAC5_PIN    12
00059  #define DAC6_PORT   1
00060  #define DAC6_PIN    15
00061  #define DAC7_PORT   1
00062  #define DAC7_PIN    8
00063 #else
00064  /** 4-layer board rev 2.1 **/
00065  #define DAC0_PORT   1
00066  #define DAC0_PIN    28
00067  #define DAC1_PORT   1
00068  #define DAC1_PIN    29
00069  #define DAC2_PORT   1
00070  #define DAC2_PIN    30
00071  #define DAC3_PORT   1
00072  #define DAC3_PIN    31
00073 /** has daniel made a mistake with dac ? **/
00074  #define DAC4_PORT   2
00075  #define DAC4_PIN    20
00076  #define DAC5_PORT   2
00077  #define DAC5_PIN    21
00078  #define DAC6_PORT   2
00079  #define DAC6_PIN    22
00080  #define DAC7_PORT   2
00081  #define DAC7_PIN    23
00082 
00083  /** MASK FOR FASTER DAC **/
00084  #define SET_MASK_DAC LPC_GPIO_PORT->MASK[1] = ~(0xF0078000); //mask P1_15...P1_18 and P1_28...P1_31
00085  #define CLR_MASK_DAC LPC_GPIO_PORT->MASK[1] = 0; // all on
00086 
00087  /* fixing wrong pins from daniel*/
00088  #define SET_MASK_DAC_LO LPC_GPIO_PORT->MASK[1] = ~(0xF0000000); //mask P1_28...P1_31
00089  #define CLR_MASK_DAC_LO LPC_GPIO_PORT->MASK[1] = 0; // all on
00090  #define SET_MASK_DAC_HI LPC_GPIO_PORT->MASK[2] = ~(0xF00000); //mask P2_20...P2_23
00091  #define CLR_MASK_DAC_HI LPC_GPIO_PORT->MASK[2] = 0; // all on
00092 
00093 #endif
00094 
00095 #define CLR_DAC0 LPC_GPIO_PORT->CLR[DAC0_PORT] = 1UL << DAC0_PIN;
00096 #define SET_DAC0 LPC_GPIO_PORT->SET[DAC0_PORT] = 1UL << DAC0_PIN;
00097 #define CLR_DAC1 LPC_GPIO_PORT->CLR[DAC1_PORT] = 1UL << DAC1_PIN;
00098 #define SET_DAC1 LPC_GPIO_PORT->SET[DAC1_PORT] = 1UL << DAC1_PIN;
00099 #define CLR_DAC2 LPC_GPIO_PORT->CLR[DAC2_PORT] = 1UL << DAC2_PIN;
00100 #define SET_DAC2 LPC_GPIO_PORT->SET[DAC2_PORT] = 1UL << DAC2_PIN;
00101 #define CLR_DAC3 LPC_GPIO_PORT->CLR[DAC3_PORT] = 1UL << DAC3_PIN;
00102 #define SET_DAC3 LPC_GPIO_PORT->SET[DAC3_PORT] = 1UL << DAC3_PIN;
00103 #define CLR_DAC4 LPC_GPIO_PORT->CLR[DAC4_PORT] = 1UL << DAC4_PIN;
00104 #define SET_DAC4 LPC_GPIO_PORT->SET[DAC4_PORT] = 1UL << DAC4_PIN;
00105 #define CLR_DAC5 LPC_GPIO_PORT->CLR[DAC5_PORT] = 1UL << DAC5_PIN;
00106 #define SET_DAC5 LPC_GPIO_PORT->SET[DAC5_PORT] = 1UL << DAC5_PIN;
00107 #define CLR_DAC6 LPC_GPIO_PORT->CLR[DAC6_PORT] = 1UL << DAC6_PIN;
00108 #define SET_DAC6 LPC_GPIO_PORT->SET[DAC6_PORT] = 1UL << DAC6_PIN;
00109 #define CLR_DAC7 LPC_GPIO_PORT->CLR[DAC7_PORT] = 1UL << DAC7_PIN;
00110 #define SET_DAC7 LPC_GPIO_PORT->SET[DAC7_PORT] = 1UL << DAC7_PIN;
00111 
00112 /** the output holder **/
00113 extern uint16_t soundbyte;
00114 
00115 namespace Pokitto {
00116 
00117 
00118 /** stream output and status */
00119 extern uint8_t streambyte, streamon, HWvolume;
00120 
00121 extern float pwm2; //virtual pwm output
00122 
00123 extern void soundInit();
00124 extern void dac_write(uint8_t value);
00125 extern uint8_t ampIsOn();
00126 extern void ampEnable(uint8_t v);
00127 extern void audio_IRQ();
00128 extern void updateSDAudioStream();
00129 extern uint8_t streamPaused();
00130 extern void pauseStream();
00131 extern void playStream();
00132 extern int setHWvolume(uint8_t);
00133 extern uint8_t getHWvolume();
00134 extern void changeHWvolume(int8_t);
00135 
00136 extern pwmout_t audiopwm;
00137 extern uint8_t pokAmpIsOn();
00138 extern void pokAmpEnable(uint8_t);
00139 
00140 extern Ticker audio;
00141 
00142 extern void update_SDAudioStream();
00143 }
00144 
00145 
00146 extern void pokSoundIRQ ();
00147 
00148 #if POK_STREAMING_MUSIC > 0
00149     extern unsigned char buffers[][BUFFER_SIZE];
00150     extern volatile int currentBuffer, oldBuffer;
00151     extern volatile int bufindex, vol;
00152     extern volatile unsigned char * currentPtr;
00153     extern volatile unsigned char * endPtr;
00154     extern int8_t streamvol;
00155     extern uint32_t streamcounter;
00156     extern uint8_t streamstep;
00157 #endif
00158 
00159 #endif //HWSOUND_H
00160 
00161