Create v1.7.5(第2次提交)

This commit is contained in:
Rdzleo 2026-01-20 16:34:28 +08:00
parent d5460d2bb9
commit fded8fba4e
2500 changed files with 422401 additions and 0 deletions

BIN
audios_new_p3.zip Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
bd44ca7d7243089a6741765e7fadc5f923340d14b1259a3514ee77b7b21e7aab

View File

@ -0,0 +1 @@
dist/

View File

@ -0,0 +1 @@
{"version": "1.0", "algorithm": "sha256", "created_at": "2025-05-27T23:31:19.840174+00:00", "files": [{"path": ".gitignore", "size": 5, "hash": "887f42eeae4276a8ba8ed3e14ec6567107ed2760d18ea7303cc715a38670fbea"}, {"path": "CMakeLists.txt", "size": 183, "hash": "64803247577ebe4b56fb98a7fcf26ab8de7b6c1853e8b684a525df6070e5e5fc"}, {"path": "idf_component.yml", "size": 245, "hash": "87ebb2ce071db64b5a77f96f45ef16e4f06099ecfc0e99df6ad3e4cf91830829"}, {"path": "opus_decoder.cc", "size": 1390, "hash": "a99f4db4b8fd1326b9ede3910397c82d3a9bcaffe408af8c851e5f2e161bb334"}, {"path": "opus_encoder.cc", "size": 2549, "hash": "1005695c88eb4a72f99227036467d532ec7a40000f43671fcbf1adb3c2c3400d"}, {"path": "opus_resampler.cc", "size": 1139, "hash": "9303c8e3fc5bd28ed63302114eaca33b51a3634f43c278b1856223846302b77c"}, {"path": "silk_resampler.h", "size": 1361, "hash": "afac70e0c296c93cf1b24710255f96b99d44df3d8de82ef72a5a4ead59c1ecbe"}, {"path": "include/opus_decoder.h", "size": 729, "hash": "7ea7d09e2aef14b6affd38470ddb1909fd16f6d4f0ee492c29b211374ff3f982"}, {"path": "include/opus_encoder.h", "size": 973, "hash": "63c9722c4964e1f29b6dab8a15356e5998b4cd32bcb0ec5a5905d0a698f4eefb"}, {"path": "include/opus_resampler.h", "size": 651, "hash": "89b4d2f5e0d7b626b9c40b326072d80941b71a3448ca3f50394f1694c9d64b7d"}, {"path": "include/resampler_structs.h", "size": 2615, "hash": "b038e84c7d79bcd31bbf524dba64103d17ab66c5006cd2b6ad7ba3289226cd18"}]}

View File

@ -0,0 +1,12 @@
idf_component_register(
SRCS
"opus_encoder.cc"
"opus_decoder.cc"
"opus_resampler.cc"
INCLUDE_DIRS
"include"
PRIV_INCLUDE_DIRS
"."
REQUIRES
"78__esp-opus"
)

View File

@ -0,0 +1,13 @@
dependencies:
78/esp-opus:
version: ^1.0.5
public: true
idf: '>=5.3'
description: ESP32 Opus Encoder C++ wrapper
files:
exclude:
- .git
license: MIT
repository: https://github.com/78/esp-opus-encoder
url: https://github.com/78/esp-opus-encoder
version: 2.3.3

View File

@ -0,0 +1,36 @@
#ifndef _OPUS_DECODER_WRAPPER_H_
#define _OPUS_DECODER_WRAPPER_H_
#include <functional>
#include <vector>
#include <cstdint>
#include <mutex>
#include "opus.h"
class OpusDecoderWrapper {
public:
OpusDecoderWrapper(int sample_rate, int channels, int duration_ms = 60);
~OpusDecoderWrapper();
bool Decode(std::vector<uint8_t>&& opus, std::vector<int16_t>& pcm);
void ResetState();
inline int sample_rate() const {
return sample_rate_;
}
inline int duration_ms() const {
return duration_ms_;
}
private:
std::mutex mutex_;
struct OpusDecoder* audio_dec_ = nullptr;
int frame_size_;
int sample_rate_;
int duration_ms_;
};
#endif // _OPUS_DECODER_WRAPPER_H_

View File

@ -0,0 +1,43 @@
#ifndef _OPUS_ENCODER_WRAPPER_H_
#define _OPUS_ENCODER_WRAPPER_H_
#include <functional>
#include <vector>
#include <memory>
#include <cstdint>
#include <mutex>
#include "opus.h"
#define MAX_OPUS_PACKET_SIZE 1000
class OpusEncoderWrapper {
public:
OpusEncoderWrapper(int sample_rate, int channels, int duration_ms = 60);
~OpusEncoderWrapper();
inline int sample_rate() const {
return sample_rate_;
}
inline int duration_ms() const {
return duration_ms_;
}
void SetDtx(bool enable);
void SetComplexity(int complexity);
void Encode(std::vector<int16_t>&& pcm, std::function<void(std::vector<uint8_t>&& opus)> handler);
bool IsBufferEmpty() const { return in_buffer_.empty(); }
void ResetState();
private:
std::mutex mutex_;
struct OpusEncoder* audio_enc_ = nullptr;
int sample_rate_;
int duration_ms_;
int frame_size_;
std::vector<int16_t> in_buffer_;
};
#endif // _OPUS_ENCODER_H_

View File

@ -0,0 +1,28 @@
#ifndef OPUS_RESAMPLER_H
#define OPUS_RESAMPLER_H
#include <cstdint>
#include "opus.h"
#include "resampler_structs.h"
class OpusResampler {
public:
OpusResampler();
~OpusResampler();
void Configure(int input_sample_rate, int output_sample_rate);
void Process(const int16_t *input, int input_samples, int16_t *output);
int GetOutputSamples(int input_samples) const;
int input_sample_rate() const { return input_sample_rate_; }
int output_sample_rate() const { return output_sample_rate_; }
private:
silk_resampler_state_struct resampler_state_;
int input_sample_rate_;
int output_sample_rate_;
};
#endif

View File

@ -0,0 +1,60 @@
/***********************************************************************
Copyright (c) 2006-2011, Skype Limited. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of Internet Society, IETF or IETF Trust, nor the
names of specific contributors, may be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#ifndef SILK_RESAMPLER_STRUCTS_H
#define SILK_RESAMPLER_STRUCTS_H
#ifdef __cplusplus
extern "C" {
#endif
#define SILK_RESAMPLER_MAX_FIR_ORDER 36
#define SILK_RESAMPLER_MAX_IIR_ORDER 6
typedef struct _silk_resampler_state_struct{
opus_int32 sIIR[ SILK_RESAMPLER_MAX_IIR_ORDER ]; /* this must be the first element of this struct */
union{
opus_int32 i32[ SILK_RESAMPLER_MAX_FIR_ORDER ];
opus_int16 i16[ SILK_RESAMPLER_MAX_FIR_ORDER ];
} sFIR;
opus_int16 delayBuf[ 48 ];
opus_int resampler_function;
opus_int batchSize;
opus_int32 invRatio_Q16;
opus_int FIR_Order;
opus_int FIR_Fracs;
opus_int Fs_in_kHz;
opus_int Fs_out_kHz;
opus_int inputDelay;
const opus_int16 *Coefs;
} silk_resampler_state_struct;
#ifdef __cplusplus
}
#endif
#endif /* SILK_RESAMPLER_STRUCTS_H */

View File

@ -0,0 +1,48 @@
#include "opus_decoder.h"
#include <esp_log.h>
#define TAG "OpusDecoderWrapper"
OpusDecoderWrapper::OpusDecoderWrapper(int sample_rate, int channels, int duration_ms)
: sample_rate_(sample_rate), duration_ms_(duration_ms) {
int error;
audio_dec_ = opus_decoder_create(sample_rate, channels, &error);
if (audio_dec_ == nullptr) {
ESP_LOGE(TAG, "Failed to create audio decoder, error code: %d", error);
return;
}
frame_size_ = sample_rate / 1000 * channels * duration_ms;
}
OpusDecoderWrapper::~OpusDecoderWrapper() {
std::lock_guard<std::mutex> lock(mutex_);
if (audio_dec_ != nullptr) {
opus_decoder_destroy(audio_dec_);
}
}
bool OpusDecoderWrapper::Decode(std::vector<uint8_t>&& opus, std::vector<int16_t>& pcm) {
std::lock_guard<std::mutex> lock(mutex_);
if (audio_dec_ == nullptr) {
ESP_LOGE(TAG, "Audio decoder is not configured");
return false;
}
pcm.resize(frame_size_);
auto ret = opus_decode(audio_dec_, opus.data(), opus.size(), pcm.data(), pcm.size(), 0);
if (ret < 0) {
ESP_LOGE(TAG, "Failed to decode audio, error code: %d", ret);
return false;
}
return true;
}
void OpusDecoderWrapper::ResetState() {
std::lock_guard<std::mutex> lock(mutex_);
if (audio_dec_ != nullptr) {
opus_decoder_ctl(audio_dec_, OPUS_RESET_STATE);
}
}

View File

@ -0,0 +1,81 @@
#include "opus_encoder.h"
#include <esp_log.h>
#define TAG "OpusEncoderWrapper"
OpusEncoderWrapper::OpusEncoderWrapper(int sample_rate, int channels, int duration_ms)
: sample_rate_(sample_rate), duration_ms_(duration_ms) {
int error;
audio_enc_ = opus_encoder_create(sample_rate, channels, OPUS_APPLICATION_VOIP, &error);
if (audio_enc_ == nullptr) {
ESP_LOGE(TAG, "Failed to create audio encoder, error code: %d", error);
return;
}
// Default DTX enabled
SetDtx(true);
// Complexity 5 almost uses up all CPU of ESP32C3
SetComplexity(5);
frame_size_ = sample_rate / 1000 * channels * duration_ms;
}
OpusEncoderWrapper::~OpusEncoderWrapper() {
std::lock_guard<std::mutex> lock(mutex_);
if (audio_enc_ != nullptr) {
opus_encoder_destroy(audio_enc_);
}
}
void OpusEncoderWrapper::Encode(std::vector<int16_t>&& pcm, std::function<void(std::vector<uint8_t>&& opus)> handler) {
std::lock_guard<std::mutex> lock(mutex_);
if (audio_enc_ == nullptr) {
ESP_LOGE(TAG, "Audio encoder is not configured");
return;
}
if (in_buffer_.empty()) {
in_buffer_ = std::move(pcm);
} else {
/* ISSUE: https://github.com/78/esp-opus-encoder/issues/1 */
in_buffer_.reserve(in_buffer_.size() + pcm.size());
in_buffer_.insert(in_buffer_.end(), pcm.begin(), pcm.end());
}
while (in_buffer_.size() >= frame_size_) {
uint8_t opus[MAX_OPUS_PACKET_SIZE];
auto ret = opus_encode(audio_enc_, in_buffer_.data(), frame_size_, opus, MAX_OPUS_PACKET_SIZE);
if (ret < 0) {
ESP_LOGE(TAG, "Failed to encode audio, error code: %ld", ret);
return;
}
if (handler != nullptr) {
handler(std::vector<uint8_t>(opus, opus + ret));
}
in_buffer_.erase(in_buffer_.begin(), in_buffer_.begin() + frame_size_);
}
}
void OpusEncoderWrapper::ResetState() {
std::lock_guard<std::mutex> lock(mutex_);
if (audio_enc_ != nullptr) {
opus_encoder_ctl(audio_enc_, OPUS_RESET_STATE);
in_buffer_.clear();
}
}
void OpusEncoderWrapper::SetDtx(bool enable) {
std::lock_guard<std::mutex> lock(mutex_);
if (audio_enc_ != nullptr) {
opus_encoder_ctl(audio_enc_, OPUS_SET_DTX(enable ? 1 : 0));
}
}
void OpusEncoderWrapper::SetComplexity(int complexity) {
std::lock_guard<std::mutex> lock(mutex_);
if (audio_enc_ != nullptr) {
opus_encoder_ctl(audio_enc_, OPUS_SET_COMPLEXITY(complexity));
}
}

View File

@ -0,0 +1,34 @@
#include "opus_resampler.h"
#include "silk_resampler.h"
#include "esp_log.h"
#define TAG "OpusResampler"
OpusResampler::OpusResampler() {
}
OpusResampler::~OpusResampler() {
}
void OpusResampler::Configure(int input_sample_rate, int output_sample_rate) {
int encode = input_sample_rate > output_sample_rate ? 1 : 0;
auto ret = silk_resampler_init(&resampler_state_, input_sample_rate, output_sample_rate, encode);
if (ret != 0) {
ESP_LOGE(TAG, "Failed to initialize resampler");
return;
}
input_sample_rate_ = input_sample_rate;
output_sample_rate_ = output_sample_rate;
ESP_LOGI(TAG, "Resampler configured with input sample rate %d and output sample rate %d", input_sample_rate_, output_sample_rate_);
}
void OpusResampler::Process(const int16_t *input, int input_samples, int16_t *output) {
auto ret = silk_resampler(&resampler_state_, output, input, input_samples);
if (ret != 0) {
ESP_LOGE(TAG, "Failed to process resampler");
}
}
int OpusResampler::GetOutputSamples(int input_samples) const {
return input_samples * output_sample_rate_ / input_sample_rate_;
}

View File

@ -0,0 +1,26 @@
#ifndef _SILK_RESAMPLER_H_
#define _SILK_RESAMPLER_H_
#include "opus.h"
#include "resampler_structs.h"
/*!
* Initialize/reset the resampler state for a given pair of input/output sampling rates
*/
extern "C" opus_int silk_resampler_init(
silk_resampler_state_struct *S, /* I/O Resampler state */
opus_int32 Fs_Hz_in, /* I Input sampling rate (Hz) */
opus_int32 Fs_Hz_out, /* I Output sampling rate (Hz) */
opus_int forEnc /* I If 1: encoder; if 0: decoder */
);
/*!
* Resampler: convert from one sampling rate to another
*/
extern "C" opus_int silk_resampler(
silk_resampler_state_struct *S, /* I/O Resampler state */
opus_int16 out[], /* O Output signal */
const opus_int16 in[], /* I Input signal */
opus_int32 inLen /* I Number of input samples */
);
#endif // _SILK_RESAMPLER_H_

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
docs/ESP32-BreadBoard.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

BIN
docs/atoms3r-echo-base.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
docs/esp-sparkbot.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
docs/esp32s3-box3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
docs/lichuang-s3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
docs/lilygo-t-circle-s3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
docs/m5stack-cores3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
docs/magiclick-2p4.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
docs/v1/atoms3r.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
docs/v1/espbox3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
docs/v1/lichuang-s3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

BIN
docs/v1/m5cores3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
docs/v1/magiclick.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
docs/v1/waveshare.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

338
docs/websocket.md Normal file
View File

@ -0,0 +1,338 @@
以下是一份基于代码实现整理的 WebSocket 通信协议文档,概述客户端(设备)与服务器之间如何通过 WebSocket 进行交互。该文档仅基于所提供的代码推断,实际部署时可能需要结合服务器端实现进行进一步确认或补充。
---
## 1. 总体流程概览
1. **设备端初始化**
- 设备上电、初始化 `Application`
- 初始化音频编解码器、显示屏、LED 等
- 连接网络
- 创建并初始化实现 `Protocol` 接口的 WebSocket 协议实例(`WebsocketProtocol`
- 进入主循环等待事件(音频输入、音频输出、调度任务等)。
2. **建立 WebSocket 连接**
- 当设备需要开始语音会话时(例如用户唤醒、手动按键触发等),调用 `OpenAudioChannel()`
- 根据编译配置获取 WebSocket URL`CONFIG_WEBSOCKET_URL`
- 设置若干请求头(`Authorization`, `Protocol-Version`, `Device-Id`, `Client-Id`
- 调用 `Connect()` 与服务器建立 WebSocket 连接
3. **发送客户端 “hello” 消息**
- 连接成功后,设备会发送一条 JSON 消息,示例结构如下:
```json
{
"type": "hello",
"version": 1,
"transport": "websocket",
"audio_params": {
"format": "opus",
"sample_rate": 16000,
"channels": 1,
"frame_duration": 60
}
}
```
- 其中 `"frame_duration"` 的值对应 `OPUS_FRAME_DURATION_MS`(例如 60ms
4. **服务器回复 “hello”**
- 设备等待服务器返回一条包含 `"type": "hello"` 的 JSON 消息,并检查 `"transport": "websocket"` 是否匹配。
- 如果匹配,则认为服务器已就绪,标记音频通道打开成功。
- 如果在超时时间(默认 10 秒)内未收到正确回复,认为连接失败并触发网络错误回调。
5. **后续消息交互**
- 设备端和服务器端之间可发送两种主要类型的数据:
1. **二进制音频数据**Opus 编码)
2. **文本 JSON 消息**用于传输聊天状态、TTS/STT 事件、IoT 命令等)
- 在代码里,接收回调主要分为:
- `OnData(...)`:
- 当 `binary``true` 时,认为是音频帧;设备会将其当作 Opus 数据进行解码。
- 当 `binary``false` 时,认为是 JSON 文本,需要在设备端用 cJSON 进行解析并做相应业务逻辑处理(见下文消息结构)。
- 当服务器或网络出现断连,回调 `OnDisconnected()` 被触发:
- 设备会调用 `on_audio_channel_closed_()`,并最终回到空闲状态。
6. **关闭 WebSocket 连接**
- 设备在需要结束语音会话时,会调用 `CloseAudioChannel()` 主动断开连接,并回到空闲状态。
- 或者如果服务器端主动断开,也会引发同样的回调流程。
---
## 2. 通用请求头
在建立 WebSocket 连接时,代码示例中设置了以下请求头:
- `Authorization`: 用于存放访问令牌,形如 `"Bearer <token>"`
- `Protocol-Version`: 固定示例中为 `"1"`
- `Device-Id`: 设备物理网卡 MAC 地址
- `Client-Id`: 设备 UUID可在应用中唯一标识设备
这些头会随着 WebSocket 握手一起发送到服务器,服务器可根据需求进行校验、认证等。
---
## 3. JSON 消息结构
WebSocket 文本帧以 JSON 方式传输,以下为常见的 `"type"` 字段及其对应业务逻辑。若消息里包含未列出的字段,可能为可选或特定实现细节。
### 3.1 客户端→服务器
1. **Hello**
- 连接成功后,由客户端发送,告知服务器基本参数。
- 例:
```json
{
"type": "hello",
"version": 1,
"transport": "websocket",
"audio_params": {
"format": "opus",
"sample_rate": 16000,
"channels": 1,
"frame_duration": 60
}
}
```
2. **Listen**
- 表示客户端开始或停止录音监听。
- 常见字段:
- `"session_id"`:会话标识
- `"type": "listen"`
- `"state"``"start"`, `"stop"`, `"detect"`(唤醒检测已触发)
- `"mode"``"auto"`, `"manual"``"realtime"`,表示识别模式。
- 例:开始监听
```json
{
"session_id": "xxx",
"type": "listen",
"state": "start",
"mode": "manual"
}
```
3. **Abort**
- 终止当前说话TTS 播放)或语音通道。
- 例:
```json
{
"session_id": "xxx",
"type": "abort",
"reason": "wake_word_detected"
}
```
- `reason` 值可为 `"wake_word_detected"` 或其他。
4. **Wake Word Detected**
- 用于客户端向服务器告知检测到唤醒词。
- 例:
```json
{
"session_id": "xxx",
"type": "listen",
"state": "detect",
"text": "你好小明"
}
```
5. **IoT**
- 发送当前设备的物联网相关信息:
- **Descriptors**(描述设备功能、属性等)
- **States**(设备状态的实时更新)
- 例:
```json
{
"session_id": "xxx",
"type": "iot",
"descriptors": { ... }
}
```
```json
{
"session_id": "xxx",
"type": "iot",
"states": { ... }
}
```
---
### 3.2 服务器→客户端
1. **Hello**
- 服务器端返回的握手确认消息。
- 必须包含 `"type": "hello"``"transport": "websocket"`
- 可能会带有 `audio_params`,表示服务器期望的音频参数,或与客户端对齐的配置。
- 成功接收后客户端会设置事件标志,表示 WebSocket 通道就绪。
2. **STT**
- `{"type": "stt", "text": "..."}`
- 表示服务器端识别到了用户语音。(例如语音转文本结果)
- 设备可能将此文本显示到屏幕上,后续再进入回答等流程。
3. **LLM**
- `{"type": "llm", "emotion": "happy", "text": "😀"}`
- 服务器指示设备调整表情动画 / UI 表达。
4. **TTS**
- `{"type": "tts", "state": "start"}`:服务器准备下发 TTS 音频,客户端进入 “speaking” 播放状态。
- `{"type": "tts", "state": "stop"}`:表示本次 TTS 结束。
- `{"type": "tts", "state": "sentence_start", "text": "..."}`
- 让设备在界面上显示当前要播放或朗读的文本片段(例如用于显示给用户)。
5. **IoT**
- `{"type": "iot", "commands": [ ... ]}`
- 服务器向设备发送物联网的动作指令,设备解析并执行(如打开灯、设置温度等)。
6. **音频数据:二进制帧**
- 当服务器发送音频二进制帧Opus 编码)时,客户端解码并播放。
- 若客户端正在处于 “listening” (录音)状态,收到的音频帧会被忽略或清空以防冲突。
---
## 4. 音频编解码
1. **客户端发送录音数据**
- 音频输入经过可能的回声消除、降噪或音量增益后,通过 Opus 编码打包为二进制帧发送给服务器。
- 如果客户端每次编码生成的二进制帧大小为 N 字节,则会通过 WebSocket 的 **binary** 消息发送这块数据。
2. **客户端播放收到的音频**
- 收到服务器的二进制帧时,同样认定是 Opus 数据。
- 设备端会进行解码,然后交由音频输出接口播放。
- 如果服务器的音频采样率与设备不一致,会在解码后再进行重采样。
---
## 5. 常见状态流转
以下简述设备端关键状态流转,与 WebSocket 消息对应:
1. **Idle****Connecting**
- 用户触发或唤醒后,设备调用 `OpenAudioChannel()` → 建立 WebSocket 连接 → 发送 `"type":"hello"`
2. **Connecting****Listening**
- 成功建立连接后,若继续执行 `SendStartListening(...)`,则进入录音状态。此时设备会持续编码麦克风数据并发送到服务器。
3. **Listening****Speaking**
- 收到服务器 TTS Start 消息 (`{"type":"tts","state":"start"}`) → 停止录音并播放接收到的音频。
4. **Speaking****Idle**
- 服务器 TTS Stop (`{"type":"tts","state":"stop"}`) → 音频播放结束。若未继续进入自动监听,则返回 Idle如果配置了自动循环则再度进入 Listening。
5. **Listening** / **Speaking****Idle**(遇到异常或主动中断)
- 调用 `SendAbortSpeaking(...)``CloseAudioChannel()` → 中断会话 → 关闭 WebSocket → 状态回到 Idle。
---
## 6. 错误处理
1. **连接失败**
- 如果 `Connect(url)` 返回失败或在等待服务器 “hello” 消息时超时,触发 `on_network_error_()` 回调。设备会提示“无法连接到服务”或类似错误信息。
2. **服务器断开**
- 如果 WebSocket 异常断开,回调 `OnDisconnected()`
- 设备回调 `on_audio_channel_closed_()`
- 切换到 Idle 或其他重试逻辑。
---
## 7. 其它注意事项
1. **鉴权**
- 设备通过设置 `Authorization: Bearer <token>` 提供鉴权,服务器端需验证是否有效。
- 如果令牌过期或无效,服务器可拒绝握手或在后续断开。
2. **会话控制**
- 代码中部分消息包含 `session_id`用于区分独立的对话或操作。服务端可根据需要对不同会话做分离处理WebSocket 协议为空。
3. **音频负载**
- 代码里默认使用 Opus 格式,并设置 `sample_rate = 16000`,单声道。帧时长由 `OPUS_FRAME_DURATION_MS` 控制,一般为 60ms。可根据带宽或性能做适当调整。
4. **IoT 指令**
- `"type":"iot"` 的消息用户端代码对接 `thing_manager` 执行具体命令,因设备定制而不同。服务器端需确保下发格式与客户端保持一致。
5. **错误或异常 JSON**
- 当 JSON 中缺少必要字段,例如 `{"type": ...}`,客户端会记录错误日志(`ESP_LOGE(TAG, "Missing message type, data: %s", data);`),不会执行任何业务。
---
## 8. 消息示例
下面给出一个典型的双向消息示例(流程简化示意):
1. **客户端 → 服务器**(握手)
```json
{
"type": "hello",
"version": 1,
"transport": "websocket",
"audio_params": {
"format": "opus",
"sample_rate": 16000,
"channels": 1,
"frame_duration": 60
}
}
```
2. **服务器 → 客户端**(握手应答)
```json
{
"type": "hello",
"transport": "websocket",
"audio_params": {
"sample_rate": 16000
}
}
```
3. **客户端 → 服务器**(开始监听)
```json
{
"session_id": "",
"type": "listen",
"state": "start",
"mode": "auto"
}
```
同时客户端开始发送二进制帧Opus 数据)。
4. **服务器 → 客户端**ASR 结果)
```json
{
"type": "stt",
"text": "用户说的话"
}
```
5. **服务器 → 客户端**TTS开始
```json
{
"type": "tts",
"state": "start"
}
```
接着服务器发送二进制音频帧给客户端播放。
6. **服务器 → 客户端**TTS结束
```json
{
"type": "tts",
"state": "stop"
}
```
客户端停止播放音频,若无更多指令,则回到空闲状态。
---
## 9. 总结
本协议通过在 WebSocket 上层传输 JSON 文本与二进制音频帧完成功能包括音频流上传、TTS 音频播放、语音识别与状态管理、IoT 指令下发等。其核心特征:
- **握手阶段**:发送 `"type":"hello"`,等待服务器返回。
- **音频通道**:采用 Opus 编码的二进制帧双向传输语音流。
- **JSON 消息**:使用 `"type"` 为核心字段标识不同业务逻辑,包括 TTS、STT、IoT、WakeWord 等。
- **扩展性**:可根据实际需求在 JSON 消息中添加字段,或在 headers 里进行额外鉴权。
服务器与客户端需提前约定各类消息的字段含义、时序逻辑以及错误处理规则,方能保证通信顺畅。上述信息可作为基础文档,便于后续对接、开发或扩展。

