Skip to content

Commit 734104b

Browse files
author
Nathan Seidle
committed
Move clock and data defs into variant files. Change begin to use globals by default.
1 parent f027a9c commit 734104b

File tree

8 files changed

+37
-17
lines changed

8 files changed

+37
-17
lines changed

libraries/PDM/examples/Example1_MicrophoneOutput/Example1_MicrophoneOutput.ino

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
Created: July 24, 2019
33
License: MIT. See SparkFun Arduino Apollo3 Project for more information
44
5-
This example demonstrates how to use the PDM microphone on Artemis boards.
5+
This example demonstrates how to use the pulse density microphone (PDM) on Artemis boards.
66
This library and example are heavily based on the Apollo3 pdm_fft example.
77
*/
88

9-
//Global variables needed for this sketch
9+
//Global variables needed for PDM library
1010
#define pdmDataBufferSize 4096 //Default is array of 4096 * 32bit
1111
uint32_t pdmDataBuffer[pdmDataBufferSize];
12+
13+
//Global variables needed for the FFT in this sketch
1214
float g_fPDMTimeDomain[pdmDataBufferSize * 2];
1315
float g_fPDMFrequencyDomain[pdmDataBufferSize * 2];
1416
float g_fPDMMagnitudes[pdmDataBufferSize * 2];
@@ -30,19 +32,13 @@ void setup()
3032
Serial.begin(9600);
3133
Serial.println("SparkFun PDM Example");
3234

33-
// Turn on the PDM, set it up for our chosen recording settings
34-
if (myPDM.begin(22, 23) == false) //Data, clock - These are the pin names from variant file, not pad names
35+
if (myPDM.begin() == false) // Turn on PDM with default settings
3536
{
3637
Serial.println("PDM Init failed. Are you sure these pins are PDM capable?");
3738
while (1);
3839
}
3940
Serial.println("PDM Initialized");
4041

41-
//myPDM.setClockSpeed(AM_HAL_PDM_CLK_3MHZ);
42-
//myPDM.setClockDivider(AM_HAL_PDM_MCLKDIV_1);
43-
//myPDM.setGain(AM_HAL_PDM_GAIN_P210DB);
44-
//myPDM.setChannel(AM_HAL_PDM_CHANNEL_STEREO);
45-
4642
printPDMConfig();
4743

4844
myPDM.getData(pdmDataBuffer, pdmDataBufferSize); //This clears the current PDM FIFO and starts DMA

libraries/PDM/examples/Example2_ConfigureMic/Example2_ConfigureMic.ino

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
This example shows how to modify the various PDM interface settings.
66
*/
77

8-
//Global variables needed for this sketch
8+
//Global variables needed for PDM library
99
#define pdmDataBufferSize 4096 //Default is array of 4096 * 32bit
1010
uint32_t pdmDataBuffer[pdmDataBufferSize];
11+
12+
//Global variables needed for the FFT in this sketch
1113
float g_fPDMTimeDomain[pdmDataBufferSize * 2];
1214
float g_fPDMFrequencyDomain[pdmDataBufferSize * 2];
1315
float g_fPDMMagnitudes[pdmDataBufferSize * 2];
@@ -29,20 +31,26 @@ void setup()
2931
Serial.begin(9600);
3032
Serial.println("SparkFun PDM Example");
3133

32-
// Turn on the PDM, set it up for our chosen recording settings.
33-
if (myPDM.begin(22, 23) == false) //Data, clock - These are the pin names from variant file, not pad names
34+
// The variant files for Artemis carrier boards have Mic data and clock pins defined
35+
// but these pins can be passed to the the .begin function
36+
//if (myPDM.begin() == false) //Use Data, clock defines from variant file
37+
if (myPDM.begin(22, 23) == false) //Data, clock on Artemis Nano - These are the pin names from variant file, not pad names
3438
{
3539
Serial.println("PDM Init failed. Are you sure these pins are PDM capable?");
3640
while (1);
3741
}
3842
Serial.println("PDM Initialized");
3943

