@@ -252,3 +252,53 @@ TEST_CASE("touch_sens_active_inactive_test", "[touch]")
252252 TEST_ASSERT_EQUAL_INT32 (touch_cnt , cb_data .active_count );
253253 TEST_ASSERT_EQUAL_INT32 (touch_cnt , cb_data .inactive_count );
254254}
255+
256+ #if SOC_TOUCH_SENSOR_VERSION > 1
257+ TEST_CASE ("touch_sens_current_meas_channel_test" , "[touch]" )
258+ {
259+ touch_sensor_handle_t touch = NULL ;
260+ touch_channel_handle_t touch_chan = NULL ;
261+
262+ touch_sensor_config_t sens_cfg = TOUCH_SENSOR_DEFAULT_BASIC_CONFIG (TOUCH_SAMPLE_CFG_NUM , s_sample_cfg );
263+ TEST_ESP_OK (touch_sensor_new_controller (& sens_cfg , & touch ));
264+
265+ /* Configuring the filter */
266+ touch_sensor_filter_config_t filter_cfg = TOUCH_SENSOR_DEFAULT_FILTER_CONFIG ();
267+ TEST_ESP_OK (touch_sensor_config_filter (touch , & filter_cfg ));
268+
269+ int err_chan [TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID + 1 ] = {[0 ...(TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID )] = -1 };
270+ int scan_times = 100 ;
271+ uint32_t curr_chan [scan_times ];
272+ /* Loop all channels */
273+ for (int ch_id = TOUCH_MIN_CHAN_ID ; ch_id <= TOUCH_MAX_CHAN_ID ; ch_id ++ ) {
274+ /* New a channel */
275+ TEST_ESP_OK (touch_sensor_new_channel (touch , ch_id , & s_chan_cfg , & touch_chan ));
276+ TEST_ESP_OK (touch_sensor_enable (touch ));
277+ /* Trigger one-shot scanning to update the current measuring channel */
278+ touch_sensor_trigger_oneshot_scanning (touch , 2000 );
279+
280+ /* Read the current measuring channel for several times */
281+ for (int i = 0 ; i < scan_times ; i ++ ) {
282+ curr_chan [i ] = touch_ll_get_current_meas_channel ();
283+ /* Check if the current measuring channel is the same as the channel id */
284+ if (curr_chan [i ] != ch_id ) {
285+ err_chan [ch_id - TOUCH_MIN_CHAN_ID ] = curr_chan [i ];
286+ }
287+ }
288+ /* Check if there is any error */
289+ TEST_ESP_OK (touch_sensor_disable (touch ));
290+ TEST_ESP_OK (touch_sensor_del_channel (touch_chan ));
291+ }
292+ TEST_ESP_OK (touch_sensor_del_controller (touch ));
293+
294+ /* Check if there is any error in the current measuring channel from any channel */
295+ bool has_error = false;
296+ for (int i = 0 ; i < TOUCH_MAX_CHAN_ID - TOUCH_MIN_CHAN_ID + 1 ; i ++ ) {
297+ if (err_chan [i ] >= 0 ) {
298+ ESP_LOGE ("TOUCH_TEST" , "actual channel is %d, but current measuring channel reads %d" , i + TOUCH_MIN_CHAN_ID , err_chan [i ]);
299+ has_error = true;
300+ }
301+ }
302+ TEST_ASSERT_FALSE (has_error );
303+ }
304+ #endif // SOC_TOUCH_SENSOR_VERSION > 1
0 commit comments