stepup2  2.1.0.0
stepup2.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 STEPUP2_H
29 #define STEPUP2_H
30 
31 #ifdef __cplusplus
32 extern "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 STEPUP2_CTRL_BYTE_VREG 0x11
74 #define STEPUP2_CTRL_BYTE_NVREG 0x21
75 #define STEPUP2_CTRL_BYTE_VREG_NVREG 0x51
76 #define STEPUP2_CTRL_BYTE_NVREG_VREG 0x61
77  // stepup2_ctrl_byte
79 
94 #define STEPUP2_WIPER_POS_MIN 0
95 #define STEPUP2_WIPER_POS_MIDDLE 127
96 #define STEPUP2_WIPER_POS_MAX 255
97 #define STEPUP2_RES_0_KOHM 0.0f
98 #define STEPUP2_RES_3_01_KOHM 3.01f
99 #define STEPUP2_RES_50_KOHM 50.0f
100 #define STEPUP2_RES_200_KOHM 200.0f
101 
106 #define STEPUP2_RESISTANCE_LIST 3.01f, 6.19f, 7.87f, 9.76f, \
107  12.1f, 18.2f, 22.6f, 28.7f, \
108  49.9f, 75.0f, 0.0f, 100.0f, \
109  124.0f, 154.0f, 191.0f
110 #define STEPUP2_VOUT_LIST 5.5f, 5.2f, 5.0f, 4.8f, 4.5f, \
111  4.3f, 4.0f, 3.8f, 3.6f, 3.5f, \
112  3.3f, 3.2f, 3.0f, 2.8f, 2.5f
113 
114 
120 #define STEPUP2_DEVICE_ADDRESS_0 0x28
121 #define STEPUP2_DEVICE_ADDRESS_1 0x29
122  // stepup2_set
124 
139 #define STEPUP2_MAP_MIKROBUS( cfg, mikrobus ) \
140  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
141  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
142  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM )
143  // stepup2_map // stepup2
146 
151 typedef struct
152 {
153  // Output pins
154  digital_out_t en;
156  // Modules
157  i2c_master_t i2c;
159  // I2C slave address
160  uint8_t slave_address;
162 } stepup2_t;
163 
168 typedef struct
169 {
170  pin_name_t scl;
171  pin_name_t sda;
173  pin_name_t en;
175  uint32_t i2c_speed;
176  uint8_t i2c_address;
178 } stepup2_cfg_t;
179 
184 typedef enum
185 {
201 
203 
208 typedef enum
209 {
211  STEPUP2_ERROR = -1
212 
214 
231 
245 err_t stepup2_init ( stepup2_t *ctx, stepup2_cfg_t *cfg );
246 
260 
272 void stepup2_enable ( stepup2_t *ctx );
273 
286 
302 err_t stepup2_write_data ( stepup2_t *ctx, uint8_t ctrl_byte, uint8_t data_in );
303 
317 err_t stepup2_read_data ( stepup2_t *ctx, uint8_t *data_out );
318 
333 err_t stepup2_set_wiper_pos ( stepup2_t *ctx, uint8_t wiper_pos );
334 
349 err_t stepup2_set_resistance ( stepup2_t *ctx, float res_kohm );
350 
368 
369 #ifdef __cplusplus
370 }
371 #endif
372 #endif // STEPUP2_H
373  // stepup2
375 
376 // ------------------------------------------------------------------------ END
STEPUP2_ERROR
@ STEPUP2_ERROR
Definition: stepup2.h:211
STEPUP2_VOUT_3V5
@ STEPUP2_VOUT_3V5
Definition: stepup2.h:195
STEPUP2_VOUT_5V2
@ STEPUP2_VOUT_5V2
Definition: stepup2.h:187
STEPUP2_VOUT_5V5
@ STEPUP2_VOUT_5V5
Definition: stepup2.h:186
stepup2_return_value_t
stepup2_return_value_t
Step Up 2 Click return value data.
Definition: stepup2.h:209
stepup2_cfg_t
Step Up 2 Click configuration object.
Definition: stepup2.h:169
stepup2_init
err_t stepup2_init(stepup2_t *ctx, stepup2_cfg_t *cfg)
Step Up 2 initialization function.
stepup2_t
Step Up 2 Click context object.
Definition: stepup2.h:152
stepup2_default_cfg
err_t stepup2_default_cfg(stepup2_t *ctx)
Step Up 2 default configuration function.
stepup2_set_resistance
err_t stepup2_set_resistance(stepup2_t *ctx, float res_kohm)
Step Up 2 sets the resistance function.
STEPUP2_VOUT_2V8
@ STEPUP2_VOUT_2V8
Definition: stepup2.h:199
STEPUP2_VOUT_4V3
@ STEPUP2_VOUT_4V3
Definition: stepup2.h:191
stepup2_cfg_t::scl
pin_name_t scl
Definition: stepup2.h:170
STEPUP2_OK
@ STEPUP2_OK
Definition: stepup2.h:210
STEPUP2_VOUT_4V5
@ STEPUP2_VOUT_4V5
Definition: stepup2.h:190
STEPUP2_VOUT_2V5
@ STEPUP2_VOUT_2V5
Definition: stepup2.h:200
stepup2_cfg_t::en
pin_name_t en
Definition: stepup2.h:173
STEPUP2_VOUT_3V8
@ STEPUP2_VOUT_3V8
Definition: stepup2.h:193
stepup2_set_vout
err_t stepup2_set_vout(stepup2_t *ctx, stepup2_vout_t vout)
Step Up 2 sets the VOUT function.
stepup2_t::i2c
i2c_master_t i2c
Definition: stepup2.h:157
STEPUP2_VOUT_4V8
@ STEPUP2_VOUT_4V8
Definition: stepup2.h:189
stepup2_cfg_t::sda
pin_name_t sda
Definition: stepup2.h:171
stepup2_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepup2.h:176
stepup2_cfg_setup
void stepup2_cfg_setup(stepup2_cfg_t *cfg)
Step Up 2 configuration object setup function.
STEPUP2_VOUT_4V
@ STEPUP2_VOUT_4V
Definition: stepup2.h:192
STEPUP2_VOUT_3V3
@ STEPUP2_VOUT_3V3
Definition: stepup2.h:196
stepup2_read_data
err_t stepup2_read_data(stepup2_t *ctx, uint8_t *data_out)
Step Up 2 data reading function.
stepup2_t::en
digital_out_t en
Definition: stepup2.h:154
stepup2_disable
void stepup2_disable(stepup2_t *ctx)
Step Up 2 disable the device function.
STEPUP2_VOUT_3V2
@ STEPUP2_VOUT_3V2
Definition: stepup2.h:197
STEPUP2_VOUT_3V6
@ STEPUP2_VOUT_3V6
Definition: stepup2.h:194
stepup2_write_data
err_t stepup2_write_data(stepup2_t *ctx, uint8_t ctrl_byte, uint8_t data_in)
Step Up 2 data writing function.
stepup2_set_wiper_pos
err_t stepup2_set_wiper_pos(stepup2_t *ctx, uint8_t wiper_pos)
Step Up 2 sets the wiper position function.
STEPUP2_VOUT_5V
@ STEPUP2_VOUT_5V
Definition: stepup2.h:188
stepup2_vout_t
stepup2_vout_t
Step Up 2 Click output voltage selection.
Definition: stepup2.h:185
stepup2_enable
void stepup2_enable(stepup2_t *ctx)
Step Up 2 enable the device function.
STEPUP2_VOUT_3V
@ STEPUP2_VOUT_3V
Definition: stepup2.h:198
stepup2_t::slave_address
uint8_t slave_address
Definition: stepup2.h:160
stepup2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepup2.h:175