digipot12  2.1.0.0
digipot12.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 DIGIPOT12_H
29 #define DIGIPOT12_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 DIGIPOT12_CTRL_BIT_NOP 0x00
70 #define DIGIPOT12_CTRL_BIT_WRITE_RDAC 0x10
71 #define DIGIPOT12_CTRL_BIT_WRITE_SHIFT_REG 0x20
72 #define DIGIPOT12_CTRL_BIT_READ 0x30
73 #define DIGIPOT12_CTRL_BIT_LIN_RDAC 0x40
74 #define DIGIPOT12_CTRL_BIT_6_DB_RDAC 0x50
75 #define DIGIPOT12_CTRL_BIT_COPY_LRDAC 0x60
76 #define DIGIPOT12_CTRL_BIT_COPY_RDAC_EEPROM 0x70
77 #define DIGIPOT12_CTRL_BIT_WRITE_EEPROM 0x80
78 #define DIGIPOT12_CTRL_BIT_SCALE 0x90
79 #define DIGIPOT12_CTRL_BIT_SW_RST 0xB0
80 #define DIGIPOT12_CTRL_BIT_SW_SHDN 0xC0
81 #define DIGIPOT12_CTRL_BIT_REG_CTRL 0xD0
82 #define DIGIPOT12_CTRL_BIT_MASK 0xF0
83  // digipot12_ctrl
85 
95 #define DIGIPOT12_ADDR_BIT_RDAC1 0x00
96 #define DIGIPOT12_ADDR_BIT_RDAC2 0x01
97 #define DIGIPOT12_ADDR_BIT_ALL_CHANNELS 0x08
98  // digipot12_addr
100 
110 #define DIGIPOT12_WIPER_SEL_1 0x00
111 #define DIGIPOT12_WIPER_SEL_2 0x01
112 #define DIGIPOT12_WIPER_SEL_BOTH 0x08
113  // digipot12_wiper_sel
115 
125 #define DIGIPOT12_ADDR_BIT_READ_INPUT_REG 0x00
126 #define DIGIPOT12_ADDR_BIT_READ_EEPROM 0x01
127 #define DIGIPOT12_ADDR_BIT_READ_CTRL_REG 0x02
128 #define DIGIPOT12_ADDR_BIT_READ_RDAC 0x03
129 #define DIGIPOT12_ADDR_BIT_RDAC_DECR 0x00
130 #define DIGIPOT12_ADDR_BIT_RDAC_INCR 0x01
131 #define DIGIPOT12_ADDR_BIT_COPY_TO_RDAC 0x00
132 #define DIGIPOT12_ADDR_BIT_COPY_TO_EEPROM 0x01
133 #define DIGIPOT12_ADDR_BIT_SCALE_MODE_NORMAL 0x80
134 #define DIGIPOT12_ADDR_BIT_SCALE_MODE_SHDN 0x81
135 #define DIGIPOT12_ADDR_BIT_SCALE_EXIT 0x00
136 #define DIGIPOT12_ADDR_BIT_SCALE_ENTER 0x01
137 #define DIGIPOT12_ADDR_BIT_SW_SHDN_MODE_NORMAL 0x00
138 #define DIGIPOT12_ADDR_BIT_SW_SHDN_MODE_SHDN 0x01
139 
140  // digipot12_mask
142 
157 #define DIGIPOT12_CTRL_REG_WIPER_POS_FROZEN 0x00
158 #define DIGIPOT12_CTRL_REG_UPDATE_WIPER_POS 0x01
159 #define DIGIPOT12_CTRL_REG_EEPROM_PROGRAM_DISABLE 0x00
160 #define DIGIPOT12_CTRL_REG_EEPROM_PROGRAM_ENABLE 0x02
161 #define DIGIPOT12_CTRL_REG_MODE_POTENTIOMETER 0x00
162 #define DIGIPOT12_CTRL_REG_MODE_LINEAR_GAIN 0x04
163 #define DIGIPOT12_CTRL_REG_MODE_BURST_DISABLE 0x00
164 #define DIGIPOT12_CTRL_REG_MODE_BURST_ENABLE 0x08
165 
170 #define DIGIPOT12_WIPER_POS_MAX 255
171 #define DIGIPOT12_WIPER_POS_MIN 0
172 #define DIGIPOT12_WIPER_POS_MIDDLE 127
173 #define DIGIPOT12_RES_10_KOHM 10
174 #define DIGIPOT12_RES_0_KOHM 0
175 
181 #define DIGIPOT12_DEVICE_ADDRESS_0 0x2F
182 #define DIGIPOT12_DEVICE_ADDRESS_1 0x2C
183 #define DIGIPOT12_DEVICE_ADDRESS_2 0x23
184 #define DIGIPOT12_DEVICE_ADDRESS_3 0x20
185  // digipot12_set
187 
202 #define DIGIPOT12_MAP_MIKROBUS( cfg, mikrobus ) \
203  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
204  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
205  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
206  // digipot12_map // digipot12
209 
214 typedef struct
215 {
216  // Output pins
217  digital_out_t rst;
219  // Modules
220  i2c_master_t i2c;
222  // I2C slave address
223  uint8_t slave_address;
225 } digipot12_t;
226 
231 typedef struct
232 {
233  pin_name_t scl;
234  pin_name_t sda;
236  pin_name_t rst;
238  uint32_t i2c_speed;
239  uint8_t i2c_address;
242 
247 typedef enum
248 {
250  DIGIPOT12_ERROR = -1
251 
253 
270 
285 
299 
313 
327 
342 err_t digipot12_write_data ( digipot12_t *ctx, uint8_t ctrl, uint8_t addr, uint8_t data_in );
343 
358 err_t digipot12_read_data ( digipot12_t *ctx, uint8_t addr, uint8_t mask, uint8_t *data_out );
359 
374 err_t digipot12_write_rdac ( digipot12_t *ctx, uint8_t addr, uint8_t data_in );
375 
390 err_t digipot12_read_rdac ( digipot12_t *ctx, uint8_t addr, uint8_t *data_out );
391 
405 err_t digipot12_set_wiper_1 ( digipot12_t *ctx, uint8_t wiper_pos );
406 
420 err_t digipot12_set_wiper_2 ( digipot12_t *ctx, uint8_t wiper_pos );
421 
436 err_t digipot12_set_resistance ( digipot12_t *ctx, uint8_t wiper_sel, float res_kohm );
437 
452 err_t digipot12_get_resistance ( digipot12_t *ctx, uint8_t wiper_sel, float *res_kohm );
453 
454 #ifdef __cplusplus
455 }
456 #endif
457 #endif // DIGIPOT12_H
458  // digipot12
460 
461 // ------------------------------------------------------------------------ END
digipot12_t::rst
digital_out_t rst
Definition: digipot12.h:217
digipot12_set_wiper_2
err_t digipot12_set_wiper_2(digipot12_t *ctx, uint8_t wiper_pos)
DIGI POT 12 set wiper 2 function.
digipot12_t::slave_address
uint8_t slave_address
Definition: digipot12.h:223
digipot12_cfg_setup
void digipot12_cfg_setup(digipot12_cfg_t *cfg)
DIGI POT 12 configuration object setup function.
DIGIPOT12_ERROR
@ DIGIPOT12_ERROR
Definition: digipot12.h:250
digipot12_device_enable
void digipot12_device_enable(digipot12_t *ctx)
DIGI POT 12 enable the device function.
digipot12_init
err_t digipot12_init(digipot12_t *ctx, digipot12_cfg_t *cfg)
DIGI POT 12 initialization function.
digipot12_read_rdac
err_t digipot12_read_rdac(digipot12_t *ctx, uint8_t addr, uint8_t *data_out)
DIGI POT 12 read the RDAC function.
digipot12_return_value_t
digipot12_return_value_t
DIGI POT 12 Click return value data.
Definition: digipot12.h:248
digipot12_get_resistance
err_t digipot12_get_resistance(digipot12_t *ctx, uint8_t wiper_sel, float *res_kohm)
DIGI POT 12 get the resistance function.
digipot12_hw_reset
void digipot12_hw_reset(digipot12_t *ctx)
DIGI POT 12 hardware reset function.
digipot12_default_cfg
err_t digipot12_default_cfg(digipot12_t *ctx)
DIGI POT 12 default configuration function.
digipot12_write_data
err_t digipot12_write_data(digipot12_t *ctx, uint8_t ctrl, uint8_t addr, uint8_t data_in)
DIGI POT 12 I2C writing function.
digipot12_cfg_t::sda
pin_name_t sda
Definition: digipot12.h:234
digipot12_cfg_t::scl
pin_name_t scl
Definition: digipot12.h:233
DIGIPOT12_OK
@ DIGIPOT12_OK
Definition: digipot12.h:249
digipot12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: digipot12.h:238
digipot12_cfg_t::rst
pin_name_t rst
Definition: digipot12.h:236
digipot12_cfg_t::i2c_address
uint8_t i2c_address
Definition: digipot12.h:239
digipot12_set_resistance
err_t digipot12_set_resistance(digipot12_t *ctx, uint8_t wiper_sel, float res_kohm)
DIGI POT 12 set the resistance function.
digipot12_t
DIGI POT 12 Click context object.
Definition: digipot12.h:215
digipot12_cfg_t
DIGI POT 12 Click configuration object.
Definition: digipot12.h:232
digipot12_t::i2c
i2c_master_t i2c
Definition: digipot12.h:220
digipot12_read_data
err_t digipot12_read_data(digipot12_t *ctx, uint8_t addr, uint8_t mask, uint8_t *data_out)
DIGI POT 12 I2C reading function.
digipot12_set_wiper_1
err_t digipot12_set_wiper_1(digipot12_t *ctx, uint8_t wiper_pos)
DIGI POT 12 set wiper 1 function.
digipot12_write_rdac
err_t digipot12_write_rdac(digipot12_t *ctx, uint8_t addr, uint8_t data_in)
DIGI POT 12 write the RDAC function.