-
Notifications
You must be signed in to change notification settings - Fork 3
libraries/PDM/src/PDM.cpp: Add PDM begin and end. #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: pdm_integration
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
} |
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 | ||
|
||
####################################### | ||
# Constants (LITERAL1) | ||
####################################### | ||
|
||
|
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 |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should create a constructor which accepts the pins, like -> |
||
#define PDM_CLK P10_4 | ||
|
||
#define SAMPLE_RATE_HZ 8000u | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would name it |
||
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 |
There was a problem hiding this comment.
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