ldc1101  2.0.0.0
ldc1101.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef LDC1101_H
36 #define LDC1101_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_in.h"
49 #include "drv_spi_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
62 #define LDC1101_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
64  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
65  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
66  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
69 
75 #define LDC1101_RETVAL uint8_t
76 
77 #define LDC1101_OK 0x00
78 #define LDC1101_INIT_ERROR 0xFF
79 
85 #define LDC1101_REG_CFG_RP_MEASUREMENT_DYNAMIC_RANGE 0x01
86 #define LDC1101_REG_CFG_INTERNAL_TIME_CONSTANT_1 0x02
87 #define LDC1101_REG_CFG_INTERNAL_TIME_CONSTANT_2 0x03
88 #define LDC1101_REG_CFG_RP_L_CONVERSION_INTERVAL 0x04
89 #define LDC1101_REG_CFG_ADDITIONAL_DEVICE 0x05
90 #define LDC1101_REG_RP_THRESH_H_LSB 0x06
91 #define LDC1101_REG_RP_THRESH_H_MSB 0x07
92 #define LDC1101_REG_RP_THRESH_L_LSB 0x08
93 #define LDC1101_REG_RP_THRESH_L_MSB 0x09
94 #define LDC1101_REG_CFG_INTB_MODE 0x0A
95 #define LDC1101_REG_CFG_POWER_STATE 0x0B
96 #define LDC1101_REG_AMPLITUDE_CONTROL_REQUIREMENT 0x0C
97 #define LDC1101_REG_L_THRESH_HI_LSB 0x16
98 #define LDC1101_REG_L_THRESH_HI_MSB 0x17
99 #define LDC1101_REG_L_THRESH_LO_LSB 0x18
100 #define LDC1101_REG_L_THRESH_LO_MSB 0x19
101 #define LDC1101_REG_RP_L_MEASUREMENT_STATUS 0x20
102 #define LDC1101_REG_RP_DATA_LSB 0x21
103 #define LDC1101_REG_RP_DATA_MSB 0x22
104 #define LDC1101_REG_L_DATA_LSB 0x23
105 #define LDC1101_REG_L_DATA_MSB 0x24
106 #define LDC1101_REG_LHR_RCOUNT_LSB 0x30
107 #define LDC1101_REG_LHR_RCOUNT_MSB 0x31
108 #define LDC1101_REG_LHR_OFFSET_LSB 0x32
109 #define LDC1101_REG_LHR_OFFSET_MSB 0x33
110 #define LDC1101_REG_CFG_LHR 0x34
111 #define LDC1101_REG_LHR_DATA_LSB 0x38
112 #define LDC1101_REG_LHR_DATA_MID 0x39
113 #define LDC1101_REG_LHR_DATA_MSB 0x3A
114 #define LDC1101_REG_LHR_STATUS 0x3B
115 #define LDC1101_REG_DEVICE_RID_VALUE 0x3E
116 #define LDC1101_REG_CHIP_ID 0x3F
117 
123 #define LDC1101_CHIP_ID_VAL 0xD4
124 
130 #define LDC1101_RP_SET_RP_MAX_IS_DRIVEN 0x00
131 #define LDC1101_RP_SET_RP_MAX_CURRENT_IS_IGNORED 0x80
132 #define LDC1101_RP_SET_RP_MAX_96KOhm 0x00
133 #define LDC1101_RP_SET_RP_MAX_48KOhm 0x10
134 #define LDC1101_RP_SET_RP_MAX_24KOhm 0x20
135 #define LDC1101_RP_SET_RP_MAX_12KOhm 0x30
136 #define LDC1101_RP_SET_RP_MAX_6KOhm 0x40
137 #define LDC1101_RP_SET_RP_MAX_3KOhm 0x50
138 #define LDC1101_RP_SET_RP_MAX_1_5KOhm 0x60
139 #define LDC1101_RP_SET_RP_MAX_0_75KOh 0x70
140 #define LDC1101_RP_SET_RP_MIN_96KOhm 0x00
141 #define LDC1101_RP_SET_RP_MIN_48KOhm 0x01
142 #define LDC1101_RP_SET_RP_MIN_24KOhm 0x02
143 #define LDC1101_RP_SET_RP_MIN_12KOhm 0x03
144 #define LDC1101_RP_SET_RP_MIN_6KOhm 0x04
145 #define LDC1101_RP_SET_RP_MIN_3KOhm 0x05
146 #define LDC1101_RP_SET_RP_MIN_1_5KOhm 0x06
147 #define LDC1101_RP_SET_RP_MIN_0_75KOh 0x07
148 
154 #define LDC1101_TC1_C1_0_75pF 0x00
155 #define LDC1101_TC1_C1_1_5pF 0x40
156 #define LDC1101_TC1_C1_3pF 0x80
157 #define LDC1101_TC1_C1_6pF 0xC0
158 #define LDC1101_TC1_R1_417kOhm 0x00
159 #define LDC1101_TC1_R1_212_7kOhm 0x10
160 #define LDC1101_TC1_R1_21_1kOhm 0x1F
161 
167 #define LDC1101_TC2_C2_3pF 0x00
168 #define LDC1101_TC2_C2_6pF 0x40
169 #define LDC1101_TC2_C2_12pF 0x80
170 #define LDC1101_TC2_C2_24pF 0xC0
171 #define LDC1101_TC2_R2_835kOhm 0x00
172 #define LDC1101_TC2_R2_426_4kOhm 0x20
173 #define LDC1101_TC2_R2_30_5kOhm 0x3F
174 
180 #define LDC1101_DIG_CFG_MIN_FREQ_500kHz 0x00
181 #define LDC1101_DIG_CFG_MIN_FREQ_118kHz 0xD0
182 #define LDC1101_DIG_CFG_MIN_FREQ_8MHz 0xF0
183 #define LDC1101_DIG_CFG_RESP_TIME_192s 0x02
184 #define LDC1101_DIG_CFG_RESP_TIME_384s 0x03
185 #define LDC1101_DIG_CFG_RESP_TIME_768s 0x04
186 #define LDC1101_DIG_CFG_RESP_TIME_1536s 0x05
187 #define LDC1101_DIG_CFG_RESP_TIME_3072s 0x06
188 #define LDC1101_DIG_CFG_RESP_TIME_6144s 0x07
189 
195 #define LDC1101_ALT_CFG_SHUTDOWN_ENABLE 0x02
196 #define LDC1101_ALT_CFG_SHUTDOWN_DISABLE 0x00
197 #define LDC1101_ALT_CFG_L_OPTIMAL_DISABLED 0x00
198 #define LDC1101_ALT_CFG_L_OPTIMAL_ENABLE 0x01
199 #define LDC1101_ALT_CFG_R_OPTIMAL_ENABLE 0x02
200 #define LDC1101_REQ_AMPLINTUDE_REGUL_CONVERT 0x00
201 #define LDC1101_CONTINUES_CONVERT 0x01
202 
208 #define LDC1101_INTB_MODE_DONT_REPORT_INTB_ON_SDO_PIN 0x00
209 #define LDC1101_INTB_MODE_REPORT_INTB_ON_SDO_PIN 0x80
210 #define LDC1101_INTB_MODE_REPORT_LHR_DATA_READY 0x20
211 #define LDC1101_INTB_MODE_L_CONVERSION_TO_L_THRESHOLDS 0x10
212 #define LDC1101_INTB_MODE_L_CONVERSION_TO_L_HIGH_THRESHOLDS 0x08
213 #define LDC1101_INTB_MODE_REPORT_RP_L_DATA_READY 0x04
214 #define LDC1101_INTB_MODE_RP_CONVERSION_TO_L_THRESHOLDS 0x02
215 #define LDC1101_INTB_MODE_RP_CONVERSION_TO_L_HIGH_THRESHOLDS 0x01
216 #define LDC1101_INTB_MODE_NO_OUTPUT 0x00
217 
223 #define LDC1101_FUNC_MODE_ACTIVE_MODE_DEF_CFG 0x00
224 #define LDC1101_RES_L_MEAS_REF_CNT_DEF_CFG 0x00
225 #define LDC1101_RES_OFF_L_MEAS_REF_CNT_DEF_CFG 0x00
226 
232 #define LDC1101_FUNC_MODE_ACTIVE_CONVERSION_MODE 0x00
233 #define LDC1101_FUNC_MODE_SLEEP_MODE 0x01
234 #define LDC1101_FUNC_MODE_SHUTDOWN_MODE 0x02
235 
241 #define LDC1101_SENSOR_FREQ_DIV_NO 0x00
242 #define LDC1101_SENSOR_FREQ_DIV_BY_2 0x01
243 #define LDC1101_SENSOR_FREQ_DIV_BY_4 0x02
244 #define LDC1101_SENSOR_FREQ_DIV_BY_8 0x04
245 
251 #define LDC1101_LHR_CFG_FREQUENCY_NOT_DIVIDED 0x00
252 #define LDC1101_LHR_CFG_FREQUENCY_DIVIDED_BY_2 0x01
253 #define LDC1101_LHR_CFG_FREQUENCY_DIVIDED_BY_4 0x02
254 #define LDC1101_LHR_CFG_FREQUENCY_DIVIDED_BY_8 0x03
255  // End group macro
258 // --------------------------------------------------------------- PUBLIC TYPES
267 typedef struct
268 {
269  digital_out_t cs;
270 
271  // Input pins
272 
273  digital_in_t pwm;
274  digital_in_t int_pin;
275 
276  // Modules
277 
278  spi_master_t spi;
279  pin_name_t chip_select;
280 
281 } ldc1101_t;
282 
286 typedef struct
287 {
288  // Communication gpio pins
289 
290  pin_name_t miso;
291  pin_name_t mosi;
292  pin_name_t sck;
293  pin_name_t cs;
294 
295  // Additional gpio pins
296 
297  pin_name_t pwm;
298  pin_name_t int_pin;
299 
300  // static variable
301 
302  uint32_t spi_speed;
303  uint8_t spi_mode;
304  spi_master_chip_select_polarity_t cs_polarity;
305 
306 } ldc1101_cfg_t;
307  // End types group
309 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
310 
315 #ifdef __cplusplus
316 extern "C"{
317 #endif
318 
328 
337 
512 
525 (
526  ldc1101_t *ctx,
527  uint8_t *wr_buf,
528  uint16_t wr_len,
529  uint8_t *rd_buf,
530  uint16_t rd_len
531 );
532 
542 void ldc1101_generic_write ( ldc1101_t *ctx, uint8_t reg_addr, uint8_t tx_data );
543 
553 uint8_t ldc1101_generic_read ( ldc1101_t *ctx, uint8_t reg_addr );
554 
567 void ldc1101_set_power_mode ( ldc1101_t *ctx, uint8_t pwr_mode );
568 
575 
582 
589 
596 uint16_t ldc1101_get_rp_data ( ldc1101_t *ctx );
597 
604 uint16_t ldc1101_get_l_data ( ldc1101_t *ctx );
605 
613 
614 
615 #ifdef __cplusplus
616 }
617 #endif
618 #endif // _LDC1101_H_
619  // End public_function group
622 
623 // ------------------------------------------------------------------------- END
ldc1101_get_interrupt
uint8_t ldc1101_get_interrupt(ldc1101_t *ctx)
Functions for get interrupt pin status.
ldc1101_get_l_data
uint16_t ldc1101_get_l_data(ldc1101_t *ctx)
Functions for reads L data.
ldc1101_t::cs
digital_out_t cs
Definition: ldc1101.h:269
ldc1101_default_cfg
void ldc1101_default_cfg(ldc1101_t *ctx)
Click Default Configuration function.
ldc1101_cfg_t::pwm
pin_name_t pwm
Definition: ldc1101.h:297
ldc1101_cfg_t::sck
pin_name_t sck
Definition: ldc1101.h:292
ldc1101_t::pwm
digital_in_t pwm
Definition: ldc1101.h:273
ldc1101_init
LDC1101_RETVAL ldc1101_init(ldc1101_t *ctx, ldc1101_cfg_t *cfg)
Initialization function.
LDC1101_RETVAL
#define LDC1101_RETVAL
Definition: ldc1101.h:75
ldc1101_cfg_t::miso
pin_name_t miso
Definition: ldc1101.h:290
ldc1101_go_to_l_mode
void ldc1101_go_to_l_mode(ldc1101_t *ctx)
Functions for go to L mode.
ldc1101_cfg_t::spi_mode
uint8_t spi_mode
Definition: ldc1101.h:303
ldc1101_get_status
uint8_t ldc1101_get_status(ldc1101_t *ctx)
Functions for reads status.
ldc1101_generic_write
void ldc1101_generic_write(ldc1101_t *ctx, uint8_t reg_addr, uint8_t tx_data)
Functions for write one byte on address.
ldc1101_generic_transfer
void ldc1101_generic_transfer(ldc1101_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
ldc1101_cfg_t
Click configuration structure definition.
Definition: ldc1101.h:287
ldc1101_cfg_t::int_pin
pin_name_t int_pin
Definition: ldc1101.h:298
ldc1101_generic_read
uint8_t ldc1101_generic_read(ldc1101_t *ctx, uint8_t reg_addr)
Functions for read byte from address.
ldc1101_cfg_t::spi_speed
uint32_t spi_speed
Definition: ldc1101.h:302
ldc1101_cfg_t::cs
pin_name_t cs
Definition: ldc1101.h:293
ldc1101_t::spi
spi_master_t spi
Definition: ldc1101.h:278
ldc1101_t
Click ctx object definition.
Definition: ldc1101.h:268
ldc1101_get_rp_data
uint16_t ldc1101_get_rp_data(ldc1101_t *ctx)
Functions for reads RP data.
ldc1101_cfg_t::mosi
pin_name_t mosi
Definition: ldc1101.h:291
ldc1101_go_to_r_mode
void ldc1101_go_to_r_mode(ldc1101_t *ctx)
Functions for go to RP mode.
ldc1101_cfg_setup
void ldc1101_cfg_setup(ldc1101_cfg_t *cfg)
Config Object Initialization function.
ldc1101_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: ldc1101.h:304
ldc1101_t::int_pin
digital_in_t int_pin
Definition: ldc1101.h:274
ldc1101_set_power_mode
void ldc1101_set_power_mode(ldc1101_t *ctx, uint8_t pwr_mode)
Set power mode function.
ldc1101_t::chip_select
pin_name_t chip_select
Definition: ldc1101.h:279