accel29 2.1.0.0
accel29.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef ACCEL29_H
29#define ACCEL29_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define ACCEL29_REG_DEVID 0x00
76#define ACCEL29_REG_OFSX 0x1E
77#define ACCEL29_REG_OFSY 0x1F
78#define ACCEL29_REG_OFSZ 0x20
79#define ACCEL29_REG_THRESH_ACT 0x24
80#define ACCEL29_REG_THRESH_INACT 0x25
81#define ACCEL29_REG_TIME_INACT 0x26
82#define ACCEL29_REG_ACT_INACT_CTL 0x27
83#define ACCEL29_REG_BW_RATE 0x2C
84#define ACCEL29_REG_POWER_CTL 0x2D
85#define ACCEL29_REG_INT_ENABLE 0x2E
86#define ACCEL29_REG_INT_MAP 0x2F
87#define ACCEL29_REG_INT_SOURCE 0x30
88#define ACCEL29_REG_DATA_FORMAT 0x31
89#define ACCEL29_REG_DATA_X0 0x32
90#define ACCEL29_REG_DATA_X1 0x33
91#define ACCEL29_REG_DATA_Y0 0x34
92#define ACCEL29_REG_DATA_Y1 0x35
93#define ACCEL29_REG_DATA_Z0 0x36
94#define ACCEL29_REG_DATA_Z1 0x37
95#define ACCEL29_REG_FIFO_CTL 0x38
96#define ACCEL29_REG_FIFO_STATUS 0x39
97
98 // accel29_reg
99
114#define ACCEL29_INT_ENABLE_DATA_READY 0x80
115#define ACCEL29_INT_ENABLE_ACTIVITY 0x10
116#define ACCEL29_INT_ENABLE_INACTIVITY 0x08
117#define ACCEL29_INT_ENABLE_OVERRUN 0x01
118
123#define ACCEL29_INT_MAP_DATA_READY_INT2 0x80
124#define ACCEL29_INT_MAP_DATA_READY_INT1 0x00
125#define ACCEL29_INT_MAP_DATA_READY_MASK 0x80
126#define ACCEL29_INT_MAP_ACTIVITY_INT2 0x10
127#define ACCEL29_INT_MAP_ACTIVITY_INT1 0x00
128#define ACCEL29_INT_MAP_ACTIVITY_MASK 0x10
129#define ACCEL29_INT_MAP_INACTIVITY_INT2 0x08
130#define ACCEL29_INT_MAP_INACTIVITY_INT1 0x00
131#define ACCEL29_INT_MAP_INACTIVITY_MASK 0x08
132#define ACCEL29_INT_MAP_OVERRUN_INT2 0x01
133#define ACCEL29_INT_MAP_OVERRUN_INT1 0x00
134#define ACCEL29_INT_MAP_OVERRUN_MASK 0x01
135
140#define ACCEL29_INT_SOURCE_DATA_READY 0x80
141#define ACCEL29_INT_SOURCE_ACTIVITY 0x10
142#define ACCEL29_INT_SOURCE_INACTIVITY 0x08
143#define ACCEL29_INT_SOURCE_OVERRUN 0x01
144
149#define ACCEL29_BW_RATE_LOW_POWER 0x10
150#define ACCEL29_BW_RATE_6_25_HZ 0x06
151#define ACCEL29_BW_RATE_12_5_HZ 0x07
152#define ACCEL29_BW_RATE_25_HZ 0x08
153#define ACCEL29_BW_RATE_50_HZ 0x09
154#define ACCEL29_BW_RATE_100_HZ 0x0A
155#define ACCEL29_BW_RATE_200_HZ 0x0B
156#define ACCEL29_BW_RATE_400_HZ 0x0C
157#define ACCEL29_BW_RATE_800_HZ 0x0D
158#define ACCEL29_BW_RATE_1600_HZ 0x0E
159#define ACCEL29_BW_RATE_3200_HZ 0x0F
160
165#define ACCEL29_POWER_CTL_LINK 0x20
166#define ACCEL29_POWER_CTL_AUTO_SLEEP 0x10
167#define ACCEL29_POWER_CTL_MEASURE 0x08
168#define ACCEL29_POWER_CTL_SLEEP 0x04
169#define ACCEL29_POWER_CTL_WAKEUP_8_HZ 0x00
170#define ACCEL29_POWER_CTL_WAKEUP_4_HZ 0x01
171#define ACCEL29_POWER_CTL_WAKEUP_2_HZ 0x02
172#define ACCEL29_POWER_CTL_WAKEUP_1_HZ 0x03
173#define ACCEL29_POWER_CTL_WAKEUP_MASK 0x03
174
179#define ACCEL29_DEVID 0xE5
180
185#define ACCEL29_OFS_RESET 0
186#define ACCEL29_OFS_SCALE_FACTOR_G_PER_LSB 0.195f
187
192#define ACCEL29_SCALE_FACTOR_LSB_PER_G 20.48f
193
198#define ACCEL29_NUM_OF_SAMPLES 100
199
204#define ACCEL29_SPI_RW_BIT 0x80
205#define ACCEL29_SPI_MB_BIT 0x40
206#define ACCEL29_ADDRESS_MASK 0x3F
207
213#define ACCEL29_DEVICE_ADDRESS_0 0x53
214#define ACCEL29_DEVICE_ADDRESS_1 0x1D
215
224#define ACCEL29_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
225#define ACCEL29_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
226
227 // accel29_set
228
243#define ACCEL29_MAP_MIKROBUS( cfg, mikrobus ) \
244 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
245 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
246 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
247 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
248 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
249 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
250 cfg.int1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
251 cfg.int2 = MIKROBUS( mikrobus, MIKROBUS_INT )
252
253 // accel29_map
254 // accel29
255
266
271typedef err_t ( *accel29_master_io_t )( struct accel29_s*, uint8_t, uint8_t*, uint8_t );
277typedef struct accel29_s
278{
279 digital_in_t int1;
280 digital_in_t int2;
282 i2c_master_t i2c;
283 spi_master_t spi;
286 pin_name_t chip_select;
293
298typedef struct
299{
300 pin_name_t scl;
301 pin_name_t sda;
302 pin_name_t miso;
303 pin_name_t mosi;
304 pin_name_t sck;
305 pin_name_t cs;
306 pin_name_t int1;
307 pin_name_t int2;
309 uint32_t i2c_speed;
310 uint8_t i2c_address;
312 uint32_t spi_speed;
313 spi_master_mode_t spi_mode;
314 spi_master_chip_select_polarity_t cs_polarity;
319
324typedef struct
325{
326 float x;
327 float y;
328 float z;
331
336typedef enum
337{
339 ACCEL29_ERROR = -1
340
342
359
375
390
404
419err_t accel29_generic_write ( accel29_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
420
435err_t accel29_generic_read ( accel29_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
436
449err_t accel29_write_register ( accel29_t *ctx, uint8_t reg, uint8_t data_in );
450
463err_t accel29_read_register ( accel29_t *ctx, uint8_t reg, uint8_t *data_out );
464
476
486
496
510
525err_t accel29_get_avg_axes ( accel29_t *ctx, uint16_t num_samples, accel29_axes_t *avg_axes );
526
541
542#ifdef __cplusplus
543}
544#endif
545#endif // ACCEL29_H
546
547 // accel29
548
549// ------------------------------------------------------------------------ END
err_t(* accel29_master_io_t)(struct accel29_s *, uint8_t, uint8_t *, uint8_t)
Accel 29 Click driver interface.
Definition accel29.h:271
accel29_return_value_t
Accel 29 Click return value data.
Definition accel29.h:337
@ ACCEL29_OK
Definition accel29.h:338
@ ACCEL29_ERROR
Definition accel29.h:339
accel29_drv_t
Accel 29 Click driver selector.
Definition accel29.h:261
@ ACCEL29_DRV_SEL_SPI
Definition accel29.h:262
@ ACCEL29_DRV_SEL_I2C
Definition accel29.h:263
struct accel29_s accel29_t
Accel 29 Click context object.
err_t accel29_generic_write(accel29_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Accel 29 data writing function.
err_t accel29_calibrate_offset(accel29_t *ctx, accel29_axes_t calib_axes)
Accel 29 calibrate offset function.
void accel29_cfg_setup(accel29_cfg_t *cfg)
Accel 29 configuration object setup function.
err_t accel29_get_axes(accel29_t *ctx, accel29_axes_t *axes)
Accel 29 get axes function.
uint8_t accel29_get_int2_pin(accel29_t *ctx)
Accel 29 get int2 pin function.
err_t accel29_check_communication(accel29_t *ctx)
Accel 29 check communication function.
err_t accel29_write_register(accel29_t *ctx, uint8_t reg, uint8_t data_in)
Accel 29 write register function.
err_t accel29_init(accel29_t *ctx, accel29_cfg_t *cfg)
Accel 29 initialization function.
err_t accel29_read_register(accel29_t *ctx, uint8_t reg, uint8_t *data_out)
Accel 29 read register function.
void accel29_drv_interface_selection(accel29_cfg_t *cfg, accel29_drv_t drv_sel)
Accel 29 driver interface setup function.
err_t accel29_get_avg_axes(accel29_t *ctx, uint16_t num_samples, accel29_axes_t *avg_axes)
Accel 29 get avg axes function.
uint8_t accel29_get_int1_pin(accel29_t *ctx)
Accel 29 get int1 pin function.
err_t accel29_default_cfg(accel29_t *ctx)
Accel 29 default configuration function.
err_t accel29_generic_read(accel29_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Accel 29 data reading function.
This file contains SPI specific macros, functions, etc.
Accel 29 Click Axes data structure.
Definition accel29.h:325
float y
Definition accel29.h:327
float x
Definition accel29.h:326
float z
Definition accel29.h:328
Accel 29 Click configuration object.
Definition accel29.h:299
pin_name_t int1
Definition accel29.h:306
pin_name_t int2
Definition accel29.h:307
uint32_t i2c_speed
Definition accel29.h:309
spi_master_chip_select_polarity_t cs_polarity
Definition accel29.h:314
pin_name_t sck
Definition accel29.h:304
spi_master_mode_t spi_mode
Definition accel29.h:313
pin_name_t mosi
Definition accel29.h:303
uint32_t spi_speed
Definition accel29.h:312
pin_name_t scl
Definition accel29.h:300
pin_name_t miso
Definition accel29.h:302
pin_name_t sda
Definition accel29.h:301
accel29_drv_t drv_sel
Definition accel29.h:316
pin_name_t cs
Definition accel29.h:305
uint8_t i2c_address
Definition accel29.h:310
Accel 29 Click context object.
Definition accel29.h:278
digital_in_t int2
Definition accel29.h:280
spi_master_t spi
Definition accel29.h:283
accel29_master_io_t read_f
Definition accel29.h:290
digital_in_t int1
Definition accel29.h:279
i2c_master_t i2c
Definition accel29.h:282
uint8_t slave_address
Definition accel29.h:285
accel29_master_io_t write_f
Definition accel29.h:289
pin_name_t chip_select
Definition accel29.h:286
accel29_drv_t drv_sel
Definition accel29.h:287