Unverified Commit 783bee5c authored by Calvin Huang's avatar Calvin Huang Committed by GitHub

Add functions to set PDM pins, remove unused pwrPin (#2133)

* functions to set PDM pins

* change pin set method to better match existing libs
parent a4390280
......@@ -25,9 +25,11 @@
class PDMClass {
public:
PDMClass(int dinPin, int clkPin, int pwrPin);
PDMClass(int dinPin, int clkPin);
virtual ~PDMClass();
void setDIN(int dinPin);
void setCLK(int clkPin);
int begin(int channels, int sampleRate);
void end();
......@@ -49,7 +51,6 @@ public:
private:
int _dinPin;
int _clkPin;
int _pwrPin;
int _channels;
int _samplerate;
......@@ -70,6 +71,4 @@ private:
void (*_onReceive)(void);
};
#ifdef PIN_PDM_DIN
extern PDMClass PDM;
#endif
......@@ -36,10 +36,9 @@ extern "C" {
}
PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
PDMClass::PDMClass(int dinPin, int clkPin) :
_dinPin(dinPin),
_clkPin(clkPin),
_pwrPin(pwrPin),
_onReceive(NULL),
_gain(-1),
_channels(-1),
......@@ -55,6 +54,14 @@ PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
PDMClass::~PDMClass() {
}
void PDMClass::setCLK(int clkPin) {
_clkPin = clkPin;
}
void PDMClass::setDIN(int dinPin) {
_dinPin = dinPin;
}
int PDMClass::begin(int channels, int sampleRate) {
if (_init == 1) {
......@@ -62,6 +69,11 @@ int PDMClass::begin(int channels, int sampleRate) {
return 0;
}
if (_dinPin == -1 || _clkPin == -1) {
//ERROR: please call setDIN/setCLK first
return 0;
}
//_channels = channels; // only one channel available
// clear the final buffers
......@@ -228,8 +240,14 @@ void PDMClass::IrqHandler(bool halftranfer) {
_onReceive();
}
}
#ifdef PIN_PDM_DIN
PDMClass PDM(PIN_PDM_DIN, PIN_PDM_CLK, -1);
#ifndef PIN_PDM_DIN
#define PIN_PDM_DIN -1
#endif // PIN_PDM_DIN
//
#ifndef PIN_PDM_CLK
#define PIN_PDM_CLK -1
#endif // PIN_PDM_CLK
PDMClass PDM(PIN_PDM_DIN, PIN_PDM_CLK);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment