Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aithinker ac101 #1

Merged
merged 2 commits into from
May 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions components/adf_utils/cloud_services/baidu_access_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "esp_http_client.h"
#include "json_utils.h"
#include "esp_log.h"
#include "audio_error.h"

#define BAIDU_URI_LENGTH (200)
#define BAIDU_AUTH_ENDPOINT "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials"
Expand All @@ -37,21 +38,27 @@ char *baidu_get_access_token(const char *access_key, const char *access_secret)
{
char *token = NULL;
char *uri = calloc(1, BAIDU_URI_LENGTH);
assert(uri);

AUDIO_MEM_CHECK(TAG, uri, return NULL);

snprintf(uri, BAIDU_URI_LENGTH, BAIDU_AUTH_ENDPOINT"&client_id=%s&client_secret=%s", access_key, access_secret);

esp_http_client_config_t config = {
.uri = uri,
};
esp_http_client_handle_t http_client = esp_http_client_init(&config);
AUDIO_MEM_CHECK(TAG, http_client, return NULL);

if (esp_http_client_open(http_client, 0) != ESP_OK) {
ESP_LOGE(TAG, "Error open http request to baidu auth server");
goto _exit;
}
esp_http_client_fetch_headers(http_client);
int max_len = 2 * 1024;
char *data = malloc(max_len);
assert(data);

AUDIO_MEM_CHECK(TAG, data, goto _exit);

int read_index = 0, total_len = 0;
while (1) {
int read_len = esp_http_client_read(http_client, data + read_index, max_len - read_index);
Expand Down
3 changes: 2 additions & 1 deletion components/adf_utils/json_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stdlib.h>
#include "esp_log.h"
#include "jsmn.h"
#include "audio_error.h"

static const char* TAG = "JSON_UTILS";

Expand Down Expand Up @@ -61,7 +62,7 @@ char *json_get_token_value(const char *json_string, const char *token_name)
if (jsoneq(json_string, &t[i], token_name) && i < r) {
int tok_len = t[i+1].end - t[i+1].start;
char *tok = calloc(1, tok_len + 1);
assert(tok);
AUDIO_MEM_CHECK(TAG, tok, return NULL);
memcpy(tok, json_string + t[i+1].start, tok_len);
return tok;
}
Expand Down
Binary file added components/audio_hal/.component.mk.swp
Binary file not shown.
19 changes: 19 additions & 0 deletions components/audio_hal/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
menu "BOARD"
choice BOARD
prompt "BOARD"
default AUDIO_KIT
help
CHOOSE MODULE

config ESP32_LYRAT
bool "ESP32_LYRAT"
help
ESPRESSIF LYRAT BOARD

config AUDIO_KIT
bool "AUDIO_KIT"
help
ESPRESSIF LYRAT BOARD

endchoice
endmenu
49 changes: 42 additions & 7 deletions components/audio_hal/audio_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,23 @@
#include "driver/gpio.h"
#include "esp_log.h"
#include "audio_hal.h"

#include "board.h"
#include "audio_mem.h"
#include "audio_mutex.h"
#include "sdkconfig.h"

#ifdef CONFIG_ESP32_LYRAT
#include "es8388.h"
#endif
#ifdef CONFIG_AUDIO_KIT
#include "AC101.h"
#endif

#define HAL_TAG "AUDIO_HAL"
static const char *TAG = "AUDIO_HAL";

#define AUDIO_HAL_CHECK_NULL(a, format, b, ...) \
if ((a) == 0) { \
ESP_LOGE(HAL_TAG, format, ##__VA_ARGS__); \
ESP_LOGE(TAG, format, ##__VA_ARGS__); \
return b;\
}

Expand All @@ -50,6 +57,22 @@ struct audio_hal {
void* handle;
};



#ifdef CONFIG_AUDIO_KIT
static struct audio_hal audio_hal_codecs_default[] = {
{
.audio_codec_initialize = AC101_init,
.audio_codec_deinitialize = AC101_deinit,
.audio_codec_ctrl = AC101_ctrl_state,
.audio_codec_config_iface = AC101_config_i2s,
.audio_codec_set_volume = AC101_set_voice_volume,
.audio_codec_get_volume = AC101_get_voice_volume,
}
};
#endif

#ifdef CONFIG_ESP32_LYRAT
static struct audio_hal audio_hal_codecs_default[] = {
{
.audio_codec_initialize = es8388_init,
Expand All @@ -60,26 +83,38 @@ static struct audio_hal audio_hal_codecs_default[] = {
.audio_codec_get_volume = es8388_get_voice_volume,
}
};
#endif



audio_hal_handle_t audio_hal_init(audio_hal_codec_config_t* audio_hal_conf, int index)
{
esp_err_t ret = 0;
if (NULL != audio_hal_codecs_default[index].handle) {
return audio_hal_codecs_default[index].handle;
}
audio_hal_handle_t audio_hal = (audio_hal_handle_t) audio_calloc(1, sizeof(struct audio_hal));
assert(audio_hal);
audio_hal_handle_t audio_hal =(audio_hal_handle_t) audio_calloc(1, sizeof(struct audio_hal));
AUDIO_MEM_CHECK(TAG, audio_hal, return NULL);
memcpy(audio_hal, &audio_hal_codecs_default[index], sizeof(struct audio_hal));
audio_hal->audio_hal_lock = mutex_create();
assert(audio_hal->audio_hal_lock);

AUDIO_MEM_CHECK(TAG, audio_hal->audio_hal_lock, {
free(audio_hal);
return NULL;
});



mutex_lock(audio_hal->audio_hal_lock);
ret = audio_hal->audio_codec_initialize(audio_hal_conf);
ret |= audio_hal->audio_codec_config_iface(AUDIO_HAL_CODEC_MODE_BOTH, &audio_hal_conf->i2s_iface);
ret |= audio_hal->audio_codec_set_volume(AUDIO_HAL_VOL_DEFAULT);
audio_hal->handle = audio_hal;
audio_hal_codecs_default[index].handle = audio_hal;
mutex_unlock(audio_hal->audio_hal_lock);
#ifdef CONFIG_ESP32_LYRAT
es8388_pa_power(true);
#endif
return audio_hal;
}

Expand All @@ -102,7 +137,7 @@ esp_err_t audio_hal_ctrl_codec(audio_hal_handle_t audio_hal, audio_hal_codec_mod
esp_err_t ret;
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
mutex_lock(audio_hal->audio_hal_lock);
ESP_LOGI(HAL_TAG, "Codec mode is %d, Ctrl:%d", mode, audio_hal_state);
ESP_LOGI(TAG, "Codec mode is %d, Ctrl:%d", mode, audio_hal_state);
ret = audio_hal->audio_codec_ctrl(mode, audio_hal_state);
mutex_unlock(audio_hal->audio_hal_lock);
return ret;
Expand Down
41 changes: 37 additions & 4 deletions components/audio_hal/board/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@
#ifdef __cplusplus
extern "C" {
#endif
#include "sdkconfig.h"

/* SD card relateed */
//#ifdef COFNIG_AiThinker_AUDIO_KIT
////#define BOARD ESP32_LYRAT
//#elif CONFIG_ESP32_LYRAT
////#define BOARD ESP32_LYRAT
//#endif


#ifdef CONFIG_ESP32_LYRAT
#define SD_CARD_INTR_GPIO GPIO_NUM_34
#define SD_CARD_INTR_SEL GPIO_SEL_34
#define SD_CARD_OPEN_FILE_NUM_MAX 5


#define IIC_CLK 23
#define IIC_DATA 18

/* PA */
#define GPIO_PA_EN GPIO_NUM_21
#define GPIO_SEL_PA_EN GPIO_SEL_21
Expand All @@ -52,6 +57,34 @@ extern "C" {
#define IIS_LCLK 25
#define IIS_DSIN 26
#define IIS_DOUT 35
#endif

#ifdef CONFIG_AUDIO_KIT
/* SD card relateed */
#define SD_CARD_INTR_GPIO GPIO_NUM_21
#define SD_CARD_INTR_SEL GPIO_SEL_21
#define SD_CARD_OPEN_FILE_NUM_MAX 5


#define IIC_CLK 18
#define IIC_DATA 19

/* PA */
//#define GPIO_PA_EN GPIO_NUM_16
//#define GPIO_SEL_PA_EN GPIO_SEL_16

/* Press button related */
#define GPIO_SEL_REC GPIO_SEL_36 //SENSOR_VP
#define GPIO_SEL_MODE GPIO_SEL_39 //SENSOR_VN
#define GPIO_REC GPIO_NUM_36
#define GPIO_MODE GPIO_NUM_39

#define IIS_SCLK 27
#define IIS_LCLK 26
#define IIS_DSIN 25
#define IIS_DOUT 35
#endif


#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions components/audio_hal/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)


COMPONENT_ADD_INCLUDEDIRS := ./include ./driver/es8388 ./board
COMPONENT_ADD_INCLUDEDIRS := ./include ./driver/es8388 ./board ./driver/AC101

COMPONENT_SRCDIRS := . ./driver/es8388 ./board
COMPONENT_SRCDIRS := . ./driver/es8388 ./board ./driver/AC101
Loading