77#include <zephyr/kernel.h>
88#include <zephyr/logging/log.h>
99
10- #include "ei_classifier_types .h"
11- #include "model-parameters/model_metadata .h"
10+ #include "edge-impulse-sdk/dsp/numpy_types .h"
11+ #include "edge-impulse-sdk/classifier/ei_classifier_types .h"
1212
13- #include "ei_wrapper.h"
1413#include "input_data.h"
1514
1615#define LOG_MODULE_NAME hello_ei
@@ -28,6 +27,12 @@ static struct {
2827
2928static size_t inference_cnt ;
3029
30+ /* External function declaration needed because the function is declared in
31+ * edge-impulse-sdk/classifier/ei_run_classifier.h which includes some
32+ * C++ source code files thus cannot be included in this C file.
33+ */
34+ extern EI_IMPULSE_ERROR run_classifier (signal_t * signal , ei_impulse_result_t * result , bool debug );
35+
3136static void print_inference_result (const ei_impulse_result_t * result , int64_t duration )
3237{
3338 LOG_INF ("=== Inference result ===" );
@@ -110,6 +115,17 @@ static int get_samples_from_buffer(size_t offset, size_t length, float *out_ptr)
110115 return 0 ;
111116}
112117
118+ static EI_IMPULSE_ERROR run_ei_classification (ei_impulse_result_t * ei_result , size_t window_size )
119+ {
120+ signal_t features_signal = {
121+ .get_data = get_samples_from_buffer ,
122+ .total_length = window_size
123+ };
124+
125+ return run_classifier (& features_signal , ei_result ,
126+ IS_ENABLED (CONFIG_EI_WRAPPER_DEBUG_MODE ));
127+ }
128+
113129static int run_model (const float * input_data , size_t input_data_size )
114130{
115131 __ASSERT_NO_MSG (input_data != NULL );
@@ -118,7 +134,7 @@ static int run_model(const float *input_data, size_t input_data_size)
118134 size_t sample_cnt = 0 ;
119135 int64_t start_time , delta ;
120136 ei_impulse_result_t inference_result ;
121- int err ;
137+ EI_IMPULSE_ERROR err ;
122138
123139 clear_sample_buffer ();
124140 inference_cnt = 0 ;
@@ -133,11 +149,11 @@ static int run_model(const float *input_data, size_t input_data_size)
133149 */
134150 if (sample_cnt >= EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE ) {
135151 start_time = k_uptime_get ();
136- err = ei_wrapper_run_inference (& inference_result , EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE );
152+ err = run_ei_classification (& inference_result , EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE );
137153 delta = k_uptime_delta (& start_time );
138154
139- if (err != 0 ) {
140- LOG_ERR ("Inference failed with error code: %d" , err );
155+ if (err != EI_IMPULSE_OK ) {
156+ LOG_ERR ("Classification failed with error code: %d" , err );
141157 return -1 ;
142158 }
143159
@@ -158,8 +174,6 @@ int main(void)
158174{
159175 print_model_info ();
160176
161- ei_wrapper_init (& get_samples_from_buffer );
162-
163177 LOG_INF ("Running inference on sine wave input data" );
164178 LOG_SEPARATOR ();
165179
0 commit comments