accel10  2.0.0.0
accel10.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 ACCEL10_H
36 #define ACCEL10_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 #include "drv_spi_master.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define ACCEL10_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
57  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
58  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
59  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
60  cfg.it1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
61  cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_INT )
62 
68 #define ACCEL10_MASTER_I2C 0
69 #define ACCEL10_MASTER_SPI 1
70 
76 #define ACCEL10_RETVAL uint8_t
77 
78 #define ACCEL10_OK 0x00
79 #define ACCEL10_INIT_ERROR 0xFF
80 
86 #define ACCEL10_SLAVE_ADDRESS_GND 0x18
87 #define ACCEL10_SLAVE_ADDRESS_VCC 0x19
88 
94 #define ACCEL10_REG_OUT_T_L 0x0D
95 #define ACCEL10_REG_OUT_T_H 0x0E
96 #define ACCEL10_REG_WHO_AM_I 0x0F
97 #define ACCEL10_REG_CTRL1 0x20
98 #define ACCEL10_REG_CTRL2 0x21
99 #define ACCEL10_REG_CTRL3 0x22
100 #define ACCEL10_REG_CTRL4_INT1_PAD_CTRL 0x23
101 #define ACCEL10_REG_CTRL5_INT2_PAD_CTRL 0x24
102 #define ACCEL10_REG_CTRL6 0x25
103 #define ACCEL10_REG_OUT_T 0x26
104 #define ACCEL10_REG_STATUS 0x27
105 #define ACCEL10_REG_OUT_X_L 0x28
106 #define ACCEL10_REG_OUT_X_H 0x29
107 #define ACCEL10_REG_OUT_Y_L 0x2A
108 #define ACCEL10_REG_OUT_Y_H 0x2B
109 #define ACCEL10_REG_OUT_Z_L 0x2C
110 #define ACCEL10_REG_OUT_Z_H 0x2D
111 #define ACCEL10_REG_FIFO_CTRL 0x2E
112 #define ACCEL10_REG_FIFO_SAMPLES 0x2F
113 #define ACCEL10_REG_TAP_THS_X 0x30
114 #define ACCEL10_REG_TAP_THS_Y 0x31
115 #define ACCEL10_REG_TAP_THS_Z 0x32
116 #define ACCEL10_REG_INT_DUR 0x33
117 #define ACCEL10_REG_WAKE_UP_THS 0x34
118 #define ACCEL10_REG_WAKE_UP_DUR 0x35
119 #define ACCEL10_REG_FREE_FALL 0x36
120 #define ACCEL10_REG_STATUS_DUP 0x37
121 #define ACCEL10_REG_WAKE_UP_SRC 0x38
122 #define ACCEL10_REG_TAP_SRC 0x39
123 #define ACCEL10_REG_SIXD_SRC 0x3A
124 #define ACCEL10_REG_ALL_INT_SRC 0x3B
125 #define ACCEL10_REG_X_OFS_USR 0x3C
126 #define ACCEL10_REG_Y_OFS_USR 0x3D
127 #define ACCEL10_REG_Z_OFS_USR 0x3E
128 #define ACCEL10_REG_CTRL_REG7 0x3F
129 
135 #define ACCEL10_WHO_AM_I_DEFAULT_VALUE 0x44
136 
147 #define ACCEL10_LP_MODE_1 0x00
148 #define ACCEL10_LP_MODE_2 0x01
149 #define ACCEL10_LP_MODE_3 0x02
150 #define ACCEL10_LP_MODE_4 0x03
151 
157 #define ACCEL10_MODE_LOW_POWER 0x00
158 #define ACCEL10_MODE_HIGH_PERF 0x04
159 #define ACCEL10_MODE_SINGLE_CONV 0x08
160 
166 #define ACCEL10_ODR_POWER_DOWN 0x00
167 #define ACCEL10_ODR_12_5_1_6HZ 0x10
168 #define ACCEL10_ODR_12_5Hz 0x20
169 #define ACCEL10_ODR_25Hz 0x30
170 #define ACCEL10_ODR_50Hz 0x40
171 #define ACCEL10_ODR_100Hz 0x50
172 #define ACCEL10_ODR_200Hz 0x60
173 #define ACCEL10_ODR_400_200Hz 0x70
174 #define ACCEL10_ODR_800_200Hz 0x80
175 #define ACCEL10_ODR_1600_200Hz 0x90
176 
189 #define ACCEL10_SIM_4_WIRE 0x00
190 #define ACCEL10_SIM_3_WIRE 0x01
191 
197 #define ACCEL10_I2C_ENABLE_I2C_AND_SPI 0x00
198 #define ACCEL10_I2C_ENABLE_SPI_ONLY 0x02
199 
205 #define ACCEL10_IF_ADD_INC_DISABLE 0x00
206 #define ACCEL10_IF_ADD_INC_ENABLE 0x04
207 
213 #define ACCEL10_BDU_CONTINUOUS_UPDATE 0x00
214 #define ACCEL10_BDU_NOT_UPDATE_MSB_LSB 0x08
215 
221 #define ACCEL10_CS_PU_DISC_CONNECT 0x00
222 #define ACCEL10_CS_PU_DISC_DISCONNECT 0x10
223 
229 #define ACCEL10_SOFT_RESET_DISABLE 0x00
230 #define ACCEL10_SOFT_RESET_ENABLE 0x40
231 
237 #define ACCEL10_BOOT_DISABLE 0x00
238 #define ACCEL10_BOOT_ENABLE 0x80
239 
252 #define ACCEL10_SLP_MODE_1_CONV_START 0x01
253 
259 #define ACCEL10_SLP_MODE_SEL_EN_INT2 0x00
260 #define ACCEL10_SLP_MODE_SEL_EN_MODE1 0x02
261 
267 #define ACCEL10_H_LACTIVE_HIGH 0x00
268 #define ACCEL10_H_LACTIVE_LOW 0x08
269 
275 #define ACCEL10_LIR_NOT_LATCHED 0x00
276 #define ACCEL10_LIR_LATCHED 0x10
277 
283 #define ACCEL10_PP_OD_PUSH_PULL 0x00
284 #define ACCEL10_PP_OD_OPEN_DRAIN 0x20
285 
291 #define ACCEL10_ST_NORMAL 0x00
292 #define ACCEL10_ST_POSITIVE 0x40
293 #define ACCEL10_ST_NEGATIVE 0x80
294 
306 #define ACCEL10_INT1_DRDY_DISABLE 0x00
307 #define ACCEL10_INT1_DRDY_ENABLE 0x01
308 
314 #define ACCEL10_INT1_FTH_DISABLE 0x00
315 #define ACCEL10_INT1_FTH_ENABLE 0x02
316 
322 #define ACCEL10_INT1_DIFF5_DISABLE 0x00
323 #define ACCEL10_INT1_DIFF5_ENABLE 0x04
324 
330 #define ACCEL10_INT1_TAP_DISABLE 0x00
331 #define ACCEL10_INT1_TAP_ENABLE 0x08
332 
338 #define ACCEL10_INT1_FF_DISABLE 0x00
339 #define ACCEL10_INT1_FF_ENABLE 0x10
340 
346 #define ACCEL10_INT1_WU_DISABLE 0x00
347 #define ACCEL10_INT1_WU_ENABLE 0x20
348 
354 #define ACCEL10_INT1_SINGLE_TAP_DISABLE 0x00
355 #define ACCEL10_INT1_SINGLE_TAP_ENABLE 0x40
356 
362 #define ACCEL10_INT1_6D_DISABLE 0x00
363 #define ACCEL10_INT1_6D_ENABLE 0x80
364 
375 #define ACCEL10_INT2_DRDY_DISABLE 0x00
376 #define ACCEL10_INT2_DRDY_ENABLE 0x01
377 
383 #define ACCEL10_INT2_FTH_DISABLE 0x00
384 #define ACCEL10_INT2_FTH_ENABLE 0x02
385 
391 #define ACCEL10_INT2_DIFF5_DISABLE 0x00
392 #define ACCEL10_INT2_DIFF5_ENABLE 0x04
393 
399 #define ACCEL10_INT2_OVR_DISABLE 0x00
400 #define ACCEL10_INT2_OVR_ENABLE 0x08
401 
407 #define ACCEL10_INT2_DRDY_T_DISABLE 0x00
408 #define ACCEL10_INT2_DRDY_T_ENABLE 0x10
409 
415 #define ACCEL10_INT2_BOOT_DISABLE 0x00
416 #define ACCEL10_INT2_BOOT_ENABLE 0x20
417 
423 #define ACCEL10_INT2_SLEEP_CHG_DISABLE 0x00
424 #define ACCEL10_INT2_SLEEP_CHG_ENABLE 0x40
425 
431 #define ACCEL10_INT2_SLEEP_STATE_DISABLE 0x00
432 #define ACCEL10_INT2_SLEEP_STATE_ENABLE 0x80
433 
444 #define ACCEL10_LOW_NOISE_DISABLE 0x00
445 #define ACCEL10_LOW_NOISE_ENABLE 0x04
446 
452 #define ACCEL10_FSD_LOW_PASS 0x00
453 #define ACCEL10_FSD_HIGH_PASS 0x08
454 
460 #define ACCEL10_FS_2G 0x00
461 #define ACCEL10_FS_4G 0x10
462 #define ACCEL10_FS_8G 0x20
463 #define ACCEL10_FS_16G 0x30
464 
470 #define ACCEL10_BW_FILT_ODR2 0x00
471 #define ACCEL10_BW_FILT_ODR4 0x40
472 #define ACCEL10_BW_FILT_ODR10 0x80
473 #define ACCEL10_BW_FILT_ODR20 0xC0
474 
481 #define ACCEL10_STATUS_DATA_READY 0x01
482 
488 #define ACCEL10_ERROR 0x00
489 #define ACCEL10_SUCCESS 0x01
490  // End group macro
493 // --------------------------------------------------------------- PUBLIC TYPES
502 typedef uint8_t accel10_select_t;
503 
507 typedef void ( *accel10_master_io_t )( struct accel10_s*, uint8_t, uint8_t*, uint8_t );
508 
512 typedef struct accel10_s
513 {
514  // Input pins
515 
516  digital_out_t cs;
517  digital_in_t it1;
518  digital_in_t it2;
519 
520  // Modules
521 
522  i2c_master_t i2c;
523  spi_master_t spi;
524 
525  // ctx variable
526 
527  uint8_t slave_address;
528  pin_name_t chip_select;
532 
533 } accel10_t;
534 
538 typedef struct
539 {
540  // Communication gpio pins
541 
542  pin_name_t scl;
543  pin_name_t sda;
544  pin_name_t miso;
545  pin_name_t mosi;
546  pin_name_t sck;
547  pin_name_t cs;
548 
549  // Additional gpio pins
550 
551  pin_name_t it1;
552  pin_name_t it2;
553 
554  // static variable
555 
556  uint32_t i2c_speed;
557  uint8_t i2c_address;
558 
559  uint32_t spi_speed;
560  spi_master_mode_t spi_mode;
561  spi_master_chip_select_polarity_t cs_polarity;
562 
564 
565 } accel10_cfg_t;
566 
570 typedef struct
571 {
572  int16_t x;
573  int16_t y;
574  int16_t z;
575 }
577  // End types group
579 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
585 #ifdef __cplusplus
586 extern "C"{
587 #endif
588 
597 void accel10_cfg_setup ( accel10_cfg_t *cfg );
598 
608 
649 void accel10_default_cfg ( accel10_t *ctx );
650 
661 void accel10_generic_write ( accel10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
662 
673 void accel10_generic_read ( accel10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
674 
689 
702 uint8_t accel10_check_data_ready ( accel10_t *ctx );
703 
712 void accel10_soft_reset ( accel10_t *ctx );
713 
724 void accel10_get_data ( accel10_t *ctx, accel10_data_t *p_accel_data );
725 
736 int8_t accel10_read_temperature ( accel10_t *ctx );
737 
751 uint8_t accel10_check_it1 ( accel10_t *ctx );
752 
766 uint8_t accel10_check_it2 ( accel10_t *ctx );
767 
768 #ifdef __cplusplus
769 }
770 #endif
771 #endif // _ACCEL10_H_
772  // End public_function group
775 
776 // ------------------------------------------------------------------------- END
accel10_cfg_t::cs
pin_name_t cs
Definition: accel10.h:547
accel10_data_t::y
int16_t y
Definition: accel10.h:573
accel10_cfg_t::sck
pin_name_t sck
Definition: accel10.h:546
accel10_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: accel10.h:560
accel10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: accel10.h:556
accel10_cfg_t::it2
pin_name_t it2
Definition: accel10.h:552
accel10_cfg_t::i2c_address
uint8_t i2c_address
Definition: accel10.h:557
accel10_s::it1
digital_in_t it1
Definition: accel10.h:517
accel10_s::chip_select
pin_name_t chip_select
Definition: accel10.h:528
accel10_cfg_t::it1
pin_name_t it1
Definition: accel10.h:551
accel10_s::i2c
i2c_master_t i2c
Definition: accel10.h:522
accel10_generic_read
void accel10_generic_read(accel10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
accel10_get_data
void accel10_get_data(accel10_t *ctx, accel10_data_t *p_accel_data)
Read Accel data function.
accel10_cfg_t::spi_speed
uint32_t spi_speed
Definition: accel10.h:559
accel10_soft_reset
void accel10_soft_reset(accel10_t *ctx)
Soft reset function.
accel10_cfg_t::miso
pin_name_t miso
Definition: accel10.h:544
accel10_check_data_ready
uint8_t accel10_check_data_ready(accel10_t *ctx)
Check data ready function.
accel10_cfg_t::mosi
pin_name_t mosi
Definition: accel10.h:545
accel10_cfg_t
Click configuration structure definition.
Definition: accel10.h:538
accel10_check_id
ACCEL10_RETVAL accel10_check_id(accel10_t *ctx)
Check ID function.
accel10_s
Click ctx object definition.
Definition: accel10.h:512
accel10_master_io_t
void(* accel10_master_io_t)(struct accel10_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: accel10.h:507
accel10_data_t::z
int16_t z
Definition: accel10.h:574
accel10_s::cs
digital_out_t cs
Definition: accel10.h:516
accel10_t
struct accel10_s accel10_t
Click ctx object definition.
accel10_read_temperature
int8_t accel10_read_temperature(accel10_t *ctx)
Read temperature function.
accel10_default_cfg
void accel10_default_cfg(accel10_t *ctx)
Click Default Configuration function.
accel10_data_t
Accel data structure definition.
Definition: accel10.h:570
accel10_select_t
uint8_t accel10_select_t
Communication type.
Definition: accel10.h:502
accel10_init
ACCEL10_RETVAL accel10_init(accel10_t *ctx, accel10_cfg_t *cfg)
Initialization function.
accel10_s::master_sel
accel10_select_t master_sel
Definition: accel10.h:531
accel10_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: accel10.h:561
accel10_check_it2
uint8_t accel10_check_it2(accel10_t *ctx)
Get interrupt 2 ststus function.
accel10_cfg_t::sda
pin_name_t sda
Definition: accel10.h:543
accel10_cfg_t::sel
accel10_select_t sel
Definition: accel10.h:563
accel10_cfg_setup
void accel10_cfg_setup(accel10_cfg_t *cfg)
Config Object Initialization function.
accel10_s::slave_address
uint8_t slave_address
Definition: accel10.h:527
accel10_generic_write
void accel10_generic_write(accel10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
ACCEL10_RETVAL
#define ACCEL10_RETVAL
Definition: accel10.h:76
accel10_cfg_t::scl
pin_name_t scl
Definition: accel10.h:542
accel10_s::read_f
accel10_master_io_t read_f
Definition: accel10.h:530
accel10_s::spi
spi_master_t spi
Definition: accel10.h:523
accel10_check_it1
uint8_t accel10_check_it1(accel10_t *ctx)
Get interrupt 1 ststus function.
accel10_s::write_f
accel10_master_io_t write_f
Definition: accel10.h:529
accel10_data_t::x
int16_t x
Definition: accel10.h:572
accel10_s::it2
digital_in_t it2
Definition: accel10.h:518