Skip to content

Commit c4d43bb

Browse files
committed
Store PDM instance
1 parent 3810682 commit c4d43bb

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

libraries/PDM/src/PDM.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 3 deletions
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) {
@@ -146,15 +149,15 @@ void PDMClass::IrqHandler(bool halftranfer)
146149
extern "C" {
147150
void PDMIrqHandler(bool halftranfer)
148151
{
149-
PDM.IrqHandler(halftranfer);
152+
_instance->IrqHandler(halftranfer);
150153
}
151154

152155
void PDMsetBufferSize(int size) {
153-
PDM.setBufferSize(size);
156+
_instance->setBufferSize(size);
154157
}
155158

156159
size_t PDMgetBufferSize() {
157-
return PDM.getBufferSize();
160+
return _instance.getBufferSize();
158161
}
159162
}
160163

0 commit comments

Comments
 (0)