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"
75#define SMARTDOF4_CH_CMD 0
76#define SMARTDOF4_CH_EXE 1
77#define SMARTDOF4_CH_CTRL 2
78#define SMARTDOF4_CH_INPUT_REP 3
79#define SMARTDOF4_CH_WAKE_REP 4
80#define SMARTDOF4_CH_GYRO_VECTOR 5
86#define SMARTDOF4_CMD_ERR 0x01
87#define SMARTDOF4_CMD_COUNT 0x02
88#define SMARTDOF4_CMD_TARE 0x03
89#define SMARTDOF4_CMD_INIT 0x04
90#define SMARTDOF4_CMD_UNS_INIT 0x84
91#define SMARTDOF4_CMD_SAVE_DCD 0x06
92#define SMARTDOF4_CMD_ME_CALIB 0x07
93#define SMARTDOF4_CMD_DCD_PERIOD_SAVE 0x09
94#define SMARTDOF4_CMD_OSCIL 0x0A
95#define SMARTDOF4_CMD_CLEAR_DCD 0x0B
96#define SMARTDOF4_CMD_CALIB 0x0C
97#define SMARTDOF4_CMD_BOOT 0x0D
98#define SMARTDOF4_CMD_INTER_CALIB 0x0E
104#define SMARTDOF4_CMD_INIT_SUB_REINIT 0x01
105#define SMARTDOF4_CMD_INIT_STATUS_OK 0x00
111#define SMARTDOF4_REP_ID_GET_FEAT_REQ 0xFE
112#define SMARTDOF4_REP_ID_SET_FEAT_CMD 0xFD
113#define SMARTDOF4_REP_ID_GET_FEAT_RESP 0xFC
114#define SMARTDOF4_REP_ID_BASE_TIMESTAMP 0xFB
115#define SMARTDOF4_REP_ID_TIMESTAMP_REBASE 0xFA
116#define SMARTDOF4_REP_ID_PROD_ID_REQ 0xF9
117#define SMARTDOF4_REP_ID_PROD_ID_RESP 0xF8
118#define SMARTDOF4_REP_ID_FRS_WR_REQ 0xF7
119#define SMARTDOF4_REP_ID_FRS_WR_DATA 0xF6
120#define SMARTDOF4_REP_ID_FRS_WR_RESP 0xF5
121#define SMARTDOF4_REP_ID_FRS_RD_REQ 0xF4
122#define SMARTDOF4_REP_ID_FRS_RD_RESP 0xF3
123#define SMARTDOF4_REP_ID_CMD_REQ 0xF2
124#define SMARTDOF4_REP_ID_CMD_RESP 0xF1
125#define SMARTDOF4_REP_ID_ACCEL 0x01
126#define SMARTDOF4_REP_ID_GYRO 0x02
127#define SMARTDOF4_REP_ID_MAGNET 0x03
128#define SMARTDOF4_REP_ID_LINEAR_ACCEL 0x04
129#define SMARTDOF4_REP_ID_ROT_VECTOR 0x05
130#define SMARTDOF4_REP_ID_GRAVITY 0x06
131#define SMARTDOF4_REP_ID_UNCALIB_GYRO 0x07
132#define SMARTDOF4_REP_ID_GAME_ROT_VECTOR 0x08
133#define SMARTDOF4_REP_ID_GEOMAG_ROT_VECTOR 0x09
134#define SMARTDOF4_REP_ID_PRESSURE 0x0A
135#define SMARTDOF4_REP_ID_AMB_LIGHT 0x0B
136#define SMARTDOF4_REP_ID_HUMIDITY 0x0C
137#define SMARTDOF4_REP_ID_PROXIMITY 0x0D
138#define SMARTDOF4_REP_ID_TEMPERATURE 0x0E
139#define SMARTDOF4_REP_ID_UNCALIB_MAG_FIELD 0x0F
140#define SMARTDOF4_REP_ID_TAP_DETECT 0x10
141#define SMARTDOF4_REP_ID_STEP_COUNT 0x11
142#define SMARTDOF4_REP_ID_SIG_MOTION 0x12
143#define SMARTDOF4_REP_ID_STABIL_CLASS 0x13
144#define SMARTDOF4_REP_ID_RAW_ACCEL 0x14
145#define SMARTDOF4_REP_ID_RAW_GYRO 0x15
146#define SMARTDOF4_REP_ID_RAW_MAGNETO 0x16
147#define SMARTDOF4_REP_ID_SAR 0x17
148#define SMARTDOF4_REP_ID_STEP_DETECT 0x18
149#define SMARTDOF4_REP_ID_SHAKE_DETECT 0x19
150#define SMARTDOF4_REP_ID_FLIP_DETECT 0x1A
151#define SMARTDOF4_REP_ID_PICKUP_DETECT 0x1B
152#define SMARTDOF4_REP_ID_STABIL_DETECT 0x1C
153#define SMARTDOF4_REP_ID_PERS_ACT_CLASS 0x1E
154#define SMARTDOF4_REP_ID_SLEEP_DETECT 0x1F
155#define SMARTDOF4_REP_ID_TILT_DETECT 0x20
156#define SMARTDOF4_REP_ID_POCKET_DETECT 0x21
157#define SMARTDOF4_REP_ID_CIRCLE_DETECT 0x22
158#define SMARTDOF4_REP_ID_HEART_RATE_MONITOR 0x23
159#define SMARTDOF4_REP_ID_ARVR_ROT_VECT 0x28
160#define SMARTDOF4_REP_ID_ARVR_GAME_ROT_VECT 0x29
166#define SMARTDOF4_REC_ID_STATIC_CALIB_AGM 0x7979
167#define SMARTDOF4_REC_ID_NOMINAL_CALIB_AGM 0x4D4D
168#define SMARTDOF4_REC_ID_STATIC_CALIB_SRA 0x8A8A
169#define SMARTDOF4_REC_ID_NOMINAL_CALIB_SRA 0x4E4E
170#define SMARTDOF4_REC_ID_DYNAMIC_CALIB 0x1F1F
171#define SMARTDOF4_REC_ID_MOTION_ENG_POW_MGMT 0xD3E2
172#define SMARTDOF4_REC_ID_SYS_ORIENT 0x2D3E
173#define SMARTDOF4_REC_ID_PRIM_ACCEL_ORIENT 0x2D41
174#define SMARTDOF4_REC_ID_SCREEN_ROT_ACCEL_ORIENT 0x2D43
175#define SMARTDOF4_REC_ID_GYRO_ORIENT 0x2D46
176#define SMARTDOF4_REC_ID_MAGNETO_ORIENT 0x2D4C
177#define SMARTDOF4_REC_ID_ARVR_ROT_VEC 0x3E2D
178#define SMARTDOF4_REC_ID_ARVR_GAME_ROT_VEC 0x3E2E
179#define SMARTDOF4_REC_ID_SIG_MOTION_DETECT_CFG 0xC274
180#define SMARTDOF4_REC_ID_SHAKE_DETECT_CFG 0x7D7D
181#define SMARTDOF4_REC_ID_MAX_FUSION_PERIOD 0xD7D7
182#define SMARTDOF4_REC_ID_SERIAL_NUM 0x4B4B
183#define SMARTDOF4_REC_ID_ENVIRO_SENS_PRESS 0x39AF
184#define SMARTDOF4_REC_ID_ENVIRO_SENS_TEMP 0x4D20
185#define SMARTDOF4_REC_ID_ENVIRO_SENS_HUMI 0x1AC9
186#define SMARTDOF4_REC_ID_ENVIRO_SENS_AMBI 0x39B1
187#define SMARTDOF4_REC_ID_ENVIRO_SENS_PROXI 0x4DA2
188#define SMARTDOF4_REC_ID_ALS_CALIB 0xD401
189#define SMARTDOF4_REC_ID_PROXI_SENS_CALIB 0xD402
190#define SMARTDOF4_REC_ID_PICKUP_DETECT_CFG 0x1B2A
191#define SMARTDOF4_REC_ID_FLIP_DETECT_CFG 0xFC94
192#define SMARTDOF4_REC_ID_STAB_DETECT_CFG 0xED85
193#define SMARTDOF4_REC_ID_ACT_TRACK_CFG 0xED88
194#define SMARTDOF4_REC_ID_SLEEP_DETECT_CFG 0xED87
195#define SMARTDOF4_REC_ID_TILT_DETECT_CFG 0xED89
196#define SMARTDOF4_REC_ID_POCK_DETECT_CFG 0xEF27
197#define SMARTDOF4_REC_ID_CIRC_DETECT_CFG 0xEE51
198#define SMARTDOF4_REC_ID_USER_REC 0x74B4
199#define SMARTDOF4_REC_ID_MOTION_ENG_TIME_SRC_SEL 0xD403
200#define SMARTDOF4_REC_ID_UART_OUT_FORMAT_SEL 0xA1A1
201#define SMARTDOF4_REC_ID_GYROINT_ROT_VEC_CFG 0xA1A2
202#define SMARTDOF4_REC_ID_FUSION_CTRL_FLAGS 0xA1A3
203#define SMARTDOF4_REC_ID_SIMPLE_CALIB_CONF 0xA1A4
204#define SMARTDOF4_REC_ID_NOMIN_CALIB_CONF 0xA1A5
205#define SMARTDOF4_REC_ID_RAW_ACCEL 0xE301
206#define SMARTDOF4_REC_ID_ACCEL 0xE302
207#define SMARTDOF4_REC_ID_LINEAR_ACCEL 0xE303
208#define SMARTDOF4_REC_ID_GRAVITY 0xE304
209#define SMARTDOF4_REC_ID_RAW_GYRO 0xE305
210#define SMARTDOF4_REC_ID_GYRO_CALIB 0xE306
211#define SMARTDOF4_REC_ID_GYRO_UNCALIB 0xE307
212#define SMARTDOF4_REC_ID_RAW_MAGNETO 0xE308
213#define SMARTDOF4_REC_ID_MAGNETO_CALIB 0xE309
214#define SMARTDOF4_REC_ID_MAGNETO_UNCALIB 0xE30A
215#define SMARTDOF4_REC_ID_ROT_VECTOR 0xE30B
216#define SMARTDOF4_REC_ID_GAME_ROT_VECTOR 0xE30C
217#define SMARTDOF4_REC_ID_GEO_ROT_VECTOR 0xE30D
218#define SMARTDOF4_REC_ID_PRESSURE 0xE30E
219#define SMARTDOF4_REC_ID_AMBIENT_LIGHT 0xE30F
220#define SMARTDOF4_REC_ID_HUMIDITY 0xE310
221#define SMARTDOF4_REC_ID_PROXI 0xE311
222#define SMARTDOF4_REC_ID_TEMPERATURE 0xE312
223#define SMARTDOF4_REC_ID_TAP_DETECT 0xE313
224#define SMARTDOF4_REC_ID_STEP_DETECT 0xE314
225#define SMARTDOF4_REC_ID_STEP_COUNT 0xE315
226#define SMARTDOF4_REC_ID_SIG_MOTION 0xE316
227#define SMARTDOF4_REC_ID_STABIL_CLASS 0xE317
228#define SMARTDOF4_REC_ID_SHAKE_DETECT 0xE318
229#define SMARTDOF4_REC_ID_FLIP_DETECT 0xE319
230#define SMARTDOF4_REC_ID_PICK_DETECT 0xE31A
231#define SMARTDOF4_REC_ID_STABIL_DETECT 0xE31B
232#define SMARTDOF4_REC_ID_PERS_ACT_CLASS 0xE31C
233#define SMARTDOF4_REC_ID_SLEEP_DETECT 0xE31D
234#define SMARTDOF4_REC_ID_TILT_DETECT 0xE31E
235#define SMARTDOF4_REC_ID_POCKET_DETECT 0xE31F
236#define SMARTDOF4_REC_ID_CIRCLE_DETECT 0xE320
237#define SMARTDOF4_REC_ID_HEART_RATE_MON 0xE321
238#define SMARTDOF4_REC_ID_ARVR_ROT_VECTOR 0xE322
239#define SMARTDOF4_REC_ID_ARVR_GAME_ROT_VECTOR 0xE323
240#define SMARTDOF4_REC_ID_GYRO_INTEG_ROT_VEC 0xE324
241#define SMARTDOF4_REC_ID_MOTION_REQ 0xE325
259#define SMARTDOF4_TIMEOUT_MS 2000
265#define SMARTDOF4_QPOINT_RAW_ACCEL 0
266#define SMARTDOF4_QPOINT_ACCEL 8
267#define SMARTDOF4_QPOINT_LINEAR_ACCEL 8
268#define SMARTDOF4_QPOINT_GRAVITY 8
269#define SMARTDOF4_QPOINT_RAW_GYRO 0
270#define SMARTDOF4_QPOINT_GYRO_CALIB 9
271#define SMARTDOF4_QPOINT_GYRO_UNCALIB 9
272#define SMARTDOF4_QPOINT_RAW_MAGNETO 0
273#define SMARTDOF4_QPOINT_MAGNET_CALIB 4
274#define SMARTDOF4_QPOINT_MAGNET_UNCALIB 4
275#define SMARTDOF4_QPOINT_ROT_VECT 14
276#define SMARTDOF4_QPOINT_GAME_ROT_VECT 14
277#define SMARTDOF4_QPOINT_GEOMAG_ROT_VECT 14
278#define SMARTDOF4_QPOINT_TAP_DETECT 0
279#define SMARTDOF4_QPOINT_STEP_DETECT 0
280#define SMARTDOF4_QPOINT_STEP_COUNT 0
281#define SMARTDOF4_QPOINT_SIG_MOTION 0
282#define SMARTDOF4_QPOINT_STABIL_CLASS 0
283#define SMARTDOF4_QPOINT_SHAKE_DETECT 0
284#define SMARTDOF4_QPOINT_STABIL_DETECT 0
285#define SMARTDOF4_QPOINT_PERS_ACT_CLASS 0
286#define SMARTDOF4_QPOINT_ARVR_STABIL_ROT_VECT 14
287#define SMARTDOF4_QPOINT_ARVR_STABIL_GAME_ROT_VECT 14
288#define SMARTDOF4_QPOINT_GYRO_INT_ROT_VECT 14
294#define SMARTDOF4_SCALEQ( x ) ( 1.0f / ( 1u << x ) )
295#define SMARTDOF4_GRAVITY 9.80665f
296#define SMARTDOF4_RAD_TO_DEG 57.2957795f
302#define SMARTDOF4_FEATURE_FLAGS 0x00
303#define SMARTDOF4_FEATURE_CHANCE_SENS 0x0000
304#define SMARTDOF4_FEATURE_REP_INTERVAL_US 100000ul
305#define SMARTDOF4_FEATURE_BATCH_INTERVAL_US 0ul
306#define SMARTDOF4_FEATURE_SENSOR_SPEC 0x00000000ul
313#define SMARTDOF4_DEVICE_ADDRESS_0 0x4A
314#define SMARTDOF4_DEVICE_ADDRESS_1 0x4B
324#define SMARTDOF4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
325#define SMARTDOF4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
343#define SMARTDOF4_MAP_MIKROBUS( cfg, mikrobus ) \
344 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
345 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
346 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
347 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
348 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
349 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
350 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
351 cfg.wup = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
352 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
376 uint8_t payload[ 1020 ];
716 uint32_t *data0_out, uint32_t *data1_out, uint16_t *rec_id );
void smartdof4_drv_interface_sel(smartdof4_cfg_t *cfg, smartdof4_drv_t drv_sel)
Smart DOF 4 driver interface setup function.
void smartdof4_set_rst_pin(smartdof4_t *ctx, uint8_t state)
Smart DOF 4 set rst pin function.
err_t smartdof4_default_cfg(smartdof4_t *ctx)
Smart DOF 4 default configuration function.
err_t smartdof4_read_data(smartdof4_t *ctx, smartdof4_axis_t *accel, smartdof4_axis_t *gyro, smartdof4_axis_t *mag)
Smart DOF 4 read data function.
err_t smartdof4_frs_rd_req(smartdof4_t *ctx, uint16_t rec_id)
Smart DOF 4 frs rd req function.
err_t smartdof4_read_pid(smartdof4_t *ctx, smartdof4_pid_t *pid)
Smart DOF 4 read pid function.
err_t smartdof4_send_packet(smartdof4_t *ctx, uint8_t ch_num, uint8_t *payload, uint16_t len)
Smart DOF 4 send packet function.
err_t smartdof4_read_packet(smartdof4_t *ctx)
Smart DOF 4 read packet function.
void smartdof4_reset_device(smartdof4_t *ctx)
Smart DOF 4 reset device function.
err_t smartdof4_frs_wr_resp(smartdof4_t *ctx, uint16_t *offset, uint8_t *status)
Smart DOF 4 frs wr resp function.
err_t smartdof4_feature_set(smartdof4_t *ctx, smartdof4_feature_t *feat)
Smart DOF 4 feature set function.
err_t smartdof4_cmd_req(smartdof4_t *ctx, uint8_t cmd, uint8_t *params)
Smart DOF 4 cmd req function.
err_t smartdof4_frs_rd_resp(smartdof4_t *ctx, uint16_t *offset, uint8_t *status, uint32_t *data0_out, uint32_t *data1_out, uint16_t *rec_id)
Smart DOF 4 frs rd resp function.
err_t smartdof4_frs_wr_req(smartdof4_t *ctx, uint16_t rec_id, uint16_t len)
Smart DOF 4 frs wr req function.
void smartdof4_set_wup_pin(smartdof4_t *ctx, uint8_t state)
Smart DOF 4 set wup pin function.
uint8_t smartdof4_get_int_pin(smartdof4_t *ctx)
Smart DOF 4 get int pin function.
err_t smartdof4_init(smartdof4_t *ctx, smartdof4_cfg_t *cfg)
Smart DOF 4 initialization function.
err_t smartdof4_feature_req(smartdof4_t *ctx, uint8_t rep_id)
Smart DOF 4 feature req function.
void smartdof4_cfg_setup(smartdof4_cfg_t *cfg)
Smart DOF 4 configuration object setup function.
err_t smartdof4_frs_wr_data_req(smartdof4_t *ctx, uint16_t offset, uint32_t data0_in, uint32_t data1_in)
Smart DOF 4 frs wr data req function.
err_t smartdof4_cmd_resp(smartdof4_t *ctx, uint8_t *cmd, uint8_t *params)
Smart DOF 4 cmd resp function.
err_t smartdof4_wait_ready(smartdof4_t *ctx, uint16_t timeout_ms)
Smart DOF 4 wait ready function.
err_t smartdof4_feature_resp(smartdof4_t *ctx, smartdof4_feature_t *feat)
Smart DOF 4 feature resp function.
smartdof4_drv_t
Smart DOF 4 Click driver selector.
Definition smartdof4.h:362
@ SMARTDOF4_DRV_SEL_SPI
Definition smartdof4.h:363
@ SMARTDOF4_DRV_SEL_I2C
Definition smartdof4.h:364
struct smartdof4_s smartdof4_t
Smart DOF 4 Click context object.
smartdof4_return_value_t
Smart DOF 4 Click return value data.
Definition smartdof4.h:479
@ SMARTDOF4_OK
Definition smartdof4.h:480
@ SMARTDOF4_ERROR
Definition smartdof4.h:481
This file contains SPI specific macros, functions, etc.
Smart DOF 4 Click data axis object.
Definition smartdof4.h:452
float y
Definition smartdof4.h:454
float x
Definition smartdof4.h:453
float z
Definition smartdof4.h:455
Smart DOF 4 Click configuration object.
Definition smartdof4.h:410
pin_name_t wup
Definition smartdof4.h:418
uint32_t i2c_speed
Definition smartdof4.h:421
spi_master_chip_select_polarity_t cs_polarity
Definition smartdof4.h:426
pin_name_t sck
Definition smartdof4.h:415
smartdof4_drv_t drv_sel
Definition smartdof4.h:428
spi_master_mode_t spi_mode
Definition smartdof4.h:425
pin_name_t mosi
Definition smartdof4.h:414
uint32_t spi_speed
Definition smartdof4.h:424
pin_name_t scl
Definition smartdof4.h:411
pin_name_t int_pin
Definition smartdof4.h:419
pin_name_t miso
Definition smartdof4.h:413
pin_name_t sda
Definition smartdof4.h:412
pin_name_t rst
Definition smartdof4.h:417
pin_name_t cs
Definition smartdof4.h:416
uint8_t i2c_address
Definition smartdof4.h:422
Smart DOF 4 Click sensor feature object.
Definition smartdof4.h:437
uint32_t rep_interval_us
Definition smartdof4.h:441
uint32_t sensor_spec
Definition smartdof4.h:443
uint16_t change_sens
Definition smartdof4.h:440
uint8_t flags
Definition smartdof4.h:439
uint32_t batch_interval_us
Definition smartdof4.h:442
uint8_t rep_id
Definition smartdof4.h:438
Smart DOF 4 Click product ID object.
Definition smartdof4.h:464
uint32_t sw_part_num
Definition smartdof4.h:468
uint8_t sw_ver_minor
Definition smartdof4.h:467
uint32_t sw_build_num
Definition smartdof4.h:469
uint8_t reset_cause
Definition smartdof4.h:465
uint8_t sw_ver_major
Definition smartdof4.h:466
uint16_t sw_ver_patch
Definition smartdof4.h:470
Smart DOF 4 Click context object.
Definition smartdof4.h:386
spi_master_t spi
Definition smartdof4.h:393
uint8_t ch_seq_num[6]
Definition smartdof4.h:400
smartdof4_drv_t drv_sel
Definition smartdof4.h:397
digital_in_t int_pin
Definition smartdof4.h:390
i2c_master_t i2c
Definition smartdof4.h:392
smartdof4_shtp_t shtp
Definition smartdof4.h:401
uint8_t cmd_seq_num
Definition smartdof4.h:399
digital_out_t wup
Definition smartdof4.h:388
digital_out_t rst
Definition smartdof4.h:387
uint8_t slave_address
Definition smartdof4.h:395
pin_name_t chip_select
Definition smartdof4.h:396
Smart DOF 4 SHTP packet buffer object.
Definition smartdof4.h:373
uint16_t payload_len
Definition smartdof4.h:377
uint8_t ch_seq_num
Definition smartdof4.h:375
uint8_t channel
Definition smartdof4.h:374