pac1720  2.0.0.0
pac1720.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 PAC1720_H
29 #define PAC1720_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 
59 #define PAC1720_REG_CONFIG 0x00
60 #define PAC1720_REG_CONVERSION_RATE 0x01
61 #define PAC1720_REG_ONE_SHOT 0x02
62 #define PAC1720_REG_CHANNEL_MASK 0x03
63 #define PAC1720_REG_HIGH_LIMIT_STATUS 0x04
64 #define PAC1720_REG_LOW_LIMIT_STATUS 0x05
65 #define PAC1720_REG_VSOURCE_CONFIG 0x0A
66 #define PAC1720_REG_CH1_VSENSE_CONFIG 0x0B
67 #define PAC1720_REG_CH2_VSENSE_CONFIG 0x0C
68 #define PAC1720_REG_CH1_VSENSE_HIGH_BYTE 0x0D
69 #define PAC1720_REG_CH1_VSENSE_LOW_BYTE 0x0E
70 #define PAC1720_REG_CH2_VSENSE_HIGH_BYTE 0x0F
71 #define PAC1720_REG_CH2_VSENSE_LOW_BYTE 0x10
72 #define PAC1720_REG_CH1_VSOURCE_HIGH_BYTE 0x11
73 #define PAC1720_REG_CH1_VSOURCE_LOW_BYTE 0x12
74 #define PAC1720_REG_CH2_VSOURCE_HIGH_BYTE 0x13
75 #define PAC1720_REG_CH2_VSOURCE_LOW_BYTE 0x14
76 #define PAC1720_REG_CH1_POWER_RATIO_HIGH_BYTE 0x15
77 #define PAC1720_REG_CH1_POWER_RATIO_LOW_BYTE 0x16
78 #define PAC1720_REG_CH2_POWER_RATIO_HIGH_BYTE 0x17
79 #define PAC1720_REG_CH2_POWER_RATIO_LOW_BYTE 0x18
80 #define PAC1720_REG_CH1_VSENSE_HIGH_LIMIT 0x19
81 #define PAC1720_REG_CH2_VSENSE_HIGH_LIMIT 0x1A
82 #define PAC1720_REG_CH1_VSENSE_LOW_LIMIT 0x1B
83 #define PAC1720_REG_CH2_VSENSE_LOW_LIMIT 0x1C
84 #define PAC1720_REG_CH1_VSOURCE_HIGH_LIMIT 0x1D
85 #define PAC1720_REG_CH2_VSOURCE_HIGH_LIMIT 0x1E
86 #define PAC1720_REG_CH1_VSOURCE_LOW_LIMIT 0x1F
87 #define PAC1720_REG_CH2_VSOURCE_LOW_LIMIT 0x20
88 #define PAC1720_REG_PRODUCT_ID 0xFD
89 #define PAC1720_REG_MANUFACTURER_ID 0xFE
90 #define PAC1720_REG_REVISION 0xFF
91  // pac1720_reg
93 
108 #define PAC1720_MAX_VOLTAGE 40.0
109 #define PAC1720_CURRENT_SENSE_RANGE_V 0.010
110 #define PAC1720_RSENSE_OHM 0.004
111 #define PAC1720_POWER_RATIO_RESOLUTION 65535
112 
117 #define PAC1720_PRODUCT_ID 0x57
118 
124 #define PAC1720_SET_DEV_ADDR_SEL_0_OHM 0x4C
125 #define PAC1720_SET_DEV_ADDR_SEL_100_OHM 0x4D
126 #define PAC1720_SET_DEV_ADDR_SEL_180_OHM 0x4E
127 #define PAC1720_SET_DEV_ADDR_SEL_300_OHM 0x4F
128 #define PAC1720_SET_DEV_ADDR_SEL_430_OHM 0x48
129 #define PAC1720_SET_DEV_ADDR_SEL_560_OHM 0x49
130 #define PAC1720_SET_DEV_ADDR_SEL_750_OHM 0x4A
131 #define PAC1720_SET_DEV_ADDR_SEL_1270_OHM 0x4B
132 #define PAC1720_SET_DEV_ADDR_SEL_1600_OHM 0x28
133 #define PAC1720_SET_DEV_ADDR_SEL_2000_OHM 0x29
134 #define PAC1720_SET_DEV_ADDR_SEL_2700_OHM 0x2A
135 #define PAC1720_SET_DEV_ADDR_SEL_3600_OHM 0x2B
136 #define PAC1720_SET_DEV_ADDR_SEL_5600_OHM 0x2C
137 #define PAC1720_SET_DEV_ADDR_SEL_9100_OHM 0x2D
138 #define PAC1720_SET_DEV_ADDR_SEL_20000_OHM 0x2E
139 #define PAC1720_SET_DEV_ADDR_SEL_OPEN 0x18
140  // pac1720_set
142 
157 #define PAC1720_MAP_MIKROBUS( cfg, mikrobus ) \
158  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
159  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
160  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
161  // pac1720_map // pac1720
164 
169 typedef struct
170 {
171  // Input pins
172  digital_in_t int_pin;
174  // Modules
175  i2c_master_t i2c;
177  // I2C slave address
178  uint8_t slave_address;
180  uint8_t ch1_vsrc_cfg;
181  uint8_t ch1_vsense_cfg;
182 
183  uint8_t ch2_vsrc_cfg;
184  uint8_t ch2_vsense_cfg;
185 
186 } pac1720_t;
187 
192 typedef struct
193 {
194  pin_name_t scl;
195  pin_name_t sda;
197  pin_name_t int_pin;
199  uint32_t i2c_speed;
200  uint8_t i2c_address;
202 } pac1720_cfg_t;
203 
208 typedef enum
209 {
211  PAC1720_ERROR = -1
212 
214 
219 typedef enum
220 {
223 
225 
231 typedef enum
232 {
241 
243 
248 typedef enum
249 {
254 
256 
261 typedef enum
262 {
267 
269 
286 
301 err_t pac1720_init ( pac1720_t *ctx, pac1720_cfg_t *cfg );
302 
317 
333 err_t pac1720_write_block ( pac1720_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
334 
350 err_t pac1720_read_block ( pac1720_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
351 
365 err_t pac1720_write_byte ( pac1720_t *ctx, uint8_t reg, uint8_t data_in );
366 
380 err_t pac1720_read_byte ( pac1720_t *ctx, uint8_t reg, uint8_t *data_out );
381 
395 err_t pac1720_set_address_pointer ( pac1720_t *ctx, uint8_t reg );
396 
410 err_t pac1720_read_last_accessed_register ( pac1720_t *ctx, uint8_t *data_out );
411 
424 err_t pac1720_set_slave_address ( pac1720_t *ctx, uint8_t slave_address );
425 
435 
448 
469 
491  pac1720_avg_t avg, pac1720_cs_rng_t cs_rng );
492 
511  float *voltage, float *current, float *power );
512 
513 #ifdef __cplusplus
514 }
515 #endif
516 #endif // PAC1720_H
517  // pac1720
519 
520 // ------------------------------------------------------------------------ END
PAC1720_SAMPLE_TIME_2p5mS
@ PAC1720_SAMPLE_TIME_2p5mS
Definition: pac1720.h:233
PAC1720_OK
@ PAC1720_OK
Definition: pac1720.h:210
pac1720_cfg_t
PAC1720 Click configuration object.
Definition: pac1720.h:193
pac1720_read_byte
err_t pac1720_read_byte(pac1720_t *ctx, uint8_t reg, uint8_t *data_out)
PAC1720 read byte function.
pac1720_t::ch2_vsense_cfg
uint8_t ch2_vsense_cfg
Definition: pac1720.h:184
pac1720_check_communication
err_t pac1720_check_communication(pac1720_t *ctx)
PAC1720 check communication function.
pac1720_set_vsource_config
err_t pac1720_set_vsource_config(pac1720_t *ctx, pac1720_ch_sel_t ch, pac1720_sample_time_t stime, pac1720_avg_t avg)
PAC1720 set vsource config function.
pac1720_cs_rng_t
pac1720_cs_rng_t
PAC1720 current sensing range setting.
Definition: pac1720.h:262
PAC1720_SAMPLE_TIME_5mS
@ PAC1720_SAMPLE_TIME_5mS
Definition: pac1720.h:234
PAC1720_SAMPLE_TIME_160mS
@ PAC1720_SAMPLE_TIME_160mS
Definition: pac1720.h:239
pac1720_t::ch2_vsrc_cfg
uint8_t ch2_vsrc_cfg
Definition: pac1720.h:183
pac1720_get_measurements
err_t pac1720_get_measurements(pac1720_t *ctx, pac1720_ch_sel_t ch, float *voltage, float *current, float *power)
PAC1720 get measurements function.
pac1720_avg_t
pac1720_avg_t
PAC1720 averaging setting.
Definition: pac1720.h:249
pac1720_sample_time_t
pac1720_sample_time_t
PAC1720 sample time setting.
Definition: pac1720.h:232
PAC1720_AVG_4_SAMPLES
@ PAC1720_AVG_4_SAMPLES
Definition: pac1720.h:252
pac1720_set_vsense_config
err_t pac1720_set_vsense_config(pac1720_t *ctx, pac1720_ch_sel_t ch, pac1720_sample_time_t stime, pac1720_avg_t avg, pac1720_cs_rng_t cs_rng)
PAC1720 set vsense config function.
pac1720_read_block
err_t pac1720_read_block(pac1720_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
PAC1720 read block function.
pac1720_t::slave_address
uint8_t slave_address
Definition: pac1720.h:178
pac1720_get_int_pin
uint8_t pac1720_get_int_pin(pac1720_t *ctx)
PAC1720 get int pin function.
pac1720_read_last_accessed_register
err_t pac1720_read_last_accessed_register(pac1720_t *ctx, uint8_t *data_out)
PAC1720 read last accessed register function.
pac1720_t::ch1_vsrc_cfg
uint8_t ch1_vsrc_cfg
Definition: pac1720.h:180
PAC1720_CHANNEL_2
@ PAC1720_CHANNEL_2
Definition: pac1720.h:222
pac1720_cfg_t::int_pin
pin_name_t int_pin
Definition: pac1720.h:197
pac1720_return_value_t
pac1720_return_value_t
PAC1720 Click return value data.
Definition: pac1720.h:209
PAC1720_CS_RANGE_40mV
@ PAC1720_CS_RANGE_40mV
Definition: pac1720.h:265
pac1720_set_address_pointer
err_t pac1720_set_address_pointer(pac1720_t *ctx, uint8_t reg)
PAC1720 set address pointer function.
pac1720_write_block
err_t pac1720_write_block(pac1720_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
PAC1720 write block function.
pac1720_t::i2c
i2c_master_t i2c
Definition: pac1720.h:175
PAC1720_SAMPLE_TIME_10mS
@ PAC1720_SAMPLE_TIME_10mS
Definition: pac1720.h:235
PAC1720_SAMPLE_TIME_320mS
@ PAC1720_SAMPLE_TIME_320mS
Definition: pac1720.h:240
pac1720_init
err_t pac1720_init(pac1720_t *ctx, pac1720_cfg_t *cfg)
PAC1720 initialization function.
PAC1720_AVG_8_SAMPLES
@ PAC1720_AVG_8_SAMPLES
Definition: pac1720.h:253
pac1720_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: pac1720.h:199
pac1720_t::int_pin
digital_in_t int_pin
Definition: pac1720.h:172
PAC1720_SAMPLE_TIME_80mS
@ PAC1720_SAMPLE_TIME_80mS
Definition: pac1720.h:238
PAC1720_AVG_2_SAMPLES
@ PAC1720_AVG_2_SAMPLES
Definition: pac1720.h:251
pac1720_cfg_setup
void pac1720_cfg_setup(pac1720_cfg_t *cfg)
PAC1720 configuration object setup function.
pac1720_cfg_t::sda
pin_name_t sda
Definition: pac1720.h:195
pac1720_cfg_t::scl
pin_name_t scl
Definition: pac1720.h:194
PAC1720_CS_RANGE_20mV
@ PAC1720_CS_RANGE_20mV
Definition: pac1720.h:264
pac1720_set_slave_address
err_t pac1720_set_slave_address(pac1720_t *ctx, uint8_t slave_address)
PAC1720 set slave address function.
pac1720_t
PAC1720 Click context object.
Definition: pac1720.h:170
PAC1720_SAMPLE_TIME_40mS
@ PAC1720_SAMPLE_TIME_40mS
Definition: pac1720.h:237
PAC1720_CHANNEL_1
@ PAC1720_CHANNEL_1
Definition: pac1720.h:221
pac1720_cfg_t::i2c_address
uint8_t i2c_address
Definition: pac1720.h:200
PAC1720_CS_RANGE_80mV
@ PAC1720_CS_RANGE_80mV
Definition: pac1720.h:266
PAC1720_ERROR
@ PAC1720_ERROR
Definition: pac1720.h:211
PAC1720_SAMPLE_TIME_20mS
@ PAC1720_SAMPLE_TIME_20mS
Definition: pac1720.h:236
pac1720_t::ch1_vsense_cfg
uint8_t ch1_vsense_cfg
Definition: pac1720.h:181
PAC1720_CS_RANGE_10mV
@ PAC1720_CS_RANGE_10mV
Definition: pac1720.h:263
pac1720_write_byte
err_t pac1720_write_byte(pac1720_t *ctx, uint8_t reg, uint8_t data_in)
PAC1720 write byte function.
pac1720_default_cfg
err_t pac1720_default_cfg(pac1720_t *ctx)
PAC1720 default configuration function.
PAC1720_AVG_DISABLE
@ PAC1720_AVG_DISABLE
Definition: pac1720.h:250
pac1720_ch_sel_t
pac1720_ch_sel_t
PAC1720 channel selection.
Definition: pac1720.h:220