Skip to content

Commit

Permalink
nRF52: Docs n small changes to examples
Browse files Browse the repository at this point in the history
- Allow configuration of PDM pins via variables pwrPin, dinPin, clkPin & gain
- Add documentation for pin config stuff & buffer sizing
- Fix examples to just choose SD card pin, not speed
  • Loading branch information
TMRh20 committed Nov 1, 2024
1 parent bd11619 commit f08291b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void setup() {
radio.stopListening();

Serial.print("Init SD card...");
if (!SD.begin(10000000, 2)) {
if (!SD.begin(2)) {
Serial.println("init failed!");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void setup() {
Serial.begin(115200);

Serial.print("Init SD card...");
if (!SD.begin(10000000, 2)) {
if (!SD.begin(2)) {
Serial.println("init failed!");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void setup() {
Serial.begin(115200);

Serial.print("Init SD card...");
if (!SD.begin(2, 32000000)) {
if (!SD.begin(2)) {
Serial.println("init failed!");
return;
}
Expand Down
76 changes: 71 additions & 5 deletions src/AutoAnalogAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ class AutoAnalog
TaskHandle_t dacTaskHandle;
#endif

/**@}*/

#if defined (ARDUINO_ARCH_NRF52840) || defined (ARDUINO_ARCH_NRF52) && !defined ARDUINO_NRF52840_FEATHER && defined __MBED__
inline static uint8_t aCtr;
Expand Down Expand Up @@ -224,13 +223,74 @@ class AutoAnalog
uint32_t sampleCounter;
//void DACC_Handler();
#endif
#if defined (ARDUINO_ARCH_NRF52840) || defined (ARDUINO_ARCH_NRF52)
bool micOn;

#if defined (ARDUINO_ARCH_NRF52840) || defined (ARDUINO_ARCH_NRF52) || defined (DOXYGEN_FORCED)
/**@}*/
/**
* @name Section for nRF52 Devices Only
*
* This section is for nRF52 devices only
*
*
*/
/**@{*/

/**
* Set the Power Pin for PDM
* By default this is PIN_PDM_PWR
* If PIN_PDM_PWR is not defined, it is set to -1 by default
* Configure this before calling `begin()`
*/
int pwrPin;

/**
* Set the Input Pin for PDM
* By default this is PIN_PDM_DIN
* If PIN_PDM_DIN is not defined, it is set to 35 by default
* Configure this before calling `begin()`
*/
int dinPin;

/**
* Set the Clock Pin for PDM
* By default this is PIN_PDM_CLK
* If PIN_PDM_CLK is not defined, it is set to 36 by default
* Configure this before calling `begin()`
*/
int clkPin;

/**
* Set the Gain for PDM
* By default this is set to 40
* Configure this before calling `begin()`
*/
int8_t gain;

/**
* Enable I2S on nRF52
* By default this is disabled (analog output using PWM)
*
* @code
* aaAudio.begin(1,1,3);
* @endcode
* @param Set to 1 for I2S DAC, 2 for I2S ADC, 3 for both
*/
uint8_t useI2S;

/**
* Configure the pins and ports for nRF52 using GPIO numbers before calling `begin()`
* Defaults:
* I2S_PIN_MCK = 2;
* I2S_PORT_MCK = 0;
* I2S_PIN_SCK = 3;
* I2S_PORT_SCK = 0;
* I2S_PIN_LRCK = 29;
* I2S_PORT_LRCK = 0;
* I2S_PIN_SDOUT = 5;
* I2S_PORT_SDOUT = 0;
* I2S_PIN_SDIN = 4;
* I2S_PORT_SDIN = 0;
*/
uint16_t I2S_PIN_MCK;
uint8_t I2S_PORT_MCK;
uint16_t I2S_PIN_SCK;
Expand All @@ -241,12 +301,18 @@ class AutoAnalog
uint8_t I2S_PORT_SDOUT;
uint16_t I2S_PIN_SDIN;
uint8_t I2S_PORT_SDIN;

/**
* Set the maximum buffer size for nRF52
* The internal buffers are all allocated dynamically.
* By default the MAX_BUFFER_SIZE is defined in AutoAnalogAudio_config.h
* Override that value for internal buffers by setting this before calling `begin()`
*/
uint32_t maxBufferSize;
#endif


/**@}*/
private:

/**
* @name Internal interface.
*
Expand Down
11 changes: 4 additions & 7 deletions src/NRF52840/AutoAnalogAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ AutoAnalog::AutoAnalog(){

adcReady = true;
adcBitsPerSample = 8;
pwrPin = PIN_PDM_PWR;
dinPin = PIN_PDM_DIN;
clkPin = PIN_PDM_CLK;
gain = -1;

dacBitsPerSample = 8;
autoAdjust = true;
Expand All @@ -96,7 +100,6 @@ AutoAnalog::AutoAnalog(){

aSize = MAX_BUFFER_SIZE;
aCtr = 0;
micOn = 0;
sampleCounter = 0;
maxBufferSize = 0;
I2S_PIN_MCK = 2;
Expand Down Expand Up @@ -471,10 +474,6 @@ if(useI2S == 2 || useI2S == 3){


set_callback(adcCallback);
dinPin = PIN_PDM_DIN;
clkPin = PIN_PDM_CLK;
pwrPin = PIN_PDM_PWR;
gain = -1;

// Enable high frequency oscillator if not already enabled
if (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
Expand Down Expand Up @@ -513,7 +512,6 @@ if(useI2S == 2 || useI2S == 3){
if (pwrPin > -1) {
pinMode(pwrPin, OUTPUT);
digitalWrite(pwrPin, HIGH);
micOn=1;
}else{
}

Expand Down Expand Up @@ -558,7 +556,6 @@ if(useI2S == 2 || useI2S == 3){
if (pwrPin > -1) {
pinMode(pwrPin, OUTPUT);
digitalWrite(pwrPin, HIGH);
micOn=1;
}else{
}

Expand Down

0 comments on commit f08291b

Please sign in to comment.