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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 #include "drv_spi_master.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define ACCEL10_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
67  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
68  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
69  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70  cfg.it1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
71  cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define ACCEL10_MASTER_I2C 0
79 #define ACCEL10_MASTER_SPI 1
80 
86 #define ACCEL10_RETVAL uint8_t
87 
88 #define ACCEL10_OK 0x00
89 #define ACCEL10_INIT_ERROR 0xFF
90 
96 #define ACCEL10_SLAVE_ADDRESS_GND 0x18
97 #define ACCEL10_SLAVE_ADDRESS_VCC 0x19
98 
104 #define ACCEL10_REG_OUT_T_L 0x0D
105 #define ACCEL10_REG_OUT_T_H 0x0E
106 #define ACCEL10_REG_WHO_AM_I 0x0F
107 #define ACCEL10_REG_CTRL1 0x20
108 #define ACCEL10_REG_CTRL2 0x21
109 #define ACCEL10_REG_CTRL3 0x22
110 #define ACCEL10_REG_CTRL4_INT1_PAD_CTRL 0x23
111 #define ACCEL10_REG_CTRL5_INT2_PAD_CTRL 0x24
112 #define ACCEL10_REG_CTRL6 0x25
113 #define ACCEL10_REG_OUT_T 0x26
114 #define ACCEL10_REG_STATUS 0x27
115 #define ACCEL10_REG_OUT_X_L 0x28
116 #define ACCEL10_REG_OUT_X_H 0x29
117 #define ACCEL10_REG_OUT_Y_L 0x2A
118 #define ACCEL10_REG_OUT_Y_H 0x2B
119 #define ACCEL10_REG_OUT_Z_L 0x2C
120 #define ACCEL10_REG_OUT_Z_H 0x2D
121 #define ACCEL10_REG_FIFO_CTRL 0x2E
122 #define ACCEL10_REG_FIFO_SAMPLES 0x2F
123 #define ACCEL10_REG_TAP_THS_X 0x30
124 #define ACCEL10_REG_TAP_THS_Y 0x31
125 #define ACCEL10_REG_TAP_THS_Z 0x32
126 #define ACCEL10_REG_INT_DUR 0x33
127 #define ACCEL10_REG_WAKE_UP_THS 0x34
128 #define ACCEL10_REG_WAKE_UP_DUR 0x35
129 #define ACCEL10_REG_FREE_FALL 0x36
130 #define ACCEL10_REG_STATUS_DUP 0x37
131 #define ACCEL10_REG_WAKE_UP_SRC 0x38
132 #define ACCEL10_REG_TAP_SRC 0x39
133 #define ACCEL10_REG_SIXD_SRC 0x3A
134 #define ACCEL10_REG_ALL_INT_SRC 0x3B
135 #define ACCEL10_REG_X_OFS_USR 0x3C
136 #define ACCEL10_REG_Y_OFS_USR 0x3D
137 #define ACCEL10_REG_Z_OFS_USR 0x3E
138 #define ACCEL10_REG_CTRL_REG7 0x3F
139 
145 #define ACCEL10_WHO_AM_I_DEFAULT_VALUE 0x44
146 
157 #define ACCEL10_LP_MODE_1 0x00
158 #define ACCEL10_LP_MODE_2 0x01
159 #define ACCEL10_LP_MODE_3 0x02
160 #define ACCEL10_LP_MODE_4 0x03
161 
167 #define ACCEL10_MODE_LOW_POWER 0x00
168 #define ACCEL10_MODE_HIGH_PERF 0x04
169 #define ACCEL10_MODE_SINGLE_CONV 0x08
170 
176 #define ACCEL10_ODR_POWER_DOWN 0x00
177 #define ACCEL10_ODR_12_5_1_6HZ 0x10
178 #define ACCEL10_ODR_12_5Hz 0x20
179 #define ACCEL10_ODR_25Hz 0x30
180 #define ACCEL10_ODR_50Hz 0x40
181 #define ACCEL10_ODR_100Hz 0x50
182 #define ACCEL10_ODR_200Hz 0x60
183 #define ACCEL10_ODR_400_200Hz 0x70
184 #define ACCEL10_ODR_800_200Hz 0x80
185 #define ACCEL10_ODR_1600_200Hz 0x90
186 
199 #define ACCEL10_SIM_4_WIRE 0x00
200 #define ACCEL10_SIM_3_WIRE 0x01
201 
207 #define ACCEL10_I2C_ENABLE_I2C_AND_SPI 0x00
208 #define ACCEL10_I2C_ENABLE_SPI_ONLY 0x02
209 
215 #define ACCEL10_IF_ADD_INC_DISABLE 0x00
216 #define ACCEL10_IF_ADD_INC_ENABLE 0x04
217 
223 #define ACCEL10_BDU_CONTINUOUS_UPDATE 0x00
224 #define ACCEL10_BDU_NOT_UPDATE_MSB_LSB 0x08
225 
231 #define ACCEL10_CS_PU_DISC_CONNECT 0x00
232 #define ACCEL10_CS_PU_DISC_DISCONNECT 0x10
233 
239 #define ACCEL10_SOFT_RESET_DISABLE 0x00
240 #define ACCEL10_SOFT_RESET_ENABLE 0x40
241 
247 #define ACCEL10_BOOT_DISABLE 0x00
248 #define ACCEL10_BOOT_ENABLE 0x80
249 
262 #define ACCEL10_SLP_MODE_1_CONV_START 0x01
263 
269 #define ACCEL10_SLP_MODE_SEL_EN_INT2 0x00
270 #define ACCEL10_SLP_MODE_SEL_EN_MODE1 0x02
271 
277 #define ACCEL10_H_LACTIVE_HIGH 0x00
278 #define ACCEL10_H_LACTIVE_LOW 0x08
279 
285 #define ACCEL10_LIR_NOT_LATCHED 0x00
286 #define ACCEL10_LIR_LATCHED 0x10
287 
293 #define ACCEL10_PP_OD_PUSH_PULL 0x00
294 #define ACCEL10_PP_OD_OPEN_DRAIN 0x20
295 
301 #define ACCEL10_ST_NORMAL 0x00
302 #define ACCEL10_ST_POSITIVE 0x40
303 #define ACCEL10_ST_NEGATIVE 0x80
304 
316 #define ACCEL10_INT1_DRDY_DISABLE 0x00
317 #define ACCEL10_INT1_DRDY_ENABLE 0x01
318 
324 #define ACCEL10_INT1_FTH_DISABLE 0x00
325 #define ACCEL10_INT1_FTH_ENABLE 0x02
326 
332 #define ACCEL10_INT1_DIFF5_DISABLE 0x00
333 #define ACCEL10_INT1_DIFF5_ENABLE 0x04
334 
340 #define ACCEL10_INT1_TAP_DISABLE 0x00
341 #define ACCEL10_INT1_TAP_ENABLE 0x08
342 
348 #define ACCEL10_INT1_FF_DISABLE 0x00
349 #define ACCEL10_INT1_FF_ENABLE 0x10
350 
356 #define ACCEL10_INT1_WU_DISABLE 0x00
357 #define ACCEL10_INT1_WU_ENABLE 0x20
358 
364 #define ACCEL10_INT1_SINGLE_TAP_DISABLE 0x00
365 #define ACCEL10_INT1_SINGLE_TAP_ENABLE 0x40
366 
372 #define ACCEL10_INT1_6D_DISABLE 0x00
373 #define ACCEL10_INT1_6D_ENABLE 0x80
374 
385 #define ACCEL10_INT2_DRDY_DISABLE 0x00
386 #define ACCEL10_INT2_DRDY_ENABLE 0x01
387 
393 #define ACCEL10_INT2_FTH_DISABLE 0x00
394 #define ACCEL10_INT2_FTH_ENABLE 0x02
395 
401 #define ACCEL10_INT2_DIFF5_DISABLE 0x00
402 #define ACCEL10_INT2_DIFF5_ENABLE 0x04
403 
409 #define ACCEL10_INT2_OVR_DISABLE 0x00
410 #define ACCEL10_INT2_OVR_ENABLE 0x08
411 
417 #define ACCEL10_INT2_DRDY_T_DISABLE 0x00
418 #define ACCEL10_INT2_DRDY_T_ENABLE 0x10
419 
425 #define ACCEL10_INT2_BOOT_DISABLE 0x00
426 #define ACCEL10_INT2_BOOT_ENABLE 0x20
427 
433 #define ACCEL10_INT2_SLEEP_CHG_DISABLE 0x00
434 #define ACCEL10_INT2_SLEEP_CHG_ENABLE 0x40
435 
441 #define ACCEL10_INT2_SLEEP_STATE_DISABLE 0x00
442 #define ACCEL10_INT2_SLEEP_STATE_ENABLE 0x80
443 
454 #define ACCEL10_LOW_NOISE_DISABLE 0x00
455 #define ACCEL10_LOW_NOISE_ENABLE 0x04
456 
462 #define ACCEL10_FSD_LOW_PASS 0x00
463 #define ACCEL10_FSD_HIGH_PASS 0x08
464 
470 #define ACCEL10_FS_2G 0x00
471 #define ACCEL10_FS_4G 0x10
472 #define ACCEL10_FS_8G 0x20
473 #define ACCEL10_FS_16G 0x30
474 
480 #define ACCEL10_BW_FILT_ODR2 0x00
481 #define ACCEL10_BW_FILT_ODR4 0x40
482 #define ACCEL10_BW_FILT_ODR10 0x80
483 #define ACCEL10_BW_FILT_ODR20 0xC0
484 
491 #define ACCEL10_STATUS_DATA_READY 0x01
492 
498 #define ACCEL10_ERROR 0x00
499 #define ACCEL10_SUCCESS 0x01
500  // End group macro
503 // --------------------------------------------------------------- PUBLIC TYPES
512 typedef uint8_t accel10_select_t;
513 
517 typedef void ( *accel10_master_io_t )( struct accel10_s*, uint8_t, uint8_t*, uint8_t );
518 
522 typedef struct accel10_s
523 {
524  // Input pins
525 
526  digital_out_t cs;
527  digital_in_t it1;
528  digital_in_t it2;
529 
530  // Modules
531 
532  i2c_master_t i2c;
533  spi_master_t spi;
534 
535  // ctx variable
536 
537  uint8_t slave_address;
538  pin_name_t chip_select;
542 
544 
548 typedef struct
549 {
550  // Communication gpio pins
551 
552  pin_name_t scl;
553  pin_name_t sda;
554  pin_name_t miso;
555  pin_name_t mosi;
556  pin_name_t sck;
557  pin_name_t cs;
558 
559  // Additional gpio pins
560 
561  pin_name_t it1;
562  pin_name_t it2;
563 
564  // static variable
565 
566  uint32_t i2c_speed;
567  uint8_t i2c_address;
568 
569  uint32_t spi_speed;
570  spi_master_mode_t spi_mode;
571  spi_master_chip_select_polarity_t cs_polarity;
572 
574 
575 } accel10_cfg_t;
576 
580 typedef struct
581 {
582  int16_t x;
583  int16_t y;
584  int16_t z;
585 }
587  // End types group
589 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
595 #ifdef __cplusplus
596 extern "C"{
597 #endif
598 
608 
618 
660 
671 void accel10_generic_write ( accel10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
672 
683 void accel10_generic_read ( accel10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
684 
699 
713 
723 
734 void accel10_get_data ( accel10_t *ctx, accel10_data_t *p_accel_data );
735 
747 
761 uint8_t accel10_check_it1 ( accel10_t *ctx );
762 
776 uint8_t accel10_check_it2 ( accel10_t *ctx );
777 
778 #ifdef __cplusplus
779 }
780 #endif
781 #endif // _ACCEL10_H_
782  // End public_function group
785 
786 // ------------------------------------------------------------------------- END
accel10_cfg_t::cs
pin_name_t cs
Definition: accel10.h:557
accel10_data_t::y
int16_t y
Definition: accel10.h:583
accel10_cfg_t::sck
pin_name_t sck
Definition: accel10.h:556
accel10_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: accel10.h:570
accel10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: accel10.h:566
accel10_cfg_t::it2
pin_name_t it2
Definition: accel10.h:562
accel10_cfg_t::i2c_address
uint8_t i2c_address
Definition: accel10.h:567
accel10_s::it1
digital_in_t it1
Definition: accel10.h:527
accel10_s::chip_select
pin_name_t chip_select
Definition: accel10.h:538
accel10_cfg_t::it1
pin_name_t it1
Definition: accel10.h:561
accel10_s::i2c
i2c_master_t i2c
Definition: accel10.h:532
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:569
accel10_soft_reset
void accel10_soft_reset(accel10_t *ctx)
Soft reset function.
accel10_cfg_t::miso
pin_name_t miso
Definition: accel10.h:554
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:555
accel10_cfg_t
Click configuration structure definition.
Definition: accel10.h:549
accel10_check_id
ACCEL10_RETVAL accel10_check_id(accel10_t *ctx)
Check ID function.
accel10_s
Click ctx object definition.
Definition: accel10.h:523
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:517
accel10_data_t::z
int16_t z
Definition: accel10.h:584
accel10_s::cs
digital_out_t cs
Definition: accel10.h:526
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:581
accel10_select_t
uint8_t accel10_select_t
Communication type.
Definition: accel10.h:512
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:541
accel10_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: accel10.h:571
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:553
accel10_cfg_t::sel
accel10_select_t sel
Definition: accel10.h:573
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:537
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:86
accel10_cfg_t::scl
pin_name_t scl
Definition: accel10.h:552
accel10_s::read_f
accel10_master_io_t read_f
Definition: accel10.h:540
accel10_s::spi
spi_master_t spi
Definition: accel10.h:533
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:539
accel10_data_t::x
int16_t x
Definition: accel10.h:582
accel10_s::it2
digital_in_t it2
Definition: accel10.h:528