| @@ -495,10 +495,18 @@ | |||
| #define DAP_COEF_WR_A2_MSB 0x0138 | |||
| #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) | |||
| { | |||
| @@ -536,11 +544,11 @@ bool AudioControlSGTL5000::enable(void) | |||
| unsigned int AudioControlSGTL5000::read(unsigned int reg) | |||
| { | |||
| unsigned int val; | |||
| Wire.beginTransmission(SGTL5000_I2C_ADDR); | |||
| Wire.beginTransmission(i2c_addr); | |||
| Wire.write(reg >> 8); | |||
| Wire.write(reg); | |||
| 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(); | |||
| return val; | |||
| @@ -549,7 +557,7 @@ unsigned int AudioControlSGTL5000::read(unsigned int reg) | |||
| bool AudioControlSGTL5000::write(unsigned int reg, unsigned int 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); | |||
| Wire.write(val >> 8); | |||
| @@ -32,6 +32,8 @@ | |||
| class AudioControlSGTL5000 : public AudioControl | |||
| { | |||
| public: | |||
| AudioControlSGTL5000(void) : i2c_addr(0x0A) { } | |||
| void setAddress(uint8_t level); | |||
| bool enable(void); | |||
| bool disable(void) { return false; } | |||
| bool volume(float n) { return volumeInteger(n * 129 + 0.499); } | |||
| @@ -92,6 +94,7 @@ protected: | |||
| bool muted; | |||
| bool volumeInteger(unsigned int n); // range: 0x00 to 0x80 | |||
| uint16_t ana_ctrl; | |||
| uint8_t i2c_addr; | |||
| unsigned char calcVol(float n, unsigned char range); | |||
| unsigned int read(unsigned int reg); | |||
| bool write(unsigned int reg, unsigned int val); | |||
| @@ -0,0 +1,67 @@ | |||
| // 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 | |||
| } | |||
| } | |||
| @@ -79,6 +79,7 @@ output KEYWORD2 | |||
| trigger KEYWORD2 | |||
| length KEYWORD2 | |||
| threshold KEYWORD2 | |||
| setAddress KEYWORD2 | |||
| enable KEYWORD2 | |||
| enableIn KEYWORD2 | |||
| enableOut KEYWORD2 | |||