BIN
docs/wiring.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

BIN
docs/wiring2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

BIN
docs/xmini-c3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

16
esp-spot/.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
# Example project files
build_esp*_*/
sdkconfig.old
sdkconfig
.DS_Store
# ESP-IDF default build directory name
build
# lock files for examples and components
dependencies.lock
# managed_components for examples
managed_components
.vscode

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Binary file not shown.

201
esp-spot/LICENSE Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

42
esp-spot/README.md Normal file
View File

@ -0,0 +1,42 @@
# ESP-SpotAI 语音交互核心模块
<div align="center">
<img src="_static/spot-cover.jpg" width="70%">
</div>
## 项目简介
ESP-Spot 是一款基于 ESP32-S3 / ESP32-C5 的 **AI 动作语音交互核心模块**,专注于**语音交互、AI感知与智能控制**适用于智能玩具、语音助手、家居控制等物联网应用场景。它不仅可以通过离线语音实现唤醒、AI对话默认使用 xiaozhi 平台等功能而且通过ESP32-S3 自带的**触摸/接近感应**外设实现玩偶触摸感知,同时设备内置加速度传感器, 可以识别玩偶姿态与动作,从而实现更丰富的交互。
<div align="center">
<img src="_static/spot-board.png" width="50%">
</div>
<div align="center">
<img src="_static/spot-3d-2.jpg" width="50%">
</div>
## 视频展示
[用触摸交互升级大模型 AI 玩具【ESP-SPOT】](https://www.bilibili.com/video/BV1ekRAYVEZ1/)
- 本视频对应的例程为:[llm_touch_toy](./example/adf/llm_touch_toy)
## 软件资源
目前已开放部分代码例程,请参考 [example 文件夹](example),后续会持续升级更新
## 硬件设计
硬件已开源在立创平台:[ESP-Spot](https://oshwhub.com/esp-college/esp-spot)
## 3D 结构设计
- 3D 打印文件已[开放附件](3D_Print),欢迎下载!
- **主体结构**
ESP-Spot 的主体结构炸视图如下:
<div align="center">
<img src="_static/esp-spot-3d.png" width="90%">
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 492 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -0,0 +1,15 @@
# ESP-Spot 示例
此目录包含一系列 ESP-Spot 示例项目。这些示例旨在演示模块的部分功能
# 示例列表
- [s3_factory_bin](./s3_factory_bin): 编译好的小智语音交流固件,可直接烧录到开发板
- [adf](./adf):基于 ESP-ADF 的音频例程
- [components](./adf/components):内置 ESP-Spot 在 ADF 中的硬件初始化组件,替换 ADF 中对应的原组件
- **[llm_touch_toy](./adf/llm_touch_toy):将 AI 大模型与 ESP32-S3 触摸传感器结合,打造可以进行动作交互的 AI 玩具**
- [touch_play_mp3](./adf/touch_play_mp3):通过触摸播放 MP3 音频和点亮灯环的基础例程
- [coze_websocket](./adf/coze_websocket):通过扣子 WebSocket 服务进行大模型语音交互
- [volc_rtc_spot](./adf/volc_rtc_spot):通过火山引擎 RTC 服务进行大模型语音交互
- [imu_led](./imu_led):加速度传感器基础例程
- [simple_touch](./simple_touch)
- [xiaozhi](./xiaozhi):基于小智 AI 的项目

View File

@ -0,0 +1,155 @@
set(COMPONENT_ADD_INCLUDEDIRS ./include)
# Edit following two lines to set component requirements (see docs)
set(COMPONENT_REQUIRES )
set(COMPONENT_PRIV_REQUIRES esp_peripherals audio_sal audio_hal esp_dispatcher display_service)
if (CONFIG_ESP_LYRAT_V4_2_BOARD)
message(STATUS "Current board name is " CONFIG_ESP_LYRAT_V4_2_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyrat_v4_2)
set(COMPONENT_SRCS
./lyrat_v4_2/board.c
./lyrat_v4_2/board_pins_config.c
)
endif()
if (CONFIG_ESP_LYRAT_V4_3_BOARD)
message(STATUS "Current board name is " CONFIG_ESP_LYRAT_V4_3_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyrat_v4_3)
set(COMPONENT_SRCS
./lyrat_v4_3/board.c
./lyrat_v4_3/board_pins_config.c
)
endif()
if (CONFIG_ESP_LYRAT_MINI_V1_1_BOARD)
message(STATUS "Current board name is " CONFIG_ESP_LYRAT_MINI_V1_1_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyrat_mini_v1_1)
set(COMPONENT_SRCS
./lyrat_mini_v1_1/board.c
./lyrat_mini_v1_1/board_pins_config.c
)
endif()
if (CONFIG_ESP_LYRATD_MSC_V2_1_BOARD)
message(STATUS "Current board name is " CONFIG_ESP_LYRATD_MSC_V2_1_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyratd_msc_v2_1)
set(COMPONENT_SRCS
./lyratd_msc_v2_1/board.c
./lyratd_msc_v2_1/board_pins_config.c
)
endif()
if (CONFIG_ESP_LYRATD_MSC_V2_2_BOARD)
message(STATUS "Current board name is " CONFIG_ESP_LYRATD_MSC_V2_2_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./lyratd_msc_v2_2)
set(COMPONENT_SRCS
./lyratd_msc_v2_2/board.c
./lyratd_msc_v2_2/board_pins_config.c
)
endif()
if (CONFIG_ESP32_KORVO_DU1906_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_KORVO_DU1906_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_korvo_du1906)
set(COMPONENT_SRCS
./esp32_korvo_du1906/board.c
./esp32_korvo_du1906/board_pins_config.c
./esp32_korvo_du1906/du1906_bar_pattern.c
)
endif()
if (CONFIG_ESP32_S2_KALUGA_1_V1_2_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_S2_KALUGA_1_V1_2_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_s2_kaluga_1_v1_2)
set(COMPONENT_SRCS
./esp32_s2_kaluga_1_v1_2/board.c
./esp32_s2_kaluga_1_v1_2/board_pins_config.c
)
endif()
if (CONFIG_ESP32_S3_KORVO2_V3_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_S3_KORVO2_V3_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_s3_korvo2_v3)
set(COMPONENT_SRCS
./esp32_s3_korvo2_v3/board.c
./esp32_s3_korvo2_v3/board_pins_config.c
)
endif()
if (CONFIG_ESP32_S3_KORVO2L_V1_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_S3_KORVO2L_V1_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_s3_korvo2l_v1)
set(COMPONENT_SRCS
./esp32_s3_korvo2l_v1/board.c
./esp32_s3_korvo2l_v1/board_pins_config.c
)
endif()
if (CONFIG_ESP32_S3_SPOT_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_S3_SPOT_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_s3_spot)
set(COMPONENT_SRCS
./esp32_s3_spot/board.c
./esp32_s3_spot/board_pins_config.c
)
endif()
if (CONFIG_ESP32_S3_BOX_LITE_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_S3_BOX_LITE_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_s3_box_lite)
set(COMPONENT_SRCS
./esp32_s3_box_lite/board.c
./esp32_s3_box_lite/board_pins_config.c
)
endif()
if (CONFIG_ESP32_S3_BOX_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_S3_BOX_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_s3_box)
set(COMPONENT_SRCS
./esp32_s3_box/board.c
./esp32_s3_box/board_pins_config.c
)
endif()
if (CONFIG_ESP32_S3_BOX_3_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_S3_BOX_3_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_s3_box_3)
set(COMPONENT_SRCS
./esp32_s3_box_3/board.c
./esp32_s3_box_3/board_pins_config.c
)
endif()
if (CONFIG_ESP32_C3_LYRA_V2_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_C3_LYRA_V2_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_c3_lyra)
set(COMPONENT_SRCS
./esp32_c3_lyra/board.c
./esp32_c3_lyra/board_pins_config.c
./esp32_c3_lyra/C3_lyra_sys_pattern.c
)
endif()
if (CONFIG_ESP32_C6_DEVKIT_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_C6_DEVKIT_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_c6_devkit)
set(COMPONENT_SRCS
./esp32_c6_devkit/board.c
./esp32_c6_devkit/board_pins_config.c
)
endif()
if (CONFIG_ESP32_P4_FUNCTION_EV_BOARD)
message(STATUS "Current board name is " CONFIG_ESP32_P4_FUNCTION_EV_BOARD)
list(APPEND COMPONENT_ADD_INCLUDEDIRS ./esp32_p4_function_ev_board)
set(COMPONENT_SRCS
./esp32_p4_function_ev_board/board.c
./esp32_p4_function_ev_board/board_pins_config.c
)
endif()
register_component()

View File

@ -0,0 +1,71 @@
menu "Audio HAL"
choice AUDIO_BOARD
prompt "Audio board"
default ESP_LYRAT_V4_3_BOARD
help
Select an audio board to use with the ESP-ADF
config AUDIO_BOARD_CUSTOM
bool "Custom audio board"
config ESP_LYRAT_V4_3_BOARD
bool "ESP32-Lyrat V4.3"
config ESP_LYRAT_V4_2_BOARD
bool "ESP32-Lyrat V4.2"
config ESP_LYRATD_MSC_V2_1_BOARD
bool "ESP32-LyraTD-MSC V2.1"
config ESP_LYRATD_MSC_V2_2_BOARD
bool "ESP32-LyraTD-MSC V2.2"
config ESP_LYRAT_MINI_V1_1_BOARD
bool "ESP32-Lyrat-Mini V1.1"
config ESP32_KORVO_DU1906_BOARD
bool "ESP32_KORVO_DU1906"
config ESP32_S2_KALUGA_1_V1_2_BOARD
bool "ESP32-S2-Kaluga-1 v1.2"
config ESP32_S3_KORVO2_V3_BOARD
bool "ESP32-S3-Korvo-2 v3"
config ESP32_S3_KORVO2L_V1_BOARD
bool "ESP32-S3-Korvo-2L v1"
config ESP32_S3_BOX_LITE_BOARD
bool "ESP32-S3-BOX-Lite"
config ESP32_S3_BOX_BOARD
bool "ESP32-S3-BOX"
config ESP32_S3_BOX_3_BOARD
bool "ESP32-S3-BOX-3"
config ESP32_C3_LYRA_V2_BOARD
bool "ESP32-C3-Lyra-v2.0"
config ESP32_C6_DEVKIT_BOARD
bool "ESP32-C6-DEVKIT"
config ESP32_P4_FUNCTION_EV_BOARD
bool "ESP32-P4-FUNCTION-EV-BOARD"
config ESP32_S3_SPOT_BOARD
bool "ESP32-S3-Spot"
endchoice
choice ESP32_KORVO_DU1906_DAC
prompt "ESP32 KORVO DU1906 Board DAC chip"
depends on ESP32_KORVO_DU1906_BOARD
default ESP32_KORVO_DU1906_DAC_TAS5805M
help
Select DAC chip to use on ESP32_KORVO_DU1906 board
config ESP32_KORVO_DU1906_DAC_TAS5805M
bool "ESP32_KORVO_DU1906_DAC_TAS5805M"
config ESP32_KORVO_DU1906_DAC_ES7148
bool "ESP32_KORVO_DU1906_DAC_ES7148"
endchoice
choice ESP32_KORVO_DU1906_ADC
prompt "ESP32 KORVO DU1906 Board ADC chip"
depends on ESP32_KORVO_DU1906_BOARD
default ESP32_KORVO_DU1906_ADC_ES7243
help
Select ADC chip to use on ESP32_KORVO_DU1906 board
config ESP32_KORVO_DU1906_ADC_ES7243
bool "ESP32_KORVO_DU1906_ADC_ES7243"
endchoice
endmenu

View File

@ -0,0 +1,53 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
COMPONENT_ADD_INCLUDEDIRS := ./include
ifdef CONFIG_ESP_LYRAT_V4_3_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./lyrat_v4_3
COMPONENT_SRCDIRS += ./lyrat_v4_3
endif
ifdef CONFIG_ESP_LYRAT_V4_2_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./lyrat_v4_2
COMPONENT_SRCDIRS += ./lyrat_v4_2
endif
ifdef CONFIG_ESP_LYRATD_MSC_V2_1_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./lyratd_msc_v2_1
COMPONENT_SRCDIRS += ./lyratd_msc_v2_1
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/../audio_hal/driver/zl38063/firmware -lfirmware
endif
ifdef CONFIG_ESP_LYRATD_MSC_V2_2_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./lyratd_msc_v2_2
COMPONENT_SRCDIRS += ./lyratd_msc_v2_2
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/../audio_hal/driver/zl38063/firmware -lfirmware
endif
ifdef CONFIG_ESP_LYRAT_MINI_V1_1_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./lyrat_mini_v1_1
COMPONENT_SRCDIRS += ./lyrat_mini_v1_1
endif
ifdef CONFIG_ESP32_KORVO_DU1906_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./esp32_korvo_du1906
COMPONENT_SRCDIRS += ./esp32_korvo_du1906
endif
ifdef CONFIG_ESP32_S2_KALUGA_1_V1_2_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./esp32_s2_kaluga_1_v1_2
COMPONENT_SRCDIRS += ./esp32_s2_kaluga_1_v1_2
endif
ifdef CONFIG_ESP32_S3_KORVO2_V3_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./esp32_s3_korvo2_v3
COMPONENT_SRCDIRS += ./esp32_s3_korvo2_v3
endif
ifdef CONFIG_ESP32_C3_LYRA_V2_BOARD
COMPONENT_ADD_INCLUDEDIRS += ./esp32_c3_lyra
COMPONENT_SRCDIRS += ./esp32_c3_lyra
endif

View File

@ -0,0 +1,311 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "display_service.h"
#include "periph_ws2812.h"
#include "board_def.h"
#include "driver/gpio.h"
#include "string.h"
#include "esp_log.h"
const struct periph_ws2812_ctrl_cfg ws2812_display_pattern[DISPLAY_PATTERN_MAX][WS2812_LED_BAR_NUMBERS] = {
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_RED,
.loop = 1000,
.time_off_ms = 200,
.time_on_ms = 400,
} // 0
},
{
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_PURPLE,
.loop = 0xFFFFFFFF,
.time_off_ms = 1500,
.time_on_ms = 1500,
} // 1
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_WHITE,
.loop = 0xFFFFFFFF,
.time_off_ms = 200,
.time_on_ms = 800,
} // 2
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 3
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_RED,
.loop = 1,
.time_off_ms = 1000,
.time_on_ms = 4000,
} // 4
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_WHITE,
.loop = 5,
.time_off_ms = 200,
.time_on_ms = 1000,
} // 5
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_BLUE,
.loop = 100,
.time_off_ms = 200,
.time_on_ms = 800,
} // 6
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 4,
.time_off_ms = 100,
.time_on_ms = 100,
} // 7
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 4,
.time_off_ms = 100,
.time_on_ms = 100,
} // 8
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_PURPLE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 9
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 2,
.time_off_ms = 200,
.time_on_ms = 400,
} // 10
},
{
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_PURPLE,
.loop = 100,
.time_off_ms = 2000,
.time_on_ms = 2000,
} // 11
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 2,
.time_off_ms = 200,
.time_on_ms = 400,
} // 12
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLUE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 13
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 14
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_YELLOW,
.loop = 2000,
.time_off_ms = 200,
.time_on_ms = 600,
} // 15
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 16
},
{
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_GREEN,
.loop = 1,
.time_off_ms = 0,
.time_on_ms = 1000,
} // 17
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_ORANGE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 18
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 19
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_WHITE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 20
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 21
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_RED,
.loop = 1000,
.time_off_ms = 200,
.time_on_ms = 800,
} // 22
},
{
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_PURPLE,
.loop = 1000,
.time_off_ms = 1500,
.time_on_ms = 1500,
} // 23
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 1000,
.time_off_ms = 1000,
.time_on_ms = 2000,
} // 24
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_PURPLE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 25
}
,
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_RED,
.loop = 0xFFFFFFFF,
.time_off_ms = 2000,
.time_on_ms = 2000,
} // 26
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_BLUE,
.loop = 0xFFFFFFFF,
.time_off_ms = 500,
.time_on_ms = 500,
} // 27,
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 28,
}
};
int8_t get_ws2812_gpio_pin(void)
{
return WS2812_LED_GPIO_PIN;
}
int get_ws2812_num(void)
{
return WS2812_LED_BAR_NUMBERS;
}
void ws2812_pattern_copy(struct periph_ws2812_ctrl_cfg *p)
{
ESP_LOGD("ws2812_pattern_copy", "has been called, %s %d", __FILE__, __LINE__);
memcpy(p, ws2812_display_pattern, sizeof(ws2812_display_pattern));
}

View File

