Core2 for AWS IoT EduKit BSP 1.5.1
Functions
speaker.h File Reference

Functions for the on-board 1W-0928 speaker using the NS4168 power amplifier. More...

#include "stdint.h"

Go to the source code of this file.

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...
 

Detailed Description

Functions for the on-board 1W-0928 speaker using the NS4168 power amplifier.

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.