feat(vad): lp vad driver and wakeup feature
This commit is contained in:
committed by
Armando (Dou Yiwen)
parent
39430c1404
commit
1792aba1dc
@@ -78,6 +78,10 @@ if(CONFIG_ULP_COPROC_TYPE_LP_CORE)
|
||||
if(CONFIG_SOC_LP_ADC_SUPPORTED)
|
||||
list(APPEND srcs "lp_core/shared/ulp_lp_core_lp_adc_shared.c")
|
||||
endif()
|
||||
|
||||
if(CONFIG_SOC_LP_VAD_SUPPORTED)
|
||||
list(APPEND srcs "lp_core/shared/ulp_lp_core_lp_vad_shared.c")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
|
||||
@@ -126,6 +126,7 @@ function(ulp_apply_default_sources ulp_app_name)
|
||||
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_spi.c"
|
||||
"${IDF_PATH}/components/ulp/lp_core/lp_core/lp_core_ubsan.c"
|
||||
"${IDF_PATH}/components/ulp/lp_core/shared/ulp_lp_core_lp_adc_shared.c"
|
||||
"${IDF_PATH}/components/ulp/lp_core/shared/ulp_lp_core_lp_vad_shared.c"
|
||||
"${IDF_PATH}/components/ulp/lp_core/shared/ulp_lp_core_critical_section_shared.c")
|
||||
|
||||
set(target_folder ${IDF_TARGET})
|
||||
|
||||
@@ -22,6 +22,7 @@ extern "C" {
|
||||
#define ULP_LP_CORE_WAKEUP_SOURCE_LP_IO BIT(2) // Enable wake-up by LP IO interrupt
|
||||
#define ULP_LP_CORE_WAKEUP_SOURCE_ETM BIT(3) // Enable wake-up by ETM event
|
||||
#define ULP_LP_CORE_WAKEUP_SOURCE_LP_TIMER BIT(4) // Enable wake-up by LP timer
|
||||
#define ULP_LP_CORE_WAKEUP_SOURCE_LP_VAD BIT(5) // Enable wake-up by LP VAD
|
||||
|
||||
/**
|
||||
* @brief ULP LP core init parameters
|
||||
|
||||
@@ -35,7 +35,7 @@ extern uint32_t _rtc_ulp_memory_start;
|
||||
|
||||
const static char* TAG = "ulp-lp-core";
|
||||
|
||||
#define WAKEUP_SOURCE_MAX_NUMBER 5
|
||||
#define WAKEUP_SOURCE_MAX_NUMBER 6
|
||||
|
||||
#define RESET_HANDLER_ADDR (intptr_t)(&_rtc_ulp_memory_start + 0x80 / 4) // Placed after the 0x80 byte long vector table
|
||||
|
||||
@@ -46,6 +46,9 @@ static uint32_t wakeup_src_sw_to_hw_flag_lookup[WAKEUP_SOURCE_MAX_NUMBER] = {
|
||||
LP_CORE_LL_WAKEUP_SOURCE_LP_IO,
|
||||
LP_CORE_LL_WAKEUP_SOURCE_ETM,
|
||||
LP_CORE_LL_WAKEUP_SOURCE_LP_TIMER,
|
||||
#if SOC_LP_VAD_SUPPORTED
|
||||
LP_CORE_LL_WAKEUP_SOURCE_LP_VAD,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Convert the wake-up sources defined in ulp_lp_core.h to the actual HW wake-up source values */
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
#include "hal/pmu_ll.h"
|
||||
#include "hal/uart_ll.h"
|
||||
#include "hal/rtc_io_ll.h"
|
||||
#if SOC_LP_I2S_SUPPORT_VAD
|
||||
//For VAD
|
||||
#include "hal/lp_i2s_ll.h"
|
||||
#endif
|
||||
|
||||
#if SOC_LP_TIMER_SUPPORTED
|
||||
#include "hal/lp_timer_ll.h"
|
||||
@@ -56,6 +60,13 @@ void ulp_lp_core_update_wakeup_cause(void)
|
||||
rtcio_ll_clear_interrupt_status();
|
||||
}
|
||||
|
||||
#if SOC_LP_VAD_SUPPORTED
|
||||
if ((lp_core_ll_get_wakeup_source() & LP_CORE_LL_WAKEUP_SOURCE_LP_VAD)) {
|
||||
lp_wakeup_cause |= LP_CORE_LL_WAKEUP_SOURCE_LP_VAD;
|
||||
lp_i2s_ll_rx_clear_interrupt_status(&LP_I2S, LP_I2S_LL_EVENT_VAD_DONE_INT);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SOC_ETM_SUPPORTED
|
||||
if ((lp_core_ll_get_wakeup_source() & LP_CORE_LL_WAKEUP_SOURCE_ETM) \
|
||||
&& lp_core_ll_get_etm_wakeup_flag()) {
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
#include "driver/lp_i2s_vad.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief LP VAD configurations
|
||||
*/
|
||||
typedef lp_vad_init_config_t lp_core_lp_vad_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief State Machine
|
||||
┌──────────────────────────────────┐
|
||||
│ │
|
||||
┌─────────────┤ speak-activity-listening-state │ ◄───────────────┐
|
||||
│ │ │ │
|
||||
│ └──────────────────────────────────┘ │
|
||||
│ ▲ │
|
||||
│ │ │
|
||||
│ │ │
|
||||
│ │ │
|
||||
│ │ │
|
||||
detected speak activity │ │ detected speak activity │ detected speak activity
|
||||
>= │ │ >= │ >=
|
||||
'speak_activity_thresh' │ │ 'min_speak_activity_thresh' │ 'max_speak_activity_thresh'
|
||||
│ │ │
|
||||
│ │ && │
|
||||
│ │ │
|
||||
│ │ detected non-speak activity │
|
||||
│ │ < │
|
||||
│ │ 'non_speak_activity_thresh' │
|
||||
│ │ │
|
||||
│ │ │
|
||||
│ │ │
|
||||
│ │ │
|
||||
│ │ │
|
||||
│ ┌───────────┴─────────────────────┐ │
|
||||
│ │ │ │
|
||||
└───────────► │ speak-activity-detected-state ├─────────────────┘
|
||||
│ │
|
||||
└─┬───────────────────────────────┘
|
||||
│
|
||||
│ ▲
|
||||
│ │
|
||||
│ │
|
||||
│ │ detected speak activity
|
||||
│ │ >=
|
||||
│ │ 'min_speak_activity_thresh'
|
||||
│ │
|
||||
│ │ &&
|
||||
│ │
|
||||
│ │ detected non-speak activity
|
||||
│ │ <
|
||||
└─────────────────────┘ 'non_speak_activity_thresh'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief LP VAD init
|
||||
*
|
||||
* @param[in] vad_id VAD ID
|
||||
* @param[in] init_config Initial configurations
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: On success
|
||||
* - ESP_ERR_INVALID_ARG: Invalid argument
|
||||
* - ESP_ERR_INVALID_STATE: Driver state is invalid, you shouldn't call this API at this moment
|
||||
*/
|
||||
esp_err_t lp_core_lp_vad_init(lp_vad_t vad_id, const lp_core_lp_vad_cfg_t *init_config);
|
||||
|
||||
/**
|
||||
* @brief Enable LP VAD
|
||||
*
|
||||
* @param[in] vad_id VAD ID
|
||||
* @param[in] init_config Initial configurations
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: On success
|
||||
* - ESP_ERR_INVALID_ARG: Invalid argument
|
||||
* - ESP_ERR_INVALID_STATE: Driver state is invalid, you shouldn't call this API at this moment
|
||||
*/
|
||||
esp_err_t lp_core_lp_vad_enable(lp_vad_t vad_id);
|
||||
|
||||
/**
|
||||
* @brief Disable LP VAD
|
||||
*
|
||||
* @param[in] vad_id VAD ID
|
||||
* @param[in] init_config Initial configurations
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: On success
|
||||
* - ESP_ERR_INVALID_ARG: Invalid argument
|
||||
* - ESP_ERR_INVALID_STATE: Driver state is invalid, you shouldn't call this API at this moment
|
||||
*/
|
||||
esp_err_t lp_core_lp_vad_disable(lp_vad_t vad_id);
|
||||
|
||||
/**
|
||||
* @brief Deinit LP VAD
|
||||
*
|
||||
* @param[in] vad_id VAD ID
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: On success
|
||||
* - ESP_ERR_INVALID_ARG: Invalid argument
|
||||
* - ESP_ERR_INVALID_STATE: Driver state is invalid, you shouldn't call this API at this moment
|
||||
*/
|
||||
esp_err_t lp_core_lp_vad_deinit(lp_vad_t vad_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#if SOC_LP_VAD_SUPPORTED
|
||||
#include "esp_check.h"
|
||||
#include "esp_err.h"
|
||||
#include "ulp_lp_core_lp_vad_shared.h"
|
||||
#if SOC_LP_I2S_SUPPORT_VAD
|
||||
//For VAD
|
||||
#include "hal/lp_i2s_ll.h"
|
||||
#include "hal/lp_i2s_hal.h"
|
||||
#include "esp_private/lp_i2s_private.h"
|
||||
#endif //SOC_LP_I2S_SUPPORT_VAD
|
||||
|
||||
//make this available for multi vad id in future
|
||||
vad_unit_handle_t s_vad_handle;
|
||||
|
||||
esp_err_t lp_core_lp_vad_init(lp_vad_t vad_id, const lp_core_lp_vad_cfg_t *init_config)
|
||||
{
|
||||
#if IS_ULP_COCPU
|
||||
// Not supported
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
esp_err_t ret = lp_i2s_vad_new_unit(vad_id, init_config, &s_vad_handle);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t lp_core_lp_vad_enable(lp_vad_t vad_id)
|
||||
{
|
||||
#if IS_ULP_COCPU
|
||||
// Not supported
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
esp_err_t ret = lp_i2s_vad_enable(s_vad_handle);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t lp_core_lp_vad_disable(lp_vad_t vad_id)
|
||||
{
|
||||
#if IS_ULP_COCPU
|
||||
// Not supported
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
esp_err_t ret = lp_i2s_vad_disable(s_vad_handle);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t lp_core_lp_vad_deinit(lp_vad_t vad_id)
|
||||
{
|
||||
#if IS_ULP_COCPU
|
||||
// Not supported
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
esp_err_t ret = lp_i2s_vad_del_unit(s_vad_handle);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
#endif /* SOC_LP_VAD_SUPPORTED */
|
||||
Reference in New Issue
Block a user