mic24045  2.0.0.0
mic24045.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 MIC24045_H
36 #define MIC24045_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 // -------------------------------------------------------------- PUBLIC MACROS
66 #define MIC24045_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
71 
77 #define MIC24045_RETVAL uint8_t
78 
79 #define MIC24045_OK 0x00
80 #define MIC24045_INIT_ERROR 0xFF
81 
87 #define MIC24045_I2C_ADDRESS 0x50
88 
95 #define MIC24045_REG_STATUS 0x00
96 #define MIC24045_REG_SETTINGS1 0x01
97 #define MIC24045_REG_SETTINGS2 0x02
98 #define MIC24045_REG_VOUT 0x03
99 #define MIC24045_REG_COMMAND 0x04
100 
106 #define MIC24045_BIT_PGS 0x01
107 #define MIC24045_BIT_ENS 0x08
108 #define MIC24045_BIT_THWRNF 0x20
109 #define MIC24045_BIT_THSDF 0x40
110 #define MIC24045_BIT_OCF 0x80
111 #define MIC24045_BIT_CIFF 0x01
112 
118 #define MIC24045_SETTING_CURRENT_NORMAL_LOAD_2_A 0x00
119 #define MIC24045_SETTING_CURRENT_NORMAL_LOAD_3_A 0x40
120 #define MIC24045_SETTING_CURRENT_NORMAL_LOAD_4_A 0x80
121 #define MIC24045_SETTING_CURRENT_NORMAL_LOAD_5_A 0xC0
122 
128 #define MIC24045_SETTING_FREQUENCY_310_kHz 0x00
129 #define MIC24045_SETTING_FREQUENCY_400_kHz 0x08
130 #define MIC24045_SETTING_FREQUENCY_500_kHz 0x10
131 #define MIC24045_SETTING_FREQUENCY_570_kHz 0x18
132 #define MIC24045_SETTING_FREQUENCY_660_kHz 0x20
133 #define MIC24045_SETTING_FREQUENCY_780_kHz 0x28
134 #define MIC24045_SETTING_FREQUENCY_970_kHz 0x30
135 #define MIC24045_SETTING_FREQUENCY_1200_kHz 0x38
136 
142 #define MIC24045_SETTING_START_UP_DELAY_0_ms 0x00
143 #define MIC24045_SETTING_START_UP_DELAY_0_5_ms 0x10
144 #define MIC24045_SETTING_START_UP_DELAY_1_ms 0x20
145 #define MIC24045_SETTING_START_UP_DELAY_2_ms 0x30
146 #define MIC24045_SETTING_START_UP_DELAY_4_ms 0x40
147 #define MIC24045_SETTING_START_UP_DELAY_6_ms 0x50
148 #define MIC24045_SETTING_START_UP_DELAY_8_ms 0x60
149 #define MIC24045_SETTING_START_UP_DELAY_10_ms 0x70
150 
156 #define MIC24045_SETTING_CHANGE_NOMINAL_0_PERC 0x00
157 #define MIC24045_SETTING_CHANGE_NOMINAL_NEG_5_PERC 0x04
158 #define MIC24045_SETTING_CHANGE_NOMINAL_POS_5_PERC 0x08
159 #define MIC24045_SETTING_CHANGE_NOMINAL_POS_5_0_PERC 0x0C
160 
166 #define MIC24045_SETTING_SOFT_START_SLOPE_0_16_Vms 0x00
167 #define MIC24045_SETTING_SOFT_START_SLOPE_0_38_Vms 0x01
168 #define MIC24045_SETTING_SOFT_START_SLOPE_0_76_Vms 0x02
169 #define MIC24045_SETTING_SOFT_START_SLOPE_1_50_Vms 0x03
170 
176 #define MIC24045_MAX_VOUT 5.250
177 #define MIC24045_MIN_VOUT 0.640
178 #define MIC24045_MAX_VOUT_DEC 0xFF
179 #define MIC24045_MIN_VOUT_DEC 0x00
180  // End group macro
183 // --------------------------------------------------------------- PUBLIC TYPES
192 typedef struct
193 {
194  // Output pins
195 
196  digital_out_t en;
197 
198  // Input pins
199 
200  digital_in_t pg;
201 
202  // Modules
203 
204  i2c_master_t i2c;
205 
206  // ctx variable
207 
208  uint8_t slave_address;
209 
210 } mic24045_t;
211 
215 typedef struct
216 {
217  // Communication gpio pins
218 
219  pin_name_t scl;
220  pin_name_t sda;
221 
222  // Additional gpio pins
223 
224  pin_name_t en;
225  pin_name_t pg;
226 
227  // static variable
228 
229  uint32_t i2c_speed;
230  uint8_t i2c_address;
231 
233  // End types group
235 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
236 
242 #ifdef __cplusplus
243 extern "C"{
244 #endif
245 
255 
265 
276 void mic24045_generic_write ( mic24045_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
277 
289 void mic24045_generic_read ( mic24045_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
290 
299 
308 
317 void mic24045_set_vout( mic24045_t *ctx, float v_out );
318 
331 void mic24045_set_vout_decimal ( mic24045_t *ctx, uint8_t dec );
332 
341 
350 
359 
360 #ifdef __cplusplus
361 }
362 #endif
363 #endif // _MIC24045_H_
364  // End public_function group
367 
368 // ------------------------------------------------------------------------- END
mic24045_disable
void mic24045_disable(mic24045_t *ctx)
Disable voltage output.
mic24045_t
Click ctx object definition.
Definition: mic24045.h:193
mic24045_set_vout_decimal
void mic24045_set_vout_decimal(mic24045_t *ctx, uint8_t dec)
Set voltage decimal.
mic24045_init
MIC24045_RETVAL mic24045_init(mic24045_t *ctx, mic24045_cfg_t *cfg)
Initialization function.
mic24045_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: mic24045.h:229
mic24045_cfg_t
Click configuration structure definition.
Definition: mic24045.h:216
mic24045_get_power_good_state
uint8_t mic24045_get_power_good_state(mic24045_t *ctx)
Get power good state.
mic24045_generic_read
void mic24045_generic_read(mic24045_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
mic24045_cfg_t::scl
pin_name_t scl
Definition: mic24045.h:219
mic24045_cfg_t::i2c_address
uint8_t i2c_address
Definition: mic24045.h:230
MIC24045_RETVAL
#define MIC24045_RETVAL
Definition: mic24045.h:77
mic24045_set_vout
void mic24045_set_vout(mic24045_t *ctx, float v_out)
Set voltage.
mic24045_enable
void mic24045_enable(mic24045_t *ctx)
Enable voltage output.
mic24045_cfg_t::en
pin_name_t en
Definition: mic24045.h:224
mic24045_cfg_t::sda
pin_name_t sda
Definition: mic24045.h:220
mic24045_cfg_setup
void mic24045_cfg_setup(mic24045_cfg_t *cfg)
Config Object Initialization function.
mic24045_get_status
uint8_t mic24045_get_status(mic24045_t *ctx)
Get status function.
mic24045_t::slave_address
uint8_t slave_address
Definition: mic24045.h:208
mic24045_t::pg
digital_in_t pg
Definition: mic24045.h:200
mic24045_cfg_t::pg
pin_name_t pg
Definition: mic24045.h:225
mic24045_t::en
digital_out_t en
Definition: mic24045.h:196
mic24045_get_vout
float mic24045_get_vout(mic24045_t *ctx)
Get voltage.
mic24045_t::i2c
i2c_master_t i2c
Definition: mic24045.h:204
mic24045_generic_write
void mic24045_generic_write(mic24045_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.