buck2  2.0.0.0
buck2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef BUCK2_H
36 #define BUCK2_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define BUCK2_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.voset0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
63  cfg.voset1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
64  cfg.en= MIKROBUS( mikrobus, MIKROBUS_CS ); \
65  cfg.fq= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
66  cfg.pg= MIKROBUS( mikrobus, MIKROBUS_INT );
67 
73 #define BUCK2_RETVAL uint8_t
74 
75 #define BUCK2_OK 0x00
76 #define BUCK2_INIT_ERROR 0xFF
77 
83 #define BUCK2_MODE_ACTIVE 0x01
84 #define BUCK2_MODE_SLEEP 0x00
85 
91 #define BUCK2_VOSET_LOW 0x00
92 #define BUCK2_VOSET_HIGH 0x01
93 
99 #define BUCK2_FREQ_790KHz 0x01
100 #define BUCK2_FREQ_565KHz 0x00
101 
107 #define BUCK2_SET_VOLTAGE_3300mV 0
108 #define BUCK2_SET_VOLTAGE_2500mV 1
109 #define BUCK2_SET_VOLTAGE_1800mV 2
110 #define BUCK2_SET_VOLTAGE_1500mV 3
111 
117 #define BUCK2_VOSET_CH_0 0
118 #define BUCK2_VOSET_CH_1 1
119  // End group macro
122 // --------------------------------------------------------------- PUBLIC TYPES
131 typedef struct
132 {
133  // Output pins
134 
135  digital_out_t voset0;
136  digital_out_t voset1;
137  digital_out_t en;
138  digital_out_t fq;
139 
140  // Input pins
141 
142  digital_in_t pg;
143 
144 } buck2_t;
145 
149 typedef struct
150 {
151  // Additional gpio pins
152 
153  pin_name_t voset0;
154  pin_name_t voset1;
155  pin_name_t en;
156  pin_name_t fq;
157  pin_name_t pg;
158 
159 } buck2_cfg_t;
160  // End types group
162 
163 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
164 
170 #ifdef __cplusplus
171 extern "C"{
172 #endif
173 
183 
192 
208 
216 void buck2_set_voset ( buck2_t *ctx, uint8_t channel, uint8_t state );
217 
230 void busk2_set_frequency ( buck2_t *ctx, uint8_t freq );
231 
244 void buck2_set_power_mode ( buck2_t *ctx, uint8_t mode );
245 
252 
263 uint8_t buck2_get_power_good ( buck2_t *ctx );
264 
279 void buck2_set_output_voltage ( buck2_t *ctx , uint8_t voltage );
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 #endif // _BUCK2_H_
285  // End public_function group
288 
289 // ------------------------------------------------------------------------- END
buck2_t::voset0
digital_out_t voset0
Definition: buck2.h:135
buck2_t::pg
digital_in_t pg
Definition: buck2.h:142
buck2_t::fq
digital_out_t fq
Definition: buck2.h:138
BUCK2_RETVAL
#define BUCK2_RETVAL
Definition: buck2.h:73
buck2_cfg_t::voset0
pin_name_t voset0
Definition: buck2.h:153
back2_device_reset
void back2_device_reset(buck2_t *ctx)
Function for reset chip.
buck2_cfg_t::voset1
pin_name_t voset1
Definition: buck2.h:154
buck2_default_cfg
void buck2_default_cfg(buck2_t *ctx)
Click Default Configuration function.
buck2_init
BUCK2_RETVAL buck2_init(buck2_t *ctx, buck2_cfg_t *cfg)
Initialization function.
buck2_cfg_t::en
pin_name_t en
Definition: buck2.h:155
buck2_cfg_t::pg
pin_name_t pg
Definition: buck2.h:157
buck2_set_output_voltage
void buck2_set_output_voltage(buck2_t *ctx, uint8_t voltage)
Function settings output voltage.
busk2_set_frequency
void busk2_set_frequency(buck2_t *ctx, uint8_t freq)
Function settings Frequency.
buck2_t
Click ctx object definition.
Definition: buck2.h:132
buck2_cfg_setup
void buck2_cfg_setup(buck2_cfg_t *cfg)
Config Object Initialization function.
buck2_get_power_good
uint8_t buck2_get_power_good(buck2_t *ctx)
Function reads state PG pin.
buck2_cfg_t::fq
pin_name_t fq
Definition: buck2.h:156
buck2_t::voset1
digital_out_t voset1
Definition: buck2.h:136
buck2_set_power_mode
void buck2_set_power_mode(buck2_t *ctx, uint8_t mode)
Function settings chip mode.
buck2_t::en
digital_out_t en
Definition: buck2.h:137
buck2_cfg_t
Click configuration structure definition.
Definition: buck2.h:150
buck2_set_voset
void buck2_set_voset(buck2_t *ctx, uint8_t channel, uint8_t state)
Function settings VOSET pin state.