Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions libraries/PDM/examples/PdmBasic/PdmBasic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "PDM.h"

PdmClass PDM;
void setup()
{
Serial.begin(115200);
if (!PDM.begin(2, 16000)) {
Serial.println("Failed to start PDM!");
while (1);
}

Serial.println("PDM Initialized!");


PDM.end();
}

void loop()
{
// Main loop does nothing, all handled via ISR and callback.
}
32 changes: 32 additions & 0 deletions libraries/PDM/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#######################################
# Syntax Coloring Map For PDM
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

#######################################
# Methods and Functions (KEYWORD2)
#######################################

begin KEYWORD2
end KEYWORD2
available KEYWORD2
read KEYWORD2
onReceive KEYWORD2
setGain KEYWORD2
setBufferSize KEYWORD2


#######################################
# Instances (KEYWORD2)
#######################################

PDM KEYWORD2
Copy link
Member

Choose a reason for hiding this comment

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

As we are going to be able to create multiple instances, this should be a data type -> KEYWORD1


#######################################
# Constants (LITERAL1)
#######################################


10 changes: 10 additions & 0 deletions libraries/PDM/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=PDM
version=0.1.0
author=Infineon Technologies AG
maintainer=Infineon Technologies AG <[email protected]>
sentence=Provides PDM audio input and output support for PSoC6.
paragraph=Implements an easy interface for reading (microphone) and PDM audio streams on PSoC6.
category=Signal Input/Output
url=https://github.com/Infineon/arduino-core-psoc6/tree/main/libraries/PDM
architectures=psoc6
includes=PDM.h
30 changes: 30 additions & 0 deletions libraries/PDM/src/PDM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "PDM.h"

#define PDM_assert(cy_ret) if (cy_ret != CY_RSLT_SUCCESS) { \
return; \
}

bool PdmClass::begin(int channels, int sample_rate) {
Copy link
Member

Choose a reason for hiding this comment

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

As discussed, there are few more things that need to be taken care in the begin:

// Set up config struct (non-const!)
cyhal_pdm_pcm_cfg_t pdm_pcm_cfg = {
.sample_rate = SAMPLE_RATE_HZ,
.decimation_rate = DECIMATION_RATE,
.mode = (channels == 2) ? CYHAL_PDM_PCM_MODE_STEREO : CYHAL_PDM_PCM_MODE_LEFT,
.word_length = 16,
.left_gain = 0,
.right_gain = 0,
};
pdm_pcm_cfg.sample_rate = sample_rate;
pdm_status = cyhal_pdm_pcm_init(&pdm_pcm, PDM_DATA, PDM_CLK, &audio_clock, &pdm_pcm_cfg);
if (pdm_status != CY_RSLT_SUCCESS) {
return false;
}

return true;
}

void PdmClass::end() {
pdm_status = cyhal_pdm_pcm_stop(&pdm_pcm);
PDM_assert(pdm_status);
cyhal_pdm_pcm_free(&pdm_pcm);
}
26 changes: 26 additions & 0 deletions libraries/PDM/src/PDM.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef PDM_H
#define PDM_H

#include "Arduino.h"
#include "cyhal_pdmpcm.h"

#define PDM_DATA P10_5
Copy link
Member

Choose a reason for hiding this comment

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

#define PDM_CLK P10_4

#define SAMPLE_RATE_HZ 8000u
Copy link
Member

Choose a reason for hiding this comment

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

These defines can be private, in the .cpp?

#define DECIMATION_RATE 64u

class PdmClass {
Copy link
Member

Choose a reason for hiding this comment

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

public:
bool begin(int channels, int sample_rate);
void end();

private:
cy_rslt_t pdm_status;
cyhal_clock_t audio_clock;
cyhal_pdm_pcm_t pdm_pcm;
};

extern PdmClass PDM;

#endif
Loading