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
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define LDO_REG_INPUT_PORT 0x00
74#define LDO_REG_OUTPUT_PORT 0x01
75#define LDO_REG_POLARITY_INV 0x02
76#define LDO_REG_CONFIG 0x03
77
78 // ldo_reg
79
94#define LDO_PIN_NONE 0x00
95#define LDO_PIN_1600_mV 0x01
96#define LDO_PIN_800_mV 0x02
97#define LDO_PIN_400_mV 0x04
98#define LDO_PIN_200_mV 0x08
99#define LDO_PIN_100_mV 0x10
100#define LDO_PIN_50_mV 0x20
101#define LDO_PIN_ALL 0x3F
102
107#define LDO_PIN_LOW 0
108#define LDO_PIN_OPEN 1
109
114#define LDO_VOUT_MIN 800
115#define LDO_VOUT_STEP 50
116#define LDO_VOUT_MAX 3950
117
122#define LDO_DEVICE_ADDRESS_0 0x38
123#define LDO_DEVICE_ADDRESS_1 0x39
124#define LDO_DEVICE_ADDRESS_2 0x3A
125#define LDO_DEVICE_ADDRESS_3 0x3B
126#define LDO_DEVICE_ADDRESS_4 0x3C
127#define LDO_DEVICE_ADDRESS_5 0x3D
128#define LDO_DEVICE_ADDRESS_6 0x3E
129#define LDO_DEVICE_ADDRESS_7 0x3F
130
131 // ldo_set
132
147#define LDO_MAP_MIKROBUS( cfg, mikrobus ) \
148 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
149 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
150 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
151
152 // ldo_map
153 // ldo
154
159typedef struct
160{
161 // Output pins
162 digital_out_t en;
164 // Modules
165 i2c_master_t i2c;
167 // I2C slave address
170} ldo_t;
171
176typedef struct
177{
178 pin_name_t scl;
179 pin_name_t sda;
180 pin_name_t en;
182 uint32_t i2c_speed;
183 uint8_t i2c_address;
185} ldo_cfg_t;
186
191typedef enum
192{
194 LDO_ERROR = -1
195
197
214
228err_t ldo_init ( ldo_t *ctx, ldo_cfg_t *cfg );
229
242err_t ldo_default_cfg ( ldo_t *ctx );
243
256err_t ldo_write_register ( ldo_t *ctx, uint8_t reg, uint8_t data_in );
257
270err_t ldo_read_register ( ldo_t *ctx, uint8_t reg, uint8_t *data_out );
271
284err_t ldo_set_pin_state ( ldo_t *ctx, uint8_t pin_mask, uint8_t state );
285
297err_t ldo_set_vout ( ldo_t *ctx, uint16_t vout );
298
308
318
319#ifdef __cplusplus
320}
321#endif
322#endif // LDO_H
323
324 // ldo
325
326// ------------------------------------------------------------------------ END
void ldo_cfg_setup(ldo_cfg_t *cfg)
LDO configuration object setup function.
void ldo_disable_device(ldo_t *ctx)
LDO disable device function.
err_t ldo_write_register(ldo_t *ctx, uint8_t reg, uint8_t data_in)
LDO write register function.
err_t ldo_set_vout(ldo_t *ctx, uint16_t vout)
LDO set vout function.
err_t ldo_init(ldo_t *ctx, ldo_cfg_t *cfg)
LDO initialization function.
err_t ldo_set_pin_state(ldo_t *ctx, uint8_t pin_mask, uint8_t state)
LDO set pin state function.
void ldo_enable_device(ldo_t *ctx)
LDO enable device function.
err_t ldo_read_register(ldo_t *ctx, uint8_t reg, uint8_t *data_out)
LDO read register function.
err_t ldo_default_cfg(ldo_t *ctx)
LDO default configuration function.
ldo_return_value_t
LDO Click return value data.
Definition ldo.h:192
@ LDO_ERROR
Definition ldo.h:194
@ LDO_OK
Definition ldo.h:193
LDO Click configuration object.
Definition ldo.h:177
uint32_t i2c_speed
Definition ldo.h:182
pin_name_t scl
Definition ldo.h:178
pin_name_t en
Definition ldo.h:180
pin_name_t sda
Definition ldo.h:179
uint8_t i2c_address
Definition ldo.h:183
LDO Click context object.
Definition ldo.h:160
i2c_master_t i2c
Definition ldo.h:165
digital_out_t en
Definition ldo.h:162
uint8_t slave_address
Definition ldo.h:168