40-
//For more settings see the
44+
//Note: The following settings will modifying the settings from default
45+
//and therefore the loudest freq will be 1/2 of what is really happening
46+
//For more AM_HAL_... defines see the am_hal_pdm.h file in the core (/mcu/apollo3/hal/)
4147
myPDM.setClockSpeed(AM_HAL_PDM_CLK_3MHZ);
4248
myPDM.setClockDivider(AM_HAL_PDM_MCLKDIV_1);
4349
myPDM.setGain(AM_HAL_PDM_GAIN_P210DB);
4450
myPDM.setChannel(AM_HAL_PDM_CHANNEL_STEREO);
4551

52+
//The equivalent getGain(), getClockSpeed(), etc are available
53+
4654
printPDMConfig();
4755

4856
myPDM.getData(pdmDataBuffer, pdmDataBufferSize); //This clears the current PDM FIFO and starts DMA

libraries/PDM/examples/Example3_FullConfigure/Example3_FullConfigure.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
that you can access all settings in one step.
88
*/
99

10-
//Global variables needed for this sketch
10+
//Global variables needed for PDM library
1111
#define pdmDataBufferSize 4096 //Default is array of 4096 * 32bit
1212
uint32_t pdmDataBuffer[pdmDataBufferSize];
13+
14+
//Global variables needed for the FFT in this sketch
1315
float g_fPDMTimeDomain[pdmDataBufferSize * 2];
1416
float g_fPDMFrequencyDomain[pdmDataBufferSize * 2];
1517
float g_fPDMMagnitudes[pdmDataBufferSize * 2];
@@ -51,8 +53,8 @@ void setup()
5153
Serial.begin(9600);
5254
Serial.println("SparkFun PDM Example");
5355

54-
// Turn on the PDM, set it up for our chosen recording settings
55-
if (myPDM.begin(22, 23) == false) //Data, clock - These are the pin names from variant file, not pad names
56+
// Turn on the PDM with default settings
57+
if (myPDM.begin() == false) //Use Data, clock defines from variant file
5658
{
5759
Serial.println("PDM Init failed. Are you sure these pins are PDM capable?");
5860
while (1);

libraries/PDM/src/PDM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const am_hal_pdm_config_t ap3_pdm_config_default = {
8585
class AP3_PDM
8686
{
8787
public:
88-
bool begin(ap3_gpio_pin_t pinPDMData, ap3_gpio_pin_t pinPDMClock);
88+
bool begin(ap3_gpio_pin_t pinPDMData = MIC_DATA, ap3_gpio_pin_t pinPDMClock = MIC_CLOCK);
8989
bool available(void); //Goes true once an interrupt has occured
9090

9191
bool setClockSpeed(am_hal_pdm_clkspd_e clockSpeed);

variants/SparkFun_Artemis/config/variant.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,9 @@ extern Uart Serial;
163163
// Many Arduino cores provide a built-in LED for quick verification, like in the Blink sketch
164164
#define LED_BUILTIN 13
165165

166+
// Artemis has a variety of PDM capable pins. These defines can be modified, even excluded
167+
// and declared during myPDM.begin(pdm_data, pdm_clock)
168+
#define MIC_DATA 36
169+
#define MIC_CLOCK 37
170+
166171
#endif // _AP3_VARIANT_H_

variants/SparkFun_BlackBoard_Artemis/config/variant.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,7 @@ extern Uart Serial1;
7575
#define TX1 1
7676
#define RX1 0
7777

78+
#define MIC_DATA 30
79+
#define MIC_CLOCK 31
80+
7881
#endif // _AP3_VARIANT_H_

variants/SparkFun_BlackBoard_Artemis_ATP/config/variant.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,7 @@ extern Uart Serial1;
7575
#define TX1 24
7676
#define RX1 25
7777

78+
#define MIC_DATA 36
79+
#define MIC_CLOCK 37
80+
7881
#endif // _AP3_VARIANT_H_

variants/SparkFun_BlackBoard_Artemis_Nano/config/variant.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,7 @@ extern Uart Serial1;
7474
#define TX1 9
7575
#define RX1 10
7676

77+
#define MIC_DATA 22
78+
#define MIC_CLOCK 23
79+
7780
#endif // _AP3_VARIANT_H_

0 commit comments

Comments
 (0)