ldc  2.0.0.0
ldc.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 LDC_H
29 #define LDC_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 LDC_REG_DATA_CH0 0x00
60 #define LDC_REG_DATA_CH1 0x02
61 #define LDC_REG_RCOUNT_CH0 0x08
62 #define LDC_REG_RCOUNT_CH1 0x09
63 #define LDC_REG_OFFSET_CH0 0x0C
64 #define LDC_REG_OFFSET_CH1 0x0D
65 #define LDC_REG_SETTLECOUNT_CH0 0x10
66 #define LDC_REG_SETTLECOUNT_CH1 0x11
67 #define LDC_REG_CLOCK_DIVIDERS_CH0 0x14
68 #define LDC_REG_CLOCK_DIVIDERS_CH1 0x15
69 #define LDC_REG_STATUS 0x18
70 #define LDC_REG_ERROR_CONFIG 0x19
71 #define LDC_REG_CONFIG 0x1A
72 #define LDC_REG_MUX_CONFIG 0x1B
73 #define LDC_REG_RESET_DEV 0x1C
74 #define LDC_REG_DRIVE_CURRENT_CH0 0x1E
75 #define LDC_REG_DRIVE_CURRENT_CH1 0x1F
76 #define LDC_REG_MANUFACTURER_ID 0x7E
77 #define LDC_REG_DEVICE_ID 0x7F
78  // ldc_reg
80 
95 #define LDC_MANUFACTURER_ID 0x5449
96 #define LDC_DEVICE_ID 0x3054
97 
102 #define LDC_INTERNAL_FREQUENCY 43.4/*<MHz*/
103 #define LDC_FREQUENCY_RESOLUTION 4096
104 #define LDC_SENSOR_CAPACITANCE 0.00022/*<uF*/
105 
110 #define LDC_GAIN_1 0x0000
111 #define LDC_GAIN_4 0x0200
112 #define LDC_GAIN_8 0x0400
113 #define LDC_GAIN_16 0x0600
114 
119 #define LDC_OVER_RANGE 0x8
120 #define LDC_UNDER_RANGE 0x4
121 #define LDC_WATCHDOG 0x3
122 
128 #define LDC_SET_DEV_ADDR 0x2B
129  // ldc_set
131 
146 #define LDC_MAP_MIKROBUS( cfg, mikrobus ) \
147  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
148  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
149  cfg.sd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
150  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
151  // ldc_map // ldc
154 
159 typedef struct
160 {
161  // Output pins
162  digital_out_t sd;
164  // Input pins
165  digital_in_t int_pin;
167  // Modules
168  i2c_master_t i2c;
170  // I2C slave address
171  uint8_t slave_address;
173 } ldc_t;
174 
179 typedef struct
180 {
181  pin_name_t scl;
182  pin_name_t sda;
184  pin_name_t sd;
185  pin_name_t int_pin;
187  uint32_t i2c_speed;
188  uint8_t i2c_address;
190 } ldc_cfg_t;
191 
196 typedef enum
197 {
198  LDC_OK = 0,
199  LDC_ERROR = -1,
202  LDC_ERROR_WATCHDOG = -4
203 
205 
221 void ldc_cfg_setup ( ldc_cfg_t *cfg );
222 
236 err_t ldc_init ( ldc_t *ctx, ldc_cfg_t *cfg );
237 
251 err_t ldc_default_cfg ( ldc_t *ctx );
252 
267 err_t ldc_generic_write ( ldc_t *ctx, uint8_t reg, uint16_t tx_data );
268 
283 err_t ldc_generic_read ( ldc_t *ctx, uint8_t reg, uint16_t *rx_data );
284 
292 uint8_t ldc_get_interrupt ( ldc_t *ctx );
293 
302 void ldc_set_shut_down ( ldc_t *ctx, uint8_t state );
303 
321 err_t ldc_get_frequency ( ldc_t *ctx, uint8_t channel, uint16_t divider, float *frequency );
322 
331 float ldc_calculate_inductance ( float frequency );
332 
333 
334 #ifdef __cplusplus
335 }
336 #endif
337 #endif // LDC_H
338  // ldc
340 
341 // ------------------------------------------------------------------------ END
ldc_generic_write
err_t ldc_generic_write(ldc_t *ctx, uint8_t reg, uint16_t tx_data)
LDC I2C writing function.
LDC_ERROR_WATCHDOG
Definition: ldc.h:201
ldc_t
LDC Click context object.
Definition: ldc.h:158
ldc_default_cfg
err_t ldc_default_cfg(ldc_t *ctx)
LDC default configuration function.
ldc_init
err_t ldc_init(ldc_t *ctx, ldc_cfg_t *cfg)
LDC initialization function.
LDC_ERROR_OVER_RANGE
Definition: ldc.h:200
ldc_cfg_setup
void ldc_cfg_setup(ldc_cfg_t *cfg)
LDC configuration object setup function.
ldc_get_interrupt
uint8_t ldc_get_interrupt(ldc_t *ctx)
Get interrupt pin status.
LDC_OK
Definition: ldc.h:197
ldc_return_value_t
ldc_return_value_t
LDC Click return value data.
Definition: ldc.h:195
ldc_calculate_inductance
float ldc_calculate_inductance(float frequency)
Calculate inductance relative to frequency.
LDC_ERROR
Definition: ldc.h:198
ldc_get_frequency
err_t ldc_get_frequency(ldc_t *ctx, uint8_t channel, uint16_t divider, float *frequency)
Get frequency value calulated for specific channel.
ldc_set_shut_down
void ldc_set_shut_down(ldc_t *ctx, uint8_t state)
Set shut down pin status.
ldc_generic_read
err_t ldc_generic_read(ldc_t *ctx, uint8_t reg, uint16_t *rx_data)
LDC I2C reading function.
divider
uint16_t divider
Definition: main.c:37
LDC_ERROR_UNDER_RANGE
Definition: ldc.h:199
ldc_cfg_t
LDC Click configuration object.
Definition: ldc.h:178