@ -0,0 +1,123 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "board.h"
#include "audio_mem.h"
#include "periph_adc_button.h"
#include "led_bar_ws2812.h"
#include "display_service.h"
static const char *TAG = "AUDIO_BOARD";
static audio_board_handle_t board_handle = NULL;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
ESP_LOGW(TAG, "The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle));
AUDIO_MEM_CHECK(TAG, board_handle, return NULL);
board_handle->audio_hal = audio_board_codec_init();
return board_handle;
}
audio_hal_handle_t audio_board_codec_init(void)
{
gpio_config_t io_conf = {0};
bool enable = true;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = BIT64(get_pa_enable_gpio());
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
if (enable) {
gpio_set_level(get_pa_enable_gpio(), 1);
} else {
gpio_set_level(get_pa_enable_gpio(), 0);
}
return NULL;
}
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
esp_err_t ret = ESP_FAIL;
return ret;
}
display_service_handle_t audio_board_led_init(void)
{
led_bar_ws2812_handle_t led = led_bar_ws2812_init(get_ws2812_gpio_pin(), get_ws2812_num());
AUDIO_NULL_CHECK(TAG, led, return NULL);
display_service_config_t display = {
.based_cfg = {
.task_stack = 0,
.task_prio = 0,
.task_core = 0,
.task_func = NULL,
.service_start = NULL,
.service_stop = NULL,
.service_destroy = NULL,
.service_ioctl = led_bar_ws2812_pattern,
.service_name = "DISPLAY_serv",
.user_data = NULL,
},
.instance = led,
};
return display_service_create(&display);
}
esp_err_t audio_board_key_init(esp_periph_set_handle_t set)
{
periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG();
adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR();
adc_btn_tag.adc_ch = ADC1_CHANNEL_2;
adc_btn_tag.total_steps = 6;
int btn_array[7] = {190, 600, 1000, 1375, 1775, 2195, 2700};
adc_btn_tag.adc_level_step = (int *)(&btn_array);
adc_btn_cfg.arr = &adc_btn_tag;
adc_btn_cfg.arr_size = 1;
esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg);
AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK);
return esp_periph_start(set, adc_btn_handle);
}
audio_board_handle_t audio_board_get_handle(void)
{
return board_handle;
}
esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
{
esp_err_t ret = ESP_OK;
ret = audio_hal_deinit(audio_board->audio_hal);
audio_board->audio_hal = NULL;
audio_free(audio_board);
board_handle = NULL;
return ret;
}

View File

@ -0,0 +1,126 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_H_
#define _AUDIO_BOARD_H_
#include "audio_hal.h"
#include "board_def.h"
#include "board_pins_config.h"
#include "esp_peripherals.h"
#include "display_service.h"
#include "periph_sdcard.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Audio board handle
*/
struct audio_board_handle {
audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */
};
typedef struct audio_board_handle *audio_board_handle_t;
/**
* @brief Initialize audio board
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_init(void);
/**
* @brief Initialize codec chip
*
* @return The audio hal handle
*/
audio_hal_handle_t audio_board_codec_init(void);
/**
* @brief Initialize led peripheral and display service
*
* @return The audio display service handle
*/
display_service_handle_t audio_board_led_init(void);
/**
* @brief Initialize sdcard peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode);
/**
* @brief Initialize key peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_key_init(esp_periph_set_handle_t set);
/**
* @brief Query audio_board_handle
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_get_handle(void);
/**
* @brief Uninitialize the audio board
*
* @param audio_board The handle of audio board
*
* @return ESP_OK success,
* others fail
*/
esp_err_t audio_board_deinit(audio_board_handle_t audio_board);
/**
* @brief Get the ws2812 gpio pin
*
* @return GPIO pin
*/
int8_t get_ws2812_gpio_pin(void);
/**
* @brief Get the number of ws2812
*
* @return number of ws2812
*/
int get_ws2812_num(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,134 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_DEFINITION_H_
#define _AUDIO_BOARD_DEFINITION_H_
/**
* @brief Audio Codec Chip Function Definition
*/
#define BOARD_PA_GAIN (10) /* Power amplifier gain defined by board (dB) */
/**
* @brief ADC Function Definition
*/
#define MIC_ADC_GPIO GPIO_NUM_0
#define PA_ENABLE_GPIO GPIO_NUM_1
#define BUTTON_ADC_GPIO GPIO_NUM_2
/**
* @brief SDCARD Function Definition
*/
#define FUNC_SDCARD_EN (0)
#define SDCARD_OPEN_FILE_NUM_MAX 5
#define SDCARD_INTR_GPIO -1
#define SDCARD_PWR_CTRL -1
#define ESP_SD_PIN_CLK -1
#define ESP_SD_PIN_CMD -1
#define ESP_SD_PIN_D0 -1
#define ESP_SD_PIN_D3 -1
/**
* @brief PDM TX Function Definition
*/
#define PDM_TX_GPIO GPIO_NUM_3
/**
* @brief LED Function Definition
*/
#define LED_PWM_BLUE_GPIO GPIO_NUM_4
#define LED_PWM_RED_GPIO GPIO_NUM_5
#define LED_PWM_GREEN_GPIO GPIO_NUM_6
#define WS2812_LED_GPIO_PIN GPIO_NUM_10
#define WS2812_LED_BAR_NUMBERS 1
#define LED_STRIP_CTRL_GPIO GPIO_NUM_7
/**
* @brief IR Function Definition
*/
#define ESP_IR_TX_GPIO GPIO_NUM_18
#define ESP_IR_RX_GPIO GPIO_NUM_19
/**
* @brief I2C Function Definition
*/
#define I2C_CLK_GPIO GPIO_NUM_8
#define I2C_DATA_GPIO GPIO_NUM_9
/**
* @brief Button Function Definition
*/
#define INPUT_KEY_NUM 6
#define BUTTON_VOLUP_ID 0
#define BUTTON_VOLDOWN_ID 1
#define BUTTON_SET_ID 2
#define BUTTON_PLAY_ID 3
#define BUTTON_COLOR_ID 4
#define BUTTON_MODE_ID 5
#define AUDIO_ADC_INPUT_CH_FORMAT "N"
#define INPUT_KEY_DEFAULT_INFO() { \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_COLOR, \
.act_id = BUTTON_COLOR_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_MODE, \
.act_id = BUTTON_MODE_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_SET, \
.act_id = BUTTON_SET_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_PLAY, \
.act_id = BUTTON_PLAY_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLUP, \
.act_id = BUTTON_VOLUP_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLDOWN, \
.act_id = BUTTON_VOLDOWN_ID, \
} \
}
#endif

View File

@ -0,0 +1,141 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "driver/gpio.h"
#include <string.h>
#include "board.h"
#include "audio_error.h"
#include "audio_mem.h"
#include "soc/soc_caps.h"
static const char *TAG = "ESP32_C3_Lyra";
esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
{
AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL);
if (port == 0) {
i2c_config->sda_io_num = GPIO_NUM_9;
i2c_config->scl_io_num = GPIO_NUM_8;
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
ESP_LOGE(TAG, "i2c port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config)
{
AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL);
i2s_config->bck_io_num = -1;
i2s_config->ws_io_num = -1;
i2s_config->data_out_num = PDM_TX_GPIO;
i2s_config->data_in_num = -1;
return ESP_OK;
}
esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config)
{
AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL);
AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL);
spi_config->mosi_io_num = -1;
spi_config->miso_io_num = -1;
spi_config->sclk_io_num = -1;
spi_config->quadwp_io_num = -1;
spi_config->quadhd_io_num = -1;
spi_device_interface_config->spics_io_num = -1;
ESP_LOGW(TAG, "SPI interface is not supported");
return ESP_OK;
}
// sdcard
int8_t get_sdcard_intr_gpio(void)
{
return SDCARD_INTR_GPIO;
}
int8_t get_sdcard_open_file_num_max(void)
{
return SDCARD_OPEN_FILE_NUM_MAX;
}
int8_t get_sdcard_power_ctrl_gpio(void)
{
return SDCARD_PWR_CTRL;
}
// input-output pins
int8_t get_pa_enable_gpio(void)
{
return PA_ENABLE_GPIO;
}
// adc button id
int8_t get_input_rec_id(void)
{
return -1;
}
int8_t get_input_mode_id(void)
{
return BUTTON_MODE_ID;
}
int8_t get_input_set_id(void)
{
return BUTTON_SET_ID;
}
int8_t get_input_play_id(void)
{
return BUTTON_PLAY_ID;
}
int8_t get_input_volup_id(void)
{
return BUTTON_VOLUP_ID;
}
int8_t get_input_voldown_id(void)
{
return BUTTON_VOLDOWN_ID;
}
// led pins
int8_t get_ws2812_led_gpio(void)
{
return WS2812_LED_GPIO_PIN;
}
int8_t get_es8311_mclk_src(void)
{
return -1;
}

View File

@ -0,0 +1,109 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "board.h"
#include "audio_mem.h"
#include "periph_adc_button.h"
#include "led_bar_ws2812.h"
#include "display_service.h"
static const char *TAG = "AUDIO_BOARD";
static audio_board_handle_t board_handle = NULL;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
ESP_LOGW(TAG, "The board has already been initialized!");
return board_handle;
}
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle));
AUDIO_MEM_CHECK(TAG, board_handle, return NULL);
board_handle->audio_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE);
return board_handle;
}
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
esp_err_t ret = ESP_FAIL;
return ret;
}
display_service_handle_t audio_board_led_init(void)
{
led_bar_ws2812_handle_t led = led_bar_ws2812_init(get_ws2812_gpio_pin(), get_ws2812_num());
AUDIO_NULL_CHECK(TAG, led, return NULL);
display_service_config_t display = {
.based_cfg = {
.task_stack = 0,
.task_prio = 0,
.task_core = 0,
.task_func = NULL,
.service_start = NULL,
.service_stop = NULL,
.service_destroy = NULL,
.service_ioctl = led_bar_ws2812_pattern,
.service_name = "DISPLAY_serv",
.user_data = NULL,
},
.instance = led,
};
return display_service_create(&display);
}
esp_err_t audio_board_key_init(esp_periph_set_handle_t set)
{
esp_err_t ret = ESP_OK;
periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG();
adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR();
adc_btn_tag.adc_ch = ADC1_CHANNEL_2;
adc_btn_tag.total_steps = 6;
int btn_array[7] = {380, 820, 1100, 1650, 1980, 2410, 2700};
adc_btn_tag.adc_level_step = (int *)(&btn_array);
adc_btn_cfg.arr = &adc_btn_tag;
adc_btn_cfg.arr_size = 1;
esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg);
AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK);
ret = esp_periph_start(set, adc_btn_handle);
return ret;
}
audio_board_handle_t audio_board_get_handle(void)
{
return board_handle;
}
esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
{
esp_err_t ret = ESP_OK;
ret = audio_hal_deinit(audio_board->audio_hal);
audio_board->audio_hal = NULL;
audio_free(audio_board);
board_handle = NULL;
return ret;
}

View File

@ -0,0 +1,126 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_H_
#define _AUDIO_BOARD_H_
#include "audio_hal.h"
#include "board_def.h"
#include "board_pins_config.h"
#include "esp_peripherals.h"
#include "display_service.h"
#include "periph_sdcard.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Audio board handle
*/
struct audio_board_handle {
audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */
};
typedef struct audio_board_handle *audio_board_handle_t;
/**
* @brief Initialize audio board
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_init(void);
/**
* @brief Initialize codec chip
*
* @return The audio hal handle
*/
audio_hal_handle_t audio_board_codec_init(void);
/**
* @brief Initialize led peripheral and display service
*
* @return The audio display service handle
*/
display_service_handle_t audio_board_led_init(void);
/**
* @brief Initialize sdcard peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode);
/**
* @brief Initialize key peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_key_init(esp_periph_set_handle_t set);
/**
* @brief Query audio_board_handle
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_get_handle(void);
/**
* @brief Uninitialize the audio board
*
* @param audio_board The handle of audio board
*
* @return ESP_OK success,
* others fail
*/
esp_err_t audio_board_deinit(audio_board_handle_t audio_board);
/**
* @brief Get the ws2812 gpio pin
*
* @return GPIO pin
*/
int8_t get_ws2812_gpio_pin(void);
/**
* @brief Get the number of ws2812
*
* @return number of ws2812
*/
int get_ws2812_num(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,147 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_DEFINITION_H_
#define _AUDIO_BOARD_DEFINITION_H_
/**
* @brief Audio Codec Chip Function Definition
*/
#define BOARD_PA_GAIN (10) /* Power amplifier gain defined by board (dB) */
/**
* @brief ADC Function Definition
*/
#define MIC_ADC_GPIO -1
#define PA_ENABLE_GPIO GPIO_NUM_7
#define BUTTON_ADC_GPIO GPIO_NUM_2
/**
* @brief SDCARD Function Definition
*/
#define FUNC_SDCARD_EN (0)
#define SDCARD_OPEN_FILE_NUM_MAX 5
#define SDCARD_INTR_GPIO -1
#define SDCARD_PWR_CTRL -1
#define ESP_SD_PIN_CLK -1
#define ESP_SD_PIN_CMD -1
#define ESP_SD_PIN_D0 -1
#define ESP_SD_PIN_D3 -1
/**
* @brief PDM TX Function Definition
*/
#define PDM_TX_GPIO GPIO_NUM_3
/**
* @brief LED Function Definition
*/
#define WS2812_LED_GPIO_PIN GPIO_NUM_8
#define WS2812_LED_BAR_NUMBERS 1
/**
* @brief IR Function Definition
*/
#define ESP_IR_TX_GPIO GPIO_NUM_18
#define ESP_IR_RX_GPIO GPIO_NUM_19
/**
* @brief I2C Function Definition
*/
#define I2C_CLK_GPIO GPIO_NUM_18
#define I2C_DATA_GPIO GPIO_NUM_19
/**
* @brief Button Function Definition
*/
#define INPUT_KEY_NUM 6
#define BUTTON_VOLUP_ID 0
#define BUTTON_VOLDOWN_ID 1
#define BUTTON_SET_ID 2
#define BUTTON_PLAY_ID 3
#define BUTTON_MODE_ID 4
#define BUTTON_REC_ID 5
extern audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE;
/**
* @brief ADC input data format
*/
#define AUDIO_ADC_INPUT_CH_FORMAT "MR"
#define AUDIO_CODEC_DEFAULT_CONFIG(){ \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
.dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \
.codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \
.i2s_iface = { \
.mode = AUDIO_HAL_MODE_SLAVE, \
.fmt = AUDIO_HAL_I2S_NORMAL, \
.samples = AUDIO_HAL_48K_SAMPLES, \
.bits = AUDIO_HAL_BIT_LENGTH_16BITS, \
}, \
};
#define INPUT_KEY_DEFAULT_INFO() { \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_REC, \
.act_id = BUTTON_REC_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_MODE, \
.act_id = BUTTON_MODE_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_SET, \
.act_id = BUTTON_SET_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_PLAY, \
.act_id = BUTTON_PLAY_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLUP, \
.act_id = BUTTON_VOLUP_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLDOWN, \
.act_id = BUTTON_VOLDOWN_ID, \
} \
}
#endif

View File

@ -0,0 +1,140 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "driver/gpio.h"
#include <string.h>
#include "board.h"
#include "audio_error.h"
#include "audio_mem.h"
static const char *TAG = "ESP32_C6_DevKit";
esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
{
AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL);
if (port == 0) {
i2c_config->sda_io_num = GPIO_NUM_19;
i2c_config->scl_io_num = GPIO_NUM_18;
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
ESP_LOGE(TAG, "i2c port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config)
{
AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL);
i2s_config->mck_io_num = GPIO_NUM_20;
i2s_config->bck_io_num = GPIO_NUM_22;
i2s_config->ws_io_num = GPIO_NUM_21;
i2s_config->data_out_num = GPIO_NUM_23;
i2s_config->data_in_num = GPIO_NUM_15;
return ESP_OK;
}
esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config)
{
AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL);
AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL);
spi_config->mosi_io_num = -1;
spi_config->miso_io_num = -1;
spi_config->sclk_io_num = -1;
spi_config->quadwp_io_num = -1;
spi_config->quadhd_io_num = -1;
spi_device_interface_config->spics_io_num = -1;
ESP_LOGW(TAG, "SPI interface is not supported");
return ESP_OK;
}
// sdcard
int8_t get_sdcard_intr_gpio(void)
{
return SDCARD_INTR_GPIO;
}
int8_t get_sdcard_open_file_num_max(void)
{
return SDCARD_OPEN_FILE_NUM_MAX;
}
int8_t get_sdcard_power_ctrl_gpio(void)
{
return SDCARD_PWR_CTRL;
}
// input-output pins
int8_t get_pa_enable_gpio(void)
{
return PA_ENABLE_GPIO;
}
// adc button id
int8_t get_input_rec_id(void)
{
return -1;
}
int8_t get_input_mode_id(void)
{
return BUTTON_MODE_ID;
}
int8_t get_input_set_id(void)
{
return BUTTON_SET_ID;
}
int8_t get_input_play_id(void)
{
return BUTTON_PLAY_ID;
}
int8_t get_input_volup_id(void)
{
return BUTTON_VOLUP_ID;
}
int8_t get_input_voldown_id(void)
{
return BUTTON_VOLDOWN_ID;
}
// led pins
int8_t get_ws2812_led_gpio(void)
{
return WS2812_LED_GPIO_PIN;
}
int8_t get_es8311_mclk_src(void)
{
return -1;
}

View File

@ -0,0 +1,163 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "board.h"
#include "audio_mem.h"
#include "periph_sdcard.h"
#include "led_indicator.h"
#include "periph_adc_button.h"
#include "led_bar_ws2812.h"
#include "display_service.h"
#include "es7243.h"
static const char *TAG = "AUDIO_BOARD";
static audio_board_handle_t board_handle;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
ESP_LOGW(TAG, "The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle));
AUDIO_MEM_CHECK(TAG, board_handle, return NULL);
board_handle->audio_hal = audio_board_dac_init();
es7243_adc_set_addr(0x24);
board_handle->adc_line_in_hal = audio_board_adc_init();
es7243_adc_set_addr(0x26);
board_handle->adc_ref_pa_hal = audio_board_adc_init();
return board_handle;
}
audio_hal_handle_t audio_board_dac_init(void)
{
audio_hal_handle_t dac_hal = NULL;
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
#ifdef CONFIG_ESP32_KORVO_DU1906_DAC_TAS5805M
dac_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE);
#elif CONFIG_ESP32_KORVO_DU1906_DAC_ES7148
dac_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7148_DEFAULT_HANDLE);
#endif
AUDIO_NULL_CHECK(TAG, dac_hal, return NULL);
return dac_hal;
}
audio_hal_handle_t audio_board_adc_init(void)
{
audio_hal_handle_t adc_hal = NULL;
#ifdef CONFIG_ESP32_KORVO_DU1906_ADC_ES7243
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, adc_hal, return NULL);
#endif
return adc_hal;
}
display_service_handle_t audio_board_led_init(void)
{
led_bar_ws2812_handle_t led = led_bar_ws2812_init(get_ws2812_gpio_pin(), get_ws2812_num());
AUDIO_NULL_CHECK(TAG, led, return NULL);
display_service_config_t display = {
.based_cfg = {
.task_stack = 0,
.task_prio = 0,
.task_core = 0,
.task_func = NULL,
.service_start = NULL,
.service_stop = NULL,
.service_destroy = NULL,
.service_ioctl = led_bar_ws2812_pattern,
.service_name = "DISPLAY_serv",
.user_data = NULL,
},
.instance = led,
};
return display_service_create(&display);
}
esp_err_t audio_board_key_init(esp_periph_set_handle_t set)
{
periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG();
adc_btn_cfg.task_cfg.ext_stack = true;
adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR();
adc_btn_tag.adc_ch = ADC1_CHANNEL_0; // GPIO36
adc_btn_tag.total_steps = 4;
int btn_array[5] = {200, 900, 1500, 2100, 2930};
adc_btn_tag.adc_level_step = btn_array;
adc_btn_cfg.arr = &adc_btn_tag;
adc_btn_cfg.arr_size = 1;
esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg);
AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK);
return esp_periph_start(set, adc_btn_handle);
}
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
if (mode != SD_MODE_1_LINE) {
ESP_LOGE(TAG, "Current board only support 1-line SD mode!");
return ESP_FAIL;
}
periph_sdcard_cfg_t sdcard_cfg = {
.root = "/sdcard",
.card_detect_pin = get_sdcard_intr_gpio(), // GPIO_NUM_34
.mode = mode
};
esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg);
esp_err_t ret = esp_periph_start(set, sdcard_handle);
int retry_time = 5;
bool mount_flag = false;
while (retry_time --) {
if (periph_sdcard_is_mounted(sdcard_handle)) {
mount_flag = true;
break;
} else {
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
if (mount_flag == false) {
ESP_LOGE(TAG, "Sdcard mount failed");
return ESP_FAIL;
}
return ret;
}
audio_board_handle_t audio_board_get_handle(void)
{
return board_handle;
}
esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
{
esp_err_t ret = ESP_OK;
ret |= audio_hal_deinit(audio_board->audio_hal);
audio_free(audio_board);
board_handle = NULL;
return ret;
}

View File

@ -0,0 +1,139 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_H_
#define _AUDIO_BOARD_H_
#include "audio_hal.h"
#include "board_def.h"
#include "board_pins_config.h"
#include "esp_peripherals.h"
#include "display_service.h"
#include "periph_sdcard.h"
#ifdef __cplusplus
extern "C" {
#endif
extern audio_hal_func_t AUDIO_CODEC_TAS5805M_DEFAULT_HANDLE;
extern audio_hal_func_t AUDIO_CODEC_ES7148_DEFAULT_HANDLE;
extern audio_hal_func_t AUDIO_CODEC_ES7243_DEFAULT_HANDLE;
/**
* @brief Audio board handle
*/
struct audio_board_handle {
audio_hal_handle_t audio_hal; /*!< pa hardware abstract layer handle */
audio_hal_handle_t adc_line_in_hal; /*!< adc hardware abstract layer handle */
audio_hal_handle_t adc_ref_pa_hal; /*!< adc hardware abstract layer handle */
};
typedef struct audio_board_handle *audio_board_handle_t;
/**
* @brief Initialize audio board
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_init(void);
/**
* @brief Initialize DAC chip
*
* @return The audio hal handle
*/
audio_hal_handle_t audio_board_dac_init(void);
/**
* @brief Initialize ADC chip
*
* @return The audio hal handle
*/
audio_hal_handle_t audio_board_adc_init(void);
/**
* @brief Initialize led peripheral and display service
*
* @return The audio display service handle
*/
display_service_handle_t audio_board_led_init(void);
/**
* @brief Initialize key peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_key_init(esp_periph_set_handle_t set);
/**
* @brief Initialize sdcard peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode);
/**
* @brief Query audio_board_handle
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_get_handle(void);
/**
* @brief Uninitialize the audio board
*
* @param audio_board The handle of audio board
*
* @return ESP_OK, success
* others, fail
*/
esp_err_t audio_board_deinit(audio_board_handle_t audio_board);
/**
* @brief Get the ws2812 gpio pin
*
* @return GPIO pin
*/
int8_t get_ws2812_gpio_pin(void);
/**
* @brief Get the number of ws2812
*
* @return number of ws2812
*/
int get_ws2812_num(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,120 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_DEFINITION_H_
#define _AUDIO_BOARD_DEFINITION_H_
/**
* @brief SDCARD Function Definition
*/
#define FUNC_SDCARD_EN (1)
#define SDCARD_OPEN_FILE_NUM_MAX 5
#define SDCARD_INTR_GPIO GPIO_NUM_39
#define ESP_SD_PIN_CLK GPIO_NUM_14
#define ESP_SD_PIN_CMD GPIO_NUM_15
#define ESP_SD_PIN_D0 GPIO_NUM_2
#define ESP_SD_PIN_D3 -1
/**
* @brief LED Function Definition
*/
#define FUNC_SYS_LEN_EN (1)
#define WS2812_LED_GPIO_PIN 3
#define WS2812_LED_BAR_NUMBERS 2
/**
* @brief Battery Detect Function Definition
*/
#define FUNC_BATTERY_DET_EN (1)
#define BATTERY_DETECT_GPIO GPIO_NUM_37
/**
* @brief Audio Codec Chip Function Definition
*/
#define FUNC_AUDIO_CODEC_EN (1)
#define CODEC_ADC_I2S_PORT ((i2s_port_t)0)
#define ES7243_MCLK_GPIO GPIO_NUM_0
#define PA_ENABLE_GPIO GPIO_NUM_12
#define BOARD_PA_GAIN (10) /* Power amplifier gain defined by board (dB) */
/**
* @brief ADC input data format
*/
#define AUDIO_ADC_INPUT_CH_FORMAT "N"
#define AUDIO_CODEC_DEFAULT_CONFIG(){ \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
.dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \
.codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \
.i2s_iface = { \
.mode = AUDIO_HAL_MODE_SLAVE, \
.fmt = AUDIO_HAL_I2S_NORMAL, \
.samples = AUDIO_HAL_48K_SAMPLES, \
.bits = AUDIO_HAL_BIT_LENGTH_16BITS, \
}, \
};
/**
* @brief Button Function Definition
*/
#define FUNC_BUTTON_EN (1)
#define ADC_DETECT_GPIO GPIO_NUM_36
#define INPUT_KEY_NUM 4
#define BUTTON_VOLUP_ID 0
#define BUTTON_VOLDOWN_ID 1
#define BUTTON_MUTE_ID 2
#define BUTTON_SET_ID 3
#define BUTTON_REC_ID (-1)
#define BUTTON_MODE_ID (-1)
#define GREEN_LED_GPIO (-1)
#define INPUT_KEY_DEFAULT_INFO() { \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLUP, \
.act_id = BUTTON_VOLUP_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLDOWN, \
.act_id = BUTTON_VOLDOWN_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_MUTE, \
.act_id = BUTTON_MUTE_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_SET, \
.act_id = BUTTON_SET_ID, \
}, \
}
#endif

