Jonne Valola / PokittoLib Featured

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:
Tue Jan 30 10:41:47 2018 +0000
Revision:
31:f4b9b85c7b62
Sound output improvements added:  louder, clearer, faster!

Who changed what in which revision?

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