stepdown7  2.1.0.0
stepdown7.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 STEPDOWN7_H
29 #define STEPDOWN7_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define STEPDOWN7_PFM_PWM_MODE 0x00
60 #define STEPDOWN7_FORCED_PWM_MODE 0x01
61 #define STEPDOWN7_R1_RPROG_ADDRESS 0x00
62 
67 #define STEPDOWN7_PIN_STATE_HIGH 0x01
68 #define STEPDOWN7_PIN_STATE_LOW 0x00
69 
74 #define STEPDOWN7_DIGIPOT_MAX_VALUE 100000ul
75 #define STEPDOWN7_DIGIPOT_RESOLUTION 257
76 #define STEPDOWN7_ROUND_TO_NEAREST_INT 0.5
77 #define STEPDOWN7_R8_VALUE 15000u
78 #define STEPDOWN7_1V5_RESISTANCE 17500u
79 #define STEPDOWN7_2V5_RESISTANCE 42500u
80 #define STEPDOWN7_3V3_RESISTANCE 62500u
81 
82 
87 #define STEPDOWN7_OUTPUT_1V5 0
88 #define STEPDOWN7_OUTPUT_2V5 1
89 #define STEPDOWN7_OUTPUT_3V3 2
90 
96 #define STEPDOWN7_ADDR_A2A1A0_000 0x28
97 #define STEPDOWN7_ADDR_A2A1A0_001 0x29
98 #define STEPDOWN7_ADDR_A2A1A0_010 0x2A
99 #define STEPDOWN7_ADDR_A2A1A0_011 0x2B
100 #define STEPDOWN7_ADDR_A2A1A0_100 0x2C
101 #define STEPDOWN7_ADDR_A2A1A0_101 0x2D
102 #define STEPDOWN7_ADDR_A2A1A0_110 0x2E
103 #define STEPDOWN7_ADDR_A2A1A0_111 0x2F
104  // stepdown7_set
106 
121 #define STEPDOWN7_MAP_MIKROBUS( cfg, mikrobus ) \
122  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
123  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
124  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
125  cfg.md = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
126  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
127  // stepdown7_map // stepdown7
130 
135 typedef struct
136 {
137  // Output pins
138  digital_out_t en ;
139  digital_out_t md;
141  // Input pins
142  digital_in_t pg;
144  // Modules
145  i2c_master_t i2c;
147  // I2C slave address
148  uint8_t slave_address;
150 } stepdown7_t;
151 
156 typedef struct
157 {
158  pin_name_t scl;
159  pin_name_t sda;
161  pin_name_t en ;
162  pin_name_t md;
163  pin_name_t pg;
165  uint32_t i2c_speed;
166  uint8_t i2c_address;
169 
174 typedef enum
175 {
177  STEPDOWN7_ERROR = -1
178 
180 
197 
212 
226 
241 err_t stepdown7_generic_write ( stepdown7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
242 
257 err_t stepdown7_generic_read ( stepdown7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
258 
268 void stepdown7_set_mode ( stepdown7_t *ctx, uint8_t mode );
269 
279 void stepdown7_set_en ( stepdown7_t *ctx, uint8_t en_state );
280 
290 
302 err_t stepdown7_set_wiper_pos ( stepdown7_t *ctx, uint16_t wiper_pos );
303 
315 err_t stepdown7_set_r1_resistance ( stepdown7_t *ctx, uint32_t resistance );
316 
328 err_t stepdown7_set_output ( stepdown7_t *ctx, uint8_t voltage );
329 
330 
331 #ifdef __cplusplus
332 }
333 #endif
334 #endif // STEPDOWN7_H
335  // stepdown7
337 
338 // ------------------------------------------------------------------------ END
stepdown7_set_en
void stepdown7_set_en(stepdown7_t *ctx, uint8_t en_state)
Step Down 5 set EN pin state function.
STEPDOWN7_OK
@ STEPDOWN7_OK
Definition: stepdown7.h:176
STEPDOWN7_ERROR
@ STEPDOWN7_ERROR
Definition: stepdown7.h:177
stepdown7_cfg_t::md
pin_name_t md
Definition: stepdown7.h:162
stepdown7_t::slave_address
uint8_t slave_address
Definition: stepdown7.h:148
stepdown7_cfg_t::pg
pin_name_t pg
Definition: stepdown7.h:163
stepdown7_cfg_t::scl
pin_name_t scl
Definition: stepdown7.h:158
stepdown7_set_r1_resistance
err_t stepdown7_set_r1_resistance(stepdown7_t *ctx, uint32_t resistance)
Step Down 7 set potentiometer resistance.
stepdown7_cfg_t::sda
pin_name_t sda
Definition: stepdown7.h:159
stepdown7_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepdown7.h:166
stepdown7_t::pg
digital_in_t pg
Definition: stepdown7.h:142
stepdown7_set_mode
void stepdown7_set_mode(stepdown7_t *ctx, uint8_t mode)
Step Down 5 mode selection function.
stepdown7_set_wiper_pos
err_t stepdown7_set_wiper_pos(stepdown7_t *ctx, uint16_t wiper_pos)
Step Down 5 set wiper 1 position.
stepdown7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepdown7.h:165
stepdown7_generic_read
err_t stepdown7_generic_read(stepdown7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Step Down 7 I2C reading function.
stepdown7_init
err_t stepdown7_init(stepdown7_t *ctx, stepdown7_cfg_t *cfg)
Step Down 7 initialization function.
stepdown7_generic_write
err_t stepdown7_generic_write(stepdown7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Step Down 7 I2C writing function.
stepdown7_cfg_t
Step Down 7 Click configuration object.
Definition: stepdown7.h:157
stepdown7_default_cfg
err_t stepdown7_default_cfg(stepdown7_t *ctx)
Step Down 7 default configuration function.
stepdown7_t::i2c
i2c_master_t i2c
Definition: stepdown7.h:145
stepdown7_return_value_t
stepdown7_return_value_t
Step Down 7 Click return value data.
Definition: stepdown7.h:175
stepdown7_t::en
digital_out_t en
Definition: stepdown7.h:138
stepdown7_get_pg_state
uint8_t stepdown7_get_pg_state(stepdown7_t *ctx)
Step Down 5 get PG pin state function.
stepdown7_set_output
err_t stepdown7_set_output(stepdown7_t *ctx, uint8_t voltage)
Step Down 7 set output voltage.
stepdown7_t::md
digital_out_t md
Definition: stepdown7.h:139
stepdown7_cfg_setup
void stepdown7_cfg_setup(stepdown7_cfg_t *cfg)
Step Down 7 configuration object setup function.
stepdown7_cfg_t::en
pin_name_t en
Definition: stepdown7.h:161
stepdown7_t
Step Down 7 Click context object.
Definition: stepdown7.h:136