accel8 2.0.0.0
accel8.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 ACCEL8_H
36#define ACCEL8_H
37
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_i2c_master.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
52#define ACCEL8_MAP_MIKROBUS( cfg, mikrobus ) \
53 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55 cfg.da = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56 cfg.cl = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
64#define ACCEL8_RETVAL uint8_t
65
66#define ACCEL8_OK 0x00
67#define ACCEL8_INIT_ERROR 0xFF
74#define ACCEL8_REG_SELF_TEST_X 0x0D
75#define ACCEL8_REG_SELF_TEST_Y 0x0E
76#define ACCEL8_REG_SELF_TEST_Z 0x0F
77#define ACCEL8_REG_SELF_TEST_A 0x10
78#define ACCEL8_REG_SMPLRT_DIV 0x19
79#define ACCEL8_REG_CONFIG 0x1A
80#define ACCEL8_REG_GYRO_CONFIG 0x1B
81#define ACCEL8_REG_ACCEL_CONFIG 0x1C
82#define ACCEL8_REG_FIFO_EN 0x23
83#define ACCEL8_REG_I2C_MST_CTRL 0x24
84#define ACCEL8_REG_I2C_SLV0_ADDR 0x25
85#define ACCEL8_REG_I2C_SLV0_REG 0x26
86#define ACCEL8_REG_I2C_SLV0_CTRL 0x27
87#define ACCEL8_REG_I2C_SLV1_ADDR 0x28
88#define ACCEL8_REG_I2C_SLV1_REG 0x29
89#define ACCEL8_REG_I2C_SLV1_CTRL 0x2A
90#define ACCEL8_REG_I2C_SLV2_ADDR 0x2B
91#define ACCEL8_REG_I2C_SLV2_REG 0x2C
92#define ACCEL8_REG_I2C_SLV2_CTRL 0x2D
93#define ACCEL8_REG_I2C_SLV3_ADDR 0x2E
94#define ACCEL8_REG_I2C_SLV3_REG 0x2F
95#define ACCEL8_REG_I2C_SLV3_CTRL 0x30
96#define ACCEL8_REG_I2C_SLV4_ADDR 0x31
97#define ACCEL8_REG_I2C_SLV4_REG 0x32
98#define ACCEL8_REG_I2C_SLV4_DO 0x33
99#define ACCEL8_REG_I2C_SLV4_CTRL 0x34
100#define ACCEL8_REG_I2C_SLV4_DI 0x35
101#define ACCEL8_REG_I2C_MST_STATUS 0x36
102#define ACCEL8_REG_INT_PIN_CFG 0x37
103#define ACCEL8_REG_INT_ENABLE 0x38
104#define ACCEL8_REG_INT_STATUS 0x3A
105#define ACCEL8_REG_ACCEL_XOUT_H 0x3B
106#define ACCEL8_REG_ACCEL_XOUT_L 0x3C
107#define ACCEL8_REG_ACCEL_YOUT_H 0x3D
108#define ACCEL8_REG_ACCEL_YOUT_L 0x3E
109#define ACCEL8_REG_ACCEL_ZOUT_H 0x3F
110#define ACCEL8_REG_ACCEL_ZOUT_L 0x40
111#define ACCEL8_REG_TEMP_OUT_H 0x41
112#define ACCEL8_REG_TEMP_OUT_L 0x42
113#define ACCEL8_REG_GYRO_XOUT_H 0x43
114#define ACCEL8_REG_GYRO_XOUT_L 0x44
115#define ACCEL8_REG_GYRO_YOUT_H 0x45
116#define ACCEL8_REG_GYRO_YOUT_L 0x46
117#define ACCEL8_REG_GYRO_ZOUT_H 0x47
118#define ACCEL8_REG_GYRO_ZOUT_L 0x48
119#define ACCEL8_REG_EXT_SENS_DATA_00 0x49
120#define ACCEL8_REG_EXT_SENS_DATA_01 0x4A
121#define ACCEL8_REG_EXT_SENS_DATA_02 0x4B
122#define ACCEL8_REG_EXT_SENS_DATA_03 0x4C
123#define ACCEL8_REG_EXT_SENS_DATA_04 0x4D
124#define ACCEL8_REG_EXT_SENS_DATA_05 0x4E
125#define ACCEL8_REG_EXT_SENS_DATA_06 0x4F
126#define ACCEL8_REG_EXT_SENS_DATA_07 0x50
127#define ACCEL8_REG_EXT_SENS_DATA_08 0x51
128#define ACCEL8_REG_EXT_SENS_DATA_09 0x52
129#define ACCEL8_REG_EXT_SENS_DATA_10 0x53
130#define ACCEL8_REG_EXT_SENS_DATA_11 0x54
131#define ACCEL8_REG_EXT_SENS_DATA_12 0x55
132#define ACCEL8_REG_EXT_SENS_DATA_13 0x56
133#define ACCEL8_REG_EXT_SENS_DATA_14 0x57
134#define ACCEL8_REG_EXT_SENS_DATA_15 0x58
135#define ACCEL8_REG_EXT_SENS_DATA_16 0x59
136#define ACCEL8_REG_EXT_SENS_DATA_17 0x5A
137#define ACCEL8_REG_EXT_SENS_DATA_18 0x5B
138#define ACCEL8_REG_EXT_SENS_DATA_19 0x5C
139#define ACCEL8_REG_EXT_SENS_DATA_20 0x5D
140#define ACCEL8_REG_EXT_SENS_DATA_21 0x5E
141#define ACCEL8_REG_EXT_SENS_DATA_22 0x5F
142#define ACCEL8_REG_EXT_SENS_DATA_23 0x60
143#define ACCEL8_REG_I2C_SLV0_DO 0x63
144#define ACCEL8_REG_I2C_SLV1_DO 0x64
145#define ACCEL8_REG_I2C_SLV2_DO 0x65
146#define ACCEL8_REG_I2C_SLV3_DO 0x66
147#define ACCEL8_REG_I2C_MST_DELAY_CTRL 0x67
148#define ACCEL8_REG_SIGNAL_PATH_RESET 0x68
149#define ACCEL8_REG_USER_CTRL 0x6A
150#define ACCEL8_REG_PWR_MGMT_1 0x6B
151#define ACCEL8_REG_PWR_MGMT_2 0x6C
152#define ACCEL8_REG_FIFO_COUNTH 0x72
153#define ACCEL8_REG_FIFO_COUNTL 0x73
154#define ACCEL8_REG_FIFO_R_W 0x74
155#define ACCEL8_REG_WHO_AM_I 0x75
162#define ACCEL8_CFG_EXT_SYNC_INPUT_DISABLED 0x00 << 3
163#define ACCEL8_CFG_EXT_SYNC_TEMP_OUTPUT 0x01 << 3
164#define ACCEL8_CFG_EXT_SYNC_GYRO_X_OUTPUT 0x02 << 3
165#define ACCEL8_CFG_EXT_SYNC_GYRO_Y_OUTPUT 0x03 << 3
166#define ACCEL8_CFG_EXT_SYNC_GYRO_Z_OUTPUT 0x04 << 3
167#define ACCEL8_CFG_EXT_SYNC_ACCEL_X_OUTPUT 0x05 << 3
168#define ACCEL8_CFG_EXT_SYNC_ACCEL_Y_OUTPUT 0x06 << 3
169#define ACCEL8_CFG_EXT_SYNC_ACCEL_Z_OUTPUT 0x07 << 3
170#define ACCEL8_CFG_DLPF_CFG_BW_A260_G256 0x00
171#define ACCEL8_CFG_DLPF_CFG_BW_A184_G188 0x01
172#define ACCEL8_CFG_DLPF_CFG_BW_A94_G98 0x02
173#define ACCEL8_CFG_DLPF_CFG_BW_A44_G42 0x03
174#define ACCEL8_CFG_DLPF_CFG_BW_A21_G20 0x04
175#define ACCEL8_CFG_DLPF_CFG_BW_A10_G10 0x05
176#define ACCEL8_CFG_DLPF_CFG_BW_A5_G5 0x06
183#define ACCEL8_GYRO_CFG_X_SELF_TEST 0x80
184#define ACCEL8_GYRO_CFG_Y_SELF_TEST 0x40
185#define ACCEL8_GYRO_CFG_Z_SELF_TEST 0x20
186#define ACCEL8_GYRO_CFG_FULL_SCALE_RANGE_250dbs 0x00
187#define ACCEL8_GYRO_CFG_FULL_SCALE_RANGE_500dbs 0x08
188#define ACCEL8_GYRO_CFG_FULL_SCALE_RANGE_1000dbs 0x10
189#define ACCEL8_GYRO_CFG_FULL_SCALE_RANGE_2000dbs 0x18
196#define ACCEL8_ACCEL_CFG_X_SELF_TEST 0x80
197#define ACCEL8_ACCEL_CFG_Y_SELF_TEST 0x40
198#define ACCEL8_ACCEL_CFG_Z_SELF_TEST 0x20
199#define ACCEL8_ACCEL_CFG_FULL_SCALE_RANGE_2g 0x00
200#define ACCEL8_ACCEL_CFG_FULL_SCALE_RANGE_4g 0x08
201#define ACCEL8_ACCEL_CFG_FULL_SCALE_RANGE_8g 0x10
202#define ACCEL8_ACCEL_CFG_FULL_SCALE_RANGE_16g 0x18
209#define ACCEL8_FIFO_ENABLE_TEMP 0x80
210#define ACCEL8_FIFO_ENABLE_X_AXIS_GYRO 0x40
211#define ACCEL8_FIFO_ENABLE_Y_AXIS_GYRO 0x20
212#define ACCEL8_FIFO_ENABLE_Z_AXIS_GYRO 0x10
213#define ACCEL8_FIFO_ENABLE_ACCEL 0x08
214#define ACCEL8_FIFO_ENABLE_EXT_SENS_DATA_SLV2 0x04
215#define ACCEL8_FIFO_ENABLE_EXT_SENS_DATA_SLV1 0x02
216#define ACCEL8_FIFO_ENABLE_EXT_SENS_DATA_SLV0 0x01
223#define ACCEL8_I2C_MST_CTRL_MUL_MST_ENABLE 0x80
224#define ACCEL8_I2C_MST_CTRL_WAIT_FOR_ES 0x40
225#define ACCEL8_I2C_MST_CTRL_EXT_SENS_DATA_SLV3 0x20
226#define ACCEL8_I2C_MST_CTRL_I2C_RESTART_BETWEEN_READS 0x00
227#define ACCEL8_I2C_MST_CTRL_I2C_STOP_AND_START 0x10
228#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_348kHz 0x00
229#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_333kHz 0x01
230#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_320kHz 0x02
231#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_308kHz 0x03
232#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_296kHz 0x04
233#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_286kHz 0x05
234#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_276kHz 0x06
235#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_367kHz 0x07
236#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_358kHz 0x08
237#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_500kHz 0x09
238#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_471kHz 0x0A
239#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_444kHz 0x0B
240#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_421kHz 0x0C
241#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_400kHz 0x0D
242#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_381kHz 0x0E
243#define ACCEL8_I2C_MST_CTRL_I2C_CLOCK_364kHz 0x0F
250#define ACCEL8_INTC_INT_PIN_IS_ACTIVE_HIGH 0x00
251#define ACCEL8_INTC_INT_PIN_IS_ACTIVE_LOW 0x80
252#define ACCEL8_INTC_INT_PIN_IS_CONFIGURED_AS_PUSH_PULL 0x00
253#define ACCEL8_INTC_INT_PIN_IS_CONFIGURED_AS_OPEN_DRAIN 0x40
254#define ACCEL8_INTC_LATCH_INT_ENABLE 0x20
255#define ACCEL8_INTC_INT_READ_CLEAR 0x10
256#define ACCEL8_INTC_FSYNC_INT_LEVEL_ACTIVE_HIGH 0x00
257#define ACCEL8_INTC_FSYNC_INT_LEVEL_ACTIVE_LOW 0x08
258#define ACCEL8_INTC_FSYNC_INT_ENABLE 0x04
259#define ACCEL8_INTC_I2C_BYPASS_ENABLE 0x02
260#define ACCEL8_INTC_I2C_BYPASS_DISABLE 0x00
267#define ACCEL8_INTE_FIFO_OFLOW_ENABLE 0x10
268#define ACCEL8_INTE_I2C_MST_INT_ENABLE 0x08
269#define ACCEL8_INTE_DATA_RDY_ENABLE 0x01
276#define ACCEL8_INTS_FIFO_OFLOW 0x10
277#define ACCEL8_INTS_I2C_MST_INT 0x08
278#define ACCEL8_INTS_DATA_RDY 0x01
285#define ACCEL8_ACCEL_X_AXIS_DATA 0x3B
286#define ACCEL8_ACCEL_Y_AXIS_DATA 0x3D
287#define ACCEL8_ACCEL_Z_AXIS_DATA 0x3F
288#define ACCEL8_TEMP_DATA 0x41
289#define ACCEL8_GYRO_X_AXIS_DATA 0x43
290#define ACCEL8_GYRO_Y_AXIS_DATA 0x45
291#define ACCEL8_GYRO_Z_AXIS_DATA 0x47
298#define ACCEL8_GYRO_RESET 0x04
299#define ACCEL8_ACCEL_RESET 0x02
300#define ACCEL8_TEMP_RESET 0x01
307#define ACCEL8_UC_FIFO_ENABLE 0x40
308#define ACCEL8_UC_I2C_MASTER_MODE 0x20
309#define ACCEL8_UC_FIFO_RESET 0x04
310#define ACCEL8_UC_I2C_MASTER_RESET 0x02
311#define ACCEL8_UC_SIG_COND_RESET 0x01
318#define ACCEL8_PM1_DEVICE_RESET 0x80
319#define ACCEL8_PM1_GO_TO_SLEEP 0x40
320#define ACCEL8_PM1_CYCLE 0x20
321#define ACCEL8_PM1_TEMP_DISABLE 0x08
322#define ACCEL8_PM1_CLKSEL_INTERNAL_8MHZ_OSCILLATOR 0x00
323#define ACCEL8_PM1_CLKSEL_PLL_WITH_X_AXIS_GYROSCOPE 0x01
324#define ACCEL8_PM1_CLKSEL_PLL_WITH_Y_AXIS_GYROSCOPE 0x02
325#define ACCEL8_PM1_CLKSEL_PLL_WITH_Z_AXIS_GYROSCOPE 0x03
326#define ACCEL8_PM1_CLKSEL_PLL_WITH_EXTERNAL_32_768kHz 0x04
327#define ACCEL8_PM1_CLKSEL_PLL_WITH_EXTERNAL_19_2kHz 0x05
328#define ACCEL8_PM1_CLKSEL_STOPS_THE_CLOCK 0x07
335#define ACCEL8_PM2_LP_WAKE_CTRL_WAKE_UP_FREQ_1_25Hz 0x00
336#define ACCEL8_PM2_LP_WAKE_CTRL_WAKE_UP_FREQ_5Hz 0x40
337#define ACCEL8_PM2_LP_WAKE_CTRL_WAKE_UP_FREQ_20Hz 0x80
338#define ACCEL8_PM2_LP_WAKE_CTRL_WAKE_UP_FREQ_40Hz 0xC0
339#define ACCEL8_PM2_LP_WAKE_CTRL_X_AXIS_ACCEL_STANDBY_MODE 0x20
340#define ACCEL8_PM2_LP_WAKE_CTRL_Y_AXIS_ACCEL_STANDBY_MODE 0x10
341#define ACCEL8_PM2_LP_WAKE_CTRL_Z_AXIS_ACCEL_STANDBY_MODE 0x08
342#define ACCEL8_PM2_LP_WAKE_CTRL_X_AXIS_GYRO_STANDBY_MODE 0x04
343#define ACCEL8_PM2_LP_WAKE_CTRL_Y_AXIS_GYRO_STANDBY_MODE 0x02
344#define ACCEL8_PM2_LP_WAKE_CTRL_Z_AXIS_GYRO_STANDBY_MODE 0x01
351#define ACCEL8_DEVICE_SLAVE_ADDRESS_ADD 0x69
352#define ACCEL8_DEVICE_SLAVE_ADDRESS_SEL 0x68 // End group macro
356// --------------------------------------------------------------- PUBLIC TYPES
365typedef struct
366{
367 // Input pins
368
369 digital_in_t da;
370 digital_in_t cl;
371 digital_in_t int_pin;
372
373 // Modules
374
375 i2c_master_t i2c;
376
377 // ctx variable
378
380
381} accel8_t;
382
386typedef struct
387{
388 // Communication gpio pins
389
390 pin_name_t scl;
391 pin_name_t sda;
392
393 // Additional gpio pins
394
395 pin_name_t da;
396 pin_name_t cl;
397 pin_name_t int_pin;
398
399 // static variable
400
401 uint32_t i2c_speed;
402 uint8_t i2c_address;
403
405
409typedef struct
410{
411 //ranges
412
413 uint8_t accel_range;
414 uint16_t gyro_range;
415
417 // End types group
419// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
420
426#ifdef __cplusplus
427extern "C"{
428#endif
429
439
449
460void accel8_default_cfg ( accel8_t *ctx, uint8_t accel_cfg, uint8_t gyro_cfg, range_retval_t *rng );
461
472void accel8_generic_write ( accel8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
473
484void accel8_generic_read ( accel8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
485
496uint16_t accel8_read_data ( accel8_t *ctx, uint8_t reg );
497
513
524void accel8_get_accel_axis ( accel8_t *ctx, int16_t *x_axis, int16_t *y_axis, int16_t *z_axis );
525
536void accel8_get_gyro_axis ( accel8_t *ctx, int16_t *x_axis, int16_t *y_axis, int16_t *z_axis );
537
548
549#ifdef __cplusplus
550}
551#endif
552#endif // _ACCEL8_H_
553 // End public_function group
556
557// ------------------------------------------------------------------------- END
#define ACCEL8_RETVAL
Definition: accel8.h:64
void accel8_cfg_setup(accel8_cfg_t *cfg)
Config Object Initialization function.
void accel8_get_accel_axis(accel8_t *ctx, int16_t *x_axis, int16_t *y_axis, int16_t *z_axis)
Functions for read Accel axis data.
uint8_t accel8_get_interrupt(accel8_t *ctx)
Functions for read INT pin state.
void accel8_generic_write(accel8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void accel8_default_cfg(accel8_t *ctx, uint8_t accel_cfg, uint8_t gyro_cfg, range_retval_t *rng)
Click Default Configuration function.
uint16_t accel8_read_data(accel8_t *ctx, uint8_t reg)
Generic read function.
void accel8_get_gyro_axis(accel8_t *ctx, int16_t *x_axis, int16_t *y_axis, int16_t *z_axis)
Functions for read Gyro axis data.
void accel8_generic_read(accel8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
ACCEL8_RETVAL accel8_init(accel8_t *ctx, accel8_cfg_t *cfg)
Initialization function.
float accel8_get_temperature(accel8_t *ctx)
Functions for read Temperature data in C.
Click configuration structure definition.
Definition: accel8.h:387
pin_name_t da
Definition: accel8.h:395
pin_name_t cl
Definition: accel8.h:396
uint32_t i2c_speed
Definition: accel8.h:401
pin_name_t scl
Definition: accel8.h:390
pin_name_t int_pin
Definition: accel8.h:397
pin_name_t sda
Definition: accel8.h:391
uint8_t i2c_address
Definition: accel8.h:402
Click ctx object definition.
Definition: accel8.h:366
digital_in_t cl
Definition: accel8.h:370
digital_in_t da
Definition: accel8.h:369
digital_in_t int_pin
Definition: accel8.h:371
i2c_master_t i2c
Definition: accel8.h:375
uint8_t slave_address
Definition: accel8.h:379
Click range structure definition.
Definition: accel8.h:410
uint8_t accel_range
Definition: accel8.h:413
uint16_t gyro_range
Definition: accel8.h:414