From e66f25caf2979887630dcd5b0f57066f688ed60a Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Mon, 10 May 2021 15:18:29 +0800 Subject: [PATCH] driver/mcpwm: fix the misleading of mcpwm_capture_enable parameters closes https://github.com/espressif/esp-idf/issues/5032 --- components/driver/include/driver/mcpwm.h | 1 + components/driver/mcpwm.c | 2 ++ components/hal/esp32/include/hal/mcpwm_ll.h | 2 +- components/hal/esp32s3/include/hal/mcpwm_ll.h | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/components/driver/include/driver/mcpwm.h b/components/driver/include/driver/mcpwm.h index f4ec17a2a9..c19b80e4f1 100644 --- a/components/driver/include/driver/mcpwm.h +++ b/components/driver/include/driver/mcpwm.h @@ -568,6 +568,7 @@ esp_err_t mcpwm_fault_deinit(mcpwm_unit_t mcpwm_num, mcpwm_fault_signal_t fault_ * @param cap_edge set capture edge, BIT(0) - negative edge, BIT(1) - positive edge * @param cap_sig capture pin, which needs to be enabled * @param num_of_pulse count time between rising/falling edge between 2 *(pulses mentioned), counter uses APB_CLK + * [0~MCPWM_LL_MAX_PRESCALE] (MCPWM_LL_MAX_PRESCALE = 255 on ESP32); * * @return * - ESP_OK Success diff --git a/components/driver/mcpwm.c b/components/driver/mcpwm.c index 45ed81c47b..e022e042e8 100644 --- a/components/driver/mcpwm.c +++ b/components/driver/mcpwm.c @@ -49,6 +49,7 @@ static const char *MCPWM_TAG = "MCPWM"; #define MCPWM_DRIVER_INIT_ERROR "MCPWM DRIVER NOT INITIALIZED" #define MCPWM_GROUP_NUM_ERROR "MCPWM GROUP NUM ERROR" +#define MCPWM_PRESCALE_ERROR "MCPWM PRESCALE ERROR" #define MCPWM_TIMER_ERROR "MCPWM TIMER NUM ERROR" #define MCPWM_CAPTURE_ERROR "MCPWM CAPTURE NUM ERROR" #define MCPWM_PARAM_ADDR_ERROR "MCPWM PARAM ADDR ERROR" @@ -531,6 +532,7 @@ esp_err_t mcpwm_capture_enable(mcpwm_unit_t mcpwm_num, mcpwm_capture_signal_t ca uint32_t num_of_pulse) { MCPWM_CHECK(mcpwm_num < SOC_MCPWM_GROUPS, MCPWM_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG); + MCPWM_CHECK(num_of_pulse <= MCPWM_LL_MAX_PRESCALE, MCPWM_PRESCALE_ERROR, ESP_ERR_INVALID_ARG); // enable MCPWM module incase user don't use `mcpwm_init` at all periph_module_enable(mcpwm_periph_signals.groups[mcpwm_num].module); mcpwm_hal_init_config_t init_config = { diff --git a/components/hal/esp32/include/hal/mcpwm_ll.h b/components/hal/esp32/include/hal/mcpwm_ll.h index e1446fc6c8..e8f954d8d1 100644 --- a/components/hal/esp32/include/hal/mcpwm_ll.h +++ b/components/hal/esp32/include/hal/mcpwm_ll.h @@ -36,7 +36,7 @@ extern "C" { /// Get the address of peripheral registers #define MCPWM_LL_GET_HW(ID) (((ID)==0)? &MCPWM0: &MCPWM1) - +#define MCPWM_LL_MAX_PRESCALE 255 /********************* Global *******************/ /** diff --git a/components/hal/esp32s3/include/hal/mcpwm_ll.h b/components/hal/esp32s3/include/hal/mcpwm_ll.h index 3b9f6a6e65..abba4a741c 100644 --- a/components/hal/esp32s3/include/hal/mcpwm_ll.h +++ b/components/hal/esp32s3/include/hal/mcpwm_ll.h @@ -36,7 +36,7 @@ extern "C" { /// Get the address of peripheral registers #define MCPWM_LL_GET_HW(ID) (((ID)==0)? &MCPWM0: &MCPWM1) - +#define MCPWM_LL_MAX_PRESCALE 255 /********************* Global *******************/ /**