39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
74#define LDC2_REG_DEVICE_ID 0x00
75#define LDC2_REG_RP_MAX 0x01
76#define LDC2_REG_RP_MIN 0x02
77#define LDC2_REG_WDT_FREQ 0x03
78#define LDC2_REG_LDC_CONFIG 0x04
79#define LDC2_REG_COMPARATOR_THLD_HIGH 0x07
80#define LDC2_REG_COMPARATOR_THLD_LOW 0x09
81#define LDC2_REG_INTB_TERMINAL_CONFIG 0x0A
82#define LDC2_REG_POWER_CONFIG 0x0B
83#define LDC2_REG_STATUS 0x20
84#define LDC2_REG_PROXIMITY_DATA 0x22
85#define LDC2_REG_FREQ_CNT_DATA_LSB 0x23
86#define LDC2_REG_FREQ_CNT_DATA_MID_BYTE 0x24
87#define LDC2_REG_FREQ_CNT_DATA_MSB 0x25
105#define LDC2_DEVICE_ID 0x84
111#define LDC2_SPI_READ_MASK 0x80
112#define LDC2_SPI_WRITE_MASK 0x7F
118#define LDC2_COMPARATOR_THLD_MIN 0x00
119#define LDC2_COMPARATOR_THLD_MAX 0xFF
125#define LDC2_STATUS_OSC_STOPPED 0x80
126#define LDC2_STATUS_NO_NEW_DATA 0x40
127#define LDC2_STATUS_WAKE_UP_DISABLED 0x20
128#define LDC2_STATUS_PROX_DATA_LESS_THAN_THLD 0x10
134#define LDC2_MHZ_TO_HZ 1000000.0
135#define LDC2_EXTERNAL_OSC_MHZ 1.8432
136#define LDC2_PARALLEL_CAPACITANCE_uF 0.000047
137#define LDC2_MIN_SENSOR_FREQ_CONST 68.94
138#define LDC2_MIN_SENSOR_FREQ_DIVIDER 2500.0
139#define LDC2_ROUND_TO_NEAREST_INT 0.5
140#define LDC2_MATH_TWO_PI 6.28318530717958
150#define LDC2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
151#define LDC2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
169#define LDC2_MAP_MIKROBUS( cfg, mikrobus ) \
170 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
171 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
172 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
173 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
174 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
err_t ldc2_generic_write(ldc2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
LDC 2 data writing function.
err_t ldc2_generic_read(ldc2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
LDC 2 data reading function.
err_t ldc2_get_response_time(ldc2_t *ctx, uint16_t *res_time)
LDC 2 get response time function.
err_t ldc2_set_wdt_frequency(ldc2_t *ctx)
LDC 2 set watchdog timer frequency function.
err_t ldc2_get_rp_range(ldc2_t *ctx, float *rp_min, float *rp_max)
LDC 2 get Rp range function.
err_t ldc2_default_cfg(ldc2_t *ctx)
LDC 2 default configuration function.
err_t ldc2_set_interrupt_mode(ldc2_t *ctx, ldc2_int_mode_t mode)
LDC 2 set interrupt mode function.
err_t ldc2_read_raw_data(ldc2_t *ctx, uint8_t *prox_data, uint32_t *freq_cnt)
LDC 2 read raw data function.
err_t ldc2_get_sensor_frequency(ldc2_t *ctx, float *freq)
LDC 2 get sensor frequency function.
err_t ldc2_set_rp_range(ldc2_t *ctx, ldc2_rp_range_t rp_min, ldc2_rp_range_t rp_max)
LDC 2 set Rp range function.
uint8_t ldc2_get_int_pin(ldc2_t *ctx)
LDC 2 get int pin function.
err_t ldc2_measure_resonance_impedance(ldc2_t *ctx, uint8_t *prox_data, float *rp_data)
LDC 2 measure resonance impedance function.
err_t ldc2_measure_inductance(ldc2_t *ctx, float *freq, float *inductance)
LDC 2 measure inductance function.
err_t ldc2_check_device_id(ldc2_t *ctx)
LDC 2 check device ID function.
err_t ldc2_get_status(ldc2_t *ctx, uint8_t *status)
LDC 2 get status function.
void ldc2_cfg_setup(ldc2_cfg_t *cfg)
LDC 2 configuration object setup function.
err_t ldc2_set_ldc_config(ldc2_t *ctx, ldc2_amplitude_t amplitude, ldc2_resp_time_t res_time)
LDC 2 set LDC config function.
err_t ldc2_set_power_mode(ldc2_t *ctx, ldc2_pwr_mode_t mode)
LDC 2 set power mode function.
err_t ldc2_init(ldc2_t *ctx, ldc2_cfg_t *cfg)
LDC 2 initialization function.
err_t ldc2_set_comparator_threshold(ldc2_t *ctx, uint8_t thld_low, uint8_t thld_high)
LDC 2 set comparator threshold function.
ldc2_return_value_t
LDC 2 Click return value data.
Definition ldc2.h:221
@ LDC2_ERROR
Definition ldc2.h:223
@ LDC2_OK
Definition ldc2.h:222
ldc2_rp_range_t
LDC 2 Click Rp range values.
Definition ldc2.h:232
@ LDC2_RP_21p547
Definition ldc2.h:252
@ LDC2_RP_64p642
Definition ldc2.h:248
@ LDC2_RP_581p776
Definition ldc2.h:240
@ LDC2_RP_27p704
Definition ldc2.h:251
@ LDC2_RP_145p444
Definition ldc2.h:245
@ LDC2_RP_747p998
Definition ldc2.h:239
@ LDC2_RP_1308p997
Definition ldc2.h:237
@ LDC2_RP_1p026
Definition ldc2.h:263
@ LDC2_RP_249p333
Definition ldc2.h:243
@ LDC2_RP_2p394
Definition ldc2.h:260
@ LDC2_RP_3p078
Definition ldc2.h:259
@ LDC2_RP_7p182
Definition ldc2.h:256
@ LDC2_RP_0p798
Definition ldc2.h:264
@ LDC2_RP_3926p991
Definition ldc2.h:233
@ LDC2_RP_193p926
Definition ldc2.h:244
@ LDC2_RP_1745p329
Definition ldc2.h:236
@ LDC2_RP_12p120
Definition ldc2.h:254
@ LDC2_RP_16p160
Definition ldc2.h:253
@ LDC2_RP_3141p593
Definition ldc2.h:234
@ LDC2_RP_48p481
Definition ldc2.h:249
@ LDC2_RP_2243p995
Definition ldc2.h:235
@ LDC2_RP_4p309
Definition ldc2.h:258
@ LDC2_RP_109p083
Definition ldc2.h:246
@ LDC2_RP_436p332
Definition ldc2.h:241
@ LDC2_RP_1p796
Definition ldc2.h:261
@ LDC2_RP_38p785
Definition ldc2.h:250
@ LDC2_RP_83p111
Definition ldc2.h:247
@ LDC2_RP_5p387
Definition ldc2.h:257
@ LDC2_RP_981p748
Definition ldc2.h:238
@ LDC2_RP_1p347
Definition ldc2.h:262
@ LDC2_RP_9p235
Definition ldc2.h:255
@ LDC2_RP_349p066
Definition ldc2.h:242
ldc2_int_mode_t
LDC 2 Click INTB Terminal configuration values.
Definition ldc2.h:300
@ LDC2_INTB_MODE_DRDY
Definition ldc2.h:304
@ LDC2_INTB_MODE_WAKE_UP
Definition ldc2.h:302
@ LDC2_INTB_MODE_DISABLED
Definition ldc2.h:301
@ LDC2_INTB_MODE_COMPARATOR_OUT
Definition ldc2.h:303
ldc2_resp_time_t
LDC 2 Click response time values.
Definition ldc2.h:285
@ LDC2_RESPONSE_TIME_384
Definition ldc2.h:287
@ LDC2_RESPONSE_TIME_1536
Definition ldc2.h:289
@ LDC2_RESPONSE_TIME_192
Definition ldc2.h:286
@ LDC2_RESPONSE_TIME_768
Definition ldc2.h:288
@ LDC2_RESPONSE_TIME_6144
Definition ldc2.h:291
@ LDC2_RESPONSE_TIME_3072
Definition ldc2.h:290
ldc2_pwr_mode_t
LDC 2 Click Power configuration values.
Definition ldc2.h:313
@ LDC2_PWR_MODE_STANDBY
Definition ldc2.h:314
@ LDC2_PWR_MODE_ACTIVE
Definition ldc2.h:315
ldc2_amplitude_t
LDC 2 Click amplitude values.
Definition ldc2.h:273
@ LDC2_AMPLITUDE_2V
Definition ldc2.h:275
@ LDC2_AMPLITUDE_4V
Definition ldc2.h:276
@ LDC2_AMPLITUDE_1V
Definition ldc2.h:274
This file contains SPI specific macros, functions, etc.
LDC 2 Click configuration object.
Definition ldc2.h:199
spi_master_chip_select_polarity_t cs_polarity
Definition ldc2.h:212
pin_name_t sck
Definition ldc2.h:203
spi_master_mode_t spi_mode
Definition ldc2.h:211
pin_name_t mosi
Definition ldc2.h:202
uint32_t spi_speed
Definition ldc2.h:210
pin_name_t int_pin
Definition ldc2.h:207
pin_name_t miso
Definition ldc2.h:201
pin_name_t cs
Definition ldc2.h:204
LDC 2 Click context object.
Definition ldc2.h:184
spi_master_t spi
Definition ldc2.h:188
digital_in_t int_pin
Definition ldc2.h:185
pin_name_t chip_select
Definition ldc2.h:190