ldo  2.1.0.0
ldo.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef LDO_H
29 #define LDO_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define LDO_REG_INPUT_PORT 0x00
60 #define LDO_REG_OUTPUT_PORT 0x01
61 #define LDO_REG_POLARITY_INV 0x02
62 #define LDO_REG_CONFIG 0x03
63  // ldo_reg
65 
80 #define LDO_PIN_NONE 0x00
81 #define LDO_PIN_1600_mV 0x01
82 #define LDO_PIN_800_mV 0x02
83 #define LDO_PIN_400_mV 0x04
84 #define LDO_PIN_200_mV 0x08
85 #define LDO_PIN_100_mV 0x10
86 #define LDO_PIN_50_mV 0x20
87 #define LDO_PIN_ALL 0x3F
88 
93 #define LDO_PIN_LOW 0
94 #define LDO_PIN_OPEN 1
95 
100 #define LDO_VOUT_MIN 800
101 #define LDO_VOUT_STEP 50
102 #define LDO_VOUT_MAX 3950
103 
108 #define LDO_DEVICE_ADDRESS_0 0x38
109 #define LDO_DEVICE_ADDRESS_1 0x39
110 #define LDO_DEVICE_ADDRESS_2 0x3A
111 #define LDO_DEVICE_ADDRESS_3 0x3B
112 #define LDO_DEVICE_ADDRESS_4 0x3C
113 #define LDO_DEVICE_ADDRESS_5 0x3D
114 #define LDO_DEVICE_ADDRESS_6 0x3E
115 #define LDO_DEVICE_ADDRESS_7 0x3F
116  // ldo_set
118 
133 #define LDO_MAP_MIKROBUS( cfg, mikrobus ) \
134  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
135  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
136  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
137  // ldo_map // ldo
140 
145 typedef struct
146 {
147  // Output pins
148  digital_out_t en;
150  // Modules
151  i2c_master_t i2c;
153  // I2C slave address
154  uint8_t slave_address;
156 } ldo_t;
157 
162 typedef struct
163 {
164  pin_name_t scl;
165  pin_name_t sda;
166  pin_name_t en;
168  uint32_t i2c_speed;
169  uint8_t i2c_address;
171 } ldo_cfg_t;
172 
177 typedef enum
178 {
179  LDO_OK = 0,
180  LDO_ERROR = -1
181 
183 
199 void ldo_cfg_setup ( ldo_cfg_t *cfg );
200 
214 err_t ldo_init ( ldo_t *ctx, ldo_cfg_t *cfg );
215 
228 err_t ldo_default_cfg ( ldo_t *ctx );
229 
242 err_t ldo_write_register ( ldo_t *ctx, uint8_t reg, uint8_t data_in );
243 
256 err_t ldo_read_register ( ldo_t *ctx, uint8_t reg, uint8_t *data_out );
257 
270 err_t ldo_set_pin_state ( ldo_t *ctx, uint8_t pin_mask, uint8_t state );
271 
283 err_t ldo_set_vout ( ldo_t *ctx, uint16_t vout );
284 
293 void ldo_enable_device ( ldo_t *ctx );
294 
303 void ldo_disable_device ( ldo_t *ctx );
304 
305 #ifdef __cplusplus
306 }
307 #endif
308 #endif // LDO_H
309  // ldo
311 
312 // ------------------------------------------------------------------------ END
ldo_cfg_t::i2c_address
uint8_t i2c_address
Definition: ldo.h:169
ldo_enable_device
void ldo_enable_device(ldo_t *ctx)
LDO enable device function.
ldo_t::i2c
i2c_master_t i2c
Definition: ldo.h:151
ldo_cfg_t::sda
pin_name_t sda
Definition: ldo.h:165
ldo_return_value_t
ldo_return_value_t
LDO Click return value data.
Definition: ldo.h:178
ldo_write_register
err_t ldo_write_register(ldo_t *ctx, uint8_t reg, uint8_t data_in)
LDO write register function.
ldo_disable_device
void ldo_disable_device(ldo_t *ctx)
LDO disable device function.
ldo_cfg_setup
void ldo_cfg_setup(ldo_cfg_t *cfg)
LDO configuration object setup function.
ldo_cfg_t::en
pin_name_t en
Definition: ldo.h:166
ldo_cfg_t::scl
pin_name_t scl
Definition: ldo.h:164
ldo_t::en
digital_out_t en
Definition: ldo.h:148
ldo_init
err_t ldo_init(ldo_t *ctx, ldo_cfg_t *cfg)
LDO initialization function.
ldo_set_vout
err_t ldo_set_vout(ldo_t *ctx, uint16_t vout)
LDO set vout function.
ldo_t
LDO Click context object.
Definition: ldo.h:146
LDO_OK
@ LDO_OK
Definition: ldo.h:179
ldo_read_register
err_t ldo_read_register(ldo_t *ctx, uint8_t reg, uint8_t *data_out)
LDO read register function.
ldo_t::slave_address
uint8_t slave_address
Definition: ldo.h:154
LDO_ERROR
@ LDO_ERROR
Definition: ldo.h:180
ldo_default_cfg
err_t ldo_default_cfg(ldo_t *ctx)
LDO default configuration function.
ldo_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ldo.h:168
ldo_set_pin_state
err_t ldo_set_pin_state(ldo_t *ctx, uint8_t pin_mask, uint8_t state)
LDO set pin state function.
ldo_cfg_t
LDO Click configuration object.
Definition: ldo.h:163