Skip to content

Commit b49b607

Browse files
authored
add support for a1s audio kit
1 parent 02b0cb5 commit b49b607

26 files changed

+7309
-6650
lines changed

components/audio_hal/CMakeLists.txt

+40-38
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
1-
set(COMPONENT_ADD_INCLUDEDIRS ./include
2-
./driver/es8388
3-
./driver/es8374
4-
./driver/es8311
5-
./driver/es7243
6-
./driver/es7148
7-
./driver/tas5805m
8-
./driver/zl38063
9-
./driver/zl38063/api_lib
10-
./driver/zl38063/example_apps
11-
./driver/zl38063/firmware
12-
./driver/include)
13-
14-
# Edit following two lines to set component requirements (see docs)
15-
set(COMPONENT_REQUIRES )
16-
set(COMPONENT_PRIV_REQUIRES audio_sal audio_board mbedtls esp_peripherals display_service esp_dispatcher)
17-
18-
set(COMPONENT_SRCS ./audio_hal.c
19-
./driver/es8388/es8388.c
20-
./driver/es8388/headphone_detect.c
21-
./driver/es8374/es8374.c
22-
./driver/es8311/es8311.c
23-
./driver/es7243/es7243.c
24-
./driver/es7148/es7148.c
25-
./driver/tas5805m/tas5805m.c
26-
./driver/zl38063/zl38063.c
27-
./driver/zl38063/api_lib/vprocTwolf_access.c
28-
./driver/zl38063/api_lib/vproc_common.c
29-
./driver/zl38063/example_apps/tw_hal_verify.c
30-
./driver/zl38063/example_apps/tw_ldcfg.c
31-
./driver/zl38063/example_apps/tw_ldfw.c
32-
./driver/zl38063/example_apps/tw_ldfwcfg.c
33-
./driver/zl38063/example_apps/tw_spi_access.c)
34-
35-
register_component()
36-
37-
target_link_libraries(${COMPONENT_TARGET} INTERFACE "-L${CMAKE_CURRENT_LIST_DIR}/driver/zl38063/firmware")
38-
target_link_libraries(${COMPONENT_TARGET} INTERFACE firmware)
1+
set(COMPONENT_ADD_INCLUDEDIRS ./include
2+
./driver/es8388
3+
./driver/es8374
4+
./driver/es8311
5+
./driver/es7243
6+
./driver/es7148
7+
./driver/ac101
8+
./driver/tas5805m
9+
./driver/zl38063
10+
./driver/zl38063/api_lib
11+
./driver/zl38063/example_apps
12+
./driver/zl38063/firmware
13+
./driver/include)
14+
15+
# Edit following two lines to set component requirements (see docs)
16+
set(COMPONENT_REQUIRES )
17+
set(COMPONENT_PRIV_REQUIRES audio_sal audio_board mbedtls esp_peripherals display_service esp_dispatcher)
18+
19+
set(COMPONENT_SRCS ./audio_hal.c
20+
./driver/es8388/es8388.c
21+
./driver/es8388/headphone_detect.c
22+
./driver/es8374/es8374.c
23+
./driver/es8311/es8311.c
24+
./driver/es7243/es7243.c
25+
./driver/ac101/ac101.c
26+
./driver/es7148/es7148.c
27+
./driver/tas5805m/tas5805m.c
28+
./driver/zl38063/zl38063.c
29+
./driver/zl38063/api_lib/vprocTwolf_access.c
30+
./driver/zl38063/api_lib/vproc_common.c
31+
./driver/zl38063/example_apps/tw_hal_verify.c
32+
./driver/zl38063/example_apps/tw_ldcfg.c
33+
./driver/zl38063/example_apps/tw_ldfw.c
34+
./driver/zl38063/example_apps/tw_ldfwcfg.c
35+
./driver/zl38063/example_apps/tw_spi_access.c)
36+
37+
register_component()
38+
39+
target_link_libraries(${COMPONENT_TARGET} INTERFACE "-L${CMAKE_CURRENT_LIST_DIR}/driver/zl38063/firmware")
40+
target_link_libraries(${COMPONENT_TARGET} INTERFACE firmware)

components/audio_hal/audio_hal.c

