PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Adafruit_VS1053.h 4.1KB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /***************************************************
  2. This is a library for the Adafruit VS1053 Codec Breakout
  3. Designed specifically to work with the Adafruit VS1053 Codec Breakout
  4. ----> https://www.adafruit.com/products/1381
  5. Adafruit invests time and resources providing this open source code,
  6. please support Adafruit and open-source hardware by purchasing
  7. products from Adafruit!
  8. Written by Limor Fried/Ladyada for Adafruit Industries.
  9. BSD license, all text above must be included in any redistribution
  10. ****************************************************/
  11. #ifndef ADAFRUIT_VS1053_H
  12. #define ADAFRUIT_VS1053_H
  13. #if (ARDUINO >= 100)
  14. #include <Arduino.h>
  15. #else
  16. #include <WProgram.h>
  17. #include <pins_arduino.h>
  18. #endif
  19. #include "pins_arduino.h"
  20. #include "wiring_private.h"
  21. #include <SPI.h>
  22. #include <SD.h>
  23. #define VS1053_FILEPLAYER_TIMER0_INT 255 // allows useInterrupt to accept pins 0 to 254
  24. #define VS1053_FILEPLAYER_PIN_INT 5
  25. #define VS1053_SCI_READ 0x03
  26. #define VS1053_SCI_WRITE 0x02
  27. #define VS1053_REG_MODE 0x00
  28. #define VS1053_REG_STATUS 0x01
  29. #define VS1053_REG_BASS 0x02
  30. #define VS1053_REG_CLOCKF 0x03
  31. #define VS1053_REG_DECODETIME 0x04
  32. #define VS1053_REG_AUDATA 0x05
  33. #define VS1053_REG_WRAM 0x06
  34. #define VS1053_REG_WRAMADDR 0x07
  35. #define VS1053_REG_HDAT0 0x08
  36. #define VS1053_REG_HDAT1 0x09
  37. #define VS1053_REG_VOLUME 0x0B
  38. #define VS1053_GPIO_DDR 0xC017
  39. #define VS1053_GPIO_IDATA 0xC018
  40. #define VS1053_GPIO_ODATA 0xC019
  41. #define VS1053_INT_ENABLE 0xC01A
  42. #define VS1053_MODE_SM_DIFF 0x0001
  43. #define VS1053_MODE_SM_LAYER12 0x0002
  44. #define VS1053_MODE_SM_RESET 0x0004
  45. #define VS1053_MODE_SM_CANCEL 0x0008
  46. #define VS1053_MODE_SM_EARSPKLO 0x0010
  47. #define VS1053_MODE_SM_TESTS 0x0020
  48. #define VS1053_MODE_SM_STREAM 0x0040
  49. #define VS1053_MODE_SM_SDINEW 0x0800
  50. #define VS1053_MODE_SM_ADPCM 0x1000
  51. #define VS1053_MODE_SM_LINE1 0x4000
  52. #define VS1053_MODE_SM_CLKRANGE 0x8000
  53. #define VS1053_SCI_AIADDR 0x0A
  54. #define VS1053_SCI_AICTRL0 0x0C
  55. #define VS1053_SCI_AICTRL1 0x0D
  56. #define VS1053_SCI_AICTRL2 0x0E
  57. #define VS1053_SCI_AICTRL3 0x0F
  58. #define VS1053_DATABUFFERLEN 32
  59. class Adafruit_VS1053 {
  60. public:
  61. Adafruit_VS1053(int8_t mosi, int8_t miso, int8_t clk,
  62. int8_t rst, int8_t cs, int8_t dcs, int8_t dreq);
  63. Adafruit_VS1053(int8_t rst, int8_t cs, int8_t dcs, int8_t dreq);
  64. uint8_t begin(void);
  65. void reset(void);
  66. void softReset(void);
  67. uint16_t sciRead(uint8_t addr);
  68. void sciWrite(uint8_t addr, uint16_t data);
  69. void sineTest(uint8_t n, uint16_t ms);
  70. void spiwrite(uint8_t d);
  71. uint8_t spiread(void);
  72. uint16_t decodeTime(void);
  73. void setVolume(uint8_t left, uint8_t right);
  74. void dumpRegs(void);
  75. void playData(uint8_t *buffer, uint8_t buffsiz);
  76. boolean readyForData(void);
  77. void applyPatch(const uint16_t *patch, uint16_t patchsize);
  78. uint16_t loadPlugin(char *fn);
  79. void GPIO_digitalWrite(uint8_t i, uint8_t val);
  80. void GPIO_digitalWrite(uint8_t i);
  81. uint16_t GPIO_digitalRead(void);
  82. boolean GPIO_digitalRead(uint8_t i);
  83. void GPIO_pinMode(uint8_t i, uint8_t dir);
  84. boolean prepareRecordOgg(char *plugin);
  85. void startRecordOgg(boolean mic);
  86. void stopRecordOgg(void);
  87. uint16_t recordedWordsWaiting(void);
  88. uint16_t recordedReadWord(void);
  89. uint8_t mp3buffer[VS1053_DATABUFFERLEN];
  90. protected:
  91. uint8_t _dreq;
  92. private:
  93. int8_t _mosi, _miso, _clk, _reset, _cs, _dcs;
  94. boolean useHardwareSPI;
  95. };
  96. class Adafruit_VS1053_FilePlayer : public Adafruit_VS1053 {
  97. public:
  98. Adafruit_VS1053_FilePlayer (int8_t mosi, int8_t miso, int8_t clk,
  99. int8_t rst, int8_t cs, int8_t dcs, int8_t dreq,
  100. int8_t cardCS);
  101. Adafruit_VS1053_FilePlayer (int8_t rst, int8_t cs, int8_t dcs, int8_t dreq,
  102. int8_t cardCS);
  103. Adafruit_VS1053_FilePlayer (int8_t cs, int8_t dcs, int8_t dreq,
  104. int8_t cardCS);
  105. boolean begin(void);
  106. boolean useInterrupt(uint8_t type);
  107. File currentTrack;
  108. boolean playingMusic;
  109. void feedBuffer(void);
  110. boolean startPlayingFile(const char *trackname);
  111. boolean playFullFile(const char *trackname);
  112. void stopPlaying(void);
  113. boolean paused(void);
  114. boolean stopped(void);
  115. void pausePlaying(boolean pause);
  116. private:
  117. uint8_t _cardCS;
  118. };
  119. #endif // ADAFRUIT_VS1053_H