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 "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 STEPDOWN7_PFM_PWM_MODE 0x00
70 #define STEPDOWN7_FORCED_PWM_MODE 0x01
71 #define STEPDOWN7_R1_RPROG_ADDRESS 0x00
72 
77 #define STEPDOWN7_PIN_STATE_HIGH 0x01
78 #define STEPDOWN7_PIN_STATE_LOW 0x00
79 
84 #define STEPDOWN7_DIGIPOT_MAX_VALUE 100000ul
85 #define STEPDOWN7_DIGIPOT_RESOLUTION 257
86 #define STEPDOWN7_ROUND_TO_NEAREST_INT 0.5
87 #define STEPDOWN7_R8_VALUE 15000u
88 #define STEPDOWN7_1V5_RESISTANCE 17500u
89 #define STEPDOWN7_2V5_RESISTANCE 42500u
90 #define STEPDOWN7_3V3_RESISTANCE 62500u
91 
92 
97 #define STEPDOWN7_OUTPUT_1V5 0
98 #define STEPDOWN7_OUTPUT_2V5 1
99 #define STEPDOWN7_OUTPUT_3V3 2
100 
106 #define STEPDOWN7_ADDR_A2A1A0_000 0x28
107 #define STEPDOWN7_ADDR_A2A1A0_001 0x29
108 #define STEPDOWN7_ADDR_A2A1A0_010 0x2A
109 #define STEPDOWN7_ADDR_A2A1A0_011 0x2B
110 #define STEPDOWN7_ADDR_A2A1A0_100 0x2C
111 #define STEPDOWN7_ADDR_A2A1A0_101 0x2D
112 #define STEPDOWN7_ADDR_A2A1A0_110 0x2E
113 #define STEPDOWN7_ADDR_A2A1A0_111 0x2F
114  // stepdown7_set
116 
131 #define STEPDOWN7_MAP_MIKROBUS( cfg, mikrobus ) \
132  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
133  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
134  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
135  cfg.md = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
136  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
137  // stepdown7_map // stepdown7
140 
145 typedef struct
146 {
147  // Output pins
148  digital_out_t en ;
149  digital_out_t md;
151  // Input pins
152  digital_in_t pg;
154  // Modules
155  i2c_master_t i2c;
157  // I2C slave address
158  uint8_t slave_address;
160 } stepdown7_t;
161 
166 typedef struct
167 {
168  pin_name_t scl;
169  pin_name_t sda;
171  pin_name_t en ;
172  pin_name_t md;
173  pin_name_t pg;
175  uint32_t i2c_speed;
176  uint8_t i2c_address;
179 
184 typedef enum
185 {
187  STEPDOWN7_ERROR = -1
188 
190 
207 
222 
236 
251 err_t stepdown7_generic_write ( stepdown7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
252 
267 err_t stepdown7_generic_read ( stepdown7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
268 
278 void stepdown7_set_mode ( stepdown7_t *ctx, uint8_t mode );
279 
289 void stepdown7_set_en ( stepdown7_t *ctx, uint8_t en_state );
290 
300 
312 err_t stepdown7_set_wiper_pos ( stepdown7_t *ctx, uint16_t wiper_pos );
313 
325 err_t stepdown7_set_r1_resistance ( stepdown7_t *ctx, uint32_t resistance );
326 
338 err_t stepdown7_set_output ( stepdown7_t *ctx, uint8_t voltage );
339 
340 
341 #ifdef __cplusplus
342 }
343 #endif
344 #endif // STEPDOWN7_H
345  // stepdown7
347 
348 // ------------------------------------------------------------------------ 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:186
STEPDOWN7_ERROR
@ STEPDOWN7_ERROR
Definition: stepdown7.h:187
stepdown7_cfg_t::md
pin_name_t md
Definition: stepdown7.h:172
stepdown7_t::slave_address
uint8_t slave_address
Definition: stepdown7.h:158
stepdown7_cfg_t::pg
pin_name_t pg
Definition: stepdown7.h:173
stepdown7_cfg_t::scl
pin_name_t scl
Definition: stepdown7.h:168
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:169
stepdown7_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepdown7.h:176
stepdown7_t::pg
digital_in_t pg
Definition: stepdown7.h:152
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:175
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:167
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:155
stepdown7_return_value_t
stepdown7_return_value_t
Step Down 7 Click return value data.
Definition: stepdown7.h:185
stepdown7_t::en
digital_out_t en
Definition: stepdown7.h:148
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:149
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:171
stepdown7_t
Step Down 7 Click context object.
Definition: stepdown7.h:146