hal_pwm.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file hal_pwm.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of PWM HAL library.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2019 GOODIX
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of GOODIX nor the names of its contributors may be used
21  to endorse or promote products derived from this software without
22  specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE.
35  ****************************************************************************************
36  */
37 
38 /** @addtogroup PERIPHERAL Peripheral Driver
39  * @{
40  */
41 
42 /** @addtogroup HAL_DRIVER HAL Driver
43  * @{
44  */
45 
46 /** @defgroup HAL_PWM PWM
47  * @brief PWM HAL module driver.
48  * @{
49  */
50 
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef HAL_PWM_H
53 #define HAL_PWM_H
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "hal_def.h"
61 #include "hal_dma.h"
62 #include "ll_pwm.h"
63 #include "hal_pwr_mgmt.h"
64 
65 /* Exported types ------------------------------------------------------------*/
66 /** @addtogroup HAL_PWM_ENUMERATIONS Enumerations
67  * @{
68  */
69 
70 /**
71  * @brief HAL_PWM_MODE Enumerations definition
72  */
73 typedef enum
74 {
75  PWM_FLICKER_MODE = 0x00, /**< Choose PWM Flicker Mode */
76  PWM_BREATH_MODE, /**< Choose PWM Breath Mode */
77  PWM_CODING_MODE, /**< Choose PWM Coding Mode */
79 
80 /**
81  * @brief HAL PWM State Enumerations definition
82  */
83 typedef enum
84 {
85  HAL_PWM_STATE_RESET = 0x00, /**< Peripheral is not initialized or disabled */
86  HAL_PWM_STATE_READY = 0x01, /**< Peripheral is initialized and ready for use */
87  HAL_PWM_STATE_BUSY = 0x02, /**< An internal process is ongoing */
88  HAL_PWM_STATE_ERROR = 0x04 /**< Reception process is ongoing */
90 
91 /** @defgroup HAL_PWM_active_channel HAL PWM active channel
92  * @{
93  */
94 
95 /**
96  * @brief HAL PWM active channel Enumerations definition
97  */
98 typedef enum
99 {
100  HAL_PWM_ACTIVE_CHANNEL_A = 0x01, /**< The active channel is A */
101  HAL_PWM_ACTIVE_CHANNEL_B = 0x02, /**< The active channel is B */
102  HAL_PWM_ACTIVE_CHANNEL_C = 0x04, /**< The active channel is C */
103  HAL_PWM_ACTIVE_CHANNEL_ALL = 0x07, /**< The active channels are ALL */
104  HAL_PWM_ACTIVE_CHANNEL_CLEARED = 0x00 /**< All active channels are cleared */
106 /** @} */
107 
108 /** @} */
109 
110 /** @addtogroup HAL_PWM_STRUCTURES Structures
111  * @{
112  */
113 
114 /** @defgroup PWM_Configuration PWM Configuration
115  * @{
116  */
117 
118 /**
119  * @brief PWM COMP value init Structure definition
120  */
121 typedef struct
122 {
123  uint32_t comp_a0; /**< Pwm comp a0 value */
124  uint32_t comp_a1; /**< Pwm comp a1 value */
125  uint32_t comp_b0; /**< Pwm comp b0 value */
126  uint32_t comp_b1; /**< Pwm comp b1 value */
127  uint32_t comp_c0; /**< Pwm comp c0 value */
128  uint32_t comp_c1; /**< Pwm comp c1 value */
130 
131 /**
132  * @brief PWM None Coding Channel init Structure definition
133  */
134 typedef struct
135 {
136  uint8_t duty; /**< Specifies the duty in PWM output mode.
137  This parameter must be a number between 0 ~ 100.*/
138 
139  uint8_t drive_polarity; /**< Specifies the drive polarity in PWM output mode.
140  This parameter can be a value of @ref PWM_Drive_Polarity.*/
141 
142  uint32_t fstoplvl; /**< Specifies the PWM io level when stop.
143  This parameter can be a value of @ref PWM_STOP_LVL */
145 
146 /**
147  * @brief PWM Coding Channel init Structure definition
148  */
149 typedef struct
150 {
151  uint32_t comp0; /**< Specifies current channel first compare value
152  This parameter must be a number ranges between Min_Data=0 and Max_Data=period.*/
153 
154  uint32_t comp1; /**< Specifies current channel second compare value
155  This parameter must be a number ranges between Min_Data=0 and Max_Data=period.*/
156 
157  uint8_t drive_polarity; /**< Specifies the drive polarity in PWM output mode.
158  This parameter can be a value of @ref PWM_Drive_Polarity.*/
159 
160  uint8_t waiting_time_lvl; /**< Specifies the waiting time level in coding mode.
161  This parameter can be a value of @ref PWM_WAITING_TIME_LVL.*/
163 
164 /**
165  * @brief PWM None Coding Init Structure definition
166  */
167 typedef struct
168 {
169  uint32_t align; /**< Specifies the PWM alignment mode with three channels
170  This parameter can be a value of PWM_Alignment_Mode */
171 
172  uint32_t freq; /**< Specifies the PWM frequency.
173  This parameter must be a number between 0 ~ SystemFreq/2.*/
174 
175  uint32_t bperiod; /**< Specifies the PWM breath period in breath mode. Unit: ms.
176  This parameter must be a number between 0 ~ 0xFFFFFFFF/SystemFreq*1000. */
177 
178  uint32_t hperiod; /**< Specifies the PWM hold period in breath mode. Unit: ms.
179  This parameter must be a number between 0 ~ 0xFFFFFF/SystemFreq*1000. */
180 
181  uint32_t bstoplvl; /**< Specifies the PWM io level when stop.
182  This parameter can be a value of @ref PWM_STOP_LVL */
183 
184  pwm_none_coding_channel_init_t channel_a; /**< Specifies the configuration parameters of channel A. */
185 
186  pwm_none_coding_channel_init_t channel_b; /**< Specifies the configuration parameters of channel B. */
187 
188  pwm_none_coding_channel_init_t channel_c; /**< Specifies the configuration parameters of channel C. */
190 
191 /**
192  * @brief PWM Coding Init Structure definition
193  */
194 typedef struct
195 {
196  uint32_t period; /**< Specifies the period value which will be used configure PWM output frequency in coding mode.
197  This parameter must be a number ranges between Min_Data = 0 and Max_Data = SysCoreCLK.*/
198 
199  uint32_t waiting_time; /**< Specifies the waiting time before PWM waveform generation in coding mode.
200  This parameter control PWM waiting time count in the coding mode.*/
201 
202  uint8_t data_width_valid; /**< Specifies the coding data valid width in Coding mode.
203  This parameter control coding data valid width = DATA_WIDTH_VALID + 1,
204  DATA_WIDTH_VALID value ranges between Min_Data = 0x0 and Max_Data = 0x1F.*/
205 
206  uint8_t coding_channel_select; /**< Specifies the coding channel select all 3 channels or only channel A.
207  This parameter can be a value of @ref PWM_CODING_CHANNEL*/
208 
209  pwm_coding_channel_init_t channel_a; /**< Specifies the configuration of channelA in coding mode.
210  This parameter can be a value of @ref pwm_coding_channel_init_t.*/
211 
212  pwm_coding_channel_init_t channel_b; /**< Specifies the configuration of channelB in coding mode.
213  This parameter can be a value of @ref pwm_coding_channel_init_t.*/
214 
215  pwm_coding_channel_init_t channel_c; /**< Specifies the configuration of channelC in coding mode.
216  This parameter can be a value of @ref pwm_coding_channel_init_t.*/
218 
219 /**
220  * @brief PWM Init Structure definition
221  */
222 typedef struct
223 {
224  hal_pwm_mode_t mode; /**< Specifies the PWM output mode state.
225  This parameter can be a value of @ref PWM_Mode */
226 
227  uint32_t prd_cycles; /**< Specifies the number of period cycle in Flicker mode or Coding mode.
228  This parameter control the number of period cycles, when set to 0 will continuously generate waveform.*/
229 
230  pwm_none_coding_init_t none_coding_mode_cfg; /**< Specifies the none coding mode config.
231  This parameter can be a value of @ref pwm_none_coding_init_t.*/
232 
233  pwm_coding_init_t coding_mode_cfg; /**< Specifies the coding mode config.
234  This parameter can be a value of @ref pwm_coding_init_t.*/
235 } pwm_init_t;
236 
237 /** @} */
238 
239 /** @defgroup PWM_handle PWM handle
240  * @{
241  */
242 
243 /**
244  * @brief PWM handle Structure definition
245  */
246 typedef struct
247 {
248  pwm_regs_t *p_instance; /**< Register base address */
249 
250  pwm_init_t init; /**< Required parameters for PWM Base */
251 
252  hal_pwm_active_channel_t active_channel; /**< Active channel */
253 
254  __IO hal_pwm_state_t state; /**< PWM operation state */
255 
256  dma_handle_t *p_dma; /**< PWM DMA Handle parameters */
257 
258  uint32_t retention[15]; /**< PWM important register information. */
259 
260  hal_status_t (*p_hal_pwm_update_freq)(void); /**< PWM update_freq function. */
261 } pwm_handle_t;
262 
263 /** @} */
264 
265 /** @} */
266 
267 /** @addtogroup HAL_PWM_CALLBACK_STRUCTURES Callback Structures
268  * @{
269  */
270 
271 /** @defgroup HAL_PWM_Callback Callback
272  * @{
273  */
274 
275 /**
276  * @brief HAL_PWM Callback function definition
277  */
278 
279 typedef struct _hal_pwm_callback
280 {
281  void (*pwm_msp_init)(pwm_handle_t *p_pwm); /**< PWM init MSP callback */
282  void (*pwm_msp_deinit)(pwm_handle_t *p_pwm); /**< PWM de-init MSP callback */
284 
285 /** @} */
286 
287 /** @} */
288 
289 /**
290  * @defgroup HAL_PWM_MACRO Defines
291  * @{
292  */
293 
294 /* Exported constants --------------------------------------------------------*/
295 /** @defgroup PWM_Exported_Constants PWM Exported Constants
296  * @{
297  */
298 
299 /** @defgroup PWM_Error_Code PWM error code
300  * @{
301  */
302 #define HAL_PWM_ERROR_NONE (0x00000000U) /**< No error */
303 #define HAL_PWM_CHANNEL_A_ERROR (0x00000001U) /**< Channel A error */
304 #define HAL_PWM_CHANNEL_B_ERROR (0x00000002U) /**< Channel B error */
305 #define HAL_PWM_CHANNEL_C_ERROR (0x00000004U) /**< Channel C error */
306 /** @} */
307 
308 /** @defgroup PWM_Mode PWM Pulses Aligned.
309  * @{
310  */
311 #define PWM_ALIGNED_EDGE LL_PWM_EDGE_ALIGNED /**< PWM edge-aligned */
312 #define PWM_ALIGNED_CENTER LL_PWM_CENTER_ALIGNED /**< PWM center-aligned */
313 /** @} */
314 
315 /** @defgroup PWM_STOP_LVL PWM stop level.
316  * @{
317  */
318 #define PWM_STOP_LVL_LOW LL_PWM_STOP_LVL_LOW /**< PWM stop in low io level */
319 #define PWM_STOP_LVL_HIGH LL_PWM_STOP_LVL_HIGH /**< PWM stop in high io level */
320 /** @} */
321 
322 /** @defgroup PWM_WAITING_TIME_LVL PWM waiting time io level
323  * @{
324  */
325 #define PWM_WAITING_TIME_LVL_LOW LL_PWM_WAITING_TIME_LVL_LOW /**< PWM waiting time io level low */
326 #define PWM_WAITING_TIME_LVL_HIGH LL_PWM_WAITING_TIME_LVL_HIGH /**< PWM waiting time io level high */
327 /** @} */
328 
329 /** @defgroup PWM_CODING_CHANNEL PWM coding channel select in coding mode
330  * @{
331  */
332 #define PWM_CODING_CHANNEL_ALL LL_PWM_CODING_CHANNEL_ALL /**< Select all channels operation in coding mode */
333 #define PWM_CODING_CHANNEL_A LL_PWM_CODING_CHANNEL_A /**< Select channle A operation in coding mode */
334 /** @} */
335 
336 /** @defgroup PWM_Drive_Polarity PWM Drive Polarity
337  * @{
338  */
339 #define PWM_DRIVEPOLARITY_NEGATIVE LL_PWM_DRIVEPOLARITY_NEGATIVE /**< PWM led-negative-drive mode */
340 #define PWM_DRIVEPOLARITY_POSITIVE LL_PWM_DRIVEPOLARITY_POSITIVE /**< PWM led-positive-drive mode */
341 /** @} */
342 
343 /** @defgroup PWM_ACTIONEVENT PWM action event
344  * @{
345  */
346 #define PWM_ACTIONEVENT_NONE LL_PWM_ACTIONEVENT_NONE /**< No action event */
347 #define PWM_ACTIONEVENT_CLEAR LL_PWM_ACTIONEVENT_CLEAR /**< Action event CLEAR */
348 #define PWM_ACTIONEVENT_SET LL_PWM_ACTIONEVENT_SET /**< Action event SET */
349 #define PWM_ACTIONEVENT_TOGGLE LL_PWM_ACTIONEVENT_TOGGLE /**< Action event TOGGLE */
350 /** @} */
351 /** @} */
352 
353 /* Exported macro ------------------------------------------------------------*/
354 /** @defgroup PWM_Exported_Macros PWM Exported Macros
355  * @{
356  */
357 
358 /** @brief Reset PWM handle states.
359  * @param __HANDLE__ PWM handle.
360  * @retval None
361  */
362 #define __HAL_PWM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_PWM_STATE_RESET)
363 
364 /** @brief Enable the specified PWM peripheral.
365  * @param __HANDLE__ specifies the PWM Handle.
366  * @retval None
367  */
368 #define __HAL_PWM_ENABLE(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->MODE, PWM_MODE_EN)
369 
370 /** @brief Disable the specified PWM peripheral.
371  * @param __HANDLE__ specifies the PWM Handle.
372  * @retval None
373  */
374 #define __HAL_PWM_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->MODE, PWM_MODE_EN)
375 
376 /** @brief Enable PWM breath mode.
377  * @param __HANDLE__ specifies the PWM Handle.
378  * @retval None
379  */
380 #define __HAL_PWM_ENABLE_BREATH(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->MODE, PWM_MODE_BREATHEN)
381 
382 /** @brief Disable PWM breath mode.
383  * @param __HANDLE__ specifies the PWM Handle.
384  * @retval None
385  */
386 #define __HAL_PWM_DISABLE_BREATH(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->MODE, PWM_MODE_BREATHEN)
387 
388 /** @} */
389 
390 /* Private macros ------------------------------------------------------------*/
391 /** @defgroup PWM_Private_Macro PWM Private Macros
392  * @{
393  */
394 
395 /**
396  * @brief Check if PWM mode is valid.
397  * @param __MODE__ PWM mode.
398  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
399  */
400 #define IS_PWM_MODE(__MODE__) (((__MODE__) == PWM_FLICKER_MODE) || \
401  ((__MODE__) == PWM_BREATH_MODE) || \
402  ((__MODE__) == PWM_CODING_MODE))
403 
404 /**
405  * @brief Check if PWM Alignment mode is valid.
406  * @param __MODE__ PWM Alignment mode.
407  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
408  */
409 #define IS_PWM_ALIGNMENT_MODE(__MODE__) (((__MODE__) == PWM_ALIGNED_EDGE) || \
410  ((__MODE__) == PWM_ALIGNED_CENTER))
411 
412 /**
413  * @brief Check if PWM stop level is valid.
414  * @param __MODE__ PWM stop level.
415  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
416  */
417 #define IS_PWM_STOP_LVL(__MODE__) (((__MODE__) == PWM_STOP_LVL_LOW) || \
418  ((__MODE__) == PWM_STOP_LVL_HIGH))
419 
420 /**
421  * @brief Check if PWM waiting time level is valid.
422  * @param __MODE__ PWM waiting time level.
423  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
424  */
425 #define IS_PWM_WAITING_TIME_LVL(__MODE__) (((__MODE__) == PWM_WAITING_TIME_LVL_LOW) || \
426  ((__MODE__) == PWM_WAITING_TIME_LVL_HIGH))
427 
428 /**
429  * @brief Check if PWM drive polarity is valid.
430  * @param __POLARITY__ PWM drive polarity.
431  * @retval SET (__POLARITY__ is valid) or RESET (__POLARITY__ is invalid)
432  */
433 #define IS_PWM_DRIVEPOLARITY(__POLARITY__) (((__POLARITY__) == PWM_DRIVEPOLARITY_NEGATIVE) || \
434  ((__POLARITY__) == PWM_DRIVEPOLARITY_POSITIVE))
435 
436 /** @} */
437 
438 /** @} */
439 
440 /* Exported functions --------------------------------------------------------*/
441 /** @addtogroup HAL_PWM_DRIVER_FUNCTIONS Functions
442  * @{
443  */
444 
445 /** @addtogroup PWM_Exported_Functions_Group1 Initialization and de-initialization functions
446  * @brief Initialization and de-initialization functions
447  *
448  * @verbatim
449 ===============================================================================
450  ##### Initialization and de-initialization functions #####
451  ===============================================================================
452  [..]
453  This subsection provides a set of functions allowing to initialize the PWMx.
454  (+) The parameters below can only be configured in breath mode:
455  (++) BreathPeriod
456  (++) HoldPeriod
457 
458 @endverbatim
459  * @{
460  */
461 
462 /**
463  ****************************************************************************************
464  * @brief Initialize the PWM mode according to the specified
465  * parameters in the pwm_init_t and initialize the associated handle.
466  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
467  * @retval ::HAL_OK: Operation is OK.
468  * @retval ::HAL_ERROR: Parameter error or operation not supported.
469  * @retval ::HAL_BUSY: Driver is busy.
470  * @retval ::HAL_TIMEOUT: Timeout occurred.
471  ****************************************************************************************
472  */
474 
475 /**
476  ****************************************************************************************
477  * @brief De-initialize the PWM peripheral.
478  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
479  * @retval ::HAL_OK: Operation is OK.
480  * @retval ::HAL_ERROR: Parameter error or operation not supported.
481  * @retval ::HAL_BUSY: Driver is busy.
482  * @retval ::HAL_TIMEOUT: Timeout occurred.
483  ****************************************************************************************
484  */
486 
487 /**
488  ****************************************************************************************
489  * @brief Initialize the PWM MSP.
490  * @note This function should not be modified. When the callback is needed,
491  the hal_pwm_msp_init can be implemented in the user file.
492  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
493  ****************************************************************************************
494  */
496 
497 /**
498  ****************************************************************************************
499  * @brief De-initialize the PWM MSP.
500  * @note This function should not be modified. When the callback is needed,
501  the hal_pwm_msp_deinit can be implemented in the user file.
502  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
503  ****************************************************************************************
504  */
506 
507 /** @} */
508 
509 /** @addtogroup PWM_Exported_Functions_Group2 IO operation functions
510  * @brief IO operation functions
511  *
512 @verbatim
513  ==============================================================================
514  ##### IO operation functions #####
515  ==============================================================================
516  [..]
517  This section provides functions allowing to:
518  (+) Start the PWM.
519  (+) Stop the PWM.
520  (+) Configure the specified PWM channel.
521 
522 @endverbatim
523  * @{
524  */
525 
526 /**
527  ****************************************************************************************
528  * @brief Starts the PWM signal generation on the output.
529  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
530  * @retval ::HAL_OK: Operation is OK.
531  * @retval ::HAL_ERROR: Parameter error or operation not supported.
532  * @retval ::HAL_BUSY: Driver is busy.
533  * @retval ::HAL_TIMEOUT: Timeout occurred.
534  ****************************************************************************************
535  */
537 
538 /**
539  ****************************************************************************************
540  * @brief Stops the PWM signal generation on the output.
541  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
542  * @retval ::HAL_OK: Operation is OK.
543  * @retval ::HAL_ERROR: Parameter error or operation not supported.
544  * @retval ::HAL_BUSY: Driver is busy.
545  * @retval ::HAL_TIMEOUT: Timeout occurred.
546  ****************************************************************************************
547  */
549 
550 /**
551  ****************************************************************************************
552  * @brief Resume the PWM signal generation on the output.
553  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
554  * @retval ::HAL_OK: Operation is OK.
555  * @retval ::HAL_ERROR: Parameter error or operation not supported.
556  * @retval ::HAL_BUSY: Driver is busy.
557  * @retval ::HAL_TIMEOUT: Timeout occurred.
558  ****************************************************************************************
559  */
561 
562 /**
563  ****************************************************************************************
564  * @brief Pause the PWM signal generation on the output.
565  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
566  * @retval ::HAL_OK: Operation is OK.
567  * @retval ::HAL_ERROR: Parameter error or operation not supported.
568  * @retval ::HAL_BUSY: Driver is busy.
569  * @retval ::HAL_TIMEOUT: Timeout occurred.
570  ****************************************************************************************
571  */
573 
574 /**
575  ****************************************************************************************
576  * @brief Update the PWM frequency on the output.
577  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
578  * @param[in] freq: This parameter ranges between min = 0 and max = SystemFreq / 2.
579  * @retval ::HAL_OK: Operation is OK.
580  * @retval ::HAL_ERROR: Parameter error or operation not supported.
581  * @retval ::HAL_BUSY: Driver is busy.
582  * @retval ::HAL_TIMEOUT: Timeout occurred.
583  ****************************************************************************************
584  */
586 
587 /**
588  ****************************************************************************************
589  * @brief Suspend some registers related to PWM configuration before sleep.
590  * @param[in] p_pwm: Pointer to a PWM handle which contains the configuration
591  * information for the specified PWM module.
592  * @retval None
593  ****************************************************************************************
594  */
596 
597 /**
598  ****************************************************************************************
599  * @brief Restore some registers related to PWM configuration after sleep.
600  * This function must be used in conjunction with the hal_pwm_suspend_reg().
601  * @param[in] p_pwm: Pointer to a PWM handle which contains the configuration
602  * information for the specified PWM module.
603  * @retval None
604  ****************************************************************************************
605  */
606 void hal_pwm_resume_reg(const pwm_handle_t *p_pwm);
607 
608 #ifdef HAL_PM_ENABLE
609 /**
610  ****************************************************************************************
611  * @brief Suspend the specified PWM.
612  * @param[in] p_pwm: Pointer to a PWM handle
613  * @retval ::HAL_PM_ACTIVE: Device is active, not allow sleep.
614  * @retval ::HAL_PM_SLEEP: Allow sleep.
615  ****************************************************************************************
616  */
618 
619 /**
620  ****************************************************************************************
621  * @brief Resume the specified PWM
622  * @param[in] p_pwm: Pointer to a PWM handle
623  * @retval ::None
624  ****************************************************************************************
625  */
626 void hal_pm_pwm_resume(const pwm_handle_t *p_pwm);
627 #endif /* HAL_PM_ENABLE */
628 
629 /**
630  ****************************************************************************************
631  * @brief Initialize the PWM channels according to the specified
632  * parameters in the pwm_init_t.
633  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
634  * @param[in] p_config: PWM Channels configuration structure.
635  * @param[in] channel: PWM Channels to be configured.
636  * This parameter can be one of the following values:
637  * @arg @ref HAL_PWM_ACTIVE_CHANNEL_A :PWM Channel A is active
638  * @arg @ref HAL_PWM_ACTIVE_CHANNEL_B :PWM Channel B is active
639  * @arg @ref HAL_PWM_ACTIVE_CHANNEL_C :PWM Channel C is active
640  * @arg @ref HAL_PWM_ACTIVE_CHANNEL_ALL :All Channels are active
641  * @retval ::HAL_OK: Operation is OK.
642  * @retval ::HAL_ERROR: Parameter error or operation not supported.
643  * @retval ::HAL_BUSY: Driver is busy.
644  * @retval ::HAL_TIMEOUT: Timeout occurred.
645  ****************************************************************************************
646  */
648 
649 /**
650  ****************************************************************************************
651  * @brief Set the specified PWM channel inactive
652  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
653  * @param[in] channel: PWM Channels to be configured.
654  * @retval ::HAL_OK: Operation is OK.
655  * @retval ::HAL_ERROR: Parameter error or operation not supported.
656  * @retval ::HAL_BUSY: Driver is busy.
657  * @retval ::HAL_TIMEOUT: Timeout occurred.
658  ****************************************************************************************
659  */
661 
662 /**
663  ****************************************************************************************
664  * @brief Set pwm coding data
665  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
666  * @param[in] coding_data: every bit represent compa0 or compa1 in coding data.
667  * @retval ::HAL_OK: Operation is OK.
668  * @retval ::HAL_ERROR: Parameter error or operation not supported.
669  * @retval ::HAL_BUSY: Driver is busy.
670  * @retval ::HAL_TIMEOUT: Timeout occurred.
671  ****************************************************************************************
672  */
674 
675 /**
676  ****************************************************************************************
677  * @brief Set pwm coding data
678  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
679  * @param[in] coding_data0: every bit represent compa0 or compa1 in coding data0.
680  * @param[in] coding_data1: every bit represent compb0 or compb1 in coding data1.
681  * @param[in] coding_data2: every bit represent compc0 or compc1 in coding data2.
682  * @retval ::HAL_OK: Operation is OK.
683  * @retval ::HAL_ERROR: Parameter error or operation not supported.
684  * @retval ::HAL_BUSY: Driver is busy.
685  * @retval ::HAL_TIMEOUT: Timeout occurred.
686  ****************************************************************************************
687  */
688 hal_status_t hal_pwm_set_coding_data_in_three_channels(const pwm_handle_t *p_pwm, uint32_t coding_data0, uint32_t coding_data1, uint32_t coding_data2);
689 
690 /**
691  ****************************************************************************************
692  * @brief Start generate wave form in DMA mode
693  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
694  * @param[in] p_data: the coding data address.
695  * @param[in] size: coding data size.
696  * @retval ::HAL_OK: Operation is OK.
697  * @retval ::HAL_ERROR: Parameter error or operation not supported.
698  * @retval ::HAL_BUSY: Driver is busy.
699  * @retval ::HAL_TIMEOUT: Timeout occurred.
700  ****************************************************************************************
701  */
702 hal_status_t hal_pwm_start_coding_with_dma(pwm_handle_t *p_pwm, uint32_t *p_data, uint16_t size);
703 
704 /**
705  ****************************************************************************************
706  * @brief Start generate one channel wave form in Interrupt mode
707  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
708  * @param[in] coding_data: every bit represent compa0 or compa1 in coding data0.
709  * @retval ::HAL_OK: Operation is OK.
710  * @retval ::HAL_ERROR: Parameter error or operation not supported.
711  * @retval ::HAL_BUSY: Driver is busy.
712  * @retval ::HAL_TIMEOUT: Timeout occurred.
713  ****************************************************************************************
714  */
716 
717 /**
718  ****************************************************************************************
719  * @brief Start generate three channels wave form in Interrupt mode
720  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
721  * @param[in] coding_data0: every bit represent compa0 or compa1 in coding data0.
722  * @param[in] coding_data1: every bit represent compb0 or compb1 in coding data1.
723  * @param[in] coding_data2: every bit represent compc0 or compc1 in coding data2.
724  * @retval ::HAL_OK: Operation is OK.
725  * @retval ::HAL_ERROR: Parameter error or operation not supported.
726  * @retval ::HAL_BUSY: Driver is busy.
727  * @retval ::HAL_TIMEOUT: Timeout occurred.
728  ****************************************************************************************
729  */
730 hal_status_t hal_pwm_start_coding_in_three_channels(pwm_handle_t *p_pwm, uint32_t coding_data0, uint32_t coding_data1, uint32_t coding_data2);
731 
732 /**
733  ****************************************************************************************
734  * @brief PWM irq handler.
735  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration
736  * information for the specified PWM module.
737  * @retval ::None
738  ****************************************************************************************
739  */
741 
742 /**
743  ****************************************************************************************
744  * @brief Return the PWM handle state.
745  * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration
746  * information for the specified PWM module.
747  * @retval ::HAL_PWM_STATE_RESET: Peripheral is not initialized or disabled.
748  * @retval ::HAL_PWM_STATE_READY: Peripheral is initialized and ready for use.
749  * @retval ::HAL_PWM_STATE_BUSY: An internal process is ongoing.
750  * @retval ::HAL_PWM_STATE_ERROR: Reception process is ongoing.
751  ****************************************************************************************
752  */
754 
755 /** @} */
756 
757 /** @} */
758 
759 #ifdef __cplusplus
760 }
761 #endif
762 
763 #endif /* HAL_PWM_H */
764 
765 /** @} */
766 
767 /** @} */
768 
769 /** @} */
pwm_coding_init_t::period
uint32_t period
Definition: hal_pwm.h:196
hal_pwm_pause
hal_status_t hal_pwm_pause(pwm_handle_t *p_pwm)
Pause the PWM signal generation on the output.
pwm_init_t
PWM Init Structure definition.
Definition: hal_pwm.h:223
pwm_coding_init_t::channel_c
pwm_coding_channel_init_t channel_c
Definition: hal_pwm.h:215
hal_pwm_init
hal_status_t hal_pwm_init(pwm_handle_t *p_pwm)
Initialize the PWM mode according to the specified parameters in the pwm_init_t and initialize the as...
pwm_coding_init_t::channel_a
pwm_coding_channel_init_t channel_a
Definition: hal_pwm.h:209
pwm_init_t::prd_cycles
uint32_t prd_cycles
Definition: hal_pwm.h:227
HAL_PWM_STATE_READY
@ HAL_PWM_STATE_READY
Definition: hal_pwm.h:86
PWM_CODING_MODE
@ PWM_CODING_MODE
Definition: hal_pwm.h:77
_hal_pwm_callback
HAL_PWM Callback function definition.
Definition: hal_pwm.h:280
HAL_PWM_STATE_RESET
@ HAL_PWM_STATE_RESET
Definition: hal_pwm.h:85
pwm_handle_t::p_dma
dma_handle_t * p_dma
Definition: hal_pwm.h:256
pwm_none_coding_init_t::bperiod
uint32_t bperiod
Definition: hal_pwm.h:175
hal_pwm_resume
hal_status_t hal_pwm_resume(pwm_handle_t *p_pwm)
Resume the PWM signal generation on the output.
hal_pwr_mgmt.h
This file contains all the functions prototypes for the HAL module driver.
pwm_comp_config_t
PWM COMP value init Structure definition.
Definition: hal_pwm.h:122
pwm_handle_t::p_instance
pwm_regs_t * p_instance
Definition: hal_pwm.h:248
pwm_comp_config_t::comp_a1
uint32_t comp_a1
Definition: hal_pwm.h:124
pwm_none_coding_init_t::channel_c
pwm_none_coding_channel_init_t channel_c
Definition: hal_pwm.h:188
hal_pwm_msp_deinit
void hal_pwm_msp_deinit(pwm_handle_t *p_pwm)
De-initialize the PWM MSP.
HAL_PWM_STATE_ERROR
@ HAL_PWM_STATE_ERROR
Definition: hal_pwm.h:88
pwm_none_coding_init_t
PWM None Coding Init Structure definition.
Definition: hal_pwm.h:168
pwm_init_t::none_coding_mode_cfg
pwm_none_coding_init_t none_coding_mode_cfg
Definition: hal_pwm.h:230
pwm_comp_config_t::comp_c1
uint32_t comp_c1
Definition: hal_pwm.h:128
pwm_coding_channel_init_t::comp0
uint32_t comp0
Definition: hal_pwm.h:151
hal_pwm_suspend_reg
void hal_pwm_suspend_reg(pwm_handle_t *p_pwm)
Suspend some registers related to PWM configuration before sleep.
hal_pm_status_t
hal_pm_status_t
Definition: hal_pwr_mgmt.h:59
hal_pwm_deinit
hal_status_t hal_pwm_deinit(pwm_handle_t *p_pwm)
De-initialize the PWM peripheral.
hal_pwm_callback_t
struct _hal_pwm_callback hal_pwm_callback_t
HAL_PWM Callback function definition.
pwm_none_coding_init_t::freq
uint32_t freq
Definition: hal_pwm.h:172
HAL_PWM_ACTIVE_CHANNEL_C
@ HAL_PWM_ACTIVE_CHANNEL_C
Definition: hal_pwm.h:102
pwm_init_t::mode
hal_pwm_mode_t mode
Definition: hal_pwm.h:224
hal_pwm_mode_t
hal_pwm_mode_t
HAL_PWM_MODE Enumerations definition.
Definition: hal_pwm.h:74
hal_pwm_inactive_channel
hal_status_t hal_pwm_inactive_channel(const pwm_handle_t *p_pwm, hal_pwm_active_channel_t channel)
Set the specified PWM channel inactive.
hal_pwm_start_coding_in_three_channels
hal_status_t hal_pwm_start_coding_in_three_channels(pwm_handle_t *p_pwm, uint32_t coding_data0, uint32_t coding_data1, uint32_t coding_data2)
Start generate three channels wave form in Interrupt mode.
pwm_comp_config_t::comp_c0
uint32_t comp_c0
Definition: hal_pwm.h:127
PWM_FLICKER_MODE
@ PWM_FLICKER_MODE
Definition: hal_pwm.h:75
pwm_handle_t::init
pwm_init_t init
Definition: hal_pwm.h:250
HAL_PWM_ACTIVE_CHANNEL_B
@ HAL_PWM_ACTIVE_CHANNEL_B
Definition: hal_pwm.h:101
pwm_none_coding_channel_init_t::duty
uint8_t duty
Definition: hal_pwm.h:136
pwm_coding_init_t::data_width_valid
uint8_t data_width_valid
Definition: hal_pwm.h:202
hal_pwm_start_coding_with_dma
hal_status_t hal_pwm_start_coding_with_dma(pwm_handle_t *p_pwm, uint32_t *p_data, uint16_t size)
Start generate wave form in DMA mode.
hal_pm_pwm_suspend
hal_pm_status_t hal_pm_pwm_suspend(pwm_handle_t *p_pwm)
Suspend the specified PWM.
pwm_comp_config_t::comp_b1
uint32_t comp_b1
Definition: hal_pwm.h:126
pwm_coding_init_t
PWM Coding Init Structure definition.
Definition: hal_pwm.h:195
hal_pm_pwm_resume
void hal_pm_pwm_resume(const pwm_handle_t *p_pwm)
Resume the specified PWM.
pwm_coding_channel_init_t::waiting_time_lvl
uint8_t waiting_time_lvl
Definition: hal_pwm.h:160
hal_pwm_stop
hal_status_t hal_pwm_stop(pwm_handle_t *p_pwm)
Stops the PWM signal generation on the output.
hal_pwm_active_channel_t
hal_pwm_active_channel_t
HAL PWM active channel Enumerations definition.
Definition: hal_pwm.h:99
ll_pwm.h
Header file containing functions prototypes of PWM LL library.
pwm_coding_init_t::waiting_time
uint32_t waiting_time
Definition: hal_pwm.h:199
HAL_PWM_STATE_BUSY
@ HAL_PWM_STATE_BUSY
Definition: hal_pwm.h:87
pwm_init_t::coding_mode_cfg
pwm_coding_init_t coding_mode_cfg
Definition: hal_pwm.h:233
pwm_handle_t
PWM handle Structure definition.
Definition: hal_pwm.h:247
pwm_none_coding_init_t::channel_b
pwm_none_coding_channel_init_t channel_b
Definition: hal_pwm.h:186
pwm_comp_config_t::comp_b0
uint32_t comp_b0
Definition: hal_pwm.h:125
pwm_coding_channel_init_t::comp1
uint32_t comp1
Definition: hal_pwm.h:154
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr_common.h:140
hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
HAL_PWM_ACTIVE_CHANNEL_ALL
@ HAL_PWM_ACTIVE_CHANNEL_ALL
Definition: hal_pwm.h:103
pwm_coding_init_t::coding_channel_select
uint8_t coding_channel_select
Definition: hal_pwm.h:206
pwm_none_coding_init_t::hperiod
uint32_t hperiod
Definition: hal_pwm.h:178
pwm_comp_config_t::comp_a0
uint32_t comp_a0
Definition: hal_pwm.h:123
hal_pwm_start
hal_status_t hal_pwm_start(pwm_handle_t *p_pwm)
Starts the PWM signal generation on the output.
hal_pwm_state_t
hal_pwm_state_t
HAL PWM State Enumerations definition.
Definition: hal_pwm.h:84
pwm_handle_t::state
__IO hal_pwm_state_t state
Definition: hal_pwm.h:254
HAL_PWM_ACTIVE_CHANNEL_A
@ HAL_PWM_ACTIVE_CHANNEL_A
Definition: hal_pwm.h:100
_hal_pwm_callback::pwm_msp_init
void(* pwm_msp_init)(pwm_handle_t *p_pwm)
Definition: hal_pwm.h:281
hal_pwm_get_state
hal_pwm_state_t hal_pwm_get_state(const pwm_handle_t *p_pwm)
Return the PWM handle state.
pwm_none_coding_init_t::bstoplvl
uint32_t bstoplvl
Definition: hal_pwm.h:181
hal_dma.h
Header file containing functions prototypes of DMA HAL library.
pwm_none_coding_init_t::align
uint32_t align
Definition: hal_pwm.h:169
hal_pwm_start_coding_in_one_channel
hal_status_t hal_pwm_start_coding_in_one_channel(pwm_handle_t *p_pwm, uint32_t coding_data)
Start generate one channel wave form in Interrupt mode.
pwm_none_coding_init_t::channel_a
pwm_none_coding_channel_init_t channel_a
Definition: hal_pwm.h:184
hal_pwm_msp_init
void hal_pwm_msp_init(pwm_handle_t *p_pwm)
Initialize the PWM MSP.
pwm_coding_init_t::channel_b
pwm_coding_channel_init_t channel_b
Definition: hal_pwm.h:212
pwm_coding_channel_init_t
PWM Coding Channel init Structure definition.
Definition: hal_pwm.h:150
pwm_none_coding_channel_init_t::fstoplvl
uint32_t fstoplvl
Definition: hal_pwm.h:142
HAL_PWM_ACTIVE_CHANNEL_CLEARED
@ HAL_PWM_ACTIVE_CHANNEL_CLEARED
Definition: hal_pwm.h:104
pwm_none_coding_channel_init_t
PWM None Coding Channel init Structure definition.
Definition: hal_pwm.h:135
pwm_none_coding_channel_init_t::drive_polarity
uint8_t drive_polarity
Definition: hal_pwm.h:139
hal_pwm_set_coding_data_in_one_channel
hal_status_t hal_pwm_set_coding_data_in_one_channel(const pwm_handle_t *p_pwm, uint32_t coding_data)
Set pwm coding data.
hal_pwm_set_coding_data_in_three_channels
hal_status_t hal_pwm_set_coding_data_in_three_channels(const pwm_handle_t *p_pwm, uint32_t coding_data0, uint32_t coding_data1, uint32_t coding_data2)
Set pwm coding data.
hal_pwm_config_channel
hal_status_t hal_pwm_config_channel(pwm_handle_t *p_pwm, const pwm_none_coding_channel_init_t *p_config, hal_pwm_active_channel_t channel)
Initialize the PWM channels according to the specified parameters in the pwm_init_t.
_dma_handle
DMA handle Structure definition.
Definition: hal_dma.h:195
hal_pwm_update_freq
hal_status_t hal_pwm_update_freq(pwm_handle_t *p_pwm, uint32_t freq)
Update the PWM frequency on the output.
hal_pwm_irq_handler
void hal_pwm_irq_handler(pwm_handle_t *p_pwm)
PWM irq handler.
PWM_BREATH_MODE
@ PWM_BREATH_MODE
Definition: hal_pwm.h:76
hal_pwm_resume_reg
void hal_pwm_resume_reg(const pwm_handle_t *p_pwm)
Restore some registers related to PWM configuration after sleep. This function must be used in conjun...
pwm_coding_channel_init_t::drive_polarity
uint8_t drive_polarity
Definition: hal_pwm.h:157
pwm_handle_t::active_channel
hal_pwm_active_channel_t active_channel
Definition: hal_pwm.h:252
_hal_pwm_callback::pwm_msp_deinit
void(* pwm_msp_deinit)(pwm_handle_t *p_pwm)
Definition: hal_pwm.h:282