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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define BUCK2_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.voset0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.voset1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
68  cfg.en= MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.fq= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
70  cfg.pg= MIKROBUS( mikrobus, MIKROBUS_INT );
71 
77 #define BUCK2_RETVAL uint8_t
78 
79 #define BUCK2_OK 0x00
80 #define BUCK2_INIT_ERROR 0xFF
81 
87 #define BUCK2_MODE_ACTIVE 0x01
88 #define BUCK2_MODE_SLEEP 0x00
89 
95 #define BUCK2_VOSET_LOW 0x00
96 #define BUCK2_VOSET_HIGH 0x01
97 
103 #define BUCK2_FREQ_790KHz 0x01
104 #define BUCK2_FREQ_565KHz 0x00
105 
111 #define BUCK2_SET_VOLTAGE_3300mV 0
112 #define BUCK2_SET_VOLTAGE_2500mV 1
113 #define BUCK2_SET_VOLTAGE_1800mV 2
114 #define BUCK2_SET_VOLTAGE_1500mV 3
115 
121 #define BUCK2_VOSET_CH_0 0
122 #define BUCK2_VOSET_CH_1 1
123  // End group macro
126 // --------------------------------------------------------------- PUBLIC TYPES
135 typedef struct
136 {
137  // Output pins
138 
139  digital_out_t voset0;
140  digital_out_t voset1;
141  digital_out_t en;
142  digital_out_t fq;
143 
144  // Input pins
145 
146  digital_in_t pg;
147 
148 } buck2_t;
149 
153 typedef struct
154 {
155  // Additional gpio pins
156 
157  pin_name_t voset0;
158  pin_name_t voset1;
159  pin_name_t en;
160  pin_name_t fq;
161  pin_name_t pg;
162 
163 } buck2_cfg_t;
164  // End types group
166 
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
174 #ifdef __cplusplus
175 extern "C"{
176 #endif
177 
187 
196 
212 
220 void buck2_set_voset ( buck2_t *ctx, uint8_t channel, uint8_t state );
221 
234 void busk2_set_frequency ( buck2_t *ctx, uint8_t freq );
235 
248 void buck2_set_power_mode ( buck2_t *ctx, uint8_t mode );
249 
256 
267 uint8_t buck2_get_power_good ( buck2_t *ctx );
268 
283 void buck2_set_output_voltage ( buck2_t *ctx , uint8_t voltage );
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 #endif // _BUCK2_H_
289  // End public_function group
292 
293 // ------------------------------------------------------------------------- END
buck2_t::voset0
digital_out_t voset0
Definition: buck2.h:139
buck2_t::pg
digital_in_t pg
Definition: buck2.h:146
buck2_t::fq
digital_out_t fq
Definition: buck2.h:142
BUCK2_RETVAL
#define BUCK2_RETVAL
Definition: buck2.h:77
buck2_cfg_t::voset0
pin_name_t voset0
Definition: buck2.h:157
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:158
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:159
buck2_cfg_t::pg
pin_name_t pg
Definition: buck2.h:161
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:136
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:160
buck2_t::voset1
digital_out_t voset1
Definition: buck2.h:140
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:141
buck2_cfg_t
Click configuration structure definition.
Definition: buck2.h:154
buck2_set_voset
void buck2_set_voset(buck2_t *ctx, uint8_t channel, uint8_t state)
Function settings VOSET pin state.