buck  2.0.0.0
buck.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 BUCK_H
36 #define BUCK_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 BUCK_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.a0= MIKROBUS( mikrobus, MIKROBUS_RST ); \
63  cfg.en= MIKROBUS( mikrobus, MIKROBUS_CS ); \
64  cfg.a1= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
65  cfg.pg= MIKROBUS( mikrobus, MIKROBUS_INT );
66 
72 #define BUCK_RETVAL uint8_t
73 
74 #define BUCK_OK 0x00
75 #define BUCK_INIT_ERROR 0xFF
76 
82 #define BUCK_DEVICE_DISABLE 0
83 #define BUCK_DEVICE_ENABLE 1
84 
90 #define BUCK_FREQ_400KHz 0x00
91 #define BUCK_FREQ_1200KHz 0x01
92 #define BUCK_FREQ_800KHz 0x02
93 #define BUCK_FREQ_1600KHz 0x03
94 
100 #define BUCK_SET_MULTIPLEXER_A0 0
101 #define BUCK_SET_MULTIPLEXER_A1 1
102  // End group macro
105 // --------------------------------------------------------------- PUBLIC TYPES
114 typedef struct
115 {
116  // Output pins
117 
118  digital_out_t a0;
119  digital_out_t en;
120  digital_out_t a1;
121 
122  // Input pins
123 
124  digital_in_t pg;
125 
126 } buck_t;
127 
131 typedef struct
132 {
133  // Additional gpio pins
134 
135  pin_name_t a0;
136  pin_name_t en;
137  pin_name_t a1;
138  pin_name_t pg;
139 
140 } buck_cfg_t;
141  // End types group
143 
144 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
145 
151 #ifdef __cplusplus
152 extern "C"{
153 #endif
154 
164 
173 
187 void buck_default_cfg ( buck_t *ctx );
188 
197 void buck_device_reset ( buck_t *ctx );
198 
205 void buck_set_mode ( buck_t *ctx, uint8_t mode );
206 
221 uint8_t buck_get_power_good ( buck_t *ctx );
222 
229 void buck_set_multiplexer_state ( buck_t *ctx, uint8_t mux, uint8_t state );
230 
246 void buck_switch_frequency ( buck_t *ctx, uint8_t frequency );
247 
248 
249 #ifdef __cplusplus
250 }
251 #endif
252 #endif // _BUCK_H_
253  // End public_function group
256 
257 // ------------------------------------------------------------------------- END
buck_cfg_t::pg
pin_name_t pg
Definition: buck.h:138
buck_set_mode
void buck_set_mode(buck_t *ctx, uint8_t mode)
Select buck mode (Disable / Enable)
buck_cfg_t::en
pin_name_t en
Definition: buck.h:136
buck_init
BUCK_RETVAL buck_init(buck_t *ctx, buck_cfg_t *cfg)
Initialization function.
buck_cfg_t::a0
pin_name_t a0
Definition: buck.h:135
buck_set_multiplexer_state
void buck_set_multiplexer_state(buck_t *ctx, uint8_t mux, uint8_t state)
Set multiplexer (A0 or A1) state.
buck_get_power_good
uint8_t buck_get_power_good(buck_t *ctx)
Get state internal comparator function.
buck_t
Click ctx object definition.
Definition: buck.h:115
buck_cfg_t::a1
pin_name_t a1
Definition: buck.h:137
buck_cfg_t
Click configuration structure definition.
Definition: buck.h:132
buck_t::en
digital_out_t en
Definition: buck.h:119
buck_t::pg
digital_in_t pg
Definition: buck.h:124
buck_device_reset
void buck_device_reset(buck_t *ctx)
Device reset chip function.
buck_switch_frequency
void buck_switch_frequency(buck_t *ctx, uint8_t frequency)
Setting the switching frequency function.
BUCK_RETVAL
#define BUCK_RETVAL
Definition: buck.h:72
buck_t::a1
digital_out_t a1
Definition: buck.h:120
buck_default_cfg
void buck_default_cfg(buck_t *ctx)
Click Default Configuration function.
buck_cfg_setup
void buck_cfg_setup(buck_cfg_t *cfg)
Config Object Initialization function.
buck_t::a0
digital_out_t a0
Definition: buck.h:118