moisture 2.0.0.0
moisture.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 MOISTURE_H
36#define MOISTURE_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define MOISTURE_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define MOISTURE_RETVAL uint8_t
77
78#define MOISTURE_OK 0x00
79#define MOISTURE_INIT_ERROR 0xFF
86#define MOISTURE_DEV_ADR_GND 0x2A
87#define MOISTURE_DEV_ADR_VCC 0x2B
94#define MOISTURE_DEFAULT_OFFSET 0x00AA
101#define MOISTURE_REG_DATA 0x00
102#define MOISTURE_REG_RCNT 0x08
103#define MOISTURE_REG_OFFSET 0x0C
104#define MOISTURE_REG_SETTLE_CNT 0x10
105#define MOISTURE_REG_CLOCK_DIVIDERS 0x14
106#define MOISTURE_REG_STATUS 0x18
107#define MOISTURE_REG_ERR_CFG 0x19
108#define MOISTURE_REG_CFG 0x1A
109#define MOISTURE_REG_MUX_CFG 0x1B
110#define MOISTURE_REG_RESET_DEV 0x1C
111#define MOISTURE_REG_DRIVE_CURR 0x1E
112#define MOISTURE_REG_DEVICE_ID 0x7F
113#define MOISTURE_REG_MFC_ID 0x7E
120#define MOISTURE_DRIVE_CURR_0_016mA 0x0000
121#define MOISTURE_DRIVE_CURR_0_018mA 0x0800
122#define MOISTURE_DRIVE_CURR_0_021mA 0x1000
123#define MOISTURE_DRIVE_CURR_0_025mA 0x1800
124#define MOISTURE_DRIVE_CURR_0_028mA 0x2000
125#define MOISTURE_DRIVE_CURR_0_033mA 0x2800
126#define MOISTURE_DRIVE_CURR_0_038mA 0x3000
127#define MOISTURE_DRIVE_CURR_0_044mA 0x3800
128#define MOISTURE_DRIVE_CURR_0_052mA 0x4000
129#define MOISTURE_DRIVE_CURR_0_060mA 0x4800
130#define MOISTURE_DRIVE_CURR_0_069mA 0x5000
131#define MOISTURE_DRIVE_CURR_0_081mA 0x5800
132#define MOISTURE_DRIVE_CURR_0_093mA 0x6000
133#define MOISTURE_DRIVE_CURR_0_108mA 0x6800
134#define MOISTURE_DRIVE_CURR_0_126mA 0x7000
135#define MOISTURE_DRIVE_CURR_0_146mA 0x7800
136#define MOISTURE_DRIVE_CURR_0_169mA 0x8000
137#define MOISTURE_DRIVE_CURR_0_196mA 0x8800
138#define MOISTURE_DRIVE_CURR_0_228mA 0x9000
139#define MOISTURE_DRIVE_CURR_0_264mA 0x9800
140#define MOISTURE_DRIVE_CURR_0_307mA 0xA000
141#define MOISTURE_DRIVE_CURR_0_356mA 0xA800
142#define MOISTURE_DRIVE_CURR_0_413mA 0xB000
143#define MOISTURE_DRIVE_CURR_0_479mA 0xB800
144#define MOISTURE_DRIVE_CURR_0_555mA 0xC000
145#define MOISTURE_DRIVE_CURR_0_644mA 0xC800
146#define MOISTURE_DRIVE_CURR_0_747mA 0xD000
147#define MOISTURE_DRIVE_CURR_0_867mA 0xD800
148#define MOISTURE_DRIVE_CURR_1_006mA 0xE000
149#define MOISTURE_DRIVE_CURR_1_167mA 0xE800
150#define MOISTURE_DRIVE_CURR_1_354mA 0xF000
151#define MOISTURE_DRIVE_CURR_1_571mA 0xF800
158#define MOISTURE_RESET_DEVICE 0x8000
159#define MOISTURE_OUTPUT_GAIN_x1 0x0000
160#define MOISTURE_OUTPUT_GAIN_x4 0x0200
161#define MOISTURE_OUTPUT_GAIN_x8 0x0400
162#define MOISTURE_OUTPUT_GAIN_x16 0x0600
169#define MOISTURE_MUX_CFG_AUTOSCAN_MODE 0x8000
170#define MOISTURE_MUX_CFG_CONTINUOUS_MODE 0x0000
171#define MOISTURE_MUX_CFG_RR_SEQUENCE_CH_01 0x0000
172#define MOISTURE_MUX_CFG_DEGLITCH_1MHz 0x0001
173#define MOISTURE_MUX_CFG_DEGLITCH_3_3MHz 0x0004
174#define MOISTURE_MUX_CFG_DEGLITCH_10MHz 0x0005
175#define MOISTURE_MUX_CFG_DEGLITCH_33MHz 0x0007
182#define MOISTURE_CFG_ACTIVE_CHAN_CH0 0x0000
183#define MOISTURE_CFG_DEVICE_ACTIVE 0x0000
184#define MOISTURE_CFG_DEVICE_IN_SLEEP_MODE 0x2000
185#define MOISTURE_CFG_FULL_CURRENT_MODE 0x0000
186#define MOISTURE_CFG_LOW_POWER_MODE 0x0800
187#define MOISTURE_CFG_INT_PIN_ENABLE 0x0000
188#define MOISTURE_CFG_INT_PIN_DISABLE 0x0080
195#define MOISTURE_ERR_CFG_WATCHDOG_TIMEOUT 0x2000
196#define MOISTURE_ERR_CFG_AMPLITUDE_HIGH 0x1000
197#define MOISTURE_ERR_CFG_AMPLITUDE_LOW 0x0800
198#define MOISTURE_ERR_CFG_DATA_RDY_IN_PIN 0x0001
205#define MOISTURE_STATUS_ERR_CHAN_0 0x0000
206#define MOISTURE_STATUS_ERR_WD 0x0800
207#define MOISTURE_STATUS_ERR_AHW 0x0400
208#define MOISTURE_STATUS_ERR_AHL 0x0200
209#define MOISTURE_STATUS_DATA_RDY 0x0040
210#define MOISTURE_STATUS_CH0_UNREADCONV 0x0008
217#define MOISTURE_CLOCK_DIVIDERS_x1 0x00001
218#define MOISTURE_CLOCK_DIVIDERS_x2 0x00002
219#define MOISTURE_CLOCK_DIVIDERS_x3 0x00003
220#define MOISTURE_CLOCK_DIVIDERS_x4 0x00004
221#define MOISTURE_CLOCK_DIVIDERS_x5 0x00005
222#define MOISTURE_CLOCK_DIVIDERS_x6 0x00006
223#define MOISTURE_CLOCK_DIVIDERS_x7 0x00007
224#define MOISTURE_CLOCK_DIVIDERS_x8 0x00008
225#define MOISTURE_CLOCK_DIVIDERS_x9 0x00009
226#define MOISTURE_CLOCK_DIVIDERS_x10 0x0000A
227#define MOISTURE_CLOCK_DIVIDERS_x11 0x0000B
228#define MOISTURE_CLOCK_DIVIDERS_x12 0x0000C
229#define MOISTURE_CLOCK_DIVIDERS_x13 0x0000D
230#define MOISTURE_CLOCK_DIVIDERS_x14 0x0000E
231#define MOISTURE_CLOCK_DIVIDERS_x15 0x0000F
238#define MOISTURE_FDC2112_ID 0x3054
239#define MOISTURE_FDC2212_ID 0x3055
246#define MOISTURE_SETTLE_CNT_CFG_DEFAULT 0x0064
247#define MOISTURE_RCNT_CFG_DEFAULT 0x010F
248#define MOISTURE_COMBINED_VAL_CH0_DIV 0x2001
249#define MOISTURE_DRIVE_CURR_CH0 0x7C00
250#define MOISTURE_ALL_ERR_ENABLED 0xFFFF
251#define MOISTURE_REG_CFG_DEFAULT_SETTINGS 0x0000
252#define MOISTURE_INPUT_DEGLITCH_FILT_BWDTH_33MHZ 0x0007
255 // End group macro
256// --------------------------------------------------------------- PUBLIC TYPES
265typedef struct
266{
267 // Input pins
268
269 digital_in_t int_pin;
270
271 // Modules
272
273 i2c_master_t i2c;
274
275 // ctx variable
276
279
280} moisture_t;
281
285typedef struct
286{
287 // Communication gpio pins
288
289 pin_name_t scl;
290 pin_name_t sda;
291
292 // Additional gpio pins
293
294 pin_name_t int_pin;
295
296 // static variable
297
298 uint32_t i2c_speed;
299 uint8_t i2c_address;
300
302
303 // End types group
304// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
305
311#ifdef __cplusplus
312extern "C"{
313#endif
314
324
334
398
409void moisture_generic_write ( moisture_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
410
421void moisture_generic_read ( moisture_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
422
432void moisture_write_word ( moisture_t *ctx, uint8_t reg, uint16_t data_in );
433
443uint16_t moisture_read_word ( moisture_t *ctx, uint8_t reg );
444
453
518void moisture_cfg( moisture_t *ctx, uint16_t gain, uint16_t offset, uint16_t clk_div );
519
530
540
550
551#ifdef __cplusplus
552}
553#endif
554#endif // _MOISTURE_H_
555
556 // End public_function group
558
559// ------------------------------------------------------------------------ END
#define MOISTURE_RETVAL
Definition moisture.h:76
void moisture_write_word(moisture_t *ctx, uint8_t reg, uint16_t data_in)
Write word function.
uint8_t moisture_check_interrupt(moisture_t *ctx)
Soft reset function.
void moisture_soft_reset(moisture_t *ctx)
Soft reset function.
void moisture_default_cfg(moisture_t *ctx)
Click Default Configuration function.
void moisture_cal(moisture_t *ctx)
Chip calibration function.
uint8_t moisture_get_data(moisture_t *ctx)
Measurement data function.
void moisture_generic_write(moisture_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void moisture_cfg(moisture_t *ctx, uint16_t gain, uint16_t offset, uint16_t clk_div)
Configure device function.
void moisture_generic_read(moisture_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
MOISTURE_RETVAL moisture_init(moisture_t *ctx, moisture_cfg_t *cfg)
Initialization function.
void moisture_cfg_setup(moisture_cfg_t *cfg)
Config Object Initialization function.
uint16_t moisture_read_word(moisture_t *ctx, uint8_t reg)
Read word function.
Click configuration structure definition.
Definition moisture.h:286
uint32_t i2c_speed
Definition moisture.h:298
pin_name_t scl
Definition moisture.h:289
pin_name_t int_pin
Definition moisture.h:294
pin_name_t sda
Definition moisture.h:290
uint8_t i2c_address
Definition moisture.h:299
Click ctx object definition.
Definition moisture.h:266
digital_in_t int_pin
Definition moisture.h:269
i2c_master_t i2c
Definition moisture.h:273
uint8_t slave_address
Definition moisture.h:277
uint16_t calib_air_data
Definition moisture.h:278