39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
74#define ACCEL15_REG_CHIP_ID 0x00
75#define ACCEL15_REG_ERROR 0x02
76#define ACCEL15_REG_STATUS 0x03
77#define ACCEL15_REG_DATA_0 0x0A
78#define ACCEL15_REG_DATA_8 0x12
79#define ACCEL15_REG_SENSORTIME_0 0x18
80#define ACCEL15_REG_EVENT 0x1B
81#define ACCEL15_REG_INT_STAT_0 0x1C
82#define ACCEL15_REG_INT_STAT_1 0x1D
83#define ACCEL15_REG_TEMPERATURE 0x22
84#define ACCEL15_REG_FIFO_LENGTH_0 0x24
85#define ACCEL15_REG_FIFO_DATA 0x26
86#define ACCEL15_REG_INTERNAL_STAT 0x2A
87#define ACCEL15_REG_ACCEL_CONFIG 0x40
88#define ACCEL15_REG_ACCEL_RANGE 0x41
89#define ACCEL15_REG_AUX_CONF 0x44
90#define ACCEL15_REG_FIFO_DOWN 0x45
91#define ACCEL15_REG_FIFO_WTM_0 0x46
92#define ACCEL15_REG_FIFO_CONFIG_0 0x48
93#define ACCEL15_REG_FIFO_CONFIG_1 0x49
94#define ACCEL15_REG_AUX_DEV_ID 0x4B
95#define ACCEL15_REG_AUX_IF_CONF 0x4C
96#define ACCEL15_REG_AUX_RD 0x4D
97#define ACCEL15_REG_INT1_IO_CTRL 0x53
98#define ACCEL15_REG_INT2_IO_CTRL 0x54
99#define ACCEL15_REG_INT_LATCH 0x55
100#define ACCEL15_REG_INT_MAP_1 0x56
101#define ACCEL15_REG_INT_MAP_2 0x57
102#define ACCEL15_REG_INT_MAP_DATA 0x58
103#define ACCEL15_REG_INIT_CTRL 0x59
104#define ACCEL15_REG_RESERVED_REG_5B 0x5B
105#define ACCEL15_REG_RESERVED_REG_5C 0x5C
106#define ACCEL15_REG_FEATURE_CONFIG 0x5E
107#define ACCEL15_REG_INTERNAL_ERROR 0x5F
108#define ACCEL15_REG_ACC_SELF_TEST 0x6D
109#define ACCEL15_REG_ACC_SELF_TEST 0x6D
110#define ACCEL15_REG_NV_CONFIG 0x70
111#define ACCEL15_REG_OFFSET_0 0x71
112#define ACCEL15_REG_OFFSET_1 0x72
113#define ACCEL15_REG_OFFSET_2 0x73
114#define ACCEL15_REG_POWER_CONF 0x7C
115#define ACCEL15_REG_POWER_CTRL 0x7D
116#define ACCEL15_REG_CMD 0x7E
139#define ACCEL15_CHIP_ID 0x1A
140#define ACCEL15_FEATURE_SIZE 0x0C
141#define ACCEL15_RD_WR_MIN_LEN 0x02
142#define ACCEL15_RD_WR_MAX_LEN 1300
148#define ACCEL15_ANY_MOT_START_ADDR 0x00
149#define ACCEL15_NO_MOT_START_ADDR 0x04
150#define ACCEL15_CONFIG_ID_START_ADDR 0x08
151#define ACCEL15_AXES_REMAP_START_ADDR 0x0A
158#define ACCEL15_X_AXIS_MSK 0x03
159#define ACCEL15_X_AXIS_SIGN_MSK 0x04
160#define ACCEL15_Y_AXIS_MSK 0x18
161#define ACCEL15_Y_AXIS_SIGN_MSK 0x20
162#define ACCEL15_Z_AXIS_MSK 0xC0
163#define ACCEL15_Z_AXIS_SIGN_MSK 0x01
170#define ACCEL15_X_AXIS_SIGN_POS 0x02
171#define ACCEL15_Y_AXIS_POS 0x03
172#define ACCEL15_Y_AXIS_SIGN_POS 0x05
173#define ACCEL15_Z_AXIS_POS 0x06
180#define ACCEL15_X_AXIS_EN 0x01
181#define ACCEL15_Y_AXIS_EN 0x02
182#define ACCEL15_Z_AXIS_EN 0x04
183#define ACCEL15_EN_ALL_AXIS 0x07
184#define ACCEL15_DIS_ALL_AXIS 0x00
191#define ACCEL15_ANY_MOT_INT 0x20
192#define ACCEL15_NO_MOT_INT 0x40
193#define ACCEL15_ERROR_INT 0x80
200#define ACCEL15_INT1_IO_CTRL_INPUT_EN 0x10
201#define ACCEL15_INT1_IO_CTRL_OUTPUT_EN 0x08
202#define ACCEL15_INT1_IO_CTRL_OD_EN 0x04
203#define ACCEL15_INT1_IO_CTRL_LVL_HIGH 0x02
204#define ACCEL15_INT1_IO_CTRL_EDGE_EN 0x01
211#define ACCEL15_INT_MAP_DATA_INT2_DRDY 0x40
212#define ACCEL15_INT_MAP_DATA_INT2_FWM 0x20
213#define ACCEL15_INT_MAP_DATA_INT2_FFULL 0x10
214#define ACCEL15_INT_MAP_DATA_INT1_DRDY 0x04
215#define ACCEL15_INT_MAP_DATA_INT1_FWM 0x02
216#define ACCEL15_INT_MAP_DATA_INT1_FFULL 0x01
230#define ACCEL15_ACCEL_OFF 0x00
231#define ACCEL15_ACCEL_ON 0x04
232#define ACCEL15_AUX_OFF 0x00
233#define ACCEL15_AUX_ON 0x01
240#define ACCEL15_APS_OFF 0x00
241#define ACCEL15_APS_ON 0x01
242#define ACCEL15_FSW_OFF 0x00
243#define ACCEL15_FSW_ON 0x02
250#define ACCEL15_CONFIG_MAJOR_POS 0x06
257#define ACCEL15_DRDY 0x01
258#define ACCEL15_ACCEL_EN 0x40
259#define ACCEL15_ACCEL_DRDY 0x80
266#define ACCEL15_SPI_WR_MASK 0x7F
267#define ACCEL15_SPI_RD_MASK 0x80
274#define ACCEL15_ENABLE 0x01
275#define ACCEL15_DISABLE 0x00
282#define ACCEL15_CIC_AVG_MODE 0
283#define ACCEL15_CONTINUOUS_MODE 1
290#define ACCEL15_ADVANCE_POWER_SAVE_MSK 0x01
297#define ACCEL15_12_BIT_RESOLUTION 12
298#define ACCEL15_16_BIT_RESOLUTION 16
305#define ACCEL15_ACCEL_ENABLE_POS 2
306#define ACCEL15_ACCEL_ENABLE_MSK 0x04
313#define ACCEL15_SOFT_RESET 0x6B
320#define ACCEL15_ACCEL_ODR_MSK 0x0F
321#define ACCEL15_ACCEL_BW_POS 4
322#define ACCEL15_ACCEL_BW_MSK 0x70
323#define ACCEL15_ACCEL_RANGE_MSK 0x03
324#define ACCEL15_ACCEL_PERFMODE_POS 7
325#define ACCEL15_ACCEL_PERFMODE_MSK 0x80
332#define ACCEL15_ACCEL_CONFIG_LENGTH 2
333#define ACCEL15_FIFO_CONFIG_LENGTH 2
334#define ACCEL15_FIFO_WM_LENGTH 2
335#define ACCEL15_ACCEL_DATA_LENGTH 6
336#define ACCEL15_FIFO_DATA_LENGTH 2
337#define ACCEL15_MA_FIFO_A_X_LSB 8
338#define ACCEL15_SENSOR_TIME_MSB_BYTE 2
339#define ACCEL15_SENSOR_TIME_XLSB_BYTE 1
340#define ACCEL15_SENSOR_TIME_LSB_BYTE 0
341#define ACCEL15_FIFO_LENGTH_MSB_BYTE 1
348#define ACCEL15_OUTPUT_DATA_RATE_12_5HZ 0x05
349#define ACCEL15_OUTPUT_DATA_RATE_25HZ 0x06
350#define ACCEL15_OUTPUT_DATA_RATE_50HZ 0x07
351#define ACCEL15_OUTPUT_DATA_RATE_100HZ 0x08
352#define ACCEL15_OUTPUT_DATA_RATE_200HZ 0x09
353#define ACCEL15_OUTPUT_DATA_RATE_400HZ 0x0A
354#define ACCEL15_OUTPUT_DATA_RATE_800HZ 0x0B
355#define ACCEL15_OUTPUT_DATA_RATE_1600HZ 0x0C
362#define ACCEL15_ACCEL_OSR4_AVG1 0
363#define ACCEL15_ACCEL_OSR2_AVG2 1
364#define ACCEL15_ACCEL_NORMAL_AVG4 2
365#define ACCEL15_ACCEL_CIC_AVG8 3
366#define ACCEL15_ACCEL_RES_AVG16 4
367#define ACCEL15_ACCEL_RES_AVG32 5
368#define ACCEL15_ACCEL_RES_AVG64 6
369#define ACCEL15_ACCEL_RES_AVG128 7
376#define ACCEL15_ACCEL_RANGE_16G 0
377#define ACCEL15_ACCEL_RANGE_8G 1
378#define ACCEL15_ACCEL_RANGE_4G 2
379#define ACCEL15_ACCEL_RANGE_2G 3
386#define ACCEL15_FATAL_ERR_MSK 0x01
387#define ACCEL15_CMD_ERR_POS 1
388#define ACCEL15_CMD_ERR_MSK 0x02
389#define ACCEL15_ERR_CODE_POS 2
390#define ACCEL15_ERR_CODE_MSK 0x1C
391#define ACCEL15_FIFO_ERR_POS 6
392#define ACCEL15_FIFO_ERR_MSK 0x40
399#define ACCEL15_FIFO_SELF_WAKE_UP_POS 1
400#define ACCEL15_FIFO_SELF_WAKE_UP_MSK 0x02
401#define ACCEL15_FIFO_BYTE_COUNTER_MSB_MSK 0x3F
402#define ACCEL15_FIFO_DATA_POS 0
403#define ACCEL15_FIFO_DATA_MSK 0xFF
404#define ACCEL15_FIFO_DOWN_ACCEL_POS 4
405#define ACCEL15_FIFO_DOWN_ACCEL_MSK 0x70
406#define ACCEL15_FIFO_FILTER_ACCEL_POS 7
407#define ACCEL15_FIFO_FILTER_ACCEL_MSK 0x80
414#define ACCEL15_FIFO_HEADER_ACC 0x84
415#define ACCEL15_FIFO_HEADER_MAG 0x90
416#define ACCEL15_FIFO_HEADER_MAG_ACC 0x94
417#define ACCEL15_FIFO_HEADER_SENSOR_TIME 0x44
418#define ACCEL15_FIFO_HEADER_INPUT_CONFIG 0x48
419#define ACCEL15_FIFO_HEADER_SKIP_FRAME 0x40
420#define ACCEL15_FIFO_HEADER_OVER_READ_MSB 0x80
421#define ACCEL15_FIFO_HEADER_SAMPLE_DROP 0x50
422#define ACCEL15_FIFO_MAG_ACC_ENABLE 0x60
423#define ACCEL15_FIFO_ACC_ENABLE 0x40
424#define ACCEL15_FIFO_MAG_ENABLE 0x20
425#define ACCEL15_FIFO_STOP_ON_FULL 0x01
426#define ACCEL15_FIFO_TIME 0x02
427#define ACCEL15_FIFO_TAG_INTR2 0x04
428#define ACCEL15_FIFO_TAG_INTR1 0x08
429#define ACCEL15_FIFO_HEADER 0x10
430#define ACCEL15_FIFO_MAG 0x20
431#define ACCEL15_FIFO_ACCEL 0x40
432#define ACCEL15_FIFO_ALL 0x7F
433#define ACCEL15_FIFO_CONFIG_0_MASK 0x03
434#define ACCEL15_FIFO_CONFIG_1_MASK 0xFC
441#define ACCEL15_FIFO_LSB_CONFIG_CHECK 0x00
442#define ACCEL15_FIFO_MSB_CONFIG_CHECK 0x80
443#define ACCEL15_FIFO_TAG_INTR_MASK 0xFC
450#define ACCEL15_ACCEL_AUX_FIFO_DROP 0x05
451#define ACCEL15_ACCEL_FIFO_DROP 0x01
458#define ACCEL15_INIT_START 0x00
459#define ACCEL15_INIT_STOP 0x01
466#define ACCEL15_SENSOR_TIME_LENGTH 3
473#define ACCEL15_FIFO_ACC_LENGTH 6
474#define ACCEL15_FIFO_MAG_LENGTH 8
475#define ACCEL15_FIFO_MAG_ACC_LENGTH 14
476#define ACCEL15_CONFIG_STREAM_MESSAGE_MSK 0x0F
477#define ACCEL15_ASIC_INITIALIZED 0x01
484#define ACCEL15_ACCEL_CONFIG_FOC 0xB7
491#define ACCEL15_X_AXIS 0
492#define ACCEL15_Y_AXIS 1
493#define ACCEL15_Z_AXIS 2
500#define ACCEL15_NV_ENABLE_I2C 0x00
501#define ACCEL15_NV_DISABLE_I2C 0x01
502#define ACCEL15_NV_ACCEL_OFFSET_POS 3
503#define ACCEL15_NV_ACCEL_OFFSET_MSK 0x08
510#define ACCEL15_SELFTEST_PASS 0
511#define ACCEL15_SELFTEST_FAIL 1
512#define ACCEL15_SELFTEST_DIFF_X_AXIS_FAILED 1
513#define ACCEL15_SELFTEST_DIFF_Y_AXIS_FAILED 2
514#define ACCEL15_SELFTEST_DIFF_Z_AXIS_FAILED 3
515#define ACCEL15_SELFTEST_DIFF_X_AND_Y_AXIS_FAILED 4
516#define ACCEL15_SELFTEST_DIFF_X_AND_Z_AXIS_FAILED 5
517#define ACCEL15_SELFTEST_DIFF_Y_AND_Z_AXIS_FAILED 6
518#define ACCEL15_SELFTEST_DIFF_X_Y_AND_Z_AXIS_FAILED 7
525#define ACCEL15_ACCEL_SELFTEST_ENABLE_MSK 0x01
526#define ACCEL15_ACCEL_SELFTEST_SIGN_POS 2
527#define ACCEL15_ACCEL_SELFTEST_SIGN_MSK 0x04
528#define ACCEL15_SELFTEST_AMP_POS 3
529#define ACCEL15_SELFTEST_AMP_MSK 0x08
536#define ACCEL15_MAX_VALUE_FIFO_FILTER 1
537#define ACCEL15_MAX_VALUE_SPI3 1
538#define ACCEL15_MAX_VALUE_SELFTEST_AMP 1
539#define ACCEL15_MAX_IF_MODE 3
540#define ACCEL15_MAX_VALUE_SELFTEST_SIGN 1
547#define ACCEL15_FOC_ACC_CONF_VAL 0xB7
554#define ACCEL15_SPI_WRITE 0x00
555#define ACCEL15_SPI_READ 0x80
562#define ACCEL15_SET_DEV_ADDR_GND 0x18
563#define ACCEL15_SET_DEV_ADDR_VCC 0x19
581#define ACCEL15_MAP_MIKROBUS( cfg, mikrobus ) \
582 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
583 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
584 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
585 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
586 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
587 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
588 cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
589 cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_INT )
struct accel15_s accel15_t
Accel 15 Click context object.
err_t(* accel15_master_io_t)(struct accel15_s *, uint8_t, uint8_t *, uint8_t)
Accel 15 Click driver interface.
Definition accel15.h:609
accel15_return_value_t
Accel 15 Click return value data.
Definition accel15.h:674
@ ACCEL15_ERROR
Definition accel15.h:676
@ ACCEL15_OK
Definition accel15.h:675
accel15_drv_t
Accel 15 Click driver selector.
Definition accel15.h:599
@ ACCEL15_DRV_SEL_I2C
Definition accel15.h:601
@ ACCEL15_DRV_SEL_SPI
Definition accel15.h:600
void accel15_enable_accel(accel15_t *ctx)
Accel 15 enable accel function.
uint8_t accel15_get_int_2(accel15_t *ctx)
Accel 15 get Interrupt 1 function.
uint8_t accel15_get_internal_status(accel15_t *ctx)
Accel 15 internal status function.
err_t accel15_generic_write(accel15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Accel 15 data writing function.
uint8_t accel15_get_error(accel15_t *ctx)
Accel 15 get error function.
uint8_t accel15_get_int_1(accel15_t *ctx)
Accel 15 get Interrupt 1 function.
uint8_t accel15_get_status(accel15_t *ctx)
Accel 15 status function.
err_t accel15_get_axis_data(accel15_t *ctx, accel15_axis_t *axis)
Accel 15 get accelerometer axis function.
void accel15_cfg_setup(accel15_cfg_t *cfg)
Accel 15 configuration object setup function.
err_t accel15_init(accel15_t *ctx, accel15_cfg_t *cfg)
Accel 15 initialization function.
void accel15_soft_reset(accel15_t *ctx)
Accel 15 soft reset function.
err_t accel15_generic_read(accel15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Accel 15 data reading function.
void accel15_cfg_accel(accel15_t *ctx, uint8_t acc_odr, uint8_t g_range)
Accel 15 config accel function.
void accel15_drv_interface_selection(accel15_cfg_t *cfg, accel15_drv_t drv_sel)
Accel 15 driver interface setup function.
err_t accel15_check_id(accel15_t *ctx)
Accel 15 check ID function.
err_t accel15_default_cfg(accel15_t *ctx)
Accel 15 default configuration function.
Accel axis data structure.
Definition accel15.h:662
int16_t z
Definition accel15.h:665
int16_t x
Definition accel15.h:663
int16_t y
Definition accel15.h:664
Accel 15 Click configuration object.
Definition accel15.h:637
accel15_drv_t drv_sel
Definition accel15.h:654
uint32_t i2c_speed
Definition accel15.h:647
spi_master_chip_select_polarity_t cs_polarity
Definition accel15.h:652
pin_name_t in2
Definition accel15.h:644
pin_name_t sck
Definition accel15.h:642
spi_master_mode_t spi_mode
Definition accel15.h:651
pin_name_t mosi
Definition accel15.h:641
uint32_t spi_speed
Definition accel15.h:650
pin_name_t scl
Definition accel15.h:638
pin_name_t in1
Definition accel15.h:645
pin_name_t miso
Definition accel15.h:640
pin_name_t sda
Definition accel15.h:639
pin_name_t cs
Definition accel15.h:643
uint8_t i2c_address
Definition accel15.h:648
Accel 15 Click context object.
Definition accel15.h:616
digital_in_t in2
Definition accel15.h:617
spi_master_t spi
Definition accel15.h:621
accel15_drv_t drv_sel
Definition accel15.h:625
accel15_master_io_t read_f
Definition accel15.h:628
digital_in_t in1
Definition accel15.h:618
accel15_master_io_t write_f
Definition accel15.h:627
i2c_master_t i2c
Definition accel15.h:620
uint8_t slave_address
Definition accel15.h:623
pin_name_t chip_select
Definition accel15.h:624