View File

@ -0,0 +1,149 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "string.h"
#include "driver/gpio.h"
#include "board.h"
#include "audio_error.h"
#include "audio_mem.h"
#include "soc/io_mux_reg.h"
#include "soc/soc_caps.h"
static const char *TAG = "ESP32_Korvo_DU1906";
esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
{
AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL);
if (port == I2C_NUM_0 || port == I2C_NUM_1) {
i2c_config->sda_io_num = GPIO_NUM_18;
i2c_config->scl_io_num = GPIO_NUM_23;
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
ESP_LOGE(TAG, "i2c port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config)
{
AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL);
if (port == 0) {
i2s_config->mck_io_num = GPIO_NUM_0;
i2s_config->bck_io_num = GPIO_NUM_4;
i2s_config->ws_io_num = GPIO_NUM_13;
i2s_config->data_out_num = GPIO_NUM_16;
i2s_config->data_in_num = GPIO_NUM_39;
} else if (port == 1) {
i2s_config->bck_io_num = -1;
i2s_config->ws_io_num = -1;
i2s_config->data_out_num = -1;
i2s_config->data_in_num = -1;
} else {
memset(i2s_config, -1, sizeof(board_i2s_pin_t));
ESP_LOGE(TAG, "i2s port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config)
{
AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL);
AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL);
spi_config->mosi_io_num = -1;
spi_config->miso_io_num = -1;
spi_config->sclk_io_num = -1;
spi_config->quadwp_io_num = -1;
spi_config->quadhd_io_num = -1;
spi_device_interface_config->spics_io_num = -1;
ESP_LOGW(TAG, "SPI interface is not supported");
return ESP_OK;
}
// sdcard
int8_t get_sdcard_intr_gpio(void)
{
return SDCARD_INTR_GPIO;
}
int8_t get_sdcard_open_file_num_max(void)
{
return SDCARD_OPEN_FILE_NUM_MAX;
}
// Using "mute" button instead of "play" button as the audio control button,
// since `ESP32-Korvo-DU1906` board has not "play" button
int8_t get_input_play_id(void)
{
return BUTTON_MUTE_ID;
}
int8_t get_input_set_id(void)
{
return BUTTON_SET_ID;
}
int8_t get_input_volup_id(void)
{
return BUTTON_VOLUP_ID;
}
int8_t get_input_voldown_id(void)
{
return BUTTON_VOLDOWN_ID;
}
int8_t get_input_rec_id(void)
{
return BUTTON_REC_ID;
}
int8_t get_input_mode_id(void)
{
return BUTTON_MODE_ID;
}
int8_t get_pa_enable_gpio(void)
{
return PA_ENABLE_GPIO;
}
int8_t get_es7243_mclk_gpio(void)
{
return ES7243_MCLK_GPIO;
}
// led pins
int8_t get_green_led_gpio(void)
{
return GREEN_LED_GPIO;
}

View File

@ -0,0 +1,513 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "display_service.h"
#include "periph_ws2812.h"
#include "board_def.h"
#include "string.h"
#include "esp_log.h"
const struct periph_ws2812_ctrl_cfg ws2812_display_pattern[DISPLAY_PATTERN_MAX][WS2812_LED_BAR_NUMBERS] = {
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_RED,
.loop = 1000,
.time_off_ms = 200,
.time_on_ms = 400,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_RED,
.loop = 1000,
.time_off_ms = 200,
.time_on_ms = 400,
} // 0
},
{
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_PURPLE,
.loop = 0xFFFFFFFF,
.time_off_ms = 1500,
.time_on_ms = 1500,
},
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_PURPLE,
.loop = 0xFFFFFFFF,
.time_off_ms = 1500,
.time_on_ms = 1500,
} // 1
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_WHITE,
.loop = 0xFFFFFFFF,
.time_off_ms = 200,
.time_on_ms = 800,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_WHITE,
.loop = 0xFFFFFFFF,
.time_off_ms = 200,
.time_on_ms = 800,
} // 2
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK ,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 3
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_RED,
.loop = 1,
.time_off_ms = 1000,
.time_on_ms = 4000,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_RED,
.loop = 1,
.time_off_ms = 1000,
.time_on_ms = 4000,
} // 4
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_WHITE,
.loop = 5,
.time_off_ms = 200,
.time_on_ms = 1000,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_WHITE,
.loop = 5,
.time_off_ms = 200,
.time_on_ms = 1000,
} // 5
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_BLUE,
.loop = 100,
.time_off_ms = 200,
.time_on_ms = 800,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_BLUE,
.loop = 100,
.time_off_ms = 200,
.time_on_ms = 800,
} // 6
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 4,
.time_off_ms = 100,
.time_on_ms = 100,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 4,
.time_off_ms = 100,
.time_on_ms = 100,
} // 7
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 4,
.time_off_ms = 100,
.time_on_ms = 100,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 4,
.time_off_ms = 100,
.time_on_ms = 100,
} // 8
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_PURPLE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_PURPLE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 9
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 2,
.time_off_ms = 200,
.time_on_ms = 400,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 2,
.time_off_ms = 200,
.time_on_ms = 400,
} // 10
},
{
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_PURPLE,
.loop = 100,
.time_off_ms = 2000,
.time_on_ms = 2000,
},
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_PURPLE,
.loop = 100,
.time_off_ms = 2000,
.time_on_ms = 2000,
} // 11
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 2,
.time_off_ms = 200,
.time_on_ms = 400,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 2,
.time_off_ms = 200,
.time_on_ms = 400,
} // 12
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLUE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLUE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 13
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 14
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_YELLOW,
.loop = 2000,
.time_off_ms = 200,
.time_on_ms = 600,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_YELLOW,
.loop = 2000,
.time_off_ms = 200,
.time_on_ms = 600,
} // 15
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 16
},
{
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_GREEN,
.loop = 1,
.time_off_ms = 0,
.time_on_ms = 1000,
},
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_GREEN,
.loop = 1,
.time_off_ms = 0,
.time_on_ms = 1000,
} // 17
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_ORANGE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_ORANGE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 18
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 19
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_WHITE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_WHITE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 20
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 21
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_RED,
.loop = 1000,
.time_off_ms = 200,
.time_on_ms = 800,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_RED,
.loop = 1000,
.time_off_ms = 200,
.time_on_ms = 800,
} // 22
},
{
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_PURPLE,
.loop = 1000,
.time_off_ms = 1500,
.time_on_ms = 1500,
},
{
.mode = PERIPH_WS2812_FADE,
.color = LED2812_COLOR_PURPLE,
.loop = 1000,
.time_off_ms = 1500,
.time_on_ms = 1500,
} // 23
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 1000,
.time_off_ms = 1000,
.time_on_ms = 2000,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_PURPLE,
.loop = 1000,
.time_off_ms = 1000,
.time_on_ms = 2000,
} // 24
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_PURPLE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_PURPLE,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 25
}
,
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_RED,
.loop = 0xFFFFFFFF,
.time_off_ms = 2000,
.time_on_ms = 2000,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_RED,
.loop = 0xFFFFFFFF,
.time_off_ms = 2000,
.time_on_ms = 2000,
} // 26
},
{
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_BLUE,
.loop = 0xFFFFFFFF,
.time_off_ms = 500,
.time_on_ms = 500,
},
{
.mode = PERIPH_WS2812_BLINK,
.color = LED2812_COLOR_BLUE,
.loop = 0xFFFFFFFF,
.time_off_ms = 500,
.time_on_ms = 500,
} // 27,
},
{
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
},
{
.mode = PERIPH_WS2812_ONE,
.color = LED2812_COLOR_BLACK,
.loop = 0,
.time_off_ms = 0,
.time_on_ms = 0,
} // 28,
}
};
int8_t get_ws2812_gpio_pin(void)
{
return WS2812_LED_GPIO_PIN;
}
int get_ws2812_num(void)
{
return WS2812_LED_BAR_NUMBERS;
}
void ws2812_pattern_copy(struct periph_ws2812_ctrl_cfg *p)
{
ESP_LOGD("ws2812_pattern_copy", "has been called, %s %d", __FILE__, __LINE__);
memcpy(p, ws2812_display_pattern, sizeof(ws2812_display_pattern));
}

View File

@ -0,0 +1,99 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2024 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "board.h"
#include "audio_mem.h"
#include "periph_sdcard.h"
#include "periph_adc_button.h"
static const char *TAG = "AUDIO_BOARD";
static audio_board_handle_t board_handle = 0;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
ESP_LOGW(TAG, "The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t)audio_calloc(1, sizeof(struct audio_board_handle));
AUDIO_MEM_CHECK(TAG, board_handle, return NULL);
board_handle->audio_hal = audio_board_codec_init();
return board_handle;
}
audio_hal_handle_t audio_board_codec_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, codec_hal, return NULL);
return codec_hal;
}
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
periph_sdcard_cfg_t sdcard_cfg = {
.root = "/sdcard",
.card_detect_pin = get_sdcard_intr_gpio(),
.mode = mode
};
esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg);
esp_err_t ret = esp_periph_start(set, sdcard_handle);
int retry_time = 5;
bool mount_flag = false;
while (retry_time--) {
if (periph_sdcard_is_mounted(sdcard_handle)) {
mount_flag = true;
break;
} else {
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
if (mount_flag == false) {
ESP_LOGE(TAG, "Sdcard mount failed");
return ESP_FAIL;
}
return ret;
}
esp_err_t audio_board_key_init(esp_periph_set_handle_t set)
{
ESP_LOGE(TAG, "esp32_p4_function_ev_board not support key");
return ESP_FAIL;
}
audio_board_handle_t audio_board_get_handle(void)
{
return board_handle;
}
esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
{
esp_err_t ret = ESP_OK;
ret |= audio_hal_deinit(audio_board->audio_hal);
audio_free(audio_board);
board_handle = NULL;
return ret;
}

View File

@ -0,0 +1,114 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2024 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_H_
#define _AUDIO_BOARD_H_
#include "audio_hal.h"
#include "board_def.h"
#include "board_pins_config.h"
#include "esp_peripherals.h"
#include "display_service.h"
#include "periph_sdcard.h"
#include "periph_lcd.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* @brief Audio board handle
*/
struct audio_board_handle {
audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */
};
typedef struct audio_board_handle *audio_board_handle_t;
/**
* @brief Initialize audio board
*
* @return
* - NULL If initialization failed
* - Others The audio board handle
*/
audio_board_handle_t audio_board_init(void);
/**
* @brief Initialize codec chip
*
* @return
* - NULL If initialization failed
* - Others The audio hal handle
*/
audio_hal_handle_t audio_board_codec_init(void);
/**
* @brief Initialize sdcard peripheral
*
* @param[in] set The handle of esp_periph_set_handle_t
* @param[in] mode SDCard mode
*
* @return
* - ESP_OK On success
* - Others On failure
*/
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode);
/**
* @brief Initialize key peripheral
*
* @param[in] set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK On success
* - Others On failure
*/
esp_err_t audio_board_key_init(esp_periph_set_handle_t set);
/**
* @brief Query audio_board_handle
*
* @return
* - NULL If board not initialized
* - Others The audio board handle
*/
audio_board_handle_t audio_board_get_handle(void);
/**
* @brief Uninitialize the audio board
*
* @param[in] audio_board The handle of audio board
*
* @return
* - ESP_OK On success
* - Others On failure
*/
esp_err_t audio_board_deinit(audio_board_handle_t audio_board);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _AUDIO_BOARD_H_ */

View File

@ -0,0 +1,112 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2024 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_DEFINITION_H_
#define _AUDIO_BOARD_DEFINITION_H_
/**
* @brief SDCARD Function Definition
*/
#define SD_PWR_CTRL_LDO_INTERNAL_IO (4)
#define FUNC_SDCARD_EN (1)
#define SDCARD_OPEN_FILE_NUM_MAX (5)
#define SDCARD_INTR_GPIO (-1)
#define SDCARD_PWR_CTRL (-1)
// In order to coexist with ESP host, slot0 is required and matrix will not be used,
// so all default configurations are set to 0
#define ESP_SD_PIN_CLK (0)
#define ESP_SD_PIN_CMD (0)
#define ESP_SD_PIN_D0 (0)
#define ESP_SD_PIN_D1 (0)
#define ESP_SD_PIN_D2 (0)
#define ESP_SD_PIN_D3 (0)
#define ESP_SD_PIN_D4 (0)
#define ESP_SD_PIN_D5 (0)
#define ESP_SD_PIN_D6 (0)
#define ESP_SD_PIN_D7 (0)
#define ESP_SD_PIN_CD (-1)
#define ESP_SD_PIN_WP (-1)
/**
* @brief Audio Codec Chip Function Definition
*/
#define FUNC_AUDIO_CODEC_EN (1)
#define ES8311_MCLK_SOURCE (1) /* 0 From MCLK of esp32 1 From BCLK */
#define HEADPHONE_DETECT (-1)
#define PA_ENABLE_GPIO GPIO_NUM_53
#define CODEC_ADC_I2S_PORT ((i2s_port_t)0)
#define CODEC_ADC_BITS_PER_SAMPLE ((i2s_data_bit_width_t)16) /* 16bit */
#define CODEC_ADC_SAMPLE_RATE (48000)
#define RECORD_HARDWARE_AEC (true)
#define BOARD_PA_GAIN (6) /* Power amplifier gain defined by board (dB) */
/**
* @brief ADC input data format
*/
#define AUDIO_ADC_INPUT_CH_FORMAT "MR"
extern audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE;
#define AUDIO_CODEC_DEFAULT_CONFIG(){ \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
.dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \
.codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \
.i2s_iface = { \
.mode = AUDIO_HAL_MODE_SLAVE, \
.fmt = AUDIO_HAL_I2S_NORMAL, \
.samples = AUDIO_HAL_48K_SAMPLES, \
.bits = AUDIO_HAL_BIT_LENGTH_16BITS, \
}, \
};
/**
* @brief Button Function Definition
*/
#define FUNC_BUTTON_EN (0)
#define INPUT_KEY_NUM (0)
#define BUTTON_VOLUP_ID (-1)
#define BUTTON_VOLDOWN_ID (-1)
#define BUTTON_SET_ID (-1)
#define BUTTON_PLAY_ID (0)
#define BUTTON_MODE_ID (-1)
#define BUTTON_REC_ID (1)
#define INPUT_KEY_DEFAULT_INFO() { \
{ \
.type = PERIPH_ID_BUTTON, \
.user_id = INPUT_KEY_USER_ID_REC, \
.act_id = BUTTON_REC_ID, \
}, \
{ \
.type = PERIPH_ID_BUTTON, \
.user_id = INPUT_KEY_USER_ID_PLAY, \
.act_id = BUTTON_PLAY_ID, \
} \
}
#endif /* _AUDIO_BOARD_DEFINITION_H_ */

View File

@ -0,0 +1,166 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2024 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <string.h>
#include "esp_log.h"
#include "driver/gpio.h"
#include "board.h"
#include "audio_error.h"
#include "audio_mem.h"
#include "soc/soc_caps.h"
static const char *TAG = "ESP32_P4_FUNCTION_EV_BOARD";
esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
{
AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL);
if (port == I2C_NUM_0 || port == I2C_NUM_1) {
i2c_config->sda_io_num = GPIO_NUM_7;
i2c_config->scl_io_num = GPIO_NUM_8;
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
ESP_LOGE(TAG, "i2c port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config)
{
AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL);
if (port == 0) {
i2s_config->bck_io_num = GPIO_NUM_12;
i2s_config->ws_io_num = GPIO_NUM_10;
i2s_config->data_out_num = GPIO_NUM_9;
i2s_config->data_in_num = GPIO_NUM_11;
i2s_config->mck_io_num = GPIO_NUM_13;
} else if (port == 1) {
i2s_config->bck_io_num = -1;
i2s_config->ws_io_num = -1;
i2s_config->data_out_num = -1;
i2s_config->data_in_num = -1;
i2s_config->mck_io_num = -1;
} else {
memset(i2s_config, -1, sizeof(board_i2s_pin_t));
ESP_LOGE(TAG, "i2s port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config)
{
AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL);
AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL);
spi_config->mosi_io_num = -1;
spi_config->miso_io_num = -1;
spi_config->sclk_io_num = -1;
spi_config->quadwp_io_num = -1;
spi_config->quadhd_io_num = -1;
spi_device_interface_config->spics_io_num = -1;
ESP_LOGW(TAG, "SPI interface is not supported");
return ESP_OK;
}
// sdcard
int8_t get_sdcard_intr_gpio(void)
{
return SDCARD_INTR_GPIO;
}
int8_t get_sdcard_open_file_num_max(void)
{
return SDCARD_OPEN_FILE_NUM_MAX;
}
int8_t get_sdcard_power_ctrl_gpio(void)
{
return SDCARD_PWR_CTRL;
}
// input-output pins
int8_t get_headphone_detect_gpio(void)
{
return HEADPHONE_DETECT;
}
int8_t get_pa_enable_gpio(void)
{
return PA_ENABLE_GPIO;
}
// adc button id
int8_t get_input_rec_id(void)
{
return -1;
}
int8_t get_input_mode_id(void)
{
return -1;
}
int8_t get_input_set_id(void)
{
return -1;
}
int8_t get_input_play_id(void)
{
return -1;
}
int8_t get_input_volup_id(void)
{
return -1;
}
int8_t get_input_voldown_id(void)
{
return -1;
}
// led pins
int8_t get_green_led_gpio(void)
{
return -1;
}
int8_t get_blue_led_gpio(void)
{
return -1;
}
int8_t get_es8311_mclk_src(void)
{
return -1;
}

View File

@ -0,0 +1,139 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2025 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "board.h"
#include "audio_mem.h"
#include "periph_sdcard.h"
#include "periph_adc_button.h"
#include "sd_pwr_ctrl_by_on_chip_ldo.h"
#include "sd_pwr_ctrl_interface.h"
#include "esp_ldo_regulator.h"
#define LDO_CHANNEL_ID (4)
#define LDO_CFG_VOL_MV (3300)
static const char *TAG = "AUDIO_BOARD";
static audio_board_handle_t board_handle = 0;
static esp_ldo_channel_handle_t ldo_audio_board = NULL;
static void _enable_audio_board_power(void)
{
// Turn on the power for audio board, so it can go from "No Power" state to "Shutdown" state
esp_ldo_channel_config_t ldo_audio_board_config = {
.chan_id = LDO_CHANNEL_ID,
.voltage_mv = LDO_CFG_VOL_MV,
};
esp_ldo_acquire_channel(&ldo_audio_board_config, &ldo_audio_board);
ESP_LOGI(TAG, "Audio board powered on");
}
static void _disable_audio_board_power(void)
{
if (ldo_audio_board) {
esp_ldo_release_channel(ldo_audio_board);
ldo_audio_board = NULL;
}
}
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
ESP_LOGW(TAG, "The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t)audio_calloc(1, sizeof(struct audio_board_handle));
AUDIO_MEM_CHECK(TAG, board_handle, return NULL);
board_handle->audio_hal = audio_board_codec_init();
board_handle->adc_hal = audio_board_adc_init();
_enable_audio_board_power();
return board_handle;
}
audio_hal_handle_t audio_board_adc_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_codec_cfg.codec_mode = AUDIO_HAL_CODEC_MODE_ENCODE;
audio_hal_handle_t adc_hal = NULL;
adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7210_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, adc_hal, return NULL);
return adc_hal;
}
audio_hal_handle_t audio_board_codec_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, codec_hal, return NULL);
return codec_hal;
}
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
periph_sdcard_cfg_t sdcard_cfg = {
.root = "/sdcard",
.card_detect_pin = get_sdcard_intr_gpio(),
.mode = mode
};
esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg);
esp_err_t ret = esp_periph_start(set, sdcard_handle);
int retry_time = 5;
bool mount_flag = false;
while (retry_time--) {
if (periph_sdcard_is_mounted(sdcard_handle)) {
mount_flag = true;
break;
} else {
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
if (mount_flag == false) {
ESP_LOGE(TAG, "Sdcard mount failed");
return ESP_FAIL;
}
return ret;
}
esp_err_t audio_board_key_init(esp_periph_set_handle_t set)
{
ESP_LOGE(TAG, "esp32_p4_function_ev_board not support key");
return ESP_FAIL;
}
audio_board_handle_t audio_board_get_handle(void)
{
return board_handle;
}
esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
{
esp_err_t ret = ESP_OK;
ret |= audio_hal_deinit(audio_board->audio_hal);
audio_free(audio_board);
_disable_audio_board_power();
board_handle = NULL;
return ret;
}

View File

@ -0,0 +1,122 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2025 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_H_
#define _AUDIO_BOARD_H_
#include "audio_hal.h"
#include "board_def.h"
#include "board_pins_config.h"
#include "esp_peripherals.h"
#include "display_service.h"
#include "periph_sdcard.h"
#include "periph_lcd.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* @brief Audio board handle
*/
struct audio_board_handle {
audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */
audio_hal_handle_t adc_hal; /*!< adc hardware abstract layer handle */
};
typedef struct audio_board_handle *audio_board_handle_t;
/**
* @brief Initialize audio board
*
* @return
* - NULL If initialization failed
* - Others The audio board handle
*/
audio_board_handle_t audio_board_init(void);
/**
* @brief Initialize codec chip
*
* @return
* - NULL If initialization failed
* - Others The audio hal handle
*/
audio_hal_handle_t audio_board_codec_init(void);
/**
* @brief Initialize adc
*
* @return The adc hal handle
*/
audio_hal_handle_t audio_board_adc_init(void);
/**
* @brief Initialize sdcard peripheral
*
* @param[in] set The handle of esp_periph_set_handle_t
* @param[in] mode SDCard mode
*
* @return
* - ESP_OK On success
* - Others On failure
*/
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode);
/**
* @brief Initialize key peripheral
*
* @param[in] set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK On success
* - Others On failure
*/
esp_err_t audio_board_key_init(esp_periph_set_handle_t set);
/**
* @brief Query audio_board_handle
*
* @return
* - NULL If board not initialized
* - Others The audio board handle
*/
audio_board_handle_t audio_board_get_handle(void);
/**
* @brief Uninitialize the audio board
*
* @param[in] audio_board The handle of audio board
*
* @return
* - ESP_OK On success
* - Others On failure
*/
esp_err_t audio_board_deinit(audio_board_handle_t audio_board);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _AUDIO_BOARD_H_ */

