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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define PRESENCE_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
56 
62 #define PRESENCE_RETVAL uint8_t
63 
64 #define PRESENCE_OK 0x00
65 #define PRESENCE_INIT_ERROR 0xFF
66 
72 #define PRESENCE_REG_TP_OBJECT_MSB 0x01
73 #define PRESENCE_REG_TP_OBJECT_MID 0x02
74 #define PRESENCE_REG_TP_OBJECT_LSB 0x03
75 #define PRESENCE_REG_TP_AMBIENT_MSB 0x03
76 #define PRESENCE_REG_TP_AMBIENT_LSB 0x04
77 #define PRESENCE_REG_TP_OBJECT_LP1_MSB 0x05
78 #define PRESENCE_REG_TP_OBJECT_LP1_MID 0x06
79 #define PRESENCE_REG_TP_OBJECT_LP1_LSB 0x07
80 #define PRESENCE_REG_TP_OBJECT_LP2_MSB 0x07
81 #define PRESENCE_REG_TP_OBJECT_LP2_MID 0x08
82 #define PRESENCE_REG_TP_OBJECT_LP2_LSB 0x09
83 #define PRESENCE_REG_TP_AMBIENT_LP3_MSB 0x0A
84 #define PRESENCE_REG_TP_AMBIENT_LP3_LSB 0x0B
85 #define PRESENCE_REG_TP_OBJECT_LP2F_MSB 0x0C
86 #define PRESENCE_REG_TP_OBJECT_LP2F_MID 0x0D
87 #define PRESENCE_REG_TP_OBJECT_LP2F_LSB 0x0E
88 #define PRESENCE_REG_TP_PRESENCE 0x0F
89 #define PRESENCE_REG_TP_MOTION 0x10
90 #define PRESENCE_REG_TP_AMBIENT_SHOCK 0x11
91 #define PRESENCE_REG_INTERRUPT_STATUS 0x12
92 #define PRESENCE_REG_CHIP_STATUS 0x13
93 #define PRESENCE_REG_LOW_PASS_TIME_1 0x14
94 #define PRESENCE_REG_LOW_PASS_TIME_2 0x15
95 #define PRESENCE_REG_TP_PRESENCE_THR 0x16
96 #define PRESENCE_REG_TP_MOTION_THR 0x17
97 #define PRESENCE_REG_TP_AMB_SHOCK_THR 0x18
98 #define PRESENCE_REG_INTERRUPT_MASK_1 0x19
99 #define PRESENCE_REG_INTERRUPT_MASK_2 0x1A
100 #define PRESENCE_REG_TIMER_INTERRUPT 0x1B
101 #define PRESENCE_REG_TP_OT_THR_1 0x1C
102 #define PRESENCE_REG_TP_OT_THR_2 0x1D
103 #define PRESENCE_REG_EEPROM_CTRL 0x1F
104 
110 #define PRESENCE_EEPROM_PROTOCOL 0x20
111 #define PRESENCE_EEPROM_CHECKSUM_1 0x21
112 #define PRESENCE_EEPROM_CHECKSUM_2 0x22
113 #define PRESENCE_EEPROM_LOOKUP 0x29
114 #define PRESENCE_EEPROM_PTAT25_1 0x2A
115 #define PRESENCE_EEPROM_PTAT25_2 0x2B
116 #define PRESENCE_EEPROM_M_1 0x2C
117 #define PRESENCE_EEPROM_M_2 0x2D
118 #define PRESENCE_EEPROM_U0_1 0x2E
119 #define PRESENCE_EEPROM_U0_2 0x2F
120 #define PRESENCE_EEPROM_UOUT_1 0x30
121 #define PRESENCE_EEPROM_UOUT_2 0x31
122 #define PRESENCE_EEPROM_TOBJ 0x32
123 #define PRESENCE_EEPROM_SLAVE_ADDR 0x3F
124 
130 #define PRESENCE_DEVICE_SLAVE_ADDRESS 0x0C
131 
137 #define PRESENCE_LOW_PASS_TIME_512s 0x00
138 #define PRESENCE_LOW_PASS_TIME_256s 0x01
139 #define PRESENCE_LOW_PASS_TIME_128s 0x02
140 #define PRESENCE_LOW_PASS_TIME_64s 0x03
141 #define PRESENCE_LOW_PASS_TIME_32s 0x04
142 #define PRESENCE_LOW_PASS_TIME_16s 0x05
143 #define PRESENCE_LOW_PASS_TIME_8s 0x08
144 #define PRESENCE_LOW_PASS_TIME_4s 0x09
145 #define PRESENCE_LOW_PASS_TIME_2s 0x0A
146 #define PRESENCE_LOW_PASS_TIME_1s 0x0B
147 #define PRESENCE_LOW_PASS_TIME_0p50s 0x0C
148 #define PRESENCE_LOW_PASS_TIME_0p25s 0x0D
149 
155 #define PRESENCE_INT_MASK1_TP_OT 0x10
156 #define PRESENCE_INT_MASK1_MOTION 0x04
157 #define PRESENCE_INT_MASK1_PRESENCE 0x08
158 #define PRESENCE_INT_MASK1_AMB_SHOCK 0x02
159 #define PRESENCE_INT_MASK1_TIMER 0x01
160 
166 #define PRESENCE_INT_MASK2_TPOT_DIR 0x10
167 #define PRESENCE_INT_MASK2_SRC_TPobj_LP2 0x00 << 2
168 #define PRESENCE_INT_MASK2_SRC_LP1_LP2 0x01 << 2
169 #define PRESENCE_INT_MASK2_SRC_TPobj_LP2Frozen 0x02 << 2
170 #define PRESENCE_INT_MASK2_SRC_LP1_LP2Frozen 0x03 << 2
171 #define PRESENCE_INT_MASK2_CYCLE_TIME_30ms 0x00
172 #define PRESENCE_INT_MASK2_CYCLE_TIME_60ms 0x01
173 #define PRESENCE_INT_MASK2_CYCLE_TIME_120ms 0x02
174 #define PRESENCE_INT_MASK2_CYCLE_TIME_140ms 0x04
175 
181 #define NULL 0x00
182  // End group macro
185 // --------------------------------------------------------------- PUBLIC TYPES
191 typedef struct
192 {
193  uint8_t *eeprom;
194  uint16_t ptat25_data;
195  uint16_t m_data;
196  uint16_t u0_data;
197  uint8_t tobj_data;
198  uint32_t uout_data;
199  uint16_t checksum_data;
200 
201 } eeprom_data_t;
202 
206 typedef struct
207 {
208  // Input pins
209 
210  digital_in_t int_pin;
211 
212  // Modules
213 
214  i2c_master_t i2c;
215 
216  // ctx variable
217 
218  uint8_t slave_address;
219 
221 
222 } presence_t;
223 
227 typedef struct
228 {
229  // Communication gpio pins
230 
231  pin_name_t scl;
232  pin_name_t sda;
233 
234  // Additional gpio pins
235 
236  pin_name_t int_pin;
237 
238  // static variable
239 
240  uint32_t i2c_speed;
241  uint8_t i2c_address;
242 
244 
245  // End types group
247 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
248 
254 #ifdef __cplusplus
255 extern "C"{
256 #endif
257 
266 void presence_cfg_setup ( presence_cfg_t *cfg );
267 
277 
288 void presence_generic_write ( presence_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
289 
300 void presence_generic_read ( presence_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
301 
310 
319 
333 uint8_t presence_eeprom_process ( presence_t *ctx );
334 
343 
354 
365 
366 #ifdef __cplusplus
367 }
368 #endif
369 #endif // _PRESENCE_H_
370  // End public_function group
373 
374 // ------------------------------------------------------------------------- END
presence_t::eeprom_data
eeprom_data_t eeprom_data
Definition: presence.h:220
presence_cfg_t::sda
pin_name_t sda
Definition: presence.h:232
presence_t::i2c
i2c_master_t i2c
Definition: presence.h:214
presence_cfg_t::i2c_address
uint8_t i2c_address
Definition: presence.h:241
presence_object_temperature
float presence_object_temperature(presence_t *ctx)
Object Temperature.
eeprom_data_t::eeprom
uint8_t * eeprom
Definition: presence.h:193
eeprom_data_t::m_data
uint16_t m_data
Definition: presence.h:195
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:197
eeprom_data_t
Definition: presence.h:191
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:198
presence_cfg_t::int_pin
pin_name_t int_pin
Definition: presence.h:236
PRESENCE_RETVAL
#define PRESENCE_RETVAL
Definition: presence.h:62
presence_t
Click ctx object definition.
Definition: presence.h:206
presence_generic_write
void presence_generic_write(presence_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
presence_init
PRESENCE_RETVAL presence_init(presence_t *ctx, presence_cfg_t *cfg)
Initialization function.
presence_get_interrupt_state
uint8_t presence_get_interrupt_state(presence_t *ctx)
Get interrupt state function.
eeprom_data_t::u0_data
uint16_t u0_data
Definition: presence.h:196
presence_generic_read
void 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:199
presence_eeprom_process
uint8_t presence_eeprom_process(presence_t *ctx)
EEPRM PROCESS.
eeprom_data_t::ptat25_data
uint16_t ptat25_data
Definition: presence.h:194
presence_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: presence.h:240
presence_cfg_t::scl
pin_name_t scl
Definition: presence.h:231
presence_cfg_t
Click configuration structure definition.
Definition: presence.h:227
presence_ambient_temperature
float presence_ambient_temperature(presence_t *ctx)
Ambient Temperature.
presence_get_calib_constants
float presence_get_calib_constants()
Calibration constant K.
presence_t::slave_address
uint8_t slave_address
Definition: presence.h:218