gg

Dependencies:   mbed SDFileSystem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers VS1053.h Source File

VS1053.h

00001 /*************************************************** 
00002   This is a library for the Adafruit VS1053 Codec Breakout
00003 
00004   Designed specifically to work with the Adafruit VS1053 Codec Breakout 
00005   ----> https://www.adafruit.com/products/1381
00006 
00007   Adafruit invests time and resources providing this open source code, 
00008   please support Adafruit and open-source hardware by purchasing 
00009   products from Adafruit!
00010 
00011   Written by Limor Fried/Ladyada for Adafruit Industries.  
00012   BSD license, all text above must be included in any redistribution
00013  ****************************************************/
00014 #ifndef ADAFRUIT_VS1053_H
00015 #define ADAFRUIT_VS1053_H
00016 
00017 
00018 #include "mbed.h"
00019 
00020 #ifdef __SAM3X8E__
00021 typedef volatile RwReg PortReg;
00022 typedef uint32_t PortMask;
00023 #else
00024 typedef volatile uint8_t PortReg;
00025 typedef uint8_t PortMask;
00026 #endif
00027 
00028 
00029 #define VS1053_FILEPLAYER_TIMER0_INT 255 // allows useInterrupt to accept pins 0 to 254
00030 #define VS1053_FILEPLAYER_PIN_INT 5
00031 
00032 #define VS1053_SCI_READ 0x03
00033 #define VS1053_SCI_WRITE 0x02
00034 
00035 #define VS1053_REG_MODE  0x00
00036 #define VS1053_REG_STATUS 0x01
00037 #define VS1053_REG_BASS 0x02
00038 #define VS1053_REG_CLOCKF 0x03
00039 #define VS1053_REG_DECODETIME 0x04
00040 #define VS1053_REG_AUDATA 0x05
00041 #define VS1053_REG_WRAM 0x06
00042 #define VS1053_REG_WRAMADDR 0x07
00043 #define VS1053_REG_HDAT0 0x08
00044 #define VS1053_REG_HDAT1 0x09
00045 #define VS1053_REG_VOLUME 0x0B
00046 
00047 #define VS1053_GPIO_DDR 0xC017
00048 #define VS1053_GPIO_IDATA 0xC018
00049 #define VS1053_GPIO_ODATA 0xC019
00050 
00051 #define VS1053_INT_ENABLE  0xC01A
00052 
00053 #define VS1053_MODE_SM_DIFF 0x0001
00054 #define VS1053_MODE_SM_LAYER12 0x0002
00055 #define VS1053_MODE_SM_RESET 0x0004
00056 #define VS1053_MODE_SM_CANCEL 0x0008
00057 #define VS1053_MODE_SM_EARSPKLO 0x0010
00058 #define VS1053_MODE_SM_TESTS 0x0020
00059 #define VS1053_MODE_SM_STREAM 0x0040
00060 #define VS1053_MODE_SM_SDINEW 0x0800
00061 #define VS1053_MODE_SM_ADPCM 0x1000
00062 #define VS1053_MODE_SM_LINE1 0x4000
00063 #define VS1053_MODE_SM_CLKRANGE 0x8000
00064 
00065 
00066 #define VS1053_SCI_AIADDR 0x0A
00067 #define VS1053_SCI_AICTRL0 0x0C
00068 #define VS1053_SCI_AICTRL1 0x0D
00069 #define VS1053_SCI_AICTRL2 0x0E
00070 #define VS1053_SCI_AICTRL3 0x0F
00071 
00072 #define VS1053_DATABUFFERLEN 32
00073 
00074 
00075 class Adafruit_VS1053 {
00076  public:
00077   Adafruit_VS1053(int8_t mosi, int8_t miso, int8_t clk, 
00078           int8_t rst, int8_t cs, int8_t dcs, int8_t dreq);
00079   Adafruit_VS1053(int8_t rst, int8_t cs, int8_t dcs, int8_t dreq);
00080   uint8_t begin(void);
00081   void reset(void);
00082   void softReset(void);
00083   uint16_t sciRead(uint8_t addr);
00084   void sciWrite(uint8_t addr, uint16_t data);
00085   void sineTest(uint8_t n, uint16_t ms);
00086   void spiwrite(uint8_t d);
00087   uint8_t spiread(void);
00088 
00089   uint16_t decodeTime(void);
00090   void setVolume(uint8_t left, uint8_t right);
00091   void dumpRegs(void);
00092 
00093   void playData(uint8_t *buffer, uint8_t buffsiz);
00094   boolean readyForData(void);
00095   void applyPatch(const uint16_t *patch, uint16_t patchsize);
00096   uint16_t loadPlugin(char *fn);
00097 
00098   void GPIO_digitalWrite(uint8_t i, uint8_t val);
00099   void GPIO_digitalWrite(uint8_t i);
00100   uint16_t GPIO_digitalRead(void);
00101   boolean GPIO_digitalRead(uint8_t i);
00102   void GPIO_pinMode(uint8_t i, uint8_t dir);
00103  
00104   boolean prepareRecordOgg(char *plugin);
00105   void startRecordOgg(boolean mic);
00106   void stopRecordOgg(void);
00107   uint16_t recordedWordsWaiting(void);
00108   uint16_t recordedReadWord(void);
00109 
00110   uint8_t mp3buffer[VS1053_DATABUFFERLEN];
00111 
00112 #ifdef ARDUINO_ARCH_SAMD
00113 protected:
00114   uint32_t  _dreq;
00115 private:
00116   int32_t _mosi, _miso, _clk, _reset, _cs, _dcs;
00117   boolean useHardwareSPI;
00118 #else
00119  protected:
00120   uint8_t  _dreq;
00121  private:
00122   int8_t _mosi, _miso, _clk, _reset, _cs, _dcs;
00123   boolean useHardwareSPI;
00124 #endif
00125 };
00126 
00127 
00128 class Adafruit_VS1053_FilePlayer : public Adafruit_VS1053 {
00129  public:
00130   Adafruit_VS1053_FilePlayer (int8_t mosi, int8_t miso, int8_t clk, 
00131                   int8_t rst, int8_t cs, int8_t dcs, int8_t dreq,
00132                   int8_t cardCS);
00133   Adafruit_VS1053_FilePlayer (int8_t rst, int8_t cs, int8_t dcs, int8_t dreq,
00134                   int8_t cardCS);
00135   Adafruit_VS1053_FilePlayer (int8_t cs, int8_t dcs, int8_t dreq,
00136                   int8_t cardCS);
00137 
00138   boolean begin(void);
00139   boolean useInterrupt(uint8_t type);
00140   File currentTrack;
00141   volatile boolean playingMusic;
00142   void feedBuffer(void);
00143   boolean startPlayingFile(const char *trackname);
00144   boolean playFullFile(const char *trackname);
00145   void stopPlaying(void);
00146   boolean paused(void);
00147   boolean stopped(void);
00148   void pausePlaying(boolean pause);
00149 
00150  private:
00151   uint8_t _cardCS;
00152 };
00153 
00154 #endif // ADAFRUIT_VS1053_H