Merge branch 'feature/support_sigma_delta_on_s3' into 'master'

sigma_delta: add periph signal list and support esp32-s3

See merge request espressif/esp-idf!10945
This commit is contained in:
Michael (XIAO Xufeng) 2020-10-30 17:22:02 +08:00
commit 35faecea1d
15 changed files with 188 additions and 83 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}
/**

View File

@ -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
#endif

View File

@ -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"

View File

@ -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

View File

@ -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
}
}
};

View File

@ -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"

View File

@ -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

View File

@ -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
}
}
};

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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
}
}
};

View File

@ -13,5 +13,24 @@
// limitations under the License.
#pragma once
#include "soc/gpio_sd_struct.h"
#include <stdint.h>
#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