#define DAP_COEF_WR_A2_MSB 0x0138 | #define DAP_COEF_WR_A2_MSB 0x0138 | ||||
#define DAP_COEF_WR_A2_LSB 0x013A | #define DAP_COEF_WR_A2_LSB 0x013A | ||||
#define SGTL5000_I2C_ADDR 0x0A // CTRL_ADR0_CS pin low (normal configuration) | |||||
//#define SGTL5000_I2C_ADDR 0x2A // CTRL_ADR0_CS pin high | |||||
#define SGTL5000_I2C_ADDR_CS_LOW 0x0A // CTRL_ADR0_CS pin low (normal configuration) | |||||
#define SGTL5000_I2C_ADDR_CS_HIGH 0x2A // CTRL_ADR0_CS pin high | |||||
void AudioControlSGTL5000::setAddress(uint8_t level) | |||||
{ | |||||
if (level == LOW) { | |||||
i2c_addr = SGTL5000_I2C_ADDR_CS_LOW; | |||||
} else { | |||||
i2c_addr = SGTL5000_I2C_ADDR_CS_HIGH; | |||||
} | |||||
} | |||||
bool AudioControlSGTL5000::enable(void) | bool AudioControlSGTL5000::enable(void) | ||||
{ | { | ||||
unsigned int AudioControlSGTL5000::read(unsigned int reg) | unsigned int AudioControlSGTL5000::read(unsigned int reg) | ||||
{ | { | ||||
unsigned int val; | unsigned int val; | ||||
Wire.beginTransmission(SGTL5000_I2C_ADDR); | |||||
Wire.beginTransmission(i2c_addr); | |||||
Wire.write(reg >> 8); | Wire.write(reg >> 8); | ||||
Wire.write(reg); | Wire.write(reg); | ||||
if (Wire.endTransmission(false) != 0) return 0; | if (Wire.endTransmission(false) != 0) return 0; | ||||
if (Wire.requestFrom(SGTL5000_I2C_ADDR, 2) < 2) return 0; | |||||
if (Wire.requestFrom((int)i2c_addr, 2) < 2) return 0; | |||||
val = Wire.read() << 8; | val = Wire.read() << 8; | ||||
val |= Wire.read(); | val |= Wire.read(); | ||||
return val; | return val; | ||||
bool AudioControlSGTL5000::write(unsigned int reg, unsigned int val) | bool AudioControlSGTL5000::write(unsigned int reg, unsigned int val) | ||||
{ | { | ||||
if (reg == CHIP_ANA_CTRL) ana_ctrl = val; | if (reg == CHIP_ANA_CTRL) ana_ctrl = val; | ||||
Wire.beginTransmission(SGTL5000_I2C_ADDR); | |||||
Wire.beginTransmission(i2c_addr); | |||||
Wire.write(reg >> 8); | Wire.write(reg >> 8); | ||||
Wire.write(reg); | Wire.write(reg); | ||||
Wire.write(val >> 8); | Wire.write(val >> 8); |
class AudioControlSGTL5000 : public AudioControl | class AudioControlSGTL5000 : public AudioControl | ||||
{ | { | ||||
public: | public: | ||||
AudioControlSGTL5000(void) : i2c_addr(0x0A) { } | |||||
void setAddress(uint8_t level); | |||||
bool enable(void); | bool enable(void); | ||||
bool disable(void) { return false; } | bool disable(void) { return false; } | ||||
bool volume(float n) { return volumeInteger(n * 129 + 0.499); } | bool volume(float n) { return volumeInteger(n * 129 + 0.499); } | ||||
bool muted; | bool muted; | ||||
bool volumeInteger(unsigned int n); // range: 0x00 to 0x80 | bool volumeInteger(unsigned int n); // range: 0x00 to 0x80 | ||||
uint16_t ana_ctrl; | uint16_t ana_ctrl; | ||||
uint8_t i2c_addr; | |||||
unsigned char calcVol(float n, unsigned char range); | unsigned char calcVol(float n, unsigned char range); | ||||
unsigned int read(unsigned int reg); | unsigned int read(unsigned int reg); | ||||
bool write(unsigned int reg, unsigned int val); | bool write(unsigned int reg, unsigned int val); |
// Quad channel output test | |||||
// Play two WAV files on two audio shields. | |||||
// | |||||
// TODO: add info about required hardware connections here.... | |||||
// | |||||
// Data files to put on your SD card can be downloaded here: | |||||
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html | |||||
// | |||||
// This example code is in the public domain. | |||||
#include <Audio.h> | |||||
#include <Wire.h> | |||||
#include <SPI.h> | |||||
#include <SD.h> | |||||
#include <SerialFlash.h> | |||||
AudioPlaySdWav playSdWav1; | |||||
AudioPlaySdWav playSdWav2; | |||||
AudioOutputI2SQuad audioOutput; | |||||
AudioConnection patchCord1(playSdWav1, 0, audioOutput, 0); | |||||
AudioConnection patchCord2(playSdWav1, 1, audioOutput, 1); | |||||
AudioConnection patchCord3(playSdWav2, 0, audioOutput, 2); | |||||
AudioConnection patchCord4(playSdWav2, 1, audioOutput, 3); | |||||
AudioControlSGTL5000 sgtl5000_1; | |||||
AudioControlSGTL5000 sgtl5000_2; | |||||
// Use these with the audio adaptor board | |||||
#define SDCARD_CS_PIN 10 | |||||
#define SDCARD_MOSI_PIN 7 | |||||
#define SDCARD_SCK_PIN 14 | |||||
void setup() { | |||||
Serial.begin(9600); | |||||
AudioMemory(10); | |||||
sgtl5000_1.setAddress(LOW); | |||||
sgtl5000_1.enable(); | |||||
sgtl5000_1.volume(0.5); | |||||
sgtl5000_2.setAddress(HIGH); | |||||
sgtl5000_2.enable(); | |||||
sgtl5000_2.volume(0.5); | |||||
SPI.setMOSI(SDCARD_MOSI_PIN); | |||||
SPI.setSCK(SDCARD_SCK_PIN); | |||||
if (!(SD.begin(SDCARD_CS_PIN))) { | |||||
// stop here, but print a message repetitively | |||||
while (1) { | |||||
Serial.println("Unable to access the SD card"); | |||||
delay(500); | |||||
} | |||||
} | |||||
} | |||||
void loop() { | |||||
if (playSdWav1.isPlaying() == false) { | |||||
Serial.println("Start playing 1"); | |||||
playSdWav1.play("SDTEST2.WAV"); | |||||
delay(10); // wait for library to parse WAV info | |||||
} | |||||
if (playSdWav2.isPlaying() == false) { | |||||
Serial.println("Start playing 2"); | |||||
playSdWav2.play("SDTEST4.WAV"); | |||||
delay(10); // wait for library to parse WAV info | |||||
} | |||||
} | |||||
trigger KEYWORD2 | trigger KEYWORD2 | ||||
length KEYWORD2 | length KEYWORD2 | ||||
threshold KEYWORD2 | threshold KEYWORD2 | ||||
setAddress KEYWORD2 | |||||
enable KEYWORD2 | enable KEYWORD2 | ||||
enableIn KEYWORD2 | enableIn KEYWORD2 | ||||
enableOut KEYWORD2 | enableOut KEYWORD2 |