efuse2  2.0.0.0
efuse2.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2021 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 EFUSE2_H
29 #define EFUSE2_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 EFUSE2_AD5175_SHUTDOWN_BIT_MASK 0x01
74 #define EFUSE2_AD5175_NORMAL_MODE 0x00
75 #define EFUSE2_AD5175_SHUTDOWN_MODE 0x01
76 
81 #define EFUSE2_AD5175_CTRL_REG_BIT_MASK 0x0B
82 #define EFUSE2_AD5175_FUSE_PROGRAM_SUCCESSFUL 0x00
83 #define EFUSE2_AD5175_FUSE_PROGRAM_UNSUCCESSFUL 0x08
84 #define EFUSE2_AD5175_WIPER_POS_FROZEN 0x00
85 #define EFUSE2_AD5175_UPDATE_WIPER_POS 0x02
86 #define EFUSE2_AD5175_50T_PROGRAM_DISABLED 0x00
87 #define EFUSE2_AD5175_50T_PROGRAM_ENABLE 0x01
88 
93 #define EFUSE2_AD5175_COMMAND_NOP 0x00
94 #define EFUSE2_AD5175_COMMAND_WRITE_RDAC 0x04
95 #define EFUSE2_AD5175_COMMAND_READ_RDAC 0x08
96 #define EFUSE2_AD5175_COMMAND_STORE_WIPER 0x0C
97 #define EFUSE2_AD5175_COMMAND_SW_RESET 0x10
98 #define EFUSE2_AD5175_COMMAND_READ_50TP 0x14
99 #define EFUSE2_AD5175_COMMAND_READ_MEMORY 0x18
100 #define EFUSE2_AD5175_COMMAND_WRITE_MEMORY 0x1C
101 #define EFUSE2_AD5175_COMMAND_READ_CONTROL 0x20
102 #define EFUSE2_AD5175_COMMAND_SW_SHUTDOWN 0x24
103 
104 #define EFUSE2_AD5241_RDAC0 0x00
105 #define EFUSE2_AD5241_RDAC1 0x80
106 #define EFUSE2_AD5241_NO_RESET 0x00
107 #define EFUSE2_AD5241_RESET 0x40
108 #define EFUSE2_AD5241_NO_SHUTDOWN 0x00
109 #define EFUSE2_AD5241_SHUTDOWN 0x20
110 #define EFUSE2_AD5241_O1_LOW 0x00
111 #define EFUSE2_AD5241_O1_HIGH 0x10
112 #define EFUSE2_AD5241_O2_LOW 0x00
113 #define EFUSE2_AD5241_O2_HIGH 0x08
114 
120 #define EFUSE2_I2C_SLAVE_ADDRESS_AD5241_0 0x2C
121 #define EFUSE2_I2C_SLAVE_ADDRESS_AD5241_1 0x2D
122 #define EFUSE2_I2C_SLAVE_ADDRESS_AD5241_2 0x2E
123 #define EFUSE2_I2C_SLAVE_ADDRESS_AD5241_3 0x2F
124 #define EFUSE2_I2C_SLAVE_ADDRESS_AD5175_GND 0x2F
125 #define EFUSE2_I2C_SLAVE_ADDRESS_AD5175_VCC 0x2C
126 #define EFUSE2_I2C_SLAVE_ADDRESS_AD5175_NC 0x2E
127 
132 #define EFUSE2_FAULT 0x00
133 #define EFUSE2_NO_FAULT 0x01
134 
139 #define EFUSE2_10_BIT 0x03FF
140 #define EFUSE2_DUMMY 0x0000
141 
142  // efuse2_set
144 
159 #define EFUSE2_MAP_MIKROBUS( cfg, mikrobus ) \
160  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
161  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
162  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
163  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
164  // efuse2_map // efuse2
167 
172 typedef struct
173 {
174  // Output pins
175  digital_out_t rst;
177  // Input pins
178  digital_in_t flt;
180  // Modules
181  i2c_master_t i2c;
183  // I2C slave address
187 } efuse2_t;
188 
193 typedef struct
194 {
195  pin_name_t scl;
196  pin_name_t sda;
198  pin_name_t rst;
199  pin_name_t flt;
201  uint32_t i2c_speed;
205 } efuse2_cfg_t;
206 
211 typedef struct
212 {
213  uint8_t select_rdac;
214  uint8_t midscale_reset;
218 
220 
225 typedef enum
226 {
228  EFUSE2_ERROR = -1
229 
231 
248 
261 err_t efuse2_init ( efuse2_t *ctx, efuse2_cfg_t *cfg );
262 
276 
290 err_t efuse2_write_ad5241 ( efuse2_t *ctx, ad5241_instru_t cmd, uint8_t data_byte );
291 
301 uint8_t efuse2_read_ad5241 ( efuse2_t *ctx );
302 
312 void efuse2_hw_reset ( efuse2_t *ctx );
313 
328 err_t efuse2_set_operating_voltage ( efuse2_t *ctx, float voltage, float *min_voltage, float *max_voltage );
342 err_t efuse2_write_ad5175 ( efuse2_t *ctx, uint8_t cmd, uint16_t data_byte );
343 
365 uint16_t efuse2_read_ad5175 ( efuse2_t *ctx, uint8_t cmd, uint8_t wiper_location );
366 
376 uint16_t efuse2_read_rdac ( efuse2_t *ctx );
377 
390 
402 err_t efuse2_write_rdac ( efuse2_t *ctx, uint16_t data_byte );
403 
416 err_t efuse2_set_current_limit ( efuse2_t *ctx, float current );
417 
429 err_t efuse2_sw_reset ( efuse2_t *ctx );
430 
443 
456 err_t efuse2_operating_mode ( efuse2_t *ctx, uint8_t mode );
457 
468 uint16_t efuse2_next_frame_read ( efuse2_t *ctx, uint8_t wiper_location );
469 
480 uint16_t efuse2_read_memory ( efuse2_t *ctx );
481 
494 uint8_t efuse2_read_control ( efuse2_t *ctx );
495 
508 uint8_t efuse2_get_fault ( efuse2_t *ctx );
509 
510 #ifdef __cplusplus
511 }
512 #endif
513 #endif // EFUSE2_H
514  // efuse2
516 
517 // ------------------------------------------------------------------------ END
ad5241_instru_t::select_rdac
uint8_t select_rdac
Definition: efuse2.h:213
efuse2_enable_write
err_t efuse2_enable_write(efuse2_t *ctx)
Enable write function.
efuse2_store_wiper
err_t efuse2_store_wiper(efuse2_t *ctx)
Store wiper setting function.
ad5241_instru_t::midscale_reset
uint8_t midscale_reset
Definition: efuse2.h:214
efuse2_read_ad5241
uint8_t efuse2_read_ad5241(efuse2_t *ctx)
Generic read data from the AD5241 function.
efuse2_cfg_t
eFuse 2 Click configuration object.
Definition: efuse2.h:194
efuse2_cfg_setup
void efuse2_cfg_setup(efuse2_cfg_t *cfg)
eFuse 2 configuration object setup function.
min_voltage
float min_voltage
Definition: main.c:40
efuse2_t::flt
digital_in_t flt
Definition: efuse2.h:178
ad5241_instru_t::output_logic_pin_1
uint8_t output_logic_pin_1
Definition: efuse2.h:216
efuse2_t::slave_address_ad5175
uint8_t slave_address_ad5175
Definition: efuse2.h:184
efuse2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: efuse2.h:201
efuse2_cfg_t::sda
pin_name_t sda
Definition: efuse2.h:196
ad5241_instru_t::active_shutdown
uint8_t active_shutdown
Definition: efuse2.h:215
efuse2_operating_mode
err_t efuse2_operating_mode(efuse2_t *ctx, uint8_t mode)
Set operating mode function.
efuse2_sw_reset
err_t efuse2_sw_reset(efuse2_t *ctx)
Software reset function.
ad5241_instru_t::output_logic_pin_2
uint8_t output_logic_pin_2
Definition: efuse2.h:217
efuse2_cfg_t::rst
pin_name_t rst
Definition: efuse2.h:198
efuse2_default_cfg
err_t efuse2_default_cfg(efuse2_t *ctx)
eFuse 2 default configuration function.
efuse2_t::rst
digital_out_t rst
Definition: efuse2.h:175
EFUSE2_OK
@ EFUSE2_OK
Definition: efuse2.h:227
ad5241_instru_t
eFuse 2 Click instruction object.
Definition: efuse2.h:212
efuse2_cfg_t::scl
pin_name_t scl
Definition: efuse2.h:195
efuse2_t::i2c
i2c_master_t i2c
Definition: efuse2.h:181
efuse2_set_operating_voltage
err_t efuse2_set_operating_voltage(efuse2_t *ctx, float voltage, float *min_voltage, float *max_voltage)
Set operating voltage function.
max_voltage
float max_voltage
Definition: main.c:41
efuse2_cfg_t::i2c_address_ad5241
uint8_t i2c_address_ad5241
Definition: efuse2.h:203
EFUSE2_ERROR
@ EFUSE2_ERROR
Definition: efuse2.h:228
efuse2_cfg_t::i2c_address_ad5175
uint8_t i2c_address_ad5175
Definition: efuse2.h:202
efuse2_next_frame_read
uint16_t efuse2_next_frame_read(efuse2_t *ctx, uint8_t wiper_location)
Next frame read function.
efuse2_get_fault
uint8_t efuse2_get_fault(efuse2_t *ctx)
Get fault function.
efuse2_read_memory
uint16_t efuse2_read_memory(efuse2_t *ctx)
Read memory function.
efuse2_write_rdac
err_t efuse2_write_rdac(efuse2_t *ctx, uint16_t data_byte)
Write RDAC function.
efuse2_return_value_t
efuse2_return_value_t
eFuse 2 Click return value data.
Definition: efuse2.h:226
efuse2_cfg_t::flt
pin_name_t flt
Definition: efuse2.h:199
efuse2_hw_reset
void efuse2_hw_reset(efuse2_t *ctx)
Hardware reset function.
efuse2_read_control
uint8_t efuse2_read_control(efuse2_t *ctx)
Read control register function.
efuse2_t::slave_address_ad5241
uint8_t slave_address_ad5241
Definition: efuse2.h:185
efuse2_init
err_t efuse2_init(efuse2_t *ctx, efuse2_cfg_t *cfg)
eFuse 2 initialization function.
efuse2_t
eFuse 2 Click context object.
Definition: efuse2.h:173
efuse2_write_ad5241
err_t efuse2_write_ad5241(efuse2_t *ctx, ad5241_instru_t cmd, uint8_t data_byte)
Generic write data to the AD5241 function.
efuse2_read_ad5175
uint16_t efuse2_read_ad5175(efuse2_t *ctx, uint8_t cmd, uint8_t wiper_location)
Generic read data from the AD5175 function.
efuse2_set_current_limit
err_t efuse2_set_current_limit(efuse2_t *ctx, float current)
Set operating current function.
efuse2_write_ad5175
err_t efuse2_write_ad5175(efuse2_t *ctx, uint8_t cmd, uint16_t data_byte)
Generic write data to the AD5175 function.
efuse2_read_rdac
uint16_t efuse2_read_rdac(efuse2_t *ctx)
Read RDAC function.