Skip to content

Commit e3ed491

Browse files
author
Nathan Seidle
committed
Moving PDM to separate library
1 parent 65a9916 commit e3ed491

File tree

5 files changed

+167
-5
lines changed

5 files changed

+167
-5
lines changed

cores/arduino/ard_sup/Arduino.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ extern "C"
7878
#include "ap3_analog.h"
7979
#include "ap3_clock_sources.h"
8080
#include "ap3_shift.h"
81-
#include "ap3_pdm.h"
8281
#include "WMath.h"
8382
#include "WCharacter.h"
8483

libraries/PDM/keywords.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#######################################
2+
# Syntax Coloring Map
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
EEPROM KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
read KEYWORD2
15+
write KEYWORD2
16+
get KEYWORD2
17+
put KEYWORD2
18+
update KEYWORD2
19+
erase KEYWORD2
20+
21+
#######################################
22+
# Constants (LITERAL1)
23+
#######################################

libraries/PDM/library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=EEPROM
2+
version=1.0
3+
author=SparkFun Electronics
4+
maintainer=SparkFun Electronics <sparkfun.com>
5+
sentence=Flash based Pseudo EEPROM for Artemis
6+
paragraph=Enables the writing of variables to a protected section of flash. These bytes will not be overwritten when new sketches are loaded and are useful when needing to record settings like calibration data or GPS waypoints that should not change between sketch updates.
7+
category=Communication
8+
url=http://www.arduino.cc/en/Reference/EEPROM
9+
architectures=apollo3

cores/arduino/ard_sup/pdm/ap3_pdm.cpp renamed to libraries/PDM/src/PDM.cpp

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1919
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
SOFTWARE.
2121
*/
22-
#include "ap3_pdm.h"
22+
#include "PDM.h"
2323

2424
AP3_PDM *ap3_pdm_handle = 0;
2525

@@ -116,6 +116,96 @@ ap3_err_t AP3_PDM::_begin(void)
116116
return retval;
117117
}
118118