View File

@ -0,0 +1,113 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2025 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_DEFINITION_H_
#define _AUDIO_BOARD_DEFINITION_H_
/**
* @brief SDCARD Function Definition
*/
#define SD_PWR_CTRL_LDO_INTERNAL_IO (4)
#define FUNC_SDCARD_EN (1)
#define SDCARD_OPEN_FILE_NUM_MAX (5)
#define SDCARD_INTR_GPIO (-1)
#define SDCARD_PWR_CTRL (-1)
// In order to coexist with ESP host, slot0 is required and matrix will not be used,
// so all default configurations are set to 0
#define ESP_SD_PIN_CLK (0)
#define ESP_SD_PIN_CMD (0)
#define ESP_SD_PIN_D0 (0)
#define ESP_SD_PIN_D1 (0)
#define ESP_SD_PIN_D2 (0)
#define ESP_SD_PIN_D3 (0)
#define ESP_SD_PIN_D4 (0)
#define ESP_SD_PIN_D5 (0)
#define ESP_SD_PIN_D6 (0)
#define ESP_SD_PIN_D7 (0)
#define ESP_SD_PIN_CD (-1)
#define ESP_SD_PIN_WP (-1)
/**
* @brief Audio Codec Chip Function Definition
*/
#define FUNC_AUDIO_CODEC_EN (1)
#define ES8311_MCLK_SOURCE (1) /* 0 From MCLK of esp32 1 From BCLK */
#define HEADPHONE_DETECT (-1)
#define PA_ENABLE_GPIO GPIO_NUM_53
#define CODEC_ADC_I2S_PORT ((i2s_port_t)0)
#define CODEC_ADC_BITS_PER_SAMPLE ((i2s_data_bit_width_t)16) /* 16bit */
#define CODEC_ADC_SAMPLE_RATE (48000)
#define RECORD_HARDWARE_AEC (true)
#define BOARD_PA_GAIN (6) /* Power amplifier gain defined by board (dB) */
/**
* @brief ADC input data format
*/
#define AUDIO_ADC_INPUT_CH_FORMAT "RMNM"
extern audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE;
extern audio_hal_func_t AUDIO_CODEC_ES7210_DEFAULT_HANDLE;
#define AUDIO_CODEC_DEFAULT_CONFIG(){ \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
.dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \
.codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \
.i2s_iface = { \
.mode = AUDIO_HAL_MODE_SLAVE, \
.fmt = AUDIO_HAL_I2S_NORMAL, \
.samples = AUDIO_HAL_48K_SAMPLES, \
.bits = AUDIO_HAL_BIT_LENGTH_16BITS, \
}, \
};
/**
* @brief Button Function Definition
*/
#define FUNC_BUTTON_EN (0)
#define INPUT_KEY_NUM (0)
#define BUTTON_VOLUP_ID (-1)
#define BUTTON_VOLDOWN_ID (-1)
#define BUTTON_SET_ID (-1)
#define BUTTON_PLAY_ID (0)
#define BUTTON_MODE_ID (-1)
#define BUTTON_REC_ID (1)
#define INPUT_KEY_DEFAULT_INFO() { \
{ \
.type = PERIPH_ID_BUTTON, \
.user_id = INPUT_KEY_USER_ID_REC, \
.act_id = BUTTON_REC_ID, \
}, \
{ \
.type = PERIPH_ID_BUTTON, \
.user_id = INPUT_KEY_USER_ID_PLAY, \
.act_id = BUTTON_PLAY_ID, \
} \
}
#endif /* _AUDIO_BOARD_DEFINITION_H_ */

View File

@ -0,0 +1,166 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2025 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <string.h>
#include "esp_log.h"
#include "driver/gpio.h"
#include "board.h"
#include "audio_error.h"
#include "audio_mem.h"
#include "soc/soc_caps.h"
static const char *TAG = "ESP32_P4_FUNCTION_EV_BOARD";
esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
{
AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL);
if (port == I2C_NUM_0 || port == I2C_NUM_1) {
i2c_config->sda_io_num = GPIO_NUM_21;
i2c_config->scl_io_num = GPIO_NUM_20;
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
ESP_LOGE(TAG, "i2c port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config)
{
AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL);
if (port == 0) { // 7210
i2s_config->bck_io_num = GPIO_NUM_47;
i2s_config->ws_io_num = GPIO_NUM_48;
i2s_config->data_out_num = GPIO_NUM_45;
i2s_config->data_in_num = GPIO_NUM_27;
i2s_config->mck_io_num = GPIO_NUM_46;
} else if (port == 1) { // 8311
i2s_config->bck_io_num = -1;
i2s_config->ws_io_num = -1;
i2s_config->data_out_num = -1;
i2s_config->data_in_num = -1;
i2s_config->mck_io_num = -1;
} else {
memset(i2s_config, -1, sizeof(board_i2s_pin_t));
ESP_LOGE(TAG, "i2s port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config)
{
AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL);
AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL);
spi_config->mosi_io_num = -1;
spi_config->miso_io_num = -1;
spi_config->sclk_io_num = -1;
spi_config->quadwp_io_num = -1;
spi_config->quadhd_io_num = -1;
spi_device_interface_config->spics_io_num = -1;
ESP_LOGW(TAG, "SPI interface is not supported");
return ESP_OK;
}
// sdcard
int8_t get_sdcard_intr_gpio(void)
{
return SDCARD_INTR_GPIO;
}
int8_t get_sdcard_open_file_num_max(void)
{
return SDCARD_OPEN_FILE_NUM_MAX;
}
int8_t get_sdcard_power_ctrl_gpio(void)
{
return SDCARD_PWR_CTRL;
}
// input-output pins
int8_t get_headphone_detect_gpio(void)
{
return HEADPHONE_DETECT;
}
int8_t get_pa_enable_gpio(void)
{
return PA_ENABLE_GPIO;
}
// adc button id
int8_t get_input_rec_id(void)
{
return -1;
}
int8_t get_input_mode_id(void)
{
return -1;
}
int8_t get_input_set_id(void)
{
return -1;
}
int8_t get_input_play_id(void)
{
return -1;
}
int8_t get_input_volup_id(void)
{
return -1;
}
int8_t get_input_voldown_id(void)
{
return -1;
}
// led pins
int8_t get_green_led_gpio(void)
{
return -1;
}
int8_t get_blue_led_gpio(void)
{
return -1;
}
int8_t get_es8311_mclk_src(void)
{
return -1;
}

View File

@ -0,0 +1,156 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "board.h"
#include "audio_mem.h"
#include "periph_adc_button.h"
static const char *TAG = "AUDIO_BOARD";
static audio_board_handle_t board_handle = NULL;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
ESP_LOGW(TAG, "The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle));
AUDIO_MEM_CHECK(TAG, board_handle, return NULL);
board_handle->audio_hal = audio_board_codec_init();
return board_handle;
}
audio_hal_handle_t audio_board_codec_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, codec_hal, return NULL);
return codec_hal;
}
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
esp_err_t ret = ESP_FAIL;
return ret;
}
display_service_handle_t audio_board_led_init(void)
{
// TODO
return NULL;
}
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0))
esp_err_t _get_lcd_io_bus (void *bus, esp_lcd_panel_io_spi_config_t *io_config,
esp_lcd_panel_io_handle_t *out_panel_io)
{
return esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)bus, io_config, out_panel_io);
}
void *audio_board_lcd_init(esp_periph_set_handle_t set, void *cb)
{
gpio_config_t bk_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = 1ULL << LCD_CTRL_GPIO
};
// Initialize the GPIO of backlight
ESP_ERROR_CHECK(gpio_config(&bk_gpio_config));
spi_bus_config_t buscfg = {
.sclk_io_num = LCD_CLK_GPIO,
.mosi_io_num = LCD_MOSI_GPIO,
.miso_io_num = -1,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 16 * LCD_H_RES * 2 + 8
};
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
esp_lcd_panel_io_spi_config_t io_config = {
.dc_gpio_num = LCD_DC_GPIO,
.cs_gpio_num = LCD_CS_GPIO,
.pclk_hz = 60 * 1000 * 1000,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.spi_mode = 0,
.trans_queue_depth = 10,
.on_color_trans_done = cb,
.user_ctx = NULL,
};
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = LCD_RST_GPIO,
.color_space = ESP_LCD_COLOR_SPACE_BGR,
.bits_per_pixel = 16,
};
periph_lcd_cfg_t cfg = {
.io_bus = (void *)SPI2_HOST,
.new_panel_io = _get_lcd_io_bus,
.lcd_io_cfg = &io_config,
.new_lcd_panel = esp_lcd_new_panel_st7789,
.lcd_dev_cfg = &panel_config,
.rest_cb = NULL,
.rest_cb_ctx = NULL,
.lcd_swap_xy = LCD_SWAP_XY,
.lcd_mirror_x = LCD_MIRROR_X,
.lcd_mirror_y = LCD_MIRROR_Y,
.lcd_color_invert = LCD_COLOR_INV,
};
esp_periph_handle_t periph_lcd = periph_lcd_init(&cfg);
AUDIO_NULL_CHECK(TAG, periph_lcd, return NULL);
esp_periph_start(set, periph_lcd);
return (void *)periph_lcd_get_panel_handle(periph_lcd);
}
#endif
esp_err_t audio_board_key_init(esp_periph_set_handle_t set)
{
periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG();
adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR();
adc_btn_tag.adc_ch = ADC1_CHANNEL_5;
adc_btn_tag.total_steps = 6;
int btn_array[7] = {190, 600, 1000, 1375, 1775, 2195, 2610};
adc_btn_tag.adc_level_step = btn_array;
adc_btn_cfg.arr = &adc_btn_tag;
adc_btn_cfg.arr_size = 1;
esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg);
AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK);
return esp_periph_start(set, adc_btn_handle);
}
audio_board_handle_t audio_board_get_handle(void)
{
return board_handle;
}
esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
{
esp_err_t ret = ESP_OK;
ret = audio_hal_deinit(audio_board->audio_hal);
audio_board->audio_hal = NULL;
audio_free(audio_board);
board_handle = NULL;
return ret;
}

View File

@ -0,0 +1,123 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_H_
#define _AUDIO_BOARD_H_
#include "audio_hal.h"
#include "board_def.h"
#include "board_pins_config.h"
#include "esp_peripherals.h"
#include "display_service.h"
#include "periph_sdcard.h"
#include "periph_lcd.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Audio board handle
*/
struct audio_board_handle {
audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */
};
typedef struct audio_board_handle *audio_board_handle_t;
/**
* @brief Initialize audio board
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_init(void);
/**
* @brief Initialize codec chip
*
* @return The audio hal handle
*/
audio_hal_handle_t audio_board_codec_init(void);
/**
* @brief Initialize led peripheral and display service
*
* @return The audio display service handle
*/
display_service_handle_t audio_board_led_init(void);
/**
* @brief Initialize lcd peripheral
*
* @param set The handle of esp_periph_set_handle_t
* @param cb The `on_color_trans_done` callback in `esp_lcd_panel_io_spi_config_t`
*
* @return The `esp_lcd_panel_handle_t` handle
*/
void *audio_board_lcd_init(esp_periph_set_handle_t set, void *cb);
/**
* @brief Initialize sdcard peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode);
/**
* @brief Initialize key peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_key_init(esp_periph_set_handle_t set);
/**
* @brief Query audio_board_handle
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_get_handle(void);
/**
* @brief Uninitialize the audio board
*
* @param audio_board The handle of audio board
*
* @return ESP_OK success,
* others fail
*/
esp_err_t audio_board_deinit(audio_board_handle_t audio_board);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,147 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_DEFINITION_H_
#define _AUDIO_BOARD_DEFINITION_H_
#include "driver/touch_pad.h"
/**
* @brief LED Function Definition
*/
#define FUNC_SYS_LEN_EN (1)
#define WS2812_LED_GPIO 45
/**
* @brief LCD SCREEN Function Definition
*/
#define FUNC_LCD_SCREEN_EN (1)
#define LCD_CTRL_GPIO GPIO_NUM_6
#define LCD_RST_GPIO GPIO_NUM_16
#define LCD_CS_GPIO GPIO_NUM_11
// LCD SPI Pins
#define LCD_DC_GPIO GPIO_NUM_13
#define LCD_CLK_GPIO GPIO_NUM_15
#define LCD_MOSI_GPIO GPIO_NUM_9
// The LCD pixel number in horizontal and vertical
#define LCD_H_RES 320
#define LCD_V_RES 240
#define LCD_SWAP_XY (true)
#define LCD_MIRROR_X (true)
#define LCD_MIRROR_Y (true)
#define LCD_COLOR_INV (false)
/**
* @brief SDCARD Function Definition
*/
#define FUNC_SDCARD_EN (0)
#define SDCARD_OPEN_FILE_NUM_MAX 5
#define SDCARD_INTR_GPIO -1
#define SDCARD_PWR_CTRL -1
#define ESP_SD_PIN_CLK -1
#define ESP_SD_PIN_CMD -1
#define ESP_SD_PIN_D0 -1
#define ESP_SD_PIN_D3 -1
/**
* @brief Audio Codec Chip Function Definition
*/
#define FUNC_AUDIO_CODEC_EN (1)
#define PA_ENABLE_GPIO (10)
#define ES8311_MCLK_SOURCE (1) /* 0 From MCLK, 1 From BCLK */
#define CODEC_ADC_I2S_PORT ((i2s_port_t)0)
#define CODEC_ADC_BITS_PER_SAMPLE ((i2s_data_bit_width_t)16) /* 16bit */
#define CODEC_ADC_SAMPLE_RATE (48000)
#define RECORD_HARDWARE_AEC (false)
#define BOARD_PA_GAIN (0) /* Power amplifier gain defined by board (dB) */
/**
* @brief ADC input data format
*/
#define AUDIO_ADC_INPUT_CH_FORMAT "MR"
extern audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE;
#define AUDIO_CODEC_DEFAULT_CONFIG(){ \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
.dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \
.codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \
.i2s_iface = { \
.mode = AUDIO_HAL_MODE_SLAVE, \
.fmt = AUDIO_HAL_I2S_NORMAL, \
.samples = AUDIO_HAL_48K_SAMPLES, \
.bits = AUDIO_HAL_BIT_LENGTH_16BITS, \
}, \
};
/**
* @brief Button Function Definition
*/
#define FUNC_BUTTON_EN (1)
#define BUTTON_ADC 6
#define INPUT_KEY_NUM 6
#define BUTTON_VOLUP_ID 0
#define BUTTON_VOLDOWN_ID 1
#define BUTTON_SET_ID 2
#define BUTTON_PLAY_ID 3
#define BUTTON_MODE_ID 4
#define BUTTON_REC_ID 5
#define GREEN_LED_GPIO (-1)
#define INPUT_KEY_DEFAULT_INFO() { \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_REC, \
.act_id = BUTTON_REC_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_MODE, \
.act_id = BUTTON_MODE_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_SET, \
.act_id = BUTTON_SET_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_PLAY, \
.act_id = BUTTON_PLAY_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLUP, \
.act_id = BUTTON_VOLUP_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLDOWN, \
.act_id = BUTTON_VOLDOWN_ID, \
} \
}
#endif

View File

@ -0,0 +1,152 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2020 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "driver/gpio.h"
#include <string.h>
#include "board.h"
#include "audio_error.h"
#include "audio_mem.h"
#include "soc/soc_caps.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
#include "rom/gpio.h"
#include "soc/gpio_sig_map.h"
#endif
static const char *TAG = "KALUGA_V1_2";
esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
{
AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL);
if (port == I2C_NUM_0) {
i2c_config->sda_io_num = GPIO_NUM_8;
i2c_config->scl_io_num = GPIO_NUM_7;
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
ESP_LOGE(TAG, "i2c port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config)
{
AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL);
i2s_config->bck_io_num = GPIO_NUM_18;
i2s_config->ws_io_num = GPIO_NUM_17;
i2s_config->data_out_num = GPIO_NUM_12;
i2s_config->data_in_num = GPIO_NUM_34;
i2s_config->mck_io_num = GPIO_NUM_35;
return ESP_OK;
}
esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config)
{
AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL);
AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL);
spi_config->mosi_io_num = -1;
spi_config->miso_io_num = -1;
spi_config->sclk_io_num = -1;
spi_config->quadwp_io_num = -1;
spi_config->quadhd_io_num = -1;
spi_device_interface_config->spics_io_num = -1;
ESP_LOGW(TAG, "SPI interface is not supported");
return ESP_OK;
}
// sdcard
int8_t get_sdcard_intr_gpio(void)
{
return SDCARD_INTR_GPIO;
}
int8_t get_sdcard_open_file_num_max(void)
{
return SDCARD_OPEN_FILE_NUM_MAX;
}
int8_t get_sdcard_power_ctrl_gpio(void)
{
return SDCARD_PWR_CTRL;
}
// input-output pins
int8_t get_pa_enable_gpio(void)
{
return PA_ENABLE_GPIO;
}
// adc button id
int8_t get_input_rec_id(void)
{
return BUTTON_REC_ID;
}
int8_t get_input_mode_id(void)
{
return BUTTON_MODE_ID;
}
int8_t get_input_set_id(void)
{
return BUTTON_SET_ID;
}
int8_t get_input_play_id(void)
{
return BUTTON_PLAY_ID;
}
int8_t get_input_volup_id(void)
{
return BUTTON_VOLUP_ID;
}
int8_t get_input_voldown_id(void)
{
return BUTTON_VOLDOWN_ID;
}
// led pins
int8_t get_ws2812_led_gpio(void)
{
return WS2812_LED_GPIO;
}
int8_t get_es8311_mclk_src(void)
{
return ES8311_MCLK_SOURCE;
}
// led pins
int8_t get_green_led_gpio(void)
{
return GREEN_LED_GPIO;
}

View File

