Skip to content

Conversation

@hathach
Copy link
Member

@hathach hathach commented Jan 8, 2020

  • also add define for PIN_PDM_DIN, PIN_PDM_CLK, PIN_PDM_PWR
  • add PDM setPins() for custom board

- also add define for PIN_PDM_DIN, PIN_PDM_CLK, PIN_PDM_PWR
- add PDM setPins() for custom board
@hathach hathach requested a review from ladyada January 8, 2020 18:14
#define PIN_PDM_PWR -1
#endif

PDMClass PDM(PIN_PDM_DIN, PIN_PDM_CLK, PIN_PDM_PWR);
Copy link
Member Author

@hathach hathach Jan 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PDM is declared within the class like Serial or Wire. It is consistent with current usage of PDM from Arduino nRF528x-mbedos. Making using 3rd party library easier. Also this help to prevent hardfault or linking error on IRQ if PDM is not defined in application sketch.

Note: it requires to remove this line from CPlay library https://github.com/adafruit/Adafruit_CircuitPlayground/blob/master/utility/Adafruit_CPlay_Mic.cpp#L30 . I will submit an PR for this after this once is merged.

PDMClass(int dataPin, int clkPin, int pwrPin);
virtual ~PDMClass();

void setPins(int dataPin, int clkPin, int pwrPin);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add setPins(), will be useful for custom nrf52 board.

/*
* PDM Interfaces
*/
#define PIN_PDM_DIN 24
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently these pin are defined for CPB


// The default Circuit Playground Bluefruit pins
// data pin, clock pin, power pin (-1 if not used)
PDMClass PDM(24, 25, -1);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, we could use PDM directly like we did with Serial

Copy link
Collaborator

@henrygab henrygab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may not result in a working PDM library.

It appears that buffers are provided (via the callback), before they are actually filled by the DMA engine.

I'd like to better understand how using the NVIC disable / enable for the public APIs will (or will not) risk losing samples.



// set the buffer for transfer
// nrf_pdm_buffer_set((uint32_t*)_doubleBuffer.data(), _doubleBuffer.availableForWrite() / (sizeof(int16_t) * _channels));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this still commented, the call a few lines later to trigger the NRF_PDM_TASK_START task will cause the peripheral to work on the nullptr buffer. This doesn't seem right....

size_t avail = _doubleBuffer.available();

//NVIC_EnableIRQ(PDM_IRQn);
NVIC_EnableIRQ(PDM_IRQn);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By disabling the PDM in the NVIC, wouldn't this potentially cause the silent loss of samples of data?
Especially with softdevice enabled, and Bluetooth active, which can pre-empt the execution here and cause unexpectedly long delays while this is still disabled?

// enable and trigger start task
nrf_pdm_enable();
nrf_pdm_event_clear(NRF_PDM_EVENT_STARTED);
nrf_pdm_task_trigger(NRF_PDM_TASK_START);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The register buffer pointer is still set to nullptr. Can you help me understand why this might be intentional?

@hathach
Copy link
Member Author

hathach commented Jan 16, 2020

I think this may not result in a working PDM library.

It appears that buffers are provided (via the callback), before they are actually filled by the DMA engine.

I'd like to better understand how using the NVIC disable / enable for the public APIs will (or will not) risk losing samples.

@henrygab thank you very much for analyzing the PDM implementation, unfortunately I am not capable of answering your question since I just learned about PDM recently. I mostly ste..l hmm use the code from Arduino repo + code comparing. You should really file issue there to get answer from PDM writer.
https://github.com/arduino/ArduinoCore-nRF528x-mbedos/blob/master/libraries/PDM/src/PDM.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants