currentlimit7 2.0.0.0
currentlimit7.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 CURRENTLIMIT7_H
29#define CURRENTLIMIT7_H
30
31#ifdef __cplusplus
32extern "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 CURRENTLIMIT7_CMD_NOP 0x00
74#define CURRENTLIMIT7_CMD_WRITE_RDAC 0x04
75#define CURRENTLIMIT7_CMD_READ_RDAC 0x08
76#define CURRENTLIMIT7_CMD_STORE_WIPER 0x0C
77#define CURRENTLIMIT7_CMD_SW_RESET 0x10
78#define CURRENTLIMIT7_CMD_READ_CONTENTS 0x14
79#define CURRENTLIMIT7_CMD_READ_MEMORY 0x18
80#define CURRENTLIMIT7_CMD_WRITE_MEMORY 0x1C
81#define CURRENTLIMIT7_CMD_READ_CTRL 0x20
82#define CURRENTLIMIT7_CMD_SW_SHUTDOWN 0x24
83
84 // currentlimit7_cmd
85
100#define CURRENTLIMIT7_OP_0_CURRENT_LIMIT_260_mA 260
101#define CURRENTLIMIT7_OP_0_CURRENT_LIMIT_280_mA 280
102#define CURRENTLIMIT7_OP_0_CURRENT_LIMIT_330_mA 330
103#define CURRENTLIMIT7_OP_0_CURRENT_LIMIT_450_mA 450
104#define CURRENTLIMIT7_OP_0_CURRENT_LIMIT_510_mA 510
105#define CURRENTLIMIT7_OP_1_CURRENT_LIMIT_510_mA 510
106#define CURRENTLIMIT7_OP_1_CURRENT_LIMIT_625_mA 625
107#define CURRENTLIMIT7_OP_1_CURRENT_LIMIT_860_mA 860
108#define CURRENTLIMIT7_OP_1_CURRENT_LIMIT_1320_mA 1320
109#define CURRENTLIMIT7_OP_1_CURRENT_LIMIT_1450_mA 1450
110#define CURRENTLIMIT7_OP_1_CURRENT_LIMIT_1550_mA 1550
111#define CURRENTLIMIT7_OP_1_CURRENT_LIMIT_1750_mA 1750
112#define CURRENTLIMIT7_OP_1_CURRENT_LIMIT_2020_mA 2020
113#define CURRENTLIMIT7_OP_1_CURRENT_LIMIT_2260_mA 2260
114#define CURRENTLIMIT7_OP_1_CURRENT_LIMIT_2500_mA 2500
115
120#define CURRENTLIMIT7_SET_SHUTDOWN_BIT_MASK 0x01
121#define CURRENTLIMIT7_SET_NORMAL_MODE 0x00
122#define CURRENTLIMIT7_SET_SHUTDOWN_MODE 0x01
123#define CURRENTLIMIT7_SET_ENABLE_WRITE_MEMORY 0x0002
124
129#define CURRENTLIMIT7_OP_MODE_500_mA_2500_mA 0x00
130#define CURRENTLIMIT7_OP_MODE_250_mA_500_mA 0x01
131
137#define CURRENTLIMIT7_SET_DEV_ADDR_0 0x2E
138#define CURRENTLIMIT7_SET_DEV_ADDR_1 0x2C
139
140 // currentlimit7_set
141
156#define CURRENTLIMIT7_MAP_MIKROBUS( cfg, mikrobus ) \
157 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
158 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
159 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
160 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
161 cfg.flg = MIKROBUS( mikrobus, MIKROBUS_INT )
162
163 // currentlimit7_map
164 // currentlimit7
165
170typedef struct
171{
172 // Output pins
173 digital_out_t en;
174 digital_out_t rst;
176 // Input pins
177 digital_in_t flg;
179 // Modules
180 i2c_master_t i2c;
182 // I2C slave address
186
191typedef struct
192{
193 pin_name_t scl;
194 pin_name_t sda;
196 pin_name_t en;
197 pin_name_t rst;
198 pin_name_t flg;
200 uint32_t i2c_speed;
201 uint8_t i2c_address;
204
215
232
248
263
277err_t currentlimit7_set_slave_address ( currentlimit7_t *ctx, uint16_t slave_address );
278
294
309
324
339err_t currentlimit7_generic_write ( currentlimit7_t *ctx, uint8_t cmd, uint16_t data_byte );
340
356err_t currentlimit7_generic_read ( currentlimit7_t *ctx, uint8_t cmd, uint16_t data_byte, uint16_t *data_out );
357
373
389err_t currentlimit7_write_rdac ( currentlimit7_t *ctx, uint16_t data_in );
390
406err_t currentlimit7_read_rdac ( currentlimit7_t *ctx, uint16_t *data_out );
407
423
439
456err_t currentlimit7_next_frame_read ( currentlimit7_t *ctx, uint8_t wiper_location, uint16_t *data_out );
457
474err_t currentlimit7_read_memory ( currentlimit7_t *ctx, uint8_t wiper_location, uint16_t *data_out );
475
492
508err_t currentlimit7_set_digi_pot ( currentlimit7_t *ctx, uint16_t wiper_pos );
509
525err_t currentlimit7_set_resistance ( currentlimit7_t *ctx, uint32_t res_ohm );
526
545err_t currentlimit7_set_current_limit ( currentlimit7_t *ctx, uint8_t op_mode, uint16_t current_limit_ma );
546
562
563
564
565#ifdef __cplusplus
566}
567#endif
568#endif // CURRENTLIMIT7_H
569
570 // currentlimit7
571
572// ------------------------------------------------------------------------ END
currentlimit7_return_value_t
Current Limit 7 Click return value data.
Definition currentlimit7.h:210
@ CURRENTLIMIT7_OK
Definition currentlimit7.h:211
@ CURRENTLIMIT7_ERROR
Definition currentlimit7.h:212
err_t currentlimit7_hw_reset(currentlimit7_t *ctx)
Current Limit 7 hardware reset function.
err_t currentlimit7_set_resistance(currentlimit7_t *ctx, uint32_t res_ohm)
Current Limit 7 set resistance function.
err_t currentlimit7_store_wiper(currentlimit7_t *ctx)
Current Limit 7 store wiper function.
err_t currentlimit7_enable_write(currentlimit7_t *ctx)
Current Limit 7 enable write function.
void currentlimit7_cfg_setup(currentlimit7_cfg_t *cfg)
Current Limit 7 configuration object setup function.
err_t currentlimit7_set_digi_pot(currentlimit7_t *ctx, uint16_t wiper_pos)
Current Limit 7 set DIGI POT function.
uint8_t currentlimit7_get_fault(currentlimit7_t *ctx)
Current Limit 7 get fault function.
err_t currentlimit7_set_current_limit(currentlimit7_t *ctx, uint8_t op_mode, uint16_t current_limit_ma)
Current Limit 7 set current limit function.
err_t currentlimit7_sw_reset(currentlimit7_t *ctx)
Current Limit 7 software reset function.
err_t currentlimit7_write_rdac(currentlimit7_t *ctx, uint16_t data_in)
Current Limit 7 write RDAC function.
err_t currentlimit7_default_cfg(currentlimit7_t *ctx)
Current Limit 7 default configuration function.
err_t currentlimit7_operating_mode(currentlimit7_t *ctx, uint8_t mode)
Current Limit 7 set operating mode function.
err_t currentlimit7_next_frame_read(currentlimit7_t *ctx, uint8_t wiper_location, uint16_t *data_out)
Current Limit 7 next frame read function.
err_t currentlimit7_set_disable(currentlimit7_t *ctx)
Current Limit 7 disable the device function.
err_t currentlimit7_read_rdac(currentlimit7_t *ctx, uint16_t *data_out)
Current Limit 7 read RDAC function.
err_t currentlimit7_init(currentlimit7_t *ctx, currentlimit7_cfg_t *cfg)
Current Limit 7 initialization function.
err_t currentlimit7_set_enable(currentlimit7_t *ctx)
Current Limit 7 enable the device function.
err_t currentlimit7_generic_write(currentlimit7_t *ctx, uint8_t cmd, uint16_t data_byte)
Current Limit 7 I2C writing function.
err_t currentlimit7_generic_read(currentlimit7_t *ctx, uint8_t cmd, uint16_t data_byte, uint16_t *data_out)
Current Limit 7 I2C reading function.
err_t currentlimit7_set_slave_address(currentlimit7_t *ctx, uint16_t slave_address)
Current Limit 7 set I2C Slave address.
err_t currentlimit7_read_memory(currentlimit7_t *ctx, uint8_t wiper_location, uint16_t *data_out)
Current Limit 7 read memory function.
Current Limit 7 Click configuration object.
Definition currentlimit7.h:192
pin_name_t flg
Definition currentlimit7.h:198
uint32_t i2c_speed
Definition currentlimit7.h:200
pin_name_t scl
Definition currentlimit7.h:193
pin_name_t en
Definition currentlimit7.h:196
pin_name_t sda
Definition currentlimit7.h:194
pin_name_t rst
Definition currentlimit7.h:197
uint8_t i2c_address
Definition currentlimit7.h:201
Current Limit 7 Click context object.
Definition currentlimit7.h:171
digital_in_t flg
Definition currentlimit7.h:177
i2c_master_t i2c
Definition currentlimit7.h:180
digital_out_t en
Definition currentlimit7.h:173
digital_out_t rst
Definition currentlimit7.h:174
uint8_t slave_address
Definition currentlimit7.h:183