gr55xx_hal_pwm.h
Go to the documentation of this file.
1
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_PWM_H__
53 #define __GR55xx_HAL_PWM_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_hal_def.h"
61 #include "gr55xx_ll_pwm.h"
62
63 /* Exported types ------------------------------------------------------------*/
75 typedef enum
76 {
77 HAL_PWM_STATE_RESET = 0x00,
78 HAL_PWM_STATE_READY = 0x01,
79 HAL_PWM_STATE_BUSY = 0x02,
80 HAL_PWM_STATE_ERROR = 0x04
81 } hal_pwm_state_t;
91 typedef enum
92 {
93 HAL_PWM_ACTIVE_CHANNEL_A = 0x01,
94 HAL_PWM_ACTIVE_CHANNEL_B = 0x02,
95 HAL_PWM_ACTIVE_CHANNEL_C = 0x04,
96 HAL_PWM_ACTIVE_CHANNEL_ALL = 0x07,
97 HAL_PWM_ACTIVE_CHANNEL_CLEARED = 0x00
98 } hal_pwm_active_channel_t;
114 typedef struct
115 {
116 uint8_t duty;
119 uint8_t drive_polarity;
122 } pwm_channel_init_t;
123
127 typedef struct
128 {
129 uint32_t mode;
132 uint32_t align;
135 uint32_t freq;
138 uint32_t bperiod;
141 uint32_t hperiod;
144 pwm_channel_init_t channel_a;
146 pwm_channel_init_t channel_b;
148 pwm_channel_init_t channel_c;
150 } pwm_init_t;
160 typedef struct
161 {
162 pwm_regs_t *p_instance;
164 pwm_init_t init;
166 hal_pwm_active_channel_t active_channel;
168 __IO hal_lock_t lock;
170 __IO hal_pwm_state_t state;
172 uint32_t retention[11];
174 } pwm_handle_t;
175
192 typedef struct _hal_pwm_callback
193 {
194 void (*pwm_msp_init)(pwm_handle_t *p_pwm);
195 void (*pwm_msp_deinit)(pwm_handle_t *p_pwm);
196 } hal_pwm_callback_t;
197
207 /* Exported constants --------------------------------------------------------*/
215 #define PWM_MODE_FLICKER LL_PWM_FLICKER_MODE
216 #define PWM_MODE_BREATH LL_PWM_BREATH_MODE
222 #define PWM_ALIGNED_EDGE LL_PWM_EDGE_ALIGNED
223 #define PWM_ALIGNED_CENTER LL_PWM_CENTER_ALIGNED
229 #define PWM_DRIVEPOLARITY_NEGATIVE LL_PWM_DRIVEPOLARITY_NEGATIVE
230 #define PWM_DRIVEPOLARITY_POSITIVE LL_PWM_DRIVEPOLARITY_POSITIVE
234 /* Exported macro ------------------------------------------------------------*/
235
243 #define __HAL_PWM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_PWM_STATE_RESET)
244
249 #define __HAL_PWM_ENABLE(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->MODE, PWM_MODE_EN)
250
255 #define __HAL_PWM_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->MODE, PWM_MODE_EN)
256
261 #define __HAL_PWM_ENABLE_BREATH(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->MODE, PWM_MODE_BREATHEN)
262
267 #define __HAL_PWM_DISABLE_BREATH(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->MODE, PWM_MODE_BREATHEN)
268
271 /* Private macros ------------------------------------------------------------*/
281 #define IS_PWM_MODE(__MODE__) (((__MODE__) == PWM_MODE_FLICKER) || \
282 ((__MODE__) == PWM_MODE_BREATH))
283
289 #define IS_PWM_ALIGNMENT_MODE(__MODE__) (((__MODE__) == PWM_EDGE) || \
290 ((__MODE__) == PWM_CENTER))
291
297 #define IS_PWM_DRIVEPOLARITY(__POLARITY__) (((__POLARITY__) == PWM_DRIVEPOLARITY_NEGATIVE) || \
298 ((__POLARITY__) == PWM_DRIVEPOLARITY_POSITIVE))
299
305 /* Exported functions --------------------------------------------------------*/
338 hal_status_t hal_pwm_init(pwm_handle_t *p_pwm);
339
350 hal_status_t hal_pwm_deinit(pwm_handle_t *p_pwm);
351
360 void hal_pwm_msp_init(pwm_handle_t *p_pwm);
361
370 void hal_pwm_msp_deinit(pwm_handle_t *p_pwm);
371
401 hal_status_t hal_pwm_start(pwm_handle_t *p_pwm);
402
413 hal_status_t hal_pwm_stop(pwm_handle_t *p_pwm);
414
426 hal_status_t hal_pwm_update_freq(pwm_handle_t *p_pwm, uint32_t freq);
427
439 hal_status_t hal_pwm_suspend_reg(pwm_handle_t *p_pwm);
440
453 hal_status_t hal_pwm_resume_reg(pwm_handle_t *p_pwm);
454
473 hal_status_t hal_pwm_config_channel(pwm_handle_t *p_pwm, pwm_channel_init_t *p_config, hal_pwm_active_channel_t channel);
474
503 hal_pwm_state_t hal_pwm_get_state(pwm_handle_t *p_pwm);
504
509 #ifdef __cplusplus
510 }
511 #endif
512
513 #endif /* __GR55xx_HAL_PWM_H__ */
514
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
pwm_init_t
PWM init Structure definition.
Definition: gr55xx_hal_pwm.h:128
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...
HAL_PWM_STATE_ERROR
@ HAL_PWM_STATE_ERROR
Definition: gr55xx_hal_pwm.h:80
_hal_pwm_callback
HAL_PWM Callback function definition.
Definition: gr55xx_hal_pwm.h:193
pwm_channel_init_t
PWM Channel init Structure definition.
Definition: gr55xx_hal_pwm.h:115
HAL_PWM_STATE_BUSY
@ HAL_PWM_STATE_BUSY
Definition: gr55xx_hal_pwm.h:79
pwm_handle_t::p_instance
pwm_regs_t * p_instance
Definition: gr55xx_hal_pwm.h:162
hal_pwm_msp_deinit
void hal_pwm_msp_deinit(pwm_handle_t *p_pwm)
De-initialize the PWM MSP.
pwm_init_t::mode
uint32_t mode
Definition: gr55xx_hal_pwm.h:129
pwm_init_t::hperiod
uint32_t hperiod
Definition: gr55xx_hal_pwm.h:141
HAL_PWM_STATE_READY
@ HAL_PWM_STATE_READY
Definition: gr55xx_hal_pwm.h:78
hal_pwm_state_t
hal_pwm_state_t
HAL PWM State Enumerations definition.
Definition: gr55xx_hal_pwm.h:76
pwm_init_t::freq
uint32_t freq
Definition: gr55xx_hal_pwm.h:135
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.
HAL_PWM_ACTIVE_CHANNEL_C
@ HAL_PWM_ACTIVE_CHANNEL_C
Definition: gr55xx_hal_pwm.h:95
pwm_handle_t::init
pwm_init_t init
Definition: gr55xx_hal_pwm.h:164
pwm_init_t::channel_c
pwm_channel_init_t channel_c
Definition: gr55xx_hal_pwm.h:148
HAL_PWM_ACTIVE_CHANNEL_B
@ HAL_PWM_ACTIVE_CHANNEL_B
Definition: gr55xx_hal_pwm.h:94
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: gr55xx_hal_pwm.h:168
hal_pwm_active_channel_t
hal_pwm_active_channel_t
HAL PWM active channel Enumerations definition.
Definition: gr55xx_hal_pwm.h:92
gr55xx_ll_pwm.h
Header file containing functions prototypes of PWM LL library.
pwm_handle_t
PWM handle Structure definition.
Definition: gr55xx_hal_pwm.h:161
HAL_PWM_STATE_RESET
@ HAL_PWM_STATE_RESET
Definition: gr55xx_hal_pwm.h:77
pwm_init_t::channel_b
pwm_channel_init_t channel_b
Definition: gr55xx_hal_pwm.h:146
HAL_PWM_ACTIVE_CHANNEL_ALL
@ HAL_PWM_ACTIVE_CHANNEL_ALL
Definition: gr55xx_hal_pwm.h:96
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
hal_pwm_start
hal_status_t hal_pwm_start(pwm_handle_t *p_pwm)
Starts the PWM signal generation on the output.
pwm_init_t::align
uint32_t align
Definition: gr55xx_hal_pwm.h:132
pwm_handle_t::state
__IO hal_pwm_state_t state
Definition: gr55xx_hal_pwm.h:170
HAL_PWM_ACTIVE_CHANNEL_A
@ HAL_PWM_ACTIVE_CHANNEL_A
Definition: gr55xx_hal_pwm.h:93
hal_pwm_get_state
hal_pwm_state_t hal_pwm_get_state(pwm_handle_t *p_pwm)
Return the PWM handle state.
_hal_pwm_callback::pwm_msp_init
void(* pwm_msp_init)(pwm_handle_t *p_pwm)
Definition: gr55xx_hal_pwm.h:194
pwm_channel_init_t::drive_polarity
uint8_t drive_polarity
Definition: gr55xx_hal_pwm.h:119
hal_pwm_msp_init
void hal_pwm_msp_init(pwm_handle_t *p_pwm)
Initialize the PWM MSP.
hal_pwm_config_channel
hal_status_t hal_pwm_config_channel(pwm_handle_t *p_pwm, pwm_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.
pwm_channel_init_t::duty
uint8_t duty
Definition: gr55xx_hal_pwm.h:116
HAL_PWM_ACTIVE_CHANNEL_CLEARED
@ HAL_PWM_ACTIVE_CHANNEL_CLEARED
Definition: gr55xx_hal_pwm.h:97
pwm_init_t::bperiod
uint32_t bperiod
Definition: gr55xx_hal_pwm.h:138
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.
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
pwm_init_t::channel_a
pwm_channel_init_t channel_a
Definition: gr55xx_hal_pwm.h:144
pwm_handle_t::active_channel
hal_pwm_active_channel_t active_channel
Definition: gr55xx_hal_pwm.h:166
_hal_pwm_callback::pwm_msp_deinit
void(* pwm_msp_deinit)(pwm_handle_t *p_pwm)
Definition: gr55xx_hal_pwm.h:195