mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
feat(pcnt): add support for ESP32P4
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -20,6 +20,9 @@ TEST_CASE("pcnt_unit_install_uninstall", "[pcnt]")
|
||||
pcnt_unit_config_t unit_config = {
|
||||
.low_limit = -100,
|
||||
.high_limit = 100,
|
||||
#if SOC_PCNT_SUPPORT_ZERO_INPUT
|
||||
.zero_input_gpio_num = -1,
|
||||
#endif
|
||||
};
|
||||
pcnt_unit_handle_t units[SOC_PCNT_UNITS_PER_GROUP];
|
||||
int count_value = 0;
|
||||
@@ -77,6 +80,9 @@ TEST_CASE("pcnt_channel_install_uninstall", "[pcnt]")
|
||||
pcnt_unit_config_t unit_config = {
|
||||
.low_limit = -100,
|
||||
.high_limit = 100,
|
||||
#if SOC_PCNT_SUPPORT_ZERO_INPUT
|
||||
.zero_input_gpio_num = -1,
|
||||
#endif
|
||||
};
|
||||
pcnt_chan_config_t chan_config = {
|
||||
.edge_gpio_num = TEST_PCNT_GPIO_A, // only detect edge signal in this case
|
||||
@@ -165,6 +171,9 @@ TEST_CASE("pcnt_multiple_units_pulse_count", "[pcnt]")
|
||||
pcnt_unit_config_t unit_config = {
|
||||
.low_limit = -100,
|
||||
.high_limit = 100,
|
||||
#if SOC_PCNT_SUPPORT_ZERO_INPUT
|
||||
.zero_input_gpio_num = -1,
|
||||
#endif
|
||||
};
|
||||
pcnt_unit_handle_t units[2];
|
||||
for (int i = 0; i < 2; i++) {
|
||||
@@ -229,7 +238,10 @@ TEST_CASE("pcnt_quadrature_decode_event", "[pcnt]")
|
||||
{
|
||||
pcnt_unit_config_t unit_config = {
|
||||
.low_limit = -100,
|
||||
.high_limit = 100
|
||||
.high_limit = 100,
|
||||
#if SOC_PCNT_SUPPORT_ZERO_INPUT
|
||||
.zero_input_gpio_num = -1,
|
||||
#endif
|
||||
};
|
||||
|
||||
printf("install pcnt unit\r\n");
|
||||
@@ -352,7 +364,10 @@ TEST_CASE("pcnt_zero_cross_mode", "[pcnt]")
|
||||
{
|
||||
pcnt_unit_config_t unit_config = {
|
||||
.low_limit = -100,
|
||||
.high_limit = 100
|
||||
.high_limit = 100,
|
||||
#if SOC_PCNT_SUPPORT_ZERO_INPUT
|
||||
.zero_input_gpio_num = -1,
|
||||
#endif
|
||||
};
|
||||
|
||||
printf("install pcnt unit\r\n");
|
||||
@@ -445,6 +460,9 @@ TEST_CASE("pcnt_virtual_io", "[pcnt]")
|
||||
pcnt_unit_config_t unit_config = {
|
||||
.low_limit = -100,
|
||||
.high_limit = 100,
|
||||
#if SOC_PCNT_SUPPORT_ZERO_INPUT
|
||||
.zero_input_gpio_num = -1,
|
||||
#endif
|
||||
};
|
||||
pcnt_chan_config_t chan_config = {
|
||||
.edge_gpio_num = TEST_PCNT_GPIO_A, // only detect edge signal in this case
|
||||
@@ -490,3 +508,63 @@ TEST_CASE("pcnt_virtual_io", "[pcnt]")
|
||||
TEST_ESP_OK(pcnt_del_channel(chan));
|
||||
TEST_ESP_OK(pcnt_del_unit(unit));
|
||||
}
|
||||
|
||||
#if SOC_PCNT_SUPPORT_ZERO_INPUT
|
||||
TEST_CASE("pcnt_zero_input_signal", "[pcnt]")
|
||||
{
|
||||
pcnt_unit_config_t unit_config = {
|
||||
.low_limit = -1000,
|
||||
.high_limit = 1000,
|
||||
.zero_input_gpio_num = TEST_PCNT_GPIO_Z,
|
||||
.flags.io_loop_back = true,
|
||||
};
|
||||
|
||||
printf("install pcnt unit\r\n");
|
||||
pcnt_unit_handle_t unit = NULL;
|
||||
TEST_ESP_OK(pcnt_new_unit(&unit_config, &unit));
|
||||
pcnt_glitch_filter_config_t filter_config = {
|
||||
.max_glitch_ns = 1000,
|
||||
};
|
||||
TEST_ESP_OK(pcnt_unit_set_glitch_filter(unit, &filter_config));
|
||||
|
||||
printf("install pcnt channels\r\n");
|
||||
pcnt_chan_config_t chan_config = {
|
||||
.level_gpio_num = -1,
|
||||
.edge_gpio_num = TEST_PCNT_GPIO_A,
|
||||
.flags.io_loop_back = true,
|
||||
};
|
||||
pcnt_channel_handle_t channel;
|
||||
|
||||
TEST_ESP_OK(pcnt_new_channel(unit, &chan_config, &channel));
|
||||
TEST_ESP_OK(pcnt_channel_set_edge_action(channel, PCNT_CHANNEL_EDGE_ACTION_INCREASE, PCNT_CHANNEL_EDGE_ACTION_HOLD));
|
||||
TEST_ESP_OK(pcnt_channel_set_level_action(channel, PCNT_CHANNEL_LEVEL_ACTION_KEEP, PCNT_CHANNEL_LEVEL_ACTION_KEEP));
|
||||
|
||||
printf("enable and start unit\r\n");
|
||||
|
||||
TEST_ESP_OK(pcnt_unit_enable(unit));
|
||||
TEST_ESP_OK(pcnt_unit_start(unit));
|
||||
TEST_ESP_OK(gpio_set_level(TEST_PCNT_GPIO_Z, 0));
|
||||
|
||||
// trigger 10 rising edge on GPIO
|
||||
test_gpio_simulate_rising_edge(TEST_PCNT_GPIO_A, 10);
|
||||
|
||||
int count_value = 0;
|
||||
|
||||
TEST_ESP_OK(pcnt_unit_get_count(unit, &count_value));
|
||||
printf("count_value=%d\r\n", count_value);
|
||||
TEST_ASSERT_EQUAL(10, count_value);
|
||||
|
||||
printf("simulating zero input signal\r\n");
|
||||
TEST_ESP_OK(gpio_set_level(TEST_PCNT_GPIO_Z, 1));
|
||||
TEST_ESP_OK(gpio_set_level(TEST_PCNT_GPIO_Z, 0));
|
||||
|
||||
TEST_ESP_OK(pcnt_unit_get_count(unit, &count_value));
|
||||
printf("count_value=%d\r\n", count_value);
|
||||
TEST_ASSERT_EQUAL(0, count_value); // 0 after rst_sig
|
||||
|
||||
TEST_ESP_OK(pcnt_del_channel(channel));
|
||||
TEST_ESP_OK(pcnt_unit_stop(unit));
|
||||
TEST_ESP_OK(pcnt_unit_disable(unit));
|
||||
TEST_ESP_OK(pcnt_del_unit(unit));
|
||||
}
|
||||
#endif // SOC_PCNT_SUPPORT_ZERO_INPUT
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -11,6 +11,7 @@ extern "C" {
|
||||
|
||||
#define TEST_PCNT_GPIO_A 0
|
||||
#define TEST_PCNT_GPIO_B 2
|
||||
#define TEST_PCNT_GPIO_Z 4
|
||||
|
||||
#if CONFIG_PCNT_ISR_IRAM_SAFE
|
||||
#define TEST_PCNT_CALLBACK_ATTR IRAM_ATTR
|
||||
|
||||
Reference in New Issue
Block a user