119+
bool AP3_PDM::setClockSpeed(am_hal_pdm_clkspd_e clockSpeed)
120+
{
121+
_PDMconfig.ePDMClkSpeed = clockSpeed;
122+
123+
return (updateConfig(_PDMconfig));
124+
}
125+
126+
am_hal_pdm_clkspd_e AP3_PDM::getClockSpeed()
127+
{
128+
return (_PDMconfig.ePDMClkSpeed);
129+
}
130+
131+
bool AP3_PDM::setClockDivider(am_hal_pdm_mclkdiv_e clockDivider)
132+
{
133+
_PDMconfig.eClkDivider = clockDivider;
134+
135+
return (updateConfig(_PDMconfig));
136+
}
137+
138+
am_hal_pdm_mclkdiv_e AP3_PDM::getClockDivider()
139+
{
140+
return (_PDMconfig.eClkDivider);
141+
}
142+
143+
bool AP3_PDM::setLeftGain(am_hal_pdm_gain_e gain)
144+
{
145+
_PDMconfig.eLeftGain = gain;
146+
147+
return (updateConfig(_PDMconfig));
148+
}
149+
150+
bool AP3_PDM::setRightGain(am_hal_pdm_gain_e gain)
151+
{
152+
_PDMconfig.eRightGain = gain;
153+
154+
return (updateConfig(_PDMconfig));
155+
}
156+
157+
bool AP3_PDM::setGain(am_hal_pdm_gain_e gain)
158+
{
159+
_PDMconfig.eLeftGain = gain;
160+
_PDMconfig.eRightGain = gain;
161+
162+
return (updateConfig(_PDMconfig));
163+
}
164+
165+
am_hal_pdm_gain_e AP3_PDM::getLeftGain()
166+
{
167+
return (_PDMconfig.eLeftGain);
168+
}
169+
am_hal_pdm_gain_e AP3_PDM::getRightGain()
170+
{
171+
return (_PDMconfig.eRightGain);
172+
}
173+
174+
bool AP3_PDM::setChannel(am_hal_pdm_chset_e channel)
175+
{
176+
_PDMconfig.ePCMChannels = channel;
177+
178+
return (updateConfig(_PDMconfig));
179+
}
180+
181+
am_hal_pdm_chset_e AP3_PDM::getChannel()
182+
{
183+
return (_PDMconfig.ePCMChannels);
184+
}
185+
186+
bool AP3_PDM::setDecimationRate(uint32_t deciRate)
187+
{
188+
_PDMconfig.ui32DecimationRate = deciRate;
189+
190+
return (updateConfig(_PDMconfig));
191+
}
192+
193+
uint32_t AP3_PDM::getDecimationRate()
194+
{
195+
return (_PDMconfig.ui32DecimationRate);
196+
}
197+
198+
//Send a given configuration struct to PDM
199+
bool AP3_PDM::updateConfig(am_hal_pdm_config_t newConfiguration)
200+
{
201+
ap3_err_t retval = (ap3_err_t)am_hal_pdm_configure(_PDMhandle, &newConfiguration);
202+
if (retval != AP3_OK)
203+
{
204+
return false;
205+
}
206+
return true;
207+
}
208+
119209
ap3_err_t ap3_pdm_pad_funcsel(ap3_pdm_pad_type_e type, ap3_gpio_pad_t pad, uint8_t *funcsel)
120210
{
121211
ap3_err_t retval = AP3_ERR;
@@ -159,6 +249,32 @@ ap3_err_t ap3_pdm_pad_funcsel(ap3_pdm_pad_type_e type, ap3_gpio_pad_t pad, uint8
159249
return retval;
160250
}
161251

252+
//*****************************************************************************
253+
//
254+
// Start a transaction to get some number of bytes from the PDM interface.
255+
//
256+
//*****************************************************************************
257+
void
258+
AP3_PDM::getData(uint32_t *PDMDataBuffer, uint32_t bufferSize)
259+
{
260+
//
261+
// Configure DMA and target address.
262+
//
263+
am_hal_pdm_transfer_t sTransfer;
264+
sTransfer.ui32TargetAddr = (uint32_t)PDMDataBuffer;
265+
sTransfer.ui32TotalCount = bufferSize * 2; //PDM_FFT_BYTES;
266+
267+
//
268+
// Start the data transfer.
269+
//
270+
am_hal_pdm_enable(_PDMhandle);
271+
am_util_delay_ms(100);
272+
am_hal_pdm_fifo_flush(_PDMhandle);
273+
am_hal_pdm_dma_start(_PDMhandle, &sTransfer);
274+
275+
myPDM._PDMdataReady = false;
276+
}
277+
162278
inline void AP3_PDM::pdm_isr(void)
163279
{
164280
uint32_t ui32Status;

cores/arduino/ard_sup/ap3_pdm.h renamed to libraries/PDM/src/PDM.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1919
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
SOFTWARE.
2121
*/
22-
#ifndef _AP3_PDM_H_
23-
#define _AP3_PDM_H_
22+
#ifndef _PDM_H_
23+
#define _PDM_H_
2424

2525
#include "Arduino.h"
2626

@@ -89,6 +89,21 @@ class AP3_PDM
8989
bool begin(ap3_gpio_pin_t pinPDMData, ap3_gpio_pin_t pinPDMClock);
9090
bool available(void); //Goes true once an interrupt has occured
9191

92+
bool setClockSpeed(am_hal_pdm_clkspd_e clockSpeed);
93+
am_hal_pdm_clkspd_e getClockSpeed();
94+
bool setClockDivider(am_hal_pdm_mclkdiv_e clockSpeed);
95+
am_hal_pdm_mclkdiv_e getClockDivider();
96+
bool setLeftGain(am_hal_pdm_gain_e gain);
97+
am_hal_pdm_gain_e getLeftGain();
98+
bool setRightGain(am_hal_pdm_gain_e gain);
99+
am_hal_pdm_gain_e getRightGain();
100+
bool setGain(am_hal_pdm_gain_e gain);
101+
bool setChannel(am_hal_pdm_chset_e channel);
102+
am_hal_pdm_chset_e getChannel();
103+
bool setDecimationRate(uint32_t deciRate);
104+
uint32_t getDecimationRate();
105+
106+
bool updateConfig(am_hal_pdm_config_t newConfiguration);
92107
//void begin(void);
93108
// void begin(unsigned long baudrate, uint16_t config);
94109
// void begin(unsigned long baudrate, am_hal_uart_config_t config);
@@ -124,4 +139,4 @@ class AP3_PDM
124139
volatile bool _PDMdataReady = false;
125140
};
126141

127-
#endif //_AP3_PDM_H_
142+
#endif //_PDM_H_

0 commit comments

Comments
 (0)