@ -0,0 +1,196 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "board.h"
#include "audio_mem.h"
#include "esp_lcd_panel_ops.h"
#include "periph_sdcard.h"
#include "periph_lcd.h"
#include "periph_adc_button.h"
#include "tca9554.h"
static const char *TAG = "AUDIO_BOARD";
static audio_board_handle_t board_handle = 0;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
ESP_LOGW(TAG, "The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle));
AUDIO_MEM_CHECK(TAG, board_handle, return NULL);
board_handle->audio_hal = audio_board_codec_init();
board_handle->adc_hal = audio_board_adc_init();
return board_handle;
}
audio_hal_handle_t audio_board_adc_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_codec_cfg.codec_mode = AUDIO_HAL_CODEC_MODE_ENCODE;
audio_hal_handle_t adc_hal = NULL;
adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7210_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, adc_hal, return NULL);
return adc_hal;
}
audio_hal_handle_t audio_board_codec_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, codec_hal, return NULL);
return codec_hal;
}
esp_err_t _lcd_rest(esp_periph_handle_t self, void *ctx)
{
// Reset the LCD
vTaskDelay(20 / portTICK_PERIOD_MS);
return ESP_OK;
}
esp_err_t _get_lcd_io_bus (void *bus, esp_lcd_panel_io_spi_config_t *io_config,
esp_lcd_panel_io_handle_t *out_panel_io)
{
return esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)bus, io_config, out_panel_io);
}
void *audio_board_lcd_init(esp_periph_set_handle_t set, void *cb)
{
gpio_config_t bk_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
/*!< Prevent left shift negtive value warning */
.pin_bit_mask = LCD_CTRL_GPIO > 0 ? 1ULL << LCD_CTRL_GPIO : 0ULL,
};
gpio_config(&bk_gpio_config);
gpio_set_level(LCD_CTRL_GPIO, true);
spi_bus_config_t buscfg = {
.sclk_io_num = LCD_CLK_GPIO,
.mosi_io_num = LCD_MOSI_GPIO,
.miso_io_num = -1,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = LCD_V_RES * LCD_H_RES * 2
};
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
esp_lcd_panel_io_spi_config_t io_config = {
.dc_gpio_num = LCD_DC_GPIO,
.cs_gpio_num = LCD_CS_GPIO,
.pclk_hz = 10 * 1000 * 1000,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.spi_mode = 0,
.trans_queue_depth = 10,
.on_color_trans_done = cb,
.user_ctx = NULL,
};
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = LCD_RST_GPIO,
.color_space = LCD_COLOR_SPACE,
.bits_per_pixel = 16,
};
periph_lcd_cfg_t cfg = {
.io_bus = (void *)SPI2_HOST,
.new_panel_io = _get_lcd_io_bus,
.lcd_io_cfg = &io_config,
.new_lcd_panel = esp_lcd_new_panel_st7789,
.lcd_dev_cfg = &panel_config,
.rest_cb = NULL,
.rest_cb_ctx = NULL,
.lcd_swap_xy = LCD_SWAP_XY,
.lcd_mirror_x = LCD_MIRROR_X,
.lcd_mirror_y = LCD_MIRROR_Y,
.lcd_color_invert = LCD_COLOR_INV,
};
esp_periph_handle_t periph_lcd = periph_lcd_init(&cfg);
AUDIO_NULL_CHECK(TAG, periph_lcd, return NULL);
esp_periph_start(set, periph_lcd);
return (void *)periph_lcd_get_panel_handle(periph_lcd);
}
esp_err_t audio_board_key_init(esp_periph_set_handle_t set)
{
periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG();
adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR();
adc_btn_tag.total_steps = 3;
adc_btn_tag.adc_ch = ADC1_CHANNEL_0;
int btn_array[4] = {190, 1000, 2195, 3000};
adc_btn_tag.adc_level_step = btn_array;
adc_btn_cfg.arr = &adc_btn_tag;
adc_btn_cfg.arr_size = 1;
esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg);
AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK);
return esp_periph_start(set, adc_btn_handle);
}
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
if (mode != SD_MODE_1_LINE) {
ESP_LOGE(TAG, "Current board only support 1-line SD mode!");
return ESP_FAIL;
}
periph_sdcard_cfg_t sdcard_cfg = {
.root = "/sdcard",
.card_detect_pin = get_sdcard_intr_gpio(),
.mode = mode
};
esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg);
esp_err_t ret = esp_periph_start(set, sdcard_handle);
int retry_time = 5;
bool mount_flag = false;
while (retry_time --) {
if (periph_sdcard_is_mounted(sdcard_handle)) {
mount_flag = true;
break;
} else {
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
if (mount_flag == false) {
ESP_LOGE(TAG, "Sdcard mount failed");
return ESP_FAIL;
}
return ret;
}
audio_board_handle_t audio_board_get_handle(void)
{
return board_handle;
}
esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
{
esp_err_t ret = ESP_OK;
ret |= audio_hal_deinit(audio_board->audio_hal);
ret |= audio_hal_deinit(audio_board->adc_hal);
audio_free(audio_board);
board_handle = NULL;
return ret;
}

View File

@ -0,0 +1,131 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_H_
#define _AUDIO_BOARD_H_
#include "audio_hal.h"
#include "board_def.h"
#include "board_pins_config.h"
#include "esp_peripherals.h"
#include "display_service.h"
#include "periph_sdcard.h"
#include "periph_lcd.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Audio board handle
*/
struct audio_board_handle {
audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */
audio_hal_handle_t adc_hal; /*!< adc hardware abstract layer handle */
};
typedef struct audio_board_handle *audio_board_handle_t;
/**
* @brief Initialize audio board
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_init(void);
/**
* @brief Initialize codec chip
*
* @return The audio hal handle
*/
audio_hal_handle_t audio_board_codec_init(void);
/**
* @brief Initialize adc
*
* @return The adc hal handle
*/
audio_hal_handle_t audio_board_adc_init(void);
/**
* @brief Initialize lcd peripheral
*
* @param set The handle of esp_periph_set_handle_t
* @param cb The `on_color_trans_done` callback in `esp_lcd_panel_io_spi_config_t`
*
* @return The `esp_lcd_panel_handle_t` handle
*/
void *audio_board_lcd_init(esp_periph_set_handle_t set, void *cb);
/**
* @brief Initialize led peripheral and display service
*
* @return The audio display service handle
*/
display_service_handle_t audio_board_blue_led_init(void);
/**
* @brief Initialize key peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_key_init(esp_periph_set_handle_t set);
/**
* @brief Initialize sdcard peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode);
/**
* @brief Query audio_board_handle
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_get_handle(void);
/**
* @brief Uninitialize the audio board
*
* @param audio_board The handle of audio board
*
* @return 0 success,
* others fail
*/
esp_err_t audio_board_deinit(audio_board_handle_t audio_board);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,141 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_DEFINITION_H_
#define _AUDIO_BOARD_DEFINITION_H_
/**
* @brief LCD SCREEN Function Definition
*/
#define FUNC_LCD_SCREEN_EN (1)
#define LCD_CTRL_GPIO GPIO_NUM_45
#define LCD_RST_GPIO GPIO_NUM_48
#define LCD_DC_GPIO GPIO_NUM_4
#define LCD_CS_GPIO GPIO_NUM_5
#define LCD_CLK_GPIO GPIO_NUM_7
#define LCD_MOSI_GPIO GPIO_NUM_6
// The LCD pixel number in horizontal and vertical
#define LCD_H_RES 320
#define LCD_V_RES 240
#define LCD_SWAP_XY (false)
#define LCD_MIRROR_X (true)
#define LCD_MIRROR_Y (true)
#define LCD_COLOR_INV (false)
#define LCD_COLOR_SPACE ESP_LCD_COLOR_SPACE_BGR
/**
* @brief SDCARD Function Definition
* PMOD2 for one line sdcard
*/
#define FUNC_SDCARD_EN (1)
#define SDCARD_OPEN_FILE_NUM_MAX 5
#define SDCARD_INTR_GPIO -1
#define SDCARD_PWR_CTRL -1
#define ESP_SD_PIN_CLK GPIO_NUM_13
#define ESP_SD_PIN_CMD GPIO_NUM_11
#define ESP_SD_PIN_D0 GPIO_NUM_14
#define ESP_SD_PIN_D1 -1
#define ESP_SD_PIN_D2 -1
#define ESP_SD_PIN_D3 -1
#define ESP_SD_PIN_D4 -1
#define ESP_SD_PIN_D5 -1
#define ESP_SD_PIN_D6 -1
#define ESP_SD_PIN_D7 -1
#define ESP_SD_PIN_CD -1
#define ESP_SD_PIN_WP -1
/**
* @brief LCD TOUCH PANEL Function Definition
*/
#define FUNC_LCD_TOUCH_EN (1)
#define TOUCH_PANEL_SWAP_XY (0)
#define TOUCH_PANEL_INVERSE_X (1)
#define TOUCH_PANEL_INVERSE_Y (0)
/**
* @brief Audio Codec Chip Function Definition
*/
#define FUNC_AUDIO_CODEC_EN (1)
#define CODEC_ADC_I2S_PORT ((i2s_port_t)0)
#define CODEC_ADC_BITS_PER_SAMPLE ((i2s_data_bit_width_t)32) /* 32bit */
#define CODEC_ADC_SAMPLE_RATE (48000)
#define RECORD_HARDWARE_AEC (true)
#define BOARD_PA_GAIN (0) /* Power amplifier gain defined by board (dB) */
#define PA_ENABLE_GPIO GPIO_NUM_46
#define HEADPHONE_DETECT -1
#define ES7210_MIC_SELECT (ES7210_INPUT_MIC1 | ES7210_INPUT_MIC2 | ES7210_INPUT_MIC3)
/**
* @brief ADC input data format
*/
#define AUDIO_ADC_INPUT_CH_FORMAT "RMNM"
extern audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE;
extern audio_hal_func_t AUDIO_CODEC_ES7210_DEFAULT_HANDLE;
#define AUDIO_CODEC_DEFAULT_CONFIG(){ \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
.dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \
.codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \
.i2s_iface = { \
.mode = AUDIO_HAL_MODE_SLAVE, \
.fmt = AUDIO_HAL_I2S_NORMAL, \
.samples = AUDIO_HAL_48K_SAMPLES, \
.bits = AUDIO_HAL_BIT_LENGTH_16BITS, \
}, \
};
/**
* @brief Button Function Definition
*/
#define FUNC_BUTTON_EN (0)
#define INPUT_KEY_NUM 3
#define BUTTON_VOLUP_ID 0
#define BUTTON_VOLDOWN_ID 1
#define BUTTON_SET_ID 2
#define BUTTON_PLAY_ID 3
#define BUTTON_MODE_ID 4
#define BUTTON_REC_ID 5
#define INPUT_KEY_DEFAULT_INFO() { \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_SET, \
.act_id = BUTTON_SET_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLUP, \
.act_id = BUTTON_VOLUP_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLDOWN, \
.act_id = BUTTON_VOLDOWN_ID, \
} \
}
#endif

View File

@ -0,0 +1,172 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "driver/gpio.h"
#include <string.h>
#include "board.h"
#include "audio_error.h"
#include "audio_mem.h"
#include "soc/soc_caps.h"
static const char *TAG = "ESP32_S3_BOX";
esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
{
AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL);
if (port == I2C_NUM_0 || port == I2C_NUM_1) {
i2c_config->sda_io_num = GPIO_NUM_8;
i2c_config->scl_io_num = GPIO_NUM_18;
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
ESP_LOGE(TAG, "i2c port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config)
{
AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL);
if (port == 0) {
i2s_config->bck_io_num = GPIO_NUM_17;
i2s_config->ws_io_num = GPIO_NUM_47;
i2s_config->data_out_num = GPIO_NUM_15;
i2s_config->data_in_num = GPIO_NUM_16;
i2s_config->mck_io_num = GPIO_NUM_2;
} else if (port == 1) {
i2s_config->bck_io_num = -1;
i2s_config->ws_io_num = -1;
i2s_config->data_out_num = -1;
i2s_config->data_in_num = -1;
i2s_config->mck_io_num = -1;
} else {
memset(i2s_config, -1, sizeof(board_i2s_pin_t));
ESP_LOGE(TAG, "i2s port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config)
{
AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL);
AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL);
spi_config->mosi_io_num = -1;
spi_config->miso_io_num = -1;
spi_config->sclk_io_num = -1;
spi_config->quadwp_io_num = -1;
spi_config->quadhd_io_num = -1;
spi_device_interface_config->spics_io_num = -1;
ESP_LOGW(TAG, "SPI interface is not supported");
return ESP_OK;
}
// sdcard
int8_t get_sdcard_intr_gpio(void)
{
return SDCARD_INTR_GPIO;
}
int8_t get_sdcard_open_file_num_max(void)
{
return SDCARD_OPEN_FILE_NUM_MAX;
}
int8_t get_sdcard_power_ctrl_gpio(void)
{
return SDCARD_PWR_CTRL;
}
// input-output pins
int8_t get_headphone_detect_gpio(void)
{
return HEADPHONE_DETECT;
}
int8_t get_pa_enable_gpio(void)
{
return PA_ENABLE_GPIO;
}
int8_t get_es7243_mclk_gpio(void)
{
return GPIO_NUM_2;
}
// adc button id
int8_t get_input_rec_id(void)
{
return BUTTON_REC_ID;
}
int8_t get_input_mode_id(void)
{
return BUTTON_MODE_ID;
}
int8_t get_input_set_id(void)
{
return BUTTON_SET_ID;
}
int8_t get_input_play_id(void)
{
return BUTTON_PLAY_ID;
}
int8_t get_input_volup_id(void)
{
return BUTTON_VOLUP_ID;
}
int8_t get_input_voldown_id(void)
{
return BUTTON_VOLDOWN_ID;
}
// led pins
int8_t get_green_led_gpio(void)
{
return -1;
}
int8_t get_blue_led_gpio(void)
{
return -1;
}
int8_t get_es8311_mclk_src(void)
{
return -1;
}

View File

@ -0,0 +1,199 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2023 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "esp_lcd_panel_ops.h"
#include "audio_mem.h"
#include "periph_sdcard.h"
#include "periph_lcd.h"
#include "periph_button.h"
#include "tca9554.h"
#include "board.h"
static const char *TAG = "AUDIO_BOARD";
static audio_board_handle_t board_handle = 0;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
ESP_LOGW(TAG, "The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle));
AUDIO_MEM_CHECK(TAG, board_handle, return NULL);
board_handle->audio_hal = audio_board_codec_init();
board_handle->adc_hal = audio_board_adc_init();
return board_handle;
}
audio_hal_handle_t audio_board_adc_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_codec_cfg.codec_mode = AUDIO_HAL_CODEC_MODE_ENCODE;
audio_hal_handle_t adc_hal = NULL;
adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7210_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, adc_hal, return NULL);
return adc_hal;
}
audio_hal_handle_t audio_board_codec_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, codec_hal, return NULL);
return codec_hal;
}
static esp_err_t _get_lcd_io_bus (void *bus, esp_lcd_panel_io_spi_config_t *io_config,
esp_lcd_panel_io_handle_t *out_panel_io)
{
return esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)bus, io_config, out_panel_io);
}
void *audio_board_lcd_init(esp_periph_set_handle_t set, void *cb)
{
if (LCD_CTRL_GPIO >=0) {
gpio_config_t bk_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = 1ULL << LCD_CTRL_GPIO
};
gpio_config(&bk_gpio_config);
gpio_set_level(LCD_CTRL_GPIO, true);
}
spi_bus_config_t buscfg = {
.sclk_io_num = LCD_CLK_GPIO,
.mosi_io_num = LCD_MOSI_GPIO,
.miso_io_num = -1,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = LCD_V_RES * LCD_H_RES * 2
};
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
esp_lcd_panel_io_spi_config_t io_config = {
.dc_gpio_num = LCD_DC_GPIO,
.cs_gpio_num = LCD_CS_GPIO,
.pclk_hz = 10 * 1000 * 1000,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.spi_mode = 0,
.trans_queue_depth = 10,
.on_color_trans_done = cb,
.user_ctx = NULL
};
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = LCD_RST_GPIO,
.flags.reset_active_high = 1,
.color_space = LCD_COLOR_SPACE,
.bits_per_pixel = 16
};
periph_lcd_cfg_t cfg = {
.io_bus = (void *)SPI2_HOST,
.new_panel_io = _get_lcd_io_bus,
.lcd_io_cfg = &io_config,
.new_lcd_panel = esp_lcd_new_panel_st7789,
.lcd_dev_cfg = &panel_config,
.rest_cb = NULL,
.rest_cb_ctx = NULL,
.lcd_swap_xy = LCD_SWAP_XY,
.lcd_mirror_x = LCD_MIRROR_X,
.lcd_mirror_y = LCD_MIRROR_Y,
.lcd_color_invert = LCD_COLOR_INV
};
esp_periph_handle_t periph_lcd = periph_lcd_init(&cfg);
AUDIO_NULL_CHECK(TAG, periph_lcd, return NULL);
esp_periph_start(set, periph_lcd);
return (void *)periph_lcd_get_panel_handle(periph_lcd);
}
esp_err_t audio_board_key_init(esp_periph_set_handle_t set)
{
periph_button_cfg_t btn_cfg = {
.gpio_mask = (1ULL << get_input_rec_id()) | (1ULL << get_input_play_id()), //REC BTN & PLAY BTN
};
esp_periph_handle_t button_handle = periph_button_init(&btn_cfg);
AUDIO_NULL_CHECK(TAG, button_handle, return ESP_ERR_ADF_MEMORY_LACK);
return esp_periph_start(set, button_handle);
}
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
if (mode != SD_MODE_1_LINE && mode != SD_MODE_4_LINE) {
ESP_LOGE(TAG, "Current board only support 1-line and 4-line SD mode!");
return ESP_FAIL;
}
periph_sdcard_cfg_t sdcard_cfg = {
.root = "/sdcard",
.card_detect_pin = get_sdcard_intr_gpio(),
.mode = mode
};
// Enable SDCard power
if (get_sdcard_power_ctrl_gpio() >= 0) {
gpio_config_t gpio_cfg = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = 1ULL << get_sdcard_power_ctrl_gpio()
};
gpio_config(&gpio_cfg);
gpio_set_level(get_sdcard_power_ctrl_gpio(), 0);
}
esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg);
esp_err_t ret = esp_periph_start(set, sdcard_handle);
int retry_time = 5;
bool mount_flag = false;
while (retry_time --) {
if (periph_sdcard_is_mounted(sdcard_handle)) {
mount_flag = true;
break;
} else {
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
if (mount_flag == false) {
ESP_LOGE(TAG, "Sdcard mount failed");
return ESP_FAIL;
}
return ret;
}
audio_board_handle_t audio_board_get_handle(void)
{
return board_handle;
}
esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
{
AUDIO_NULL_CHECK(TAG, audio_board, return ESP_FAIL);
esp_err_t ret = ESP_OK;
ret |= audio_hal_deinit(audio_board->audio_hal);
ret |= audio_hal_deinit(audio_board->adc_hal);
audio_free(audio_board);
board_handle = NULL;
return ret;
}

View File

@ -0,0 +1,131 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2023 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_H_
#define _AUDIO_BOARD_H_
#include "audio_hal.h"
#include "board_def.h"
#include "board_pins_config.h"
#include "esp_peripherals.h"
#include "display_service.h"
#include "periph_sdcard.h"
#include "periph_lcd.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Audio board handle
*/
struct audio_board_handle {
audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */
audio_hal_handle_t adc_hal; /*!< adc hardware abstract layer handle */
};
typedef struct audio_board_handle *audio_board_handle_t;
/**
* @brief Initialize audio board
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_init(void);
/**
* @brief Initialize codec chip
*
* @return The audio hal handle
*/
audio_hal_handle_t audio_board_codec_init(void);
/**
* @brief Initialize adc
*
* @return The adc hal handle
*/
audio_hal_handle_t audio_board_adc_init(void);
/**
* @brief Initialize lcd peripheral
*
* @param set The handle of esp_periph_set_handle_t
* @param cb The `on_color_trans_done` callback in `esp_lcd_panel_io_spi_config_t`
*
* @return The `esp_lcd_panel_handle_t` handle
*/
void *audio_board_lcd_init(esp_periph_set_handle_t set, void *cb);
/**
* @brief Initialize led peripheral and display service
*
* @return The audio display service handle
*/
display_service_handle_t audio_board_blue_led_init(void);
/**
* @brief Initialize key peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_key_init(esp_periph_set_handle_t set);
/**
* @brief Initialize sdcard peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode);
/**
* @brief Query audio_board_handle
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_get_handle(void);
/**
* @brief Uninitialize the audio board
*
* @param audio_board The handle of audio board
*
* @return 0 success,
* others fail
*/
esp_err_t audio_board_deinit(audio_board_handle_t audio_board);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,131 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2023 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_DEFINITION_H_
#define _AUDIO_BOARD_DEFINITION_H_
/**
* @brief LCD SCREEN Function Definition
*/
#define FUNC_LCD_SCREEN_EN (1)
#define LCD_CTRL_GPIO GPIO_NUM_47
#define LCD_RST_GPIO GPIO_NUM_48
#define LCD_DC_GPIO GPIO_NUM_4
#define LCD_CS_GPIO GPIO_NUM_5
#define LCD_CLK_GPIO GPIO_NUM_7
#define LCD_MOSI_GPIO GPIO_NUM_6
// The LCD pixel number in horizontal and vertical
#define LCD_H_RES (320)
#define LCD_V_RES (240)
#define LCD_SWAP_XY (false)
#define LCD_MIRROR_X (true)
#define LCD_MIRROR_Y (true)
#define LCD_COLOR_INV (false)
#define LCD_COLOR_SPACE ESP_LCD_COLOR_SPACE_BGR
/**
* @brief SDCARD Function Definition
*/
#define FUNC_SDCARD_EN (1)
#define SDCARD_OPEN_FILE_NUM_MAX (5)
#define SDCARD_INTR_GPIO (-1)
#define SDCARD_PWR_CTRL GPIO_NUM_43
#define ESP_SD_PIN_CLK GPIO_NUM_11
#define ESP_SD_PIN_CMD GPIO_NUM_14
#define ESP_SD_PIN_D0 GPIO_NUM_9
#define ESP_SD_PIN_D1 GPIO_NUM_13
#define ESP_SD_PIN_D2 GPIO_NUM_42
#define ESP_SD_PIN_D3 GPIO_NUM_12
#define ESP_SD_PIN_D4 (-1)
#define ESP_SD_PIN_D5 (-1)
#define ESP_SD_PIN_D6 (-1)
#define ESP_SD_PIN_D7 (-1)
#define ESP_SD_PIN_CD (-1)
#define ESP_SD_PIN_WP (-1)
/**
* @brief LCD TOUCH PANEL Function Definition
*/
#define FUNC_LCD_TOUCH_EN (1)
#define TOUCH_PANEL_SWAP_XY (0)
#define TOUCH_PANEL_INVERSE_X (1)
#define TOUCH_PANEL_INVERSE_Y (0)
/**
* @brief Audio Codec Chip Function Definition
*/
#define FUNC_AUDIO_CODEC_EN (1)
#define CODEC_ADC_I2S_PORT ((i2s_port_t)0)
#define CODEC_ADC_BITS_PER_SAMPLE ((i2s_data_bit_width_t)32) /* 32bit */
#define CODEC_ADC_SAMPLE_RATE (48000)
#define RECORD_HARDWARE_AEC (true)
#define BOARD_PA_GAIN (0) /* Power amplifier gain defined by board (dB) */
#define PA_ENABLE_GPIO GPIO_NUM_46
#define HEADPHONE_DETECT (-1)
#define ES7210_MIC_SELECT (ES7210_INPUT_MIC1 | ES7210_INPUT_MIC2 | ES7210_INPUT_MIC3)
/**
* @brief ADC input data format
*/
#define AUDIO_ADC_INPUT_CH_FORMAT "RMNM"
extern audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE;
extern audio_hal_func_t AUDIO_CODEC_ES7210_DEFAULT_HANDLE;
#define AUDIO_CODEC_DEFAULT_CONFIG(){ \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
.dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \
.codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \
.i2s_iface = { \
.mode = AUDIO_HAL_MODE_SLAVE, \
.fmt = AUDIO_HAL_I2S_NORMAL, \
.samples = AUDIO_HAL_48K_SAMPLES, \
.bits = AUDIO_HAL_BIT_LENGTH_16BITS, \
}, \
};
/**
* @brief Button Function Definition
*/
#define FUNC_BUTTON_EN (1)
#define INPUT_KEY_NUM (2)
#define BUTTON_VOLUP_ID (-1)
#define BUTTON_VOLDOWN_ID (-1)
#define BUTTON_SET_ID (-1)
#define BUTTON_PLAY_ID (0)
#define BUTTON_MODE_ID (-1)
#define BUTTON_REC_ID (1)
#define INPUT_KEY_DEFAULT_INFO() { \
{ \
.type = PERIPH_ID_BUTTON, \
.user_id = INPUT_KEY_USER_ID_REC, \
.act_id = BUTTON_REC_ID, \
}, \
{ \
.type = PERIPH_ID_BUTTON, \
.user_id = INPUT_KEY_USER_ID_PLAY, \
.act_id = BUTTON_PLAY_ID, \
} \
}
#endif

