From 17808b3ff883d18c87ff45f221a02e055057ad6f Mon Sep 17 00:00:00 2001 From: morris Date: Thu, 22 Oct 2020 13:16:49 +0800 Subject: [PATCH] sigma_delta: add periph signal list and support esp32-s3 --- components/driver/sigmadelta.c | 6 +- components/driver/test/test_sigmadelta.c | 64 +++++-------------- .../hal/esp32s3/include/hal/sigmadelta_ll.h | 2 +- components/hal/include/hal/sigmadelta_types.h | 4 +- components/soc/esp32/CMakeLists.txt | 1 + components/soc/esp32/include/soc/soc_caps.h | 4 +- components/soc/esp32/sigmadelta_periph.c | 45 +++++++++++++ components/soc/esp32s2/CMakeLists.txt | 1 + components/soc/esp32s2/include/soc/soc_caps.h | 4 +- components/soc/esp32s2/sigmadelta_periph.c | 45 +++++++++++++ components/soc/esp32s3/CMakeLists.txt | 1 + .../soc/esp32s3/include/soc/sigmadelta_caps.h | 25 -------- components/soc/esp32s3/include/soc/soc_caps.h | 3 +- components/soc/esp32s3/sigmadelta_periph.c | 45 +++++++++++++ .../soc/include/soc/sigmadelta_periph.h | 21 +++++- 15 files changed, 188 insertions(+), 83 deletions(-) create mode 100644 components/soc/esp32/sigmadelta_periph.c create mode 100644 components/soc/esp32s2/sigmadelta_periph.c delete mode 100644 components/soc/esp32s3/include/soc/sigmadelta_caps.h create mode 100644 components/soc/esp32s3/sigmadelta_periph.c diff --git a/components/driver/sigmadelta.c b/components/driver/sigmadelta.c index d2e480dc89..043a996fba 100644 --- a/components/driver/sigmadelta.c +++ b/components/driver/sigmadelta.c @@ -19,7 +19,7 @@ #include "hal/sigmadelta_hal.h" #include "esp_rom_gpio.h" -static const char *TAG = "SIGMADELTA"; +static const char *TAG = "sigma-delta"; #define SIGMADELTA_CHECK(a,str,ret_val) if(!(a)) { \ ESP_LOGE(TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \ @@ -40,7 +40,7 @@ static sigmadelta_obj_t *p_sigmadelta_obj[SIGMADELTA_PORT_MAX] = {0}; static inline esp_err_t _sigmadelta_set_duty(sigmadelta_port_t sigmadelta_port, sigmadelta_channel_t channel, int8_t duty) { SIGMADELTA_OBJ_CHECK(sigmadelta_port); - + sigmadelta_hal_set_duty(&(p_sigmadelta_obj[sigmadelta_port]->hal), channel, duty); return ESP_OK; } @@ -59,7 +59,7 @@ static inline esp_err_t _sigmadelta_set_pin(sigmadelta_port_t sigmadelta_port, s PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[gpio_num], PIN_FUNC_GPIO); gpio_set_direction(gpio_num, GPIO_MODE_OUTPUT); - esp_rom_gpio_connect_out_signal(gpio_num, GPIO_SD0_OUT_IDX + channel, 0, 0); + esp_rom_gpio_connect_out_signal(gpio_num, sigma_delta_periph_signals.channels[channel].sd_sig, 0, 0); return ESP_OK; } diff --git a/components/driver/test/test_sigmadelta.c b/components/driver/test/test_sigmadelta.c index 592e893d71..d0a1856ac3 100644 --- a/components/driver/test/test_sigmadelta.c +++ b/components/driver/test/test_sigmadelta.c @@ -1,60 +1,32 @@ -/* - * Sigamadelta Test: - * 1. basic configuration test - * 2. pin, duty, prescale test - */ -#include "unity.h" -#include "test_utils.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#include "unity.h" +#include "test_utils.h" +#include "soc/soc_caps.h" #include "driver/sigmadelta.h" -#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S3) - -TEST_CASE("SigmaDelta config test", "[sigma_delta]") +TEST_CASE("Sigma-Delta config test", "[sigma_delta]") { sigmadelta_config_t sigmadelta_cfg = { - .channel = SIGMADELTA_CHANNEL_0, .sigmadelta_prescale = 80, .sigmadelta_duty = 45, .sigmadelta_gpio = 4, }; - TEST_ESP_OK(sigmadelta_config(&sigmadelta_cfg)); - - sigmadelta_cfg.channel = SIGMADELTA_CHANNEL_1; - TEST_ESP_OK(sigmadelta_config(&sigmadelta_cfg)); - - sigmadelta_cfg.channel = SIGMADELTA_CHANNEL_2; - TEST_ESP_OK(sigmadelta_config(&sigmadelta_cfg)); - - sigmadelta_cfg.channel = SIGMADELTA_CHANNEL_3; - TEST_ESP_OK(sigmadelta_config(&sigmadelta_cfg)); - - sigmadelta_cfg.channel = SIGMADELTA_CHANNEL_4; - TEST_ESP_OK(sigmadelta_config(&sigmadelta_cfg)); - - sigmadelta_cfg.channel = SIGMADELTA_CHANNEL_5; - TEST_ESP_OK(sigmadelta_config(&sigmadelta_cfg)); - - sigmadelta_cfg.channel = SIGMADELTA_CHANNEL_6; - TEST_ESP_OK(sigmadelta_config(&sigmadelta_cfg)); - - sigmadelta_cfg.channel = SIGMADELTA_CHANNEL_7; - TEST_ESP_OK(sigmadelta_config(&sigmadelta_cfg)); - - //ERROR PARAM - sigmadelta_cfg.channel = SIGMADELTA_CHANNEL_MAX; - TEST_ASSERT(sigmadelta_config(&sigmadelta_cfg) == ESP_ERR_INVALID_ARG); + for (int i = 0; i < SOC_SIGMADELTA_CHANNEL_NUM; i++) { + sigmadelta_cfg.channel = i; + TEST_ESP_OK(sigmadelta_config(&sigmadelta_cfg)); + } + sigmadelta_cfg.channel = SOC_SIGMADELTA_CHANNEL_NUM; + TEST_ASSERT_EQUAL_MESSAGE(ESP_ERR_INVALID_ARG, sigmadelta_config(&sigmadelta_cfg), "wrong channel number should be inspected"); } // connect GPIO4 with LED positive pin, and the GND pin connect LED negative pin // logic analyzer help also to see the wave form(more standard and accurate) -// can't test it in CI, ignore TEST_CASE("SigmaDelta pin, duty, prescale set", "[sigma_delta][ignore]") { sigmadelta_config_t sigmadelta_cfg = { - .channel = SIGMADELTA_CHANNEL_0, + .channel = 0, .sigmadelta_prescale = 80, .sigmadelta_duty = 0, .sigmadelta_gpio = 4, @@ -63,8 +35,8 @@ TEST_CASE("SigmaDelta pin, duty, prescale set", "[sigma_delta][ignore]") int8_t duty = 0; int inc = 1; - for(int i=0; i<1000; i++) { - sigmadelta_set_duty(SIGMADELTA_CHANNEL_0, duty); + for (int i = 0; i < 1000; i++) { + sigmadelta_set_duty(0, duty); vTaskDelay(10 / portTICK_PERIOD_MS); duty += inc; @@ -73,9 +45,9 @@ TEST_CASE("SigmaDelta pin, duty, prescale set", "[sigma_delta][ignore]") } } - TEST_ESP_OK(sigmadelta_set_prescale(SIGMADELTA_CHANNEL_0, 200)); - for(int i=0; i<1000; i++) { - sigmadelta_set_duty(SIGMADELTA_CHANNEL_0, duty); + TEST_ESP_OK(sigmadelta_set_prescale(0, 200)); + for (int i = 0; i < 1000; i++) { + sigmadelta_set_duty(0, duty); vTaskDelay(10 / portTICK_PERIOD_MS); duty += inc; @@ -84,8 +56,6 @@ TEST_CASE("SigmaDelta pin, duty, prescale set", "[sigma_delta][ignore]") } } - TEST_ESP_OK(sigmadelta_set_pin(SIGMADELTA_CHANNEL_0, 5)); + TEST_ESP_OK(sigmadelta_set_pin(0, 5)); vTaskDelay(3000 / portTICK_PERIOD_MS); } - -#endif diff --git a/components/hal/esp32s3/include/hal/sigmadelta_ll.h b/components/hal/esp32s3/include/hal/sigmadelta_ll.h index 2e605ee594..16f7af6862 100644 --- a/components/hal/esp32s3/include/hal/sigmadelta_ll.h +++ b/components/hal/esp32s3/include/hal/sigmadelta_ll.h @@ -40,7 +40,7 @@ extern "C" { */ static inline void sigmadelta_ll_set_en(gpio_sd_dev_t *hw, bool en) { - // The clk enable register does not exist on ESP32. + hw->misc.function_clk_en = en; } /** diff --git a/components/hal/include/hal/sigmadelta_types.h b/components/hal/include/hal/sigmadelta_types.h index e4dce6fbe6..81023905d6 100644 --- a/components/hal/include/hal/sigmadelta_types.h +++ b/components/hal/include/hal/sigmadelta_types.h @@ -38,10 +38,12 @@ typedef enum { SIGMADELTA_CHANNEL_1, /*!< Sigma-delta channel 1 */ SIGMADELTA_CHANNEL_2, /*!< Sigma-delta channel 2 */ SIGMADELTA_CHANNEL_3, /*!< Sigma-delta channel 3 */ +#if SOC_SIGMADELTA_CHANNEL_NUM > 4 SIGMADELTA_CHANNEL_4, /*!< Sigma-delta channel 4 */ SIGMADELTA_CHANNEL_5, /*!< Sigma-delta channel 5 */ SIGMADELTA_CHANNEL_6, /*!< Sigma-delta channel 6 */ SIGMADELTA_CHANNEL_7, /*!< Sigma-delta channel 7 */ +#endif SIGMADELTA_CHANNEL_MAX, /*!< Sigma-delta channel max */ } sigmadelta_channel_t; @@ -57,4 +59,4 @@ typedef struct { #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/components/soc/esp32/CMakeLists.txt b/components/soc/esp32/CMakeLists.txt index 024eb92ce4..b708c824a4 100644 --- a/components/soc/esp32/CMakeLists.txt +++ b/components/soc/esp32/CMakeLists.txt @@ -11,6 +11,7 @@ set(srcs "rtc_periph.c" "sdio_slave_periph.c" "sdmmc_periph.c" + "sigmadelta_periph.c" "soc_memory_layout.c" "spi_periph.c" "touch_sensor_periph.c" diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index 76d778e71c..8bba5ad293 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -166,8 +166,8 @@ #define SOC_RTCIO_PIN_COUNT 18 /*-------------------------- SIGMA DELTA CAPS --------------------------------*/ -// ESP32 have 1 SIGMADELTA peripheral. -#define SOC_SIGMADELTA_NUM 1 +#define SOC_SIGMADELTA_NUM (1) // 1 sigma-delta peripheral +#define SOC_SIGMADELTA_CHANNEL_NUM (8) // 8 channels /*-------------------------- SPI CAPS ----------------------------------------*/ #define SOC_SPI_PERIPH_NUM 3 diff --git a/components/soc/esp32/sigmadelta_periph.c b/components/soc/esp32/sigmadelta_periph.c new file mode 100644 index 0000000000..9dbab7673d --- /dev/null +++ b/components/soc/esp32/sigmadelta_periph.c @@ -0,0 +1,45 @@ +// Copyright 2020 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. + +#include "soc/sigmadelta_periph.h" +#include "soc/gpio_sig_map.h" + +const sigma_delta_signal_conn_t sigma_delta_periph_signals = { + .channels = { + [0] = { + GPIO_SD0_OUT_IDX + }, + [1] = { + GPIO_SD1_OUT_IDX + }, + [2] = { + GPIO_SD2_OUT_IDX + }, + [3] = { + GPIO_SD3_OUT_IDX + }, + [4] = { + GPIO_SD4_OUT_IDX + }, + [5] = { + GPIO_SD5_OUT_IDX + }, + [6] = { + GPIO_SD6_OUT_IDX + }, + [7] = { + GPIO_SD7_OUT_IDX + } + } +}; diff --git a/components/soc/esp32s2/CMakeLists.txt b/components/soc/esp32s2/CMakeLists.txt index c44629d0e6..e8010f9d52 100644 --- a/components/soc/esp32s2/CMakeLists.txt +++ b/components/soc/esp32s2/CMakeLists.txt @@ -10,6 +10,7 @@ set(srcs "pcnt_periph.c" "rtc_io_periph.c" "rtc_periph.c" + "sigmadelta_periph.c" "soc_memory_layout.c" "spi_periph.c" "touch_sensor_periph.c" diff --git a/components/soc/esp32s2/include/soc/soc_caps.h b/components/soc/esp32s2/include/soc/soc_caps.h index 1dfc101d13..942707d58c 100644 --- a/components/soc/esp32s2/include/soc/soc_caps.h +++ b/components/soc/esp32s2/include/soc/soc_caps.h @@ -154,8 +154,8 @@ #define SOC_RTCIO_PIN_COUNT 22 /*-------------------------- SIGMA DELTA CAPS --------------------------------*/ -// ESP32-S2 have 1 SIGMADELTA peripheral. -#define SOC_SIGMADELTA_NUM 1 +#define SOC_SIGMADELTA_NUM (1) // 1 sigma-delta peripheral +#define SOC_SIGMADELTA_CHANNEL_NUM (8) // 8 channels /*-------------------------- SPI CAPS ----------------------------------------*/ #define SOC_SPI_PERIPH_NUM 3 diff --git a/components/soc/esp32s2/sigmadelta_periph.c b/components/soc/esp32s2/sigmadelta_periph.c new file mode 100644 index 0000000000..9dbab7673d --- /dev/null +++ b/components/soc/esp32s2/sigmadelta_periph.c @@ -0,0 +1,45 @@ +// Copyright 2020 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. + +#include "soc/sigmadelta_periph.h" +#include "soc/gpio_sig_map.h" + +const sigma_delta_signal_conn_t sigma_delta_periph_signals = { + .channels = { + [0] = { + GPIO_SD0_OUT_IDX + }, + [1] = { + GPIO_SD1_OUT_IDX + }, + [2] = { + GPIO_SD2_OUT_IDX + }, + [3] = { + GPIO_SD3_OUT_IDX + }, + [4] = { + GPIO_SD4_OUT_IDX + }, + [5] = { + GPIO_SD5_OUT_IDX + }, + [6] = { + GPIO_SD6_OUT_IDX + }, + [7] = { + GPIO_SD7_OUT_IDX + } + } +}; diff --git a/components/soc/esp32s3/CMakeLists.txt b/components/soc/esp32s3/CMakeLists.txt index 86e7dc8597..440b92a2be 100644 --- a/components/soc/esp32s3/CMakeLists.txt +++ b/components/soc/esp32s3/CMakeLists.txt @@ -12,6 +12,7 @@ set(srcs "rtc_periph.c" "sdio_slave_periph.c" "sdmmc_periph.c" + "sigmadelta_periph.c" "soc_memory_layout.c" "spi_periph.c" "touch_sensor_periph.c" diff --git a/components/soc/esp32s3/include/soc/sigmadelta_caps.h b/components/soc/esp32s3/include/soc/sigmadelta_caps.h deleted file mode 100644 index 0aa44b707f..0000000000 --- a/components/soc/esp32s3/include/soc/sigmadelta_caps.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015-2020 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 - -// ESP32-S3 have 1 SIGMADELTA peripheral. -#define SOC_SIGMADELTA_NUM (SIGMADELTA_PORT_MAX) - -#ifdef __cplusplus -} -#endif diff --git a/components/soc/esp32s3/include/soc/soc_caps.h b/components/soc/esp32s3/include/soc/soc_caps.h index 3c73576f80..0575dd4dbb 100644 --- a/components/soc/esp32s3/include/soc/soc_caps.h +++ b/components/soc/esp32s3/include/soc/soc_caps.h @@ -59,7 +59,8 @@ #include "rtc_io_caps.h" /*-------------------------- SIGMA DELTA CAPS --------------------------------*/ -#include "sigmadelta_caps.h" +#define SOC_SIGMADELTA_NUM (1) // 1 sigma-delta peripheral +#define SOC_SIGMADELTA_CHANNEL_NUM (8) // 8 channels /*-------------------------- SPI CAPS ----------------------------------------*/ #include "spi_caps.h" diff --git a/components/soc/esp32s3/sigmadelta_periph.c b/components/soc/esp32s3/sigmadelta_periph.c new file mode 100644 index 0000000000..9dbab7673d --- /dev/null +++ b/components/soc/esp32s3/sigmadelta_periph.c @@ -0,0 +1,45 @@ +// Copyright 2020 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. + +#include "soc/sigmadelta_periph.h" +#include "soc/gpio_sig_map.h" + +const sigma_delta_signal_conn_t sigma_delta_periph_signals = { + .channels = { + [0] = { + GPIO_SD0_OUT_IDX + }, + [1] = { + GPIO_SD1_OUT_IDX + }, + [2] = { + GPIO_SD2_OUT_IDX + }, + [3] = { + GPIO_SD3_OUT_IDX + }, + [4] = { + GPIO_SD4_OUT_IDX + }, + [5] = { + GPIO_SD5_OUT_IDX + }, + [6] = { + GPIO_SD6_OUT_IDX + }, + [7] = { + GPIO_SD7_OUT_IDX + } + } +}; diff --git a/components/soc/include/soc/sigmadelta_periph.h b/components/soc/include/soc/sigmadelta_periph.h index 63ec3a41d9..75e723c7d8 100644 --- a/components/soc/include/soc/sigmadelta_periph.h +++ b/components/soc/include/soc/sigmadelta_periph.h @@ -13,5 +13,24 @@ // limitations under the License. #pragma once -#include "soc/gpio_sd_struct.h" + +#include +#include "soc/soc_caps.h" #include "soc/gpio_sd_reg.h" +#include "soc/gpio_sd_struct.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + struct { + const uint32_t sd_sig; + } channels[SOC_SIGMADELTA_CHANNEL_NUM]; +} sigma_delta_signal_conn_t; + +extern const sigma_delta_signal_conn_t sigma_delta_periph_signals; + +#ifdef __cplusplus +} +#endif \ No newline at end of file