PDMGen3_RK
Public Member Functions | Protected Attributes
PDMGen3Static< NUM_SAMPLES > Class Template Reference

Construct a PDM decoder using a static buffer. More...

#include <PDMGen3_RK.h>

Inheritance diagram for PDMGen3Static< NUM_SAMPLES >:
PDMGen3

Public Member Functions

 PDMGen3Static (pin_t clkPin, pin_t datPin)
 Allocate a PDMGen3 object for using the hardware PDM decoder. More...
 
virtual ~PDMGen3Static ()
 Destructor. You typically allocate this as a global variable so it won't be deleted.
 
- Public Member Functions inherited from PDMGen3
 PDMGen3 (pin_t clkPin, pin_t datPin, int16_t *samples, size_t samplesPerBuf)
 Allocate a PDMGen3 object for using the hardware PDM decoder. More...
 
virtual ~PDMGen3 ()
 Destructor. You typically allocate this as a global variable so it won't be deleted.
 
nrfx_err_t init ()
 Initialize the PDM module. More...
 
void uninit ()
 Uniniialize the PDM module. More...
 
nrfx_err_t start ()
 Start sampling.
 
nrfx_err_t stop ()
 Stop sampling.
 
PDMGen3withGainDb (float gainDb)
 Sets the gain in dB. More...
 
PDMGen3withGain (nrf_pdm_gain_t gainL, nrf_pdm_gain_t gainR)
 Sets the PDM gain using an rRF52 configuration value. More...
 
PDMGen3withStereoMode ()
 Set stereo mode. In stereo mode, each buffer will interleave L and R samples. Default is mono mode.
 
PDMGen3withMonoMode ()
 Set mono mode (left channel only). The default is mono mode, so you normally don't need to set this. More...
 
PDMGen3withMode (nrf_pdm_mode_t mode)
 Sets a mode using a nrf_pdm_mode_t constant. Default is NRF_PDM_MODE_MONOl. More...
 
PDMGen3withFreq (nrf_pdm_freq_t freq)
 Sets the sampling frequency. Default is 1.032 MHz, which works out to be a PCM sample rate of 16125 samples/sec. More...
 
PDMGen3withEdge (nrf_pdm_edge_t edge)
 Sets the edge mode. More...
 
PDMGen3withOutputSize (OutputSize outputSize)
 Sets the size of the output samples. More...
 
PDMGen3withRange (Range range)
 Sets the range of the output samples. More...
 
PDMGen3withInterruptCallback (std::function< void(void *sampleBuf, size_t numSamples)> interruptCallback)
 Sets a callback function to be called at interrupt time.
 
void * getAvailableSamples () const
 Call this to poll for available samples from loop() More...
 
void doneWithSamples ()
 Call when you are done using the samples returns from getAvailableSamples(). Required! More...
 
size_t getSamplesPerBuf () const
 Returns the number of samples (not bytes) that was returned from getAvailableSamples()
 

Protected Attributes

int16_t staticBuffer [NUM_SAMPLES *2]
 Buffer to hold samples.
 
- Protected Attributes inherited from PDMGen3
pin_t clkPin
 The pin used for the PDM clock (output)
 
pin_t datPin
 The pin used for the PDM data (input)
 
int16_t * samples
 Buffer to hold samples. There are 2x samples per buf because of double buffering.
 
size_t samplesPerBuf
 Number of samples per each of the double buffers.
 
nrf_pdm_gain_t gainL = NRF_PDM_GAIN_DEFAULT
 0x28 = 0dB gain
 
nrf_pdm_gain_t gainR = NRF_PDM_GAIN_DEFAULT
 0x28 = 0dB gain
 
nrf_pdm_mode_t mode = NRF_PDM_MODE_MONO
 mono or stereo mode
 
nrf_pdm_freq_t freq = NRF_PDM_FREQ_1032K
 clock frequency
 
nrf_pdm_edge_t edge = NRF_PDM_EDGE_LEFTFALLING
 clock edge configuration
 
OutputSize outputSize = OutputSize::SIGNED_16
 Output size (8 or 16 bits)
 
Range range = Range::RANGE_2048
 Range adjustment factor.
 
std::function< void(void *sampleBuf, size_t numSamples)> interruptCallback = NULL
 buffer completion callback
 
bool useBufferA = true
 Which buffer we're reading from of the double buffers.
 
int16_t * availableSamples = NULL
 Used to pass data to loop() for processing out of interrupt context.
 

Additional Inherited Members

- Public Types inherited from PDMGen3
enum  OutputSize { OutputSize::UNSIGNED_8, OutputSize::SIGNED_16, OutputSize::RAW_SIGNED_16 }
 Configuration for the size of the output data. More...
 
enum  Range {
  Range::RANGE_128 = 0, Range::RANGE_256, Range::RANGE_512, Range::RANGE_1024,
  Range::RANGE_2048, Range::RANGE_4096, Range::RANGE_8192, Range::RANGE_16384,
  Range::RANGE_32768
}
 Adjustment value so samples fill most of an 8 or 16 bit output size. More...
 
- Protected Member Functions inherited from PDMGen3
void dataHandler (nrfx_pdm_evt_t const *const pEvent)
 Used internally to handle notifications from the PDM peripheral.
 
- Static Protected Member Functions inherited from PDMGen3
static void dataHandlerStatic (nrfx_pdm_evt_t const *const pEvent)
 Used internally to handle notifications from the PDM peripheral (static function) More...
 
- Static Protected Attributes inherited from PDMGen3
static PDMGen3instance = NULL
 Singleton instance of this class. More...
 

Detailed Description

template<size_t NUM_SAMPLES>
class PDMGen3Static< NUM_SAMPLES >

Construct a PDM decoder using a static buffer.

Parameters
NUM_SAMPLESThe number of samples to save. The number of bytes is 4x this value because each sample is 2 bytes and there are double buffers. The number is must be large enough so you can process the data from loop() without losing samples.

Constructor & Destructor Documentation

◆ PDMGen3Static()

template<size_t NUM_SAMPLES>
PDMGen3Static< NUM_SAMPLES >::PDMGen3Static ( pin_t  clkPin,
pin_t  datPin 
)
inline

Allocate a PDMGen3 object for using the hardware PDM decoder.

Parameters
clkPinClock pin. Use any available GPIO: A0, A1, ..., D0, D1, ... even pins like RX, TX, etc. if you are not using that interface. Will be set as OUTPUT.
datPinData pin. Use any available GPIO. Will be set as INPUT.

The documentation for this class was generated from the following file: