accel28  2.1.0.0
accel28.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 ACCEL28_H
29 #define ACCEL28_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 #include "drv_spi_master.h"
39 #include "spi_specifics.h"
40 
61 #define ACCEL28_REG_TEMP_L 0x0B
62 #define ACCEL28_REG_TEMP_H 0x0C
63 #define ACCEL28_REG_WHO_AM_I 0x0F
64 #define ACCEL28_REG_ACT_THS 0x1E
65 #define ACCEL28_REG_ACT_DUS 0x1F
66 #define ACCEL28_REG_CTRL1 0x20
67 #define ACCEL28_REG_CTRL2 0x21
68 #define ACCEL28_REG_CTRL3 0x22
69 #define ACCEL28_REG_CTRL4 0x23
70 #define ACCEL28_REG_CTRL5 0x24
71 #define ACCEL28_REG_CTRL6 0x25
72 #define ACCEL28_REG_CTRL7 0x26
73 #define ACCEL28_REG_STATUS 0x27
74 #define ACCEL28_REG_OUT_X_L 0x28
75 #define ACCEL28_REG_OUT_X_H 0x29
76 #define ACCEL28_REG_OUT_Y_L 0x2A
77 #define ACCEL28_REG_OUT_Y_H 0x2B
78 #define ACCEL28_REG_OUT_Z_L 0x2C
79 #define ACCEL28_REG_OUT_Z_H 0x2D
80 #define ACCEL28_REG_FIFO_CTRL 0x2E
81 #define ACCEL28_REG_FIFO_SRC 0x2F
82 #define ACCEL28_REG_IG_CFG1 0x30
83 #define ACCEL28_REG_IG_SRC1 0x31
84 #define ACCEL28_REG_IG_THS_X1 0x32
85 #define ACCEL28_REG_IG_THS_Y1 0x33
86 #define ACCEL28_REG_IG_THS_Z1 0x34
87 #define ACCEL28_REG_IG_DUR1 0x35
88 #define ACCEL28_REG_IG_CFG2 0x36
89 #define ACCEL28_REG_IG_SRC2 0x37
90 #define ACCEL28_REG_IG_THS2 0x38
91 #define ACCEL28_REG_IG_DUR2 0x39
92 #define ACCEL28_REG_XL_REFERENCE 0x3A
93 #define ACCEL28_REG_XH_REFERENCE 0x3B
94 #define ACCEL28_REG_YL_REFERENCE 0x3C
95 #define ACCEL28_REG_YH_REFERENCE 0x3D
96 #define ACCEL28_REG_ZL_REFERENCE 0x3E
97 #define ACCEL28_REG_ZH_REFERENCE 0x3F
98  // accel28_reg
100 
115 #define ACCEL28_WHO_AM_I_VALUE 0x41
116 
122 #define ACCEL28_CTRL1_X_AXIS_ENABLE 0x01
123 #define ACCEL28_CTRL1_Y_AXIS_ENABLE 0x02
124 #define ACCEL28_CTRL1_Z_AXIS_ENABLE 0x04
125 #define ACCEL28_CTRL1_BLOCK_DATA_UPATE_EN 0x08
126 #define ACCEL28_CTRL1_ODR_POWER_DOWN 0x00
127 #define ACCEL28_CTRL1_ODR_10HZ 0x10
128 #define ACCEL28_CTRL1_ODR_50HZ 0x20
129 #define ACCEL28_CTRL1_ODR_100HZ 0x30
130 #define ACCEL28_CTRL1_ODR_200HZ 0x40
131 #define ACCEL28_CTRL1_ODR_400HZ 0x50
132 #define ACCEL28_CTRL1_ODR_800HZ 0x60
133 #define ACCEL28_CTRL1_ODR_NA 0x70
134 #define ACCEL28_CTRL1_HR_MODE 0x80
135 
140 #define ACCEL28_CTRL2_HP_ENABLE_INT2 0x01
141 #define ACCEL28_CTRL2_HP_ENABLE_INT1 0x02
142 #define ACCEL28_CTRL2_FDS_ENABLE 0x04
143 #define ACCEL28_CTRL2_HPM_NORMAL_MODE 0x00
144 #define ACCEL28_CTRL2_HPM_REF_SIGNAL_FILTERING 0x08
145 #define ACCEL28_CTRL2_HPM_FREQ_DEV_50 0x00
146 #define ACCEL28_CTRL2_HPM_FREQ_DEV_100 0x20
147 #define ACCEL28_CTRL2_HPM_FREQ_DEV_9 0x40
148 #define ACCEL28_CTRL2_HPM_FREQ_DEV_400 0x60
149 
155 #define ACCEL28_CTRL3_INT1_DRDY_EN 0x01
156 #define ACCEL28_CTRL3_INT1_FTH 0x02
157 #define ACCEL28_CTRL3_INT1_OVR 0x04
158 #define ACCEL28_CTRL3_INT1_IG1 0x08
159 #define ACCEL28_CTRL3_INT1_IG2 0x10
160 #define ACCEL28_CTRL3_INT1_INACT_EN 0x20
161 #define ACCEL28_CTRL3_STOP_FTH 0x40
162 #define ACCEL28_CTRL3_FIFO_EN 0x80
163 
169 #define ACCEL28_CTRL4_SPI_MODE_3_WIRE 0x01
170 #define ACCEL28_CTRL4_SPI_MODE_4_WIRE 0x00
171 #define ACCEL28_CTRL4_I2C_DISABLED 0x02
172 #define ACCEL28_CTRL4_I2C_ENABLED 0x00
173 #define ACCEL28_CTRL4_ADD_INC_ENABLED 0x04
174 #define ACCEL28_CTRL4_BW_SCALE_ODR 0x00
175 #define ACCEL28_CTRL4_BW_SCALE_BW 0x08
176 #define ACCEL28_CTRL4_FS_2G 0x00
177 #define ACCEL28_CTRL4_FS_4G 0x20
178 #define ACCEL28_CTRL4_FS_8G 0x30
179 #define ACCEL28_CTRL4_FS_MASK 0x30
180 #define ACCEL28_CTRL4_BW_400HZ 0x00
181 #define ACCEL28_CTRL4_BW_200HZ 0x40
182 #define ACCEL28_CTRL4_BW_100HZ 0x80
183 #define ACCEL28_CTRL4_BW_50HZ 0xC0
184 
190 #define ACCEL28_CTRL5_INT_PUSH_PULL 0x00
191 #define ACCEL28_CTRL5_INT_OPEN_DRAIN 0x01
192 #define ACCEL28_CTRL5_INT_ACTIVE_HIGH 0x00
193 #define ACCEL28_CTRL5_INT_ACTIVE_LOW 0x02
194 #define ACCEL28_CTRL5_NORMAL_MODE 0x00
195 #define ACCEL28_CTRL5_POSITIVE_SELF_TEST 0x04
196 #define ACCEL28_CTRL5_NEGATIVE_SELF_TEST 0x08
197 #define ACCEL28_CTRL5_DEC_UDATE_OFF 0x00
198 #define ACCEL28_CTRL5_DEC_UDATE_2_SAMPLES 0x10
199 #define ACCEL28_CTRL5_DEC_UDATE_4_SAMPLES 0x20
200 #define ACCEL28_CTRL5_DEC_UDATE_8_SAMPLES 0x30
201 #define ACCEL28_CTRL5_SW_RESET 0x40
202 #define ACCEL28_CTRL5_DEBUG_MODE 0x80
203 
209 #define ACCEL28_CTRL6_INT2_DRDY 0x01
210 #define ACCEL28_CTRL6_INT2_FTH 0x02
211 #define ACCEL28_CTRL6_INT2_EMPTY 0x04
212 #define ACCEL28_CTRL6_INT2_IG1 0x08
213 #define ACCEL28_CTRL6_INT2_IG2 0x10
214 #define ACCEL28_CTRL6_INT2_BOOT 0x20
215 #define ACCEL28_CTRL6_BOOT 0x80
216 
222 #define ACCEL28_STATUS_X_DATA_AVL 0x01
223 #define ACCEL28_STATUS_Y_DATA_AVL 0x02
224 #define ACCEL28_STATUS_Z_DATA_AVL 0x04
225 #define ACCEL28_STATUS_ZYX_DATA_AVL 0x08
226 #define ACCEL28_STATUS_X_DATA_OVERRUN 0x10
227 #define ACCEL28_STATUS_Y_DATA_OVERRUN 0x20
228 #define ACCEL28_STATUS_Z_DATA_OVERRUN 0x40
229 #define ACCEL28_STATUS_ZYX_DATA_OVERRUN 0x80
230 
236 #define ACCEL28_2G_DATA_CONV 0.061f
237 #define ACCEL28_4G_DATA_CONV 0.122f
238 #define ACCEL28_8G_DATA_CONV 0.244f
239 
245 #define ACCEL28_PIN_STATE_HIGH 0x01
246 #define ACCEL28_PIN_STATE_LOW 0x00
247 
253 #define ACCEL28_DEVICE_ADDRESS_0 0x1E
254 #define ACCEL28_DEVICE_ADDRESS_1 0x1D
255 
264 #define ACCEL28_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
265 #define ACCEL28_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
266  // accel28_set
268 
283 #define ACCEL28_MAP_MIKROBUS( cfg, mikrobus ) \
284  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
285  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
286  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
287  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
288  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
289  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
290  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
291  // accel28_map // accel28
294 
299 typedef enum
300 {
305 
310 typedef err_t ( *accel28_master_io_t )( struct accel28_s*, uint8_t, uint8_t*, uint8_t );
316 typedef struct accel28_s
317 {
318  digital_in_t int_pin;
320  i2c_master_t i2c;
321  spi_master_t spi;
323  uint8_t slave_address;
324  pin_name_t chip_select;
331 
336 typedef struct
337 {
338  pin_name_t scl;
339  pin_name_t sda;
340  pin_name_t miso;
341  pin_name_t mosi;
342  pin_name_t sck;
343  pin_name_t cs;
344  pin_name_t int_pin;
346  uint32_t i2c_speed;
347  uint8_t i2c_address;
349  uint32_t spi_speed;
350  spi_master_mode_t spi_mode;
351  spi_master_chip_select_polarity_t cs_polarity;
355 } accel28_cfg_t;
356 
361 typedef struct
362 {
363  float x_data;
364  float y_data;
365  float z_data;
368 
373 typedef enum
374 {
376  ACCEL28_ERROR = -1
377 
379 
396 
412 
426 err_t accel28_init ( accel28_t *ctx, accel28_cfg_t *cfg );
427 
441 
456 err_t accel28_generic_write ( accel28_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
457 
472 err_t accel28_generic_read ( accel28_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
473 
483 
496 
508 err_t accel28_get_data ( accel28_t *ctx, accel28_data_t *data_out );
509 
522 err_t accel28_write_reg ( accel28_t *ctx, uint8_t reg, uint8_t data_in );
523 
537 err_t accel28_read_reg ( accel28_t *ctx, uint8_t reg, uint8_t *data_out );
538 
550 
551 #ifdef __cplusplus
552 }
553 #endif
554 #endif // ACCEL28_H
555  // accel28
557 
558 // ------------------------------------------------------------------------ END
accel28_s::read_f
accel28_master_io_t read_f
Definition: accel28.h:328
accel28_t
struct accel28_s accel28_t
Accel 28 Click context object.
accel28_cfg_t::cs
pin_name_t cs
Definition: accel28.h:343
accel28_cfg_t::sck
pin_name_t sck
Definition: accel28.h:342
spi_specifics.h
This file contains SPI specific macros, functions, etc.
accel28_default_cfg
err_t accel28_default_cfg(accel28_t *ctx)
Accel 28 default configuration function.
accel28_s
Accel 28 Click context object.
Definition: accel28.h:317
accel28_cfg_t::miso
pin_name_t miso
Definition: accel28.h:340
accel28_generic_read
err_t accel28_generic_read(accel28_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Accel 28 data reading function.
accel28_get_data
err_t accel28_get_data(accel28_t *ctx, accel28_data_t *data_out)
Accel 28 data reading function.
accel28_write_reg
err_t accel28_write_reg(accel28_t *ctx, uint8_t reg, uint8_t data_in)
Accel 28 register data writing function.
accel28_master_io_t
err_t(* accel28_master_io_t)(struct accel28_s *, uint8_t, uint8_t *, uint8_t)
Accel 28 Click driver interface.
Definition: accel28.h:310
accel28_data_t
Accel 28 Click data object.
Definition: accel28.h:362
accel28_generic_write
err_t accel28_generic_write(accel28_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Accel 28 data writing function.
accel28_drv_interface_selection
void accel28_drv_interface_selection(accel28_cfg_t *cfg, accel28_drv_t drv_sel)
Accel 28 driver interface setup function.
accel28_cfg_t::mosi
pin_name_t mosi
Definition: accel28.h:341
accel28_s::slave_address
uint8_t slave_address
Definition: accel28.h:323
accel28_s::int_pin
digital_in_t int_pin
Definition: accel28.h:318
accel28_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: accel28.h:346
accel28_cfg_setup
void accel28_cfg_setup(accel28_cfg_t *cfg)
Accel 28 configuration object setup function.
accel28_get_raw_data
err_t accel28_get_raw_data(accel28_t *ctx, accel28_data_t *data_out)
Accel 28 raw data reading function.
accel28_cfg_t
Accel 28 Click configuration object.
Definition: accel28.h:337
accel28_data_t::z_data
float z_data
Definition: accel28.h:365
accel28_s::spi
spi_master_t spi
Definition: accel28.h:321
accel28_read_reg
err_t accel28_read_reg(accel28_t *ctx, uint8_t reg, uint8_t *data_out)
Accel 28 register data reading function.
ACCEL28_OK
@ ACCEL28_OK
Definition: accel28.h:375
accel28_s::chip_select
pin_name_t chip_select
Definition: accel28.h:324
accel28_s::i2c
i2c_master_t i2c
Definition: accel28.h:320
accel28_cfg_t::sda
pin_name_t sda
Definition: accel28.h:339
accel28_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: accel28.h:350
accel28_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: accel28.h:351
accel28_cfg_t::int_pin
pin_name_t int_pin
Definition: accel28.h:344
ACCEL28_DRV_SEL_I2C
@ ACCEL28_DRV_SEL_I2C
Definition: accel28.h:302
accel28_get_int_state
uint8_t accel28_get_int_state(accel28_t *ctx)
Accel 28 interrupt reading function.
accel28_cfg_t::i2c_address
uint8_t i2c_address
Definition: accel28.h:347
accel28_cfg_t::spi_speed
uint32_t spi_speed
Definition: accel28.h:349
accel28_s::drv_sel
accel28_drv_t drv_sel
Definition: accel28.h:325
ACCEL28_DRV_SEL_SPI
@ ACCEL28_DRV_SEL_SPI
Definition: accel28.h:301
accel28_sw_reset
err_t accel28_sw_reset(accel28_t *ctx)
Accel 28 SW reset function.
accel28_data_t::x_data
float x_data
Definition: accel28.h:363
accel28_data_t::y_data
float y_data
Definition: accel28.h:364
accel28_drv_t
accel28_drv_t
Accel 28 Click driver selector.
Definition: accel28.h:300
accel28_cfg_t::scl
pin_name_t scl
Definition: accel28.h:338
accel28_init
err_t accel28_init(accel28_t *ctx, accel28_cfg_t *cfg)
Accel 28 initialization function.
accel28_s::write_f
accel28_master_io_t write_f
Definition: accel28.h:327
ACCEL28_ERROR
@ ACCEL28_ERROR
Definition: accel28.h:376
accel28_cfg_t::drv_sel
accel28_drv_t drv_sel
Definition: accel28.h:353
accel28_return_value_t
accel28_return_value_t
Accel 28 Click return value data.
Definition: accel28.h:374