-
Notifications
You must be signed in to change notification settings - Fork 1
/
speaker.c
27 lines (24 loc) · 853 Bytes
/
speaker.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// speaker (audio out) functions
// utilizing library from http://www.mind-dump.net/configuring-the-stm32f4-discovery-for-audio by A.Finkelmeyer
#include "speaker.h"
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "codec.h"
// initialize the speaker (audio output)
void init_speaker() {
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
codec_init();
codec_ctrl_init();
I2S_Cmd(CODEC_I2S, ENABLE);
}
// send one audio sample to the speaker
void send_to_speaker(int16_t audio_sample) {
// same sample for both left and right speakers in stereo speakers
if (SPI_I2S_GetFlagStatus(CODEC_I2S, SPI_I2S_FLAG_TXE)) {
SPI_I2S_SendData(CODEC_I2S, audio_sample);
}
if (SPI_I2S_GetFlagStatus(CODEC_I2S, SPI_I2S_FLAG_TXE)) {
SPI_I2S_SendData(CODEC_I2S, audio_sample);
}
}