Add initial board, HAL, and executor modules
This commit is contained in:
1 parent
3b9e129c88
commit
0b2eebe76d
82 files changed
+20611
No files matched your search
@@ -0,0 +1,74 @@
|
||||
#ifndef AUDIO_CODEC_H
|
||||
#define AUDIO_CODEC_H
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "audio_hal.h"
|
||||
#include "board.h"
|
||||
#include "esp_peripherals.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// 使用audio_hal中已定义的模式类型,避免重复定义
|
||||
typedef audio_hal_codec_mode_t audio_codec_mode_t;
|
||||
|
||||
// 为了代码可读性,定义别名
|
||||
#define AUDIO_CODEC_MODE_DECODE AUDIO_HAL_CODEC_MODE_DECODE
|
||||
#define AUDIO_CODEC_MODE_ENCODE AUDIO_HAL_CODEC_MODE_ENCODE
|
||||
#define AUDIO_CODEC_MODE_BOTH AUDIO_HAL_CODEC_MODE_BOTH
|
||||
|
||||
class AudioCodec {
|
||||
public:
|
||||
// 获取单例实例
|
||||
static AudioCodec* GetInstance();
|
||||
|
||||
// 初始化音频编解码器(默认启用双向模式)
|
||||
esp_err_t Initialize();
|
||||
|
||||
// 音量控制
|
||||
esp_err_t SetVolume(uint8_t volume);
|
||||
esp_err_t GetVolume(uint8_t* volume);
|
||||
|
||||
// ADC音量控制(录音)
|
||||
esp_err_t SetAdcVolume(uint8_t volume);
|
||||
|
||||
// 获取音频板句柄
|
||||
audio_board_handle_t GetBoardHandle();
|
||||
|
||||
// 检查是否已初始化
|
||||
bool IsInitialized();
|
||||
|
||||
// 反初始化
|
||||
esp_err_t Deinitialize();
|
||||
|
||||
private:
|
||||
AudioCodec(); // 私有构造函数
|
||||
~AudioCodec();
|
||||
|
||||
// 禁止拷贝构造和赋值
|
||||
AudioCodec(const AudioCodec&) = delete;
|
||||
AudioCodec& operator=(const AudioCodec&) = delete;
|
||||
|
||||
static AudioCodec* instance_;
|
||||
static SemaphoreHandle_t mutex_;
|
||||
|
||||
audio_board_handle_t board_handle_;
|
||||
bool is_initialized_;
|
||||
audio_codec_mode_t current_mode_;
|
||||
uint8_t current_volume_;
|
||||
|
||||
esp_err_t InitializeBoard();
|
||||
void Cleanup();
|
||||
esp_err_t StartCodec(audio_codec_mode_t mode);
|
||||
esp_err_t StopCodec();
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // AUDIO_CODEC_H
|
||||
Reference in new issue
Block a user