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 
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 DIGIPOT13_CMD_VREG 0x11
74 #define DIGIPOT13_CMD_NVREG 0x21
75 #define DIGIPOT13_CMD_VREGxNVREG 0x51
76 #define DIGIPOT13_CMD_NVREGxVREG 0x61
77  // digipot13_cmd
79 
94 #define DIGIPOT13_WIPER_POS_MIN 0
95 #define DIGIPOT13_WIPER_POS_MIDDLE 127
96 #define DIGIPOT13_WIPER_POS_MAX 255
97 #define DIGIPOT13_RES_0_KOHM 0
98 #define DIGIPOT13_RES_50_KOHM 50
99 #define DIGIPOT13_RES_200_KOHM 200
100 
106 #define DIGIPOT13_DEVICE_ADDRESS_GND 0x28
107 #define DIGIPOT13_DEVICE_ADDRESS_VCC 0x29
108  // digipot13_set
110 
125 #define DIGIPOT13_MAP_MIKROBUS( cfg, mikrobus ) \
126  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
127  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
128  // digipot13_map // digipot13
130 
135 typedef struct
136 {
137  // Modules
138  i2c_master_t i2c;
140  // I2C slave address
141  uint8_t slave_address;
143 } digipot13_t;
144 
149 typedef struct
150 {
151  pin_name_t scl;
152  pin_name_t sda;
154  uint32_t i2c_speed;
155  uint8_t i2c_address;
158 
163 typedef enum
164 {
166  DIGIPOT13_ERROR = -1
167 
169 
174 typedef enum
175 {
180 
197 
212 
226 
241 err_t digipot13_write_data ( digipot13_t *ctx, uint8_t cmd, uint8_t data_in );
242 
256 err_t digipot13_set_wiper_pos ( digipot13_t *ctx, uint8_t wiper_pos );
257 
273 err_t digipot13_set_resistance ( digipot13_t *ctx, digipot13_cfg_res_t cfg_res, float res_kohm );
274 
289 
304 
305 #ifdef __cplusplus
306 }
307 #endif
308 #endif // DIGIPOT13_H
309  // digipot13
311 
312 // ------------------------------------------------------------------------ END
digipot13_t::i2c
i2c_master_t i2c
Definition: digipot13.h:138
digipot13_t::slave_address
uint8_t slave_address
Definition: digipot13.h:141
digipot13_cfg_t::scl
pin_name_t scl
Definition: digipot13.h:151
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:166
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:176
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:175
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:136
DIGIPOT13_OK
@ DIGIPOT13_OK
Definition: digipot13.h:165
DIGIPOT13_CFG_RES_WH
@ DIGIPOT13_CFG_RES_WH
Definition: digipot13.h:177
digipot13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: digipot13.h:154
digipot13_cfg_t::i2c_address
uint8_t i2c_address
Definition: digipot13.h:155
digipot13_cfg_t::sda
pin_name_t sda
Definition: digipot13.h:152
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:150
digipot13_return_value_t
digipot13_return_value_t
DIGI POT 13 Click return value data.
Definition: digipot13.h:164
digipot13_cfg_setup
void digipot13_cfg_setup(digipot13_cfg_t *cfg)
DIGI POT 13 configuration object setup function.