From 2b52031029f24fa0e4e26d5864d46200dbdaee15 Mon Sep 17 00:00:00 2001 From: xysun Date: Wed, 13 Sep 2023 17:43:35 +0800 Subject: [PATCH] feat(esp32s3): Support C++ --- include/esp32s3/dl_lib.h | 7 +++++++ include/esp32s3/dl_lib_coefgetter_if.h | 10 +++++++++- include/esp32s3/dl_lib_conv_queue.h | 11 +++++++++-- include/esp32s3/dl_lib_convq8_queue.h | 11 ++++++++++- include/esp32s3/dl_lib_convq_queue.h | 9 ++++++++- include/esp32s3/dl_lib_matrix.h | 8 ++++++++ include/esp32s3/dl_lib_matrixq.h | 9 +++++++++ include/esp32s3/dl_lib_matrixq8.h | 11 ++++++++++- include/esp32s3/esp_afe_config.h | 9 ++++++++- include/esp32s3/esp_afe_sr_iface.h | 8 ++++++++ include/esp32s3/esp_afe_sr_models.h | 8 ++++++++ include/esp32s3/esp_agc.h | 9 +++++++++ include/esp32s3/esp_mase.h | 14 +++++++++++++- include/esp32s3/esp_mn_iface.h | 7 +++++++ include/esp32s3/esp_mn_models.h | 7 ++++++- include/esp32s3/esp_wn_iface.h | 8 ++++++++ include/esp32s3/esp_wn_models.h | 7 +++++++ 17 files changed, 144 insertions(+), 9 deletions(-) diff --git a/include/esp32s3/dl_lib.h b/include/esp32s3/dl_lib.h index d7b6d8f..63ba6da 100644 --- a/include/esp32s3/dl_lib.h +++ b/include/esp32s3/dl_lib.h @@ -32,6 +32,10 @@ #include "esp32s3/rom/cache.h" #endif +#ifdef __cplusplus +extern "C" { +#endif + typedef int padding_state; // /** @@ -407,5 +411,8 @@ dl_matrix2d_t *dl_basic_conv_layer(const dl_matrix2d_t *in, const dl_matrix2d_t dl_matrix2d_t *dl_basic_conv_layer_quantised_weight(const dl_matrix2d_t *in, const dl_matrix2dq_t *weight, const dl_matrix2d_t *bias, int filter_width, int filter_height, const int out_channels, const int stride_x, const int stride_y, padding_state pad, const dl_matrix2d_t* out); +#ifdef __cplusplus +} #endif +#endif \ No newline at end of file diff --git a/include/esp32s3/dl_lib_coefgetter_if.h b/include/esp32s3/dl_lib_coefgetter_if.h index f1a9373..a21de8d 100644 --- a/include/esp32s3/dl_lib_coefgetter_if.h +++ b/include/esp32s3/dl_lib_coefgetter_if.h @@ -19,6 +19,10 @@ #include "dl_lib_matrixq8.h" #include "cJSON.h" +#ifdef __cplusplus +extern "C" { +#endif + //Set this if the coefficient requested is a batch-normalization popvar matrix which needs to be preprocessed by //dl_batch_normalize_get_sqrtvar first. #define COEF_GETTER_HINT_BNVAR (1<<0) @@ -69,4 +73,8 @@ typedef struct { const cJSON* (*getter_config)(void *arg); } model_coeff_getter_t; -#endif \ No newline at end of file +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/esp32s3/dl_lib_conv_queue.h b/include/esp32s3/dl_lib_conv_queue.h index 280d21d..7cb9bf9 100644 --- a/include/esp32s3/dl_lib_conv_queue.h +++ b/include/esp32s3/dl_lib_conv_queue.h @@ -16,8 +16,11 @@ #include "dl_lib_matrix.h" -typedef float fptp_t; +#ifdef __cplusplus +extern "C" { +#endif +typedef float fptp_t; //Flags for matrices // #define DL_MF_FOREIGNDATA (0) /*< Matrix *item data actually points to another matrix and should not be freed */ @@ -170,4 +173,8 @@ fptp_t *dl_dilation_layer(dl_conv_queue_t *in, dl_conv_queue_t *out, int rate, i void test_atrous_conv(int size, int rate, int in_channel, int out_channel); -#endif \ No newline at end of file +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/esp32s3/dl_lib_convq8_queue.h b/include/esp32s3/dl_lib_convq8_queue.h index c37803c..0e53902 100644 --- a/include/esp32s3/dl_lib_convq8_queue.h +++ b/include/esp32s3/dl_lib_convq8_queue.h @@ -20,6 +20,10 @@ #include "dl_lib_conv_queue.h" #include "dl_lib_convq_queue.h" +#ifdef __cplusplus +extern "C" { +#endif + //[nch, n, c] typedef struct { int n; /*< the length of queue */ @@ -290,4 +294,9 @@ void print_convq8(dl_convq8_queue_t *cq, int offset); void print_convq(dl_convq_queue_t *cq, int offset); void lstmq8_free(void); -#endif \ No newline at end of file + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/esp32s3/dl_lib_convq_queue.h b/include/esp32s3/dl_lib_convq_queue.h index 0e8ab47..c71d5ca 100644 --- a/include/esp32s3/dl_lib_convq_queue.h +++ b/include/esp32s3/dl_lib_convq_queue.h @@ -18,6 +18,9 @@ #include "dl_lib_conv_queue.h" #include "dl_lib.h" +#ifdef __cplusplus +extern "C" { +#endif //fixed-point convolution FIFO queue. //[nch, n, c] @@ -372,4 +375,8 @@ void test_lstm_convq(int size, int in_dim, int lstm_cell); void dl_nn_tanh_i162(dl_convq_queue_t **cqm, int offset, int nch); void dl_copy_queue_item_by_qmf(dl_convq_queue_t *cq, fptp_t* item, int m_bit, int f_bit, int offset, int ch); void dl_convq_queue_mc_bzero(dl_convq_queue_t **cqm, int nch); -#endif \ No newline at end of file +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/esp32s3/dl_lib_matrix.h b/include/esp32s3/dl_lib_matrix.h index 1a5e2ee..b5fae74 100644 --- a/include/esp32s3/dl_lib_matrix.h +++ b/include/esp32s3/dl_lib_matrix.h @@ -21,6 +21,10 @@ #include "esp_system.h" #endif +#ifdef __cplusplus +extern "C" { +#endif + // #ifdef CONFIG_IDF_TARGET_ESP32S3 // #include "dl_tie728_bzero.h" // #endif @@ -249,5 +253,9 @@ inline static void dl_matrix_set(dl_matrix2d_t *m, const int x, const int y, fpt void matrix_get_range(const dl_matrix2d_t *m, fptp_t *rmin, fptp_t *rmax); +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/esp32s3/dl_lib_matrixq.h b/include/esp32s3/dl_lib_matrixq.h index 5f0474a..8ad397b 100644 --- a/include/esp32s3/dl_lib_matrixq.h +++ b/include/esp32s3/dl_lib_matrixq.h @@ -17,6 +17,10 @@ #include #include "dl_lib_matrix.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef int16_t qtp_t; //Quantized matrix. Uses fixed numbers and has the storage for the rows/columns inverted @@ -375,4 +379,9 @@ fptp_t dl_matrixq_get(const dl_matrix2dq_t *m, const int x, const int y); */ void dl_matrixq_set(dl_matrix2dq_t *m, const int x, const int y, fptp_t val); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/esp32s3/dl_lib_matrixq8.h b/include/esp32s3/dl_lib_matrixq8.h index 579b1c0..377df7c 100644 --- a/include/esp32s3/dl_lib_matrixq8.h +++ b/include/esp32s3/dl_lib_matrixq8.h @@ -19,6 +19,10 @@ #include "dl_lib.h" #include "dl_lib_matrixq.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef int8_t q8tp_t; typedef struct { @@ -68,4 +72,9 @@ dl_matrix2dq8_t *dl_matrixq8_copy_to_psram(const dl_matrix2dq8_t *m); */ dl_matrix2dq8_t *dl_matrixq8_from_matrix2d(const dl_matrix2d_t *m, dl_matrix2dq8_t *out); -#endif \ No newline at end of file +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/esp32s3/esp_afe_config.h b/include/esp32s3/esp_afe_config.h index 1291b5c..ee43c0c 100644 --- a/include/esp32s3/esp_afe_config.h +++ b/include/esp32s3/esp_afe_config.h @@ -4,6 +4,10 @@ #include "esp_wn_models.h" #include "esp_vad.h" +#ifdef __cplusplus +extern "C" { +#endif + //AFE: Audio Front-End //SR: Speech Recognition //afe_sr/AFE_SR: the audio front-end for speech recognition @@ -135,4 +139,7 @@ typedef struct { .debug_init = false, \ .debug_hook = {{AFE_DEBUG_HOOK_MASE_TASK_IN, NULL}, {AFE_DEBUG_HOOK_FETCH_TASK_IN, NULL}}, \ } -#endif \ No newline at end of file + +#ifdef __cplusplus +} +#endif diff --git a/include/esp32s3/esp_afe_sr_iface.h b/include/esp32s3/esp_afe_sr_iface.h index d45c118..daf5b92 100644 --- a/include/esp32s3/esp_afe_sr_iface.h +++ b/include/esp32s3/esp_afe_sr_iface.h @@ -2,6 +2,10 @@ #include "stdint.h" #include "esp_afe_config.h" +#ifdef __cplusplus +extern "C" { +#endif + //AFE: Audio Front-End //SR: Speech Recognition //afe_sr/AFE_SR: the audio front-end for speech recognition @@ -200,3 +204,7 @@ typedef struct { esp_afe_sr_iface_op_enable_se_t enable_se; esp_afe_sr_iface_op_destroy_t destroy; } esp_afe_sr_iface_t; + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/esp32s3/esp_afe_sr_models.h b/include/esp32s3/esp_afe_sr_models.h index 43a0d08..feaad43 100644 --- a/include/esp32s3/esp_afe_sr_models.h +++ b/include/esp32s3/esp_afe_sr_models.h @@ -1,5 +1,9 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + #if defined CONFIG_USE_AFE #include "esp_afe_sr_iface.h" @@ -24,4 +28,8 @@ extern const esp_afe_sr_iface_t esp_afe_vc_v1; #define ESP_AFE_SR_HANDLE esp_afe_sr_v1 #define ESP_AFE_VC_HANDLE esp_afe_vc_v1 +#endif + +#ifdef __cplusplus +} #endif \ No newline at end of file diff --git a/include/esp32s3/esp_agc.h b/include/esp32s3/esp_agc.h index 37116eb..76d3015 100644 --- a/include/esp32s3/esp_agc.h +++ b/include/esp32s3/esp_agc.h @@ -14,6 +14,10 @@ #ifndef _ESP_AGC_H_ #define _ESP_AGC_H_ +#ifdef __cplusplus +extern "C" { +#endif + ////all positive value is valid, negective is error typedef enum { ESP_AGC_SUCCESS = 0, ////success @@ -28,4 +32,9 @@ void set_agc_config(void *agc_handle, int gain_dB, int limiter_enable, int targe int esp_agc_process(void *agc_handle, short *in_pcm, short *out_pcm, int frame_size, int sample_rate); void esp_agc_close(void *agc_handle); + +#ifdef __cplusplus +} +#endif + #endif // _ESP_AGC_H_ diff --git a/include/esp32s3/esp_mase.h b/include/esp32s3/esp_mase.h index 0b12e82..0999762 100644 --- a/include/esp32s3/esp_mase.h +++ b/include/esp32s3/esp_mase.h @@ -11,6 +11,12 @@ // 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 +#ifndef _ESP_MASE_H_ +#define _ESP_MASE_H_ + +#ifdef __cplusplus +extern "C" { +#endif #define MASE_SAMPLE_RATE 16000 // Supports 16kHz only #define MASE_FRAME_SIZE 16 // Supports 16ms only @@ -78,4 +84,10 @@ void mase_process(mase_handle_t st, int16_t *in, int16_t *dsp_out); * @return None * */ -void mase_destory(mase_handle_t st); \ No newline at end of file +void mase_destory(mase_handle_t st); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/esp32s3/esp_mn_iface.h b/include/esp32s3/esp_mn_iface.h index faccea1..9297e5a 100644 --- a/include/esp32s3/esp_mn_iface.h +++ b/include/esp32s3/esp_mn_iface.h @@ -1,6 +1,9 @@ #pragma once #include "stdint.h" #include "esp_wn_iface.h" +#ifdef __cplusplus +extern "C" { +#endif #define ESP_MN_RESULT_MAX_NUM 5 #define ESP_MN_MAX_PHRASE_NUM 400 @@ -213,3 +216,7 @@ typedef struct { esp_mn_iface_op_print_active_speech_commands print_active_speech_commands; esp_mn_iface_op_check_speech_command check_speech_command; } esp_mn_iface_t; + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/esp32s3/esp_mn_models.h b/include/esp32s3/esp_mn_models.h index 15d7ddd..8571648 100644 --- a/include/esp32s3/esp_mn_models.h +++ b/include/esp32s3/esp_mn_models.h @@ -4,7 +4,9 @@ //Contains declarations of all available speech recognion models. Pair this up with the right coefficients and you have a model that can recognize //a specific phrase or word. - +#ifdef __cplusplus +extern "C" { +#endif /** * @brief Get the multinet handle from model name * @@ -59,3 +61,6 @@ if (r>0) { model->destroy(model_data) */ +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/esp32s3/esp_wn_iface.h b/include/esp32s3/esp_wn_iface.h index 9cc9e5c..bbcdcb9 100644 --- a/include/esp32s3/esp_wn_iface.h +++ b/include/esp32s3/esp_wn_iface.h @@ -1,6 +1,10 @@ #pragma once #include "stdint.h" +#ifdef __cplusplus +extern "C" { +#endif + //Opaque model data container typedef struct model_iface_data_t model_iface_data_t; @@ -183,3 +187,7 @@ typedef struct { esp_wn_iface_op_clean_t clean; esp_wn_iface_op_destroy_t destroy; } esp_wn_iface_t; + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/esp32s3/esp_wn_models.h b/include/esp32s3/esp_wn_models.h index 31ac0ab..38972e7 100644 --- a/include/esp32s3/esp_wn_models.h +++ b/include/esp32s3/esp_wn_models.h @@ -1,6 +1,9 @@ #pragma once #include "esp_wn_iface.h" +#ifdef __cplusplus +extern "C" { +#endif // The prefix of wakenet model name is used to filter all wakenet from availabel models. #define ESP_WN_PREFIX "wn" @@ -98,6 +101,10 @@ char* esp_wn_wakeword_from_name(const char *model_name); #define WAKENET_COEFF "COEFF_NULL" #endif +#ifdef __cplusplus +} +#endif + /* static const sr_model_iface_t *model = esp_wn_handle_from_name(model_name);