41#ifdef PREINIT_SUPPORTED
45#ifdef MikroCCoreVersion
46 #if MikroCCoreVersion >= 1
51#include "drv_digital_out.h"
52#include "drv_digital_in.h"
53#include "drv_i2c_master.h"
65#define PAC1921_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
69 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define PAC1921_RETVAL uint8_t
78#define PAC1921_OK 0x00
79#define PAC1921_INIT_ERROR 0xFF
86#define PAC1921_SLAVE_ADDRESS 0x4C
93#define PAC1921_GAIN_CFG_REG 0x00
94#define PAC1921_INTEGRATION_CFG_REG 0x01
95#define PAC1921_CONTROL_REG 0x02
96#define PAC1921_VBUS_RESULT_HIGH 0x10
97#define PAC1921_VBUS_RESULT_LOW 0x11
98#define PAC1921_VSENSE_RESULT_HIGH 0x12
99#define PAC1921_VSENSE_RESULT_LOW 0x13
100#define PAC1921_VSUM_ACCUMULATOR_HIGH 0x14
101#define PAC1921_VSUM_ACCUMULATOR_MID_H 0x15
102#define PAC1921_VSUM_ACCUMULATOR_MID_L 0x16
103#define PAC1921_VSUM_ACCUMULATOR_LOW 0x17
104#define PAC1921_ISUM_ACCUMULATOR_HIGH 0x18
105#define PAC1921_ISUM_ACCUMULATOR_MID_H 0x19
106#define PAC1921_ISUM_ACCUMULATOR_MID_L 0x1A
107#define PAC1921_ISUM_ACCUMULATOR_LOW 0x1B
108#define PAC1921_OVERFLOW_STATUS 0x1C
109#define PAC1921_VPOWER_RESULT_HIGH 0x1D
110#define PAC1921_VPOWER_RESULT_LOW 0x1E
111#define PAC1921_SAMPLES_HIGH 0x21
112#define PAC1921_SAMPLES_LOW 0x22
113#define PAC1921_PSUM_ACCUMULATOR_HIGH 0x23
114#define PAC1921_PSUM_ACCUMULATOR_MID_H 0x24
115#define PAC1921_PSUM_ACCUMULATOR_MID_M 0x25
116#define PAC1921_PSUM_ACCUMULATOR_MID_L 0x26
117#define PAC1921_PSUM_ACCUMULATOR_LOW 0x27
118#define PAC1921_PRODUCT_ID 0xFD
119#define PAC1921_MANUFACTURER_ID 0xFE
120#define PAC1921_REVISION 0xFF
127#define PAC1921_I_RESOLUTION_11_BIT 0x80
128#define PAC1921_I_RESOLUTION_14_BIT 0x00
129#define PAC1921_V_RESOLUTION_11_BIT 0x40
130#define PAC1921_V_RESOLUTION_14_BIT 0x00
131#define PAC1921_DIGITAL_I_GAIN_1X 0x00
132#define PAC1921_DIGITAL_I_GAIN_2X 0x08
133#define PAC1921_DIGITAL_I_GAIN_4X 0x10
134#define PAC1921_DIGITAL_I_GAIN_8X 0x18
135#define PAC1921_DIGITAL_I_GAIN_16X 0x20
136#define PAC1921_DIGITAL_I_GAIN_32X 0x28
137#define PAC1921_DIGITAL_I_GAIN_64X 0x30
138#define PAC1921_DIGITAL_I_GAIN_128X 0x38
139#define PAC1921_DIGITAL_V_GAIN_1X 0x00
140#define PAC1921_DIGITAL_V_GAIN_2X 0x01
141#define PAC1921_DIGITAL_V_GAIN_4X 0x02
142#define PAC1921_DIGITAL_V_GAIN_8X 0x03
143#define PAC1921_DIGITAL_V_GAIN_16X 0x04
144#define PAC1921_DIGITAL_V_GAIN_32X 0x05
145#define PAC1921_DIGITAL_V_GAIN_64X 0x06
146#define PAC1921_DIGITAL_V_GAIN_128X 0x07
153#define PAC1921_SAMPLE_RATE_1 0x00
154#define PAC1921_SAMPLE_RATE_2 0x10
155#define PAC1921_SAMPLE_RATE_4 0x20
156#define PAC1921_SAMPLE_RATE_8 0x30
157#define PAC1921_SAMPLE_RATE_16 0x40
158#define PAC1921_SAMPLE_RATE_32 0x50
159#define PAC1921_SAMPLE_RATE_64 0x60
160#define PAC1921_SAMPLE_RATE_128 0x70
161#define PAC1921_SAMPLE_RATE_256 0x80
162#define PAC1921_SAMPLE_RATE_512 0x90
163#define PAC1921_SAMPLE_RATE_1024 0xA0
164#define PAC1921_SAMPLE_RATE_2048 0xB0
165#define PAC1921_V_SENSE_FILTER_ON 0x08
166#define PAC1921_V_SENSE_FILTER_OFF 0x00
167#define PAC1921_V_BUS_FILTER_ON 0x04
168#define PAC1921_V_BUS_FILTER_OFF 0x00
169#define PAC1921_READ_INT_OVERRIDE_ON 0x02
170#define PAC1921_READ_INT_OVERRIDE_OFF 0x00
171#define PAC1921_FORCED_INTEGRATE_MODE_ON 0x01
172#define PAC1921_FORCED_INTEGRATE_MODE_OFF 0x00
179#define PAC1921_MEASUREMENT_MODE_V_POWER_PIN_CTRL 0x00
180#define PAC1921_MEASUREMENT_MODE_V_SENSE_FREE_RUN 0x40
181#define PAC1921_MEASUREMENT_MODE_V_BUS_FREE_RUN 0x80
182#define PAC1921_MEASUREMENT_MODE_V_POWER_FREE_RUN 0xC0
183#define PAC1921_MEASUREMENT_MODE_MASK 0xC0
184#define PAC1921_OUT_PIN_FULL_SCALE_RANGE_3V 0x00
185#define PAC1921_OUT_PIN_FULL_SCALE_RANGE_2V 0x10
186#define PAC1921_OUT_PIN_FULL_SCALE_RANGE_1_5_V 0x20
187#define PAC1921_OUT_PIN_FULL_SCALE_RANGE_1V 0x30
188#define PAC1921_TIMEOUT_ON 0x08
189#define PAC1921_TIMEOUT_OFF 0x00
190#define PAC1921_SLEEP_ON 0x04
191#define PAC1921_SLEEP_OFF 0x00
192#define PAC1921_FORCED_READ_MODE_ON 0x02
193#define PAC1921_FORCED_READ_MODE_OFF 0x00
194#define PAC1921_FORCED_RECALCULATE_MODE_ON 0x01
195#define PAC1921_FORCED_RECALCULATE_MODE_OFF 0x00
202#define PAC1921_VOLTAGE_MAX 10
203#define PAC1921_CURRENT_MAX 32
#define PAC1921_RETVAL
Definition pac1921.h:76
void pac1921_cfg_setup(pac1921_cfg_t *cfg)
Config Object Initialization function.
uint8_t pac1921_get_an_pin(pac1921_t *ctx)
AN pin get input function.
float pac1921_get_measured_data(pac1921_t *ctx, uint8_t measurement_mode, uint8_t sample_num)
Measured data read function.
PAC1921_RETVAL pac1921_init(pac1921_t *ctx, pac1921_cfg_t *cfg)
Initialization function.
void pac1921_write_to_reg(pac1921_t *ctx, uint8_t reg_addr, uint8_t *write_data, uint8_t len)
Register write function.
void pac1921_set_int_pin(pac1921_t *ctx, uint8_t output)
INT pin set output function.
void pac1921_default_cfg(pac1921_t *ctx)
Click Default Configuration function.
void pac1921_generic_write(pac1921_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void pac1921_generic_read(pac1921_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
Auxiliary variables default cfg.
Definition pac1921.h:231
uint8_t iarp
Definition pac1921.h:236
uint8_t cfg_byte
Definition pac1921.h:233
uint8_t ctrl_byte
Definition pac1921.h:232
uint16_t output_fsr
Definition pac1921.h:237
uint8_t measurement_mode_old
Definition pac1921.h:234
uint8_t sample_num_old
Definition pac1921.h:235
Auxiliary variables structure.
Definition pac1921.h:217
uint8_t iarp
Definition pac1921.h:222
uint8_t cfg_byte
Definition pac1921.h:219
uint8_t ctrl_byte
Definition pac1921.h:218
uint16_t output_fsr
Definition pac1921.h:223
uint8_t measurement_mode_old
Definition pac1921.h:220
uint8_t sample_num_old
Definition pac1921.h:221
Click configuration structure definition.
Definition pac1921.h:269
uint32_t i2c_speed
Definition pac1921.h:282
aux_cfg_t aux_cfg
Definition pac1921.h:284
pin_name_t scl
Definition pac1921.h:272
pin_name_t int_pin
Definition pac1921.h:278
pin_name_t sda
Definition pac1921.h:273
pin_name_t an
Definition pac1921.h:277
uint8_t i2c_address
Definition pac1921.h:283
Click ctx object definition.
Definition pac1921.h:245
aux_vars_t aux
Definition pac1921.h:261
i2c_master_t i2c
Definition pac1921.h:256
digital_in_t an
Definition pac1921.h:252
digital_out_t int_pin
Definition pac1921.h:248
uint8_t slave_address
Definition pac1921.h:260