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