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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define LDO_REG_INPUT_PORT 0x00
70 #define LDO_REG_OUTPUT_PORT 0x01
71 #define LDO_REG_POLARITY_INV 0x02
72 #define LDO_REG_CONFIG 0x03
73  // ldo_reg
75 
90 #define LDO_PIN_NONE 0x00
91 #define LDO_PIN_1600_mV 0x01
92 #define LDO_PIN_800_mV 0x02
93 #define LDO_PIN_400_mV 0x04
94 #define LDO_PIN_200_mV 0x08
95 #define LDO_PIN_100_mV 0x10
96 #define LDO_PIN_50_mV 0x20
97 #define LDO_PIN_ALL 0x3F
98 
103 #define LDO_PIN_LOW 0
104 #define LDO_PIN_OPEN 1
105 
110 #define LDO_VOUT_MIN 800
111 #define LDO_VOUT_STEP 50
112 #define LDO_VOUT_MAX 3950
113 
118 #define LDO_DEVICE_ADDRESS_0 0x38
119 #define LDO_DEVICE_ADDRESS_1 0x39
120 #define LDO_DEVICE_ADDRESS_2 0x3A
121 #define LDO_DEVICE_ADDRESS_3 0x3B
122 #define LDO_DEVICE_ADDRESS_4 0x3C
123 #define LDO_DEVICE_ADDRESS_5 0x3D
124 #define LDO_DEVICE_ADDRESS_6 0x3E
125 #define LDO_DEVICE_ADDRESS_7 0x3F
126  // ldo_set
128 
143 #define LDO_MAP_MIKROBUS( cfg, mikrobus ) \
144  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
145  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
146  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
147  // ldo_map // ldo
150 
155 typedef struct
156 {
157  // Output pins
158  digital_out_t en;
160  // Modules
161  i2c_master_t i2c;
163  // I2C slave address
164  uint8_t slave_address;
166 } ldo_t;
167 
172 typedef struct
173 {
174  pin_name_t scl;
175  pin_name_t sda;
176  pin_name_t en;
178  uint32_t i2c_speed;
179  uint8_t i2c_address;
181 } ldo_cfg_t;
182 
187 typedef enum
188 {
189  LDO_OK = 0,
190  LDO_ERROR = -1
191 
193 
209 void ldo_cfg_setup ( ldo_cfg_t *cfg );
210 
224 err_t ldo_init ( ldo_t *ctx, ldo_cfg_t *cfg );
225 
238 err_t ldo_default_cfg ( ldo_t *ctx );
239 
252 err_t ldo_write_register ( ldo_t *ctx, uint8_t reg, uint8_t data_in );
253 
266 err_t ldo_read_register ( ldo_t *ctx, uint8_t reg, uint8_t *data_out );
267 
280 err_t ldo_set_pin_state ( ldo_t *ctx, uint8_t pin_mask, uint8_t state );
281 
293 err_t ldo_set_vout ( ldo_t *ctx, uint16_t vout );
294 
303 void ldo_enable_device ( ldo_t *ctx );
304 
313 void ldo_disable_device ( ldo_t *ctx );
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 #endif // LDO_H
319  // ldo
321 
322 // ------------------------------------------------------------------------ END
ldo_cfg_t::i2c_address
uint8_t i2c_address
Definition: ldo.h:179
ldo_enable_device
void ldo_enable_device(ldo_t *ctx)
LDO enable device function.
ldo_t::i2c
i2c_master_t i2c
Definition: ldo.h:161
ldo_cfg_t::sda
pin_name_t sda
Definition: ldo.h:175
ldo_return_value_t
ldo_return_value_t
LDO Click return value data.
Definition: ldo.h:188
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:176
ldo_cfg_t::scl
pin_name_t scl
Definition: ldo.h:174
ldo_t::en
digital_out_t en
Definition: ldo.h:158
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:156
LDO_OK
@ LDO_OK
Definition: ldo.h:189
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:164
LDO_ERROR
@ LDO_ERROR
Definition: ldo.h:190
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:178
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:173