Skip to content

Commit 4d1a4df

Browse files
committed
feat(mcpwm): add a new api to get cap value directly
1 parent a2ef01f commit 4d1a4df

File tree

5 files changed

+32
-35
lines changed

5 files changed

+32
-35
lines changed

components/driver/Kconfig

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,6 @@ menu "Driver Configurations"
22

33
orsource "./twai/Kconfig.twai"
44

5-
menu "Legacy MCPWM Driver Configurations"
6-
depends on SOC_MCPWM_SUPPORTED
7-
config MCPWM_SUPPRESS_DEPRECATE_WARN
8-
bool "Suppress legacy driver deprecated warning"
9-
default n
10-
help
11-
Whether to suppress the deprecation warnings when using legacy MCPWM driver (driver/mcpwm.h).
12-
If you want to continue using the legacy driver, and don't want to see related deprecation warnings,
13-
you can enable this option.
14-
15-
config MCPWM_SKIP_LEGACY_CONFLICT_CHECK
16-
bool "Skip legacy conflict check"
17-
default n
18-
help
19-
This configuration option allows the user to bypass the conflict check mechanism with legacy code.
20-
endmenu # Legacy MCPWM Driver Configurations
21-
225
menu "Legacy RMT Driver Configurations"
236
depends on SOC_RMT_SUPPORTED
247
config RMT_SUPPRESS_DEPRECATE_WARN
@@ -45,23 +28,6 @@ menu "Driver Configurations"
4528
This configuration option allows the user to bypass the conflict check mechanism with legacy code.
4629
endmenu # Legacy I2C Driver Configurationss
4730

48-
menu "Legacy PCNT Driver Configurations"
49-
depends on SOC_PCNT_SUPPORTED
50-
config PCNT_SUPPRESS_DEPRECATE_WARN
51-
bool "Suppress legacy driver deprecated warning"
52-
default n
53-
help
54-
whether to suppress the deprecation warnings when using legacy PCNT driver (driver/pcnt.h).
55-
If you want to continue using the legacy driver, and don't want to see related deprecation warnings,
56-
you can enable this option.
57-
58-
config PCNT_SKIP_LEGACY_CONFLICT_CHECK
59-
bool "Skip legacy conflict check"
60-
default n
61-
help
62-
This configuration option allows the user to bypass the conflict check mechanism with legacy code.
63-
endmenu # Legacy PCNT Driver Configurationss
64-
6531
menu "Legacy SDM Driver Configurations"
6632
depends on SOC_SDM_SUPPORTED
6733
config SDM_SUPPRESS_DEPRECATE_WARN

components/esp_driver_mcpwm/include/driver/mcpwm_cap.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -242,6 +242,20 @@ esp_err_t mcpwm_capture_channel_register_event_callbacks(mcpwm_cap_channel_handl
242242
*/
243243
esp_err_t mcpwm_capture_channel_trigger_soft_catch(mcpwm_cap_channel_handle_t cap_channel);
244244

245+
/**
246+
* @brief Get the last captured value of the MCPWM capture channel
247+
*
248+
* @note To convert the count value to a time, user can use `mcpwm_capture_timer_get_resolution` to get the resolution of the capture timer.
249+
*
250+
* @param[in] cap_channel MCPWM capture channel handle, allocated by `mcpwm_new_capture_channel()`
251+
* @param[out] value Returned capture value
252+
* @return
253+
* - ESP_OK: Get capture value successfully
254+
* - ESP_ERR_INVALID_ARG: Get capture value failed because of invalid argument
255+
* - ESP_FAIL: Get capture value failed because of other error
256+
*/
257+
esp_err_t mcpwm_capture_get_latched_value(mcpwm_cap_channel_handle_t cap_channel, uint32_t *value);
258+
245259
#ifdef __cplusplus
246260
}
247261
#endif

components/esp_driver_mcpwm/src/mcpwm_cap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ esp_err_t mcpwm_capture_channel_trigger_soft_catch(mcpwm_cap_channel_handle_t ca
413413
return ESP_OK;
414414
}
415415

416+
esp_err_t mcpwm_capture_get_latched_value(mcpwm_cap_channel_handle_t cap_channel, uint32_t *value)
417+
{
418+
ESP_RETURN_ON_FALSE(cap_channel && value, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
419+
*value = mcpwm_ll_capture_get_value(cap_channel->cap_timer->group->hal.dev, cap_channel->cap_chan_id);
420+
return ESP_OK;
421+
}
422+
416423
esp_err_t mcpwm_capture_timer_set_phase_on_sync(mcpwm_cap_timer_handle_t cap_timer, const mcpwm_capture_timer_sync_phase_config_t *config)
417424
{
418425
ESP_RETURN_ON_FALSE(cap_timer, ESP_ERR_INVALID_ARG, TAG, "invalid argument");

docs/en/api-reference/peripherals/mcpwm.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,11 @@ Trigger a Software Capture Event
960960

961961
Sometimes, the software also wants to trigger a "fake" capture event. The :cpp:func:`mcpwm_capture_channel_trigger_soft_catch` is provided for that purpose. Please note that, even though it is a "fake" capture event, it can still cause an interrupt, thus your capture event callback function gets invoked as well.
962962

963+
Get the Last Captured Value
964+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
965+
966+
If you don't want to process the captured value in the capture event callback function, but want to process it in other places, you can call :cpp:func:`mcpwm_capture_get_latched_value` to get the last captured value.
967+
963968
.. only:: SOC_MCPWM_SUPPORT_ETM
964969

965970
.. _mcpwm-etm-event-and-task:

docs/zh_CN/api-reference/peripherals/mcpwm.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,11 @@ MCPWM 捕获通道支持在信号上检测到有效边沿时发送通知。须
960960

961961
某些场景下,可能存在需要软件触发“虚假”捕获事件的需求。此时,可以调用 :cpp:func:`mcpwm_capture_channel_trigger_soft_catch` 实现。需注意,此类“虚假”捕获事件仍然会触发中断,并从而调用捕获事件回调函数。
962962

963+
获得上一次锁存的捕获值
964+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
965+
966+
如果不想在捕获事件回调函数中处理捕获值,而是想在其他地方处理,可以调用 :cpp:func:`mcpwm_capture_get_latched_value` 获得上一次锁存的捕获值。
967+
963968
.. only:: SOC_MCPWM_SUPPORT_ETM
964969

965970
.. _mcpwm-etm-event-and-task:

0 commit comments

Comments
 (0)