digipot7  2.0.0.0
digipot7.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 DIGIPOT7_H
29 #define DIGIPOT7_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 
64 #define DIGIPOT7_COMMAND_NOP 0x00
65 #define DIGIPOT7_COMMAND_WRITE_RDAC 0x04
66 #define DIGIPOT7_COMMAND_READ_RDAC 0x08
67 #define DIGIPOT7_COMMAND_STORE_WIPER 0x0C
68 #define DIGIPOT7_COMMAND_SW_RESET 0x10
69 #define DIGIPOT7_COMMAND_READ_50TP 0x14
70 #define DIGIPOT7_COMMAND_READ_MEMORY 0x18
71 #define DIGIPOT7_COMMAND_WRITE_MEMORY 0x1C
72 #define DIGIPOT7_COMMAND_READ_CONTROL 0x20
73 #define DIGIPOT7_COMMAND_SW_SHUTDOWN 0x24
74 
79 #define DIGIPOT7_SHUTDOWN_BIT_MASK 0x01
80 #define DIGIPOT7_NORMAL_MODE 0x00
81 #define DIGIPOT7_SHUTDOWN_MODE 0x01
82 
87 #define DIGIPOT7_CTRL_REG_BIT_MASK 0x0B
88 #define DIGIPOT7_FUSE_PROGRAM_SUCCESSFUL 0x00
89 #define DIGIPOT7_FUSE_PROGRAM_UNSUCCESSFUL 0x08
90 #define DIGIPOT7_WIPER_POS_FROZEN 0x00
91 #define DIGIPOT7_UPDATE_WIPER_POS 0x02
92 #define DIGIPOT7_50T_PROGRAM_DISABLED 0x00
93 #define DIGIPOT7_50T_PROGRAM_ENABLE 0x01
94 
99 #define DIGIPOT7_10_BIT 0x03FF
100 #define DIGIPOT7_DUMMY 0x0000
101 
107 #define DIGIPOT7_I2C_SLAVE_ADDRESS_GND 0x2F
108 #define DIGIPOT7_I2C_SLAVE_ADDRESS_VCC 0x2C
109 #define DIGIPOT7_I2C_SLAVE_ADDRESS_NC 0x2E
110  // digipot7_set
112 
127 #define DIGIPOT7_MAP_MIKROBUS( cfg, mikrobus ) \
128  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
129  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
130  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
131  // digipot7_map // digipot7
134 
139 typedef struct
140 {
141  // Output pins
142  digital_out_t rst;
144  // Modules
145  i2c_master_t i2c;
147  // I2C slave address
148  uint8_t slave_address;
150 } digipot7_t;
151 
156 typedef struct
157 {
158  pin_name_t scl;
159  pin_name_t sda;
161  pin_name_t rst;
163  uint32_t i2c_speed;
164  uint8_t i2c_address;
167 
172 typedef enum
173 {
175  DIGIPOT7_ERROR = -1
176 
178 
197 
213 
225 void digipot7_generic_write ( digipot7_t *ctx, uint8_t cmd, uint16_t data_byte );
226 
239 uint16_t digipot7_generic_read ( digipot7_t *ctx, uint8_t cmd, uint8_t wiper_pos );
240 
252 
264 
276 uint16_t digipot7_read_rdac ( digipot7_t *ctx );
277 
290 void digipot7_write_rdac ( digipot7_t *ctx, uint16_t rdac_data );
291 
306 err_t digipot7_set_resistance ( digipot7_t *ctx, uint16_t res_ohm );
307 
319 
331 
343 void digipot7_operating_mode ( digipot7_t *ctx, uint8_t mode );
344 
356 uint16_t digipot7_next_frame_read ( digipot7_t *ctx, uint8_t wiper_location );
357 
370 
382 
383 #ifdef __cplusplus
384 }
385 #endif
386 #endif // DIGIPOT7_H
387  // digipot7
389 
390 // ------------------------------------------------------------------------ END
digipot7_hw_reset
void digipot7_hw_reset(digipot7_t *ctx)
Hardware reset function.
digipot7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: digipot7.h:163
digipot7_next_frame_read
uint16_t digipot7_next_frame_read(digipot7_t *ctx, uint8_t wiper_location)
Next frame read function.
digipot7_cfg_setup
void digipot7_cfg_setup(digipot7_cfg_t *cfg)
DIGI POT 7 configuration object setup function.
digipot7_cfg_t::rst
pin_name_t rst
Definition: digipot7.h:161
digipot7_sw_reset
void digipot7_sw_reset(digipot7_t *ctx)
Software reset function.
digipot7_read_control
uint8_t digipot7_read_control(digipot7_t *ctx)
Read control register function.
digipot7_enable_write
void digipot7_enable_write(digipot7_t *ctx)
Enable write function.
digipot7_cfg_t
DIGI POT 7 Click configuration object.
Definition: digipot7.h:157
digipot7_generic_write
void digipot7_generic_write(digipot7_t *ctx, uint8_t cmd, uint16_t data_byte)
DIGI POT 7 I2C writing function.
digipot7_t
DIGI POT 7 Click context object.
Definition: digipot7.h:140
digipot7_t::i2c
i2c_master_t i2c
Definition: digipot7.h:145
digipot7_cfg_t::sda
pin_name_t sda
Definition: digipot7.h:159
digipot7_init
err_t digipot7_init(digipot7_t *ctx, digipot7_cfg_t *cfg)
DIGI POT 7 initialization function.
DIGIPOT7_OK
@ DIGIPOT7_OK
Definition: digipot7.h:174
digipot7_operating_mode
void digipot7_operating_mode(digipot7_t *ctx, uint8_t mode)
Set operating mode function.
digipot7_write_rdac
void digipot7_write_rdac(digipot7_t *ctx, uint16_t rdac_data)
Write RDAC function.
digipot7_t::rst
digital_out_t rst
Definition: digipot7.h:142
DIGIPOT7_ERROR
@ DIGIPOT7_ERROR
Definition: digipot7.h:175
digipot7_return_value_t
digipot7_return_value_t
DIGI POT 7 Click return value data.
Definition: digipot7.h:173
digipot7_read_rdac
uint16_t digipot7_read_rdac(digipot7_t *ctx)
Read RDAC function.
digipot7_set_resistance
err_t digipot7_set_resistance(digipot7_t *ctx, uint16_t res_ohm)
Set resistance function.
digipot7_t::slave_address
uint8_t slave_address
Definition: digipot7.h:148
digipot7_generic_read
uint16_t digipot7_generic_read(digipot7_t *ctx, uint8_t cmd, uint8_t wiper_pos)
DIGI POT 7 I2C reading function.
digipot7_store_wiper
void digipot7_store_wiper(digipot7_t *ctx)
Store wiper setting function.
digipot7_cfg_t::i2c_address
uint8_t i2c_address
Definition: digipot7.h:164
digipot7_cfg_t::scl
pin_name_t scl
Definition: digipot7.h:158
digipot7_read_memory
uint16_t digipot7_read_memory(digipot7_t *ctx)
Read memory function.