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 
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 #include "drv_spi_master.h"
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define ACCEL10_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
71  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
72  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
73  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
74  cfg.it1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
75  cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_INT )
76 
82 #define ACCEL10_MASTER_I2C 0
83 #define ACCEL10_MASTER_SPI 1
84 
90 #define ACCEL10_RETVAL uint8_t
91 
92 #define ACCEL10_OK 0x00
93 #define ACCEL10_INIT_ERROR 0xFF
94 
100 #define ACCEL10_SLAVE_ADDRESS_GND 0x18
101 #define ACCEL10_SLAVE_ADDRESS_VCC 0x19
102 
108 #define ACCEL10_REG_OUT_T_L 0x0D
109 #define ACCEL10_REG_OUT_T_H 0x0E
110 #define ACCEL10_REG_WHO_AM_I 0x0F
111 #define ACCEL10_REG_CTRL1 0x20
112 #define ACCEL10_REG_CTRL2 0x21
113 #define ACCEL10_REG_CTRL3 0x22
114 #define ACCEL10_REG_CTRL4_INT1_PAD_CTRL 0x23
115 #define ACCEL10_REG_CTRL5_INT2_PAD_CTRL 0x24
116 #define ACCEL10_REG_CTRL6 0x25
117 #define ACCEL10_REG_OUT_T 0x26
118 #define ACCEL10_REG_STATUS 0x27
119 #define ACCEL10_REG_OUT_X_L 0x28
120 #define ACCEL10_REG_OUT_X_H 0x29
121 #define ACCEL10_REG_OUT_Y_L 0x2A
122 #define ACCEL10_REG_OUT_Y_H 0x2B
123 #define ACCEL10_REG_OUT_Z_L 0x2C
124 #define ACCEL10_REG_OUT_Z_H 0x2D
125 #define ACCEL10_REG_FIFO_CTRL 0x2E
126 #define ACCEL10_REG_FIFO_SAMPLES 0x2F
127 #define ACCEL10_REG_TAP_THS_X 0x30
128 #define ACCEL10_REG_TAP_THS_Y 0x31
129 #define ACCEL10_REG_TAP_THS_Z 0x32
130 #define ACCEL10_REG_INT_DUR 0x33
131 #define ACCEL10_REG_WAKE_UP_THS 0x34
132 #define ACCEL10_REG_WAKE_UP_DUR 0x35
133 #define ACCEL10_REG_FREE_FALL 0x36
134 #define ACCEL10_REG_STATUS_DUP 0x37
135 #define ACCEL10_REG_WAKE_UP_SRC 0x38
136 #define ACCEL10_REG_TAP_SRC 0x39
137 #define ACCEL10_REG_SIXD_SRC 0x3A
138 #define ACCEL10_REG_ALL_INT_SRC 0x3B
139 #define ACCEL10_REG_X_OFS_USR 0x3C
140 #define ACCEL10_REG_Y_OFS_USR 0x3D
141 #define ACCEL10_REG_Z_OFS_USR 0x3E
142 #define ACCEL10_REG_CTRL_REG7 0x3F
143 
149 #define ACCEL10_WHO_AM_I_DEFAULT_VALUE 0x44
150 
161 #define ACCEL10_LP_MODE_1 0x00
162 #define ACCEL10_LP_MODE_2 0x01
163 #define ACCEL10_LP_MODE_3 0x02
164 #define ACCEL10_LP_MODE_4 0x03
165 
171 #define ACCEL10_MODE_LOW_POWER 0x00
172 #define ACCEL10_MODE_HIGH_PERF 0x04
173 #define ACCEL10_MODE_SINGLE_CONV 0x08
174 
180 #define ACCEL10_ODR_POWER_DOWN 0x00
181 #define ACCEL10_ODR_12_5_1_6HZ 0x10
182 #define ACCEL10_ODR_12_5Hz 0x20
183 #define ACCEL10_ODR_25Hz 0x30
184 #define ACCEL10_ODR_50Hz 0x40
185 #define ACCEL10_ODR_100Hz 0x50
186 #define ACCEL10_ODR_200Hz 0x60
187 #define ACCEL10_ODR_400_200Hz 0x70
188 #define ACCEL10_ODR_800_200Hz 0x80
189 #define ACCEL10_ODR_1600_200Hz 0x90
190 
203 #define ACCEL10_SIM_4_WIRE 0x00
204 #define ACCEL10_SIM_3_WIRE 0x01
205 
211 #define ACCEL10_I2C_ENABLE_I2C_AND_SPI 0x00
212 #define ACCEL10_I2C_ENABLE_SPI_ONLY 0x02
213 
219 #define ACCEL10_IF_ADD_INC_DISABLE 0x00
220 #define ACCEL10_IF_ADD_INC_ENABLE 0x04
221 
227 #define ACCEL10_BDU_CONTINUOUS_UPDATE 0x00
228 #define ACCEL10_BDU_NOT_UPDATE_MSB_LSB 0x08
229 
235 #define ACCEL10_CS_PU_DISC_CONNECT 0x00
236 #define ACCEL10_CS_PU_DISC_DISCONNECT 0x10
237 
243 #define ACCEL10_SOFT_RESET_DISABLE 0x00
244 #define ACCEL10_SOFT_RESET_ENABLE 0x40
245 
251 #define ACCEL10_BOOT_DISABLE 0x00
252 #define ACCEL10_BOOT_ENABLE 0x80
253 
266 #define ACCEL10_SLP_MODE_1_CONV_START 0x01
267 
273 #define ACCEL10_SLP_MODE_SEL_EN_INT2 0x00
274 #define ACCEL10_SLP_MODE_SEL_EN_MODE1 0x02
275 
281 #define ACCEL10_H_LACTIVE_HIGH 0x00
282 #define ACCEL10_H_LACTIVE_LOW 0x08
283 
289 #define ACCEL10_LIR_NOT_LATCHED 0x00
290 #define ACCEL10_LIR_LATCHED 0x10
291 
297 #define ACCEL10_PP_OD_PUSH_PULL 0x00
298 #define ACCEL10_PP_OD_OPEN_DRAIN 0x20
299 
305 #define ACCEL10_ST_NORMAL 0x00
306 #define ACCEL10_ST_POSITIVE 0x40
307 #define ACCEL10_ST_NEGATIVE 0x80
308 
320 #define ACCEL10_INT1_DRDY_DISABLE 0x00
321 #define ACCEL10_INT1_DRDY_ENABLE 0x01
322 
328 #define ACCEL10_INT1_FTH_DISABLE 0x00
329 #define ACCEL10_INT1_FTH_ENABLE 0x02
330 
336 #define ACCEL10_INT1_DIFF5_DISABLE 0x00
337 #define ACCEL10_INT1_DIFF5_ENABLE 0x04
338 
344 #define ACCEL10_INT1_TAP_DISABLE 0x00
345 #define ACCEL10_INT1_TAP_ENABLE 0x08
346 
352 #define ACCEL10_INT1_FF_DISABLE 0x00
353 #define ACCEL10_INT1_FF_ENABLE 0x10
354 
360 #define ACCEL10_INT1_WU_DISABLE 0x00
361 #define ACCEL10_INT1_WU_ENABLE 0x20
362 
368 #define ACCEL10_INT1_SINGLE_TAP_DISABLE 0x00
369 #define ACCEL10_INT1_SINGLE_TAP_ENABLE 0x40
370 
376 #define ACCEL10_INT1_6D_DISABLE 0x00
377 #define ACCEL10_INT1_6D_ENABLE 0x80
378 
389 #define ACCEL10_INT2_DRDY_DISABLE 0x00
390 #define ACCEL10_INT2_DRDY_ENABLE 0x01
391 
397 #define ACCEL10_INT2_FTH_DISABLE 0x00
398 #define ACCEL10_INT2_FTH_ENABLE 0x02
399 
405 #define ACCEL10_INT2_DIFF5_DISABLE 0x00
406 #define ACCEL10_INT2_DIFF5_ENABLE 0x04
407 
413 #define ACCEL10_INT2_OVR_DISABLE 0x00
414 #define ACCEL10_INT2_OVR_ENABLE 0x08
415 
421 #define ACCEL10_INT2_DRDY_T_DISABLE 0x00
422 #define ACCEL10_INT2_DRDY_T_ENABLE 0x10
423 
429 #define ACCEL10_INT2_BOOT_DISABLE 0x00
430 #define ACCEL10_INT2_BOOT_ENABLE 0x20
431 
437 #define ACCEL10_INT2_SLEEP_CHG_DISABLE 0x00
438 #define ACCEL10_INT2_SLEEP_CHG_ENABLE 0x40
439 
445 #define ACCEL10_INT2_SLEEP_STATE_DISABLE 0x00
446 #define ACCEL10_INT2_SLEEP_STATE_ENABLE 0x80
447 
458 #define ACCEL10_LOW_NOISE_DISABLE 0x00
459 #define ACCEL10_LOW_NOISE_ENABLE 0x04
460 
466 #define ACCEL10_FSD_LOW_PASS 0x00
467 #define ACCEL10_FSD_HIGH_PASS 0x08
468 
474 #define ACCEL10_FS_2G 0x00
475 #define ACCEL10_FS_4G 0x10
476 #define ACCEL10_FS_8G 0x20
477 #define ACCEL10_FS_16G 0x30
478 
484 #define ACCEL10_BW_FILT_ODR2 0x00
485 #define ACCEL10_BW_FILT_ODR4 0x40
486 #define ACCEL10_BW_FILT_ODR10 0x80
487 #define ACCEL10_BW_FILT_ODR20 0xC0
488 
495 #define ACCEL10_STATUS_DATA_READY 0x01
496 
502 #define ACCEL10_ERROR 0x00
503 #define ACCEL10_SUCCESS 0x01
504  // End group macro
507 // --------------------------------------------------------------- PUBLIC TYPES
516 typedef uint8_t accel10_select_t;
517 
521 typedef void ( *accel10_master_io_t )( struct accel10_s*, uint8_t, uint8_t*, uint8_t );
522 
526 typedef struct accel10_s
527 {
528  // Input pins
529 
530  digital_out_t cs;
531  digital_in_t it1;
532  digital_in_t it2;
533 
534  // Modules
535 
536  i2c_master_t i2c;
537  spi_master_t spi;
538 
539  // ctx variable
540 
541  uint8_t slave_address;
542  pin_name_t chip_select;
546 
548 
552 typedef struct
553 {
554  // Communication gpio pins
555 
556  pin_name_t scl;
557  pin_name_t sda;
558  pin_name_t miso;
559  pin_name_t mosi;
560  pin_name_t sck;
561  pin_name_t cs;
562 
563  // Additional gpio pins
564 
565  pin_name_t it1;
566  pin_name_t it2;
567 
568  // static variable
569 
570  uint32_t i2c_speed;
571  uint8_t i2c_address;
572 
573  uint32_t spi_speed;
574  spi_master_mode_t spi_mode;
575  spi_master_chip_select_polarity_t cs_polarity;
576 
578 
579 } accel10_cfg_t;
580 
584 typedef struct
585 {
586  int16_t x;
587  int16_t y;
588  int16_t z;
589 }
591  // End types group
593 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
599 #ifdef __cplusplus
600 extern "C"{
601 #endif
602 
612 
622 
664 
675 void accel10_generic_write ( accel10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
676 
687 void accel10_generic_read ( accel10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
688 
703 
717 
727 
738 void accel10_get_data ( accel10_t *ctx, accel10_data_t *p_accel_data );
739 
751 
765 uint8_t accel10_check_it1 ( accel10_t *ctx );
766 
780 uint8_t accel10_check_it2 ( accel10_t *ctx );
781 
782 #ifdef __cplusplus
783 }
784 #endif
785 #endif // _ACCEL10_H_
786  // End public_function group
789 
790 // ------------------------------------------------------------------------- END
accel10_cfg_t::cs
pin_name_t cs
Definition: accel10.h:561
accel10_data_t::y
int16_t y
Definition: accel10.h:587
accel10_cfg_t::sck
pin_name_t sck
Definition: accel10.h:560
accel10_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: accel10.h:574
accel10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: accel10.h:570
accel10_cfg_t::it2
pin_name_t it2
Definition: accel10.h:566
accel10_cfg_t::i2c_address
uint8_t i2c_address
Definition: accel10.h:571
accel10_s::it1
digital_in_t it1
Definition: accel10.h:531
accel10_s::chip_select
pin_name_t chip_select
Definition: accel10.h:542
accel10_cfg_t::it1
pin_name_t it1
Definition: accel10.h:565
accel10_s::i2c
i2c_master_t i2c
Definition: accel10.h:536
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:573
accel10_soft_reset
void accel10_soft_reset(accel10_t *ctx)
Soft reset function.
accel10_cfg_t::miso
pin_name_t miso
Definition: accel10.h:558
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:559
accel10_cfg_t
Click configuration structure definition.
Definition: accel10.h:553
accel10_check_id
ACCEL10_RETVAL accel10_check_id(accel10_t *ctx)
Check ID function.
accel10_s
Click ctx object definition.
Definition: accel10.h:527
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:521
accel10_data_t::z
int16_t z
Definition: accel10.h:588
accel10_s::cs
digital_out_t cs
Definition: accel10.h:530
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:585
accel10_select_t
uint8_t accel10_select_t
Communication type.
Definition: accel10.h:516
accel10_t
struct accel10_s accel10_t
Click ctx object definition.
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:545
accel10_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: accel10.h:575
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:557
accel10_cfg_t::sel
accel10_select_t sel
Definition: accel10.h:577
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:541
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:90
accel10_cfg_t::scl
pin_name_t scl
Definition: accel10.h:556
accel10_s::read_f
accel10_master_io_t read_f
Definition: accel10.h:544
accel10_s::spi
spi_master_t spi
Definition: accel10.h:537
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:543
accel10_data_t::x
int16_t x
Definition: accel10.h:586
accel10_s::it2
digital_in_t it2
Definition: accel10.h:532