app_pwm.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file app_pwm.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of PWM app 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 APP_DRIVER APP DRIVER
43 * @{
44 */
45
46 /** @defgroup APP_PWM PWM
47 * @brief PWM APP module driver.
48 * @{
49 */
50 #ifndef _APP_PWM_H_
51 #define _APP_PWM_H_
52
53 #include "grx_hal.h"
54 #include "app_io.h"
55 #include "app_drv_error.h"
56 #include "app_drv_config.h"
57 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
58 #include "app_dma.h"
59 #endif
60
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64
65 #ifdef HAL_PWM_MODULE_ENABLED
66
67 /** @addtogroup APP_PWM_DEFINE Defines
68 * @{
69 */
70
71 #define APP_PWM_PIN_ENABLE 1 /**< PWM pin enable */
72 #define APP_PWM_PIN_DISABLE 0 /**< PWM pin disable */
73
74 /** @} */
75
76 /** @addtogroup APP_PWM_ENUM Enumerations
77 * @{
78 */
79
80 /**
81 * @brief PWM module Enumerations definition
82 */
83 typedef enum
84 {
85 APP_PWM_ID_0, /**< PWM module 0 */
86 APP_PWM_ID_1, /**< PWM module 1 */
87 APP_PWM_ID_MAX /**< Only for check parameter, not used as input parameters. */
88 } app_pwm_id_t;
89
90 /**
91 * @brief PWM active channel Enumerations definition
92 */
93 typedef enum
94 {
95 APP_PWM_ACTIVE_CHANNEL_A = 0x01, /**< The active channel is A */
96 APP_PWM_ACTIVE_CHANNEL_B = 0x02, /**< The active channel is B */
97 APP_PWM_ACTIVE_CHANNEL_C = 0x04, /**< The active channel is C */
98 APP_PWM_ACTIVE_CHANNEL_ALL = 0x07, /**< The active channels are ALL */
99 APP_PWM_ACTIVE_CHANNEL_CLEARED = 0x00 /**< All active channels are cleared */
100 } app_pwm_active_channel_t;
101
102 /**@brief App pwm state types. */
103 typedef enum
104 {
105 APP_PWM_INVALID = 0,
106 APP_PWM_ACTIVITY,
107 #ifdef APP_DRIVER_WAKEUP_CALL_FUN
108 APP_PWM_SLEEP,
109 #endif
110
111 } app_pwm_state_t;
112
113 /**@brief App pwm module state types. */
114 typedef enum
115 {
116 APP_PWM_STOP = 0,
117 APP_PWM_START,
118 } app_pwm_module_state_t;
119
120 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
121 /**
122 * @brief PWM event Enumerations definition
123 */
124 typedef enum
125 {
126 APP_PWM_CHANNEL_A_ERROR, /**< Channel A error in coding mode. */
127 APP_PWM_CHANNEL_B_ERROR, /**< Channel B error in coding mode. */
128 APP_PWM_CHANNEL_C_ERROR, /**< Channel C error in coding mode. */
129 APP_PWM_CODING_DONE, /**< Coding done in coding mode. */
130 APP_PWM_CODING_LOAD, /**< Coding load in coding mode. */
131 } app_pwm_evt_type_t;
132 #endif
133
134 /** @} */
135
136 /** @addtogroup APP_PWM_STRUCTURES Structures
137 * @{
138 */
139
140 /**
141 * @brief PWM IO configuration Structures
142 */
143 typedef struct
144 {
145 app_io_type_t type; /**< Specifies the type of PWM IO. */
146 app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */
147 uint32_t pin; /**< Specifies the IO pins to be configured.
148 This parameter can be any value of @ref GR5xxx_pins. */
149 app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */
150 uint8_t enable; /**< Enable or disable the pin. */
151 } app_pwm_pin_t;
152
153 /**
154 * @brief PWM configuration Structures
155 */
156 typedef struct
157 {
158 app_pwm_pin_t channel_a; /**< Set the configuration of PWM channel A pin. */
159 app_pwm_pin_t channel_b; /**< Set the configuration of PWM channel B pin. */
160 app_pwm_pin_t channel_c; /**< Set the configuration of PWM channel C pin. */
161 } app_pwm_pin_cfg_t;
162
163 /**
164 * @brief PWM Channel init Structure definition
165 */
166 typedef struct
167 {
168 uint8_t duty; /**< Specifies the duty in PWM output mode.
169 This parameter must be a number between 0 ~ 100.*/
170
171 uint8_t drive_polarity; /**< Specifies the drive polarity in PWM output mode.
172 This parameter can be a value of @ref PWM_Drive_Polarity.*/
173 #if (APP_DRIVER_CHIP_TYPE != APP_DRIVER_GR551X)
174 uint32_t fstoplvl; /**< Specifies the PWM io level when stop.
175 This parameter can be a value of @ref PWM_STOP_LVL */
176 #endif
177 } app_pwm_channel_init_t;
178
179 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
180 /**
181 * @brief PWM operate mode Enumerations definition
182 */
183 typedef struct
184 {
185 dma_regs_t *pwm_dma_instance; /**< Specifies the DMA instance.*/
186 dma_channel_t pwm_dma_channel; /**< Specifies the dma channel of PWM. */
187 } app_pwm_mode_t;
188
189 /**
190 * @brief PWM event structure definition
191 */
192 typedef struct
193 {
194 app_pwm_evt_type_t type; /**< Type of event. */
195 uint32_t error_code; /**< Error code */
196 } app_pwm_evt_t;
197
198 /**
199 * @brief PWM event callback definition
200 */
201 typedef void (*app_pwm_evt_handler_t)(app_pwm_evt_t *p_evt);
202 #endif
203
204 /**
205 * @brief PWM device structure definition
206 */
207 typedef struct
208 {
209 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
210 app_pwm_evt_handler_t evt_handler;
211 #endif
212 app_pwm_pin_cfg_t *p_pin_cfg; /**< PWM configuration Structures. */
213 app_pwm_state_t pwm_state; /**< App pwm state types. */
214 app_pwm_module_state_t pwm_module_state; /**< App pwm module state types. */
215 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
216 app_pwm_mode_t use_mode;
217 dma_id_t dma_id[1];
218 #endif
219 pwm_handle_t handle; /**< PWM handle Structure. */
220 } pwm_env_t;
221
222 /**
223 * @brief PWM parameters structure definition
224 */
225 typedef struct
226 {
227 app_pwm_id_t id; /**< specified PWM module ID. */
228 app_pwm_pin_cfg_t pin_cfg; /**< the pin configuration information for the specified PWM module. */
229 app_pwm_active_channel_t active_channel; /**< PWM operate mode. */
230 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
231 app_pwm_mode_t use_mode; /**< PWM operate mode. */
232 #endif
233 pwm_init_t init; /**< PWM communication parameters. */
234 pwm_env_t pwm_env; /**< PWM device structure definition. */
235 } app_pwm_params_t;
236 /** @} */
237
238 /* Exported functions --------------------------------------------------------*/
239 /** @addtogroup APP_PWM_DRIVER_FUNCTIONS Functions
240 * @{
241 */
242
243 /**
244 ****************************************************************************************
245 * @brief Initialize the pwm peripheral.
246 *
247 * @param[in] p_params: Pointer to app_pwm_params_t parameter which contains the
248 * configuration information for the specified PWM module.
249 *
250 * @return Result of initialization.
251 ****************************************************************************************
252 */
253 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
254 uint16_t app_pwm_init(app_pwm_params_t *p_params, app_pwm_evt_handler_t evt_handler);
255 #else
256 uint16_t app_pwm_init(app_pwm_params_t *p_params);
257 #endif
258
259 /**
260 ****************************************************************************************
261 * @brief De-initialize the pwm peripheral.
262 *
263 * @param[in] id: De-initialize for a specific ID.
264 *
265 * @return Result of De-initialization.
266 ****************************************************************************************
267 */
268 uint16_t app_pwm_deinit(app_pwm_id_t id);
269
270
271 /**
272 ****************************************************************************************
273 * @brief Starts the PWM signal generation on the output.
274 *
275 * @param[in] id: which PWM module want to output.
276 *
277 * @return Result of operation.
278 ****************************************************************************************
279 */
280 uint16_t app_pwm_start(app_pwm_id_t id);
281
282
283 /**
284 ****************************************************************************************
285 * @brief Stops the PWM signal generation on the output.
286 *
287 * @param[in] id: which PWM module want to stop output.
288 *
289 * @return Result of operation.
290 ****************************************************************************************
291 */
292 uint16_t app_pwm_stop(app_pwm_id_t id);
293
294 /**
295 ****************************************************************************************
296 * @brief Update the PWM frequency on the output.
297 *
298 * @param[in] id: which PWM module want to config.
299 * @param[in] freq: This parameter ranges between min = 0 and max = SystemFreq / 2.
300 *
301 * @return Result of operation.
302 ****************************************************************************************
303 */
304 uint16_t app_pwm_update_freq(app_pwm_id_t id, uint32_t freq);
305
306 /**
307 ****************************************************************************************
308 * @brief Initialize the PWM channels according to the specified parameters.
309 *
310 * @param[in] id: which PWM module want to config.
311 * @param[in] channel: PWM Channels to be configured.
312 * @param[in] p_config: PWM Channels configuration structure.
313 *
314 * @return Result of operation.
315 ****************************************************************************************
316 */
317 uint16_t app_pwm_config_channel(app_pwm_id_t id, app_pwm_active_channel_t channel, app_pwm_channel_init_t *p_config);
318
319 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
320 /**
321 ****************************************************************************************
322 * @brief Resume the PWM signal generation on the output.
323 *
324 * @param[in] id: which PWM module want to output.
325 *
326 * @return Result of operation.
327 ****************************************************************************************
328 */
329 uint16_t app_pwm_resume(app_pwm_id_t id);
330
331 /**
332 ****************************************************************************************
333 * @brief Pause the PWM signal generation on the output.
334 *
335 * @param[in] id: which PWM module want to stop output.
336 *
337 * @return Result of operation.
338 ****************************************************************************************
339 */
340 uint16_t app_pwm_pause(app_pwm_id_t id);
341 #endif
342
343 #if (APP_DRIVER_CHIP_TYPE != APP_DRIVER_GR551X)
344 /**
345 ****************************************************************************************
346 * @brief Set the specified PWM channel inactive
347 *
348 * @param[in] id: PWM ID.
349 * @param[in] channel: PWM Channels to be configured.
350 *
351 * @return Result of operation.
352 ****************************************************************************************
353 */
354 uint16_t app_pwm_inactive_channel(app_pwm_id_t id, app_pwm_active_channel_t channel);
355 #endif
356
357 /**
358 ****************************************************************************************
359 * @brief Return the PWM handle.
360 *
361 * @param[in] id: PWM ID.
362 *
363 * @return Pointer to the specified ID's PWM handle.
364 ****************************************************************************************
365 */
366 pwm_handle_t *app_pwm_get_handle(app_pwm_id_t id);
367
368 #if (APP_DRIVER_CHIP_TYPE == APP_DRIVER_GR5332X)
369 /**
370 ****************************************************************************************
371 * @brief Set coding data in one channel mode
372 *
373 * @param[in] id: which PWM module want to config.
374 * @param[in] coding_data: every bit represent compa0 or compa1 in coding data.
375 *
376 * @return Result of operation.
377 ****************************************************************************************
378 */
379 uint16_t app_pwm_set_coding_data_in_one_channel(app_pwm_id_t id, uint32_t coding_data);
380
381 /**
382 ****************************************************************************************
383 * @brief Set coding data in three channels mode
384 *
385 * @param[in] id: which PWM module want to config.
386 * @param[in] coding_data0: every bit represent compa0 or compa1 in coding data0.
387 * @param[in] coding_data1: every bit represent compb0 or compb1 in coding data1.
388 * @param[in] coding_data2: every bit represent compc0 or compc1 in coding data2.
389 *
390 * @return Result of operation.
391 ****************************************************************************************
392 */
393 uint16_t app_pwm_set_coding_data_in_three_channels(app_pwm_id_t id, uint32_t coding_data0, uint32_t coding_data1, uint32_t coding_data2);
394
395 /**
396 ****************************************************************************************
397 * @brief Start generate one channel wave form in Interrupt mode
398 *
399 * @param[in] id: which PWM module want to config.
400 * @param[in] coding_data: every bit represent compa0 or compa1 in coding data.
401 *
402 * @return Result of operation.
403 ****************************************************************************************
404 */
405 uint16_t app_pwm_start_coding_in_one_channel(app_pwm_id_t id, uint32_t coding_data);
406
407 /**
408 ****************************************************************************************
409 * @brief Start generate three channels wave form in Interrupt mode
410 *
411 * @param[in] id: which PWM module want to config.
412 * @param[in] coding_data0: every bit represent compa0 or compa1 in coding data0.
413 * @param[in] coding_data1: every bit represent compb0 or compb1 in coding data1.
414 * @param[in] coding_data2: every bit represent compc0 or compc1 in coding data2.
415 *
416 * @return Result of operation.
417 ****************************************************************************************
418 */
419 uint16_t app_pwm_start_coding_in_three_channels(app_pwm_id_t id, uint32_t coding_data0, uint32_t coding_data1, uint32_t coding_data2);
420 #endif
421
422 /** @} */
423
424 #endif
425
426 #ifdef __cplusplus
427 }
428 #endif
429
430 #endif
431
432 /** @} */
433
434 /** @} */
435
436 /** @} */
437
APP_PWM_ACTIVE_CHANNEL_A
@ APP_PWM_ACTIVE_CHANNEL_A
The active channel is A
Definition: app_pwm.h:95
app_pwm_channel_init_t
PWM Channel init Structure definition.
Definition: app_pwm.h:167
app_pwm_params_t::init
pwm_init_t init
PWM communication parameters.
Definition: app_pwm.h:233
app_pwm_pin_cfg_t::channel_a
app_pwm_pin_t channel_a
Set the configuration of PWM channel A pin.
Definition: app_pwm.h:158
app_pwm_pin_cfg_t::channel_b
app_pwm_pin_t channel_b
Set the configuration of PWM channel B pin.
Definition: app_pwm.h:159
app_pwm_get_handle
pwm_handle_t * app_pwm_get_handle(app_pwm_id_t id)
Return the PWM handle.
app_pwm_active_channel_t
app_pwm_active_channel_t
PWM active channel Enumerations definition.
Definition: app_pwm.h:94
app_pwm_pin_t
PWM IO configuration Structures.
Definition: app_pwm.h:144
pwm_init_t
PWM init Structure definition.
Definition: gr55xx_hal_pwm.h:128
app_pwm_update_freq
uint16_t app_pwm_update_freq(app_pwm_id_t id, uint32_t freq)
Update the PWM frequency on the output.
app_pwm_pin_t::enable
uint8_t enable
Enable or disable the pin.
Definition: app_pwm.h:150
app_pwm_params_t::pwm_env
pwm_env_t pwm_env
PWM device structure definition.
Definition: app_pwm.h:234
app_pwm_pin_t::pin
uint32_t pin
Specifies the IO pins to be configured.
Definition: app_pwm.h:147
APP_PWM_ACTIVE_CHANNEL_ALL
@ APP_PWM_ACTIVE_CHANNEL_ALL
The active channels are ALL.
Definition: app_pwm.h:98
pwm_env_t::p_pin_cfg
app_pwm_pin_cfg_t * p_pin_cfg
PWM configuration Structures.
Definition: app_pwm.h:212
app_pwm_init
uint16_t app_pwm_init(app_pwm_params_t *p_params)
Initialize the pwm peripheral.
app_io_pull_t
app_io_pull_t
GPIO pull Enumerations definition.
Definition: app_io.h:181
app_io_type_t
app_io_type_t
GPIO type Enumerations definition.
Definition: app_io.h:145
APP_PWM_ACTIVE_CHANNEL_C
@ APP_PWM_ACTIVE_CHANNEL_C
The active channel is C
Definition: app_pwm.h:97
app_pwm_state_t
app_pwm_state_t
App pwm state types.
Definition: app_pwm.h:104
app_pwm_params_t::id
app_pwm_id_t id
specified PWM module ID.
Definition: app_pwm.h:227
APP_PWM_ACTIVITY
@ APP_PWM_ACTIVITY
Definition: app_pwm.h:106
APP_PWM_ID_0
@ APP_PWM_ID_0
PWM module 0.
Definition: app_pwm.h:85
app_io.h
Header file containing functions prototypes of GPIO app library.
app_pwm_start
uint16_t app_pwm_start(app_pwm_id_t id)
Starts the PWM signal generation on the output.
app_pwm_pin_t::pull
app_io_pull_t pull
Specifies the Pull-up or Pull-Down activation for the selected pins.
Definition: app_pwm.h:149
grx_hal.h
This file contains all the functions prototypes for the HAL module driver.
app_pwm_id_t
app_pwm_id_t
PWM module Enumerations definition.
Definition: app_pwm.h:84
app_pwm_module_state_t
app_pwm_module_state_t
App pwm module state types.
Definition: app_pwm.h:115
APP_PWM_START
@ APP_PWM_START
Definition: app_pwm.h:117
APP_PWM_ID_1
@ APP_PWM_ID_1
PWM module 1.
Definition: app_pwm.h:86
pwm_handle_t
PWM handle Structure definition.
Definition: gr55xx_hal_pwm.h:161
app_pwm_stop
uint16_t app_pwm_stop(app_pwm_id_t id)
Stops the PWM signal generation on the output.
pwm_env_t::pwm_module_state
app_pwm_module_state_t pwm_module_state
App pwm module state types.
Definition: app_pwm.h:214
APP_PWM_ACTIVE_CHANNEL_B
@ APP_PWM_ACTIVE_CHANNEL_B
The active channel is B
Definition: app_pwm.h:96
app_pwm_channel_init_t::duty
uint8_t duty
Specifies the duty in PWM output mode.
Definition: app_pwm.h:168
app_pwm_channel_init_t::drive_polarity
uint8_t drive_polarity
Specifies the drive polarity in PWM output mode.
Definition: app_pwm.h:171
app_dma.h
Header file containing functions prototypes of DMA app library.
app_pwm_params_t
PWM parameters structure definition.
Definition: app_pwm.h:226
pwm_env_t
PWM device structure definition.
Definition: app_pwm.h:208
app_pwm_pin_cfg_t
PWM configuration Structures.
Definition: app_pwm.h:157
app_pwm_config_channel
uint16_t app_pwm_config_channel(app_pwm_id_t id, app_pwm_active_channel_t channel, app_pwm_channel_init_t *p_config)
Initialize the PWM channels according to the specified parameters.
link_node::channel
uint32_t channel
Which channel to be sample; This parameter can be any value of ADC_INPUT_SOURCE:ADC_INPUT_SRC_IO0~ADC...
Definition: app_adc.h:152
app_pwm_pin_t::type
app_io_type_t type
Specifies the type of PWM IO.
Definition: app_pwm.h:145
pwm_env_t::pwm_state
app_pwm_state_t pwm_state
App pwm state types.
Definition: app_pwm.h:213
pwm_env_t::handle
pwm_handle_t handle
PWM handle Structure.
Definition: app_pwm.h:219
app_io_mux_t
app_io_mux_t
GPIO mux Enumerations definition.
Definition: app_io.h:253
app_pwm_params_t::pin_cfg
app_pwm_pin_cfg_t pin_cfg
the pin configuration information for the specified PWM module.
Definition: app_pwm.h:228
APP_PWM_STOP
@ APP_PWM_STOP
Definition: app_pwm.h:116
APP_PWM_ID_MAX
@ APP_PWM_ID_MAX
Only for check parameter, not used as input parameters.
Definition: app_pwm.h:87
app_pwm_deinit
uint16_t app_pwm_deinit(app_pwm_id_t id)
De-initialize the pwm peripheral.
app_pwm_pin_cfg_t::channel_c
app_pwm_pin_t channel_c
Set the configuration of PWM channel C pin.
Definition: app_pwm.h:160
app_pwm_params_t::active_channel
app_pwm_active_channel_t active_channel
PWM operate mode.
Definition: app_pwm.h:229
app_drv_error.h
Header file of app driver error code.
app_drv_config.h
Header file of app driver config code.
APP_PWM_INVALID
@ APP_PWM_INVALID
Definition: app_pwm.h:105
app_pwm_pin_t::mux
app_io_mux_t mux
Specifies the Peripheral to be connected to the selected pins.
Definition: app_pwm.h:146
APP_PWM_ACTIVE_CHANNEL_CLEARED
@ APP_PWM_ACTIVE_CHANNEL_CLEARED
All active channels are cleared.
Definition: app_pwm.h:99
dma_id_t
int16_t dma_id_t
DMA id definition.
Definition: app_dma.h:98
dma_channel_t
dma_channel_t
HAL DMA Channel Enumerations definition.
Definition: gr55xx_hal_dma.h:93