pac1944  2.0.0.0
pac1944.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 PAC1944_H
29 #define PAC1944_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 
60 #define PAC1944_REG_REFRESH 0x00
61 #define PAC1944_REG_CTRL 0x01
62 #define PAC1944_REG_ACC_COUNT 0x02
63 #define PAC1944_REG_VACC_CH1 0x03
64 #define PAC1944_REG_VACC_CH2 0x04
65 #define PAC1944_REG_VACC_CH3 0x05
66 #define PAC1944_REG_VACC_CH4 0x06
67 #define PAC1944_REG_VBUS_CH1 0x07
68 #define PAC1944_REG_VBUS_CH2 0x08
69 #define PAC1944_REG_VBUS_CH3 0x09
70 #define PAC1944_REG_VBUS_CH4 0x0A
71 #define PAC1944_REG_VSENSE_CH1 0x0B
72 #define PAC1944_REG_VSENSE_CH2 0x0C
73 #define PAC1944_REG_VSENSE_CH3 0x0D
74 #define PAC1944_REG_VSENSE_CH4 0x0E
75 #define PAC1944_REG_VBUS_CH1_AVG 0x0F
76 #define PAC1944_REG_VBUS_CH2_AVG 0x10
77 #define PAC1944_REG_VBUS_CH3_AVG 0x11
78 #define PAC1944_REG_VBUS_CH4_AVG 0x12
79 #define PAC1944_REG_VSENSE_CH1_AVG 0x13
80 #define PAC1944_REG_VSENSE_CH2_AVG 0x14
81 #define PAC1944_REG_VSENSE_CH3_AVG 0x15
82 #define PAC1944_REG_VSENSE_CH4_AVG 0x16
83 #define PAC1944_REG_VPOWER_CH1 0x17
84 #define PAC1944_REG_VPOWER_CH2 0x18
85 #define PAC1944_REG_VPOWER_CH3 0x19
86 #define PAC1944_REG_VPOWER_CH4 0x1A
87 #define PAC1944_REG_SMBUS_CFG 0x1C
88 #define PAC1944_REG_NEG_PWR_FSR 0x1D
89 #define PAC1944_REG_REFRESH_G 0x1E
90 #define PAC1944_REG_REFRESH_V 0x1F
91 #define PAC1944_REG_SLOW 0x20
92 #define PAC1944_REG_CTRL_ACT 0x21
93 #define PAC1944_REG_NEG_PWR_FSR_ACT 0x22
94 #define PAC1944_REG_CTRL_LAT 0x23
95 #define PAC1944_REG_NEG_PWR_FSR_LAT 0x24
96 #define PAC1944_REG_ACC_CFG 0x25
97 #define PAC1944_REG_ALERT_STATUS 0x26
98 #define PAC1944_REG_SLOW_ALERT1 0x27
99 #define PAC1944_REG_GPIO_ALERT2 0x28
100 #define PAC1944_REG_ACC_FULLNESS_LIM 0x29
101 #define PAC1944_REG_OC_LIM_CH1 0x30
102 #define PAC1944_REG_OC_LIM_CH2 0x31
103 #define PAC1944_REG_OC_LIM_CH3 0x32
104 #define PAC1944_REG_OC_LIM_CH4 0x33
105 #define PAC1944_REG_UC_LIM_CH1 0x34
106 #define PAC1944_REG_UC_LIM_CH2 0x35
107 #define PAC1944_REG_UC_LIM_CH3 0x36
108 #define PAC1944_REG_UC_LIM_CH4 0x37
109 #define PAC1944_REG_OP_LIM_CH1 0x38
110 #define PAC1944_REG_OP_LIM_CH2 0x39
111 #define PAC1944_REG_OP_LIM_CH3 0x3A
112 #define PAC1944_REG_OP_LIM_CH4 0x3B
113 #define PAC1944_REG_OV_LIM_CH1 0x3C
114 #define PAC1944_REG_OV_LIM_CH2 0x3D
115 #define PAC1944_REG_OV_LIM_CH3 0x3E
116 #define PAC1944_REG_OV_LIM_CH4 0x3F
117 #define PAC1944_REG_UV_LIM_CH1 0x40
118 #define PAC1944_REG_UV_LIM_CH2 0x41
119 #define PAC1944_REG_UV_LIM_CH3 0x42
120 #define PAC1944_REG_UV_LIM_CH4 0x43
121 #define PAC1944_REG_OC_LIM_NSAMPLES 0x44
122 #define PAC1944_REG_UC_LIM_NSAMPLES 0x45
123 #define PAC1944_REG_OP_LIM_NSAMPLES 0x46
124 #define PAC1944_REG_OV_LIM_NSAMPLES 0x47
125 #define PAC1944_REG_UV_LIM_NSAMPLES 0x48
126 #define PAC1944_REG_ALERT_ENABLE 0x49
127 #define PAC1944_REG_ACC_CFG_ACT 0x4A
128 #define PAC1944_REG_ACC_CFG_LAT 0x4B
129 #define PAC1944_REG_ID_PRODUCT 0xFD
130 #define PAC1944_REG_ID_MANUFACTURER 0xFE
131 #define PAC1944_REG_ID_REVISION 0xFF
132  // pac1944_reg
134 
145 #define PAC1944_MEAS_SEL_V_SOURCE 0
146 #define PAC1944_MEAS_SEL_I_SENSE 1
147 #define PAC1944_MEAS_SEL_P_SENSE 2
148  // meas_sel
150 
161 #define PAC1944_CH_SEL_CH_1 1
162 #define PAC1944_CH_SEL_CH_2 2
163 #define PAC1944_CH_SEL_CH_3 3
164 #define PAC1944_CH_SEL_CH_4 4
165  // ch_sel
167 
178 #define PAC1944_AVG_SEL_DISABLE 0
179 #define PAC1944_AVG_SEL_ENABLE 1
180  // avg_sel
182 
193 #define PAC1944_MEAS_MODE_UNIPOLAR_FSR 0
194 #define PAC1944_MEAS_MODE_BIPOLAR_FSR 1
195 #define PAC1944_MEAS_MODE_BIPOLAR_HALF_FSR 2
196  // meas_mode
198 
209 #define PAC1944_SLOW_STATE_ON 1
210 #define PAC1944_SLOW_STATE_OFF 0
211 
212 #define PAC1944_DEV_ENABLE 1
213 #define PAC1944_DEV_PWR_DWN 0
214 
215 #define PAC1944_ALERT_ACTIVE 0
216 #define PAC1944_ALERT_INACTIVE 1
217  // state
219 
235 #define PAC1944_CTRLH_SPS_1024_ADAPT_ACC 0x00
236 #define PAC1944_CTRLH_SPS_256_ADAPT_ACC 0x10
237 #define PAC1944_CTRLH_SPS_64_ADAPT_ACC 0x20
238 #define PAC1944_CTRLH_SPS_8_ADAPT_ACC 0x30
239 #define PAC1944_CTRLH_SPS_1024 0x40
240 #define PAC1944_CTRLH_SPS_256 0x50
241 #define PAC1944_CTRLH_SPS_64 0x60
242 #define PAC1944_CTRLH_SPS_8 0x70
243 #define PAC1944_CTRLH_SINGLE_SHOT_MODE 0x80
244 #define PAC1944_CTRLH_SINGLE_SHOT_8X 0x90
245 #define PAC1944_CTRLH_FAST_MODE 0xA0
246 #define PAC1944_CTRLH_BURST_MODE 0xB0
247 #define PAC1944_CTRLH_SLEEP 0xF0
248 
249 #define PAC1944_CTRLH_INT_PIN_ALERT 0x00
250 #define PAC1944_CTRLH_INT_PIN_DIG_IN 0x04
251 #define PAC1944_CTRLH_INT_PIN_DIG_OUT 0x08
252 #define PAC1944_CTRLH_INT_PIN_SLOW 0x0C
253 
254 #define PAC1944_CTRLH_SLW_PIN_ALERT 0x00
255 #define PAC1944_CTRLH_SLW_PIN_DIG_IN 0x01
256 #define PAC1944_CTRLH_SLW_PIN_DIG_OUT 0x02
257 #define PAC1944_CTRLH_SLW_PIN_SLOW 0x03
258 
259 #define PAC1944_CTRLL_CH1_OFF 0x80
260 #define PAC1944_CTRLL_CH2_OFF 0x40
261 #define PAC1944_CTRLL_CH3_OFF 0x20
262 #define PAC1944_CTRLL_CH4_OFF 0x10
263 #define PAC1944_CTRLL_ALL_CH_OFF 0xF0
264 #define PAC1944_CTRLL_ALL_CH_ON 0x00
265 
266 #define PAC1944_SMBUS_INT_PIN_MASK 0x80
267 #define PAC1944_SMBUS_SLW_PIN_MASK 0x40
268 #define PAC1944_SMBUS_ALERT_MASK 0x20
269 #define PAC1944_SMBUS_POR_MASK 0x10
270 #define PAC1944_SMBUS_TIMEOUT_OFF 0x00
271 #define PAC1944_SMBUS_TIMEOUT_ON 0x08
272 #define PAC1944_SMBUS_BYTE_COUNT_OFF 0x00
273 #define PAC1944_SMBUS_BYTE_COUNT_ON 0x04
274 #define PAC1944_SMBUS_AUTO_INC_SKIP_ON 0x00
275 #define PAC1944_SMBUS_AUTO_INC_SKIP_OFF 0x02
276 #define PAC1944_SMBUS_I2C_HIGH_SPEED 0x01
277 
284 #define PAC1944_DEVICE_ADDR_GND 0x10
285 #define PAC1944_DEVICE_ADDR_499_OHM 0x11
286 #define PAC1944_DEVICE_ADDR_806_OHM 0x12
287 #define PAC1944_DEVICE_ADDR_1270_OHM 0x13
288 #define PAC1944_DEVICE_ADDR_2050_OHM 0x14
289 #define PAC1944_DEVICE_ADDR_3240_OHM 0x15
290 #define PAC1944_DEVICE_ADDR_5230_OHM 0x16
291 #define PAC1944_DEVICE_ADDR_8450_OHM 0x17
292 #define PAC1944_DEVICE_ADDR_13K3_OHM 0x18
293 #define PAC1944_DEVICE_ADDR_21K5_OHM 0x19
294 #define PAC1944_DEVICE_ADDR_34K_OHM 0x1A
295 #define PAC1944_DEVICE_ADDR_54K9_OHM 0x1B
296 #define PAC1944_DEVICE_ADDR_88K7_OHM 0x1C
297 #define PAC1944_DEVICE_ADDR_140K_OHM 0x1D
298 #define PAC1944_DEVICE_ADDR_226K_OHM 0x1E
299 #define PAC1944_DEVICE_ADDR_VCC 0x1F
300  // pac1944_set
302 
317 #define PAC1944_MAP_MIKROBUS( cfg, mikrobus ) \
318  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
319  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
320  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
321  cfg.slw = MIKROBUS( mikrobus, MIKROBUS_RST ); \
322  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
323  // pac1944_map // pac1944
326 
331 typedef struct
332 {
333  // Output pins
334 
335  digital_out_t en;
336  digital_out_t slw;
338  // Input pins
339 
340  digital_in_t int_pin;
342  // Modules
343 
344  i2c_master_t i2c;
346  // I2C slave address
347 
348  uint8_t slave_address;
350 } pac1944_t;
351 
356 typedef struct
357 {
358  pin_name_t scl;
359  pin_name_t sda;
361  pin_name_t en;
362  pin_name_t slw;
363  pin_name_t int_pin;
365  uint32_t i2c_speed;
366  uint8_t i2c_address;
368 } pac1944_cfg_t;
369 
374 typedef struct
375 {
376  uint8_t sample_mode;
377  uint8_t gpio_alert2;
378  uint8_t slow_alert1;
379  uint8_t channels_state;
380  uint8_t cfg_vsense1;
381  uint8_t cfg_vsense2;
382  uint8_t cfg_vsense3;
383  uint8_t cfg_vsense4;
384  uint8_t cfg_vbus1;
385  uint8_t cfg_vbus2;
386  uint8_t cfg_vbus3;
387  uint8_t cfg_vbus4;
390 
409 
426 err_t pac1944_init ( pac1944_t *ctx, pac1944_cfg_t *cfg );
427 
444 
458 void pac1944_set_slow_state ( pac1944_t *ctx, uint8_t state );
459 
473 void pac1944_device_state ( pac1944_t *ctx, uint8_t state );
474 
488 
506 err_t pac1944_generic_write ( pac1944_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
507 
525 err_t pac1944_generic_read ( pac1944_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
526 
539 
552 void pac1944_set_address_pointer ( pac1944_t *ctx, uint8_t reg_addr );
553 
567 
581 
597 
611 
624 
642 void pac1944_get_accumulator_output( pac1944_t *ctx, uint8_t ch_sel, uint8_t *acc_out );
643 
668 uint32_t pac1944_get_measurement ( pac1944_t *ctx, uint8_t meas_sel, uint8_t ch_sel, uint8_t avg_sel );
669 
698 float pac1944_get_calc_measurement ( pac1944_t *ctx, uint8_t meas_sel, uint8_t ch_sel, uint8_t avg_sel, uint8_t meas_mode );
699 
700 #ifdef __cplusplus
701 }
702 #endif
703 #endif // PAC1944_H
704  // pac1944
706 
707 // ------------------------------------------------------------------------ END
pac1944_t::slave_address
uint8_t slave_address
Definition: pac1944.h:348
pac1944_t
PAC1944 Click context object.
Definition: pac1944.h:332
pac1944_cfg_t::scl
pin_name_t scl
Definition: pac1944.h:358
pac1944_setup_t::cfg_vbus2
uint8_t cfg_vbus2
Definition: pac1944.h:385
pac1944_setup_t::cfg_vsense1
uint8_t cfg_vsense1
Definition: pac1944.h:380
pac1944_t::slw
digital_out_t slw
Definition: pac1944.h:336
pac1944_setup_t::cfg_vsense4
uint8_t cfg_vsense4
Definition: pac1944.h:383
pac1944_set_slow_state
void pac1944_set_slow_state(pac1944_t *ctx, uint8_t state)
PAC1944 set slow state function.
pac1944_setup_t::cfg_vsense2
uint8_t cfg_vsense2
Definition: pac1944.h:381
pac1944_t::int_pin
digital_in_t int_pin
Definition: pac1944.h:340
pac1944_get_accumulator_output
void pac1944_get_accumulator_output(pac1944_t *ctx, uint8_t ch_sel, uint8_t *acc_out)
PAC1944 get accumulator output function.
pac1944_cfg_t::sda
pin_name_t sda
Definition: pac1944.h:359
pac1944_get_alert_state
uint8_t pac1944_get_alert_state(pac1944_t *ctx)
PAC1944 get alert state function.
pac1944_cfg_t::slw
pin_name_t slw
Definition: pac1944.h:362
pac1944_t::i2c
i2c_master_t i2c
Definition: pac1944.h:344
pac1944_device_state
void pac1944_device_state(pac1944_t *ctx, uint8_t state)
PAC1944 set device state function.
pac1944_cfg_t::int_pin
pin_name_t int_pin
Definition: pac1944.h:363
pac1944_setup_t::cfg_vsense3
uint8_t cfg_vsense3
Definition: pac1944.h:382
pac1944_cfg_t
PAC1944 Click configuration object.
Definition: pac1944.h:357
pac1944_volatile_refresh_cmd
void pac1944_volatile_refresh_cmd(pac1944_t *ctx)
PAC1944 volatile refresh command.
pac1944_setup_t::cfg_vbus3
uint8_t cfg_vbus3
Definition: pac1944.h:386
pac1944_general_refresh_cmd
void pac1944_general_refresh_cmd(pac1944_t *ctx)
PAC1944 general refresh command.
pac1944_setup_t::cfg_vbus1
uint8_t cfg_vbus1
Definition: pac1944.h:384
pac1944_get_calc_measurement
float pac1944_get_calc_measurement(pac1944_t *ctx, uint8_t meas_sel, uint8_t ch_sel, uint8_t avg_sel, uint8_t meas_mode)
PAC1944 get calculated measurement function.
pac1944_generic_read
err_t pac1944_generic_read(pac1944_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
PAC1944 I2C reading function.
pac1944_setup_t
PAC1944 Configuration setup structure.
Definition: pac1944.h:375
pac1944_t::en
digital_out_t en
Definition: pac1944.h:335
pac1944_set_address_pointer
void pac1944_set_address_pointer(pac1944_t *ctx, uint8_t reg_addr)
PAC1944 set address pointer function.
pac1944_setup_t::gpio_alert2
uint8_t gpio_alert2
Definition: pac1944.h:377
pac1944_cfg_t::en
pin_name_t en
Definition: pac1944.h:361
pac1944_setup_t::slow_alert1
uint8_t slow_alert1
Definition: pac1944.h:378
pac1944_setup_t::sample_mode
uint8_t sample_mode
Definition: pac1944.h:376
pac1944_generic_write
err_t pac1944_generic_write(pac1944_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
PAC1944 I2C writing function.
pac1944_get_accumulator_count
uint32_t pac1944_get_accumulator_count(pac1944_t *ctx)
PAC1944 accumulator count function.
pac1944_get_measurement
uint32_t pac1944_get_measurement(pac1944_t *ctx, uint8_t meas_sel, uint8_t ch_sel, uint8_t avg_sel)
PAC1944 get measurement function.
pac1944_cfg_setup
void pac1944_cfg_setup(pac1944_cfg_t *cfg)
PAC1944 configuration object setup function.
pac1944_read_last_accessed_register
uint8_t pac1944_read_last_accessed_register(pac1944_t *ctx)
PAC1944 last accessed register read function.
pac1944_cfg_t::i2c_address
uint8_t i2c_address
Definition: pac1944.h:366
pac1944_setup_config
void pac1944_setup_config(pac1944_t *ctx, pac1944_setup_t cfg_data)
PAC1944 setup config function.
pac1944_setup_t::channels_state
uint8_t channels_state
Definition: pac1944.h:379
pac1944_init
err_t pac1944_init(pac1944_t *ctx, pac1944_cfg_t *cfg)
PAC1944 initialization function.
pac1944_setup_t::cfg_vbus4
uint8_t cfg_vbus4
Definition: pac1944.h:387
pac1944_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: pac1944.h:365
pac1944_refresh_cmd
void pac1944_refresh_cmd(pac1944_t *ctx)
PAC1944 refresh command.
pac1944_default_cfg
void pac1944_default_cfg(pac1944_t *ctx)
PAC1944 default configuration function.