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 "gr55xx_hal.h"
54 #include "app_io.h"
55 #include "app_drv_error.h"
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 #ifdef HAL_PWM_MODULE_ENABLED
62 
63 /** @addtogroup APP_PWM_DEFINE Defines
64  * @{
65  */
66 
67 #define APP_PWM_PIN_ENABLE 1 /**< PWM pin enable */
68 #define APP_PWM_PIN_DISABLE 0 /**< PWM pin disable */
69 
70 /** @} */
71 
72 /** @addtogroup APP_PWM_ENUM Enumerations
73  * @{
74  */
75 
76 /**
77  * @brief PWM module Enumerations definition
78  */
79 typedef enum
80 {
81  APP_PWM_ID_0, /**< PWM module 0 */
82  APP_PWM_ID_1, /**< PWM module 1 */
83  APP_PWM_ID_MAX /**< Only for check parameter, not used as input parameters. */
85 /** @} */
86 
87 /** @addtogroup APP_PWM_STRUCTURES Structures
88  * @{
89  */
90 /**
91  * @brief PWM IO configuration Structures
92  */
93 typedef struct
94 {
95  app_io_type_t type; /**< Specifies the type of PWM IO. */
96  app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */
97  uint32_t pin; /**< Specifies the IO pins to be configured.
98  This parameter can be any value of @ref GR551x_pins. */
99  app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */
100  uint8_t enable; /**< Enable or disable the pin. */
101 } app_pwm_pin_t;
102 
103 
104 /**
105  * @brief PWM configuration Structures
106  */
107 typedef struct
108 {
109  app_pwm_pin_t channel_a; /**< Set the configuration of PWM channel A pin. */
110  app_pwm_pin_t channel_b; /**< Set the configuration of PWM channel B pin. */
111  app_pwm_pin_t channel_c; /**< Set the configuration of PWM channel C pin. */
113 
114 
115 /**
116  * @brief PWM Channel init Structure definition
117  */
118 typedef struct
119 {
120  uint8_t duty; /**< Specifies the duty in PWM output mode.
121  This parameter must be a number between 0 ~ 100.*/
122 
123  uint8_t drive_polarity; /**< Specifies the drive polarity in PWM output mode.
124  This parameter can be a value of @ref PWM_Drive_Polarity.*/
126 /** @} */
127 
128 /** @addtogroup APP_PWM_ENUM Enumerations
129  * @{
130  */
131 /**
132  * @brief PWM active channel Enumerations definition
133  */
134 typedef enum
135 {
136  APP_PWM_ACTIVE_CHANNEL_A = 0x01, /**< The active channel is A */
137  APP_PWM_ACTIVE_CHANNEL_B = 0x02, /**< The active channel is B */
138  APP_PWM_ACTIVE_CHANNEL_C = 0x04, /**< The active channel is C */
139  APP_PWM_ACTIVE_CHANNEL_ALL = 0x07, /**< The active channels are ALL */
140  APP_PWM_ACTIVE_CHANNEL_CLEARED = 0x00 /**< All active channels are cleared */
142 /** @} */
143 
144 /** @addtogroup APP_PWM_STRUCTURES Structures
145  * @{
146  */
147 /**
148  * @brief PWM parameters structure definition
149  */
150 typedef struct
151 {
152  app_pwm_id_t id; /**< specified PWM module ID. */
153  app_pwm_pin_cfg_t pin_cfg; /**< the pin configuration information for the specified PWM module. */
154  app_pwm_active_channel_t active_channel; /**< PWM operate mode. */
155  pwm_init_t init; /**< PWM communication parameters. */
157 /** @} */
158 
159 
160 /* Exported functions --------------------------------------------------------*/
161 /** @addtogroup APP_PWM_DRIVER_FUNCTIONS Functions
162  * @{
163  */
164 
165 /**
166  ****************************************************************************************
167  * @brief Initialize the pwm peripheral.
168  *
169  * @param[in] p_params: Pointer to app_pwm_params_t parameter which contains the
170  * configuration information for the specified PWM module.
171  *
172  * @return Result of initialization.
173  ****************************************************************************************
174  */
175 uint16_t app_pwm_init(app_pwm_params_t *p_params);
176 
177 
178 /**
179  ****************************************************************************************
180  * @brief De-initialize the pwm peripheral.
181  *
182  * @param[in] id: De-initialize for a specific ID.
183  *
184  * @return Result of De-initialization.
185  ****************************************************************************************
186  */
188 
189 
190 /**
191  ****************************************************************************************
192  * @brief Starts the PWM signal generation on the output.
193  *
194  * @param[in] id: which PWM module want to output.
195  *
196  * @return Result of operation.
197  ****************************************************************************************
198  */
200 
201 
202 /**
203  ****************************************************************************************
204  * @brief Stops the PWM signal generation on the output.
205  *
206  * @param[in] id: which PWM module want to stop output.
207  *
208  * @return Result of operation.
209  ****************************************************************************************
210  */
212 
213 /**
214  ****************************************************************************************
215  * @brief Update the PWM frequency on the output.
216  *
217  * @param[in] id: which PWM module want to config.
218  * @param[in] freq: This parameter ranges between min = 0 and max = SystemFreq / 2.
219  *
220  * @return Result of operation.
221  ****************************************************************************************
222  */
223 uint16_t app_pwm_update_freq(app_pwm_id_t id, uint32_t freq);
224 
225 /**
226  ****************************************************************************************
227  * @brief Initialize the PWM channels according to the specified parameters.
228  *
229  * @param[in] id: which PWM module want to config.
230  * @param[in] channel: PWM Channels to be configured.
231  * @param[in] p_config: PWM Channels configuration structure.
232  *
233  * @return Result of operation.
234  ****************************************************************************************
235  */
237 
238 /** @} */
239 
240 #endif
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 
246 #endif
247 
248 /** @} */
249 /** @} */
250 /** @} */
APP_PWM_ACTIVE_CHANNEL_A
@ APP_PWM_ACTIVE_CHANNEL_A
The active channel is A
Definition: app_pwm.h:136
app_pwm_channel_init_t
PWM Channel init Structure definition.
Definition: app_pwm.h:119
app_pwm_params_t::init
pwm_init_t init
PWM communication parameters.
Definition: app_pwm.h:155
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:109
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:110
app_pwm_active_channel_t
app_pwm_active_channel_t
PWM active channel Enumerations definition.
Definition: app_pwm.h:135
app_pwm_pin_t
PWM IO configuration Structures.
Definition: app_pwm.h:94
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:100
app_pwm_pin_t::pin
uint32_t pin
Specifies the IO pins to be configured.
Definition: app_pwm.h:97
APP_PWM_ACTIVE_CHANNEL_ALL
@ APP_PWM_ACTIVE_CHANNEL_ALL
The active channels are ALL.
Definition: app_pwm.h:139
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:187
app_io_type_t
app_io_type_t
GPIO type Enumerations definition.
Definition: app_io.h:141
APP_PWM_ACTIVE_CHANNEL_C
@ APP_PWM_ACTIVE_CHANNEL_C
The active channel is C
Definition: app_pwm.h:138
app_pwm_params_t::id
app_pwm_id_t id
specified PWM module ID.
Definition: app_pwm.h:152
APP_PWM_ID_0
@ APP_PWM_ID_0
PWM module 0.
Definition: app_pwm.h:81
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:99
app_pwm_id_t
app_pwm_id_t
PWM module Enumerations definition.
Definition: app_pwm.h:80
APP_PWM_ID_1
@ APP_PWM_ID_1
PWM module 1.
Definition: app_pwm.h:82
app_pwm_stop
uint16_t app_pwm_stop(app_pwm_id_t id)
Stops the PWM signal generation on the output.
APP_PWM_ACTIVE_CHANNEL_B
@ APP_PWM_ACTIVE_CHANNEL_B
The active channel is B
Definition: app_pwm.h:137
app_pwm_channel_init_t::duty
uint8_t duty
Specifies the duty in PWM output mode.
Definition: app_pwm.h:120
app_pwm_channel_init_t::drive_polarity
uint8_t drive_polarity
Specifies the drive polarity in PWM output mode.
Definition: app_pwm.h:123
app_pwm_params_t
PWM parameters structure definition.
Definition: app_pwm.h:151
gr55xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
app_pwm_pin_cfg_t
PWM configuration Structures.
Definition: app_pwm.h:108
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.
app_pwm_pin_t::type
app_io_type_t type
Specifies the type of PWM IO.
Definition: app_pwm.h:95
app_io_mux_t
app_io_mux_t
GPIO mux Enumerations definition.
Definition: app_io.h:198
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:153
APP_PWM_ID_MAX
@ APP_PWM_ID_MAX
Only for check parameter, not used as input parameters.
Definition: app_pwm.h:83
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:111
app_pwm_params_t::active_channel
app_pwm_active_channel_t active_channel
PWM operate mode.
Definition: app_pwm.h:154
app_drv_error.h
Header file of app driver error code.
app_pwm_pin_t::mux
app_io_mux_t mux
Specifies the Peripheral to be connected to the selected pins.
Definition: app_pwm.h:96
APP_PWM_ACTIVE_CHANNEL_CLEARED
@ APP_PWM_ACTIVE_CHANNEL_CLEARED
All active channels are cleared.
Definition: app_pwm.h:140