digipot13  2.1.0.0
digipot13.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 DIGIPOT13_H
29 #define DIGIPOT13_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 DIGIPOT13_CMD_VREG 0x11
70 #define DIGIPOT13_CMD_NVREG 0x21
71 #define DIGIPOT13_CMD_VREGxNVREG 0x51
72 #define DIGIPOT13_CMD_NVREGxVREG 0x61
73  // digipot13_cmd
75 
90 #define DIGIPOT13_WIPER_POS_MIN 0
91 #define DIGIPOT13_WIPER_POS_MIDDLE 127
92 #define DIGIPOT13_WIPER_POS_MAX 255
93 #define DIGIPOT13_RES_0_KOHM 0
94 #define DIGIPOT13_RES_50_KOHM 50
95 #define DIGIPOT13_RES_200_KOHM 200
96 
102 #define DIGIPOT13_DEVICE_ADDRESS_GND 0x28
103 #define DIGIPOT13_DEVICE_ADDRESS_VCC 0x29
104  // digipot13_set
106 
121 #define DIGIPOT13_MAP_MIKROBUS( cfg, mikrobus ) \
122  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
123  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
124  // digipot13_map // digipot13
126 
131 typedef struct
132 {
133  // Modules
134  i2c_master_t i2c;
136  // I2C slave address
137  uint8_t slave_address;
139 } digipot13_t;
140 
145 typedef struct
146 {
147  pin_name_t scl;
148  pin_name_t sda;
150  uint32_t i2c_speed;
151  uint8_t i2c_address;
154 
159 typedef enum
160 {
162  DIGIPOT13_ERROR = -1
163 
165 
170 typedef enum
171 {
176 
193 
208 
222 
237 err_t digipot13_write_data ( digipot13_t *ctx, uint8_t cmd, uint8_t data_in );
238 
252 err_t digipot13_set_wiper_pos ( digipot13_t *ctx, uint8_t wiper_pos );
253 
269 err_t digipot13_set_resistance ( digipot13_t *ctx, digipot13_cfg_res_t cfg_res, float res_kohm );
270 
285 
300 
301 #ifdef __cplusplus
302 }
303 #endif
304 #endif // DIGIPOT13_H
305  // digipot13
307 
308 // ------------------------------------------------------------------------ END
digipot13_t::i2c
i2c_master_t i2c
Definition: digipot13.h:134
digipot13_t::slave_address
uint8_t slave_address
Definition: digipot13.h:137
digipot13_cfg_t::scl
pin_name_t scl
Definition: digipot13.h:147
digipot13_init
err_t digipot13_init(digipot13_t *ctx, digipot13_cfg_t *cfg)
DIGI POT 13 initialization function.
DIGIPOT13_ERROR
@ DIGIPOT13_ERROR
Definition: digipot13.h:162
digipot13_default_cfg
err_t digipot13_default_cfg(digipot13_t *ctx)
DIGI POT 13 default configuration function.
DIGIPOT13_CFG_RES_WL
@ DIGIPOT13_CFG_RES_WL
Definition: digipot13.h:172
digipot13_switch_v_to_nv
err_t digipot13_switch_v_to_nv(digipot13_t *ctx)
DIGI POT 13 data transfers volatile to nonvolatile function.
digipot13_set_wiper_pos
err_t digipot13_set_wiper_pos(digipot13_t *ctx, uint8_t wiper_pos)
DIGI POT 13 set the wiper position function.
digipot13_cfg_res_t
digipot13_cfg_res_t
DIGI POT 13 Click resistance configuration value data.
Definition: digipot13.h:171
digipot13_set_resistance
err_t digipot13_set_resistance(digipot13_t *ctx, digipot13_cfg_res_t cfg_res, float res_kohm)
DIGI POT 13 set the resistance function.
digipot13_t
DIGI POT 13 Click context object.
Definition: digipot13.h:132
DIGIPOT13_OK
@ DIGIPOT13_OK
Definition: digipot13.h:161
DIGIPOT13_CFG_RES_WH
@ DIGIPOT13_CFG_RES_WH
Definition: digipot13.h:173
digipot13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: digipot13.h:150
digipot13_cfg_t::i2c_address
uint8_t i2c_address
Definition: digipot13.h:151
digipot13_cfg_t::sda
pin_name_t sda
Definition: digipot13.h:148
digipot13_switch_nv_to_v
err_t digipot13_switch_nv_to_v(digipot13_t *ctx)
DIGI POT 13 data transfers nonvolatile to volatile function.
digipot13_write_data
err_t digipot13_write_data(digipot13_t *ctx, uint8_t cmd, uint8_t data_in)
DIGI POT 13 write data function.
digipot13_cfg_t
DIGI POT 13 Click configuration object.
Definition: digipot13.h:146
digipot13_return_value_t
digipot13_return_value_t
DIGI POT 13 Click return value data.
Definition: digipot13.h:160
digipot13_cfg_setup
void digipot13_cfg_setup(digipot13_cfg_t *cfg)
DIGI POT 13 configuration object setup function.