Merge pull request #677 from adafruit/fix-pdm

fix pdm issue when bluefruit is enabled
This commit is contained in:
Ha Thach authored and GitHub committed 2021-07-20 01:07:40 +07:00
commit 6e9700442f
2 files changed
+25 -5

No files matched your search

@@ -18,7 +18,7 @@ volatile int samplesRead;
void setup() {
Serial.begin(9600);
while (!Serial);
while (!Serial) yield();
// configure the data receive callback
PDM.onReceive(onPDMdata);
@@ -31,7 +31,7 @@ void setup() {
// - a 16 kHz sample rate
if (!PDM.begin(1, 16000)) {
Serial.println("Failed to start PDM!");
while (1);
while (1) yield();
}
}
+23 -3
View File
@@ -58,9 +58,29 @@ int PDMClass::begin(int channels, long sampleRate)
_channels = channels;
// Enable high frequency oscillator if not already enabled
if (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) { }
uint8_t sd_en = 0;
sd_softdevice_is_enabled(&sd_en);
if (sd_en)
{
uint32_t is_running;
sd_clock_hfclk_is_running(&is_running);
if (!is_running) {
sd_clock_hfclk_request();
while(!is_running) {
yield();
sd_clock_hfclk_is_running(&is_running);
}
}
}
else
{
if (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) yield();
}
}
// configure the sample rate and channels