Core2 for AWS IoT EduKit BSP 1.5.1
Macros | Functions
speaker.c File Reference
#include "freertos/FreeRTOS.h"
#include "speaker.h"
#include "driver/i2s.h"
#include "esp_idf_version.h"

Macros

#define I2S_BCK_PIN   12
 
#define I2S_LRCK_PIN   0
 
#define I2S_DATA_PIN   2
 
#define I2S_DATA_IN_PIN   34
 
#define SPEAKER_I2S_NUMBER   I2S_NUM_0
 

Functions

esp_err_t Speaker_Init ()
 Initializes the speaker over I2S. The I2S bus is initialized for output with a sample rate of 44100Hz, with a 16-bit depth, and right channel audio. Other configurations requires using the ESP-IDF I2S driver directly. More...
 
esp_err_t Speaker_WriteBuff (uint8_t *buff, uint32_t len, uint32_t timeout)
 Plays buffer through the speaker. More...
 
esp_err_t Speaker_Deinit ()
 De-initializes the speaker. More...
 

Macro Definition Documentation

◆ I2S_BCK_PIN

#define I2S_BCK_PIN   12

◆ I2S_LRCK_PIN

#define I2S_LRCK_PIN   0

◆ I2S_DATA_PIN

#define I2S_DATA_PIN   2

◆ I2S_DATA_IN_PIN

#define I2S_DATA_IN_PIN   34

◆ SPEAKER_I2S_NUMBER

#define SPEAKER_I2S_NUMBER   I2S_NUM_0

Function Documentation

◆ Speaker_Init()

esp_err_t Speaker_Init ( )

Initializes the speaker over I2S. The I2S bus is initialized for output with a sample rate of 44100Hz, with a 16-bit depth, and right channel audio. Other configurations requires using the ESP-IDF I2S driver directly.

Note
You must enable the speaker after initializing it with Core2ForAWS_Speaker_Enable(). The speaker cannot be initialized at the same time as the microphone since they both share a common pin (GPIO0). Attempting to enable or use both at the same time will cause the device to hard fault.
Returns
esp_err_t. 0 or ESP_OK if successful.

◆ Speaker_WriteBuff()

esp_err_t Speaker_WriteBuff ( uint8_t *  buff,
uint32_t  len,
uint32_t  timeout 
)

Plays buffer through the speaker.

Note
The speaker cannot be used at the same time as the microphone since they both share a common pin (GPIO0). Attempting to enable or use both at the same time will cause the device to hard fault.

Example:

Play a sound buffer. The audio clip is too short to be recognized and is just to serve as an example.

Microphone_Deinit(); // If the microphone was initialized, be sure to deinit it first.
const uint8_t sound[16] = [0x01,0x00,0xff,0xff,0x01,0x00,0xff,0xff,0x01,0x00,0xff,0xff,0xff,0xff,0xff,0xff];
Speaker_WriteBuff(&sound, 16, portMAX_DELAY);
void Core2ForAWS_Speaker_Enable(bool state)
Enables or disables the NS4168 speaker amplifier.
Definition: core2forAWS.c:153
void Microphone_Deinit()
De-initializes the microphone over I2S.
Definition: microphone.c:37
esp_err_t Speaker_WriteBuff(uint8_t *buff, uint32_t len, uint32_t timeout)
Plays buffer through the speaker.
Definition: speaker.c:48
esp_err_t Speaker_Deinit()
De-initializes the speaker.
Definition: speaker.c:53
esp_err_t Speaker_Init()
Initializes the speaker over I2S. The I2S bus is initialized for output with a sample rate of 44100Hz...
Definition: speaker.c:12
Parameters
[out]buffThe sound buffer to play.
[in]lenLength of the buffer.
[in]timeoutUNUSED.
Returns
esp_err_t. 0 or ESP_OK if successful.

◆ Speaker_Deinit()

esp_err_t Speaker_Deinit ( )

De-initializes the speaker.

Returns
esp_err_t. 0 or ESP_OK if successful.