aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/hal/templates/hal_pwm_lld.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/os/hal/templates/hal_pwm_lld.h')
-rw-r--r--lib/chibios/os/hal/templates/hal_pwm_lld.h215
1 files changed, 215 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/templates/hal_pwm_lld.h b/lib/chibios/os/hal/templates/hal_pwm_lld.h
new file mode 100644
index 000000000..625dd5755
--- /dev/null
+++ b/lib/chibios/os/hal/templates/hal_pwm_lld.h
@@ -0,0 +1,215 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file hal_pwm_lld.h
19 * @brief PLATFORM PWM subsystem low level driver header.
20 *
21 * @addtogroup PWM
22 * @{
23 */
24
25#ifndef HAL_PWM_LLD_H
26#define HAL_PWM_LLD_H
27
28#if (HAL_USE_PWM == TRUE) || defined(__DOXYGEN__)
29
30/*===========================================================================*/
31/* Driver constants. */
32/*===========================================================================*/
33
34/**
35 * @brief Number of PWM channels per PWM driver.
36 */
37#define PWM_CHANNELS 4
38
39/*===========================================================================*/
40/* Driver pre-compile time settings. */
41/*===========================================================================*/
42
43/**
44 * @name PLATFORM configuration options
45 * @{
46 */
47/**
48 * @brief PWMD1 driver enable switch.
49 * @details If set to @p TRUE the support for PWM1 is included.
50 * @note The default is @p FALSE.
51 */
52#if !defined(PLATFORM_PWM_USE_PWM1) || defined(__DOXYGEN__)
53#define PLATFORM_PWM_USE_PWM1 FALSE
54#endif
55/** @} */
56
57/*===========================================================================*/
58/* Configuration checks. */
59/*===========================================================================*/
60
61/*===========================================================================*/
62/* Driver data structures and types. */
63/*===========================================================================*/
64
65/**
66 * @brief Type of a PWM mode.
67 */
68typedef uint32_t pwmmode_t;
69
70/**
71 * @brief Type of a PWM channel.
72 */
73typedef uint8_t pwmchannel_t;
74
75/**
76 * @brief Type of a channels mask.
77 */
78typedef uint32_t pwmchnmsk_t;
79
80/**
81 * @brief Type of a PWM counter.
82 */
83typedef uint32_t pwmcnt_t;
84
85/**
86 * @brief Type of a PWM driver channel configuration structure.
87 */
88typedef struct {
89 /**
90 * @brief Channel active logic level.
91 */
92 pwmmode_t mode;
93 /**
94 * @brief Channel callback pointer.
95 * @note This callback is invoked on the channel compare event. If set to
96 * @p NULL then the callback is disabled.
97 */
98 pwmcallback_t callback;
99 /* End of the mandatory fields.*/
100} PWMChannelConfig;
101
102/**
103 * @brief Type of a PWM driver configuration structure.
104 */
105typedef struct {
106 /**
107 * @brief Timer clock in Hz.
108 * @note The low level can use assertions in order to catch invalid
109 * frequency specifications.
110 */
111 uint32_t frequency;
112 /**
113 * @brief PWM period in ticks.
114 * @note The low level can use assertions in order to catch invalid
115 * period specifications.
116 */
117 pwmcnt_t period;
118 /**
119 * @brief Periodic callback pointer.
120 * @note This callback is invoked on PWM counter reset. If set to
121 * @p NULL then the callback is disabled.
122 */
123 pwmcallback_t callback;
124 /**
125 * @brief Channels configurations.
126 */
127 PWMChannelConfig channels[PWM_CHANNELS];
128 /* End of the mandatory fields.*/
129} PWMConfig;
130
131/**
132 * @brief Structure representing a PWM driver.
133 */
134struct PWMDriver {
135 /**
136 * @brief Driver state.
137 */
138 pwmstate_t state;
139 /**
140 * @brief Current driver configuration data.
141 */
142 const PWMConfig *config;
143 /**
144 * @brief Current PWM period in ticks.
145 */
146 pwmcnt_t period;
147 /**
148 * @brief Mask of the enabled channels.
149 */
150 pwmchnmsk_t enabled;
151 /**
152 * @brief Number of channels in this instance.
153 */
154 pwmchannel_t channels;
155#if defined(PWM_DRIVER_EXT_FIELDS)
156 PWM_DRIVER_EXT_FIELDS
157#endif
158 /* End of the mandatory fields.*/
159};
160
161/*===========================================================================*/
162/* Driver macros. */
163/*===========================================================================*/
164
165/**
166 * @brief Changes the period the PWM peripheral.
167 * @details This function changes the period of a PWM unit that has already
168 * been activated using @p pwmStart().
169 * @pre The PWM unit must have been activated using @p pwmStart().
170 * @post The PWM unit period is changed to the new value.
171 * @note The function has effect at the next cycle start.
172 * @note If a period is specified that is shorter than the pulse width
173 * programmed in one of the channels then the behavior is not
174 * guaranteed.
175 *
176 * @param[in] pwmp pointer to a @p PWMDriver object
177 * @param[in] period new cycle time in ticks
178 *
179 * @notapi
180 */
181#define pwm_lld_change_period(pwmp, period)
182
183/*===========================================================================*/
184/* External declarations. */
185/*===========================================================================*/
186
187#if (PLATFORM_PWM_USE_PWM1 == TRUE) && !defined(__DOXYGEN__)
188extern PWMDriver PWMD1;
189#endif
190
191#ifdef __cplusplus
192extern "C" {
193#endif
194 void pwm_lld_init(void);
195 void pwm_lld_start(PWMDriver *pwmp);
196 void pwm_lld_stop(PWMDriver *pwmp);
197 void pwm_lld_enable_channel(PWMDriver *pwmp,
198 pwmchannel_t channel,
199 pwmcnt_t width);
200 void pwm_lld_disable_channel(PWMDriver *pwmp, pwmchannel_t channel);
201 void pwm_lld_enable_periodic_notification(PWMDriver *pwmp);
202 void pwm_lld_disable_periodic_notification(PWMDriver *pwmp);
203 void pwm_lld_enable_channel_notification(PWMDriver *pwmp,
204 pwmchannel_t channel);
205 void pwm_lld_disable_channel_notification(PWMDriver *pwmp,
206 pwmchannel_t channel);
207#ifdef __cplusplus
208}
209#endif
210
211#endif /* HAL_USE_PWM == TRUE */
212
213#endif /* HAL_PWM_LLD_H */
214
215/** @} */