Kaynağa Gözat

Add WM8731 inputSelect() function and update example

dds
PaulStoffregen 6 yıl önce
ebeveyn
işleme
e83ddeefdd
3 değiştirilmiş dosya ile 48 ekleme ve 8 silme
  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 Dosyayı Görüntüle

@@ -109,6 +109,18 @@ bool AudioControlWM8731::inputLevel(float n)
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 Dosyayı Görüntüle

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

+ 35
- 7
examples/HardwareTesting/WM8731MikroSine/WM8731MikroSine.ino Dosyayı Görüntüle

@@ -1,4 +1,4 @@
// 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
// http://www.mikroe.com/add-on-boards/audio-voice/audio-codec-proto/
@@ -10,7 +10,7 @@
// SCK 9
// MISO 13
// MOSI 22
// ADCL
// ADCL 23 (yes, ADCL & DACL connect together)
// DACL 23
// SDA 18
// SCL 19
@@ -26,11 +26,16 @@
#include <SerialFlash.h>

// 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


@@ -44,8 +49,31 @@ void setup() {
waveform1.amplitude(0.9);

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() {
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);
}
}


Yükleniyor…
İptal
Kaydet