ldc1000  2.0.0.0
ldc1000.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 LDC1000_H
36 #define LDC1000_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 #include "math.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define LDC1000_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
69 
75 #define LDC1000_RETVAL uint8_t
76 
77 #define LDC1000_OK 0x00
78 #define LDC1000_INIT_ERROR 0xFF
79 
85 #define LDC1000_CMD_ID 0x00
86 #define LDC1000_CMD_RPMAX 0x01
87 #define LDC1000_CMD_RPMIN 0x02
88 #define LDC1000_CMD_SENSORFREQ 0x03
89 #define LDC1000_CMD_LDCCONFIG 0x04
90 #define LDC1000_CMD_CLKCONFIG 0x05
91 #define LDC1000_CMD_THRESHILSB 0x06
92 #define LDC1000_CMD_THRESHIMSB 0x07
93 #define LDC1000_CMD_THRESLOLSB 0x08
94 #define LDC1000_CMD_THRESLOMSB 0x09
95 #define LDC1000_CMD_INTCONFIG 0x0A
96 #define LDC1000_CMD_PWRCONFIG 0x0B
97 #define LDC1000_CMD_STATUS 0x20
98 #define LDC1000_CMD_PROXLSB 0x21
99 #define LDC1000_CMD_PROXMSB 0x22
100 #define LDC1000_CMD_FREQCTRLSB 0x23
101 #define LDC1000_CMD_FREQCTRMID 0x24
102 #define LDC1000_CMD_FREQCTRMSB 0x25
103 
109 #define LDC1000_RPMAX_38_785K 0x11
110 #define LDC1000_RPMIN_2_39K 0x3B
111 #define LDC1000_SENSORFREQ_N217_F20 0xD9
112 #define LDC1000_LDCCONFIG_A2V_T6144 0x0F
113 #define LDC1000_CLKCONFIG_EC_ET_ENABLE 0x02
114 #define LDC1000_PWRCONFIG_ACTIVE_MODE 0x01
115 #define LDC1000_CMD_SPI_READ 0x80
116 #define LDC1000_SENSITIVITY 100
117  // End group macro
120 // --------------------------------------------------------------- PUBLIC TYPES
129 typedef struct
130 {
131  digital_out_t cs;
132 
133  // Input pins
134 
135  digital_in_t int_pin;
136 
137  // Modules
138 
139  spi_master_t spi;
140  pin_name_t chip_select;
141 
142 } ldc1000_t;
143 
147 typedef struct
148 {
149  // Communication gpio pins
150 
151  pin_name_t miso;
152  pin_name_t mosi;
153  pin_name_t sck;
154  pin_name_t cs;
155 
156  // Additional gpio pins
157 
158  pin_name_t int_pin;
159 
160  // static variable
161 
162  uint32_t spi_speed;
163  uint8_t spi_mode;
164  spi_master_chip_select_polarity_t cs_polarity;
165 
166 } ldc1000_cfg_t;
167  // End types group
169 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
170 
175 #ifdef __cplusplus
176 extern "C"{
177 #endif
178 
188 
197 
206 
216 void ldc1000_write_byte ( ldc1000_t *ctx, uint8_t address, uint8_t input_data );
217 
226 uint8_t ldc1000_read_byte ( ldc1000_t *ctx, uint8_t address );
227 
236 
245 
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 #endif // _LDC1000_H_
259  // End public_function group
262 
263 // ------------------------------------------------------------------------- END
ldc1000_read_byte
uint8_t ldc1000_read_byte(ldc1000_t *ctx, uint8_t address)
Byte read function.
ldc1000_cfg_t::spi_speed
uint32_t spi_speed
Definition: ldc1000.h:162
ldc1000_cfg_setup
void ldc1000_cfg_setup(ldc1000_cfg_t *cfg)
Config Object Initialization function.
ldc1000_get_int_input
uint8_t ldc1000_get_int_input(ldc1000_t *ctx)
Get interrupt pin input function.
ldc1000_cfg_t::int_pin
pin_name_t int_pin
Definition: ldc1000.h:158
ldc1000_t::spi
spi_master_t spi
Definition: ldc1000.h:139
ldc1000_t
Click ctx object definition.
Definition: ldc1000.h:130
LDC1000_RETVAL
#define LDC1000_RETVAL
Definition: ldc1000.h:75
ldc1000_cfg_t::mosi
pin_name_t mosi
Definition: ldc1000.h:152
ldc1000_cfg_t::miso
pin_name_t miso
Definition: ldc1000.h:151
ldc1000_get_proximity_data
uint16_t ldc1000_get_proximity_data(ldc1000_t *ctx)
Get proximity data function.
ldc1000_t::chip_select
pin_name_t chip_select
Definition: ldc1000.h:140
ldc1000_t::int_pin
digital_in_t int_pin
Definition: ldc1000.h:135
ldc1000_default_cfg
void ldc1000_default_cfg(ldc1000_t *ctx)
Click Default Configuration function.
ldc1000_cfg_t::cs
pin_name_t cs
Definition: ldc1000.h:154
ldc1000_cfg_t::sck
pin_name_t sck
Definition: ldc1000.h:153
ldc1000_t::cs
digital_out_t cs
Definition: ldc1000.h:131
ldc1000_get_inductance_data
float ldc1000_get_inductance_data(ldc1000_t *ctx)
Get inductance data function.
ldc1000_init
LDC1000_RETVAL ldc1000_init(ldc1000_t *ctx, ldc1000_cfg_t *cfg)
Initialization function.
ldc1000_write_byte
void ldc1000_write_byte(ldc1000_t *ctx, uint8_t address, uint8_t input_data)
Byte write function.
ldc1000_cfg_t
Click configuration structure definition.
Definition: ldc1000.h:148
ldc1000_cfg_t::spi_mode
uint8_t spi_mode
Definition: ldc1000.h:163
ldc1000_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: ldc1000.h:164