+136-136
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,136 @@
1-
/*
2-
* ESPRESSIF MIT License
3-
*
4-
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5-
*
6-
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
7-
* it is free of charge, to any person obtaining a copy of this software and associated
8-
* documentation files (the "Software"), to deal in the Software without restriction, including
9-
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10-
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11-
* to do so, subject to the following conditions:
12-
*
13-
* The above copyright notice and this permission notice shall be included in all copies or
14-
* substantial portions of the Software.
15-
*
16-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18-
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19-
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20-
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21-
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22-
*
23-
*/
24-
25-
#include <string.h>
26-
#include "driver/gpio.h"
27-
#include "esp_log.h"
28-
#include "audio_hal.h"
29-
30-
#include "audio_mem.h"
31-
#include "audio_mutex.h"
32-
33-
static const char *TAG = "AUDIO_HAL";
34-
35-
#define AUDIO_HAL_CHECK_NULL(a, format, b, ...) \
36-
if ((a) == 0) { \
37-
ESP_LOGE(TAG, format, ##__VA_ARGS__); \
38-
return b;\
39-
}
40-
41-
audio_hal_handle_t audio_hal_init(audio_hal_codec_config_t *audio_hal_conf, audio_hal_func_t *audio_hal_func)
42-
{
43-
esp_err_t ret = 0;
44-
audio_hal_handle_t audio_hal = (audio_hal_handle_t) audio_calloc(1, sizeof(audio_hal_func_t));
45-
AUDIO_MEM_CHECK(TAG, audio_hal, return NULL);
46-
memcpy(audio_hal, audio_hal_func, sizeof(audio_hal_func_t));
47-
audio_hal->audio_hal_lock = mutex_create();
48-
49-
AUDIO_MEM_CHECK(TAG, audio_hal->audio_hal_lock, {
50-
audio_free(audio_hal);
51-
return NULL;
52-
});
53-
mutex_lock(audio_hal->audio_hal_lock);
54-
ret = audio_hal->audio_codec_initialize(audio_hal_conf);
55-
if (ret == ESP_FAIL) {
56-
audio_free(audio_hal);
57-
if (audio_hal_func->handle) {
58-
return audio_hal_func->handle;
59-
} else {
60-
ESP_LOGE(TAG, "codec init failed!");
61-
return NULL;
62-
}
63-
}
64-
ret |= audio_hal->audio_codec_config_iface(audio_hal_conf->codec_mode, &audio_hal_conf->i2s_iface);
65-
ret |= audio_hal->audio_codec_set_volume(AUDIO_HAL_VOL_DEFAULT);
66-
audio_hal->handle = audio_hal;
67-
audio_hal_func->handle = audio_hal;
68-
mutex_unlock(audio_hal->audio_hal_lock);
69-
return audio_hal;
70-
}
71-
72-
esp_err_t audio_hal_deinit(audio_hal_handle_t audio_hal)
73-
{
74-
esp_err_t ret;
75-
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
76-
mutex_destroy(audio_hal->audio_hal_lock);
77-
ret = audio_hal->audio_codec_deinitialize();
78-
audio_hal->audio_hal_lock = NULL;
79-
audio_hal->handle = NULL;
80-
audio_free(audio_hal);
81-
audio_hal = NULL;
82-
return ret;
83-
}
84-
85-
esp_err_t audio_hal_ctrl_codec(audio_hal_handle_t audio_hal, audio_hal_codec_mode_t mode, audio_hal_ctrl_t audio_hal_state)
86-
{
87-
esp_err_t ret;
88-
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
89-
mutex_lock(audio_hal->audio_hal_lock);
90-
ESP_LOGI(TAG, "Codec mode is %d, Ctrl:%d", mode, audio_hal_state);
91-
ret = audio_hal->audio_codec_ctrl(mode, audio_hal_state);
92-
mutex_unlock(audio_hal->audio_hal_lock);
93-
return ret;
94-
}
95-
96-
esp_err_t audio_hal_codec_iface_config(audio_hal_handle_t audio_hal, audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface)
97-
{
98-
esp_err_t ret = 0;
99-
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
100-
AUDIO_HAL_CHECK_NULL(iface, "Get volume para is null", -1);
101-
mutex_lock(audio_hal->audio_hal_lock);
102-
ret = audio_hal->audio_codec_config_iface(mode, iface);
103-
mutex_unlock(audio_hal->audio_hal_lock);
104-
return ret;
105-
}
106-
107-
esp_err_t audio_hal_set_mute(audio_hal_handle_t audio_hal, bool mute)
108-
{
109-
esp_err_t ret;
110-
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
111-
mutex_lock(audio_hal->audio_hal_lock);
112-
ret = audio_hal->audio_codec_set_mute(mute);
113-
mutex_unlock(audio_hal->audio_hal_lock);
114-
return ret;
115-
}
116-
117-
esp_err_t audio_hal_set_volume(audio_hal_handle_t audio_hal, int volume)
118-
{
119-
esp_err_t ret;
120-
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
121-
mutex_lock(audio_hal->audio_hal_lock);
122-
ret = audio_hal->audio_codec_set_volume(volume);
123-
mutex_unlock(audio_hal->audio_hal_lock);
124-
return ret;
125-
}
126-
127-
esp_err_t audio_hal_get_volume(audio_hal_handle_t audio_hal, int *volume)
128-
{
129-
esp_err_t ret;
130-
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
131-
AUDIO_HAL_CHECK_NULL(volume, "Get volume para is null", -1);
132-
mutex_lock(audio_hal->audio_hal_lock);
133-
ret = audio_hal->audio_codec_get_volume(volume);
134-
mutex_unlock(audio_hal->audio_hal_lock);
135-
return ret;
136-
}
1+
/*
2+
* ESPRESSIF MIT License
3+
*
4+
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5+
*
6+
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
7+
* it is free of charge, to any person obtaining a copy of this software and associated
8+
* documentation files (the "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11+
* to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all copies or
14+
* substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
*/
24+
25+
#include <string.h>
26+
#include "driver/gpio.h"
27+
#include "esp_log.h"
28+
#include "audio_hal.h"
29+
30+
#include "audio_mem.h"
31+
#include "audio_mutex.h"
32+
33+
static const char *TAG = "AUDIO_HAL";
34+
35+
#define AUDIO_HAL_CHECK_NULL(a, format, b, ...) \
36+
if ((a) == 0) { \
37+
ESP_LOGE(TAG, format, ##__VA_ARGS__); \
38+
return b;\
39+
}
40+
41+
audio_hal_handle_t audio_hal_init(audio_hal_codec_config_t *audio_hal_conf, audio_hal_func_t *audio_hal_func)
42+
{
43+
esp_err_t ret = 0;
44+
audio_hal_handle_t audio_hal = (audio_hal_handle_t) audio_calloc(1, sizeof(audio_hal_func_t));
45+
AUDIO_MEM_CHECK(TAG, audio_hal, return NULL);
46+
memcpy(audio_hal, audio_hal_func, sizeof(audio_hal_func_t));
47+
audio_hal->audio_hal_lock = mutex_create();
48+
49+
AUDIO_MEM_CHECK(TAG, audio_hal->audio_hal_lock, {
50+
audio_free(audio_hal);
51+
return NULL;
52+
});
53+
mutex_lock(audio_hal->audio_hal_lock);
54+
ret = audio_hal->audio_codec_initialize(audio_hal_conf);
55+
if (ret == ESP_FAIL) {
56+
audio_free(audio_hal);
57+
if (audio_hal_func->handle) {
58+
return audio_hal_func->handle;
59+
} else {
60+
ESP_LOGE(TAG, "codec init failed!");
61+
return NULL;
62+
}
63+
}
64+
ret |= audio_hal->audio_codec_config_iface(audio_hal_conf->codec_mode, &audio_hal_conf->i2s_iface);
65+
ret |= audio_hal->audio_codec_set_volume(AUDIO_HAL_VOL_DEFAULT);
66+
audio_hal->handle = audio_hal;
67+
audio_hal_func->handle = audio_hal;
68+
mutex_unlock(audio_hal->audio_hal_lock);
69+
return audio_hal;
70+
}
71+
72+
esp_err_t audio_hal_deinit(audio_hal_handle_t audio_hal)
73+
{
74+
esp_err_t ret;
75+
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
76+
mutex_destroy(audio_hal->audio_hal_lock);
77+
ret = audio_hal->audio_codec_deinitialize();
78+
audio_hal->audio_hal_lock = NULL;
79+
audio_hal->handle = NULL;
80+
audio_free(audio_hal);
81+
audio_hal = NULL;
82+
return ret;
83+
}
84+
85+
esp_err_t audio_hal_ctrl_codec(audio_hal_handle_t audio_hal, audio_hal_codec_mode_t mode, audio_hal_ctrl_t audio_hal_state)
86+
{
87+
esp_err_t ret;
88+
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
89+
mutex_lock(audio_hal->audio_hal_lock);
90+
ESP_LOGI(TAG, "Codec mode is %d, Ctrl:%d", mode, audio_hal_state);
91+
ret = audio_hal->audio_codec_ctrl(mode, audio_hal_state);
92+
mutex_unlock(audio_hal->audio_hal_lock);
93+
return ret;
94+
}
95+
96+
esp_err_t audio_hal_codec_iface_config(audio_hal_handle_t audio_hal, audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface)
97+
{
98+
esp_err_t ret = 0;
99+
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
100+
AUDIO_HAL_CHECK_NULL(iface, "Get volume para is null", -1);
101+
mutex_lock(audio_hal->audio_hal_lock);
102+
ret = audio_hal->audio_codec_config_iface(mode, iface);
103+
mutex_unlock(audio_hal->audio_hal_lock);
104+
return ret;
105+
}
106+
107+
esp_err_t audio_hal_set_mute(audio_hal_handle_t audio_hal, bool mute)
108+
{
109+
esp_err_t ret;
110+
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
111+
mutex_lock(audio_hal->audio_hal_lock);
112+
ret = audio_hal->audio_codec_set_mute(mute);
113+
mutex_unlock(audio_hal->audio_hal_lock);
114+
return ret;
115+
}
116+
117+
esp_err_t audio_hal_set_volume(audio_hal_handle_t audio_hal, int volume)
118+
{
119+
esp_err_t ret;
120+
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
121+
mutex_lock(audio_hal->audio_hal_lock);
122+
ret = audio_hal->audio_codec_set_volume(volume);
123+
mutex_unlock(audio_hal->audio_hal_lock);
124+
return ret;
125+
}
126+
127+
esp_err_t audio_hal_get_volume(audio_hal_handle_t audio_hal, int *volume)
128+
{
129+
esp_err_t ret;
130+
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
131+
AUDIO_HAL_CHECK_NULL(volume, "Get volume para is null", -1);
132+
mutex_lock(audio_hal->audio_hal_lock);
133+
ret = audio_hal->audio_codec_get_volume(volume);
134+
mutex_unlock(audio_hal->audio_hal_lock);
135+
return ret;
136+
}

components/audio_hal/component.mk

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
#
2-
# "main" pseudo-component makefile.
3-
#
4-
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
5-
6-
COMPONENT_ADD_INCLUDEDIRS := ./include ./driver/include
7-
COMPONENT_SRCDIRS := .
8-
COMPONENT_PRIV_INCLUDEDIRS := ./driver/include
9-
10-
COMPONENT_ADD_INCLUDEDIRS += ./driver/es8388 ./driver/es8374
11-
COMPONENT_SRCDIRS += ./driver/es8388 ./driver/es8374
12-
13-
COMPONENT_ADD_INCLUDEDIRS += ./driver/es8311 ./driver/es7243
14-
COMPONENT_SRCDIRS += ./driver/es8311 ./driver/es7243
15-
16-
COMPONENT_ADD_INCLUDEDIRS += ./driver/zl38063 ./driver/zl38063/api_lib ./driver/zl38063/example_apps ./driver/zl38063/firmware
17-
COMPONENT_SRCDIRS += ./driver/zl38063 ./driver/zl38063/api_lib ./driver/zl38063/example_apps ./driver/zl38063/firmware
18-
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/driver/zl38063/firmware -lfirmware
19-
20-
COMPONENT_ADD_INCLUDEDIRS += ./driver/tas5805m ./driver/es7148
21-
COMPONENT_SRCDIRS += ./driver/tas5805m ./driver/es7148
1+
#
2+
# "main" pseudo-component makefile.
3+
#
4+
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
5+
6+
COMPONENT_ADD_INCLUDEDIRS := ./include ./driver/include
7+
COMPONENT_SRCDIRS := .
8+
COMPONENT_PRIV_INCLUDEDIRS := ./driver/include
9+
10+
COMPONENT_ADD_INCLUDEDIRS += ./driver/es8388 ./driver/es8374
11+
COMPONENT_SRCDIRS += ./driver/es8388 ./driver/es8374
12+
13+
COMPONENT_ADD_INCLUDEDIRS += ./driver/es8311 ./driver/es7243
14+
COMPONENT_SRCDIRS += ./driver/es8311 ./driver/es7243
15+
16+
COMPONENT_ADD_INCLUDEDIRS += ./driver/zl38063 ./driver/zl38063/api_lib ./driver/zl38063/example_apps ./driver/zl38063/firmware
17+
COMPONENT_SRCDIRS += ./driver/zl38063 ./driver/zl38063/api_lib ./driver/zl38063/example_apps ./driver/zl38063/firmware
18+
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/driver/zl38063/firmware -lfirmware
19+
20+
COMPONENT_ADD_INCLUDEDIRS += ./driver/tas5805m ./driver/es7148
21+
COMPONENT_SRCDIRS += ./driver/tas5805m ./driver/es7148
22+
23+
COMPONENT_ADD_INCLUDEDIRS += ./driver/ac101
24+
COMPONENT_SRCDIRS += ./driver/ac101

0 commit comments

Comments
 (0)