diff --git a/components/driver/Kconfig b/components/driver/Kconfig index 1b7cf24aeb..366e5ff831 100644 --- a/components/driver/Kconfig +++ b/components/driver/Kconfig @@ -279,4 +279,15 @@ menu "Driver configurations" Note that, this option only controls the PCNT driver log, won't affect other drivers. endmenu # PCNT Configuration + menu "RMT Configuration" + depends on SOC_RMT_SUPPORTED + config RMT_SUPPRESS_DEPRECATE_WARN + bool "Suppress legacy driver deprecated warning" + default n + help + Wether to suppress the deprecation warnings when using legacy rmt driver (driver/rmt.h). + If you want to continue using the legacy driver, and don't want to see related deprecation warnings, + you can enable this option. + endmenu # RMT Configuration + endmenu # Driver configurations diff --git a/components/driver/include/driver/rmt.h b/components/driver/deprecated/driver/rmt.h similarity index 71% rename from components/driver/include/driver/rmt.h rename to components/driver/deprecated/driver/rmt.h index 6d3aa286ac..c99bde31be 100644 --- a/components/driver/include/driver/rmt.h +++ b/components/driver/deprecated/driver/rmt.h @@ -6,281 +6,22 @@ #pragma once -#include #include +#include +#include "sdkconfig.h" #include "esp_err.h" -#include "soc/soc_caps.h" -#include "soc/clk_tree_defs.h" -#include "driver/gpio.h" #include "freertos/FreeRTOS.h" #include "freertos/ringbuf.h" -#include "hal/rmt_types.h" +#include "driver/rmt_types_legacy.h" + +#if !CONFIG_RMT_SUPPRESS_DEPRECATE_WARN +#warning "The legacy RMT driver is deprecated, please use driver/rmt_tx.h and/or driver/rmt_rx.h" +#endif #ifdef __cplusplus extern "C" { #endif -#define RMT_CHANNEL_FLAGS_AWARE_DFS (1 << 0) /*!< Channel can work during APB clock scaling */ -#define RMT_CHANNEL_FLAGS_INVERT_SIG (1 << 1) /*!< Invert RMT signal */ - -/** @cond */ -#define RMT_CHANNEL_FLAGS_ALWAYS_ON RMT_CHANNEL_FLAGS_AWARE_DFS /*!< Deprecated name, defined here for compatibility */ -/** @endcond */ - -/** - * @brief Define memory space of each RMT channel (in words = 4 bytes) - * - */ -#define RMT_MEM_ITEM_NUM SOC_RMT_MEM_WORDS_PER_CHANNEL - -/** - * @brief Definition of RMT item - */ -typedef struct { - union { - struct { - uint32_t duration0 : 15; /*!< Duration of level0 */ - uint32_t level0 : 1; /*!< Level of the first part */ - uint32_t duration1 : 15; /*!< Duration of level1 */ - uint32_t level1 : 1; /*!< Level of the second part */ - }; - uint32_t val; /*!< Equivalent unsigned value for the RMT item */ - }; -} rmt_item32_t; - -/** - * @brief RMT hardware memory layout - */ -typedef struct { - struct { - volatile rmt_item32_t data32[SOC_RMT_MEM_WORDS_PER_CHANNEL]; - } chan[SOC_RMT_CHANNELS_PER_GROUP]; -} rmt_mem_t; - -/** -* @brief RMT channel ID -* -*/ -typedef enum { - RMT_CHANNEL_0, /*!< RMT channel number 0 */ - RMT_CHANNEL_1, /*!< RMT channel number 1 */ - RMT_CHANNEL_2, /*!< RMT channel number 2 */ - RMT_CHANNEL_3, /*!< RMT channel number 3 */ -#if SOC_RMT_CHANNELS_PER_GROUP > 4 - RMT_CHANNEL_4, /*!< RMT channel number 4 */ - RMT_CHANNEL_5, /*!< RMT channel number 5 */ - RMT_CHANNEL_6, /*!< RMT channel number 6 */ - RMT_CHANNEL_7, /*!< RMT channel number 7 */ -#endif - RMT_CHANNEL_MAX /*!< Number of RMT channels */ -} rmt_channel_t; - -/** - * @brief RMT Internal Memory Owner - * - */ -typedef enum { - RMT_MEM_OWNER_TX, /*!< RMT RX mode, RMT transmitter owns the memory block*/ - RMT_MEM_OWNER_RX, /*!< RMT RX mode, RMT receiver owns the memory block*/ - RMT_MEM_OWNER_MAX, -} rmt_mem_owner_t; - -/** - * @brief Clock Source of RMT Channel - * - */ -typedef soc_periph_rmt_clk_src_legacy_t rmt_source_clk_t; - -/** - * @brief RMT Data Mode - * - * @note We highly recommended to use MEM mode not FIFO mode since there will be some gotcha in FIFO mode. - * - */ -typedef enum { - RMT_DATA_MODE_FIFO, /* +#include "soc/soc_caps.h" +#include "soc/clk_tree_defs.h" +#include "driver/gpio.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#define RMT_CHANNEL_FLAGS_AWARE_DFS (1 << 0) /*!< Channel can work during APB clock scaling */ +#define RMT_CHANNEL_FLAGS_INVERT_SIG (1 << 1) /*!< Invert RMT signal */ +#define RMT_CHANNEL_FLAGS_ALWAYS_ON _Pragma ("GCC warning \"'RMT_CHANNEL_FLAGS_ALWAYS_ON' macro is deprecated\"") RMT_CHANNEL_FLAGS_AWARE_DFS + +/** + * @brief Define memory space of each RMT channel (in words = 4 bytes) + * + */ +#define RMT_MEM_ITEM_NUM SOC_RMT_MEM_WORDS_PER_CHANNEL + +/** + * @brief Definition of RMT item + */ +typedef struct { + union { + struct { + uint32_t duration0 : 15; /*!< Duration of level0 */ + uint32_t level0 : 1; /*!< Level of the first part */ + uint32_t duration1 : 15; /*!< Duration of level1 */ + uint32_t level1 : 1; /*!< Level of the second part */ + }; + uint32_t val; /*!< Equivalent unsigned value for the RMT item */ + }; +} rmt_item32_t; + +/** + * @brief RMT hardware memory layout + */ +typedef struct { + struct { + volatile rmt_item32_t data32[SOC_RMT_MEM_WORDS_PER_CHANNEL]; + } chan[SOC_RMT_CHANNELS_PER_GROUP]; +} rmt_mem_t; + +/** +* @brief RMT channel ID +* +*/ +typedef enum { + RMT_CHANNEL_0, /*!< RMT channel number 0 */ + RMT_CHANNEL_1, /*!< RMT channel number 1 */ + RMT_CHANNEL_2, /*!< RMT channel number 2 */ + RMT_CHANNEL_3, /*!< RMT channel number 3 */ +#if SOC_RMT_CHANNELS_PER_GROUP > 4 + RMT_CHANNEL_4, /*!< RMT channel number 4 */ + RMT_CHANNEL_5, /*!< RMT channel number 5 */ + RMT_CHANNEL_6, /*!< RMT channel number 6 */ + RMT_CHANNEL_7, /*!< RMT channel number 7 */ +#endif + RMT_CHANNEL_MAX /*!< Number of RMT channels */ +} rmt_channel_t; + +/** + * @brief RMT Internal Memory Owner + * + */ +typedef enum { + RMT_MEM_OWNER_TX, /*!< RMT RX mode, RMT transmitter owns the memory block*/ + RMT_MEM_OWNER_RX, /*!< RMT RX mode, RMT receiver owns the memory block*/ + RMT_MEM_OWNER_MAX, +} rmt_mem_owner_t; + +/** + * @brief Clock Source of RMT Channel + * + */ +typedef soc_periph_rmt_clk_src_legacy_t rmt_source_clk_t; + +/** + * @brief RMT Data Mode + * + * @note We highly recommended to use MEM mode not FIFO mode since there will be some gotcha in FIFO mode. + * + */ +typedef enum { + RMT_DATA_MODE_FIFO, /* +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include "esp_log.h" #include "ir_tools.h" diff --git a/examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_builder_rmt_rc5.c b/components/driver/test_apps/legacy_rmt_driver/components/infrared_tools/src/ir_builder_rmt_rc5.c similarity index 92% rename from examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_builder_rmt_rc5.c rename to components/driver/test_apps/legacy_rmt_driver/components/infrared_tools/src/ir_builder_rmt_rc5.c index 7063961abf..9160779cea 100644 --- a/examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_builder_rmt_rc5.c +++ b/components/driver/test_apps/legacy_rmt_driver/components/infrared_tools/src/ir_builder_rmt_rc5.c @@ -1,16 +1,8 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include #include "esp_log.h" diff --git a/examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_parser_rmt_nec.c b/components/driver/test_apps/legacy_rmt_driver/components/infrared_tools/src/ir_parser_rmt_nec.c similarity index 92% rename from examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_parser_rmt_nec.c rename to components/driver/test_apps/legacy_rmt_driver/components/infrared_tools/src/ir_parser_rmt_nec.c index cddeabbad8..715997dabd 100644 --- a/examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_parser_rmt_nec.c +++ b/components/driver/test_apps/legacy_rmt_driver/components/infrared_tools/src/ir_parser_rmt_nec.c @@ -1,16 +1,8 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include #include "esp_log.h" diff --git a/examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_parser_rmt_rc5.c b/components/driver/test_apps/legacy_rmt_driver/components/infrared_tools/src/ir_parser_rmt_rc5.c similarity index 90% rename from examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_parser_rmt_rc5.c rename to components/driver/test_apps/legacy_rmt_driver/components/infrared_tools/src/ir_parser_rmt_rc5.c index ede3b4290b..fa5eabdc8d 100644 --- a/examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_parser_rmt_rc5.c +++ b/components/driver/test_apps/legacy_rmt_driver/components/infrared_tools/src/ir_parser_rmt_rc5.c @@ -1,16 +1,8 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include #include "esp_log.h" diff --git a/components/driver/test_apps/legacy_rmt_driver/main/CMakeLists.txt b/components/driver/test_apps/legacy_rmt_driver/main/CMakeLists.txt new file mode 100644 index 0000000000..f8bd38290a --- /dev/null +++ b/components/driver/test_apps/legacy_rmt_driver/main/CMakeLists.txt @@ -0,0 +1,5 @@ +set(srcs "test_app_main.c" + "test_legacy_rmt.c") + +idf_component_register(SRCS ${srcs} + WHOLE_ARCHIVE) diff --git a/components/driver/test_apps/legacy_rmt_driver/main/test_app_main.c b/components/driver/test_apps/legacy_rmt_driver/main/test_app_main.c new file mode 100644 index 0000000000..183a88ae3c --- /dev/null +++ b/components/driver/test_apps/legacy_rmt_driver/main/test_app_main.c @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "unity.h" +#include "unity_test_runner.h" +#include "esp_heap_caps.h" + +#define TEST_MEMORY_LEAK_THRESHOLD (-600) + +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); + before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); +} + +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"); +} + +void app_main(void) +{ + unity_run_menu(); +} diff --git a/components/driver/test/test_rmt.c b/components/driver/test_apps/legacy_rmt_driver/main/test_legacy_rmt.c similarity index 99% rename from components/driver/test/test_rmt.c rename to components/driver/test_apps/legacy_rmt_driver/main/test_legacy_rmt.c index aeff44a124..cb3b005ba3 100644 --- a/components/driver/test/test_rmt.c +++ b/components/driver/test_apps/legacy_rmt_driver/main/test_legacy_rmt.c @@ -3,7 +3,6 @@ * * SPDX-License-Identifier: Apache-2.0 */ -// RMT driver unit test is based on extended NEC protocol #include #include @@ -14,10 +13,8 @@ #include "freertos/task.h" #include "esp_log.h" #include "unity.h" -#include "test_utils.h" #include "esp_rom_gpio.h" -#if SOC_RMT_SUPPORTED #include "ir_tools.h" #include "driver/rmt.h" @@ -32,6 +29,7 @@ #define RMT_TESTBENCH_FLAGS_LOOP_ON (1<<2) static const char *TAG = "RMT.test"; + static ir_builder_t *s_ir_builder = NULL; static ir_parser_t *s_ir_parser = NULL; @@ -598,5 +596,3 @@ TEST_CASE("RMT TX loop", "[rmt]") rmt_clean_testbench(tx_channel, rx_channel); } #endif - -#endif // SOC_RMT_SUPPORTED diff --git a/components/driver/test_apps/legacy_rmt_driver/pytest_legacy_rmt_driver.py b/components/driver/test_apps/legacy_rmt_driver/pytest_legacy_rmt_driver.py new file mode 100644 index 0000000000..84b97179c9 --- /dev/null +++ b/components/driver/test_apps/legacy_rmt_driver/pytest_legacy_rmt_driver.py @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32 +@pytest.mark.esp32s2 +@pytest.mark.esp32s3 +@pytest.mark.esp32c3 +@pytest.mark.generic +@pytest.mark.parametrize('config', [ + 'release', +], indirect=True) +def test_legacy_rmt(dut: Dut) -> None: + dut.expect('Press ENTER to see the list of tests') + dut.write('*') + dut.expect_unity_test_output(timeout=120) diff --git a/components/driver/test_apps/legacy_rmt_driver/sdkconfig.ci.release b/components/driver/test_apps/legacy_rmt_driver/sdkconfig.ci.release new file mode 100644 index 0000000000..91d93f163e --- /dev/null +++ b/components/driver/test_apps/legacy_rmt_driver/sdkconfig.ci.release @@ -0,0 +1,5 @@ +CONFIG_PM_ENABLE=y +CONFIG_FREERTOS_USE_TICKLESS_IDLE=y +CONFIG_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y diff --git a/components/driver/test_apps/legacy_rmt_driver/sdkconfig.defaults b/components/driver/test_apps/legacy_rmt_driver/sdkconfig.defaults new file mode 100644 index 0000000000..c16b1aed99 --- /dev/null +++ b/components/driver/test_apps/legacy_rmt_driver/sdkconfig.defaults @@ -0,0 +1,3 @@ +CONFIG_FREERTOS_HZ=1000 +CONFIG_ESP_TASK_WDT=n +CONFIG_RMT_SUPPRESS_DEPRECATE_WARN=y diff --git a/examples/peripherals/rmt/ir_protocols/components/infrared_tools/include/ir_timings.h b/examples/peripherals/rmt/ir_protocols/components/infrared_tools/include/ir_timings.h deleted file mode 100644 index 2325059c2f..0000000000 --- a/examples/peripherals/rmt/ir_protocols/components/infrared_tools/include/ir_timings.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Timings for NEC protocol - * - */ -#define NEC_LEADING_CODE_HIGH_US (9000) -#define NEC_LEADING_CODE_LOW_US (4500) -#define NEC_PAYLOAD_ONE_HIGH_US (560) -#define NEC_PAYLOAD_ONE_LOW_US (1690) -#define NEC_PAYLOAD_ZERO_HIGH_US (560) -#define NEC_PAYLOAD_ZERO_LOW_US (560) -#define NEC_REPEAT_CODE_HIGH_US (9000) -#define NEC_REPEAT_CODE_LOW_US (2250) -#define NEC_ENDING_CODE_HIGH_US (560) - -/** - * @brief Timings for RC5 protocol - * - */ -#define RC5_PULSE_DURATION_US (889) - -#ifdef __cplusplus -} -#endif diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 7284511f4d..94a8e6b6b6 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -2073,11 +2073,6 @@ examples/peripherals/mcpwm/mcpwm_brushed_dc_control/main/mcpwm_brushed_dc_contro examples/peripherals/mcpwm/mcpwm_capture_hc_sr04/main/mcpwm_capture_hc_sr04.c examples/peripherals/mcpwm/mcpwm_servo_control/main/mcpwm_servo_control_example_main.c examples/peripherals/mcpwm/mcpwm_sync_example/main/mcpwm_sync_example.c -examples/peripherals/rmt/ir_protocols/components/infrared_tools/include/ir_timings.h -examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_builder_rmt_nec.c -examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_builder_rmt_rc5.c -examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_parser_rmt_nec.c -examples/peripherals/rmt/ir_protocols/components/infrared_tools/src/ir_parser_rmt_rc5.c examples/peripherals/rmt/ir_protocols/example_test.py examples/peripherals/rmt/ir_protocols/main/ir_protocols_main.c examples/peripherals/rmt/led_strip/main/led_strip_main.c diff --git a/tools/unit-test-app/CMakeLists.txt b/tools/unit-test-app/CMakeLists.txt index 24351c17bc..0db4c32b4a 100644 --- a/tools/unit-test-app/CMakeLists.txt +++ b/tools/unit-test-app/CMakeLists.txt @@ -2,8 +2,7 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) -list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/examples/cxx/experimental/experimental_cpp_component/" - "$ENV{IDF_PATH}/examples/peripherals/rmt/ir_protocols/components") +list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/examples/cxx/experimental/experimental_cpp_component/") include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(unit-test-app) diff --git a/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c b/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c index 0c7225befc..14ce9dc992 100644 --- a/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c +++ b/tools/unit-test-app/components/test_utils/ref_clock_impl_rmt_pcnt.c @@ -25,8 +25,8 @@ #include "freertos/FreeRTOS.h" #include "esp_intr_alloc.h" #include "esp_private/periph_ctrl.h" -#include "driver/rmt.h" #include "driver/pulse_cnt.h" +#include "driver/rmt_types_legacy.h" #include "soc/gpio_sig_map.h" #include "soc/gpio_periph.h" #include "soc/soc_caps.h"