ChibiOS/HAL 9.0.0
hal_pwm_lld.h
Go to the documentation of this file.
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 */
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 */
99 /* End of the mandatory fields.*/
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 */
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 */
124 /**
125 * @brief Channels configurations.
126 */
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 */
139 /**
140 * @brief Current driver configuration data.
141 */
143 /**
144 * @brief Current PWM period in ticks.
145 */
147 /**
148 * @brief Mask of the enabled channels.
149 */
151 /**
152 * @brief Number of channels in this instance.
153 */
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);
198 pwmchannel_t channel,
199 pwmcnt_t width);
204 pwmchannel_t channel);
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/** @} */
void pwm_lld_disable_periodic_notification(PWMDriver *pwmp)
Disables the periodic activation edge notification.
#define PWM_CHANNELS
Number of PWM channels per PWM driver.
Definition hal_pwm_lld.h:37
void pwm_lld_stop(PWMDriver *pwmp)
Deactivates the PWM peripheral.
uint32_t pwmcnt_t
Type of a PWM counter.
Definition hal_pwm_lld.h:83
uint32_t pwmmode_t
Type of a PWM mode.
Definition hal_pwm_lld.h:68
uint8_t pwmchannel_t
Type of a PWM channel.
Definition hal_pwm_lld.h:73
void pwm_lld_disable_channel_notification(PWMDriver *pwmp, pwmchannel_t channel)
Disables a channel de-activation edge notification.
void pwm_lld_disable_channel(PWMDriver *pwmp, pwmchannel_t channel)
Disables a PWM channel and its notification.
void pwm_lld_init(void)
Low level PWM driver initialization.
Definition hal_pwm_lld.c:66
void pwm_lld_start(PWMDriver *pwmp)
Configures and activates the PWM peripheral.
Definition hal_pwm_lld.c:83
uint32_t pwmchnmsk_t
Type of a channels mask.
Definition hal_pwm_lld.h:78
void pwm_lld_enable_channel(PWMDriver *pwmp, pwmchannel_t channel, pwmcnt_t width)
Enables a PWM channel.
void(* pwmcallback_t)(PWMDriver *pwmp)
Type of a PWM notification callback.
Definition hal_pwm.h:90
pwmstate_t
Driver state machine possible states.
Definition hal_pwm.h:74
void pwm_lld_enable_periodic_notification(PWMDriver *pwmp)
Enables the periodic activation edge notification.
void pwm_lld_enable_channel_notification(PWMDriver *pwmp, pwmchannel_t channel)
Enables a channel de-activation edge notification.
PWMDriver PWMD1
PWMD1 driver identifier.
Definition hal_pwm_lld.c:42
Type of a PWM driver channel configuration structure.
Definition hal_pwm_lld.h:88
pwmcallback_t callback
Channel callback pointer.
Definition hal_pwm_lld.h:98
pwmmode_t mode
Channel active logic level.
Definition hal_pwm_lld.h:92
Type of a PWM driver configuration structure.
pwmcallback_t callback
Periodic callback pointer.
PWMChannelConfig channels[PWM_CHANNELS]
Channels configurations.
uint32_t frequency
Timer clock in Hz.
pwmcnt_t period
PWM period in ticks.
Structure representing a PWM driver.
pwmcnt_t period
Current PWM period in ticks.
pwmchannel_t channels
Number of channels in this instance.
pwmchnmsk_t enabled
Mask of the enabled channels.
const PWMConfig * config
Current driver configuration data.
pwmstate_t state
Driver state.