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 Sep 18 11:47:51 2017 +0000
Revision:
0:e8b8f36b4505
Child:
2:968589ca3484
Initial;

Who changed what in which revision?

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