stepdown11 2.1.0.0
stepdown11.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 STEPDOWN11_H
29#define STEPDOWN11_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 STEPDOWN11_ADDR_BIT_READ_INPUT_REG 0x00
74#define STEPDOWN11_ADDR_BIT_READ_EEPROM 0x01
75#define STEPDOWN11_ADDR_BIT_READ_CTRL_REG 0x02
76#define STEPDOWN11_ADDR_BIT_READ_RDAC 0x03
77#define STEPDOWN11_ADDR_BIT_RDAC_DECR 0x00
78#define STEPDOWN11_ADDR_BIT_RDAC_INCR 0x01
79#define STEPDOWN11_ADDR_BIT_COPY_TO_RDAC 0x00
80#define STEPDOWN11_ADDR_BIT_COPY_TO_EEPROM 0x01
81#define STEPDOWN11_ADDR_BIT_SCALE_MODE_NORMAL 0x80
82#define STEPDOWN11_ADDR_BIT_SCALE_MODE_SHDN 0x81
83#define STEPDOWN11_ADDR_BIT_SCALE_EXIT 0x00
84#define STEPDOWN11_ADDR_BIT_SCALE_ENTER 0x01
85#define STEPDOWN11_ADDR_BIT_SW_SHDN_MODE_NORMAL 0x00
86#define STEPDOWN11_ADDR_BIT_SW_SHDN_MODE_SHDN 0x01
87
88 // stepdown11_reg
89
104#define STEPDOWN11_CTRL_BIT_NOP 0x00
105#define STEPDOWN11_CTRL_BIT_WRITE_RDAC 0x10
106#define STEPDOWN11_CTRL_BIT_WRITE_SHIFT_REG 0x20
107#define STEPDOWN11_CTRL_BIT_READ 0x30
108#define STEPDOWN11_CTRL_BIT_LIN_RDAC 0x40
109#define STEPDOWN11_CTRL_BIT_6_DB_RDAC 0x50
110#define STEPDOWN11_CTRL_BIT_COPY_LRDAC 0x60
111#define STEPDOWN11_CTRL_BIT_COPY_RDAC_EEPROM 0x70
112#define STEPDOWN11_CTRL_BIT_WRITE_EEPROM 0x80
113#define STEPDOWN11_CTRL_BIT_SCALE 0x90
114#define STEPDOWN11_CTRL_BIT_SW_RST 0xB0
115#define STEPDOWN11_CTRL_BIT_SW_SHDN 0xC0
116#define STEPDOWN11_CTRL_BIT_REG_CTRL 0xD0
117#define STEPDOWN11_CTRL_BIT_MASK 0xF0
118
123#define STEPDOWN11_WIPER_SEL_1 0x00
124#define STEPDOWN11_WIPER_SEL_2 0x01
125#define STEPDOWN11_WIPER_SEL_BOTH 0x08
126
131#define STEPDOWN11_S_CONF_1MHZ_SPREAD_OFF 0
132#define STEPDOWN11_S_CONF_2_2MHZ_SPREAD_OFF 4870
133#define STEPDOWN11_S_CONF_2_2MHZ_SPREAD_TRIANGLE 6040
134#define STEPDOWN11_S_CONF_2_2MHZ_SPREAD_RANDOM 7500
135
140#define STEPDOWN11_WIPER_POS_MAX 255
141#define STEPDOWN11_WIPER_POS_MIN 0
142#define STEPDOWN11_WIPER_POS_MIDDLE 127
143#define STEPDOWN11_RES_10_KOHM 10000
144#define STEPDOWN11_RES_0_KOHM 0
145#define STEPDOWN11_R_5_RESISTANCE 2700
146#define STEPDOWN11_R_9_RESISTANCE 10
147#define STEPDOWN11_VFB_VALUE 0.8f
148
153#define STEPDOWN11_ENABLE_OUTPUT 0x01
154#define STEPDOWN11_DISABLE_OUTPUT 0x00
155
161#define STEPDOWN11_DEVICE_ADDRESS_0 0x2F
162#define STEPDOWN11_DEVICE_ADDRESS_1 0x2C
163#define STEPDOWN11_DEVICE_ADDRESS_2 0x23
164#define STEPDOWN11_DEVICE_ADDRESS_3 0x20
165
166 // stepdown11_set
167
182#define STEPDOWN11_MAP_MIKROBUS( cfg, mikrobus ) \
183 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
184 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
185 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
186 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
187 cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
188
189 // stepdown11_map
190 // stepdown11
191
196typedef struct
197{
198 // Output pins
199 digital_out_t rst;
200 digital_out_t en;
202 // Input pins
203 digital_in_t pg;
205 // Modules
206 i2c_master_t i2c;
208 // I2C slave address
212
217typedef struct
218{
219 pin_name_t scl;
220 pin_name_t sda;
222 pin_name_t rst;
223 pin_name_t en;
224 pin_name_t pg;
226 uint32_t i2c_speed;
227 uint8_t i2c_address;
230
241
258
273
287
302err_t stepdown11_generic_write ( stepdown11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
303
318err_t stepdown11_generic_read ( stepdown11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
319
329void stepdown11_set_en_pin ( stepdown11_t *ctx, uint8_t pin_state );
330
340
350
365err_t stepdown11_write_data ( stepdown11_t *ctx, uint8_t ctrl, uint8_t addr, uint8_t data_in );
366
381err_t stepdown11_read_data ( stepdown11_t *ctx, uint8_t addr, uint8_t mask, uint8_t *data_out );
382
397err_t stepdown11_write_rdac ( stepdown11_t *ctx, uint8_t addr, uint8_t data_in );
398
413err_t stepdown11_read_rdac ( stepdown11_t *ctx, uint8_t addr, uint8_t *data_out );
414
429err_t stepdown11_set_resistance ( stepdown11_t *ctx, uint8_t wiper_sel, float res_kohm );
430
445err_t stepdown11_get_resistance ( stepdown11_t *ctx, uint8_t wiper_sel, float *res_kohm );
446
458err_t stepdown11_set_voltage ( stepdown11_t *ctx, float v_out );
459
471err_t stepdown11_set_mode ( stepdown11_t *ctx, float sconf_mode );
472
473#ifdef __cplusplus
474}
475#endif
476#endif // STEPDOWN11_H
477
478 // stepdown11
479
480// ------------------------------------------------------------------------ END
err_t stepdown11_init(stepdown11_t *ctx, stepdown11_cfg_t *cfg)
Step Down 11 initialization function.
err_t stepdown11_write_rdac(stepdown11_t *ctx, uint8_t addr, uint8_t data_in)
Step Down 11 write the RDAC function.
uint8_t stepdown11_get_pg_pin(stepdown11_t *ctx)
Step Down 11 get PG pin state function.
err_t stepdown11_generic_write(stepdown11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Step Down 11 I2C writing function.
err_t stepdown11_set_mode(stepdown11_t *ctx, float sconf_mode)
Step Down 11 set S-CONF device configuration mode function.
void stepdown11_cfg_setup(stepdown11_cfg_t *cfg)
Step Down 11 configuration object setup function.
void stepdown11_reset_digi_pot(stepdown11_t *ctx)
Step Down 11 reset digi pot function.
err_t stepdown11_get_resistance(stepdown11_t *ctx, uint8_t wiper_sel, float *res_kohm)
Step Down 11 get the resistance function.
err_t stepdown11_write_data(stepdown11_t *ctx, uint8_t ctrl, uint8_t addr, uint8_t data_in)
Step Down 11 I2C writing function.
err_t stepdown11_read_data(stepdown11_t *ctx, uint8_t addr, uint8_t mask, uint8_t *data_out)
Step Down 11 I2C reading function.
err_t stepdown11_default_cfg(stepdown11_t *ctx)
Step Down 11 default configuration function.
err_t stepdown11_set_resistance(stepdown11_t *ctx, uint8_t wiper_sel, float res_kohm)
Step Down 11 set the resistance function.
void stepdown11_set_en_pin(stepdown11_t *ctx, uint8_t pin_state)
Step Down 11 set EN pin state function.
err_t stepdown11_generic_read(stepdown11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Step Down 11 I2C reading function.
err_t stepdown11_set_voltage(stepdown11_t *ctx, float v_out)
Step Down 11 set voltage output function.
err_t stepdown11_read_rdac(stepdown11_t *ctx, uint8_t addr, uint8_t *data_out)
Step Down 11 read the RDAC function.
stepdown11_return_value_t
Step Down 11 Click return value data.
Definition stepdown11.h:236
@ STEPDOWN11_OK
Definition stepdown11.h:237
@ STEPDOWN11_ERROR
Definition stepdown11.h:238
Step Down 11 Click configuration object.
Definition stepdown11.h:218
uint32_t i2c_speed
Definition stepdown11.h:226
pin_name_t scl
Definition stepdown11.h:219
pin_name_t en
Definition stepdown11.h:223
pin_name_t sda
Definition stepdown11.h:220
pin_name_t pg
Definition stepdown11.h:224
pin_name_t rst
Definition stepdown11.h:222
uint8_t i2c_address
Definition stepdown11.h:227
Step Down 11 Click context object.
Definition stepdown11.h:197
i2c_master_t i2c
Definition stepdown11.h:206
digital_out_t en
Definition stepdown11.h:200
digital_out_t rst
Definition stepdown11.h:199
uint8_t slave_address
Definition stepdown11.h:209
digital_in_t pg
Definition stepdown11.h:203