View File

@ -0,0 +1,161 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2023 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <string.h>
#include "soc/soc_caps.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "audio_error.h"
#include "audio_mem.h"
#include "board.h"
static const char *TAG = "ESP32_S3_BOX_3";
esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
{
AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL);
if (port == I2C_NUM_0 || port == I2C_NUM_1) {
i2c_config->sda_io_num = GPIO_NUM_8;
i2c_config->scl_io_num = GPIO_NUM_18;
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
ESP_LOGE(TAG, "i2c port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config)
{
AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL);
if (port == 0) {
i2s_config->bck_io_num = GPIO_NUM_17;
i2s_config->ws_io_num = GPIO_NUM_45;
i2s_config->data_out_num = GPIO_NUM_15;
i2s_config->data_in_num = GPIO_NUM_16;
i2s_config->mck_io_num = GPIO_NUM_2;
} else {
memset(i2s_config, -1, sizeof(board_i2s_pin_t));
ESP_LOGE(TAG, "I2S PORT %d is not supported, please use I2S PORT 0", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config)
{
AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL);
AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL);
spi_config->mosi_io_num = -1;
spi_config->miso_io_num = -1;
spi_config->sclk_io_num = -1;
spi_config->quadwp_io_num = -1;
spi_config->quadhd_io_num = -1;
spi_device_interface_config->spics_io_num = -1;
ESP_LOGW(TAG, "SPI interface is not supported");
return ESP_OK;
}
// sdcard
int8_t get_sdcard_intr_gpio(void)
{
return SDCARD_INTR_GPIO;
}
int8_t get_sdcard_open_file_num_max(void)
{
return SDCARD_OPEN_FILE_NUM_MAX;
}
int8_t get_sdcard_power_ctrl_gpio(void)
{
return SDCARD_PWR_CTRL;
}
// input-output pins
int8_t get_headphone_detect_gpio(void)
{
return HEADPHONE_DETECT;
}
int8_t get_pa_enable_gpio(void)
{
return PA_ENABLE_GPIO;
}
// adc button id
int8_t get_input_rec_id(void)
{
return BUTTON_REC_ID;
}
int8_t get_input_mode_id(void)
{
return BUTTON_MODE_ID;
}
int8_t get_input_set_id(void)
{
return BUTTON_SET_ID;
}
int8_t get_input_play_id(void)
{
return BUTTON_PLAY_ID;
}
int8_t get_input_volup_id(void)
{
return BUTTON_VOLUP_ID;
}
int8_t get_input_voldown_id(void)
{
return BUTTON_VOLDOWN_ID;
}
// led pins
int8_t get_green_led_gpio(void)
{
return -1;
}
int8_t get_blue_led_gpio(void)
{
return -1;
}
int8_t get_es8311_mclk_src(void)
{
return -1;
}

View File

@ -0,0 +1,196 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "board.h"
#include "audio_mem.h"
#include "esp_lcd_panel_ops.h"
#include "periph_sdcard.h"
#include "periph_lcd.h"
#include "periph_adc_button.h"
#include "tca9554.h"
static const char *TAG = "AUDIO_BOARD";
static audio_board_handle_t board_handle = 0;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
ESP_LOGW(TAG, "The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle));
AUDIO_MEM_CHECK(TAG, board_handle, return NULL);
board_handle->audio_hal = audio_board_codec_init();
board_handle->adc_hal = audio_board_adc_init();
return board_handle;
}
audio_hal_handle_t audio_board_adc_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_codec_cfg.codec_mode = AUDIO_HAL_CODEC_MODE_ENCODE;
audio_hal_handle_t adc_hal = NULL;
adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7243E_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, adc_hal, return NULL);
return adc_hal;
}
audio_hal_handle_t audio_board_codec_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8156_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, codec_hal, return NULL);
return codec_hal;
}
esp_err_t _lcd_rest(esp_periph_handle_t self, void *ctx)
{
// Reset the LCD
vTaskDelay(200 / portTICK_PERIOD_MS);
return ESP_OK;
}
esp_err_t _get_lcd_io_bus (void *bus, esp_lcd_panel_io_spi_config_t *io_config,
esp_lcd_panel_io_handle_t *out_panel_io)
{
return esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)bus, io_config, out_panel_io);
}
void *audio_board_lcd_init(esp_periph_set_handle_t set, void *cb)
{
gpio_config_t bk_gpio_config = {
.mode = GPIO_MODE_OUTPUT,
/*!< Prevent left shift negtive value warning */
.pin_bit_mask = LCD_CTRL_GPIO > 0 ? 1ULL << LCD_CTRL_GPIO : 0ULL,
};
gpio_config(&bk_gpio_config);
gpio_set_level(LCD_CTRL_GPIO, false);
spi_bus_config_t buscfg = {
.sclk_io_num = LCD_CLK_GPIO,
.mosi_io_num = LCD_MOSI_GPIO,
.miso_io_num = -1,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 16 * LCD_H_RES * 2 + 8
};
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
esp_lcd_panel_io_spi_config_t io_config = {
.dc_gpio_num = LCD_DC_GPIO,
.cs_gpio_num = LCD_CS_GPIO,
.pclk_hz = 10 * 1000 * 1000,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.spi_mode = 0,
.trans_queue_depth = 10,
.on_color_trans_done = cb,
.user_ctx = NULL,
};
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = LCD_RST_GPIO,
.color_space = LCD_COLOR_SPACE,
.bits_per_pixel = 16,
};
periph_lcd_cfg_t cfg = {
.io_bus = (void *)SPI2_HOST,
.new_panel_io = _get_lcd_io_bus,
.lcd_io_cfg = &io_config,
.new_lcd_panel = esp_lcd_new_panel_st7789,
.lcd_dev_cfg = &panel_config,
.rest_cb = NULL,
.rest_cb_ctx = NULL,
.lcd_swap_xy = LCD_SWAP_XY,
.lcd_mirror_x = LCD_MIRROR_X,
.lcd_mirror_y = LCD_MIRROR_Y,
.lcd_color_invert = LCD_COLOR_INV,
};
esp_periph_handle_t periph_lcd = periph_lcd_init(&cfg);
AUDIO_NULL_CHECK(TAG, periph_lcd, return NULL);
esp_periph_start(set, periph_lcd);
return (void *)periph_lcd_get_panel_handle(periph_lcd);
}
esp_err_t audio_board_key_init(esp_periph_set_handle_t set)
{
periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG();
adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR();
adc_btn_tag.total_steps = 3;
adc_btn_tag.adc_ch = ADC1_CHANNEL_0;
int btn_array[4] = {190, 1000, 2195, 3000};
adc_btn_tag.adc_level_step = btn_array;
adc_btn_cfg.arr = &adc_btn_tag;
adc_btn_cfg.arr_size = 1;
esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg);
AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK);
return esp_periph_start(set, adc_btn_handle);
}
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
if (mode != SD_MODE_1_LINE) {
ESP_LOGE(TAG, "Current board only support 1-line SD mode!");
return ESP_FAIL;
}
periph_sdcard_cfg_t sdcard_cfg = {
.root = "/sdcard",
.card_detect_pin = get_sdcard_intr_gpio(),
.mode = mode
};
esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg);
esp_err_t ret = esp_periph_start(set, sdcard_handle);
int retry_time = 5;
bool mount_flag = false;
while (retry_time --) {
if (periph_sdcard_is_mounted(sdcard_handle)) {
mount_flag = true;
break;
} else {
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
if (mount_flag == false) {
ESP_LOGE(TAG, "Sdcard mount failed");
return ESP_FAIL;
}
return ret;
}
audio_board_handle_t audio_board_get_handle(void)
{
return board_handle;
}
esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
{
esp_err_t ret = ESP_OK;
ret |= audio_hal_deinit(audio_board->audio_hal);
ret |= audio_hal_deinit(audio_board->adc_hal);
audio_free(audio_board);
board_handle = NULL;
return ret;
}

View File

@ -0,0 +1,131 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_H_
#define _AUDIO_BOARD_H_
#include "audio_hal.h"
#include "board_def.h"
#include "board_pins_config.h"
#include "esp_peripherals.h"
#include "display_service.h"
#include "periph_sdcard.h"
#include "periph_lcd.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Audio board handle
*/
struct audio_board_handle {
audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */
audio_hal_handle_t adc_hal; /*!< adc hardware abstract layer handle */
};
typedef struct audio_board_handle *audio_board_handle_t;
/**
* @brief Initialize audio board
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_init(void);
/**
* @brief Initialize codec chip
*
* @return The audio hal handle
*/
audio_hal_handle_t audio_board_codec_init(void);
/**
* @brief Initialize adc
*
* @return The adc hal handle
*/
audio_hal_handle_t audio_board_adc_init(void);
/**
* @brief Initialize lcd peripheral
*
* @param set The handle of esp_periph_set_handle_t
* @param cb The `on_color_trans_done` callback in `esp_lcd_panel_io_spi_config_t`
*
* @return The `esp_lcd_panel_handle_t` handle
*/
void *audio_board_lcd_init(esp_periph_set_handle_t set, void *cb);
/**
* @brief Initialize led peripheral and display service
*
* @return The audio display service handle
*/
display_service_handle_t audio_board_blue_led_init(void);
/**
* @brief Initialize key peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_key_init(esp_periph_set_handle_t set);
/**
* @brief Initialize sdcard peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode);
/**
* @brief Query audio_board_handle
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_get_handle(void);
/**
* @brief Uninitialize the audio board
*
* @param audio_board The handle of audio board
*
* @return 0 success,
* others fail
*/
esp_err_t audio_board_deinit(audio_board_handle_t audio_board);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,131 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_DEFINITION_H_
#define _AUDIO_BOARD_DEFINITION_H_
/**
* @brief LCD SCREEN Function Definition
*/
#define FUNC_LCD_SCREEN_EN (1)
#define LCD_CTRL_GPIO GPIO_NUM_45
#define LCD_RST_GPIO GPIO_NUM_48
#define LCD_DC_GPIO GPIO_NUM_4
#define LCD_CS_GPIO GPIO_NUM_5
#define LCD_MOSI_GPIO GPIO_NUM_6
#define LCD_CLK_GPIO GPIO_NUM_7
// The LCD pixel number in horizontal and vertical
#define LCD_H_RES 320
#define LCD_V_RES 240
#define LCD_SWAP_XY (true)
#define LCD_MIRROR_X (false)
#define LCD_MIRROR_Y (true)
#define LCD_COLOR_INV (true)
#define LCD_COLOR_SPACE ESP_LCD_COLOR_SPACE_RGB
/**
* @brief SDCARD Function Definition
* PMOD2 for one line sdcard
*/
#define FUNC_SDCARD_EN (1)
#define SDCARD_OPEN_FILE_NUM_MAX 5
#define SDCARD_INTR_GPIO -1
#define SDCARD_PWR_CTRL -1
#define ESP_SD_PIN_CLK GPIO_NUM_13
#define ESP_SD_PIN_CMD GPIO_NUM_11
#define ESP_SD_PIN_D0 GPIO_NUM_14
#define ESP_SD_PIN_D1 -1
#define ESP_SD_PIN_D2 -1
#define ESP_SD_PIN_D3 -1
#define ESP_SD_PIN_D4 -1
#define ESP_SD_PIN_D5 -1
#define ESP_SD_PIN_D6 -1
#define ESP_SD_PIN_D7 -1
#define ESP_SD_PIN_CD -1
#define ESP_SD_PIN_WP -1
/**
* @brief Audio Codec Chip Function Definition
*/
#define FUNC_AUDIO_CODEC_EN (1)
#define HEADPHONE_DETECT -1
#define PA_ENABLE_GPIO GPIO_NUM_46
#define CODEC_ADC_I2S_PORT ((i2s_port_t)0)
#define CODEC_ADC_BITS_PER_SAMPLE ((i2s_data_bit_width_t)I2S_BITS_PER_SAMPLE_32BIT)
#define CODEC_ADC_SAMPLE_RATE (48000)
#define RECORD_HARDWARE_AEC (false)
#define BOARD_PA_GAIN (0) /* Power amplifier gain defined by board (dB) */
extern audio_hal_func_t AUDIO_CODEC_ES8156_DEFAULT_HANDLE;
extern audio_hal_func_t AUDIO_CODEC_ES7243E_DEFAULT_HANDLE;
/**
* @brief ADC input data format
*/
#define AUDIO_ADC_INPUT_CH_FORMAT "N"
#define AUDIO_CODEC_DEFAULT_CONFIG(){ \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
.dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \
.codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \
.i2s_iface = { \
.mode = AUDIO_HAL_MODE_SLAVE, \
.fmt = AUDIO_HAL_I2S_NORMAL, \
.samples = AUDIO_HAL_48K_SAMPLES, \
.bits = AUDIO_HAL_BIT_LENGTH_16BITS, \
}, \
};
/**
* @brief Button Function Definition
*/
#define INPUT_KEY_NUM 3
#define BUTTON_VOLUP_ID 0
#define BUTTON_VOLDOWN_ID 1
#define BUTTON_SET_ID 2
#define BUTTON_PLAY_ID 3
#define BUTTON_MODE_ID 4
#define BUTTON_REC_ID 5
#define INPUT_KEY_DEFAULT_INFO() { \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_SET, \
.act_id = BUTTON_SET_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLUP, \
.act_id = BUTTON_VOLUP_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLDOWN, \
.act_id = BUTTON_VOLDOWN_ID, \
} \
}
#endif

View File

