earthquake  2.0.0.0
earthquake.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 EARTHQUAKE_H
36 #define EARTHQUAKE_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 EARTHQUAKE_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.st = MIKROBUS( mikrobus, MIKROBUS_CS ); \
56  cfg.int2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
57  cfg.int1 = MIKROBUS( mikrobus, MIKROBUS_INT );
58 
64 #define EARTHQUAKE_STANDBY_MODE 0
65 #define EARTHQUAKE_NORMAL_MODE 1
66 #define EARTHQUAKE_INIT_INST 2
67 #define EARTHQUAKE_OFFSET_ACQ 3
68 #define EARTHQUAKE_SELF_DIAGNOSTIC 4
69 
75 #define EARTHQUAKE_RETVAL uint8_t
76 
77 #define EARTHQUAKE_OK 0x00
78 #define EARTHQUAKE_INIT_ERROR 0xFF
79  // End group macro
82 
83 // -------------------------------------------------------------- PRIVATE MACROS
93 #define EARTHQUAKE_I2C_ADDRESS 0x55
94 
100 #define EARTHQUAKE_CLICK_ERR 0xFF
101 #define EARTHQUAKE_CLICK_OK 0x00
102 
108 #define EARTHQUAKE_STATE 0x1000
109 #define EARTHQUAKE_AXIS_STATE 0x1001
110 #define EARTHQUAKE_EVENT 0x1002
111 
117 #define EARTHQUAKE_MODE 0x1003
118 #define EARTHQUAKE_CTRL 0x1004
119 #define EARTHQUAKE_CLEAR_COMMAND 0x1005
120 
126 #define EARTHQUAKE_MAIN_SI_H 0x2000
127 #define EARTHQUAKE_MAIN_SI_L 0x2001
128 #define EARTHQUAKE_MAIN_PGA_H 0x2002
129 #define EARTHQUAKE_MAIN_PGA_L 0x2003
130 
136 #define EARTHQUAKE_N1_MAIN_OFFSET_X_H 0x3000
137 #define EARTHQUAKE_N1_MAIN_OFFSET_X_L 0x3001
138 #define EARTHQUAKE_N1_MAIN_OFFSET_Y_H 0x3002
139 #define EARTHQUAKE_N1_MAIN_OFFSET_Y_L 0x3003
140 #define EARTHQUAKE_N1_MAIN_OFFSET_Z_H 0x3004
141 #define EARTHQUAKE_N1_MAIN_OFFSET_Z_L 0x3005
142 
143 #define EARTHQUAKE_N1_MAIN_T_AVE_H 0x3006
144 #define EARTHQUAKE_N1_MAIN_T_AVE_L 0x3007
145 #define EARTHQUAKE_N1_MAIN_SI_H 0x3008
146 #define EARTHQUAKE_N1_MAIN_SI_L 0x3009
147 #define EARTHQUAKE_N1_MAIN_PGA_H 0x300A
148 #define EARTHQUAKE_N1_MAIN_PGA_L 0x300B
149 
155 #define EARTHQUAKE_N2_MAIN_OFFSET_X_H 0x3100
156 #define EARTHQUAKE_N2_MAIN_OFFSET_X_L 0x3101
157 #define EARTHQUAKE_N2_MAIN_OFFSET_Y_H 0x3102
158 #define EARTHQUAKE_N2_MAIN_OFFSET_Y_L 0x3103
159 #define EARTHQUAKE_N2_MAIN_OFFSET_Z_H 0x3104
160 #define EARTHQUAKE_N2_MAIN_OFFSET_Z_L 0x3105
161 
162 #define EARTHQUAKE_N2_MAIN_T_AVE_H 0x3106
163 #define EARTHQUAKE_N2_MAIN_T_AVE_L 0x3107
164 #define EARTHQUAKE_N2_MAIN_SI_H 0x3108
165 #define EARTHQUAKE_N2_MAIN_SI_L 0x3109
166 #define EARTHQUAKE_N2_MAIN_PGA_H 0x310A
167 #define EARTHQUAKE_N2_MAIN_PGA_L 0x310B
168 
174 #define EARTHQUAKE_N3_MAIN_OFFSET_X_H 0x3200
175 #define EARTHQUAKE_N3_MAIN_OFFSET_X_L 0x3201
176 #define EARTHQUAKE_N3_MAIN_OFFSET_Y_H 0x3202
177 #define EARTHQUAKE_N3_MAIN_OFFSET_Y_L 0x3203
178 #define EARTHQUAKE_N3_MAIN_OFFSET_Z_H 0x3204
179 #define EARTHQUAKE_N3_MAIN_OFFSET_Z_L 0x3205
180 
181 #define EARTHQUAKE_N3_MAIN_T_AVE_H 0x3206
182 #define EARTHQUAKE_N3_MAIN_T_AVE_L 0x3207
183 #define EARTHQUAKE_N3_MAIN_SI_H 0x3208
184 #define EARTHQUAKE_N3_MAIN_SI_L 0x3209
185 #define EARTHQUAKE_N3_MAIN_PGA_H 0x320A
186 #define EARTHQUAKE_N3_MAIN_PGA_L 0x320B
187 
193 #define EARTHQUAKE_N4_MAIN_OFFSET_X_H 0x3300
194 #define EARTHQUAKE_N4_MAIN_OFFSET_X_L 0x3301
195 #define EARTHQUAKE_N4_MAIN_OFFSET_Y_H 0x3302
196 #define EARTHQUAKE_N4_MAIN_OFFSET_Y_L 0x3303
197 #define EARTHQUAKE_N4_MAIN_OFFSET_Z_H 0x3304
198 #define EARTHQUAKE_N4_MAIN_OFFSET_Z_L 0x3305
199 
200 #define EARTHQUAKE_N4_MAIN_T_AVE_H 0x3306
201 #define EARTHQUAKE_N4_MAIN_T_AVE_L 0x3307
202 #define EARTHQUAKE_N4_MAIN_SI_H 0x3308
203 #define EARTHQUAKE_N4_MAIN_SI_L 0x3309
204 #define EARTHQUAKE_N4_MAIN_PGA_H 0x330A
205 #define EARTHQUAKE_N4_MAIN_PGA_L 0x330B
206 
212 #define EARTHQUAKE_N5_MAIN_OFFSET_X_H 0x3400
213 #define EARTHQUAKE_N5_MAIN_OFFSET_X_L 0x3401
214 #define EARTHQUAKE_N5_MAIN_OFFSET_Y_H 0x3402
215 #define EARTHQUAKE_N5_MAIN_OFFSET_Y_L 0x3403
216 #define EARTHQUAKE_N5_MAIN_OFFSET_Z_H 0x3404
217 #define EARTHQUAKE_N5_MAIN_OFFSET_Z_L 0x3405
218 
219 #define EARTHQUAKE_N5_MAIN_T_AVE_H 0x3406
220 #define EARTHQUAKE_N5_MAIN_T_AVE_L 0x3407
221 #define EARTHQUAKE_N5_MAIN_SI_H 0x3408
222 #define EARTHQUAKE_N5_MAIN_SI_L 0x3409
223 #define EARTHQUAKE_N5_MAIN_PGA_H 0x340A
224 #define EARTHQUAKE_N5_MAIN_PGA_L 0x340B
225 
231 #define EARTHQUAKE_M1_MAIN_OFFSET_X_H 0x3500
232 #define EARTHQUAKE_M1_MAIN_OFFSET_X_L 0x3501
233 #define EARTHQUAKE_M1_MAIN_OFFSET_Y_H 0x3502
234 #define EARTHQUAKE_M1_MAIN_OFFSET_Y_L 0x3503
235 #define EARTHQUAKE_M1_MAIN_OFFSET_Z_H 0x3504
236 #define EARTHQUAKE_M1_MAIN_OFFSET_Z_L 0x3505
237 
238 #define EARTHQUAKE_M1_MAIN_T_AVE_H 0x3506
239 #define EARTHQUAKE_M1_MAIN_T_AVE_L 0x3507
240 #define EARTHQUAKE_M1_MAIN_SI_H 0x3508
241 #define EARTHQUAKE_M1_MAIN_SI_L 0x3509
242 #define EARTHQUAKE_M1_MAIN_PGA_H 0x350A
243 #define EARTHQUAKE_M1_MAIN_PGA_L 0x350B
244 
250 #define EARTHQUAKE_M2_MAIN_OFFSET_X_H 0x3600
251 #define EARTHQUAKE_M2_MAIN_OFFSET_X_L 0x3601
252 #define EARTHQUAKE_M2_MAIN_OFFSET_Y_H 0x3602
253 #define EARTHQUAKE_M2_MAIN_OFFSET_Y_L 0x3603
254 #define EARTHQUAKE_M2_MAIN_OFFSET_Z_H 0x3604
255 #define EARTHQUAKE_M2_MAIN_OFFSET_Z_L 0x3605
256 
257 #define EARTHQUAKE_M2_MAIN_T_AVE_H 0x3606
258 #define EARTHQUAKE_M2_MAIN_T_AVE_L 0x3607
259 #define EARTHQUAKE_M2_MAIN_SI_H 0x3608
260 #define EARTHQUAKE_M2_MAIN_SI_L 0x3609
261 #define EARTHQUAKE_M2_MAIN_PGA_H 0x360A
262 #define EARTHQUAKE_M2_MAIN_PGA_L 0x360B
263 
269 #define EARTHQUAKE_M3_MAIN_OFFSET_X_H 0x3700
270 #define EARTHQUAKE_M3_MAIN_OFFSET_X_L 0x3701
271 #define EARTHQUAKE_M3_MAIN_OFFSET_Y_H 0x3702
272 #define EARTHQUAKE_M3_MAIN_OFFSET_Y_L 0x3703
273 #define EARTHQUAKE_M3_MAIN_OFFSET_Z_H 0x3704
274 #define EARTHQUAKE_M3_MAIN_OFFSET_Z_L 0x3705
275 
276 #define EARTHQUAKE_M3_MAIN_T_AVE_H 0x3706
277 #define EARTHQUAKE_M3_MAIN_T_AVE_L 0x3707
278 #define EARTHQUAKE_M3_MAIN_SI_H 0x3708
279 #define EARTHQUAKE_M3_MAIN_SI_L 0x3709
280 #define EARTHQUAKE_M3_MAIN_PGA_H 0x370A
281 #define EARTHQUAKE_M3_MAIN_PGA_L 0x370B
282 
288 #define EARTHQUAKE_M4_MAIN_OFFSET_X_H 0x3800
289 #define EARTHQUAKE_M4_MAIN_OFFSET_X_L 0x3801
290 #define EARTHQUAKE_M4_MAIN_OFFSET_Y_H 0x3802
291 #define EARTHQUAKE_M4_MAIN_OFFSET_Y_L 0x3803
292 #define EARTHQUAKE_M4_MAIN_OFFSET_Z_H 0x3804
293 #define EARTHQUAKE_M4_MAIN_OFFSET_Z_L 0x3805
294 
295 #define EARTHQUAKE_M4_MAIN_T_AVE_H 0x3806
296 #define EARTHQUAKE_M4_MAIN_T_AVE_L 0x3807
297 #define EARTHQUAKE_M4_MAIN_SI_H 0x3808
298 #define EARTHQUAKE_M4_MAIN_SI_L 0x3809
299 #define EARTHQUAKE_M4_MAIN_PGA_H 0x380A
300 #define EARTHQUAKE_M4_MAIN_PGA_L 0x380B
301 
307 #define EARTHQUAKE_M5_MAIN_OFFSET_X_H 0x3900
308 #define EARTHQUAKE_M5_MAIN_OFFSET_X_L 0x3901
309 #define EARTHQUAKE_M5_MAIN_OFFSET_Y_H 0x3902
310 #define EARTHQUAKE_M5_MAIN_OFFSET_Y_L 0x3903
311 #define EARTHQUAKE_M5_MAIN_OFFSET_Z_H 0x3904
312 #define EARTHQUAKE_M5_MAIN_OFFSET_Z_L 0x3905
313 
314 #define EARTHQUAKE_M5_MAIN_T_AVE_H 0x3906
315 #define EARTHQUAKE_M5_MAIN_T_AVE_L 0x3907
316 #define EARTHQUAKE_M5_MAIN_SI_H 0x3908
317 #define EARTHQUAKE_M5_MAIN_SI_L 0x3909
318 #define EARTHQUAKE_M5_MAIN_PGA_H 0x390A
319 #define EARTHQUAKE_M5_MAIN_PGA_L 0x390B
320 
326 #define EARTHQUAKE_OFFSET_SET_X_H 0x4000
327 #define EARTHQUAKE_OFFSET_SET_X_L 0x4001
328 #define EARTHQUAKE_OFFSET_SET_Y_H 0x4002
329 #define EARTHQUAKE_OFFSET_SET_Y_L 0x4003
330 #define EARTHQUAKE_OFFSET_SET_Z_H 0x4004
331 #define EARTHQUAKE_OFFSET_SET_Z_L 0x4005
332 
333 #define EARTHQUAKE_OFFSET_SET_T_AVE_H 0x4006
334 #define EARTHQUAKE_OFFSET_SET_T_AVE_L 0x4007
335 #define EARTHQUAKE_OFFSET_SET_MAX_X_H 0x4008
336 #define EARTHQUAKE_OFFSET_SET_MAX_X_L 0x4009
337 #define EARTHQUAKE_OFFSET_SET_MAX_Y_H 0x400A
338 #define EARTHQUAKE_OFFSET_SET_MAX_Y_L 0x400B
339 #define EARTHQUAKE_OFFSET_SET_MAX_Z_H 0x400C
340 #define EARTHQUAKE_OFFSET_SET_MAX_Z_L 0x400D
341 
342 #define EARTHQUAKE_OFFSET_SET_MIN_X_H 0x400E
343 #define EARTHQUAKE_OFFSET_SET_MIN_X_L 0x400F
344 #define EARTHQUAKE_OFFSET_SET_MIN_Y_H 0x4010
345 #define EARTHQUAKE_OFFSET_SET_MIN_Y_L 0x4011
346 #define EARTHQUAKE_OFFSET_SET_MIN_Z_H 0x4012
347 #define EARTHQUAKE_OFFSET_SET_MIN_Z_L 0x4013
348 
349 #define EARTHQUAKE_OFFSET_SET_AXIS 0x4014
350 
356 #define EARTHQUAKE_OFFSET_RECENT_X_H 0x4100
357 #define EARTHQUAKE_OFFSET_RECENT_X_L 0x4101
358 #define EARTHQUAKE_OFFSET_RECENT_Y_H 0x4102
359 #define EARTHQUAKE_OFFSET_RECENT_Y_L 0x4103
360 #define EARTHQUAKE_OFFSET_RECENT_Z_H 0x4104
361 #define EARTHQUAKE_OFFSET_RECENT_Z_L 0x4105
362 
363 #define EARTHQUAKE_OFFSET_RECENT_T_AVE_H 0x4106
364 #define EARTHQUAKE_OFFSET_RECENT_T_AVE_L 0x4107
365 
366 #define EARTHQUAKE_OFFSET_RECENT_MAX_X_H 0x4108
367 #define EARTHQUAKE_OFFSET_RECENT_MAX_X_L 0x4109
368 #define EARTHQUAKE_OFFSET_RECENT_MAX_Y_H 0x410A
369 #define EARTHQUAKE_OFFSET_RECENT_MAX_Y_L 0x410B
370 #define EARTHQUAKE_OFFSET_RECENT_MAX_Z_H 0x410C
371 #define EARTHQUAKE_OFFSET_RECENT_MAX_Z_L 0x410D
372 
373 #define EARTHQUAKE_OFFSET_RECENT_MIN_X_H 0x410E
374 #define EARTHQUAKE_OFFSET_RECENT_MIN_X_L 0x410F
375 #define EARTHQUAKE_OFFSET_RECENT_MIN_Y_H 0x4110
376 #define EARTHQUAKE_OFFSET_RECENT_MIN_Y_L 0x4111
377 #define EARTHQUAKE_OFFSET_RECENT_MIN_Z_H 0x4112
378 #define EARTHQUAKE_OFFSET_RECENT_MIN_Z_L 0x4113
379 
380 #define EARTHQUAKE_OFFSET_RECENT_STATE 0x4114
381 
387 #define EARTHQUAKE_SELFTEST_BEFORE_X_H 0x4200
388 #define EARTHQUAKE_SELFTEST_BEFORE_X_L 0x4201
389 #define EARTHQUAKE_SELFTEST_AFTER_X_H 0x4202
390 #define EARTHQUAKE_SELFTEST_AFTER_X_L 0x4203
391 #define EARTHQUAKE_SELFTEST_BEFORE_Y_H 0x4204
392 #define EARTHQUAKE_SELFTEST_BEFORE_Y_L 0x4205
393 #define EARTHQUAKE_SELFTEST_AFTER_Y_H 0x4206
394 #define EARTHQUAKE_SELFTEST_AFTER_Y_L 0x4207
395 #define EARTHQUAKE_SELFTEST_BEFORE_Z_H 0x4208
396 #define EARTHQUAKE_SELFTEST_BEFORE_Z_L 0x4209
397 #define EARTHQUAKE_SELFTEST_AFTER_Z_H 0x420A
398 #define EARTHQUAKE_SELFTEST_AFTER_Z_L 0x420B
399 
400 #define EARTHQUAKE_SELFTEST_T_AVE_H 0x420C
401 #define EARTHQUAKE_SELFTEST_T_AVE_L 0x420D
402 
403 #define EARTHQUAKE_SELFTEST_ERROR 0x420E
404  // End group macro
408 
409 // --------------------------------------------------------------- PUBLIC TYPES
418 typedef struct
419 {
420  // Input pins
421 
422  digital_in_t int2;
423  digital_in_t int1;
424 
425  // Output pins
426 
427  digital_out_t st;
428 
429  // Modules
430 
431  i2c_master_t i2c;
432 
433  // ctx variable
434 
435  uint8_t slave_address;
436 
437 } earthquake_t;
438 
442 typedef struct
443 {
444  // Communication gpio pins
445 
446  pin_name_t scl;
447  pin_name_t sda;
448 
449  // Additional gpio pins
450 
451  pin_name_t st;
452  pin_name_t int2;
453  pin_name_t int1;
454 
455  // static variable
456 
457  uint8_t i2c_speed;
458  uint8_t i2c_address;
459 
461  // End types group
463 
464 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
465 
471 #ifdef __cplusplus
472 extern "C"{
473 #endif
474 
484 
493 
502 
513 void earthquake_generic_write ( earthquake_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len );
514 
526 void earthquake_generic_read ( earthquake_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len );
527 
541 uint8_t earthquake_proc_notify ( earthquake_t *ctx );
542 
555 uint8_t earthquake_shutoff_output ( earthquake_t *ctx );
556 
570 uint8_t earthquake_read_status ( earthquake_t *ctx );
571 
581 uint16_t earthquake_read_si ( earthquake_t *ctx );
582 
593 
594 #ifdef __cplusplus
595 }
596 #endif
597 #endif // _EARTHQUAKE_H_
598  // End public_function group
601 
602 // ------------------------------------------------------------------------- END
pin_name_t st
Definition: earthquake.h:451
digital_in_t int1
Definition: earthquake.h:423
pin_name_t sda
Definition: earthquake.h:447
void earthquake_default_cfg(earthquake_t *ctx)
Click Default Configuration function.
uint8_t earthquake_read_status(earthquake_t *ctx)
Read status function.
uint8_t earthquake_proc_notify(earthquake_t *ctx)
Shutoff output function.
i2c_master_t i2c
Definition: earthquake.h:431
uint8_t i2c_speed
Definition: earthquake.h:457
uint16_t earthquake_read_si(earthquake_t *ctx)
Read SI function.
EARTHQUAKE_RETVAL earthquake_init(earthquake_t *ctx, earthquake_cfg_t *cfg)
Initialization function.
void earthquake_generic_write(earthquake_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
#define EARTHQUAKE_RETVAL
Definition: earthquake.h:75
void earthquake_cfg_setup(earthquake_cfg_t *cfg)
Config Object Initialization function.
uint8_t slave_address
Definition: earthquake.h:435
void earthquake_clear_mememory(earthquake_t *ctx)
Clear Memory function.
pin_name_t int1
Definition: earthquake.h:453
digital_out_t st
Definition: earthquake.h:427
pin_name_t int2
Definition: earthquake.h:452
digital_in_t int2
Definition: earthquake.h:422
void earthquake_generic_read(earthquake_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
Click ctx object definition.
Definition: earthquake.h:418
pin_name_t scl
Definition: earthquake.h:446
uint8_t i2c_address
Definition: earthquake.h:458
Click configuration structure definition.
Definition: earthquake.h:442
uint8_t earthquake_shutoff_output(earthquake_t *ctx)
Shutoff output function.