presence  2.0.0.0
presence.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 PRESENCE_H
36 #define PRESENCE_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_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define PRESENCE_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define PRESENCE_OK 0
73 #define PRESENCE_ERROR -1
74 
80 #define PRESENCE_REG_TP_OBJECT_MSB 0x01
81 #define PRESENCE_REG_TP_OBJECT_MID 0x02
82 #define PRESENCE_REG_TP_OBJECT_LSB 0x03
83 #define PRESENCE_REG_TP_AMBIENT_MSB 0x03
84 #define PRESENCE_REG_TP_AMBIENT_LSB 0x04
85 #define PRESENCE_REG_TP_OBJECT_LP1_MSB 0x05
86 #define PRESENCE_REG_TP_OBJECT_LP1_MID 0x06
87 #define PRESENCE_REG_TP_OBJECT_LP1_LSB 0x07
88 #define PRESENCE_REG_TP_OBJECT_LP2_MSB 0x07
89 #define PRESENCE_REG_TP_OBJECT_LP2_MID 0x08
90 #define PRESENCE_REG_TP_OBJECT_LP2_LSB 0x09
91 #define PRESENCE_REG_TP_AMBIENT_LP3_MSB 0x0A
92 #define PRESENCE_REG_TP_AMBIENT_LP3_LSB 0x0B
93 #define PRESENCE_REG_TP_OBJECT_LP2F_MSB 0x0C
94 #define PRESENCE_REG_TP_OBJECT_LP2F_MID 0x0D
95 #define PRESENCE_REG_TP_OBJECT_LP2F_LSB 0x0E
96 #define PRESENCE_REG_TP_PRESENCE 0x0F
97 #define PRESENCE_REG_TP_MOTION 0x10
98 #define PRESENCE_REG_TP_AMBIENT_SHOCK 0x11
99 #define PRESENCE_REG_INTERRUPT_STATUS 0x12
100 #define PRESENCE_REG_CHIP_STATUS 0x13
101 #define PRESENCE_REG_LOW_PASS_TIME_1 0x14
102 #define PRESENCE_REG_LOW_PASS_TIME_2 0x15
103 #define PRESENCE_REG_TP_PRESENCE_THR 0x16
104 #define PRESENCE_REG_TP_MOTION_THR 0x17
105 #define PRESENCE_REG_TP_AMB_SHOCK_THR 0x18
106 #define PRESENCE_REG_INTERRUPT_MASK_1 0x19
107 #define PRESENCE_REG_INTERRUPT_MASK_2 0x1A
108 #define PRESENCE_REG_TIMER_INTERRUPT 0x1B
109 #define PRESENCE_REG_TP_OT_THR_1 0x1C
110 #define PRESENCE_REG_TP_OT_THR_2 0x1D
111 #define PRESENCE_REG_EEPROM_CTRL 0x1F
112 
118 #define PRESENCE_EEPROM_PROTOCOL 0x20
119 #define PRESENCE_EEPROM_CHECKSUM_1 0x21
120 #define PRESENCE_EEPROM_CHECKSUM_2 0x22
121 #define PRESENCE_EEPROM_LOOKUP 0x29
122 #define PRESENCE_EEPROM_PTAT25_1 0x2A
123 #define PRESENCE_EEPROM_PTAT25_2 0x2B
124 #define PRESENCE_EEPROM_M_1 0x2C
125 #define PRESENCE_EEPROM_M_2 0x2D
126 #define PRESENCE_EEPROM_U0_1 0x2E
127 #define PRESENCE_EEPROM_U0_2 0x2F
128 #define PRESENCE_EEPROM_UOUT_1 0x30
129 #define PRESENCE_EEPROM_UOUT_2 0x31
130 #define PRESENCE_EEPROM_TOBJ 0x32
131 #define PRESENCE_EEPROM_SLAVE_ADDR 0x3F
132 
138 #define PRESENCE_DEVICE_SLAVE_ADDRESS 0x0C
139 #define PRESENCE_DEVICE_GEN_CALL_ADDRESS 0x00
140 
146 #define PRESENCE_LOW_PASS_TIME_512S 0x00
147 #define PRESENCE_LOW_PASS_TIME_256S 0x01
148 #define PRESENCE_LOW_PASS_TIME_128S 0x02
149 #define PRESENCE_LOW_PASS_TIME_64S 0x03
150 #define PRESENCE_LOW_PASS_TIME_32S 0x04
151 #define PRESENCE_LOW_PASS_TIME_16S 0x05
152 #define PRESENCE_LOW_PASS_TIME_8S 0x08
153 #define PRESENCE_LOW_PASS_TIME_4S 0x09
154 #define PRESENCE_LOW_PASS_TIME_2S 0x0A
155 #define PRESENCE_LOW_PASS_TIME_1S 0x0B
156 #define PRESENCE_LOW_PASS_TIME_0P50S 0x0C
157 #define PRESENCE_LOW_PASS_TIME_0P25S 0x0D
158 
164 #define PRESENCE_INT_MASK1_TP_OT 0x10
165 #define PRESENCE_INT_MASK1_PRESENCE 0x08
166 #define PRESENCE_INT_MASK1_MOTION 0x04
167 #define PRESENCE_INT_MASK1_AMB_SHOCK 0x02
168 #define PRESENCE_INT_MASK1_TIMER 0x01
169 
175 #define PRESENCE_INT_MASK2_TPOT_DIR 0x10
176 #define PRESENCE_INT_MASK2_SRC_TPOBJ_LP2 ( 0x00 << 2 )
177 #define PRESENCE_INT_MASK2_SRC_LP1_LP2 ( 0x01 << 2 )
178 #define PRESENCE_INT_MASK2_SRC_TPOBJ_LP2FROZEN ( 0x02 << 2 )
179 #define PRESENCE_INT_MASK2_SRC_LP1_LP2FROZEN ( 0x03 << 2 )
180 #define PRESENCE_INT_MASK2_CYCLE_TIME_30MS 0x00
181 #define PRESENCE_INT_MASK2_CYCLE_TIME_60MS 0x01
182 #define PRESENCE_INT_MASK2_CYCLE_TIME_120MS 0x02
183 #define PRESENCE_INT_MASK2_CYCLE_TIME_140MS 0x04
184  // End group macro
187 // --------------------------------------------------------------- PUBLIC TYPES
193 typedef struct
194 {
195  uint16_t ptat25_data;
196  uint16_t m_data;
197  uint16_t u0_data;
198  uint8_t tobj_data;
199  uint32_t uout_data;
200  uint16_t checksum_data;
201 
202 } eeprom_data_t;
203 
207 typedef struct
208 {
209  // Input pins
210  digital_in_t int_pin;
211 
212  // Modules
213  i2c_master_t i2c;
214 
215  // ctx variable
216  uint8_t slave_address;
217 
219 
220 } presence_t;
221 
225 typedef struct
226 {
227  // Communication gpio pins
228  pin_name_t scl;
229  pin_name_t sda;
230 
231  // Additional gpio pins
232  pin_name_t int_pin;
233 
234  // static variable
235  uint32_t i2c_speed;
236  uint8_t i2c_address;
237 
239 
240  // End types group
242 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
243 
249 #ifdef __cplusplus
250 extern "C"{
251 #endif
252 
262 
272 
286 
300 err_t presence_generic_write ( presence_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
301 
315 err_t presence_generic_read ( presence_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
316 
325 
334 
349 
360 
372 err_t presence_ambient_temperature( presence_t *ctx, float *temperature );
373 
385 err_t presence_object_temperature( presence_t *ctx, float *temperature );
386 
387 #ifdef __cplusplus
388 }
389 #endif
390 #endif // _PRESENCE_H_
391  // End public_function group
394 
395 // ------------------------------------------------------------------------- END
presence_t::eeprom_data
eeprom_data_t eeprom_data
Definition: presence.h:218
presence_cfg_t::sda
pin_name_t sda
Definition: presence.h:229
presence_t::i2c
i2c_master_t i2c
Definition: presence.h:213
presence_cfg_t::i2c_address
uint8_t i2c_address
Definition: presence.h:236
eeprom_data_t::m_data
uint16_t m_data
Definition: presence.h:196
presence_get_int_state
uint8_t presence_get_int_state(presence_t *ctx)
Get interrupt state function.
presence_ambient_temperature
err_t presence_ambient_temperature(presence_t *ctx, float *temperature)
Ambient Temperature.
presence_general_call_addr
void presence_general_call_addr(presence_t *ctx)
General call address.
presence_t::int_pin
digital_in_t int_pin
Definition: presence.h:210
eeprom_data_t::tobj_data
uint8_t tobj_data
Definition: presence.h:198
eeprom_data_t
Definition: presence.h:194
presence_cfg_setup
void presence_cfg_setup(presence_cfg_t *cfg)
Config Object Initialization function.
eeprom_data_t::uout_data
uint32_t uout_data
Definition: presence.h:199
presence_init
err_t presence_init(presence_t *ctx, presence_cfg_t *cfg)
Initialization function.
presence_cfg_t::int_pin
pin_name_t int_pin
Definition: presence.h:232
presence_t
Click ctx object definition.
Definition: presence.h:208
presence_object_temperature
err_t presence_object_temperature(presence_t *ctx, float *temperature)
Object Temperature.
presence_get_calib_constants
float presence_get_calib_constants(presence_t *ctx)
Calibration constant K.
presence_default_cfg
err_t presence_default_cfg(presence_t *ctx)
Presence default configuration function.
eeprom_data_t::u0_data
uint16_t u0_data
Definition: presence.h:197
presence_generic_write
err_t presence_generic_write(presence_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
presence_generic_read
err_t presence_generic_read(presence_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
eeprom_data_t::checksum_data
uint16_t checksum_data
Definition: presence.h:200
eeprom_data_t::ptat25_data
uint16_t ptat25_data
Definition: presence.h:195
presence_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: presence.h:235
presence_cfg_t::scl
pin_name_t scl
Definition: presence.h:228
presence_eeprom_process
err_t presence_eeprom_process(presence_t *ctx)
EEPRM PROCESS.
presence_cfg_t
Click configuration structure definition.
Definition: presence.h:226
presence_t::slave_address
uint8_t slave_address
Definition: presence.h:216