c3xbuck  2.0.0.0
c3xbuck.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 C3XBUCK_H
36 #define C3XBUCK_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 #include "drv_i2c_master.h"
55 
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define C3XBUCK_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70  cfg.en1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71  cfg.en2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
72  cfg.en3 = MIKROBUS( mikrobus, MIKROBUS_INT );
73 
79 #define C3XBUCK_RETVAL uint8_t
80 
81 #define C3XBUCK_OK 0x00
82 #define C3XBUCK_INIT_ERROR 0xFF
83 
89 #define C3XBUCK_SELECT_BUCK_1 0x00
90 #define C3XBUCK_SELECT_BUCK_2 0x01
91 #define C3XBUCK_SELECT_BUCK_3 0x02
92 
98 #define C3XBUCK_BUCK_DEFAULT_OUTPUT_VOLTAGE 0x80
99 #define C3XBUCK_REG_VOUT1_SEL 0x00
100 #define C3XBUCK_REG_VOUT2_SEL 0x01
101 #define C3XBUCK_REG_VOUT3_SEL 0x02
102 #define C3XBUCK_REG_VOUT1_COM 0x03
103 #define C3XBUCK_REG_VOUT2_COM 0x04
104 #define C3XBUCK_REG_VOUT3_COM 0x05
105 #define C3XBUCK_REG_SYS_STATUS 0x06
106 
112 #define C3XBUCK_CFG_RATE_10mV_0cycles 0x00
113 #define C3XBUCK_CFG_RATE_10mV_2cycles 0x10
114 #define C3XBUCK_CFG_RATE_10mV_4cycles 0x20
115 #define C3XBUCK_CFG_RATE_10mV_8cycles 0x30
116 #define C3XBUCK_CFG_RATE_10mV_16cycles 0x40
117 #define C3XBUCK_CFG_RATE_10mV_32cycles 0x50
118 #define C3XBUCK_CFG_RATE_10mV_64cycles 0x60
119 #define C3XBUCK_CFG_RATE_10mV_128cycles 0x70
120 #define C3XBUCK_CFG_MODE_PSM_OPERATION 0x00
121 #define C3XBUCK_CFG_MODE_PWM_OPERATION 0x02
122 #define C3XBUCK_CFG_SW_ENABLE_BUCK 0x00
123 #define C3XBUCK_CFG_SW_DISABLE_BUCK 0x01
124 
131 #define C3XBUCK_OUTPUT_VOLTAGE_680mV 0x00
132 #define C3XBUCK_OUTPUT_VOLTAGE_690mV 0x01
133 #define C3XBUCK_OUTPUT_VOLTAGE_700mV 0x02
134 #define C3XBUCK_OUTPUT_VOLTAGE_710mV 0x03
135 #define C3XBUCK_OUTPUT_VOLTAGE_720mV 0x04
136 #define C3XBUCK_OUTPUT_VOLTAGE_730mV 0x05
137 #define C3XBUCK_OUTPUT_VOLTAGE_740mV 0x06
138 #define C3XBUCK_OUTPUT_VOLTAGE_750mV 0x07
139 #define C3XBUCK_OUTPUT_VOLTAGE_760mV 0x08
140 #define C3XBUCK_OUTPUT_VOLTAGE_770mV 0x09
141 #define C3XBUCK_OUTPUT_VOLTAGE_780mV 0x0A
142 #define C3XBUCK_OUTPUT_VOLTAGE_790mV 0x0B
143 #define C3XBUCK_OUTPUT_VOLTAGE_800mV 0x0C
144 #define C3XBUCK_OUTPUT_VOLTAGE_810mV 0x0D
145 #define C3XBUCK_OUTPUT_VOLTAGE_820mV 0x0E
146 #define C3XBUCK_OUTPUT_VOLTAGE_830mV 0x0F
147 #define C3XBUCK_OUTPUT_VOLTAGE_840mV 0x10
148 #define C3XBUCK_OUTPUT_VOLTAGE_850mV 0x11
149 #define C3XBUCK_OUTPUT_VOLTAGE_860mV 0x12
150 #define C3XBUCK_OUTPUT_VOLTAGE_870mV 0x13
151 #define C3XBUCK_OUTPUT_VOLTAGE_880mV 0x14
152 #define C3XBUCK_OUTPUT_VOLTAGE_890mV 0x15
153 #define C3XBUCK_OUTPUT_VOLTAGE_900mV 0x16
154 #define C3XBUCK_OUTPUT_VOLTAGE_910mV 0x17
155 #define C3XBUCK_OUTPUT_VOLTAGE_920mV 0x18
156 #define C3XBUCK_OUTPUT_VOLTAGE_930mV 0x19
157 #define C3XBUCK_OUTPUT_VOLTAGE_940mV 0x1A
158 #define C3XBUCK_OUTPUT_VOLTAGE_950mV 0x1B
159 #define C3XBUCK_OUTPUT_VOLTAGE_960mV 0x1C
160 #define C3XBUCK_OUTPUT_VOLTAGE_970mV 0x1D
161 #define C3XBUCK_OUTPUT_VOLTAGE_980mV 0x1E
162 #define C3XBUCK_OUTPUT_VOLTAGE_990mV 0x1F
163 #define C3XBUCK_OUTPUT_VOLTAGE_1000mV 0x20
164 #define C3XBUCK_OUTPUT_VOLTAGE_1010mV 0x21
165 #define C3XBUCK_OUTPUT_VOLTAGE_1020mV 0x22
166 #define C3XBUCK_OUTPUT_VOLTAGE_1030mV 0x23
167 #define C3XBUCK_OUTPUT_VOLTAGE_1040mV 0x24
168 #define C3XBUCK_OUTPUT_VOLTAGE_1050mV 0x25
169 #define C3XBUCK_OUTPUT_VOLTAGE_1060mV 0x26
170 #define C3XBUCK_OUTPUT_VOLTAGE_1070mV 0x27
171 #define C3XBUCK_OUTPUT_VOLTAGE_1080mV 0x28
172 #define C3XBUCK_OUTPUT_VOLTAGE_1090mV 0x29
173 #define C3XBUCK_OUTPUT_VOLTAGE_1100mV 0x2A
174 #define C3XBUCK_OUTPUT_VOLTAGE_1110mV 0x2B
175 #define C3XBUCK_OUTPUT_VOLTAGE_1120mV 0x2C
176 #define C3XBUCK_OUTPUT_VOLTAGE_1130mV 0x2D
177 #define C3XBUCK_OUTPUT_VOLTAGE_1140mV 0x2E
178 #define C3XBUCK_OUTPUT_VOLTAGE_1150mV 0x2F
179 #define C3XBUCK_OUTPUT_VOLTAGE_1160mV 0x30
180 #define C3XBUCK_OUTPUT_VOLTAGE_1170mV 0x31
181 #define C3XBUCK_OUTPUT_VOLTAGE_1180mV 0x32
182 #define C3XBUCK_OUTPUT_VOLTAGE_1190mV 0x33
183 #define C3XBUCK_OUTPUT_VOLTAGE_1200mV 0x34
184 #define C3XBUCK_OUTPUT_VOLTAGE_1210mV 0x35
185 #define C3XBUCK_OUTPUT_VOLTAGE_1220mV 0x36
186 #define C3XBUCK_OUTPUT_VOLTAGE_1230mV 0x37
187 #define C3XBUCK_OUTPUT_VOLTAGE_1240mV 0x38
188 #define C3XBUCK_OUTPUT_VOLTAGE_1250mV 0x39
189 #define C3XBUCK_OUTPUT_VOLTAGE_1260mV 0x3A
190 #define C3XBUCK_OUTPUT_VOLTAGE_1270mV 0x3B
191 #define C3XBUCK_OUTPUT_VOLTAGE_1280mV 0x3C
192 #define C3XBUCK_OUTPUT_VOLTAGE_1290mV 0x3D
193 #define C3XBUCK_OUTPUT_VOLTAGE_1300mV 0x3E
194 #define C3XBUCK_OUTPUT_VOLTAGE_1310mV 0x3F
195 #define C3XBUCK_OUTPUT_VOLTAGE_1320mV 0x40
196 #define C3XBUCK_OUTPUT_VOLTAGE_1330mV 0x41
197 #define C3XBUCK_OUTPUT_VOLTAGE_1340mV 0x42
198 #define C3XBUCK_OUTPUT_VOLTAGE_1350mV 0x43
199 #define C3XBUCK_OUTPUT_VOLTAGE_1360mV 0x44
200 #define C3XBUCK_OUTPUT_VOLTAGE_1370mV 0x45
201 #define C3XBUCK_OUTPUT_VOLTAGE_1380mV 0x46
202 #define C3XBUCK_OUTPUT_VOLTAGE_1390mV 0x47
203 #define C3XBUCK_OUTPUT_VOLTAGE_1400mV 0x48
204 #define C3XBUCK_OUTPUT_VOLTAGE_1410mV 0x49
205 #define C3XBUCK_OUTPUT_VOLTAGE_1420mV 0x4A
206 #define C3XBUCK_OUTPUT_VOLTAGE_1430mV 0x4B
207 #define C3XBUCK_OUTPUT_VOLTAGE_1440mV 0x4C
208 #define C3XBUCK_OUTPUT_VOLTAGE_1450mV 0x4D
209 #define C3XBUCK_OUTPUT_VOLTAGE_1460mV 0x4E
210 #define C3XBUCK_OUTPUT_VOLTAGE_1470mV 0x4F
211 #define C3XBUCK_OUTPUT_VOLTAGE_1480mV 0x50
212 #define C3XBUCK_OUTPUT_VOLTAGE_1490mV 0x51
213 #define C3XBUCK_OUTPUT_VOLTAGE_1500mV 0x52
214 #define C3XBUCK_OUTPUT_VOLTAGE_1510mV 0x53
215 #define C3XBUCK_OUTPUT_VOLTAGE_1520mV 0x54
216 #define C3XBUCK_OUTPUT_VOLTAGE_1530mV 0x55
217 #define C3XBUCK_OUTPUT_VOLTAGE_1540mV 0x56
218 #define C3XBUCK_OUTPUT_VOLTAGE_1550mV 0x57
219 #define C3XBUCK_OUTPUT_VOLTAGE_1560mV 0x58
220 #define C3XBUCK_OUTPUT_VOLTAGE_1570mV 0x59
221 #define C3XBUCK_OUTPUT_VOLTAGE_1580mV 0x5A
222 #define C3XBUCK_OUTPUT_VOLTAGE_1590mV 0x5B
223 #define C3XBUCK_OUTPUT_VOLTAGE_1600mV 0x5C
224 #define C3XBUCK_OUTPUT_VOLTAGE_1610mV 0x5D
225 #define C3XBUCK_OUTPUT_VOLTAGE_1620mV 0x5E
226 #define C3XBUCK_OUTPUT_VOLTAGE_1630mV 0x5F
227 #define C3XBUCK_OUTPUT_VOLTAGE_1640mV 0x60
228 #define C3XBUCK_OUTPUT_VOLTAGE_1650mV 0x61
229 #define C3XBUCK_OUTPUT_VOLTAGE_1660mV 0x62
230 #define C3XBUCK_OUTPUT_VOLTAGE_1670mV 0x63
231 #define C3XBUCK_OUTPUT_VOLTAGE_1680mV 0x64
232 #define C3XBUCK_OUTPUT_VOLTAGE_1690mV 0x65
233 #define C3XBUCK_OUTPUT_VOLTAGE_1700mV 0x66
234 #define C3XBUCK_OUTPUT_VOLTAGE_1710mV 0x67
235 #define C3XBUCK_OUTPUT_VOLTAGE_1720mV 0x68
236 #define C3XBUCK_OUTPUT_VOLTAGE_1730mV 0x69
237 #define C3XBUCK_OUTPUT_VOLTAGE_1740mV 0x6A
238 #define C3XBUCK_OUTPUT_VOLTAGE_1750mV 0x6B
239 #define C3XBUCK_OUTPUT_VOLTAGE_1760mV 0x6C
240 #define C3XBUCK_OUTPUT_VOLTAGE_1770mV 0x6D
241 #define C3XBUCK_OUTPUT_VOLTAGE_1780mV 0x6E
242 #define C3XBUCK_OUTPUT_VOLTAGE_1790mV 0x6F
243 #define C3XBUCK_OUTPUT_VOLTAGE_1800mV 0x70
244 #define C3XBUCK_OUTPUT_VOLTAGE_1810mV 0x71
245 #define C3XBUCK_OUTPUT_VOLTAGE_1820mV 0x72
246 #define C3XBUCK_OUTPUT_VOLTAGE_1830mV 0x73
247 #define C3XBUCK_OUTPUT_VOLTAGE_1840mV 0x74
248 #define C3XBUCK_OUTPUT_VOLTAGE_1850mV 0x75
249 #define C3XBUCK_OUTPUT_VOLTAGE_1860mV 0x76
250 #define C3XBUCK_OUTPUT_VOLTAGE_1870mV 0x77
251 #define C3XBUCK_OUTPUT_VOLTAGE_1880mV 0x78
252 #define C3XBUCK_OUTPUT_VOLTAGE_1890mV 0x79
253 #define C3XBUCK_OUTPUT_VOLTAGE_1900mV 0x7A
254 #define C3XBUCK_OUTPUT_VOLTAGE_1910mV 0x7B
255 #define C3XBUCK_OUTPUT_VOLTAGE_1920mV 0x7C
256 #define C3XBUCK_OUTPUT_VOLTAGE_1930mV 0x7D
257 #define C3XBUCK_OUTPUT_VOLTAGE_1940mV 0x7E
258 #define C3XBUCK_OUTPUT_VOLTAGE_1950mV 0x7F
259  // End group macro
261 // --------------------------------------------------------------- PUBLIC TYPES
270 typedef struct
271 {
272  // Output pins
273 
274  digital_out_t en1;
275  digital_out_t en2;
276  digital_out_t en3;
277 
278  // Modules
279 
280  i2c_master_t i2c;
281 
282  // ctx variable
283 
284  uint8_t slave_address;
285 
286 } c3xbuck_t;
287 
291 typedef struct
292 {
293  // Communication gpio pins
294 
295  pin_name_t scl;
296  pin_name_t sda;
297 
298  // Additional gpio pins
299 
300  pin_name_t en1;
301  pin_name_t en2;
302  pin_name_t en3;
303 
304  // static variable
305 
306  uint32_t i2c_speed;
307  uint8_t i2c_address;
308 
309 } c3xbuck_cfg_t;
310  // End types group
312 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
313 
319 #ifdef __cplusplus
320 extern "C"{
321 #endif
322 
332 
342 
351 
363 void c3xbuck_write_byte ( c3xbuck_t *ctx, uint8_t reg, uint8_t data_value );
364 
365 
378 uint8_t c3xbuck_read_byte( c3xbuck_t *ctx, uint8_t reg);
379 
380 
388 void c3xbuck_enable_buck ( c3xbuck_t *ctx, uint8_t buck );
389 
397 void c3xbuck_disable_buck ( c3xbuck_t *ctx, uint8_t buck );
398 
408 void c3xbuck_set_voltage ( c3xbuck_t *ctx, uint8_t buck, uint8_t voltage );
409 
419 
428 void c3xbuck_configuration_buck( c3xbuck_t *ctx, uint8_t buck, uint8_t config);
429 
430 #ifdef __cplusplus
431 }
432 #endif
433 #endif // _C3XBUCK_H_
434  // End public_function group
437 
438 // ------------------------------------------------------------------------- END
c3xbuck_t::en2
digital_out_t en2
Definition: c3xbuck.h:275
c3xbuck_t::slave_address
uint8_t slave_address
Definition: c3xbuck.h:284
c3xbuck_default_cfg
void c3xbuck_default_cfg(c3xbuck_t *ctx)
Click Default Configuration function.
c3xbuck_cfg_t::scl
pin_name_t scl
Definition: c3xbuck.h:295
c3xbuck_cfg_t
Click configuration structure definition.
Definition: c3xbuck.h:292
c3xbuck_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c3xbuck.h:306
c3xbuck_t::en3
digital_out_t en3
Definition: c3xbuck.h:276
c3xbuck_t::i2c
i2c_master_t i2c
Definition: c3xbuck.h:280
c3xbuck_cfg_t::en3
pin_name_t en3
Definition: c3xbuck.h:302
c3xbuck_enable_buck
void c3xbuck_enable_buck(c3xbuck_t *ctx, uint8_t buck)
Enable Buck function.
c3xbuck_set_voltage
void c3xbuck_set_voltage(c3xbuck_t *ctx, uint8_t buck, uint8_t voltage)
Set voltage function.
c3xbuck_cfg_t::sda
pin_name_t sda
Definition: c3xbuck.h:296
c3xbuck_disable_buck
void c3xbuck_disable_buck(c3xbuck_t *ctx, uint8_t buck)
Disable Buck function.
c3xbuck_write_byte
void c3xbuck_write_byte(c3xbuck_t *ctx, uint8_t reg, uint8_t data_value)
Write byte function.
c3xbuck_t::en1
digital_out_t en1
Definition: c3xbuck.h:274
c3xbuck_read_byte
uint8_t c3xbuck_read_byte(c3xbuck_t *ctx, uint8_t reg)
Generic read function.
c3xbuck_cfg_t::en2
pin_name_t en2
Definition: c3xbuck.h:301
c3xbuck_cfg_t::en1
pin_name_t en1
Definition: c3xbuck.h:300
c3xbuck_t
Click ctx object definition.
Definition: c3xbuck.h:271
c3xbuck_get_status
uint8_t c3xbuck_get_status(c3xbuck_t *ctx)
Get status function.
c3xbuck_configuration_buck
void c3xbuck_configuration_buck(c3xbuck_t *ctx, uint8_t buck, uint8_t config)
Configuration function.
C3XBUCK_RETVAL
#define C3XBUCK_RETVAL
Definition: c3xbuck.h:79
c3xbuck_cfg_t::i2c_address
uint8_t i2c_address
Definition: c3xbuck.h:307
c3xbuck_cfg_setup
void c3xbuck_cfg_setup(c3xbuck_cfg_t *cfg)
Config Object Initialization function.
c3xbuck_init
C3XBUCK_RETVAL c3xbuck_init(c3xbuck_t *ctx, c3xbuck_cfg_t *cfg)
Initialization function.