@@ -24,7 +24,6 @@ SOFTWARE.
24
24
AP3_PDM *ap3_pdm_handle = 0 ;
25
25
am_hal_pdm_transfer_t sTransfer ;
26
26
27
- // Temp
28
27
#define internalPDMDataBufferSize 4096 // Default is array of 4096 * 32bit
29
28
uint32_t internalPDMDataBuffer[internalPDMDataBufferSize];
30
29
@@ -215,6 +214,8 @@ bool AP3_PDM::updateConfig(am_hal_pdm_config_t newConfiguration)
215
214
_PDMconfig = newConfiguration;
216
215
ap3_err_t retval = (ap3_err_t )am_hal_pdm_configure (_PDMhandle, &_PDMconfig);
217
216
217
+ am_hal_pdm_enable (_PDMhandle); // Reenable after changes
218
+
218
219
if (retval != AP3_OK)
219
220
{
220
221
return false ;
@@ -267,18 +268,23 @@ ap3_err_t ap3_pdm_pad_funcsel(ap3_pdm_pad_type_e type, ap3_gpio_pad_t pad, uint8
267
268
268
269
// *****************************************************************************
269
270
//
270
- // Start a transaction to get some number of bytes from the PDM interface.
271
+ // Read PDM data from internal buffer
272
+ // Returns number of bytes read.
271
273
//
272
274
// *****************************************************************************
273
- void AP3_PDM::getData (uint32_t *externalBuffer, uint32_t bufferSize)
275
+ uint32_t AP3_PDM::getData (uint32_t *externalBuffer, uint32_t bufferSize)
274
276
{
275
277
if (_PDMdataReady)
276
278
{
279
+ if (bufferSize > internalPDMDataBufferSize)
280
+ bufferSize = internalPDMDataBufferSize;
281
+
277
282
noInterrupts ();
278
283
279
284
// Move data from internal buffer to external caller
280
285
for (int x = 0 ; x < bufferSize; x++)
281
- externalBuffer[x] = internalPDMDataBuffer[x]; // Not clear, PDMDataBuffer is bufferSize * 2, do we need just the one left byte vs one right byte?
286
+ externalBuffer[x] = internalPDMDataBuffer[x];
287
+
282
288
interrupts ();
283
289
}
284
290
_PDMdataReady = false ;
@@ -297,23 +303,16 @@ inline void AP3_PDM::pdm_isr(void)
297
303
am_hal_pdm_interrupt_status_get (_PDMhandle, &ui32Status, true );
298
304
am_hal_pdm_interrupt_clear (_PDMhandle, ui32Status);
299
305
300
- //
301
- // Once our DMA transaction completes, we will disable the PDM and send a
302
- // flag back down to the main routine. Disabling the PDM is only necessary
303
- // because this example only implemented a single buffer for storing FFT
304
- // data. More complex programs could use a system of multiple buffers to
305
- // allow the CPU to run the FFT in one buffer while the DMA pulls PCM data
306
- // into another buffer.
307
- //
308
306
if (ui32Status & AM_HAL_PDM_INT_DCMP)
309
307
{
310
308
if (_PDMdataReady == true )
311
- Serial.println (" Buffer overrun!" );
312
- else
313
309
{
314
- // New data has been loaded into internalPDMDataBuffer
315
- _PDMdataReady = true ;
310
+ // If flag has not previously been cleared, we're overrun
311
+ // Serial.println("Buffer overrun!") ;
316
312
}
313
+
314
+ // New data has been loaded into internalPDMDataBuffer
315
+ _PDMdataReady = true ;
317
316
}
318
317
}
319
318
0 commit comments