gr533x_hal_pwm.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr533x_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 __GR533x_HAL_PWM_H__
53 #define __GR533x_HAL_PWM_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr533x_hal_def.h"
61 #include "gr533x_ll_pwm.h"
62
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_PWM_ENUMERATIONS Enumerations
65 * @{
66 */
67
68 /**
69 * @brief HAL_PWM_MODE Enumerations definition
70 */
71 typedef enum
72 {
73 PWM_FLICKER_MODE = 0x00, /**< Choose PWM Flicker Mode */
74 PWM_BREATH_MODE, /**< Choose PWM Breath Mode */
75 PWM_CODING_MODE, /**< Choose PWM Coding Mode */
76 } hal_pwm_mode_t;
77
78 /**
79 * @brief HAL PWM State Enumerations definition
80 */
81 typedef enum
82 {
83 HAL_PWM_STATE_RESET = 0x00, /**< Peripheral is not initialized or disabled */
84 HAL_PWM_STATE_READY = 0x01, /**< Peripheral is initialized and ready for use */
85 HAL_PWM_STATE_BUSY = 0x02, /**< An internal process is ongoing */
86 HAL_PWM_STATE_ERROR = 0x04 /**< Reception process is ongoing */
87 } hal_pwm_state_t;
88
89 /** @defgroup HAL_PWM_active_channel HAL PWM active channel
90 * @{
91 */
92
93 /**
94 * @brief HAL PWM active channel Enumerations definition
95 */
96 typedef enum
97 {
98 HAL_PWM_ACTIVE_CHANNEL_A = 0x01, /**< The active channel is A */
99 HAL_PWM_ACTIVE_CHANNEL_B = 0x02, /**< The active channel is B */
100 HAL_PWM_ACTIVE_CHANNEL_C = 0x04, /**< The active channel is C */
101 HAL_PWM_ACTIVE_CHANNEL_ALL = 0x07, /**< The active channels are ALL */
102 HAL_PWM_ACTIVE_CHANNEL_CLEARED = 0x00 /**< All active channels are cleared */
103 } hal_pwm_active_channel_t;
104 /** @} */
105
106 /** @} */
107
108 /** @addtogroup HAL_PWM_STRUCTURES Structures
109 * @{
110 */
111
112 /** @defgroup PWM_Configuration PWM Configuration
113 * @{
114 */
115
116 /**
117 * @brief PWM COMP value init Structure definition
118 */
119 typedef struct
120 {
121 uint32_t comp_a0; /**< Pwm comp a0 value */
122 uint32_t comp_a1; /**< Pwm comp a1 value */
123 uint32_t comp_b0; /**< Pwm comp b0 value */
124 uint32_t comp_b1; /**< Pwm comp b1 value */
125 uint32_t comp_c0; /**< Pwm comp c0 value */
126 uint32_t comp_c1; /**< Pwm comp c1 value */
127 }pwm_comp_config_t;
128
129 /**
130 * @brief PWM None Coding Channel init Structure definition
131 */
132 typedef struct
133 {
134 uint8_t duty; /**< Specifies the duty in PWM output mode.
135 This parameter must be a number between 0 ~ 100.*/
136
137 uint8_t drive_polarity; /**< Specifies the drive polarity in PWM output mode.
138 This parameter can be a value of @ref PWM_Drive_Polarity.*/
139
140 uint32_t fstoplvl; /**< Specifies the PWM io level when stop.
141 This parameter can be a value of @ref PWM_STOP_LVL */
142 } pwm_none_coding_channel_init_t;
143
144 /**
145 * @brief PWM Coding Channel init Structure definition
146 */
147 typedef struct
148 {
149 uint32_t comp0; /**< Specifies current channel first compare value
150 This parameter must be a number ranges between Min_Data=0 and Max_Data=period.*/
151
152 uint32_t comp1; /**< Specifies current channel second compare value
153 This parameter must be a number ranges between Min_Data=0 and Max_Data=period.*/
154
155 uint8_t drive_polarity; /**< Specifies the drive polarity in PWM output mode.
156 This parameter can be a value of @ref PWM_Drive_Polarity.*/
157
158 uint8_t waiting_time_lvl; /**< Specifies the waiting time level in coding mode.
159 This parameter can be a value of @ref PWM_WAITING_TIME_LVL.*/
160 } pwm_coding_channel_init_t;
161
162 /**
163 * @brief PWM None Coding Init Structure definition
164 */
165 typedef struct
166 {
167 uint32_t align; /**< Specifies the PWM alignment mode with three channels
168 This parameter can be a value of PWM_Alignment_Mode */
169
170 uint32_t freq; /**< Specifies the PWM frequency.
171 This parameter must be a number between 0 ~ SystemFreq/2.*/
172
173 uint32_t bperiod; /**< Specifies the PWM breath period in breath mode. Unit: ms.
174 This parameter must be a number between 0 ~ 0xFFFFFFFF/SystemFreq*1000. */
175
176 uint32_t hperiod; /**< Specifies the PWM hold period in breath mode. Unit: ms.
177 This parameter must be a number between 0 ~ 0xFFFFFF/SystemFreq*1000. */
178
179 uint32_t bstoplvl; /**< Specifies the PWM io level when stop.
180 This parameter can be a value of @ref PWM_STOP_LVL */
181
182 pwm_none_coding_channel_init_t channel_a; /**< Specifies the configuration parameters of channel A. */
183
184 pwm_none_coding_channel_init_t channel_b; /**< Specifies the configuration parameters of channel B. */
185
186 pwm_none_coding_channel_init_t channel_c; /**< Specifies the configuration parameters of channel C. */
187 } pwm_none_coding_init_t;
188
189 /**
190 * @brief PWM Coding Init Structure definition
191 */
192 typedef struct
193 {
194 uint32_t period; /**< Specifies the period value which will be used configure PWM output frequency in coding mode.
195 This parameter must be a number ranges between Min_Data = 0 and Max_Data = SysCoreCLK.*/
196
197 uint32_t waiting_time; /**< Specifies the waiting time before PWM waveform generation in coding mode.
198 This parameter control PWM waiting time count in the coding mode.*/
199
200 uint8_t data_width_valid; /**< Specifies the coding data valid width in Coding mode.
201 This parameter control coding data valid width = DATA_WIDTH_VALID + 1,
202 DATA_WIDTH_VALID value ranges between Min_Data = 0x0 and Max_Data = 0x1F.*/
203
204 uint8_t coding_channel_select; /**< Specifies the coding channel select all 3 channels or only channel A.
205 This parameter can be a value of @ref PWM_CODING_CHANNEL*/
206
207 pwm_coding_channel_init_t channel_a; /**< Specifies the configuration of channelA in coding mode.
208 This parameter can be a value of @ref pwm_coding_channel_init_t.*/
209
210 pwm_coding_channel_init_t channel_b; /**< Specifies the configuration of channelB in coding mode.
211 This parameter can be a value of @ref pwm_coding_channel_init_t.*/
212
213 pwm_coding_channel_init_t channel_c; /**< Specifies the configuration of channelC in coding mode.
214 This parameter can be a value of @ref pwm_coding_channel_init_t.*/
215 } pwm_coding_init_t;
216
217 /**
218 * @brief PWM Init Structure definition
219 */
220 typedef struct
221 {
222 hal_pwm_mode_t mode; /**< Specifies the PWM output mode state.
223 This parameter can be a value of @ref PWM_Mode */
224
225 uint32_t prd_cycles; /**< Specifies the number of period cycle in Flicker mode or Coding mode.
226 This parameter control the number of period cycles, when set to 0 will continuously generate waveform.*/
227
228 pwm_none_coding_init_t none_coding_mode_cfg; /**< Specifies the none coding mode config.
229 This parameter can be a value of @ref pwm_none_coding_init_t.*/
230
231 pwm_coding_init_t coding_mode_cfg; /**< Specifies the coding mode config.
232 This parameter can be a value of @ref pwm_coding_init_t.*/
233 } pwm_init_t;
234
235 /** @} */
236
237 /** @defgroup PWM_handle PWM handle
238 * @{
239 */
240
241 /**
242 * @brief PWM handle Structure definition
243 */
244 typedef struct
245 {
246 pwm_regs_t *p_instance; /**< Register base address */
247
248 pwm_init_t init; /**< Required parameters for PWM Base */
249
250 hal_pwm_active_channel_t active_channel; /**< Active channel */
251
252 __IO hal_lock_t lock; /**< Lock object */
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 */
283 } hal_pwm_callback_t;
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 */
473 hal_status_t hal_pwm_init(pwm_handle_t *p_pwm);
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 */
485 hal_status_t hal_pwm_deinit(pwm_handle_t *p_pwm);
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 */
495 void hal_pwm_msp_init(pwm_handle_t *p_pwm);
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 */
505 void hal_pwm_msp_deinit(pwm_handle_t *p_pwm);
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 */
536 hal_status_t hal_pwm_start(pwm_handle_t *p_pwm);
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 */
548 hal_status_t hal_pwm_stop(pwm_handle_t *p_pwm);
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 */
560 hal_status_t hal_pwm_resume(pwm_handle_t *p_pwm);
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 */
572 hal_status_t hal_pwm_pause(pwm_handle_t *p_pwm);
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 */
585 hal_status_t hal_pwm_update_freq(pwm_handle_t *p_pwm, uint32_t freq);
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 ::HAL_OK: Operation is OK.
593 * @retval ::HAL_ERROR: Parameter error or operation not supported.
594 * @retval ::HAL_BUSY: Driver is busy.
595 * @retval ::HAL_TIMEOUT: Timeout occurred.
596 ****************************************************************************************
597 */
598 hal_status_t hal_pwm_suspend_reg(pwm_handle_t *p_pwm);
599
600 /**
601 ****************************************************************************************
602 * @brief Restore some registers related to PWM configuration after sleep.
603 * This function must be used in conjunction with the hal_pwm_suspend_reg().
604 * @param[in] p_pwm: Pointer to a PWM handle which contains the configuration
605 * information for the specified PWM module.
606 * @retval ::HAL_OK: Operation is OK.
607 * @retval ::HAL_ERROR: Parameter error or operation not supported.
608 * @retval ::HAL_BUSY: Driver is busy.
609 * @retval ::HAL_TIMEOUT: Timeout occurred.
610 ****************************************************************************************
611 */
612 hal_status_t hal_pwm_resume_reg(pwm_handle_t *p_pwm);
613
614 /**
615 ****************************************************************************************
616 * @brief Initialize the PWM channels according to the specified
617 * parameters in the pwm_init_t.
618 * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
619 * @param[in] p_config: PWM Channels configuration structure.
620 * @param[in] channel: PWM Channels to be configured.
621 * This parameter can be one of the following values:
622 * @arg @ref HAL_PWM_ACTIVE_CHANNEL_A :PWM Channel A is active
623 * @arg @ref HAL_PWM_ACTIVE_CHANNEL_B :PWM Channel B is active
624 * @arg @ref HAL_PWM_ACTIVE_CHANNEL_C :PWM Channel C is active
625 * @arg @ref HAL_PWM_ACTIVE_CHANNEL_ALL :All Channels are active
626 * @retval ::HAL_OK: Operation is OK.
627 * @retval ::HAL_ERROR: Parameter error or operation not supported.
628 * @retval ::HAL_BUSY: Driver is busy.
629 * @retval ::HAL_TIMEOUT: Timeout occurred.
630 ****************************************************************************************
631 */
632 hal_status_t hal_pwm_config_channel(pwm_handle_t *p_pwm, pwm_none_coding_channel_init_t *p_config, hal_pwm_active_channel_t channel);
633
634 /**
635 ****************************************************************************************
636 * @brief Set the specified PWM channel inactive
637 * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
638 * @param[in] channel: PWM Channels to be configured.
639 * @retval ::HAL_OK: Operation is OK.
640 * @retval ::HAL_ERROR: Parameter error or operation not supported.
641 * @retval ::HAL_BUSY: Driver is busy.
642 * @retval ::HAL_TIMEOUT: Timeout occurred.
643 ****************************************************************************************
644 */
645 hal_status_t hal_pwm_inactive_channel(pwm_handle_t *p_pwm, hal_pwm_active_channel_t channel);
646
647 /**
648 ****************************************************************************************
649 * @brief Set pwm coding data
650 * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
651 * @param[in] coding_data: every bit represent compa0 or compa1 in coding data.
652 * @retval ::HAL_OK: Operation is OK.
653 * @retval ::HAL_ERROR: Parameter error or operation not supported.
654 * @retval ::HAL_BUSY: Driver is busy.
655 * @retval ::HAL_TIMEOUT: Timeout occurred.
656 ****************************************************************************************
657 */
658 hal_status_t hal_pwm_set_coding_data_in_one_channel(pwm_handle_t *p_pwm, uint32_t coding_data);
659
660 /**
661 ****************************************************************************************
662 * @brief Set pwm coding data
663 * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
664 * @param[in] coding_data0: every bit represent compa0 or compa1 in coding data0.
665 * @param[in] coding_data1: every bit represent compb0 or compb1 in coding data1.
666 * @param[in] coding_data2: every bit represent compc0 or compc1 in coding data2.
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 */
673 hal_status_t hal_pwm_set_coding_data_in_three_channels(pwm_handle_t *p_pwm, uint32_t coding_data0, uint32_t coding_data1, uint32_t coding_data2);
674
675 /**
676 ****************************************************************************************
677 * @brief Start generate wave form in DMA mode
678 * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
679 * @param[in] p_data: the coding data address.
680 * @param[in] size: coding data size.
681 * @retval ::HAL_OK: Operation is OK.
682 * @retval ::HAL_ERROR: Parameter error or operation not supported.
683 * @retval ::HAL_BUSY: Driver is busy.
684 * @retval ::HAL_TIMEOUT: Timeout occurred.
685 ****************************************************************************************
686 */
687 hal_status_t hal_pwm_start_coding_with_dma(pwm_handle_t *p_pwm, uint32_t *p_data, uint16_t size);
688
689 /**
690 ****************************************************************************************
691 * @brief Start generate one channel wave form in Interrupt mode
692 * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
693 * @param[in] coding_data: every bit represent compa0 or compa1 in coding data0.
694 * @retval ::HAL_OK: Operation is OK.
695 * @retval ::HAL_ERROR: Parameter error or operation not supported.
696 * @retval ::HAL_BUSY: Driver is busy.
697 * @retval ::HAL_TIMEOUT: Timeout occurred.
698 ****************************************************************************************
699 */
700 hal_status_t hal_pwm_start_coding_in_one_channel(pwm_handle_t *p_pwm, uint32_t coding_data);
701
702 /**
703 ****************************************************************************************
704 * @brief Start generate three channels wave form in Interrupt mode
705 * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration information for the specified PWM module.
706 * @param[in] coding_data0: every bit represent compa0 or compa1 in coding data0.
707 * @param[in] coding_data1: every bit represent compb0 or compb1 in coding data1.
708 * @param[in] coding_data2: every bit represent compc0 or compc1 in coding data2.
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 */
715 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);
716
717 /**
718 ****************************************************************************************
719 * @brief PWM irq handler.
720 * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration
721 * information for the specified PWM module.
722 * @retval ::None
723 ****************************************************************************************
724 */
725 void hal_pwm_irq_handler(pwm_handle_t *p_pwm);
726
727 /**
728 ****************************************************************************************
729 * @brief Return the PWM handle state.
730 * @param[in] p_pwm: Pointer to a PWM handle that contains the configuration
731 * information for the specified PWM module.
732 * @retval ::HAL_PWM_STATE_RESET: Peripheral is not initialized or disabled.
733 * @retval ::HAL_PWM_STATE_READY: Peripheral is initialized and ready for use.
734 * @retval ::HAL_PWM_STATE_BUSY: An internal process is ongoing.
735 * @retval ::HAL_PWM_STATE_ERROR: Reception process is ongoing.
736 ****************************************************************************************
737 */
738 hal_pwm_state_t hal_pwm_get_state(pwm_handle_t *p_pwm);
739
740 /** @} */
741
742 /** @} */
743
744 #ifdef __cplusplus
745 }
746 #endif
747
748 #endif /* __GR533x_HAL_PWM_H__ */
749
750 /** @} */
751
752 /** @} */
753
754 /** @} */
pwm_coding_init_t::period
uint32_t period
Definition: gr533x_hal_pwm.h:194
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr533x_hal_def.h:81
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: gr533x_hal_pwm.h:221
pwm_coding_init_t::channel_c
pwm_coding_channel_init_t channel_c
Definition: gr533x_hal_pwm.h:213
hal_pwm_suspend_reg
hal_status_t hal_pwm_suspend_reg(pwm_handle_t *p_pwm)
Suspend some registers related to PWM configuration before sleep.
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: gr533x_hal_pwm.h:207
pwm_init_t::prd_cycles
uint32_t prd_cycles
Definition: gr533x_hal_pwm.h:225
HAL_PWM_STATE_READY
@ HAL_PWM_STATE_READY
Definition: gr533x_hal_pwm.h:84
PWM_CODING_MODE
@ PWM_CODING_MODE
Definition: gr533x_hal_pwm.h:75
_hal_pwm_callback
HAL_PWM Callback function definition.
Definition: gr533x_hal_pwm.h:280
HAL_PWM_STATE_RESET
@ HAL_PWM_STATE_RESET
Definition: gr533x_hal_pwm.h:83
pwm_handle_t::p_dma
dma_handle_t * p_dma
Definition: gr533x_hal_pwm.h:256
pwm_none_coding_init_t::bperiod
uint32_t bperiod
Definition: gr533x_hal_pwm.h:173
hal_pwm_resume
hal_status_t hal_pwm_resume(pwm_handle_t *p_pwm)
Resume the PWM signal generation on the output.
pwm_comp_config_t
PWM COMP value init Structure definition.
Definition: gr533x_hal_pwm.h:120
pwm_handle_t::p_instance
pwm_regs_t * p_instance
Definition: gr533x_hal_pwm.h:246
pwm_comp_config_t::comp_a1
uint32_t comp_a1
Definition: gr533x_hal_pwm.h:122
pwm_none_coding_init_t::channel_c
pwm_none_coding_channel_init_t channel_c
Definition: gr533x_hal_pwm.h:186
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: gr533x_hal_pwm.h:86
pwm_none_coding_init_t
PWM None Coding Init Structure definition.
Definition: gr533x_hal_pwm.h:166
pwm_init_t::none_coding_mode_cfg
pwm_none_coding_init_t none_coding_mode_cfg
Definition: gr533x_hal_pwm.h:228
pwm_comp_config_t::comp_c1
uint32_t comp_c1
Definition: gr533x_hal_pwm.h:126
pwm_coding_channel_init_t::comp0
uint32_t comp0
Definition: gr533x_hal_pwm.h:149
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: gr533x_hal_pwm.h:170
HAL_PWM_ACTIVE_CHANNEL_C
@ HAL_PWM_ACTIVE_CHANNEL_C
Definition: gr533x_hal_pwm.h:100
pwm_init_t::mode
hal_pwm_mode_t mode
Definition: gr533x_hal_pwm.h:222
hal_pwm_mode_t
hal_pwm_mode_t
HAL_PWM_MODE Enumerations definition.
Definition: gr533x_hal_pwm.h:72
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: gr533x_hal_pwm.h:125
PWM_FLICKER_MODE
@ PWM_FLICKER_MODE
Definition: gr533x_hal_pwm.h:73
pwm_handle_t::init
pwm_init_t init
Definition: gr533x_hal_pwm.h:248
HAL_PWM_ACTIVE_CHANNEL_B
@ HAL_PWM_ACTIVE_CHANNEL_B
Definition: gr533x_hal_pwm.h:99
gr533x_ll_pwm.h
Header file containing functions prototypes of PWM LL library.
pwm_none_coding_channel_init_t::duty
uint8_t duty
Definition: gr533x_hal_pwm.h:134
pwm_coding_init_t::data_width_valid
uint8_t data_width_valid
Definition: gr533x_hal_pwm.h:200
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.
pwm_comp_config_t::comp_b1
uint32_t comp_b1
Definition: gr533x_hal_pwm.h:124
pwm_coding_init_t
PWM Coding Init Structure definition.
Definition: gr533x_hal_pwm.h:193
pwm_coding_channel_init_t::waiting_time_lvl
uint8_t waiting_time_lvl
Definition: gr533x_hal_pwm.h:158
hal_pwm_stop
hal_status_t hal_pwm_stop(pwm_handle_t *p_pwm)
Stops the PWM signal generation on the output.
hal_pwm_resume_reg
hal_status_t hal_pwm_resume_reg(pwm_handle_t *p_pwm)
Restore some registers related to PWM configuration after sleep. This function must be used in conjun...
pwm_handle_t::lock
__IO hal_lock_t lock
Definition: gr533x_hal_pwm.h:252
hal_pwm_active_channel_t
hal_pwm_active_channel_t
HAL PWM active channel Enumerations definition.
Definition: gr533x_hal_pwm.h:97
pwm_coding_init_t::waiting_time
uint32_t waiting_time
Definition: gr533x_hal_pwm.h:197
HAL_PWM_STATE_BUSY
@ HAL_PWM_STATE_BUSY
Definition: gr533x_hal_pwm.h:85
pwm_init_t::coding_mode_cfg
pwm_coding_init_t coding_mode_cfg
Definition: gr533x_hal_pwm.h:231
pwm_handle_t
PWM handle Structure definition.
Definition: gr533x_hal_pwm.h:245
pwm_none_coding_init_t::channel_b
pwm_none_coding_channel_init_t channel_b
Definition: gr533x_hal_pwm.h:184
pwm_comp_config_t::comp_b0
uint32_t comp_b0
Definition: gr533x_hal_pwm.h:123
pwm_coding_channel_init_t::comp1
uint32_t comp1
Definition: gr533x_hal_pwm.h:152
HAL_PWM_ACTIVE_CHANNEL_ALL
@ HAL_PWM_ACTIVE_CHANNEL_ALL
Definition: gr533x_hal_pwm.h:101
pwm_coding_init_t::coding_channel_select
uint8_t coding_channel_select
Definition: gr533x_hal_pwm.h:204
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr533x_hal_def.h:70
pwm_none_coding_init_t::hperiod
uint32_t hperiod
Definition: gr533x_hal_pwm.h:176
pwm_comp_config_t::comp_a0
uint32_t comp_a0
Definition: gr533x_hal_pwm.h:121
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: gr533x_hal_pwm.h:82
pwm_handle_t::state
__IO hal_pwm_state_t state
Definition: gr533x_hal_pwm.h:254
hal_pwm_config_channel
hal_status_t hal_pwm_config_channel(pwm_handle_t *p_pwm, 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.
HAL_PWM_ACTIVE_CHANNEL_A
@ HAL_PWM_ACTIVE_CHANNEL_A
Definition: gr533x_hal_pwm.h:98
_hal_pwm_callback::pwm_msp_init
void(* pwm_msp_init)(pwm_handle_t *p_pwm)
Definition: gr533x_hal_pwm.h:281
pwm_none_coding_init_t::bstoplvl
uint32_t bstoplvl
Definition: gr533x_hal_pwm.h:179
pwm_none_coding_init_t::align
uint32_t align
Definition: gr533x_hal_pwm.h:167
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: gr533x_hal_pwm.h:182
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: gr533x_hal_pwm.h:210
hal_pwm_inactive_channel
hal_status_t hal_pwm_inactive_channel(pwm_handle_t *p_pwm, hal_pwm_active_channel_t channel)
Set the specified PWM channel inactive.
pwm_coding_channel_init_t
PWM Coding Channel init Structure definition.
Definition: gr533x_hal_pwm.h:148
gr533x_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
pwm_none_coding_channel_init_t::fstoplvl
uint32_t fstoplvl
Definition: gr533x_hal_pwm.h:140
hal_pwm_get_state
hal_pwm_state_t hal_pwm_get_state(pwm_handle_t *p_pwm)
Return the PWM handle state.
HAL_PWM_ACTIVE_CHANNEL_CLEARED
@ HAL_PWM_ACTIVE_CHANNEL_CLEARED
Definition: gr533x_hal_pwm.h:102
pwm_none_coding_channel_init_t
PWM None Coding Channel init Structure definition.
Definition: gr533x_hal_pwm.h:133
hal_pwm_set_coding_data_in_three_channels
hal_status_t hal_pwm_set_coding_data_in_three_channels(pwm_handle_t *p_pwm, uint32_t coding_data0, uint32_t coding_data1, uint32_t coding_data2)
Set pwm coding data.
pwm_none_coding_channel_init_t::drive_polarity
uint8_t drive_polarity
Definition: gr533x_hal_pwm.h:137
_dma_handle
DMA handle Structure definition.
Definition: gr533x_hal_dma.h:194
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: gr533x_hal_pwm.h:74
hal_pwm_set_coding_data_in_one_channel
hal_status_t hal_pwm_set_coding_data_in_one_channel(pwm_handle_t *p_pwm, uint32_t coding_data)
Set pwm coding data.
pwm_coding_channel_init_t::drive_polarity
uint8_t drive_polarity
Definition: gr533x_hal_pwm.h:155
pwm_handle_t::active_channel
hal_pwm_active_channel_t active_channel
Definition: gr533x_hal_pwm.h:250
_hal_pwm_callback::pwm_msp_deinit
void(* pwm_msp_deinit)(pwm_handle_t *p_pwm)
Definition: gr533x_hal_pwm.h:282