8000 Add functions to set PDM pins, remove unused pwrPin (#2133) · MaikHo/arduino-pico@783bee5 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 783bee5

Browse files
authored
Add functions to set PDM pins, remove unused pwrPin (earlephilhower#2133)
* functions to set PDM pins * change pin set method to better match existing libs
1 parent a439028 commit 783bee5

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

libraries/PDM/src/PDM.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525

2626
class PDMClass {
2727
public:
28-
PDMClass(int dinPin, int clkPin, int pwrPin);
28+
PDMClass(int dinPin, int clkPin);
2929
virtual ~PDMClass();
3030

31+
void setDIN(int dinPin);
32+
void setCLK(int clkPin);
3133
int begin(int channels, int sampleRate);
3234
void end();
3335

@@ -49,7 +51,6 @@ class PDMClass {
4951
private:
5052
int _dinPin;
5153
int _clkPin;
52-
int _pwrPin;
5354

5455
int _channels;
5556
int _samplerate;
@@ -70,6 +71,4 @@ class PDMClass {
7071
void (*_onReceive)(void);
7172
};
7273

73-
#ifdef PIN_PDM_DIN
7474
extern PDMClass PDM;
75-
#endif

libraries/PDM/src/rp2040/PDM.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ extern "C" {
3636
}
3737

3838

39-
PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
39+
PDMClass::PDMClass(int dinPin, int clkPin) :
4040
_dinPin(dinPin),
4141
_clkPin(clkPin),
42-
_pwrPin(pwrPin),
4342
_onReceive(NULL),
4443
_gain(-1),
4544
_channels(-1),
@@ -55,13 +54,26 @@ PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
5554
PDMClass::~PDMClass() {
5655
}
5756

57+
void PDMClass::setCLK(int clkPin) {
58+
_clkPin = clkPin;
59+
}
60+
61+
void PDMClass::setDIN(int dinPin) {
62+
_dinPin = dinPin;
63+
}
64+
5865
int PDMClass::begin(int channels, int sampleRate) {
5966

6067
if (_init == 1) {
6168
//ERROR: please call end first
6269
return 0;
6370
}
6471

72+
if (_dinPin == -1 || _clkPin == -1) {
73+
//ERROR: please call setDIN/setCLK first
74+
return 0;
75+
}
76+
6577
//_channels = channels; // only one channel available
6678

6779
// clear the final buffers
@@ -228,8 +240,14 @@ void PDMClass::IrqHandler(bool halftranfer) {
228240
_onReceive();
229241
}
230242
}
231-
#ifdef PIN_PDM_DIN
232-
PDMClass PDM(PIN_PDM_DIN, PIN_PDM_CLK, -1);
243+
#ifndef PIN_PDM_DIN
244+
#define PIN_PDM_DIN -1
233245
#endif // PIN_PDM_DIN
246+
//
247+
#ifndef PIN_PDM_CLK
248+
#define PIN_PDM_CLK -1
249+
#endif // PIN_PDM_CLK
250+
251+
PDMClass PDM(PIN_PDM_DIN, PIN_PDM_CLK);
234252

235253

0 commit comments

Comments
 (0)
0