42#ifdef PREINIT_SUPPORTED
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
52#include "drv_digital_in.h"
53#include "drv_i2c_master.h"
66#define PROXIMITY13_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define PROXIMITY13_RETVAL uint8_t
78#define PROXIMITY13_OK 0x00
79#define PROXIMITY13_INIT_ERROR 0xFF
80#define PROXIMITY13_ERROR 0xEE
87#define PROXIMITY13_SLAVE_ADDRESS 0x53
94#define PROXIMITY13_REG_PART_ID 0x00
95#define PROXIMITY13_REG_HW_ID 0x01
96#define PROXIMITY13_REG_REV_ID 0x02
97#define PROXIMITY13_REG_INFO_0 0x03
98#define PROXIMITY13_REG_INFO_1 0x04
99#define PROXIMITY13_REG_HOSTIN_0 0x0A
100#define PROXIMITY13_REG_COMMAND 0x0B
101#define PROXIMITY13_REG_IRQ_ENABLE 0x0F
102#define PROXIMITY13_REG_RESPONSE_1 0x10
103#define PROXIMITY13_REG_RESPONSE_0 0x11
104#define PROXIMITY13_REG_IRQ_STATUS 0x12
105#define PROXIMITY13_REG_HOSTOUT_0 0x13
106#define PROXIMITY13_REG_HOSTOUT_1 0x14
107#define PROXIMITY13_REG_HOSTOUT_2 0x15
108#define PROXIMITY13_REG_HOSTOUT_3 0x16
109#define PROXIMITY13_REG_HOSTOUT_4 0x17
110#define PROXIMITY13_REG_HOSTOUT_5 0x18
111#define PROXIMITY13_REG_HOSTOUT_6 0x19
112#define PROXIMITY13_REG_HOSTOUT_7 0x1A
113#define PROXIMITY13_REG_HOSTOUT_8 0x1B
114#define PROXIMITY13_REG_HOSTOUT_9 0x1C
115#define PROXIMITY13_REG_HOSTOUT_10 0x1D
116#define PROXIMITY13_REG_HOSTOUT_11 0x1E
117#define PROXIMITY13_REG_HOSTOUT_12 0x1F
118#define PROXIMITY13_REG_HOSTOUT_13 0x20
119#define PROXIMITY13_REG_HOSTOUT_14 0x21
120#define PROXIMITY13_REG_HOSTOUT_15 0x22
121#define PROXIMITY13_REG_HOSTOUT_16 0x23
122#define PROXIMITY13_REG_HOSTOUT_17 0x24
123#define PROXIMITY13_REG_HOSTOUT_18 0x25
124#define PROXIMITY13_REG_HOSTOUT_19 0x26
125#define PROXIMITY13_REG_HOSTOUT_20 0x27
126#define PROXIMITY13_REG_HOSTOUT_21 0x28
127#define PROXIMITY13_REG_HOSTOUT_22 0x29
128#define PROXIMITY13_REG_HOSTOUT_23 0x2A
129#define PROXIMITY13_REG_HOSTOUT_24 0x2B
130#define PROXIMITY13_REG_HOSTOUT_25 0x2C
137#define PROXIMITY13_PARAMETER_I2C_ADDR 0x00
138#define PROXIMITY13_PARAMETER_CHAN_LIST 0x01
139#define PROXIMITY13_PARAMETER_ADCCONFIG_0 0x02
140#define PROXIMITY13_PARAMETER_ADCSENS_0 0x03
141#define PROXIMITY13_PARAMETER_ADCPOST_0 0x04
142#define PROXIMITY13_PARAMETER_MEASCONFIG_0 0x05
143#define PROXIMITY13_PARAMETER_ADCCONFIG_1 0x06
144#define PROXIMITY13_PARAMETER_ADCSENS_1 0x07
145#define PROXIMITY13_PARAMETER_ADCPOST_1 0x08
146#define PROXIMITY13_PARAMETER_MEASCONFIG_1 0x09
147#define PROXIMITY13_PARAMETER_ADCCONFIG_2 0x0A
148#define PROXIMITY13_PARAMETER_ADCSENS_2 0x0B
149#define PROXIMITY13_PARAMETER_ADCPOST_2 0x0C
150#define PROXIMITY13_PARAMETER_MEASCONFIG_2 0x0D
151#define PROXIMITY13_PARAMETER_ADCCONFIG_3 0x0E
152#define PROXIMITY13_PARAMETER_ADCSENS_3 0x0F
153#define PROXIMITY13_PARAMETER_ADCPOST_3 0x10
154#define PROXIMITY13_PARAMETER_MEASCONFIG_3 0x11
155#define PROXIMITY13_PARAMETER_ADCCONFIG_4 0x12
156#define PROXIMITY13_PARAMETER_ADCSENS_4 0x13
157#define PROXIMITY13_PARAMETER_ADCPOST_4 0x14
158#define PROXIMITY13_PARAMETER_MEASCONFIG_4 0x15
159#define PROXIMITY13_PARAMETER_ADCCONFIG_5 0x16
160#define PROXIMITY13_PARAMETER_ADCSENS_5 0x17
161#define PROXIMITY13_PARAMETER_ADCPOST_5 0x18
162#define PROXIMITY13_PARAMETER_MEASCONFIG_5 0x19
163#define PROXIMITY13_PARAMETER_MEASRATE_H 0x1A
164#define PROXIMITY13_PARAMETER_MEASRATE_L 0x1B
165#define PROXIMITY13_PARAMETER_MEASCOUNT_0 0x1C
166#define PROXIMITY13_PARAMETER_MEASCOUNT_1 0x1D
167#define PROXIMITY13_PARAMETER_MEASCOUNT_2 0x1E
168#define PROXIMITY13_PARAMETER_LED1_A 0x1F
169#define PROXIMITY13_PARAMETER_LED1_B 0x20
170#define PROXIMITY13_PARAMETER_LED2_A 0x21
171#define PROXIMITY13_PARAMETER_LED2_B 0x22
172#define PROXIMITY13_PARAMETER_LED3_A 0x23
173#define PROXIMITY13_PARAMETER_LED3_B 0x24
174#define PROXIMITY13_PARAMETER_THRESHOLD0_H 0x25
175#define PROXIMITY13_PARAMETER_THRESHOLD0_L 0x26
176#define PROXIMITY13_PARAMETER_THRESHOLD1_H 0x27
177#define PROXIMITY13_PARAMETER_THRESHOLD1_L 0x28
178#define PROXIMITY13_PARAMETER_THRESHOLD2_H 0x29
179#define PROXIMITY13_PARAMETER_THRESHOLD2_L 0x2A
180#define PROXIMITY13_PARAMETER_BURST 0x2B
187#define PROXIMITY13_CMD_RESET_CTR 0x00
188#define PROXIMITY13_CMD_RESET_SW 0x01
189#define PROXIMITY13_CMD_FORCE 0x11
190#define PROXIMITY13_CMD_PAUSE 0x12
191#define PROXIMITY13_CMD_START 0x13
198#define PROXIMITY13_DEV_ID_VAL 0x53
199#define PROXIMITY13_HW_ID_VAL 0x01
200#define PROXIMITY13_REV_ID_VAL 0x11
207#define PROXIMITY13_ADC_CFG_RATE_48p8_US 0x00
208#define PROXIMITY13_ADC_CFG_RATE_97p6_US 0x20
209#define PROXIMITY13_ADC_CFG_RATE_195_US 0x40
210#define PROXIMITY13_ADC_CFG_RATE_24p4_US 0x60
211#define PROXIMITY13_ADC_CFG_MUX_SMALL_IR 0x00
212#define PROXIMITY13_ADC_CFG_MUX_MEDIUM_IR 0x01
213#define PROXIMITY13_ADC_CFG_MUX_LARGE_IR 0x02
214#define PROXIMITY13_ADC_CFG_MUX_WHITE 0x0B
215#define PROXIMITY13_ADC_CFG_MUX_LARGE_WHITE 0x0D
222#define PROXIMITY13_ADC_SENS_SW_GAIN_1 0x00
223#define PROXIMITY13_ADC_SENS_SW_GAIN_2 0x10
224#define PROXIMITY13_ADC_SENS_SW_GAIN_4 0x20
225#define PROXIMITY13_ADC_SENS_SW_GAIN_8 0x30
226#define PROXIMITY13_ADC_SENS_SW_GAIN_16 0x40
227#define PROXIMITY13_ADC_SENS_SW_GAIN_32 0x50
228#define PROXIMITY13_ADC_SENS_SW_GAIN_64 0x60
229#define PROXIMITY13_ADC_SENS_SW_GAIN_128 0x70
230#define PROXIMITY13_ADC_SENS_HW_GAIN_MIN_24p4_US 0x00
231#define PROXIMITY13_ADC_SENS_HW_GAIN_MAX_50_MS 0x0B
238#define PROXIMITY13_ADC_POST_RESOLUTION_16 0x00
239#define PROXIMITY13_ADC_POST_RESOLUTION_24 0x40
240#define PROXIMITY13_ADC_POST_INT_MORE_THEN_THRESH 0x00
241#define PROXIMITY13_ADC_POST_INT_LESS_THEN_THRESH 0x04
242#define PROXIMITY13_ADC_POST_INT_NO_TRESH 0x00
243#define PROXIMITY13_ADC_POST_INT_THRESHOLD_0_EN 0x01
244#define PROXIMITY13_ADC_POST_INT_THRESHOLD_1_EN 0x02
245#define PROXIMITY13_ADC_POST_INT_BETWEEN_TRESHOLD 0x03
252#define PROXIMITY13_MEAS_CFG_BURST_ONLY 0x00
253#define PROXIMITY13_MEAS_CFG_MEASCOUNT0 0x40
254#define PROXIMITY13_MEAS_CFG_MEASCOUNT1 0x80
255#define PROXIMITY13_MEAS_CFG_MEASCOUNT2 0xC0
256#define PROXIMITY13_MEAS_CFG_NOMINAL_LED 0x00
257#define PROXIMITY13_MEAS_CFG_LED_UNDEFINED 0x10
258#define PROXIMITY13_MEAS_CFG_LED_INC_9_PCT 0x20
259#define PROXIMITY13_MEAS_CFG_LED_INC_10_PCT 0x30
260#define PROXIMITY13_MEAS_CFG_LED_A 0x00
261#define PROXIMITY13_MEAS_CFG_LED_B 0x08
262#define PROXIMITY13_MEAS_CFG_LED_2 0x04
263#define PROXIMITY13_MEAS_CFG_LED_3 0x02
264#define PROXIMITY13_MEAS_CFG_LED_1 0x01
271#define PROXIMITY13_PIN_HIGH 1
272#define PROXIMITY13_PIN_LOW 0
279#define PROXIMITY13_CHANNEL_0 0x01
280#define PROXIMITY13_CHANNEL_1 0x02
281#define PROXIMITY13_CHANNEL_2 0x04
282#define PROXIMITY13_CHANNEL_3 0x08
283#define PROXIMITY13_CHANNEL_4 0x10
284#define PROXIMITY13_CHANNEL_5 0x20
#define PROXIMITY13_RETVAL
Definition proximity13.h:76
uint8_t proximity13_generic_read(proximity13_t *ctx, uint8_t reg_adr)
Generic read function.
uint8_t porximity13_check_id(proximity13_t *ctx)
Checks id of the device.
void proximity13_generic_write(proximity13_t *ctx, uint8_t reg_adr, uint8_t write_data)
Generic write function.
uint8_t porximity13_config_channel(proximity13_t *ctx, uint8_t chn_num, proximity13_config_t cfg_val)
Configuration of channel.
PROXIMITY13_RETVAL proximity13_init(proximity13_t *ctx, proximity13_cfg_t *cfg)
Initialization function.
void proximity13_read_channels(proximity13_t *ctx, proximity13_chn_val_t *chn_val)
Reads all enabled channels.
uint8_t proximity13_get_int_pin_status(proximity13_t *ctx)
Checks status of int pin.
void proximity13_cfg_setup(proximity13_cfg_t *cfg)
Config Object Initialization function.
void proximity13_default_cfg(proximity13_t *ctx)
Click Default Configuration function.
uint8_t proximity13_set_parameter(proximity13_t *ctx, uint8_t param, uint8_t cmd_val)
Sets parameter.
uint8_t proximity13_send_command(proximity13_t *ctx, uint8_t cmd_val)
Sends command to command register.
Click configuration structure definition.
Definition proximity13.h:317
uint32_t i2c_speed
Definition proximity13.h:329
pin_name_t scl
Definition proximity13.h:320
pin_name_t int_pin
Definition proximity13.h:325
pin_name_t sda
Definition proximity13.h:321
uint8_t i2c_address
Definition proximity13.h:330
Structure for reading values of channels.
Definition proximity13.h:349
uint32_t channel_2
Definition proximity13.h:352
uint32_t channel_3
Definition proximity13.h:353
uint32_t channel_0
Definition proximity13.h:350
uint32_t channel_1
Definition proximity13.h:351
uint32_t channel_5
Definition proximity13.h:355
uint32_t channel_4
Definition proximity13.h:354
Structure for configurating device.
Definition proximity13.h:338
uint8_t adc_post
Definition proximity13.h:341
uint8_t adc_cfg
Definition proximity13.h:339
uint8_t measure_cfg
Definition proximity13.h:342
uint8_t adc_sens
Definition proximity13.h:340
Click ctx object definition.
Definition proximity13.h:298
digital_in_t int_pin
Definition proximity13.h:301
i2c_master_t i2c
Definition proximity13.h:305
uint8_t slave_address
Definition proximity13.h:309