@ -0,0 +1,172 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "driver/gpio.h"
#include <string.h>
#include "board.h"
#include "audio_error.h"
#include "audio_mem.h"
#include "soc/soc_caps.h"
static const char *TAG = "ESP32_S3_BOX_LITE";
esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
{
AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL);
if (port == I2C_NUM_0 || port == I2C_NUM_1) {
i2c_config->sda_io_num = GPIO_NUM_8;
i2c_config->scl_io_num = GPIO_NUM_18;
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
ESP_LOGE(TAG, "i2c port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config)
{
AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL);
if (port == 0) {
i2s_config->bck_io_num = GPIO_NUM_17;
i2s_config->ws_io_num = GPIO_NUM_47;
i2s_config->data_out_num = GPIO_NUM_15;
i2s_config->data_in_num = GPIO_NUM_16;
i2s_config->mck_io_num = GPIO_NUM_2;
} else if (port == 1) {
i2s_config->bck_io_num = -1;
i2s_config->ws_io_num = -1;
i2s_config->data_out_num = -1;
i2s_config->data_in_num = -1;
i2s_config->mck_io_num = -1;
} else {
memset(i2s_config, -1, sizeof(board_i2s_pin_t));
ESP_LOGE(TAG, "i2s port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config)
{
AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL);
AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL);
spi_config->mosi_io_num = -1;
spi_config->miso_io_num = -1;
spi_config->sclk_io_num = -1;
spi_config->quadwp_io_num = -1;
spi_config->quadhd_io_num = -1;
spi_device_interface_config->spics_io_num = -1;
ESP_LOGW(TAG, "SPI interface is not supported");
return ESP_OK;
}
// sdcard
int8_t get_sdcard_intr_gpio(void)
{
return SDCARD_INTR_GPIO;
}
int8_t get_sdcard_open_file_num_max(void)
{
return SDCARD_OPEN_FILE_NUM_MAX;
}
int8_t get_sdcard_power_ctrl_gpio(void)
{
return SDCARD_PWR_CTRL;
}
// input-output pins
int8_t get_headphone_detect_gpio(void)
{
return HEADPHONE_DETECT;
}
int8_t get_pa_enable_gpio(void)
{
return PA_ENABLE_GPIO;
}
int8_t get_es7243_mclk_gpio(void)
{
return GPIO_NUM_2;
}
// adc button id
int8_t get_input_rec_id(void)
{
return BUTTON_REC_ID;
}
int8_t get_input_mode_id(void)
{
return BUTTON_MODE_ID;
}
int8_t get_input_set_id(void)
{
return BUTTON_SET_ID;
}
int8_t get_input_play_id(void)
{
return BUTTON_PLAY_ID;
}
int8_t get_input_volup_id(void)
{
return BUTTON_VOLUP_ID;
}
int8_t get_input_voldown_id(void)
{
return BUTTON_VOLDOWN_ID;
}
// led pins
int8_t get_green_led_gpio(void)
{
return -1;
}
int8_t get_blue_led_gpio(void)
{
return -1;
}
int8_t get_es8311_mclk_src(void)
{
return -1;
}

View File

@ -0,0 +1,215 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "board.h"
#include "audio_mem.h"
#include "periph_sdcard.h"
#include "periph_adc_button.h"
#include "tca9554.h"
static const char *TAG = "AUDIO_BOARD";
static audio_board_handle_t board_handle = 0;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
ESP_LOGW(TAG, "The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle));
AUDIO_MEM_CHECK(TAG, board_handle, return NULL);
board_handle->audio_hal = audio_board_codec_init();
board_handle->adc_hal = audio_board_adc_init();
return board_handle;
}
audio_hal_handle_t audio_board_adc_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_codec_cfg.codec_mode = AUDIO_HAL_CODEC_MODE_ENCODE;
audio_hal_handle_t adc_hal = NULL;
adc_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES7210_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, adc_hal, return NULL);
return adc_hal;
}
audio_hal_handle_t audio_board_codec_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, codec_hal, return NULL);
return codec_hal;
}
esp_err_t _lcd_rest(esp_periph_handle_t self, void *ctx)
{
// Reset the LCD
tca9554_set_output_state(LCD_RST_GPIO, TCA9554_IO_LOW);
vTaskDelay(100 / portTICK_PERIOD_MS);
tca9554_set_output_state(LCD_RST_GPIO, TCA9554_IO_HIGH);
vTaskDelay(200 / portTICK_PERIOD_MS);
return ESP_OK;
}
esp_err_t _get_lcd_io_bus (void *bus, esp_lcd_panel_io_spi_config_t *io_config,
esp_lcd_panel_io_handle_t *out_panel_io)
{
return esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)bus, io_config, out_panel_io);
}
display_service_handle_t audio_board_led_init(void)
{
return NULL;
}
void *audio_board_lcd_init(esp_periph_set_handle_t set, void *cb)
{
esp_tca9554_config_t pca_cfg = {
.i2c_scl = GPIO_NUM_18,
.i2c_sda = GPIO_NUM_17,
.interrupt_output = -1,
};
tca9554_init(&pca_cfg);
// Set LCD_BL_CTRL output
tca9554_set_io_config(LCD_CTRL_GPIO, TCA9554_IO_OUTPUT);
// Set LCD_RST output
tca9554_set_io_config(LCD_RST_GPIO, TCA9554_IO_OUTPUT);
// Set LCD_CS pin output
tca9554_set_io_config(LCD_CS_GPIO, TCA9554_IO_OUTPUT);
tca9554_set_output_state(LCD_CTRL_GPIO, TCA9554_IO_HIGH);
tca9554_set_output_state(LCD_CS_GPIO, TCA9554_IO_HIGH);
vTaskDelay(10 / portTICK_PERIOD_MS);
tca9554_set_output_state(LCD_CS_GPIO, TCA9554_IO_LOW);
vTaskDelay(10 / portTICK_PERIOD_MS);
spi_bus_config_t buscfg = {
.sclk_io_num = LCD_CLK_GPIO,
.mosi_io_num = LCD_MOSI_GPIO,
.miso_io_num = -1,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = LCD_V_RES * LCD_H_RES * 2
};
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
esp_lcd_panel_io_spi_config_t io_config = {
.dc_gpio_num = LCD_DC_GPIO,
.cs_gpio_num = -1,
.pclk_hz = 60 * 1000 * 1000,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.spi_mode = 0,
.trans_queue_depth = 10,
.on_color_trans_done = cb,
.user_ctx = NULL,
};
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = -1,
.color_space = ESP_LCD_COLOR_SPACE_BGR,
.bits_per_pixel = 16,
};
periph_lcd_cfg_t cfg = {
.io_bus = (void *)SPI2_HOST,
.new_panel_io = _get_lcd_io_bus,
.lcd_io_cfg = &io_config,
.new_lcd_panel = esp_lcd_new_panel_st7789,
.lcd_dev_cfg = &panel_config,
.rest_cb = _lcd_rest,
.rest_cb_ctx = NULL,
.lcd_swap_xy = LCD_SWAP_XY,
.lcd_mirror_x = LCD_MIRROR_X,
.lcd_mirror_y = LCD_MIRROR_Y,
.lcd_color_invert = LCD_COLOR_INV,
};
esp_periph_handle_t periph_lcd = periph_lcd_init(&cfg);
AUDIO_NULL_CHECK(TAG, periph_lcd, return NULL);
esp_periph_start(set, periph_lcd);
return (void *)periph_lcd_get_panel_handle(periph_lcd);
}
esp_err_t audio_board_key_init(esp_periph_set_handle_t set)
{
periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG();
adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR();
adc_btn_tag.total_steps = 6;
adc_btn_tag.adc_ch = ADC1_CHANNEL_4;
int btn_array[7] = {190, 600, 1000, 1375, 1775, 2195, 3000};
adc_btn_tag.adc_level_step = btn_array;
adc_btn_cfg.arr = &adc_btn_tag;
adc_btn_cfg.arr_size = 1;
if (audio_mem_spiram_stack_is_enabled()) {
adc_btn_cfg.task_cfg.ext_stack = true;
}
esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg);
AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK);
return esp_periph_start(set, adc_btn_handle);
}
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
if (mode != SD_MODE_1_LINE) {
ESP_LOGE(TAG, "Current board only support 1-line SD mode!");
return ESP_FAIL;
}
periph_sdcard_cfg_t sdcard_cfg = {
.root = "/sdcard",
.card_detect_pin = get_sdcard_intr_gpio(),
.mode = mode
};
esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg);
esp_err_t ret = esp_periph_start(set, sdcard_handle);
int retry_time = 5;
bool mount_flag = false;
while (retry_time --) {
if (periph_sdcard_is_mounted(sdcard_handle)) {
mount_flag = true;
break;
} else {
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
if (mount_flag == false) {
ESP_LOGE(TAG, "Sdcard mount failed");
return ESP_FAIL;
}
return ret;
}
audio_board_handle_t audio_board_get_handle(void)
{
return board_handle;
}
esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
{
esp_err_t ret = ESP_OK;
ret |= audio_hal_deinit(audio_board->audio_hal);
ret |= audio_hal_deinit(audio_board->adc_hal);
audio_free(audio_board);
board_handle = NULL;
return ret;
}

View File

@ -0,0 +1,138 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_H_
#define _AUDIO_BOARD_H_
#include "audio_hal.h"
#include "board_def.h"
#include "board_pins_config.h"
#include "esp_peripherals.h"
#include "display_service.h"
#include "periph_sdcard.h"
#include "periph_lcd.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Audio board handle
*/
struct audio_board_handle {
audio_hal_handle_t audio_hal; /*!< audio hardware abstract layer handle */
audio_hal_handle_t adc_hal; /*!< adc hardware abstract layer handle */
};
typedef struct audio_board_handle *audio_board_handle_t;
/**
* @brief Initialize audio board
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_init(void);
/**
* @brief Initialize codec chip
*
* @return The audio hal handle
*/
audio_hal_handle_t audio_board_codec_init(void);
/**
* @brief Initialize adc
*
* @return The adc hal handle
*/
audio_hal_handle_t audio_board_adc_init(void);
/**
* @brief Initialize lcd peripheral
*
* @param set The handle of esp_periph_set_handle_t
* @param cb The `on_color_trans_done` callback in `esp_lcd_panel_io_spi_config_t`
*
* @return The `esp_lcd_panel_handle_t` handle
*/
void *audio_board_lcd_init(esp_periph_set_handle_t set, void *cb);
/**
* @brief Initialize led peripheral and display service
*
* @return The audio display service handle
*/
display_service_handle_t audio_board_led_init(void);
/**
* @brief Initialize led peripheral and display service
*
* @return The audio display service handle
*/
display_service_handle_t audio_board_blue_led_init(void);
/**
* @brief Initialize key peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_key_init(esp_periph_set_handle_t set);
/**
* @brief Initialize sdcard peripheral
*
* @param set The handle of esp_periph_set_handle_t
*
* @return
* - ESP_OK, success
* - Others, fail
*/
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode);
/**
* @brief Query audio_board_handle
*
* @return The audio board handle
*/
audio_board_handle_t audio_board_get_handle(void);
/**
* @brief Uninitialize the audio board
*
* @param audio_board The handle of audio board
*
* @return 0 success,
* others fail
*/
esp_err_t audio_board_deinit(audio_board_handle_t audio_board);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,188 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _AUDIO_BOARD_DEFINITION_H_
#define _AUDIO_BOARD_DEFINITION_H_
/**
* @brief LED Function Definition
*/
#define GREEN_LED_GPIO -1
#define BLUE_LED_GPIO BIT(7) // TCA9554_GPIO_NUM_7
#define RED_LED_GPIO BIT(6) // TCA9554_GPIO_NUM_6
/**
* @brief LCD SCREEN Function Definition
*/
#define FUNC_LCD_SCREEN_EN (1)
#define LCD_CTRL_GPIO BIT(1) // TCA9554_GPIO_NUM_1
#define LCD_RST_GPIO BIT(2) // TCA9554_GPIO_NUM_2
#define LCD_CS_GPIO BIT(3) // TCA9554_GPIO_NUM_3
// LCD SPI Pins
#define LCD_DC_GPIO GPIO_NUM_2
#define LCD_CLK_GPIO GPIO_NUM_1
#define LCD_MOSI_GPIO GPIO_NUM_0
// The LCD pixel number in horizontal and vertical
#define LCD_H_RES 320
#define LCD_V_RES 240
#define LCD_SWAP_XY (false)
#define LCD_MIRROR_X (true)
#define LCD_MIRROR_Y (true)
#define LCD_COLOR_INV (false)
/**
* @brief SDCARD Function Definition
*/
#define FUNC_SDCARD_EN (1)
#define SDCARD_OPEN_FILE_NUM_MAX 5
#define SDCARD_INTR_GPIO -1
#define SDCARD_PWR_CTRL -1
#define ESP_SD_PIN_CLK GPIO_NUM_15
#define ESP_SD_PIN_CMD GPIO_NUM_7
#define ESP_SD_PIN_D0 GPIO_NUM_4
#define ESP_SD_PIN_D1 -1
#define ESP_SD_PIN_D2 -1
#define ESP_SD_PIN_D3 -1
#define ESP_SD_PIN_D4 -1
#define ESP_SD_PIN_D5 -1
#define ESP_SD_PIN_D6 -1
#define ESP_SD_PIN_D7 -1
#define ESP_SD_PIN_CD -1
#define ESP_SD_PIN_WP -1
/**
* @brief Camera Function Definition
*/
#define FUNC_CAMERA_EN (1)
#define CAM_PIN_PWDN -1
#define CAM_PIN_RESET -1
#define CAM_PIN_XCLK GPIO_NUM_40
#define CAM_PIN_SIOD GPIO_NUM_17
#define CAM_PIN_SIOC GPIO_NUM_18
#define CAM_PIN_D7 GPIO_NUM_39
#define CAM_PIN_D6 GPIO_NUM_41
#define CAM_PIN_D5 GPIO_NUM_42
#define CAM_PIN_D4 GPIO_NUM_12
#define CAM_PIN_D3 GPIO_NUM_3
#define CAM_PIN_D2 GPIO_NUM_14
#define CAM_PIN_D1 GPIO_NUM_47
#define CAM_PIN_D0 GPIO_NUM_13
#define CAM_PIN_VSYNC GPIO_NUM_21
#define CAM_PIN_HREF GPIO_NUM_38
#define CAM_PIN_PCLK GPIO_NUM_11
/**
* @brief LCD TOUCH PANEL Function Definition
*/
#define FUNC_LCD_TOUCH_EN (1)
#define TOUCH_PANEL_SWAP_XY (0)
#define TOUCH_PANEL_INVERSE_X (1)
#define TOUCH_PANEL_INVERSE_Y (0)
/**
* @brief Audio Codec Chip Function Definition
*/
#define FUNC_AUDIO_CODEC_EN (1)
#define CODEC_ADC_I2S_PORT ((i2s_port_t)0)
#define CODEC_ADC_BITS_PER_SAMPLE ((i2s_data_bit_width_t)32) /* 32bit */
#define CODEC_ADC_SAMPLE_RATE (48000)
#define RECORD_HARDWARE_AEC (true)
#define BOARD_PA_GAIN (6) /* Power amplifier gain defined by board (dB) */
#define HEADPHONE_DETECT (-1)
#define PA_ENABLE_GPIO GPIO_NUM_48
#define ES8311_MCLK_SOURCE (0) /* 0 From MCLK of esp32 1 From BCLK */
#define ES7210_MIC_SELECT (ES7210_INPUT_MIC1 | ES7210_INPUT_MIC2 | ES7210_INPUT_MIC3)
/**
* @brief ADC input data format
*/
#define AUDIO_ADC_INPUT_CH_FORMAT "RMNM"
extern audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE;
extern audio_hal_func_t AUDIO_CODEC_ES7210_DEFAULT_HANDLE;
#define AUDIO_CODEC_DEFAULT_CONFIG(){ \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
.dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \
.codec_mode = AUDIO_HAL_CODEC_MODE_BOTH, \
.i2s_iface = { \
.mode = AUDIO_HAL_MODE_SLAVE, \
.fmt = AUDIO_HAL_I2S_NORMAL, \
.samples = AUDIO_HAL_48K_SAMPLES, \
.bits = AUDIO_HAL_BIT_LENGTH_16BITS, \
}, \
};
/**
* @brief Button Function Definition
*/
#define FUNC_BUTTON_EN (1)
#define INPUT_KEY_NUM 6
#define BUTTON_VOLUP_ID 0
#define BUTTON_VOLDOWN_ID 1
#define BUTTON_SET_ID 2
#define BUTTON_PLAY_ID 3
#define BUTTON_MODE_ID 4
#define BUTTON_REC_ID 5
#define INPUT_KEY_DEFAULT_INFO() { \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_REC, \
.act_id = BUTTON_REC_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_MUTE, \
.act_id = BUTTON_MODE_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_SET, \
.act_id = BUTTON_SET_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_PLAY, \
.act_id = BUTTON_PLAY_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLUP, \
.act_id = BUTTON_VOLUP_ID, \
}, \
{ \
.type = PERIPH_ID_ADC_BTN, \
.user_id = INPUT_KEY_USER_ID_VOLDOWN, \
.act_id = BUTTON_VOLDOWN_ID, \
} \
}
#endif

View File

@ -0,0 +1,167 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "driver/gpio.h"
#include <string.h>
#include "board.h"
#include "audio_error.h"
#include "audio_mem.h"
#include "soc/soc_caps.h"
static const char *TAG = "ESP32_S3_KORVO_2";
esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config)
{
AUDIO_NULL_CHECK(TAG, i2c_config, return ESP_FAIL);
if (port == I2C_NUM_0 || port == I2C_NUM_1) {
i2c_config->sda_io_num = GPIO_NUM_17;
i2c_config->scl_io_num = GPIO_NUM_18;
} else {
i2c_config->sda_io_num = -1;
i2c_config->scl_io_num = -1;
ESP_LOGE(TAG, "i2c port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_i2s_pins(int port, board_i2s_pin_t *i2s_config)
{
AUDIO_NULL_CHECK(TAG, i2s_config, return ESP_FAIL);
if (port == 0) {
i2s_config->bck_io_num = GPIO_NUM_9;
i2s_config->ws_io_num = GPIO_NUM_45;
i2s_config->data_out_num = GPIO_NUM_8;
i2s_config->data_in_num = GPIO_NUM_10;
i2s_config->mck_io_num = GPIO_NUM_16;
} else if (port == 1) {
i2s_config->bck_io_num = -1;
i2s_config->ws_io_num = -1;
i2s_config->data_out_num = -1;
i2s_config->data_in_num = -1;
i2s_config->mck_io_num = -1;
} else {
memset(i2s_config, -1, sizeof(board_i2s_pin_t));
ESP_LOGE(TAG, "i2s port %d is not supported", port);
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config)
{
AUDIO_NULL_CHECK(TAG, spi_config, return ESP_FAIL);
AUDIO_NULL_CHECK(TAG, spi_device_interface_config, return ESP_FAIL);
spi_config->mosi_io_num = -1;
spi_config->miso_io_num = -1;
spi_config->sclk_io_num = -1;
spi_config->quadwp_io_num = -1;
spi_config->quadhd_io_num = -1;
spi_device_interface_config->spics_io_num = -1;
ESP_LOGW(TAG, "SPI interface is not supported");
return ESP_OK;
}
// sdcard
int8_t get_sdcard_intr_gpio(void)
{
return SDCARD_INTR_GPIO;
}
int8_t get_sdcard_open_file_num_max(void)
{
return SDCARD_OPEN_FILE_NUM_MAX;
}
int8_t get_sdcard_power_ctrl_gpio(void)
{
return SDCARD_PWR_CTRL;
}
// input-output pins
int8_t get_headphone_detect_gpio(void)
{
return HEADPHONE_DETECT;
}
int8_t get_pa_enable_gpio(void)
{
return PA_ENABLE_GPIO;
}
// adc button id
int8_t get_input_rec_id(void)
{
return BUTTON_REC_ID;
}
int8_t get_input_mode_id(void)
{
return BUTTON_MODE_ID;
}
int8_t get_input_set_id(void)
{
return BUTTON_SET_ID;
}
int8_t get_input_play_id(void)
{
return BUTTON_PLAY_ID;
}
int8_t get_input_volup_id(void)
{
return BUTTON_VOLUP_ID;
}
int8_t get_input_voldown_id(void)
{
return BUTTON_VOLDOWN_ID;
}
// led pins
int8_t get_green_led_gpio(void)
{
return GREEN_LED_GPIO;
}
int8_t get_blue_led_gpio(void)
{
return BLUE_LED_GPIO;
}
int8_t get_es8311_mclk_src(void)
{
return ES8311_MCLK_SOURCE;
}

View File

@ -0,0 +1,219 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2022 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "esp_log.h"
#include "board.h"
#include "audio_mem.h"
#include "periph_sdcard.h"
#include "periph_adc_button.h"
#include "tca9554.h"
static const char *TAG = "AUDIO_BOARD";
static audio_board_handle_t board_handle = 0;
audio_board_handle_t audio_board_init(void)
{
if (board_handle) {
ESP_LOGW(TAG, "The board has already been initialized!");
return board_handle;
}
board_handle = (audio_board_handle_t) audio_calloc(1, sizeof(struct audio_board_handle));
AUDIO_MEM_CHECK(TAG, board_handle, return NULL);
board_handle->audio_hal = audio_board_codec_init();
return board_handle;
}
audio_hal_handle_t audio_board_codec_init(void)
{
audio_hal_codec_config_t audio_codec_cfg = AUDIO_CODEC_DEFAULT_CONFIG();
audio_hal_handle_t codec_hal = audio_hal_init(&audio_codec_cfg, &AUDIO_CODEC_ES8311_DEFAULT_HANDLE);
AUDIO_NULL_CHECK(TAG, codec_hal, return NULL);
return codec_hal;
}
esp_err_t audio_board_usb_cam_init(void)
{
gpio_config_t usb_camera_pins_cfg = {
.intr_type = GPIO_INTR_DISABLE,
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = (BIT64(USB_CAM_PIN_PWDN)),
.pull_up_en = 0,
.pull_down_en = 0,
};
gpio_config(&usb_camera_pins_cfg);
gpio_set_level(USB_CAM_PIN_PWDN, 0);
return ESP_OK;
}
esp_err_t _lcd_rest(esp_periph_handle_t self, void *ctx)
{
// Reset the LCD
tca9554_set_output_state(LCD_RST_GPIO, TCA9554_IO_LOW);
vTaskDelay(10 / portTICK_PERIOD_MS);
tca9554_set_output_state(LCD_RST_GPIO, TCA9554_IO_HIGH);
vTaskDelay(10 / portTICK_PERIOD_MS);
return ESP_OK;
}
esp_err_t _get_lcd_io_bus (void *bus, esp_lcd_panel_io_spi_config_t *io_config,
esp_lcd_panel_io_handle_t *out_panel_io)
{
return esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)bus, io_config, out_panel_io);
}
display_service_handle_t audio_board_led_init(void)
{
return NULL;
}
void *audio_board_lcd_init(esp_periph_set_handle_t set, void *cb)
{
esp_tca9554_config_t pca_cfg = {
.i2c_scl = GPIO_NUM_18,
.i2c_sda = GPIO_NUM_17,
.interrupt_output = -1,
};
tca9554_init(&pca_cfg);
// Set LCD_BL_CTRL output
tca9554_set_io_config(LCD_CTRL_GPIO, TCA9554_IO_OUTPUT);
// Set LCD_RST output
tca9554_set_io_config(LCD_RST_GPIO, TCA9554_IO_OUTPUT);
// Set LCD_CS pin output
tca9554_set_io_config(LCD_CS_GPIO, TCA9554_IO_OUTPUT);
tca9554_set_output_state(LCD_CTRL_GPIO, TCA9554_IO_HIGH);
tca9554_set_output_state(LCD_CS_GPIO, TCA9554_IO_HIGH);
vTaskDelay(10 / portTICK_PERIOD_MS);
tca9554_set_output_state(LCD_CS_GPIO, TCA9554_IO_LOW);
vTaskDelay(10 / portTICK_PERIOD_MS);
spi_bus_config_t buscfg = {
.sclk_io_num = LCD_CLK_GPIO,
.mosi_io_num = LCD_MOSI_GPIO,
.miso_io_num = -1,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = LCD_V_RES * LCD_H_RES * 2
};
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
esp_lcd_panel_io_spi_config_t io_config = {
.dc_gpio_num = LCD_DC_GPIO,
.cs_gpio_num = -1,
.pclk_hz = 60 * 1000 * 1000,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.spi_mode = 0,
.trans_queue_depth = 10,
.on_color_trans_done = cb,
.user_ctx = NULL,
};
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = -1,
.color_space = ESP_LCD_COLOR_SPACE_BGR,
.bits_per_pixel = 16,
};
periph_lcd_cfg_t cfg = {
.io_bus = (void *)SPI2_HOST,
.new_panel_io = _get_lcd_io_bus,
.lcd_io_cfg = &io_config,
.new_lcd_panel = esp_lcd_new_panel_st7789,
.lcd_dev_cfg = &panel_config,
.rest_cb = _lcd_rest,
.rest_cb_ctx = NULL,
.lcd_swap_xy = LCD_SWAP_XY,
.lcd_mirror_x = LCD_MIRROR_X,
.lcd_mirror_y = LCD_MIRROR_Y,
.lcd_color_invert = LCD_COLOR_INV,
};
esp_periph_handle_t periph_lcd = periph_lcd_init(&cfg);
AUDIO_NULL_CHECK(TAG, periph_lcd, return NULL);
esp_periph_start(set, periph_lcd);
vTaskDelay(200 / portTICK_PERIOD_MS);
return (void *)periph_lcd_get_panel_handle(periph_lcd);
}
esp_err_t audio_board_key_init(esp_periph_set_handle_t set)
{
periph_adc_button_cfg_t adc_btn_cfg = PERIPH_ADC_BUTTON_DEFAULT_CONFIG();
adc_arr_t adc_btn_tag = ADC_DEFAULT_ARR();
adc_btn_tag.total_steps = 6;
adc_btn_tag.adc_ch = ADC1_CHANNEL_4;
int btn_array[7] = {190, 600, 1000, 1375, 1775, 2195, 3000};
adc_btn_tag.adc_level_step = btn_array;
adc_btn_cfg.arr = &adc_btn_tag;
adc_btn_cfg.arr_size = 1;
esp_periph_handle_t adc_btn_handle = periph_adc_button_init(&adc_btn_cfg);
AUDIO_NULL_CHECK(TAG, adc_btn_handle, return ESP_ERR_ADF_MEMORY_LACK);
return esp_periph_start(set, adc_btn_handle);
}
esp_err_t audio_board_sdcard_init(esp_periph_set_handle_t set, periph_sdcard_mode_t mode)
{
if (mode != SD_MODE_1_LINE) {
ESP_LOGE(TAG, "Current board only support 1-line SD mode!");
return ESP_FAIL;
}
periph_sdcard_cfg_t sdcard_cfg = {
.root = "/sdcard",
.card_detect_pin = get_sdcard_intr_gpio(),
.mode = mode
};
esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg);
esp_err_t ret = esp_periph_start(set, sdcard_handle);
int retry_time = 5;
bool mount_flag = false;
while (retry_time --) {
if (periph_sdcard_is_mounted(sdcard_handle)) {
mount_flag = true;
break;
} else {
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
if (mount_flag == false) {
ESP_LOGE(TAG, "Sdcard mount failed");
return ESP_FAIL;
}
return ret;
}
audio_board_handle_t audio_board_get_handle(void)
{
return board_handle;
}
esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
{
esp_err_t ret = ESP_OK;
ret |= audio_hal_deinit(audio_board->audio_hal);
audio_free(audio_board);
board_handle = NULL;
return ret;
}

Some files were not shown because too many files have changed in this diff Show More