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 @@ ...@@ -25,9 +25,11 @@
class PDMClass { class PDMClass {
public: public:
PDMClass(int dinPin, int clkPin, int pwrPin); PDMClass(int dinPin, int clkPin);
virtual ~PDMClass(); virtual ~PDMClass();
void setDIN(int dinPin);
void setCLK(int clkPin);
int begin(int channels, int sampleRate); int begin(int channels, int sampleRate);
void end(); void end();
...@@ -49,7 +51,6 @@ public: ...@@ -49,7 +51,6 @@ public:
private: private:
int _dinPin; int _dinPin;
int _clkPin; int _clkPin;
int _pwrPin;
int _channels; int _channels;
int _samplerate; int _samplerate;
...@@ -70,6 +71,4 @@ private: ...@@ -70,6 +71,4 @@ private:
void (*_onReceive)(void); void (*_onReceive)(void);
}; };
#ifdef PIN_PDM_DIN
extern PDMClass PDM; extern PDMClass PDM;
#endif
...@@ -36,10 +36,9 @@ extern "C" { ...@@ -36,10 +36,9 @@ extern "C" {
} }
PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) : PDMClass::PDMClass(int dinPin, int clkPin) :
_dinPin(dinPin), _dinPin(dinPin),
_clkPin(clkPin), _clkPin(clkPin),
_pwrPin(pwrPin),
_onReceive(NULL), _onReceive(NULL),
_gain(-1), _gain(-1),
_channels(-1), _channels(-1),
...@@ -55,6 +54,14 @@ PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) : ...@@ -55,6 +54,14 @@ PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
PDMClass::~PDMClass() { PDMClass::~PDMClass() {
} }
void PDMClass::setCLK(int clkPin) {
_clkPin = clkPin;
}
void PDMClass::setDIN(int dinPin) {
_dinPin = dinPin;
}
int PDMClass::begin(int channels, int sampleRate) { int PDMClass::begin(int channels, int sampleRate) {
if (_init == 1) { if (_init == 1) {
...@@ -62,6 +69,11 @@ int PDMClass::begin(int channels, int sampleRate) { ...@@ -62,6 +69,11 @@ int PDMClass::begin(int channels, int sampleRate) {
return 0; return 0;
} }
if (_dinPin == -1 || _clkPin == -1) {
//ERROR: please call setDIN/setCLK first
return 0;
}
//_channels = channels; // only one channel available //_channels = channels; // only one channel available
// clear the final buffers // clear the final buffers
...@@ -228,8 +240,14 @@ void PDMClass::IrqHandler(bool halftranfer) { ...@@ -228,8 +240,14 @@ void PDMClass::IrqHandler(bool halftranfer) {
_onReceive(); _onReceive();
} }
} }
#ifdef PIN_PDM_DIN #ifndef PIN_PDM_DIN
PDMClass PDM(PIN_PDM_DIN, PIN_PDM_CLK, -1); #define PIN_PDM_DIN -1
#endif // PIN_PDM_DIN #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