audio codec example refactured
This commit is contained in:
parent
b9d6eb9779
commit
59a58e7522
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// The CS43L22 is a Low Power, Stereo DAC w/Headphone & Speaker Amps
|
// The CS43L22 is a Low Power, Stereo DAC w/Headphone & Speaker Amps
|
||||||
//
|
//
|
||||||
// related links:
|
// related links:
|
||||||
|
@ -39,12 +38,9 @@ void codec_writeReg(unsigned char reg, unsigned char data)
|
||||||
error = Wire.endTransmission();
|
error = Wire.endTransmission();
|
||||||
}
|
}
|
||||||
|
|
||||||
// each register retries until success
|
|
||||||
// if communication fails the device will hang
|
|
||||||
// codec setup from
|
// codec setup from
|
||||||
// https://github.com/mubase/STM32F4-Arduino-core/blob/master/cores/maple/libmaple/stm32f4codec/codec.h
|
// https://github.com/mubase/STM32F4-Arduino-core/blob/master/cores/maple/libmaple/stm32f4codec/codec.h
|
||||||
// TBD: to be refactured
|
// TBD: to be refactured
|
||||||
|
|
||||||
void codec_reg_setup(void)
|
void codec_reg_setup(void)
|
||||||
{
|
{
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
@ -89,14 +85,12 @@ void setup()
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
static uint16_t n;
|
static uint16_t n;
|
||||||
|
|
||||||
I2S.write(n += 300); // produce sound: simple triangle waveform
|
I2S.write(n += 300); // produce sound: simple triangle waveform
|
||||||
|
|
||||||
if ( digitalRead( USER_BTN ) )
|
if ( digitalRead( USER_BTN ) ) // sound on/off when button pressed
|
||||||
{
|
{
|
||||||
while (1) // stop sound when user button pressed
|
while(1);
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -105,4 +99,3 @@ void loop()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue