mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
Merge branch 'feature/h2_gpio_hysteresis_support' into 'master'
gpio: h2 support input hysteresis filter Closes IDF-6653 See merge request espressif/esp-idf!22263
This commit is contained in:
@@ -12,6 +12,10 @@ if(CONFIG_SOC_SDM_SUPPORTED)
|
||||
list(APPEND srcs "test_sdm.c")
|
||||
endif()
|
||||
|
||||
if(CONFIG_SOC_GPIO_SUPPORT_PIN_HYS_FILTER)
|
||||
list(APPEND srcs "test_hysteresis.c")
|
||||
endif()
|
||||
|
||||
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
|
||||
# the component can be registered as WHOLE_ARCHIVE
|
||||
idf_component_register(SRCS ${srcs}
|
||||
|
@@ -1,26 +1,19 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include "unity_test_runner.h"
|
||||
#include "unity_test_utils.h"
|
||||
#include "esp_heap_caps.h"
|
||||
|
||||
// Some resources are lazy allocated in the driver, the threshold is left for that case
|
||||
#define TEST_MEMORY_LEAK_THRESHOLD (-300)
|
||||
#define TEST_MEMORY_LEAK_THRESHOLD (300)
|
||||
|
||||
static size_t before_free_8bit;
|
||||
static size_t before_free_32bit;
|
||||
|
||||
static void check_leak(size_t before_free, size_t after_free, const char *type)
|
||||
{
|
||||
ssize_t delta = after_free - before_free;
|
||||
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
|
||||
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
|
||||
}
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
@@ -31,8 +24,9 @@ void tearDown(void)
|
||||
{
|
||||
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||
check_leak(before_free_8bit, after_free_8bit, "8BIT");
|
||||
check_leak(before_free_32bit, after_free_32bit, "32BIT");
|
||||
printf("\n");
|
||||
unity_utils_check_leak(before_free_8bit, after_free_8bit, "8BIT", TEST_MEMORY_LEAK_THRESHOLD);
|
||||
unity_utils_check_leak(before_free_32bit, after_free_32bit, "32BIT", TEST_MEMORY_LEAK_THRESHOLD);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
|
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "unity.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
|
||||
/**
|
||||
* NOTE: To run this special feature test case, a slope analog signal is needed.
|
||||
* A simple RC circuit used here to formate pin switches to continuos slop signal.
|
||||
*
|
||||
* +---------+
|
||||
* | |
|
||||
* | (intr)26|----------------+ C:1000uF
|
||||
* | | | ++ +
|
||||
* | (wave)27|______+-----+___+___|| |_____
|
||||
* | | +-----+ || | |
|
||||
* | ESP32 | R:10k ++ + |
|
||||
* | | |
|
||||
* | GND|------------------------------+
|
||||
* +---------+
|
||||
*
|
||||
* or you can connect your slop signals from signal generator to ESP32 pin
|
||||
* which enabled the hysteresis feature directly to have a test.
|
||||
**/
|
||||
|
||||
|
||||
static void test_gpio_hysteresis_intr_handler(void *args)
|
||||
{
|
||||
esp_rom_printf("%d\n", ++*((uint32_t *)args));
|
||||
}
|
||||
|
||||
// This case is now tested only manually
|
||||
TEST_CASE("GPIO Input hysteresis filter", "[gpio_filter][timeout=50][ignore]")
|
||||
{
|
||||
const gpio_num_t TEST_HYS_IO = 26;
|
||||
const gpio_num_t TEST_WAVE_IO = 27;
|
||||
uint32_t intr_cnt=0;
|
||||
|
||||
gpio_config_t gpio_cfg = {
|
||||
.pin_bit_mask = 1 << TEST_WAVE_IO,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_down_en = GPIO_PULLDOWN_ENABLE,
|
||||
};
|
||||
TEST_ESP_OK(gpio_config(&gpio_cfg));
|
||||
|
||||
gpio_cfg.pin_bit_mask = 1 << TEST_HYS_IO;
|
||||
gpio_cfg.mode = GPIO_MODE_INPUT;
|
||||
gpio_cfg.intr_type = GPIO_INTR_ANYEDGE;
|
||||
gpio_cfg.hys_ctrl_mode = GPIO_HYS_SOFT_ENABLE;
|
||||
TEST_ESP_OK(gpio_config(&gpio_cfg));
|
||||
|
||||
gpio_install_isr_service(0);
|
||||
gpio_isr_handler_add(TEST_HYS_IO, test_gpio_hysteresis_intr_handler, &intr_cnt);
|
||||
|
||||
// generate 5 rising and falling slopes to test gpio interrupt
|
||||
for (uint8_t i=0; i<5; i++) {
|
||||
printf("----falling %dth\n", i);
|
||||
gpio_set_level(TEST_WAVE_IO, 0);
|
||||
vTaskDelay(1500);
|
||||
printf("----rising %dth\n", i);
|
||||
gpio_set_level(TEST_WAVE_IO, 1);
|
||||
vTaskDelay(1500);
|
||||
}
|
||||
|
||||
gpio_isr_handler_remove(TEST_HYS_IO);
|
||||
gpio_uninstall_isr_service();
|
||||
// should shot ISR exactly 10 times
|
||||
TEST_ASSERT_UINT32_WITHIN(1, 10, intr_cnt);
|
||||
}
|
Reference in New Issue
Block a user