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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define LDC_REG_DATA_CH0 0x00
74 #define LDC_REG_DATA_CH1 0x02
75 #define LDC_REG_RCOUNT_CH0 0x08
76 #define LDC_REG_RCOUNT_CH1 0x09
77 #define LDC_REG_OFFSET_CH0 0x0C
78 #define LDC_REG_OFFSET_CH1 0x0D
79 #define LDC_REG_SETTLECOUNT_CH0 0x10
80 #define LDC_REG_SETTLECOUNT_CH1 0x11
81 #define LDC_REG_CLOCK_DIVIDERS_CH0 0x14
82 #define LDC_REG_CLOCK_DIVIDERS_CH1 0x15
83 #define LDC_REG_STATUS 0x18
84 #define LDC_REG_ERROR_CONFIG 0x19
85 #define LDC_REG_CONFIG 0x1A
86 #define LDC_REG_MUX_CONFIG 0x1B
87 #define LDC_REG_RESET_DEV 0x1C
88 #define LDC_REG_DRIVE_CURRENT_CH0 0x1E
89 #define LDC_REG_DRIVE_CURRENT_CH1 0x1F
90 #define LDC_REG_MANUFACTURER_ID 0x7E
91 #define LDC_REG_DEVICE_ID 0x7F
92  // ldc_reg
94 
109 #define LDC_MANUFACTURER_ID 0x5449
110 #define LDC_DEVICE_ID 0x3054
111 
116 #define LDC_INTERNAL_FREQUENCY 43.4/*<MHz*/
117 #define LDC_FREQUENCY_RESOLUTION 4096
118 #define LDC_SENSOR_CAPACITANCE 0.00022/*<uF*/
119 #define LDC_MATH_TWO_PI 6.28318530717958
120 
125 #define LDC_GAIN_1 0x0000
126 #define LDC_GAIN_4 0x0200
127 #define LDC_GAIN_8 0x0400
128 #define LDC_GAIN_16 0x0600
129 
134 #define LDC_OVER_RANGE 0x8
135 #define LDC_UNDER_RANGE 0x4
136 #define LDC_WATCHDOG 0x3
137 
142 #define LDC_STATUS_DRDY 0x0040
143 
149 #define LDC_SET_DEV_ADDR 0x2B
150  // ldc_set
152 
167 #define LDC_MAP_MIKROBUS( cfg, mikrobus ) \
168  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
169  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
170  cfg.sd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
171  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
172  // ldc_map // ldc
175 
180 typedef struct
181 {
182  // Output pins
183  digital_out_t sd;
185  // Input pins
186  digital_in_t int_pin;
188  // Modules
189  i2c_master_t i2c;
191  // I2C slave address
192  uint8_t slave_address;
194 } ldc_t;
195 
200 typedef struct
201 {
202  pin_name_t scl;
203  pin_name_t sda;
205  pin_name_t sd;
206  pin_name_t int_pin;
208  uint32_t i2c_speed;
209  uint8_t i2c_address;
211 } ldc_cfg_t;
212 
217 typedef enum
218 {
219  LDC_OK = 0,
220  LDC_ERROR = -1,
223  LDC_ERROR_WATCHDOG = -4
224 
226 
242 void ldc_cfg_setup ( ldc_cfg_t *cfg );
243 
257 err_t ldc_init ( ldc_t *ctx, ldc_cfg_t *cfg );
258 
272 err_t ldc_default_cfg ( ldc_t *ctx );
273 
288 err_t ldc_generic_write ( ldc_t *ctx, uint8_t reg, uint16_t tx_data );
289 
304 err_t ldc_generic_read ( ldc_t *ctx, uint8_t reg, uint16_t *rx_data );
305 
313 uint8_t ldc_get_interrupt ( ldc_t *ctx );
314 
323 void ldc_set_shut_down ( ldc_t *ctx, uint8_t state );
324 
342 err_t ldc_get_frequency ( ldc_t *ctx, uint8_t channel, uint16_t divider, float *frequency );
343 
352 float ldc_calculate_inductance ( float frequency );
353 
354 
355 #ifdef __cplusplus
356 }
357 #endif
358 #endif // LDC_H
359  // ldc
361 
362 // ------------------------------------------------------------------------ END
ldc_cfg_t::scl
pin_name_t scl
Definition: ldc.h:202
ldc_generic_write
err_t ldc_generic_write(ldc_t *ctx, uint8_t reg, uint16_t tx_data)
LDC I2C writing function.
ldc_cfg_t::sda
pin_name_t sda
Definition: ldc.h:203
ldc_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ldc.h:208
ldc_cfg_t::sd
pin_name_t sd
Definition: ldc.h:205
LDC_ERROR_WATCHDOG
@ LDC_ERROR_WATCHDOG
Definition: ldc.h:223
ldc_t
LDC Click context object.
Definition: ldc.h:181
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
@ LDC_ERROR_OVER_RANGE
Definition: ldc.h:222
ldc_t::i2c
i2c_master_t i2c
Definition: ldc.h:189
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_cfg_t::int_pin
pin_name_t int_pin
Definition: ldc.h:206
ldc_t::sd
digital_out_t sd
Definition: ldc.h:183
LDC_OK
@ LDC_OK
Definition: ldc.h:219
ldc_return_value_t
ldc_return_value_t
LDC Click return value data.
Definition: ldc.h:218
ldc_calculate_inductance
float ldc_calculate_inductance(float frequency)
Calculate inductance relative to frequency.
ldc_cfg_t::i2c_address
uint8_t i2c_address
Definition: ldc.h:209
LDC_ERROR
@ LDC_ERROR
Definition: ldc.h:220
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.
ldc_t::slave_address
uint8_t slave_address
Definition: ldc.h:192
ldc_t::int_pin
digital_in_t int_pin
Definition: ldc.h:186
divider
uint16_t divider
Definition: main.c:37
LDC_ERROR_UNDER_RANGE
@ LDC_ERROR_UNDER_RANGE
Definition: ldc.h:221
ldc_cfg_t
LDC Click configuration object.
Definition: ldc.h:201