pac1954  2.0.0.0
pac1954.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 PAC1954_H
29 #define PAC1954_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 PAC1954_REG_REFRESH 0x00
60 #define PAC1954_REG_CTRL 0x01
61 #define PAC1954_REG_ACC_COUNT 0x02
62 #define PAC1954_REG_VACC_CH1 0x03
63 #define PAC1954_REG_VACC_CH2 0x04
64 #define PAC1954_REG_VACC_CH3 0x05
65 #define PAC1954_REG_VACC_CH4 0x06
66 #define PAC1954_REG_VBUS_CH1 0x07
67 #define PAC1954_REG_VBUS_CH2 0x08
68 #define PAC1954_REG_VBUS_CH3 0x09
69 #define PAC1954_REG_VBUS_CH4 0x0A
70 #define PAC1954_REG_VSENSE_CH1 0x0B
71 #define PAC1954_REG_VSENSE_CH2 0x0C
72 #define PAC1954_REG_VSENSE_CH3 0x0D
73 #define PAC1954_REG_VSENSE_CH4 0x0E
74 #define PAC1954_REG_VBUS_CH1_AVG 0x0F
75 #define PAC1954_REG_VBUS_CH2_AVG 0x10
76 #define PAC1954_REG_VBUS_CH3_AVG 0x11
77 #define PAC1954_REG_VBUS_CH4_AVG 0x12
78 #define PAC1954_REG_VSENSE_CH1_AVG 0x13
79 #define PAC1954_REG_VSENSE_CH2_AVG 0x14
80 #define PAC1954_REG_VSENSE_CH3_AVG 0x15
81 #define PAC1954_REG_VSENSE_CH4_AVG 0x16
82 #define PAC1954_REG_VPOWER_CH1 0x17
83 #define PAC1954_REG_VPOWER_CH2 0x18
84 #define PAC1954_REG_VPOWER_CH3 0x19
85 #define PAC1954_REG_VPOWER_CH4 0x1A
86 #define PAC1954_REG_SMBUS_CFG 0x1C
87 #define PAC1954_REG_NEG_PWR_FSR 0x1D
88 #define PAC1954_REG_REFRESH_G 0x1E
89 #define PAC1954_REG_REFRESH_V 0x1F
90 #define PAC1954_REG_SLOW 0x20
91 #define PAC1954_REG_CTRL_ACT 0x21
92 #define PAC1954_REG_NEG_PWR_FSR_ACT 0x22
93 #define PAC1954_REG_CTRL_LAT 0x23
94 #define PAC1954_REG_NEG_PWR_FSR_LAT 0x24
95 #define PAC1954_REG_ACC_CFG 0x25
96 #define PAC1954_REG_ALERT_STATUS 0x26
97 #define PAC1954_REG_SLOW_ALERT1 0x27
98 #define PAC1954_REG_GPIO_ALERT2 0x28
99 #define PAC1954_REG_ACC_FULLNESS_LIM 0x29
100 #define PAC1954_REG_OC_LIM_CH1 0x30
101 #define PAC1954_REG_OC_LIM_CH2 0x31
102 #define PAC1954_REG_OC_LIM_CH3 0x32
103 #define PAC1954_REG_OC_LIM_CH4 0x33
104 #define PAC1954_REG_UC_LIM_CH1 0x34
105 #define PAC1954_REG_UC_LIM_CH2 0x35
106 #define PAC1954_REG_UC_LIM_CH3 0x36
107 #define PAC1954_REG_UC_LIM_CH4 0x37
108 #define PAC1954_REG_OP_LIM_CH1 0x38
109 #define PAC1954_REG_OP_LIM_CH2 0x39
110 #define PAC1954_REG_OP_LIM_CH3 0x3A
111 #define PAC1954_REG_OP_LIM_CH4 0x3B
112 #define PAC1954_REG_OV_LIM_CH1 0x3C
113 #define PAC1954_REG_OV_LIM_CH2 0x3D
114 #define PAC1954_REG_OV_LIM_CH3 0x3E
115 #define PAC1954_REG_OV_LIM_CH4 0x3F
116 #define PAC1954_REG_UV_LIM_CH1 0x40
117 #define PAC1954_REG_UV_LIM_CH2 0x41
118 #define PAC1954_REG_UV_LIM_CH3 0x42
119 #define PAC1954_REG_UV_LIM_CH4 0x43
120 #define PAC1954_REG_OC_LIM_NSAMPLES 0x44
121 #define PAC1954_REG_UC_LIM_NSAMPLES 0x45
122 #define PAC1954_REG_OP_LIM_NSAMPLES 0x46
123 #define PAC1954_REG_OV_LIM_NSAMPLES 0x47
124 #define PAC1954_REG_UV_LIM_NSAMPLES 0x48
125 #define PAC1954_REG_ALERT_ENABLE 0x49
126 #define PAC1954_REG_ACC_CFG_ACT 0x4A
127 #define PAC1954_REG_ACC_CFG_LAT 0x4B
128 #define PAC1954_REG_ID_PRODUCT 0xFD
129 #define PAC1954_REG_ID_MANUFACTURER 0xFE
130 #define PAC1954_REG_ID_REVISION 0xFF
131  // pac1954_reg
133 
148 #define PAC1954_CTRLH_SPS_1024_ADAPT_ACC 0x00
149 #define PAC1954_CTRLH_SPS_256_ADAPT_ACC 0x10
150 #define PAC1954_CTRLH_SPS_64_ADAPT_ACC 0x20
151 #define PAC1954_CTRLH_SPS_8_ADAPT_ACC 0x30
152 #define PAC1954_CTRLH_SPS_1024 0x40
153 #define PAC1954_CTRLH_SPS_256 0x50
154 #define PAC1954_CTRLH_SPS_64 0x60
155 #define PAC1954_CTRLH_SPS_8 0x70
156 #define PAC1954_CTRLH_SINGLE_SHOT_MODE 0x80
157 #define PAC1954_CTRLH_SINGLE_SHOT_8X 0x90
158 #define PAC1954_CTRLH_FAST_MODE 0xA0
159 #define PAC1954_CTRLH_BURST_MODE 0xB0
160 #define PAC1954_CTRLH_SLEEP 0xF0
161 #define PAC1954_CTRLH_INT_PIN_ALERT 0x00
162 #define PAC1954_CTRLH_INT_PIN_DIG_IN 0x04
163 #define PAC1954_CTRLH_INT_PIN_DIG_OUT 0x08
164 #define PAC1954_CTRLH_INT_PIN_SLOW 0x0C
165 #define PAC1954_CTRLH_SLW_PIN_ALERT 0x00
166 #define PAC1954_CTRLH_SLW_PIN_DIG_IN 0x01
167 #define PAC1954_CTRLH_SLW_PIN_DIG_OUT 0x02
168 #define PAC1954_CTRLH_SLW_PIN_SLOW 0x03
169 #define PAC1954_CTRLL_CH1_OFF 0x80
170 #define PAC1954_CTRLL_CH2_OFF 0x40
171 #define PAC1954_CTRLL_CH3_OFF 0x20
172 #define PAC1954_CTRLL_CH4_OFF 0x10
173 #define PAC1954_CTRLL_ALL_CH_OFF 0xF0
174 #define PAC1954_CTRLL_ALL_CH_ON 0x00
175 
180 #define PAC1954_NEG_PWR_FSR_CH1_OFFSET 6
181 #define PAC1954_NEG_PWR_FSR_CH2_OFFSET 4
182 #define PAC1954_NEG_PWR_FSR_CH3_OFFSET 2
183 #define PAC1954_NEG_PWR_FSR_CH4_OFFSET 0
184 
189 #define PAC1954_SMBUS_INT_PIN_MASK 0x80
190 #define PAC1954_SMBUS_SLW_PIN_MASK 0x40
191 #define PAC1954_SMBUS_ALERT_MASK 0x20
192 #define PAC1954_SMBUS_POR_MASK 0x10
193 #define PAC1954_SMBUS_TIMEOUT_OFF 0x00
194 #define PAC1954_SMBUS_TIMEOUT_ON 0x08
195 #define PAC1954_SMBUS_BYTE_COUNT_OFF 0x00
196 #define PAC1954_SMBUS_BYTE_COUNT_ON 0x04
197 #define PAC1954_SMBUS_AUTO_INC_SKIP_ON 0x00
198 #define PAC1954_SMBUS_AUTO_INC_SKIP_OFF 0x02
199 #define PAC1954_SMBUS_I2C_HIGH_SPEED 0x01
200 
205 #define PAC1954_MEAS_SEL_V_SOURCE 0
206 #define PAC1954_MEAS_SEL_I_SENSE 1
207 #define PAC1954_MEAS_SEL_P_SENSE 2
208 
213 #define PAC1954_CH_SEL_CH_1 1
214 #define PAC1954_CH_SEL_CH_2 2
215 #define PAC1954_CH_SEL_CH_3 3
216 #define PAC1954_CH_SEL_CH_4 4
217 
222 #define PAC1954_AVG_SEL_DISABLE 0
223 #define PAC1954_AVG_SEL_ENABLE 1
224 
229 #define PAC1954_MEAS_MODE_UNIPOLAR_FSR 0
230 #define PAC1954_MEAS_MODE_BIPOLAR_FSR 1
231 #define PAC1954_MEAS_MODE_BIPOLAR_HALF_FSR 2
232 
237 #define PAC1954_ALL_CH_SAMPLE_8SPS_ON 1
238 #define PAC1954_ALL_CH_SAMPLE_8SPS_OFF 0
239 
244 #define PAC1954_DEV_ENABLE 1
245 #define PAC1954_DEV_PWR_DWN 0
246 
251 #define PAC1954_ALERT_ACTIVE 0
252 #define PAC1954_ALERT_INACTIVE 1
253 
259 #define PAC1954_DEV_ADDR_0 0x10
260 #define PAC1954_DEV_ADDR_1 0x1F
261  // pac1954_set
263 
278 #define PAC1954_MAP_MIKROBUS( cfg, mikrobus ) \
279  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
280  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
281  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
282  cfg.slw = MIKROBUS( mikrobus, MIKROBUS_RST ); \
283  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
284  // pac1954_map // pac1954
287 
292 typedef struct
293 {
294  // Output pins
295  digital_out_t en;
296  digital_out_t slw;
298  // Input pins
299  digital_in_t int_pin;
301  // Modules
302  i2c_master_t i2c;
304  // I2C slave address
305  uint8_t slave_address;
307 } pac1954_t;
308 
313 typedef struct
314 {
315  pin_name_t scl;
316  pin_name_t sda;
318  pin_name_t en;
319  pin_name_t slw;
320  pin_name_t int_pin;
322  uint32_t i2c_speed;
323  uint8_t i2c_address;
325 } pac1954_cfg_t;
326 
331 typedef enum
332 {
334  PAC1954_ERROR = -1
335 
337 
354 
369 err_t pac1954_init ( pac1954_t *ctx, pac1954_cfg_t *cfg );
370 
385 
401 err_t pac1954_generic_write ( pac1954_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
402 
418 err_t pac1954_generic_read ( pac1954_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
419 
433 err_t pac1954_single_write ( pac1954_t *ctx, uint8_t reg, uint8_t data_in );
434 
448 err_t pac1954_single_read ( pac1954_t *ctx, uint8_t reg, uint8_t *data_out );
449 
463 err_t pac1954_set_address_pointer ( pac1954_t *ctx, uint8_t reg );
464 
478 err_t pac1954_read_last_access_reg ( pac1954_t *ctx, uint8_t *data_out );
479 
496 
512 
530 err_t pac1954_get_measurement ( pac1954_t *ctx, uint8_t meas_sel, uint8_t ch_sel,
531  uint8_t avg_sel, uint32_t *data_out );
532 
545 err_t pac1954_get_acc_count ( pac1954_t *ctx, uint32_t *data_out );
546 
561 err_t pac1954_get_acc_output ( pac1954_t *ctx, uint8_t ch_sel, uint8_t *data_out );
562 
582 err_t pac1954_get_calc_measurement ( pac1954_t *ctx, uint8_t meas_sel, uint8_t ch_sel,
583  uint8_t avg_sel, uint8_t meas_mode, float *data_out );
584 
595 void pac1954_set_ch_8_sps ( pac1954_t *ctx, uint8_t state );
596 
607 void pac1954_enable ( pac1954_t *ctx, uint8_t state );
608 
619 
620 #ifdef __cplusplus
621 }
622 #endif
623 #endif // PAC1954_H
624  // pac1954
626 
627 // ------------------------------------------------------------------------ END
pac1954_set_address_pointer
err_t pac1954_set_address_pointer(pac1954_t *ctx, uint8_t reg)
PAC1954 Set Address Pointer Function.
pac1954_cfg_setup
void pac1954_cfg_setup(pac1954_cfg_t *cfg)
PAC1954 configuration object setup function.
pac1954_get_measurement
err_t pac1954_get_measurement(pac1954_t *ctx, uint8_t meas_sel, uint8_t ch_sel, uint8_t avg_sel, uint32_t *data_out)
PAC1954 Get Measurement Function.
pac1954_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: pac1954.h:322
pac1954_t::slw
digital_out_t slw
Definition: pac1954.h:296
pac1954_set_ch_8_sps
void pac1954_set_ch_8_sps(pac1954_t *ctx, uint8_t state)
PAC1954 Slow Down Sampling Freq Of All Channels Function.
pac1954_t::int_pin
digital_in_t int_pin
Definition: pac1954.h:299
pac1954_t
PAC1954 Click context object.
Definition: pac1954.h:293
pac1954_single_read
err_t pac1954_single_read(pac1954_t *ctx, uint8_t reg, uint8_t *data_out)
PAC1954 Single Byte Read Function.
pac1954_generic_write
err_t pac1954_generic_write(pac1954_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
PAC1954 I2C writing function.
pac1954_default_cfg
err_t pac1954_default_cfg(pac1954_t *ctx)
PAC1954 default configuration function.
pac1954_t::i2c
i2c_master_t i2c
Definition: pac1954.h:302
pac1954_enable
void pac1954_enable(pac1954_t *ctx, uint8_t state)
PAC1954 Power Control Function.
pac1954_cfg_t
PAC1954 Click configuration object.
Definition: pac1954.h:314
pac1954_cfg_t::sda
pin_name_t sda
Definition: pac1954.h:316
pac1954_cfg_t::scl
pin_name_t scl
Definition: pac1954.h:315
pac1954_get_calc_measurement
err_t pac1954_get_calc_measurement(pac1954_t *ctx, uint8_t meas_sel, uint8_t ch_sel, uint8_t avg_sel, uint8_t meas_mode, float *data_out)
PAC1954 Get Calculated Measurement Function.
pac1954_get_acc_output
err_t pac1954_get_acc_output(pac1954_t *ctx, uint8_t ch_sel, uint8_t *data_out)
PAC1954 Get Accumulator Output Function.
pac1954_cfg_t::slw
pin_name_t slw
Definition: pac1954.h:319
pac1954_get_acc_count
err_t pac1954_get_acc_count(pac1954_t *ctx, uint32_t *data_out)
PAC1954 Get Accumulator Count Function.
pac1954_init
err_t pac1954_init(pac1954_t *ctx, pac1954_cfg_t *cfg)
PAC1954 initialization function.
pac1954_t::en
digital_out_t en
Definition: pac1954.h:295
pac1954_get_alert2_status
uint8_t pac1954_get_alert2_status(pac1954_t *ctx)
PAC1954 Get INT Pin State Function.
PAC1954_OK
@ PAC1954_OK
Definition: pac1954.h:333
PAC1954_ERROR
@ PAC1954_ERROR
Definition: pac1954.h:334
pac1954_single_write
err_t pac1954_single_write(pac1954_t *ctx, uint8_t reg, uint8_t data_in)
PAC1954 Single Byte Write Function.
pac1954_generic_read
err_t pac1954_generic_read(pac1954_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
PAC1954 I2C reading function.
pac1954_refresh_cmd
err_t pac1954_refresh_cmd(pac1954_t *ctx)
PAC1954 Refresh Command.
pac1954_return_value_t
pac1954_return_value_t
PAC1954 Click return value data.
Definition: pac1954.h:332
pac1954_cfg_t::en
pin_name_t en
Definition: pac1954.h:318
pac1954_cfg_t::int_pin
pin_name_t int_pin
Definition: pac1954.h:320
pac1954_read_last_access_reg
err_t pac1954_read_last_access_reg(pac1954_t *ctx, uint8_t *data_out)
PAC1954 Last Accessed Register Read Function.
pac1954_vol_refresh_cmd
err_t pac1954_vol_refresh_cmd(pac1954_t *ctx)
PAC1954 Volatile Refresh Command.
pac1954_cfg_t::i2c_address
uint8_t i2c_address
Definition: pac1954.h:323
pac1954_t::slave_address
uint8_t slave_address
Definition: pac1954.h:305