stepdown5  2.1.0.0
stepdown5.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 STEPDOWN5_H
29 #define STEPDOWN5_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 STEPDOWN5_PFM_PWM_MODE 0x00
70 #define STEPDOWN5_FORCED_PWM_MODE 0x01
71 #define STEPDOWN5_R1_RPROG_ADDRESS 0x00
72 #define STEPDOWN5_R2_RPROG_ADDRESS 0x10
73 
78 #define STEPDOWN5_DIGIPOT_MAX_VALUE 100000ul
79 #define STEPDOWN5_DIGIPOT_RESOLUTION 257
80 #define STEPDOWN5_ROUND_TO_NEAREST_INT 0.5
81 
86 #define STEPDOWN5_OUTPUT_0V6 1
87 #define STEPDOWN5_OUTPUT_1V5 2
88 #define STEPDOWN5_OUTPUT_2V5 3
89 #define STEPDOWN5_OUTPUT_3V3 4
90 #define STEPDOWN5_OUTPUT_5V 5
91 
97 #define STEPDOWN5_ADDR_A2A1A0_000 0x28
98 #define STEPDOWN5_ADDR_A2A1A0_001 0x29
99 #define STEPDOWN5_ADDR_A2A1A0_010 0x2A
100 #define STEPDOWN5_ADDR_A2A1A0_011 0x2B
101 #define STEPDOWN5_ADDR_A2A1A0_100 0x2C
102 #define STEPDOWN5_ADDR_A2A1A0_101 0x2D
103 #define STEPDOWN5_ADDR_A2A1A0_110 0x2E
104 #define STEPDOWN5_ADDR_A2A1A0_111 0x2F
105  // stepdown5_set
107 
122 #define STEPDOWN5_MAP_MIKROBUS( cfg, mikrobus ) \
123  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
124  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
125  cfg.md = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
126  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
127  // stepdown5_map // stepdown5
130 
135 typedef struct
136 {
137  // Output pins
138  digital_out_t md;
140  // Input pins
141  digital_in_t pg;
143  // Modules
144  i2c_master_t i2c;
146  // I2C slave address
147  uint8_t slave_address;
149 } stepdown5_t;
150 
155 typedef struct
156 {
157  pin_name_t scl;
158  pin_name_t sda;
160  pin_name_t md;
161  pin_name_t pg;
163  uint32_t i2c_speed;
164  uint8_t i2c_address;
167 
172 typedef enum
173 {
175  STEPDOWN5_ERROR = -1
176 
178 
195 
210 
224 
239 err_t stepdown5_generic_write ( stepdown5_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
240 
255 err_t stepdown5_generic_read ( stepdown5_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
256 
266 void stepdown5_set_mode ( stepdown5_t *ctx, uint8_t mode );
267 
277 
289 err_t stepdown5_set_wiper_0_pos ( stepdown5_t *ctx, uint16_t wiper_0_pos );
290 
302 err_t stepdown5_set_wiper_1_pos ( stepdown5_t *ctx, uint16_t wiper_1_pos );
303 
315 err_t stepdown5_set_r1_resistance ( stepdown5_t *ctx, uint32_t resistance );
316 
328 err_t stepdown5_set_r2_resistance ( stepdown5_t *ctx, uint32_t resistance );
329 
341 err_t stepdown5_set_output ( stepdown5_t *ctx, uint8_t voltage );
342 
343 #ifdef __cplusplus
344 }
345 #endif
346 #endif // STEPDOWN5_H
347  // stepdown5
349 
350 // ------------------------------------------------------------------------ END
stepdown5_cfg_t::md
pin_name_t md
Definition: stepdown5.h:160
STEPDOWN5_ERROR
@ STEPDOWN5_ERROR
Definition: stepdown5.h:175
stepdown5_generic_read
err_t stepdown5_generic_read(stepdown5_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Step Down 5 I2C reading function.
stepdown5_set_r2_resistance
err_t stepdown5_set_r2_resistance(stepdown5_t *ctx, uint32_t resistance)
Step Down 5 set potentiometer 1 resistance.
stepdown5_t::md
digital_out_t md
Definition: stepdown5.h:138
stepdown5_cfg_t::sda
pin_name_t sda
Definition: stepdown5.h:158
stepdown5_cfg_t::scl
pin_name_t scl
Definition: stepdown5.h:157
stepdown5_get_pg_state
uint8_t stepdown5_get_pg_state(stepdown5_t *ctx)
Step Down 5 get PG pin state function.
stepdown5_cfg_t
Step Down 5 Click configuration object.
Definition: stepdown5.h:156
stepdown5_generic_write
err_t stepdown5_generic_write(stepdown5_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Step Down 5 I2C writing function.
stepdown5_cfg_t::pg
pin_name_t pg
Definition: stepdown5.h:161
stepdown5_return_value_t
stepdown5_return_value_t
Step Down 5 Click return value data.
Definition: stepdown5.h:173
STEPDOWN5_OK
@ STEPDOWN5_OK
Definition: stepdown5.h:174
stepdown5_init
err_t stepdown5_init(stepdown5_t *ctx, stepdown5_cfg_t *cfg)
Step Down 5 initialization function.
stepdown5_cfg_setup
void stepdown5_cfg_setup(stepdown5_cfg_t *cfg)
Step Down 5 configuration object setup function.
stepdown5_set_mode
void stepdown5_set_mode(stepdown5_t *ctx, uint8_t mode)
Step Down 5 mode selection function.
stepdown5_set_r1_resistance
err_t stepdown5_set_r1_resistance(stepdown5_t *ctx, uint32_t resistance)
Step Down 5 set potentiometer 0 resistance.
stepdown5_set_wiper_0_pos
err_t stepdown5_set_wiper_0_pos(stepdown5_t *ctx, uint16_t wiper_0_pos)
Step Down 5 set wiper 0 position.
stepdown5_t::slave_address
uint8_t slave_address
Definition: stepdown5.h:147
stepdown5_set_wiper_1_pos
err_t stepdown5_set_wiper_1_pos(stepdown5_t *ctx, uint16_t wiper_1_pos)
Step Down 5 set wiper 1 position.
stepdown5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepdown5.h:163
stepdown5_t
Step Down 5 Click context object.
Definition: stepdown5.h:136
stepdown5_t::i2c
i2c_master_t i2c
Definition: stepdown5.h:144
stepdown5_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepdown5.h:164
stepdown5_set_output
err_t stepdown5_set_output(stepdown5_t *ctx, uint8_t voltage)
Step Down 5 set output voltage.
stepdown5_default_cfg
err_t stepdown5_default_cfg(stepdown5_t *ctx)
Step Down 5 default configuration function.
stepdown5_t::pg
digital_in_t pg
Definition: stepdown5.h:141