Select one of the symbols to view example projects that use it.
 
Outline
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#include "driver/mcpwm_types.h"
mcpwm_timer_event_callbacks_t
mcpwm_timer_config_t
mcpwm_new_timer(const mcpwm_timer_config_t *, mcpwm_timer_handle_t *);
mcpwm_del_timer(mcpwm_timer_handle_t);
mcpwm_timer_set_period(mcpwm_timer_handle_t, uint32_t);
mcpwm_timer_enable(mcpwm_timer_handle_t);
mcpwm_timer_disable(mcpwm_timer_handle_t);
mcpwm_timer_start_stop(mcpwm_timer_handle_t, mcpwm_timer_start_stop_cmd_t);
mcpwm_timer_register_event_callbacks(mcpwm_timer_handle_t, const mcpwm_timer_event_callbacks_t *, void *);
mcpwm_timer_sync_phase_config_t
mcpwm_timer_set_phase_on_sync(mcpwm_timer_handle_t, const mcpwm_timer_sync_phase_config_t *);
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/esp_driver_mcpwm/include/driver/mcpwm_timer.h
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #pragma once #include <stdint.h> #include <stdbool.h> #include "esp_err.h" #include "driver/mcpwm_types.h" #ifdef __cplusplus extern "C" { #endif /** * @brief Group of supported MCPWM timer event callbacks * @note The callbacks are all running under ISR environment *//* ... */ typedef struct { mcpwm_timer_event_cb_t on_full; /*!< callback function when MCPWM timer counts to peak value */ mcpwm_timer_event_cb_t on_empty; /*!< callback function when MCPWM timer counts to zero */ mcpwm_timer_event_cb_t on_stop; /*!< callback function when MCPWM timer stops */ }{ ... } mcpwm_timer_event_callbacks_t; /** * @brief MCPWM timer configuration *//* ... */ typedef struct { int group_id; /*!< Specify from which group to allocate the MCPWM timer */ mcpwm_timer_clock_source_t clk_src; /*!< MCPWM timer clock source */ uint32_t resolution_hz; /*!< Counter resolution in Hz The step size of each count tick equals to (1 / resolution_hz) seconds *//* ... */ mcpwm_timer_count_mode_t count_mode; /*!< Count mode */ uint32_t period_ticks; /*!< Number of count ticks within a period */ int intr_priority; /*!< MCPWM timer interrupt priority, if set to 0, the driver will try to allocate an interrupt with a relative low priority (1,2,3) *//* ... */ struct { uint32_t update_period_on_empty: 1; /*!< Whether to update period when timer counts to zero */ uint32_t update_period_on_sync: 1; /*!< Whether to update period on sync event */ uint32_t allow_pd: 1; /*!< Set to allow power down. When this flag set, the driver will backup/restore the MCPWM registers before/after entering/exist sleep mode. By this approach, the system can power off MCPWM's power domain. This can save power, but at the expense of more RAM being consumed. *//* ... */ }{ ... } flags; /*!< Extra configuration flags for timer */ }{ ... } mcpwm_timer_config_t; /** * @brief Create MCPWM timer * * @param[in] config MCPWM timer configuration * @param[out] ret_timer Returned MCPWM timer handle * @return * - ESP_OK: Create MCPWM timer successfully * - ESP_ERR_INVALID_ARG: Create MCPWM timer failed because of invalid argument * - ESP_ERR_NO_MEM: Create MCPWM timer failed because out of memory * - ESP_ERR_NOT_FOUND: Create MCPWM timer failed because all hardware timers are used up and no more free one * - ESP_FAIL: Create MCPWM timer failed because of other error *//* ... */ esp_err_t mcpwm_new_timer(const mcpwm_timer_config_t *config, mcpwm_timer_handle_t *ret_timer); /** * @brief Delete MCPWM timer * * @param[in] timer MCPWM timer handle, allocated by `mcpwm_new_timer()` * @return * - ESP_OK: Delete MCPWM timer successfully * - ESP_ERR_INVALID_ARG: Delete MCPWM timer failed because of invalid argument * - ESP_ERR_INVALID_STATE: Delete MCPWM timer failed because timer is not in init state * - ESP_FAIL: Delete MCPWM timer failed because of other error *//* ... */ esp_err_t mcpwm_del_timer(mcpwm_timer_handle_t timer); /** * @brief Set a new period for MCPWM timer * * @note If `mcpwm_timer_config_t::update_period_on_empty` and `mcpwm_timer_config_t::update_period_on_sync` are not set, * the new period will take effect immediately. * Otherwise, the new period will take effect when timer counts to zero or on sync event. * @note You may need to use `mcpwm_comparator_set_compare_value` to set a new compare value for MCPWM comparator * in order to keep the same PWM duty cycle. * * @param[in] timer MCPWM timer handle, allocated by `mcpwm_new_timer` * @param[in] period_ticks New period in count ticks * @return * - ESP_OK: Set new period for MCPWM timer successfully * - ESP_ERR_INVALID_ARG: Set new period for MCPWM timer failed because of invalid argument * - ESP_FAIL: Set new period for MCPWM timer failed because of other error *//* ... */ esp_err_t mcpwm_timer_set_period(mcpwm_timer_handle_t timer, uint32_t period_ticks); /** * @brief Enable MCPWM timer * * @param[in] timer MCPWM timer handle, allocated by `mcpwm_new_timer()` * @return * - ESP_OK: Enable MCPWM timer successfully * - ESP_ERR_INVALID_ARG: Enable MCPWM timer failed because of invalid argument * - ESP_ERR_INVALID_STATE: Enable MCPWM timer failed because timer is enabled already * - ESP_FAIL: Enable MCPWM timer failed because of other error *//* ... */ esp_err_t mcpwm_timer_enable(mcpwm_timer_handle_t timer); /** * @brief Disable MCPWM timer * * @param[in] timer MCPWM timer handle, allocated by `mcpwm_new_timer()` * @return * - ESP_OK: Disable MCPWM timer successfully * - ESP_ERR_INVALID_ARG: Disable MCPWM timer failed because of invalid argument * - ESP_ERR_INVALID_STATE: Disable MCPWM timer failed because timer is disabled already * - ESP_FAIL: Disable MCPWM timer failed because of other error *//* ... */ esp_err_t mcpwm_timer_disable(mcpwm_timer_handle_t timer); /** * @brief Send specific start/stop commands to MCPWM timer * * @param[in] timer MCPWM timer handle, allocated by `mcpwm_new_timer()` * @param[in] command Supported command list for MCPWM timer * @return * - ESP_OK: Start or stop MCPWM timer successfully * - ESP_ERR_INVALID_ARG: Start or stop MCPWM timer failed because of invalid argument * - ESP_ERR_INVALID_STATE: Start or stop MCPWM timer failed because timer is not enabled * - ESP_FAIL: Start or stop MCPWM timer failed because of other error *//* ... */ esp_err_t mcpwm_timer_start_stop(mcpwm_timer_handle_t timer, mcpwm_timer_start_stop_cmd_t command); /** * @brief Set event callbacks for MCPWM timer * * @note The first call to this function needs to be before the call to `mcpwm_timer_enable` * @note User can deregister a previously registered callback by calling this function and setting the callback member in the `cbs` structure to NULL. * * @param[in] timer MCPWM timer handle, allocated by `mcpwm_new_timer()` * @param[in] cbs Group of callback functions * @param[in] user_data User data, which will be passed to callback functions directly * @return * - ESP_OK: Set event callbacks successfully * - ESP_ERR_INVALID_ARG: Set event callbacks failed because of invalid argument * - ESP_ERR_INVALID_STATE: Set event callbacks failed because timer is not in init state * - ESP_FAIL: Set event callbacks failed because of other error *//* ... */ esp_err_t mcpwm_timer_register_event_callbacks(mcpwm_timer_handle_t timer, const mcpwm_timer_event_callbacks_t *cbs, void *user_data); /** * @brief MCPWM Timer sync phase configuration *//* ... */ typedef struct { mcpwm_sync_handle_t sync_src; /*!< The sync event source. Set to NULL will disable the timer being synced by others */ uint32_t count_value; /*!< The count value that should lock to upon sync event */ mcpwm_timer_direction_t direction; /*!< The count direction that should lock to upon sync event */ }{ ... } mcpwm_timer_sync_phase_config_t; /** * @brief Set sync phase for MCPWM timer * * @param[in] timer MCPWM timer handle, allocated by `mcpwm_new_timer()` * @param[in] config MCPWM timer sync phase configuration * @return * - ESP_OK: Set sync phase for MCPWM timer successfully * - ESP_ERR_INVALID_ARG: Set sync phase for MCPWM timer failed because of invalid argument * - ESP_FAIL: Set sync phase for MCPWM timer failed because of other error *//* ... */ esp_err_t mcpwm_timer_set_phase_on_sync(mcpwm_timer_handle_t timer, const mcpwm_timer_sync_phase_config_t *config); #ifdef __cplusplus }{...} #endif
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.