From e4d45608d32152a8e749e488554b185e45462bcf Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 27 Nov 2019 12:11:28 +0100 Subject: [PATCH] soc: add ledc_caps.h, replace target-based ifdefs with caps-based --- components/soc/esp32/include/soc/ledc_caps.h | 24 +++++++++++++++++++ .../soc/esp32s2beta/include/soc/ledc_caps.h | 24 +++++++++++++++++++ components/soc/include/hal/ledc_types.h | 7 +++--- components/soc/include/soc/ledc_periph.h | 9 +++---- components/soc/src/hal/ledc_hal.c | 8 +++---- 5 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 components/soc/esp32/include/soc/ledc_caps.h create mode 100644 components/soc/esp32s2beta/include/soc/ledc_caps.h diff --git a/components/soc/esp32/include/soc/ledc_caps.h b/components/soc/esp32/include/soc/ledc_caps.h new file mode 100644 index 000000000..e7283424b --- /dev/null +++ b/components/soc/esp32/include/soc/ledc_caps.h @@ -0,0 +1,24 @@ +// Copyright 2015-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 + +#define SOC_LEDC_SUPPORT_HS_MODE (1) + +#ifdef __cplusplus +} +#endif diff --git a/components/soc/esp32s2beta/include/soc/ledc_caps.h b/components/soc/esp32s2beta/include/soc/ledc_caps.h new file mode 100644 index 000000000..0600e5812 --- /dev/null +++ b/components/soc/esp32s2beta/include/soc/ledc_caps.h @@ -0,0 +1,24 @@ +// Copyright 2015-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 + +#define SOC_LEDC_SUPPORT_XTAL_CLOCK (1) + +#ifdef __cplusplus +} +#endif diff --git a/components/soc/include/hal/ledc_types.h b/components/soc/include/hal/ledc_types.h index 855c18c6c..6cdaea97c 100644 --- a/components/soc/include/hal/ledc_types.h +++ b/components/soc/include/hal/ledc_types.h @@ -20,9 +20,10 @@ extern "C" { #include #include +#include "soc/ledc_caps.h" typedef enum { -#ifdef CONFIG_IDF_TARGET_ESP32 +#ifdef SOC_LEDC_SUPPORT_HS_MODE LEDC_HIGH_SPEED_MODE = 0, /*!< LEDC high speed speed_mode */ #endif LEDC_LOW_SPEED_MODE, /*!< LEDC low speed speed_mode */ @@ -49,7 +50,7 @@ typedef enum { typedef enum { LEDC_SLOW_CLK_RTC8M = 0, /*!< LEDC low speed timer clock source is 8MHz RTC clock*/ LEDC_SLOW_CLK_APB, /*!< LEDC low speed timer clock source is 80MHz APB clock*/ -#ifdef CONFIG_IDF_TARGET_ESP32S2BETA +#ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK LEDC_SLOW_CLK_XTAL, /*!< LEDC low speed timer clock source XTAL clock*/ #endif } ledc_slow_clk_sel_t; @@ -59,7 +60,7 @@ typedef enum { LEDC_USE_REF_TICK, /*!< LEDC timer select REF_TICK clock as source clock*/ LEDC_USE_APB_CLK, /*!< LEDC timer select APB clock as source clock*/ LEDC_USE_RTC8M_CLK, /*!< LEDC timer select RTC8M_CLK as source clock. Only for low speed channels and this parameter must be the same for all low speed channels*/ -#ifdef CONFIG_IDF_TARGET_ESP32S2BETA +#ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK LEDC_USE_XTAL_CLK, /*!< LEDC timer select XTAL clock as source clock*/ #endif } ledc_clk_cfg_t; diff --git a/components/soc/include/soc/ledc_periph.h b/components/soc/include/soc/ledc_periph.h index 9ddd5f58a..e93771e19 100644 --- a/components/soc/include/soc/ledc_periph.h +++ b/components/soc/include/soc/ledc_periph.h @@ -15,6 +15,7 @@ #pragma once #include "soc/ledc_reg.h" #include "soc/ledc_struct.h" +#include "soc/ledc_caps.h" /* Stores a bunch of per-ledc-peripheral data. @@ -23,8 +24,8 @@ typedef struct { const uint8_t sig_out0_idx; } ledc_signal_conn_t; -#if CONFIG_IDF_TARGET_ESP32S2BETA -extern const ledc_signal_conn_t ledc_periph_signal[1]; -#elif defined CONFIG_IDF_TARGET_ESP32 +#ifdef SOC_LEDC_SUPPORT_HS_MODE extern const ledc_signal_conn_t ledc_periph_signal[2]; -#endif \ No newline at end of file +#else +extern const ledc_signal_conn_t ledc_periph_signal[1]; +#endif diff --git a/components/soc/src/hal/ledc_hal.c b/components/soc/src/hal/ledc_hal.c index 4895f58e8..71854e3cc 100644 --- a/components/soc/src/hal/ledc_hal.c +++ b/components/soc/src/hal/ledc_hal.c @@ -37,7 +37,7 @@ void ledc_hal_get_clk_cfg(ledc_hal_context_t *hal, ledc_timer_t timer_sel, ledc_ ledc_hal_get_slow_clk_sel(hal, &slow_clk); if (slow_clk == LEDC_SLOW_CLK_RTC8M) { *clk_cfg = LEDC_USE_RTC8M_CLK; -#ifdef CONFIG_IDF_TARGET_ESP32S2BETA +#ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK } else if (slow_clk == LEDC_SLOW_CLK_XTAL) { *clk_cfg = LEDC_USE_XTAL_CLK; #endif @@ -50,11 +50,11 @@ void ledc_hal_set_slow_clk(ledc_hal_context_t *hal, ledc_clk_cfg_t clk_cfg) { // For low speed channels, if RTC_8MCLK is used as the source clock, the `slow_clk_sel` register should be cleared, otherwise it should be set. ledc_slow_clk_sel_t slow_clk_sel = LEDC_SLOW_CLK_APB; -#ifdef CONFIG_IDF_TARGET_ESP32 - slow_clk_sel = (clk_cfg == LEDC_USE_RTC8M_CLK) ? LEDC_SLOW_CLK_RTC8M : LEDC_SLOW_CLK_APB; -#elif defined CONFIG_IDF_TARGET_ESP32S2BETA +#ifdef SOC_LEDC_SUPPORT_XTAL_CLOCK slow_clk_sel = (clk_cfg == LEDC_USE_RTC8M_CLK) ? LEDC_SLOW_CLK_RTC8M : ((clk_cfg == LEDC_USE_XTAL_CLK) ? LEDC_SLOW_CLK_XTAL : LEDC_SLOW_CLK_APB); +#else + slow_clk_sel = (clk_cfg == LEDC_USE_RTC8M_CLK) ? LEDC_SLOW_CLK_RTC8M : LEDC_SLOW_CLK_APB; #endif ledc_hal_set_slow_clk_sel(hal, slow_clk_sel); }