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 
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 // -------------------------------------------------------------- PUBLIC MACROS
62 #define MIC24045_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define MIC24045_RETVAL uint8_t
74 
75 #define MIC24045_OK 0x00
76 #define MIC24045_INIT_ERROR 0xFF
77 
83 #define MIC24045_I2C_ADDRESS 0x50
84 
91 #define MIC24045_REG_STATUS 0x00
92 #define MIC24045_REG_SETTINGS1 0x01
93 #define MIC24045_REG_SETTINGS2 0x02
94 #define MIC24045_REG_VOUT 0x03
95 #define MIC24045_REG_COMMAND 0x04
96 
102 #define MIC24045_BIT_PGS 0x01
103 #define MIC24045_BIT_ENS 0x08
104 #define MIC24045_BIT_THWRNF 0x20
105 #define MIC24045_BIT_THSDF 0x40
106 #define MIC24045_BIT_OCF 0x80
107 #define MIC24045_BIT_CIFF 0x01
108 
114 #define MIC24045_SETTING_CURRENT_NORMAL_LOAD_2_A 0x00
115 #define MIC24045_SETTING_CURRENT_NORMAL_LOAD_3_A 0x40
116 #define MIC24045_SETTING_CURRENT_NORMAL_LOAD_4_A 0x80
117 #define MIC24045_SETTING_CURRENT_NORMAL_LOAD_5_A 0xC0
118 
124 #define MIC24045_SETTING_FREQUENCY_310_kHz 0x00
125 #define MIC24045_SETTING_FREQUENCY_400_kHz 0x08
126 #define MIC24045_SETTING_FREQUENCY_500_kHz 0x10
127 #define MIC24045_SETTING_FREQUENCY_570_kHz 0x18
128 #define MIC24045_SETTING_FREQUENCY_660_kHz 0x20
129 #define MIC24045_SETTING_FREQUENCY_780_kHz 0x28
130 #define MIC24045_SETTING_FREQUENCY_970_kHz 0x30
131 #define MIC24045_SETTING_FREQUENCY_1200_kHz 0x38
132 
138 #define MIC24045_SETTING_START_UP_DELAY_0_ms 0x00
139 #define MIC24045_SETTING_START_UP_DELAY_0_5_ms 0x10
140 #define MIC24045_SETTING_START_UP_DELAY_1_ms 0x20
141 #define MIC24045_SETTING_START_UP_DELAY_2_ms 0x30
142 #define MIC24045_SETTING_START_UP_DELAY_4_ms 0x40
143 #define MIC24045_SETTING_START_UP_DELAY_6_ms 0x50
144 #define MIC24045_SETTING_START_UP_DELAY_8_ms 0x60
145 #define MIC24045_SETTING_START_UP_DELAY_10_ms 0x70
146 
152 #define MIC24045_SETTING_CHANGE_NOMINAL_0_PERC 0x00
153 #define MIC24045_SETTING_CHANGE_NOMINAL_NEG_5_PERC 0x04
154 #define MIC24045_SETTING_CHANGE_NOMINAL_POS_5_PERC 0x08
155 #define MIC24045_SETTING_CHANGE_NOMINAL_POS_5_0_PERC 0x0C
156 
162 #define MIC24045_SETTING_SOFT_START_SLOPE_0_16_Vms 0x00
163 #define MIC24045_SETTING_SOFT_START_SLOPE_0_38_Vms 0x01
164 #define MIC24045_SETTING_SOFT_START_SLOPE_0_76_Vms 0x02
165 #define MIC24045_SETTING_SOFT_START_SLOPE_1_50_Vms 0x03
166 
172 #define MIC24045_MAX_VOUT 5.250
173 #define MIC24045_MIN_VOUT 0.640
174 #define MIC24045_MAX_VOUT_DEC 0xFF
175 #define MIC24045_MIN_VOUT_DEC 0x00
176  // End group macro
179 // --------------------------------------------------------------- PUBLIC TYPES
188 typedef struct
189 {
190  // Output pins
191 
192  digital_out_t en;
193 
194  // Input pins
195 
196  digital_in_t pg;
197 
198  // Modules
199 
200  i2c_master_t i2c;
201 
202  // ctx variable
203 
204  uint8_t slave_address;
205 
206 } mic24045_t;
207 
211 typedef struct
212 {
213  // Communication gpio pins
214 
215  pin_name_t scl;
216  pin_name_t sda;
217 
218  // Additional gpio pins
219 
220  pin_name_t en;
221  pin_name_t pg;
222 
223  // static variable
224 
225  uint32_t i2c_speed;
226  uint8_t i2c_address;
227 
229  // End types group
231 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
232 
238 #ifdef __cplusplus
239 extern "C"{
240 #endif
241 
251 
261 
272 void mic24045_generic_write ( mic24045_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
273 
285 void mic24045_generic_read ( mic24045_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
286 
295 
304 
313 void mic24045_set_vout( mic24045_t *ctx, float v_out );
314 
327 void mic24045_set_vout_decimal ( mic24045_t *ctx, uint8_t dec );
328 
337 
346 
355 
356 #ifdef __cplusplus
357 }
358 #endif
359 #endif // _MIC24045_H_
360  // End public_function group
363 
364 // ------------------------------------------------------------------------- END
mic24045_disable
void mic24045_disable(mic24045_t *ctx)
Disable voltage output.
mic24045_t
Click ctx object definition.
Definition: mic24045.h:189
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:225
mic24045_cfg_t
Click configuration structure definition.
Definition: mic24045.h:212
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:215
mic24045_cfg_t::i2c_address
uint8_t i2c_address
Definition: mic24045.h:226
MIC24045_RETVAL
#define MIC24045_RETVAL
Definition: mic24045.h:73
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:220
mic24045_cfg_t::sda
pin_name_t sda
Definition: mic24045.h:216
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:204
mic24045_t::pg
digital_in_t pg
Definition: mic24045.h:196
mic24045_cfg_t::pg
pin_name_t pg
Definition: mic24045.h:221
mic24045_t::en
digital_out_t en
Definition: mic24045.h:192
mic24045_get_vout
float mic24045_get_vout(mic24045_t *ctx)
Get voltage.
mic24045_t::i2c
i2c_master_t i2c
Definition: mic24045.h:200
mic24045_generic_write
void mic24045_generic_write(mic24045_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.