Go to the documentation of this file.
38 #include "mikrosdk_version.h"
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 #include "drv_spi_master.h"
64 #define ACCEL6_MAP_MIKROBUS( cfg, mikrobus ) \
65 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
66 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
67 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
68 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
69 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
70 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
77 #define ACCEL6_MASTER_I2C 0
78 #define ACCEL6_MASTER_SPI 1
85 #define ACCEL6_RETVAL uint8_t
87 #define ACCEL6_OK 0x00
88 #define ACCEL6_INIT_ERROR 0xFF
95 #define ACCEL6_CHIP_ID 0xFB
96 #define ACCEL6_SOFT_RESET 0xB6
103 #define ACCEL6_AXIS_X 0x02
104 #define ACCEL6_AXIS_Y 0x04
105 #define ACCEL6_AXIS_Z 0x06
112 #define ACCEL6_REG_CHIP_ID 0x00
113 #define ACCEL6_REG_AXIS_X_LSB 0x02
114 #define ACCEL6_REG_AXIS_X_MSB 0x03
115 #define ACCEL6_REG_AXIS_Y_LSB 0x04
116 #define ACCEL6_REG_AXIS_Y_MSB 0x05
117 #define ACCEL6_REG_AXIS_Z_LSB 0x06
118 #define ACCEL6_REG_AXIS_Z_MSB 0x07
119 #define ACCEL6_REG_TEMPERATURE 0x08
120 #define ACCEL6_REG_INT_STATUS_0 0x09
121 #define ACCEL6_REG_INT_STATUS_1 0x0A
122 #define ACCEL6_REG_INT_STATUS_2 0x0B
123 #define ACCEL6_REG_INT_STATUS_3 0x0C
124 #define ACCEL6_REG_FIFO_STATUS 0x0E
125 #define ACCEL6_REG_PMU_RANGE 0x0F
126 #define ACCEL6_REG_PMU_BW 0x10
127 #define ACCEL6_REG_PMU_LPW 0x11
128 #define ACCEL6_REG_PMU_LOW_POWER 0x12
129 #define ACCEL6_REG_ACCD_HBW 0x13
130 #define ACCEL6_REG_BGW_SOFTRESET 0x14
131 #define ACCEL6_REG_INT_EN_0 0x16
132 #define ACCEL6_REG_INT_EN_1 0x17
133 #define ACCEL6_REG_INT_EN_2 0x18
134 #define ACCEL6_REG_INT_MAP_0 0x19
135 #define ACCEL6_REG_INT_MAP_1 0x1A
136 #define ACCEL6_REG_INT_MAP_2 0x1B
137 #define ACCEL6_REG_INT_SRC 0x1E
138 #define ACCEL6_REG_INT_OUT_CTRL 0x20
139 #define ACCEL6_REG_INT_RST_LATCH 0x21
140 #define ACCEL6_REG_INT1 0x23
141 #define ACCEL6_REG_INT2 0x24
142 #define ACCEL6_REG_INT3 0x25
143 #define ACCEL6_REG_INT4 0x26
144 #define ACCEL6_REG_INT5 0x27
145 #define ACCEL6_REG_INT6 0x28
146 #define ACCEL6_REG_INT7 0x29
147 #define ACCEL6_REG_INT8 0x2A
148 #define ACCEL6_REG_INT9 0x2B
149 #define ACCEL6_REG_INT_A 0x2C
150 #define ACCEL6_REG_INT_B 0x2D
151 #define ACCEL6_REG_INT_C 0x2E
152 #define ACCEL6_REG_INT_D 0x2F
153 #define ACCEL6_REG_FIFO_CONFIG_0 0x30
154 #define ACCEL6_REG_PMU_SELF_TEST 0x32
155 #define ACCEL6_REG_TRIM_NVM_CTRL 0x33
156 #define ACCEL6_REG_BGW_SPI3_WDT 0x34
157 #define ACCEL6_REG_OFC_CTRL 0x36
158 #define ACCEL6_REG_OFC_SETTINGS 0x37
159 #define ACCEL6_REG_OFC_OFFSET_X 0x38
160 #define ACCEL6_REG_OFC_OFFSET_Y 0x39
161 #define ACCEL6_REG_OFC_OFFSET_Z 0x3A
162 #define ACCEL6_REG_TRIM_GP_0 0x3B
163 #define ACCEL6_REG_TRIM_GP_1 0x3C
164 #define ACCEL6_REG_FIFO_CONFIG_1 0x3E
165 #define ACCEL6_REG_FIFO_DATA 0x3F
172 #define ACCEL6_STATUS_0_FLAT_INT 0x80
173 #define ACCEL6_STATUS_0_ORIENT_INT 0x40
174 #define ACCEL6_STATUS_0_SINGLE_TAP_INT 0x20
175 #define ACCEL6_STATUS_0_DOUBLE_TAP_INT 0x10
176 #define ACCEL6_STATUS_0_MOTION_INT 0x08
177 #define ACCEL6_STATUS_0_SLOPE_INT 0x04
178 #define ACCEL6_STATUS_0_HIGH_INT 0x02
179 #define ACCEL6_STATUS_0_LOW_INT 0x01
186 #define ACCEL6_STATUS_1_DATA_INT 0x80
187 #define ACCEL6_STATUS_1_FIFO_WM_INT 0x40
188 #define ACCEL6_STATUS_1_FIFO_FULL_INT 0x20
195 #define ACCEL6_STATUS_2_TAP_SING 0x80
196 #define ACCEL6_STATUS_2_TAP_FIRST_Z 0x40
197 #define ACCEL6_STATUS_2_TAP_FIRST_Y 0x20
198 #define ACCEL6_STATUS_2_TAP_FIRST_X 0x10
199 #define ACCEL6_STATUS_2_SLOPE_SING 0x08
200 #define ACCEL6_STATUS_2_SLOPE_FIRST_Z 0x04
201 #define ACCEL6_STATUS_2_SLOPE_FIRST_Y 0x02
202 #define ACCEL6_STATUS_2_SLOPE_FIRST_X 0x01
209 #define ACCEL6_STATUS_3_FLAT_POSITION 0x80
210 #define ACCEL6_STATUS_3_ORIENT_Z_UPWARD 0x00
211 #define ACCEL6_STATUS_3_ORIENT_Z_DOWNWARD 0x40
212 #define ACCEL6_STATUS_3_ORIENT_XY_UPRIGHT 0x00
213 #define ACCEL6_STATUS_3_ORIENT_XY_UPSIDE 0x10
214 #define ACCEL6_STATUS_3_ORIENT_XY_LANDSCAPE_LEFT 0x20
215 #define ACCEL6_STATUS_3_ORIENT_XY_LANDSCAPE_RIGHT 0x30
216 #define ACCEL6_STATUS_3_HIGH_SING_POSITIVE 0x00
217 #define ACCEL6_STATUS_3_HIGH_SING_NEGATIVE 0x08
218 #define ACCEL6_STATUS_3_HIGH_FIRST_Z 0x04
219 #define ACCEL6_STATUS_3_HIGH_FIRST_Y 0x02
220 #define ACCEL6_STATUS_3_HIGH_FIRST_X 0x01
227 #define ACCEL6_PMU_RANGE_2g 0x03
228 #define ACCEL6_PMU_RANGE_4g 0x05
229 #define ACCEL6_PMU_RANGE_8g 0x08
230 #define ACCEL6_PMU_RANGE_16g 0x0C
237 #define ACCEL6_PMU_BW_7_81Hz 0x08
238 #define ACCEL6_PMU_BW_15_63Hz 0x09
239 #define ACCEL6_PMU_BW_31_25Hz 0x0A
240 #define ACCEL6_PMU_BW_62_5Hz 0x0B
241 #define ACCEL6_PMU_BW_125Hz 0x0C
242 #define ACCEL6_PMU_BW_250Hz 0x0D
243 #define ACCEL6_PMU_BW_500Hz 0x0E
250 #define ACCEL6_PMU_LPW_NORMAL_MODE 0x00
251 #define ACCEL6_PMU_LPW_DEEP_SUSPEND_MODE 0x20
252 #define ACCEL6_PMU_LPW_LOW_POWER_MODE 0x40
253 #define ACCEL6_PMU_LPW_SUSPEND_MODE 0x80
254 #define ACCEL6_PMU_LPW_SLEEP_0_5ms 0x05
255 #define ACCEL6_PMU_LPW_SLEEP_1ms 0x06
256 #define ACCEL6_PMU_LPW_SLEEP_2ms 0x07
257 #define ACCEL6_PMU_LPW_SLEEP_4ms 0x08
258 #define ACCEL6_PMU_LPW_SLEEP_6ms 0x09
259 #define ACCEL6_PMU_LPW_SLEEP_10ms 0x0A
260 #define ACCEL6_PMU_LPW_SLEEP_25ms 0x0B
261 #define ACCEL6_PMU_LPW_SLEEP_50ms 0x0C
262 #define ACCEL6_PMU_LPW_SLEEP_100ms 0x0D
263 #define ACCEL6_PMU_LPW_SLEEP_500ms 0x0E
270 #define ACCEL6_INT_EN_0_FLAT_ENABLE 0x80
271 #define ACCEL6_INT_EN_0_ORIENT_ENABLE 0x40
272 #define ACCEL6_INT_EN_0_SINGLE_TAP_ENABLE 0x20
273 #define ACCEL6_INT_EN_0_DOUBLE_TAP_ENABLE 0x10
274 #define ACCEL6_INT_EN_0_SLOPE_Z_ENABLE 0x04
275 #define ACCEL6_INT_EN_0_SLOPE_Y_ENABLE 0x02
276 #define ACCEL6_INT_EN_0_SLOPE_X_ENABLE 0x01
283 #define ACCEL6_INT_EN_1_FIFO_WM_ENABLE 0x40
284 #define ACCEL6_INT_EN_1_FIFO_FULL_ENABLE 0x20
285 #define ACCEL6_INT_EN_1_DATA_ENABLE 0x10
286 #define ACCEL6_INT_EN_1_LOW_ENABLE 0x08
287 #define ACCEL6_INT_EN_1_HIGH_Z_ENABLE 0x04
288 #define ACCEL6_INT_EN_1_HIGH_Y_ENABLE 0x02
289 #define ACCEL6_INT_EN_1_HIGH_X_ENABLE 0x01
296 #define ACCEL6_INT_EN_2_MOTION_ENABLE 0x08
297 #define ACCEL6_INT_EN_2_MOTION_Z_ENABLE 0x04
298 #define ACCEL6_INT_EN_2_MOTION_Y_ENABLE 0x02
299 #define ACCEL6_INT_EN_2_MOTION_X_ENABLE 0x01
306 #define ACCEL6_INT1_MAP_FLAT_ENABLE 0x80
307 #define ACCEL6_INT1_MAP_ORIENT_ENABLE 0x40
308 #define ACCEL6_INT1_MAP_SINGLE_TAP_ENABLE 0x20
309 #define ACCEL6_INT1_MAP_DOUBLE_TAP_ENABLE 0x10
310 #define ACCEL6_INT1_MAP_MOTION_ENABLE 0x08
311 #define ACCEL6_INT1_MAP_SLOPE_ENABLE 0x04
312 #define ACCEL6_INT1_MAP_HIGH_ENABLE 0x02
313 #define ACCEL6_INT1_MAP_LOW_ENABLE 0x01
320 #define ACCEL6_INT2_MAP_DATA_ENABLE 0x80
321 #define ACCEL6_INT2_MAP_FIFO_WM_ENABLE 0x40
322 #define ACCEL6_INT2_MAP_FIFO_FULL_ENABLE 0x20
323 #define ACCEL6_INT1_MAP_DATA_ENABLE 0x01
324 #define ACCEL6_INT1_MAP_FIFO_WM_ENABLE 0x02
325 #define ACCEL6_INT1_MAP_FIFO_FULL_ENABLE 0x04
332 #define ACCEL6_INT2_MAP_FLAT_ENABLE 0x80
333 #define ACCEL6_INT2_MAP_ORIENT_ENABLE 0x40
334 #define ACCEL6_INT2_MAP_SINGLE_TAP_ENABLE 0x20
335 #define ACCEL6_INT2_MAP_DOUBLE_TAP_ENABLE 0x10
336 #define ACCEL6_INT2_MAP_MOTION_ENABLE 0x08
337 #define ACCEL6_INT2_MAP_SLOPE_ENABLE 0x04
338 #define ACCEL6_INT2_MAP_HIGH_ENABLE 0x02
339 #define ACCEL6_INT2_MAP_LOW_ENABLE 0x01
346 #define ACCEL6_INT_SRC_DATA 0x20
347 #define ACCEL6_INT_SRC_TAP 0x10
348 #define ACCEL6_INT_SRC_MOTION 0x08
349 #define ACCEL6_INT_SRC_SLOPE 0x04
350 #define ACCEL6_INT_SRC_HIGH 0x02
351 #define ACCEL6_INT_SRC_LOW 0x01
358 #define ACCEL6_INT2_CTRL_OPEN_DRAIN 0x08
359 #define ACCEL6_INT1_CTRL_OPEN_DRAIN 0x02
360 #define ACCEL6_INT2_CTRL_ACTIVE_HIGH_LEVEL 0x04
361 #define ACCEL6_INT1_CTRL_ACTIVE_HIGH_LEVEL 0x01
368 #define ACCEL6_LATCH_RESET_INT 0x80
369 #define ACCEL6_LATCH_INT_250ms 0x01
370 #define ACCEL6_LATCH_INT_500ms 0x02
371 #define ACCEL6_LATCH_INT_1sec 0x03
372 #define ACCEL6_LATCH_INT_2sec 0x04
373 #define ACCEL6_LATCH_INT_4sec 0x05
374 #define ACCEL6_LATCH_INT_8sec 0x06
375 #define ACCEL6_LATCH_INT_250us 0x09
376 #define ACCEL6_LATCH_INT_500us 0x0A
377 #define ACCEL6_LATCH_INT_1ms 0x0B
378 #define ACCEL6_LATCH_INT_12_5ms 0x0C
379 #define ACCEL6_LATCH_INT_25ms 0x0D
380 #define ACCEL6_LATCH_INT_50ms 0x0E
387 #define ACCEL6_TAP_QUIET_30ms 0x00
388 #define ACCEL6_TAP_QUIET_20ms 0x80
389 #define ACCEL6_TAP_SHOCK_50ms 0x00
390 #define ACCEL6_TAP_SHOCK_75ms 0x40
391 #define ACCEL6_TAP_DUR_50ms 0x00
392 #define ACCEL6_TAP_DUR_100ms 0x01
393 #define ACCEL6_TAP_DUR_150ms 0x02
394 #define ACCEL6_TAP_DUR_200ms 0x03
395 #define ACCEL6_TAP_DUR_250ms 0x04
396 #define ACCEL6_TAP_DUR_375ms 0x05
397 #define ACCEL6_TAP_DUR_500ms 0x06
398 #define ACCEL6_TAP_DUR_700ms 0x07
405 #define ACCEL6_TAP_2_SAMPLES 0x00
406 #define ACCEL6_TAP_4_SAMPLES 0x40
407 #define ACCEL6_TAP_8_SAMPLES 0x80
408 #define ACCEL6_TAP_16_SAMPLES 0xC0
415 #define ACCEL6_SELF_TEST_SING_POSITIVE 0x40
416 #define ACCEL6_SELF_TEST_SING_NEGATIVE 0x00
417 #define ACCEL6_SELF_TEST_DISABLE 0x00
418 #define ACCEL6_SELF_TEST_X_AXIS 0x01
419 #define ACCEL6_SELF_TEST_Y_AXIS 0x02
420 #define ACCEL6_SELF_TEST_Z_AXIS 0x03
427 #define ACCEL6_I2C_ENABLE 0x04
428 #define ACCEL6_I2C_DISABLE 0x00
429 #define ACCEL6_I2C_WTD_1ms 0x00
430 #define ACCEL6_I2C_WTD_50ms 0x02
431 #define ACCEL6_SPI_4_WIRE 0x00
432 #define ACCEL6_SPI_3_WIRE 0x01
439 #define ACCEL6_OFFSET_RESET 0x80
440 #define ACCEL6_OFFSET_TRIGGER_X_AXIS 0x20
441 #define ACCEL6_OFFSET_TRIGGER_Y_AXIS 0x40
442 #define ACCEL6_OFFSET_TRIGGER_Z_AXIS 0x60
443 #define ACCEL6_OFFSET_NOT_TRIGGER 0x00
444 #define ACCEL6_OFC_HP_X_ENABLE 0x04
445 #define ACCEL6_OFC_HP_Y_ENABLE 0x02
446 #define ACCEL6_OFC_HP_Z_ENABLE 0x01
453 #define ACCEL6_OFFSET_TARGET_Z_0g 0x00
454 #define ACCEL6_OFFSET_TARGET_Z_PLUS_1g 0x20
455 #define ACCEL6_OFFSET_TARGET_Z_MINUS_1g 0x40
456 #define ACCEL6_OFFSET_TARGET_Y_PLUS_1g 0x08
457 #define ACCEL6_OFFSET_TARGET_Y_MINUS_1g 0x10
458 #define ACCEL6_OFFSET_TARGET_X_PLUS_1g 0x02
459 #define ACCEL6_OFFSET_TARGET_X_MINUS_1g 0x04
460 #define ACCEL6_OFFSET_CUT_OFF_1Hz 0x00
461 #define ACCEL6_OFFSET_CUT_OFF_10Hz 0x01
468 #define ACCEL6_FIFO_MODE_BYPASS 0x00
469 #define ACCEL6_FIFO_MODE_FIFO 0x40
470 #define ACCEL6_FIFO_MODE_STREAM 0x80
471 #define ACCEL6_FIFO_SELECT_XYZ_AXIS 0x00
472 #define ACCEL6_FIFO_SELECT_X_AXIS 0x01
473 #define ACCEL6_FIFO_SELECT_Y_AXIS 0x02
474 #define ACCEL6_FIFO_SELECT_Z_AXIS 0x03
482 #define DEVICE_ERROR 0x04
483 #define DEVICE_OK 0x00
490 #define TAP_X_NEGATIVE 0x01
491 #define TAP_Y_NEGATIVE 0x02
492 #define TAP_Z_NEGATIVE 0x03
493 #define TAP_X_POSITIVE 0x04
494 #define TAP_Y_POSITIVE 0x05
495 #define TAP_Z_POSITIVE 0x06
503 #define SLOPE_X_NEGATIVE 0x01
504 #define SLOPE_Y_NEGATIVE 0x02
505 #define SLOPE_Z_NEGATIVE 0x03
506 #define SLOPE_X_POSITIVE 0x04
507 #define SLOPE_Y_POSITIVE 0x05
508 #define SLOPE_Z_POSITIVE 0x06
509 #define NON_SLOPE 0x00
516 #define Z_ORIENT_UPWARD_LOOKING 0x01
517 #define Z_ORIENT_DOWNWARD_LOOKING 0x02
518 #define XY_ORIENT_UPSIDE_DOWN 0x01
519 #define XY_ORIENT_LANDSCAPE_LEFT 0x02
520 #define XY_ORIENT_LANDSCAPE_RIGHT 0x03
521 #define XY_ORIENT_UPRIGHT 0x04
uint32_t spi_speed
Definition: accel6.h:584
void accel6_data_offset(accel6_t *ctx, uint8_t set_offset, float *offset_data)
Functions for set offset.
Click configuration structure definition.
Definition: accel6.h:570
float accel6_get_axis(accel6_t *ctx, uint8_t axis)
Functions for read axis data.
uint32_t i2c_speed
Definition: accel6.h:582
uint8_t i2c_address
Definition: accel6.h:583
pin_name_t sck
Definition: accel6.h:577
void accel6_generic_write(accel6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void accel6_generic_read(accel6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
pin_name_t miso
Definition: accel6.h:575
float accel6_get_temperature(accel6_t *ctx)
Functions for read temperature.
spi_master_t spi
Definition: accel6.h:551
pin_name_t scl
Definition: accel6.h:573
void accel6_get_orient(accel6_t *ctx, uint8_t *z_orient, uint8_t *xy_orient)
Functions for read orient.
void accel6_soft_reset(accel6_t *ctx)
Functions for software reset.
float device_freq
Definition: accel6.h:562
spi_master_chip_select_polarity_t cs_polarity
Definition: accel6.h:586
uint8_t accel6_select_t
Communication type.
Definition: accel6.h:534
i2c_master_t i2c
Definition: accel6.h:550
float device_gaus
Definition: accel6.h:561
void accel6_cfg_setup(accel6_cfg_t *cfg)
Config Object Initialization function.
uint8_t spi_mode
Definition: accel6.h:585
float dev_freq
Definition: accel6.h:591
ACCEL6_RETVAL accel6_init(accel6_t *ctx, accel6_cfg_t *cfg)
Initialization function.
accel6_select_t master_sel
Definition: accel6.h:559
void accel6_default_cfg(accel6_t *ctx, uint8_t range_data, uint8_t bw_data, uint8_t lpw_data)
Click Default Configuration function.
float dev_gaus
Definition: accel6.h:590
uint8_t slave_address
Definition: accel6.h:555
pin_name_t chip_select
Definition: accel6.h:556
pin_name_t cs
Definition: accel6.h:578
uint8_t accel6_get_slope_status(accel6_t *ctx)
Functions for detect slope on the x/y/z axis.
accel6_select_t sel
Definition: accel6.h:588
struct accel6_s accel6_t
Click ctx object definition.
accel6_master_io_t write_f
Definition: accel6.h:557
uint8_t accel6_get_tap_status(accel6_t *ctx)
Functions for detect tap on the x/y/z axis.
#define ACCEL6_RETVAL
Definition: accel6.h:85
void(* accel6_master_io_t)(struct accel6_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: accel6.h:539
digital_out_t cs
Definition: accel6.h:546
Click ctx object definition.
Definition: accel6.h:545
accel6_master_io_t read_f
Definition: accel6.h:558
pin_name_t mosi
Definition: accel6.h:576
pin_name_t sda
Definition: accel6.h:574