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
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 EARTHQUAKE_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.st = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70 cfg.int2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
71 cfg.int1 = MIKROBUS( mikrobus, MIKROBUS_INT );
78#define EARTHQUAKE_STANDBY_MODE 0
79#define EARTHQUAKE_NORMAL_MODE 1
80#define EARTHQUAKE_INIT_INST 2
81#define EARTHQUAKE_OFFSET_ACQ 3
82#define EARTHQUAKE_SELF_DIAGNOSTIC 4
89#define EARTHQUAKE_RETVAL uint8_t
90
91#define EARTHQUAKE_OK 0x00
92#define EARTHQUAKE_INIT_ERROR 0xFF
95 // End group macro
96
97// -------------------------------------------------------------- PRIVATE MACROS
107#define EARTHQUAKE_I2C_ADDRESS 0x55
114#define EARTHQUAKE_CLICK_ERR 0xFF
115#define EARTHQUAKE_CLICK_OK 0x00
122#define EARTHQUAKE_STATE 0x1000
123#define EARTHQUAKE_AXIS_STATE 0x1001
124#define EARTHQUAKE_EVENT 0x1002
131#define EARTHQUAKE_MODE 0x1003
132#define EARTHQUAKE_CTRL 0x1004
133#define EARTHQUAKE_CLEAR_COMMAND 0x1005
140#define EARTHQUAKE_MAIN_SI_H 0x2000
141#define EARTHQUAKE_MAIN_SI_L 0x2001
142#define EARTHQUAKE_MAIN_PGA_H 0x2002
143#define EARTHQUAKE_MAIN_PGA_L 0x2003
150#define EARTHQUAKE_N1_MAIN_OFFSET_X_H 0x3000
151#define EARTHQUAKE_N1_MAIN_OFFSET_X_L 0x3001
152#define EARTHQUAKE_N1_MAIN_OFFSET_Y_H 0x3002
153#define EARTHQUAKE_N1_MAIN_OFFSET_Y_L 0x3003
154#define EARTHQUAKE_N1_MAIN_OFFSET_Z_H 0x3004
155#define EARTHQUAKE_N1_MAIN_OFFSET_Z_L 0x3005
156
157#define EARTHQUAKE_N1_MAIN_T_AVE_H 0x3006
158#define EARTHQUAKE_N1_MAIN_T_AVE_L 0x3007
159#define EARTHQUAKE_N1_MAIN_SI_H 0x3008
160#define EARTHQUAKE_N1_MAIN_SI_L 0x3009
161#define EARTHQUAKE_N1_MAIN_PGA_H 0x300A
162#define EARTHQUAKE_N1_MAIN_PGA_L 0x300B
169#define EARTHQUAKE_N2_MAIN_OFFSET_X_H 0x3100
170#define EARTHQUAKE_N2_MAIN_OFFSET_X_L 0x3101
171#define EARTHQUAKE_N2_MAIN_OFFSET_Y_H 0x3102
172#define EARTHQUAKE_N2_MAIN_OFFSET_Y_L 0x3103
173#define EARTHQUAKE_N2_MAIN_OFFSET_Z_H 0x3104
174#define EARTHQUAKE_N2_MAIN_OFFSET_Z_L 0x3105
175
176#define EARTHQUAKE_N2_MAIN_T_AVE_H 0x3106
177#define EARTHQUAKE_N2_MAIN_T_AVE_L 0x3107
178#define EARTHQUAKE_N2_MAIN_SI_H 0x3108
179#define EARTHQUAKE_N2_MAIN_SI_L 0x3109
180#define EARTHQUAKE_N2_MAIN_PGA_H 0x310A
181#define EARTHQUAKE_N2_MAIN_PGA_L 0x310B
188#define EARTHQUAKE_N3_MAIN_OFFSET_X_H 0x3200
189#define EARTHQUAKE_N3_MAIN_OFFSET_X_L 0x3201
190#define EARTHQUAKE_N3_MAIN_OFFSET_Y_H 0x3202
191#define EARTHQUAKE_N3_MAIN_OFFSET_Y_L 0x3203
192#define EARTHQUAKE_N3_MAIN_OFFSET_Z_H 0x3204
193#define EARTHQUAKE_N3_MAIN_OFFSET_Z_L 0x3205
194
195#define EARTHQUAKE_N3_MAIN_T_AVE_H 0x3206
196#define EARTHQUAKE_N3_MAIN_T_AVE_L 0x3207
197#define EARTHQUAKE_N3_MAIN_SI_H 0x3208
198#define EARTHQUAKE_N3_MAIN_SI_L 0x3209
199#define EARTHQUAKE_N3_MAIN_PGA_H 0x320A
200#define EARTHQUAKE_N3_MAIN_PGA_L 0x320B
207#define EARTHQUAKE_N4_MAIN_OFFSET_X_H 0x3300
208#define EARTHQUAKE_N4_MAIN_OFFSET_X_L 0x3301
209#define EARTHQUAKE_N4_MAIN_OFFSET_Y_H 0x3302
210#define EARTHQUAKE_N4_MAIN_OFFSET_Y_L 0x3303
211#define EARTHQUAKE_N4_MAIN_OFFSET_Z_H 0x3304
212#define EARTHQUAKE_N4_MAIN_OFFSET_Z_L 0x3305
213
214#define EARTHQUAKE_N4_MAIN_T_AVE_H 0x3306
215#define EARTHQUAKE_N4_MAIN_T_AVE_L 0x3307
216#define EARTHQUAKE_N4_MAIN_SI_H 0x3308
217#define EARTHQUAKE_N4_MAIN_SI_L 0x3309
218#define EARTHQUAKE_N4_MAIN_PGA_H 0x330A
219#define EARTHQUAKE_N4_MAIN_PGA_L 0x330B
226#define EARTHQUAKE_N5_MAIN_OFFSET_X_H 0x3400
227#define EARTHQUAKE_N5_MAIN_OFFSET_X_L 0x3401
228#define EARTHQUAKE_N5_MAIN_OFFSET_Y_H 0x3402
229#define EARTHQUAKE_N5_MAIN_OFFSET_Y_L 0x3403
230#define EARTHQUAKE_N5_MAIN_OFFSET_Z_H 0x3404
231#define EARTHQUAKE_N5_MAIN_OFFSET_Z_L 0x3405
232
233#define EARTHQUAKE_N5_MAIN_T_AVE_H 0x3406
234#define EARTHQUAKE_N5_MAIN_T_AVE_L 0x3407
235#define EARTHQUAKE_N5_MAIN_SI_H 0x3408
236#define EARTHQUAKE_N5_MAIN_SI_L 0x3409
237#define EARTHQUAKE_N5_MAIN_PGA_H 0x340A
238#define EARTHQUAKE_N5_MAIN_PGA_L 0x340B
245#define EARTHQUAKE_M1_MAIN_OFFSET_X_H 0x3500
246#define EARTHQUAKE_M1_MAIN_OFFSET_X_L 0x3501
247#define EARTHQUAKE_M1_MAIN_OFFSET_Y_H 0x3502
248#define EARTHQUAKE_M1_MAIN_OFFSET_Y_L 0x3503
249#define EARTHQUAKE_M1_MAIN_OFFSET_Z_H 0x3504
250#define EARTHQUAKE_M1_MAIN_OFFSET_Z_L 0x3505
251
252#define EARTHQUAKE_M1_MAIN_T_AVE_H 0x3506
253#define EARTHQUAKE_M1_MAIN_T_AVE_L 0x3507
254#define EARTHQUAKE_M1_MAIN_SI_H 0x3508
255#define EARTHQUAKE_M1_MAIN_SI_L 0x3509
256#define EARTHQUAKE_M1_MAIN_PGA_H 0x350A
257#define EARTHQUAKE_M1_MAIN_PGA_L 0x350B
264#define EARTHQUAKE_M2_MAIN_OFFSET_X_H 0x3600
265#define EARTHQUAKE_M2_MAIN_OFFSET_X_L 0x3601
266#define EARTHQUAKE_M2_MAIN_OFFSET_Y_H 0x3602
267#define EARTHQUAKE_M2_MAIN_OFFSET_Y_L 0x3603
268#define EARTHQUAKE_M2_MAIN_OFFSET_Z_H 0x3604
269#define EARTHQUAKE_M2_MAIN_OFFSET_Z_L 0x3605
270
271#define EARTHQUAKE_M2_MAIN_T_AVE_H 0x3606
272#define EARTHQUAKE_M2_MAIN_T_AVE_L 0x3607
273#define EARTHQUAKE_M2_MAIN_SI_H 0x3608
274#define EARTHQUAKE_M2_MAIN_SI_L 0x3609
275#define EARTHQUAKE_M2_MAIN_PGA_H 0x360A
276#define EARTHQUAKE_M2_MAIN_PGA_L 0x360B
283#define EARTHQUAKE_M3_MAIN_OFFSET_X_H 0x3700
284#define EARTHQUAKE_M3_MAIN_OFFSET_X_L 0x3701
285#define EARTHQUAKE_M3_MAIN_OFFSET_Y_H 0x3702
286#define EARTHQUAKE_M3_MAIN_OFFSET_Y_L 0x3703
287#define EARTHQUAKE_M3_MAIN_OFFSET_Z_H 0x3704
288#define EARTHQUAKE_M3_MAIN_OFFSET_Z_L 0x3705
289
290#define EARTHQUAKE_M3_MAIN_T_AVE_H 0x3706
291#define EARTHQUAKE_M3_MAIN_T_AVE_L 0x3707
292#define EARTHQUAKE_M3_MAIN_SI_H 0x3708
293#define EARTHQUAKE_M3_MAIN_SI_L 0x3709
294#define EARTHQUAKE_M3_MAIN_PGA_H 0x370A
295#define EARTHQUAKE_M3_MAIN_PGA_L 0x370B
302#define EARTHQUAKE_M4_MAIN_OFFSET_X_H 0x3800
303#define EARTHQUAKE_M4_MAIN_OFFSET_X_L 0x3801
304#define EARTHQUAKE_M4_MAIN_OFFSET_Y_H 0x3802
305#define EARTHQUAKE_M4_MAIN_OFFSET_Y_L 0x3803
306#define EARTHQUAKE_M4_MAIN_OFFSET_Z_H 0x3804
307#define EARTHQUAKE_M4_MAIN_OFFSET_Z_L 0x3805
308
309#define EARTHQUAKE_M4_MAIN_T_AVE_H 0x3806
310#define EARTHQUAKE_M4_MAIN_T_AVE_L 0x3807
311#define EARTHQUAKE_M4_MAIN_SI_H 0x3808
312#define EARTHQUAKE_M4_MAIN_SI_L 0x3809
313#define EARTHQUAKE_M4_MAIN_PGA_H 0x380A
314#define EARTHQUAKE_M4_MAIN_PGA_L 0x380B
321#define EARTHQUAKE_M5_MAIN_OFFSET_X_H 0x3900
322#define EARTHQUAKE_M5_MAIN_OFFSET_X_L 0x3901
323#define EARTHQUAKE_M5_MAIN_OFFSET_Y_H 0x3902
324#define EARTHQUAKE_M5_MAIN_OFFSET_Y_L 0x3903
325#define EARTHQUAKE_M5_MAIN_OFFSET_Z_H 0x3904
326#define EARTHQUAKE_M5_MAIN_OFFSET_Z_L 0x3905
327
328#define EARTHQUAKE_M5_MAIN_T_AVE_H 0x3906
329#define EARTHQUAKE_M5_MAIN_T_AVE_L 0x3907
330#define EARTHQUAKE_M5_MAIN_SI_H 0x3908
331#define EARTHQUAKE_M5_MAIN_SI_L 0x3909
332#define EARTHQUAKE_M5_MAIN_PGA_H 0x390A
333#define EARTHQUAKE_M5_MAIN_PGA_L 0x390B
340#define EARTHQUAKE_OFFSET_SET_X_H 0x4000
341#define EARTHQUAKE_OFFSET_SET_X_L 0x4001
342#define EARTHQUAKE_OFFSET_SET_Y_H 0x4002
343#define EARTHQUAKE_OFFSET_SET_Y_L 0x4003
344#define EARTHQUAKE_OFFSET_SET_Z_H 0x4004
345#define EARTHQUAKE_OFFSET_SET_Z_L 0x4005
346
347#define EARTHQUAKE_OFFSET_SET_T_AVE_H 0x4006
348#define EARTHQUAKE_OFFSET_SET_T_AVE_L 0x4007
349#define EARTHQUAKE_OFFSET_SET_MAX_X_H 0x4008
350#define EARTHQUAKE_OFFSET_SET_MAX_X_L 0x4009
351#define EARTHQUAKE_OFFSET_SET_MAX_Y_H 0x400A
352#define EARTHQUAKE_OFFSET_SET_MAX_Y_L 0x400B
353#define EARTHQUAKE_OFFSET_SET_MAX_Z_H 0x400C
354#define EARTHQUAKE_OFFSET_SET_MAX_Z_L 0x400D
355
356#define EARTHQUAKE_OFFSET_SET_MIN_X_H 0x400E
357#define EARTHQUAKE_OFFSET_SET_MIN_X_L 0x400F
358#define EARTHQUAKE_OFFSET_SET_MIN_Y_H 0x4010
359#define EARTHQUAKE_OFFSET_SET_MIN_Y_L 0x4011
360#define EARTHQUAKE_OFFSET_SET_MIN_Z_H 0x4012
361#define EARTHQUAKE_OFFSET_SET_MIN_Z_L 0x4013
362
363#define EARTHQUAKE_OFFSET_SET_AXIS 0x4014
370#define EARTHQUAKE_OFFSET_RECENT_X_H 0x4100
371#define EARTHQUAKE_OFFSET_RECENT_X_L 0x4101
372#define EARTHQUAKE_OFFSET_RECENT_Y_H 0x4102
373#define EARTHQUAKE_OFFSET_RECENT_Y_L 0x4103
374#define EARTHQUAKE_OFFSET_RECENT_Z_H 0x4104
375#define EARTHQUAKE_OFFSET_RECENT_Z_L 0x4105
376
377#define EARTHQUAKE_OFFSET_RECENT_T_AVE_H 0x4106
378#define EARTHQUAKE_OFFSET_RECENT_T_AVE_L 0x4107
379
380#define EARTHQUAKE_OFFSET_RECENT_MAX_X_H 0x4108
381#define EARTHQUAKE_OFFSET_RECENT_MAX_X_L 0x4109
382#define EARTHQUAKE_OFFSET_RECENT_MAX_Y_H 0x410A
383#define EARTHQUAKE_OFFSET_RECENT_MAX_Y_L 0x410B
384#define EARTHQUAKE_OFFSET_RECENT_MAX_Z_H 0x410C
385#define EARTHQUAKE_OFFSET_RECENT_MAX_Z_L 0x410D
386
387#define EARTHQUAKE_OFFSET_RECENT_MIN_X_H 0x410E
388#define EARTHQUAKE_OFFSET_RECENT_MIN_X_L 0x410F
389#define EARTHQUAKE_OFFSET_RECENT_MIN_Y_H 0x4110
390#define EARTHQUAKE_OFFSET_RECENT_MIN_Y_L 0x4111
391#define EARTHQUAKE_OFFSET_RECENT_MIN_Z_H 0x4112
392#define EARTHQUAKE_OFFSET_RECENT_MIN_Z_L 0x4113
393
394#define EARTHQUAKE_OFFSET_RECENT_STATE 0x4114
401#define EARTHQUAKE_SELFTEST_BEFORE_X_H 0x4200
402#define EARTHQUAKE_SELFTEST_BEFORE_X_L 0x4201
403#define EARTHQUAKE_SELFTEST_AFTER_X_H 0x4202
404#define EARTHQUAKE_SELFTEST_AFTER_X_L 0x4203
405#define EARTHQUAKE_SELFTEST_BEFORE_Y_H 0x4204
406#define EARTHQUAKE_SELFTEST_BEFORE_Y_L 0x4205
407#define EARTHQUAKE_SELFTEST_AFTER_Y_H 0x4206
408#define EARTHQUAKE_SELFTEST_AFTER_Y_L 0x4207
409#define EARTHQUAKE_SELFTEST_BEFORE_Z_H 0x4208
410#define EARTHQUAKE_SELFTEST_BEFORE_Z_L 0x4209
411#define EARTHQUAKE_SELFTEST_AFTER_Z_H 0x420A
412#define EARTHQUAKE_SELFTEST_AFTER_Z_L 0x420B
413
414#define EARTHQUAKE_SELFTEST_T_AVE_H 0x420C
415#define EARTHQUAKE_SELFTEST_T_AVE_L 0x420D
416
417#define EARTHQUAKE_SELFTEST_ERROR 0x420E
421 // End group macro
422
423// --------------------------------------------------------------- PUBLIC TYPES
432typedef struct
433{
434 // Input pins
435
436 digital_in_t int2;
437 digital_in_t int1;
438
439 // Output pins
440
441 digital_out_t st;
442
443 // Modules
444
445 i2c_master_t i2c;
446
447 // ctx variable
448
450
452
456typedef struct
457{
458 // Communication gpio pins
459
460 pin_name_t scl;
461 pin_name_t sda;
462
463 // Additional gpio pins
464
465 pin_name_t st;
466 pin_name_t int2;
467 pin_name_t int1;
468
469 // static variable
470
471 uint8_t i2c_speed;
472 uint8_t i2c_address;
473
475
476 // End types group
477
478// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
479
485#ifdef __cplusplus
486extern "C"{
487#endif
488
498
507
518void earthquake_generic_write ( earthquake_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len );
519
531void earthquake_generic_read ( earthquake_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len );
532
547
561
576
587
598
599#ifdef __cplusplus
600}
601#endif
602#endif // _EARTHQUAKE_H_
603
604 // End public_function group
606
607// ------------------------------------------------------------------------- END
#define EARTHQUAKE_RETVAL
Definition earthquake.h:89
void earthquake_clear_memory(earthquake_t *ctx)
Clear Memory function.
void earthquake_generic_write(earthquake_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t earthquake_shutoff_output(earthquake_t *ctx)
Shutoff output function.
uint8_t earthquake_read_status(earthquake_t *ctx)
Read status function.
EARTHQUAKE_RETVAL earthquake_init(earthquake_t *ctx, earthquake_cfg_t *cfg)
Initialization function.
uint16_t earthquake_read_si(earthquake_t *ctx)
Read SI function.
uint8_t earthquake_proc_notify(earthquake_t *ctx)
Shutoff output function.
void earthquake_cfg_setup(earthquake_cfg_t *cfg)
Config Object Initialization function.
void earthquake_generic_read(earthquake_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
Click configuration structure definition.
Definition earthquake.h:457
pin_name_t int1
Definition earthquake.h:467
pin_name_t st
Definition earthquake.h:465
pin_name_t int2
Definition earthquake.h:466
pin_name_t scl
Definition earthquake.h:460
uint8_t i2c_speed
Definition earthquake.h:471
pin_name_t sda
Definition earthquake.h:461
uint8_t i2c_address
Definition earthquake.h:472
Click ctx object definition.
Definition earthquake.h:433
digital_in_t int2
Definition earthquake.h:436
digital_in_t int1
Definition earthquake.h:437
i2c_master_t i2c
Definition earthquake.h:445
digital_out_t st
Definition earthquake.h:441
uint8_t slave_address
Definition earthquake.h:449