Browse Source

Add WM8731 inputSelect() function and update example

dds
PaulStoffregen 6 years ago
parent
commit
e83ddeefdd
3 changed files with 48 additions and 8 deletions
  1. +12
    -0
      control_wm8731.cpp
  2. +1
    -1
      control_wm8731.h
  3. +35
    -7
      examples/HardwareTesting/WM8731MikroSine/WM8731MikroSine.ino

+ 12
- 0
control_wm8731.cpp View File

return true; return true;
} }


bool AudioControlWM8731::inputSelect(int n)
{
if (n == AUDIO_INPUT_LINEIN) {
write(WM8731_REG_ANALOG, 0x12);
} else if (n == AUDIO_INPUT_MIC) {
write(WM8731_REG_ANALOG, 0x15);
} else {
return false;
}
return true;
}

/******************************************************************/ /******************************************************************/





+ 1
- 1
control_wm8731.h View File

bool disable(void) { return false; } bool disable(void) { return false; }
bool volume(float n) { return volumeInteger(n * 80.0 + 47.499); } bool volume(float n) { return volumeInteger(n * 80.0 + 47.499); }
bool inputLevel(float n); // range: 0.0f to 1.0f bool inputLevel(float n); // range: 0.0f to 1.0f
bool inputSelect(int n) { return false; }
bool inputSelect(int n);
protected: protected:
bool write(unsigned int reg, unsigned int val); bool write(unsigned int reg, unsigned int val);
bool volumeInteger(unsigned int n); // range: 0x2F to 0x7F bool volumeInteger(unsigned int n); // range: 0x2F to 0x7F

+ 35
- 7
examples/HardwareTesting/WM8731MikroSine/WM8731MikroSine.ino View File

// Simple sine wave test for WM8731 Audio Codec Board
// Simple sine wave & input level test for WM8731 Audio Codec Board
// //
// Requires the MikroElektronika Audio Codec board or similar hardware // Requires the MikroElektronika Audio Codec board or similar hardware
// http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/ // http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/
// SCK 9 // SCK 9
// MISO 13 // MISO 13
// MOSI 22 // MOSI 22
// ADCL
// ADCL 23 (yes, ADCL & DACL connect together)
// DACL 23 // DACL 23
// SDA 18 // SDA 18
// SCL 19 // SCL 19
#include <SerialFlash.h> #include <SerialFlash.h>


// GUItool: begin automatically generated code // GUItool: begin automatically generated code
AudioSynthWaveform waveform1; //xy=110,75
AudioOutputI2Sslave i2ss1; //xy=303,78
AudioConnection patchCord1(waveform1, 0, i2ss1, 0);
AudioConnection patchCord2(waveform1, 0, i2ss1, 1);
AudioControlWM8731master wm8731m1; //xy=230,154
AudioSynthWaveform waveform1; //xy=245,160
AudioInputI2Sslave i2sslave1; //xy=265,252
AudioOutputI2Sslave i2sslave2; //xy=429,158
AudioAnalyzeRMS rms2; //xy=436,323
AudioAnalyzeRMS rms1; //xy=444,265
AudioConnection patchCord1(waveform1, 0, i2sslave2, 0);
AudioConnection patchCord2(waveform1, 0, i2sslave2, 1);
AudioConnection patchCord3(i2sslave1, 0, rms1, 0);
AudioConnection patchCord4(i2sslave1, 1, rms2, 0);
AudioControlWM8731master wm8731m1; //xy=292,379
// GUItool: end automatically generated code // GUItool: end automatically generated code




waveform1.amplitude(0.9); waveform1.amplitude(0.9);


wm8731m1.volume(0.50); wm8731m1.volume(0.50);
wm8731m1.inputSelect(AUDIO_INPUT_MIC);
// wm8731m1.inputSelect(AUDIO_INPUT_LINEIN); // not connected on MikroE-516
} }


elapsedMillis msec;


// Print a simple level meter
void loop() { void loop() {
if (msec > 40) {
if (rms1.available() && rms2.available()) {
msec = 0;
int level_left = rms1.read() * 30.0;
int level_right = rms2.read() * 30.0;
printchar(' ', 30 - level_left);
printchar('<', level_left);
Serial.print("||");
printchar('>', level_right);
Serial.println();
}
}
} }

void printchar(char c, int num) {
for (int i=0; i < num; i++) {
Serial.write(c);
}
}


Loading…
Cancel
Save