mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-03 03:31:41 +03:00
Merge branch 'refactor/p4_touch_channel_increase_1_v5.5' into 'release/v5.5'
refactor(touch): adjust touch channel number on P4 from 0-13 to 1-14 (v5.5) See merge request espressif/esp-idf!39791
This commit is contained in:
@@ -136,6 +136,7 @@ esp_err_t touch_sensor_new_channel(touch_sensor_handle_t sens_handle, int chan_i
|
||||
TOUCH_NULL_POINTER_CHECK(chan_cfg);
|
||||
TOUCH_NULL_POINTER_CHECK(ret_chan_handle);
|
||||
TOUCH_CHANNEL_CHECK(chan_id);
|
||||
uint32_t ch_offset = chan_id - TOUCH_MIN_CHAN_ID;
|
||||
|
||||
ESP_RETURN_ON_FALSE(g_touch == sens_handle, ESP_ERR_INVALID_ARG, TAG, "The input touch sensor handle is unmatched");
|
||||
|
||||
@@ -143,31 +144,31 @@ esp_err_t touch_sensor_new_channel(touch_sensor_handle_t sens_handle, int chan_i
|
||||
xSemaphoreTakeRecursive(sens_handle->mutex, portMAX_DELAY);
|
||||
|
||||
TOUCH_GOTO_ON_FALSE_FSM(!sens_handle->is_enabled, ESP_ERR_INVALID_STATE, err2, TAG, "Please disable the touch sensor first");
|
||||
ESP_GOTO_ON_FALSE(!sens_handle->ch[chan_id], ESP_ERR_INVALID_STATE, err2, TAG, "The channel %d has been registered", chan_id);
|
||||
ESP_GOTO_ON_FALSE(!sens_handle->ch[ch_offset], ESP_ERR_INVALID_STATE, err2, TAG, "The channel %d has been registered", chan_id);
|
||||
|
||||
sens_handle->ch[chan_id] = (touch_channel_handle_t)heap_caps_calloc(1, sizeof(struct touch_channel_s), TOUCH_MEM_ALLOC_CAPS);
|
||||
ESP_GOTO_ON_FALSE(sens_handle->ch[chan_id], ESP_ERR_NO_MEM, err2, TAG, "No memory for touch channel");
|
||||
sens_handle->ch[chan_id]->id = chan_id;
|
||||
sens_handle->ch[chan_id]->base = sens_handle;
|
||||
sens_handle->ch[ch_offset] = (touch_channel_handle_t)heap_caps_calloc(1, sizeof(struct touch_channel_s), TOUCH_MEM_ALLOC_CAPS);
|
||||
ESP_GOTO_ON_FALSE(sens_handle->ch[ch_offset], ESP_ERR_NO_MEM, err2, TAG, "No memory for touch channel");
|
||||
sens_handle->ch[ch_offset]->id = chan_id;
|
||||
sens_handle->ch[ch_offset]->base = sens_handle;
|
||||
#if SOC_TOUCH_SUPPORT_PROX_SENSING
|
||||
sens_handle->ch[chan_id]->prox_id = 0;
|
||||
sens_handle->ch[ch_offset]->prox_id = 0;
|
||||
#endif
|
||||
|
||||
/* Init the channel */
|
||||
ESP_GOTO_ON_ERROR(touch_priv_config_channel(sens_handle->ch[chan_id], chan_cfg),
|
||||
ESP_GOTO_ON_ERROR(touch_priv_config_channel(sens_handle->ch[ch_offset], chan_cfg),
|
||||
err1, TAG, "Failed to configure the touch channel %d", chan_id);
|
||||
touch_channel_pin_init(chan_id);
|
||||
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
|
||||
sens_handle->chan_mask |= 1 << chan_id;
|
||||
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
|
||||
|
||||
*ret_chan_handle = sens_handle->ch[chan_id];
|
||||
*ret_chan_handle = sens_handle->ch[ch_offset];
|
||||
|
||||
xSemaphoreGiveRecursive(sens_handle->mutex);
|
||||
return ret;
|
||||
err1:
|
||||
free(sens_handle->ch[chan_id]);
|
||||
sens_handle->ch[chan_id] = NULL;
|
||||
free(sens_handle->ch[ch_offset]);
|
||||
sens_handle->ch[ch_offset] = NULL;
|
||||
err2:
|
||||
xSemaphoreGiveRecursive(sens_handle->mutex);
|
||||
return ret;
|
||||
@@ -205,13 +206,14 @@ esp_err_t touch_sensor_del_channel(touch_channel_handle_t chan_handle)
|
||||
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
|
||||
}
|
||||
#endif
|
||||
int id = chan_handle->id;
|
||||
int ch_offset = chan_handle->id - TOUCH_MIN_CHAN_ID;
|
||||
assert(ch_offset >= 0);
|
||||
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
|
||||
sens_handle->chan_mask &= ~(1UL << id);
|
||||
sens_handle->chan_mask &= ~(1UL << chan_handle->id);
|
||||
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
|
||||
|
||||
free(g_touch->ch[id]);
|
||||
g_touch->ch[id] = NULL;
|
||||
free(g_touch->ch[ch_offset]);
|
||||
g_touch->ch[ch_offset] = NULL;
|
||||
err:
|
||||
xSemaphoreGiveRecursive(sens_handle->mutex);
|
||||
return ret;
|
||||
@@ -376,7 +378,7 @@ esp_err_t touch_sensor_trigger_oneshot_scanning(touch_sensor_handle_t sens_handl
|
||||
FOR_EACH_TOUCH_CHANNEL(i) {
|
||||
if (sens_handle->ch[i]) {
|
||||
TOUCH_ENTER_CRITICAL(TOUCH_PERIPH_LOCK);
|
||||
touch_ll_channel_sw_measure_mask(BIT(i));
|
||||
touch_ll_channel_sw_measure_mask(BIT(sens_handle->ch[i]->id));
|
||||
touch_ll_trigger_oneshot_measurement();
|
||||
TOUCH_EXIT_CRITICAL(TOUCH_PERIPH_LOCK);
|
||||
while (!touch_ll_is_measure_done()) {
|
||||
|
||||
@@ -30,7 +30,7 @@ extern "C" {
|
||||
/* Helper macros */
|
||||
#define TOUCH_NULL_POINTER_CHECK(p) ESP_RETURN_ON_FALSE((p), ESP_ERR_INVALID_ARG, TAG, "input parameter '"#p"' is NULL")
|
||||
#define TOUCH_NULL_POINTER_CHECK_ISR(p) ESP_RETURN_ON_FALSE_ISR((p), ESP_ERR_INVALID_ARG, TAG, "input parameter '"#p"' is NULL")
|
||||
#define FOR_EACH_TOUCH_CHANNEL(i) for (int i = 0; i < SOC_TOUCH_SENSOR_NUM; i++)
|
||||
#define FOR_EACH_TOUCH_CHANNEL(i) for (int i = 0; i < TOUCH_TOTAL_CHAN_NUM; i++)
|
||||
#define TOUCH_IRAM_CHECK(cb) (!(cb) || esp_ptr_in_iram(cb))
|
||||
|
||||
/* IRAM safe caps */
|
||||
@@ -87,6 +87,7 @@ struct touch_sensor_s {
|
||||
touch_channel_handle_t ch[SOC_TOUCH_SENSOR_NUM]; /*!< Touch sensor channel handles, will be NULL if the channel is not registered */
|
||||
uint32_t chan_mask; /*!< Enabled channel mask, corresponding bit will be set if the channel is registered */
|
||||
uint32_t src_freq_hz; /*!< Source clock frequency */
|
||||
uint32_t interval_freq_hz; /*!< Frequency of the interval clock */
|
||||
intr_handle_t intr_handle; /*!< Interrupt handle */
|
||||
touch_event_callbacks_t cbs; /*!< Event callbacks */
|
||||
touch_channel_handle_t deep_slp_chan; /*!< The configured channel for depp sleep, will be NULL if not enable the deep sleep */
|
||||
|
||||
Reference in New Issue
Block a user