Skip to content

Commit e50ec8a

Browse files
authored
Merge pull request #199 from pennam/pdm_breakout
PDM breakout
2 parents 1082779 + 6ef24ac commit e50ec8a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

libraries/PDM/src/PDM.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class PDMClass
5959
int _init;
6060

6161
PDMDoubleBuffer _doubleBuffer;
62-
62+
6363
void (*_onReceive)(void);
6464
};
6565

libraries/PDM/src/stm32/PDM.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern "C" {
2929
}
3030

3131
extern "C" uint16_t *g_pcmbuf;
32+
static PDMClass *_instance = NULL;
3233

3334
PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
3435
_dinPin(dinPin),
@@ -40,10 +41,12 @@ PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
4041
_samplerate(-1),
4142
_init(-1)
4243
{
44+
_instance = this;
4345
}
4446

4547
PDMClass::~PDMClass()
4648
{
49+
_instance = NULL;
4750
}
4851

4952
int PDMClass::begin(int channels, int sampleRate) {
@@ -63,6 +66,10 @@ int PDMClass::begin(int channels, int sampleRate) {
6366
i2c.write(8 << 1, data, sizeof(data));
6467
}
6568

69+
if(_instance != this) {
70+
return 0;
71+
}
72+
6673
_channels = channels;
6774
_samplerate = sampleRate;
6875

@@ -102,6 +109,9 @@ int PDMClass::read(void* buffer, size_t size)
102109
void PDMClass::onReceive(void(*function)(void))
103110
{
104111
_onReceive = function;
112+
if(_instance != this) {
113+
_instance = this;
114+
}
105115
}
106116

107117
void PDMClass::setGain(int gain)
@@ -146,15 +156,15 @@ void PDMClass::IrqHandler(bool halftranfer)
146156
extern "C" {
147157
void PDMIrqHandler(bool halftranfer)
148158
{
149-
PDM.IrqHandler(halftranfer);
159+
_instance->IrqHandler(halftranfer);
150160
}
151161

152162
void PDMsetBufferSize(int size) {
153-
PDM.setBufferSize(size);
163+
_instance->setBufferSize(size);
154164
}
155165

156166
size_t PDMgetBufferSize() {
157-
return PDM.getBufferSize();
167+
return _instance.getBufferSize();
158168
}
159169
}
160170

0 commit comments

Comments
 (0)