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