smartsens2  2.0.0.0
smartsens2.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 SMARTSENS2_H
29 #define SMARTSENS2_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 
69 #define SMARTSENS2_FLASHIMG 0 /*< Firmware image for flash include */
70 #define SMARTSENS2_FLASH 1 /*< Boot firmware from flash */
71 #define SMARTSENS2_RAM 0 /*< Upload and boot firmware from RAM */
72 
77 #define SMARTSENS2_REG_COMMAND_INPUT 0x00
78 #define SMARTSENS2_REG_WAKE_UP_FIFO 0x01
79 #define SMARTSENS2_REG_NON_WAKE_UP_FIFO 0x02
80 #define SMARTSENS2_REG_STATUS_DEBUG_FIFO 0x03
81 #define SMARTSENS2_REG_CHIP_CTRL 0x05
82 #define SMARTSENS2_REG_HOST_INTERFACE_CTRL 0x06
83 #define SMARTSENS2_REG_HOST_INTERRUPT_CTRL 0x07
84 #define SMARTSENS2_REG_RESET_REQUEST 0x14
85 #define SMARTSENS2_REG_TIMESTAMP_EVENT_REQUEST 0x15
86 #define SMARTSENS2_REG_HOST_CTRL 0x16
87 #define SMARTSENS2_REG_HOST_STATUS 0x17
88 #define SMARTSENS2_REG_HOST_CRC 0x18191A1B
89 #define SMARTSENS2_REG_FUSER2_PRODUCT_ID 0x1C
90 #define SMARTSENS2_REG_FUSER2_REVISION_ID 0x1D
91 #define SMARTSENS2_REG_ROM_VERSION 0x1E1F
92 #define SMARTSENS2_REG_KERNEL_VERSION 0x2021
93 #define SMARTSENS2_REG_USER_VERSION 0x2223
94 #define SMARTSENS2_REG_FEATURE_STATUS 0x24
95 #define SMARTSENS2_REG_BOOT_STATUS 0x25
96 #define SMARTSENS2_REG_HOST_INTERRUPT_TIMESTAMP 0x26 // Start of interrupt state. Length 5 Bytes. [0x26..0x2A]
97 #define SMARTSENS2_REG_CHIP_ID 0x2B
98 #define SMARTSENS2_REG_INTERRUPT_STATUS 0x2D
99 #define SMARTSENS2_REG_ERROR_VALUE 0x2E
100 #define SMARTSENS2_REG_ERROR_AUX 0x2F
101 #define SMARTSENS2_REG_DEBUG_VALUE 0x30
102 #define SMARTSENS2_REG_DEBUG_STATE 0x31
103 
108 #define SMARTSENS2_CMD_DOWNLOAD_POST_MORTEM_DATA 0x0001
109 #define SMARTSENS2_CMD_UPLOAD_TO_RAM 0x0002
110 #define SMARTSENS2_CMD_BOOT_RAM 0x0003
111 #define SMARTSENS2_CMD_ERASE_FLASH 0x0004
112 #define SMARTSENS2_CMD_WRITE_FLASH 0x0005
113 #define SMARTSENS2_CMD_BOOT_FLASH 0x0006
114 #define SMARTSENS2_CMD_SET_SENSOR_DATA_INJECTION 0x0007
115 #define SMARTSENS2_CMD_INJECT_SENSOR_DATA 0x0008
116 #define SMARTSENS2_CMD_FIFO_FLUSH 0x0009
117 #define SMARTSENS2_CMD_SOFT_PASS_THROUGH 0x000A
118 #define SMARTSENS2_CMD_REQUEST_SENSOR_SELF_TEST 0x000B
119 #define SMARTSENS2_CMD_REQUEST_SENSOR_FAST_OFFSET_COMPENSATION 0x000C
120 #define SMARTSENS2_CMD_CONFIGURE_SENSOR 0x000D
121 #define SMARTSENS2_CMD_CHANGE_SENSOR_DYNAMIC_RANGE 0x000E
122 #define SMARTSENS2_CMD_SET_CHANGE_SENSITIVITY 0x000F
123 #define SMARTSENS2_CMD_DEBUG_TEST 0x0010
124 #define SMARTSENS2_CMD_DUT_CONTINUE 0x0011
125 #define SMARTSENS2_CMD_DUT_START_TEST 0x0012
126 #define SMARTSENS2_CMD_CTRL_FIFO_FORMAT 0x0015
127 #define SMARTSENS2_CMD_RAISE_SPEED 0x0017
128 /*
129  * COMMANDS WITH PARAMETERS:
130  * 0x0100..0x01FF -> System Parameters
131  * 0x0200..0x02FF -> BSX Algorithm Parameters
132  * 0x0300..0x03FF -> Virual Sensor Information Parameters
133  * 0x0500..0x05FF -> Virtual Sensor Configuration Parameters
134  * 0x0800..0x0DFF -> Costumer Defined
135  * 0x0E00..0x0EFF -> Physical Sensor Control Parameters
136  */
137 // System Parameters
138 #define SMARTSENS2_CMD_SYSTEM_PARAMETERS_READ_MASK 0x1000
139 #define SMARTSENS2_CMD_META_EVENT_CTRL_NON_WAKE_UP_FIFO 0x0101
140 #define SMARTSENS2_CMD_META_EVENT_CTRL_WAKE_UP_FIFO 0x0102
141 #define SMARTSENS2_CMD_META_EVENT_CTRL_FIFO_CTRL 0x0103
142 #define SMARTSENS2_CMD_META_EVENT_CTRL_FIRMWARE_VERSION 0x0104
143 #define SMARTSENS2_CMD_META_EVENT_CTRL_TIMESTAMPS 0x0105
144 #define SMARTSENS2_CMD_META_EVENT_CTRL_FRAMEWORK_STATUS 0x0106
145 #define SMARTSENS2_CMD_META_EVENT_CTRL_VIRUAL_SENSOR_PRESENT 0x011F
146 #define SMARTSENS2_CMD_META_EVENT_CTRL_PHYSICAL_SENSOR_PRESENT 0x0120
147 #define SMARTSENS2_CMD_META_EVENT_CTRL_PHYSICAL_SENSOR_INFO 0x0121 //0x0121..0x0160
148 // BSX Algorithm Parameters
149 #define SMARTSENS2_CMD_CALIBRATION_STATE_ACCELEROMETER 0x0201
150 #define SMARTSENS2_CMD_CALIBRATION_STATE_GYROSCOPE 0x0203
151 #define SMARTSENS2_CMD_CALIBRATION_STATE_MAGNETOMETER 0x0205
152 #define SMARTSENS2_CMD_SIC_MATRIX 0x027D
153 #define SMARTSENS2_CMD_BSX_VERSION 0x027E
154 // Virual Sensor Information Parameters
155 #define SMARTSENS2_CMD_VIRTUAL_SENSOR_INFO 0x0300
156 
161 #define SMARTSENS2_START_FLASH_ADR 0x00001F84
162  // smartsens2_reg
164 
179 #define SMARTSENS2_SENSOR_ID_CUSTOM_START 160
180 #define SMARTSENS2_SENSOR_ID_CUSTOM_END 191
181 #define SMARTSENS2_SENSOR_ID_MAX 200
182 #define SMARTSENS2_SENSOR_ID_TBD SMARTSENS2_SENSOR_ID_MAX - 1
183 #define SMARTSENS2_SENSOR_ID_ACC_PASS 1 /* Accelerometer passthrough */
184 #define SMARTSENS2_SENSOR_ID_ACC_RAW 3 /* Accelerometer uncalibrated */
185 #define SMARTSENS2_SENSOR_ID_ACC 4 /* Accelerometer corrected */
186 #define SMARTSENS2_SENSOR_ID_ACC_BIAS 5 /* Accelerometer offset */
187 #define SMARTSENS2_SENSOR_ID_ACC_WU 6 /* Accelerometer corrected wake up */
188 #define SMARTSENS2_SENSOR_ID_ACC_RAW_WU 7 /* Accelerometer uncalibrated wake up */
189 #define SMARTSENS2_SENSOR_ID_GYRO_PASS 10 /* Gyroscope passthrough */
190 #define SMARTSENS2_SENSOR_ID_GYRO_RAW 12 /* Gyroscope uncalibrated */
191 #define SMARTSENS2_SENSOR_ID_GYRO 13 /* Gyroscope corrected */
192 #define SMARTSENS2_SENSOR_ID_GYRO_BIAS 14 /* Gyroscope offset */
193 #define SMARTSENS2_SENSOR_ID_GYRO_WU 15 /* Gyroscope wake up */
194 #define SMARTSENS2_SENSOR_ID_GYRO_RAW_WU 16 /* Gyroscope uncalibrated wake up */
195 #define SMARTSENS2_SENSOR_ID_MAG_PASS 19 /* Magnetometer passthrough */
196 #define SMARTSENS2_SENSOR_ID_MAG_RAW 21 /* Magnetometer uncalibrated */
197 #define SMARTSENS2_SENSOR_ID_MAG 22 /* Magnetometer corrected */
198 #define SMARTSENS2_SENSOR_ID_MAG_BIAS 23 /* Magnetometer offset */
199 #define SMARTSENS2_SENSOR_ID_MAG_WU 24 /* Magnetometer wake up */
200 #define SMARTSENS2_SENSOR_ID_MAG_RAW_WU 25 /* Magnetometer uncalibrated wake up */
201 #define SMARTSENS2_SENSOR_ID_GRA 28 /* Gravity vector */
202 #define SMARTSENS2_SENSOR_ID_GRA_WU 29 /* Gravity vector wake up */
203 #define SMARTSENS2_SENSOR_ID_LACC 31 /* Linear acceleration */
204 #define SMARTSENS2_SENSOR_ID_LACC_WU 32 /* Linear acceleration wake up */
205 #define SMARTSENS2_SENSOR_ID_RV 34 /* Rotation vector */
206 #define SMARTSENS2_SENSOR_ID_RV_WU 35 /* Rotation vector wake up */
207 #define SMARTSENS2_SENSOR_ID_GAMERV 37 /* Game rotation vector */
208 #define SMARTSENS2_SENSOR_ID_GAMERV_WU 38 /* Game rotation vector wake up */
209 #define SMARTSENS2_SENSOR_ID_GEORV 40 /* Geo-magnetic rotation vector */
210 #define SMARTSENS2_SENSOR_ID_GEORV_WU 41 /* Geo-magnetic rotation vector wake up */
211 #define SMARTSENS2_SENSOR_ID_ORI 43 /* Orientation */
212 #define SMARTSENS2_SENSOR_ID_ORI_WU 44 /* Orientation wake up */
213 #define SMARTSENS2_SENSOR_ID_TILT_DETECTOR 48 /* Tilt detector */
214 #define SMARTSENS2_SENSOR_ID_STD 50 /* Step detector */
215 #define SMARTSENS2_SENSOR_ID_STC 52 /* Step counter */
216 #define SMARTSENS2_SENSOR_ID_STC_WU 53 /* Step counter wake up */
217 #define SMARTSENS2_SENSOR_ID_SIG 55 /* Significant motion */
218 #define SMARTSENS2_SENSOR_ID_WAKE_GESTURE 57 /* Wake gesture */
219 #define SMARTSENS2_SENSOR_ID_GLANCE_GESTURE 59 /* Glance gesture */
220 #define SMARTSENS2_SENSOR_ID_PICKUP_GESTURE 61 /* Pickup gesture */
221 #define SMARTSENS2_SENSOR_ID_AR 63 /* Activity recognition */
222 #define SMARTSENS2_SENSOR_ID_WRIST_TILT_GESTURE 67 /* Wrist tilt gesture */
223 #define SMARTSENS2_SENSOR_ID_DEVICE_ORI 69 /* Device orientation */
224 #define SMARTSENS2_SENSOR_ID_DEVICE_ORI_WU 70 /* Device orientation wake up */
225 #define SMARTSENS2_SENSOR_ID_STATIONARY_DET 75 /* Stationary detect */
226 #define SMARTSENS2_SENSOR_ID_MOTION_DET 77 /* Motion detect */
227 #define SMARTSENS2_SENSOR_ID_ACC_BIAS_WU 91 /* Accelerometer offset wake up */
228 #define SMARTSENS2_SENSOR_ID_GYRO_BIAS_WU 92 /* Gyroscope offset wake up */
229 #define SMARTSENS2_SENSOR_ID_MAG_BIAS_WU 93 /* Magnetometer offset wake up */
230 #define SMARTSENS2_SENSOR_ID_STD_WU 94 /* Step detector wake up */
231 #define SMARTSENS2_SENSOR_ID_TEMP 128 /* Temperature */
232 #define SMARTSENS2_SENSOR_ID_BARO 129 /* Barometer */
233 #define SMARTSENS2_SENSOR_ID_HUM 130 /* Humidity */
234 #define SMARTSENS2_SENSOR_ID_GAS 131 /* Gas */
235 #define SMARTSENS2_SENSOR_ID_TEMP_WU 132 /* Temperature wake up */
236 #define SMARTSENS2_SENSOR_ID_BARO_WU 133 /* Barometer wake up */
237 #define SMARTSENS2_SENSOR_ID_HUM_WU 134 /* Humidity wake up */
238 #define SMARTSENS2_SENSOR_ID_GAS_WU 135 /* Gas wake up */
239 #define SMARTSENS2_SENSOR_ID_STC_HW 136 /* Hardware Step counter */
240 #define SMARTSENS2_SENSOR_ID_STD_HW 137 /* Hardware Step detector */
241 #define SMARTSENS2_SENSOR_ID_SIG_HW 138 /* Hardware Significant motion */
242 #define SMARTSENS2_SENSOR_ID_STC_HW_WU 139 /* Hardware Step counter wake up */
243 #define SMARTSENS2_SENSOR_ID_STD_HW_WU 140 /* Hardware Step detector wake up */
244 #define SMARTSENS2_SENSOR_ID_SIG_HW_WU 141 /* Hardware Significant motion wake up */
245 #define SMARTSENS2_SENSOR_ID_ANY_MOTION 142 /* Any motion */
246 #define SMARTSENS2_SENSOR_ID_ANY_MOTION_WU 143 /* Any motion wake up */
247 #define SMARTSENS2_SENSOR_ID_EXCAMERA 144 /* External camera trigger */
248 #define SMARTSENS2_SENSOR_ID_GPS 145 /* GPS */
249 #define SMARTSENS2_SENSOR_ID_LIGHT 146 /* Light */
250 #define SMARTSENS2_SENSOR_ID_PROX 147 /* Proximity */
251 #define SMARTSENS2_SENSOR_ID_LIGHT_WU 148 /* Light wake up */
252 #define SMARTSENS2_SENSOR_ID_PROX_WU 149 /* Proximity wake up */
253 #define SMARTSENS2_IS_SYS_ID( sid ) ( ( sid ) >= 224 )
254 #define SMARTSENS2_SYS_ID_PADDING 0
255 #define SMARTSENS2_SYS_ID_TS_SMALL_DELTA 251
256 #define SMARTSENS2_SYS_ID_TS_LARGE_DELTA 252
257 #define SMARTSENS2_SYS_ID_TS_FULL 253
258 #define SMARTSENS2_SYS_ID_META_EVENT 254
259 #define SMARTSENS2_SYS_ID_TS_SMALL_DELTA_WU 245
260 #define SMARTSENS2_SYS_ID_TS_LARGE_DELTA_WU 246
261 #define SMARTSENS2_SYS_ID_TS_FULL_WU 247
262 #define SMARTSENS2_SYS_ID_META_EVENT_WU 248
263 #define SMARTSENS2_SYS_ID_FILLER 255
264 #define SMARTSENS2_SYS_ID_DEBUG_MSG 250
265 #define SMARTSENS2_SYS_ID_SMARTSENS2_LOG_UPDATE_SUB 243
266 #define SMARTSENS2_SYS_ID_SMARTSENS2_LOG_DOSTEP 244
267 #define SMARTSENS2_N_VIRTUAL_SENSOR_MAX 256 /* Maximum no of available virtual sensor */
268 #define SMARTSENS2_SPECIAL_SENSOR_ID_OFFSET 245 /* Special & debug virtual sensor id starts at 245 */
269 
274 #define SMARTSENS2_META_EVENT_FLUSH_COMPLETE 1
275 #define SMARTSENS2_META_EVENT_SAMPLE_RATE_CHANGED 2
276 #define SMARTSENS2_META_EVENT_POWER_MODE_CHANGED 3
277 #define SMARTSENS2_META_EVENT_ALGORITHM_EVENTS 5
278 #define SMARTSENS2_META_EVENT_SENSOR_STATUS 6
279 #define SMARTSENS2_META_EVENT_BSX_DO_STEPS_MAIN 7
280 #define SMARTSENS2_META_EVENT_BSX_DO_STEPS_CALIB 8
281 #define SMARTSENS2_META_EVENT_BSX_GET_OUTPUT_SIGNAL 9
282 #define SMARTSENS2_META_EVENT_RESERVED1 10
283 #define SMARTSENS2_META_EVENT_SENSOR_ERROR 11
284 #define SMARTSENS2_META_EVENT_FIFO_OVERFLOW 12
285 #define SMARTSENS2_META_EVENT_DYNAMIC_RANGE_CHANGED 13
286 #define SMARTSENS2_META_EVENT_FIFO_WATERMARK 14
287 #define SMARTSENS2_META_EVENT_RESERVED2 15
288 #define SMARTSENS2_META_EVENT_INITIALIZED 16
289 #define SMARTSENS2_META_TRANSFER_CAUSE 17
290 #define SMARTSENS2_META_EVENT_SENSOR_FRAMEWORK 18
291 #define SMARTSENS2_META_EVENT_RESET 19
292 #define SMARTSENS2_META_EVENT_SPACER 20
293 
298 #define SMARTSENS2_CHIP_ID_VALUE 0x70
299 #define SMARTSENS2_FUSER2_PRODUCT_ID_VALUE 0x89
300 
305 #define SMARTSENS2_BOOTSTATUS_FLASH_DETECTED 0x01
306 #define SMARTSENS2_BOOTSTATUS_FLASH_VERIFY_DONE 0x02
307 #define SMARTSENS2_BOOTSTATUS_FLASH_VERIFY_ERROR 0x04
308 #define SMARTSENS2_BOOTSTATUS_NO_FLASH 0x08
309 #define SMARTSENS2_BOOTSTATUS_HOST_INTERFACE_READY 0x10
310 #define SMARTSENS2_BOOTSTATUS_HOST_FW_VERIFY_DONE 0x20
311 #define SMARTSENS2_BOOTSTATUS_HOST_FW_VERIFY_ERROR 0x40
312 #define SMARTSENS2_BOOTSTATUS_HOST_FW_IDLE 0x80
313 
318 #define SMARTSENS2_HOSTSTATUS_POWER_STATE 0x01
319 #define SMARTSENS2_HOSTSTATUS_HOST_PROTOCOL 0x02
320 #define SMARTSENS2_HOSTSTATUS_HOST_CHANNEL_0 0x10
321 #define SMARTSENS2_HOSTSTATUS_HOST_CHANNEL_1 0x20
322 #define SMARTSENS2_HOSTSTATUS_HOST_CHANNEL_2 0x40
323 #define SMARTSENS2_HOSTSTATUS_HOST_CHANNEL_3 0x80
324 
329 #define SMARTSENS2_IST_MASK_ASSERTED 0x1
330 #define SMARTSENS2_IST_MASK_FIFO_W 0x6
331 #define SMARTSENS2_IST_MASK_FIFO_NW 0x18
332 #define SMARTSENS2_IST_MASK_STATUS 0x20
333 #define SMARTSENS2_IST_MASK_DEBUG 0x40
334 #define SMARTSENS2_IST_MASK_RESET_FAULT 0x80
335 #define SMARTSENS2_IST_FIFO_W_DRDY 0x2
336 #define SMARTSENS2_IST_FIFO_W_LTCY 0x4
337 #define SMARTSENS2_IST_FIFO_W_WM 0x6
338 #define SMARTSENS2_IST_FIFO_NW_DRDY 0x8
339 #define SMARTSENS2_IST_FIFO_NW_LTCY 0x10
340 #define SMARTSENS2_IST_FIFO_NW_WM 0x18
341 #define SMARTSENS2_IS_INT_FIFO_W( status ) ( status & SMARTSENS2_IST_MASK_FIFO_W )
342 #define SMARTSENS2_IS_INT_FIFO_NW( status ) ( status & SMARTSENS2_IST_MASK_FIFO_NW )
343 #define SMARTSENS2_IS_INT_STATUS( status ) ( status & SMARTSENS2_IST_MASK_STATUS )
344 #define SMARTSENS2_IS_INT_ASYNC_STATUS( status ) ( status & SMARTSENS2_IST_MASK_DEBUG )
345 #define SMARTSENS2_IS_INT_RESET( status ) ( status & SMARTSENS2_IST_MASK_RESET_FAULT )
346 #define SMARTSENS2_IST_MASK_FIFO ( SMARTSENS2_IST_MASK_FIFO_W | SMARTSENS2_IST_MASK_FIFO_NW )
347 #define SMARTSENS2_IS_INT_FIFO( status ) ( status & SMARTSENS2_IST_MASK_FIFO )
348 
353 #define SMARTSENS2_ICTL_DISABLE_FIFO_W 0x01
354 #define SMARTSENS2_ICTL_DISABLE_FIFO_NW 0x02
355 #define SMARTSENS2_ICTL_DISABLE_STATUS_FIFO 0x04
356 #define SMARTSENS2_ICTL_DISABLE_DEBUG 0x08
357 #define SMARTSENS2_ICTL_DISABLE_FAULT 0x10
358 #define SMARTSENS2_ICTL_ACTIVE_LOW 0x20
359 #define SMARTSENS2_ICTL_EDGE 0x40
360 #define SMARTSENS2_ICTL_OPEN_DRAIN 0x80
361 
366 #define SMARTSENS2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_0 0x01
367 #define SMARTSENS2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_1 0x02
368 #define SMARTSENS2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_2 0x04
369 #define SMARTSENS2_HIF_CTRL_ABORT_TRANSFER_CHANNEL_3 0x08
370 #define SMARTSENS2_HIF_CTRL_AP_SUSPENDED 0x10
371 #define SMARTSENS2_HIF_CTRL_TIMESTAMP_EV_CTRL 0x40
372 #define SMARTSENS2_HIF_CTRL_ASYNC_STATUS_CHANNEL 0x80
373 
378 #define SMARTSENS2_LE2U16( x ) ( ( uint16_t )( ( x )[ 0 ] | ( x )[ 1 ] << 8 ) )
379 #define SMARTSENS2_LE2S16( x ) ( ( int16_t )SMARTSENS2_LE2U16( x ) )
380 #define SMARTSENS2_LE2U24( x ) ( ( uint32_t )( ( x )[ 0 ] | \
381  ( uint32_t )( x )[ 1 ] << 8 | \
382  ( uint32_t )( x )[ 2 ] << 16 ) )
383 #define SMARTSENS2_LE2U32( x ) ( ( uint32_t )( ( x )[ 0 ] | \
384  ( uint32_t )( x )[ 1 ] << 8 | \
385  ( uint32_t )( x )[ 2 ] << 16 | \
386  ( uint32_t )( x )[ 3 ] << 24 ) )
387 #define SMARTSENS2_LE2S32( x ) ( ( int32_t )SMARTSENS2_LE2U32( x ) )
388 #define SMARTSENS2_LE2U40( x ) ( SMARTSENS2_LE2U32( x ) | ( uint32_t )( x )[ 4 ] << 32 )
389 #define SMARTSENS2_TIMESTAMP_TO_SEC( x ) ( ( uint32_t ) ( x * ( 15625.0 / UINT32_C( 1000000000 ) ) ) )
390 
396 #define SMARTSENS2_SLAVE_ADDRESS_1 0x29
397 #define SMARTSENS2_SLAVE_ADDRESS_0 0x28
398 
407 #define SMARTSENS2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
408 #define SMARTSENS2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
409  // smartsens2_set
411 
426 #define SMARTSENS2_MAP_MIKROBUS( cfg, mikrobus ) \
427  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
428  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
429  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
430  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
431  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
432  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
433  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
434  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
435  // smartsens2_map // smartsens2
438 
443 typedef enum
444 {
449 
455 {
460 };
461 
467 {
468  uint8_t sensor_id;
470  uint8_t data_size;
471  uint8_t *data_ptr;
472  uint32_t *time_stamp;
473 };
474 
480 typedef err_t ( *smartsens2_master_io_t )( struct smartsens2_s*, uint8_t, uint8_t*, uint8_t );
482 typedef void ( *smartsens2_fifo_parse_callback_t )( struct smartsens2_fifo_parse_data_info *callback_info, void *private_data );
483 
489 {
490  uint16_t u16_val;
491  uint8_t bytes[ 2 ];
492 };
493 
499 {
500  uint32_t u32_val;
501  uint8_t bytes[ 4 ];
502 };
503 
509 {
510  float f_val;
511  uint32_t u32_val;
512  uint8_t bytes[ 4 ];
513 };
514 
520 {
521  uint8_t sensor_type;
522  uint8_t driver_id;
523  uint8_t driver_version;
524  uint8_t power;
530  uint8_t event_size;
532 };
533 
539 {
540  uint8_t event_size;
543 };
544 
550 {
551  uint32_t read_pos;
552  uint32_t read_length;
553  uint32_t remain_length;
554  uint32_t buffer_size;
555  uint8_t *buffer;
556 };
557 
562 typedef struct smartsens2_s
563 {
564  digital_out_t rst;
566  digital_in_t int_pin;
568  i2c_master_t i2c;
569  spi_master_t spi;
571  uint8_t slave_address;
572  pin_name_t chip_select;
580 
582 
587 typedef struct
588 {
589  pin_name_t scl;
590  pin_name_t sda;
591  pin_name_t miso;
592  pin_name_t mosi;
593  pin_name_t sck;
594  pin_name_t cs;
595  pin_name_t rst;
596  pin_name_t int_pin;
598  uint32_t i2c_speed;
599  uint8_t i2c_address;
601  uint32_t spi_speed;
602  spi_master_mode_t spi_mode;
603  spi_master_chip_select_polarity_t cs_polarity;
608 
613 typedef enum
614 {
618 
620 
637 
653 
669 
684 
700 err_t smartsens2_generic_write ( smartsens2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
701 
717 err_t smartsens2_generic_read ( smartsens2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
718 
731 err_t smartsens2_byte_write ( smartsens2_t *ctx, uint8_t reg, uint8_t data_in );
732 
745 err_t smartsens2_byte_read ( smartsens2_t *ctx, uint8_t reg, uint8_t *data_out );
746 
755 
770 err_t smartsens2_cmd_write ( smartsens2_t *ctx, uint16_t cmd, uint8_t *cmd_buf, uint16_t cmd_len );
771 
785 err_t smartsens2_status_read ( smartsens2_t *ctx, uint16_t *cmd, uint8_t *cmd_buf, uint16_t *cmd_len );
786 
799 err_t smartsens2_get_parameter ( smartsens2_t *ctx, uint16_t parameter,
800  uint8_t *parameter_buf, uint16_t *parameter_len );
801 
810 
822 
838 
853 
867 
878 
890 err_t smartsens2_get_virt_sensor_list ( smartsens2_t *ctx, uint8_t *sensor_list );
891 
904 err_t smartsens2_set_virt_sensor_cfg( smartsens2_t *ctx, uint8_t sensor_id, float sample_rate, uint32_t latency );
905 
916 err_t smartsens2_get_and_process_fifo ( smartsens2_t *ctx, uint8_t *work_buffer, uint32_t buffer_size );
917 
931 
932 #ifdef __cplusplus
933 }
934 #endif
935 #endif // SMARTSENS2_H
936  // smartsens2
938 
939 // ------------------------------------------------------------------------ END
smartsens2_cfg_t::i2c_address
uint8_t i2c_address
Definition: smartsens2.h:599
smartsens2_sensor_info::max_rate
union smartsens2_float_conv max_rate
Definition: smartsens2.h:527
smartsens2_t
struct smartsens2_s smartsens2_t
Smart Sens 2 Click context object.
smartsens2_s::drv_sel
smartsens2_drv_t drv_sel
Definition: smartsens2.h:573
SMARTSENS2_FIFO_TYPE_STATUS
@ SMARTSENS2_FIFO_TYPE_STATUS
Definition: smartsens2.h:458
smartsens2_default_cfg
err_t smartsens2_default_cfg(smartsens2_t *ctx)
Smart Sens 2 default configuration function.
smartsens2_cfg_t::rst
pin_name_t rst
Definition: smartsens2.h:595
smartsens2_fifo_parse_data_info::sensor_id
uint8_t sensor_id
Definition: smartsens2.h:468
smartsens2_sensor_info::resolution
union smartsens2_u16_conv resolution
Definition: smartsens2.h:526
smartsens2_fifo_buffer
Fifo buffer.
Definition: smartsens2.h:550
smartsens2_reset
void smartsens2_reset(smartsens2_t *ctx)
Reset device.
smartsens2_sensor_info::event_size
uint8_t event_size
Definition: smartsens2.h:530
smartsens2_s::spi
spi_master_t spi
Definition: smartsens2.h:569
smartsens2_get_interrupt
uint8_t smartsens2_get_interrupt(smartsens2_t *ctx)
Get interrupt.
smartsens2_drv_t
smartsens2_drv_t
Smart Sens 2 Click driver selector.
Definition: smartsens2.h:444
smartsens2_sensor_info::fifo_reserved
union smartsens2_u32_conv fifo_reserved
Definition: smartsens2.h:528
smartsens2_cfg_t::scl
pin_name_t scl
Definition: smartsens2.h:589
smartsens2_init
err_t smartsens2_init(smartsens2_t *ctx, smartsens2_cfg_t *cfg)
Smart Sens 2 initialization function.
smartsens2_float_conv::f_val
float f_val
Definition: smartsens2.h:510
smartsens2_power_on_device
err_t smartsens2_power_on_device(smartsens2_t *ctx)
Power on device boot/upload firmware to device.
smartsens2_fifo_parse_callback_table::event_size
uint8_t event_size
Definition: smartsens2.h:540
smartsens2_get_virt_sensor_list
err_t smartsens2_get_virt_sensor_list(smartsens2_t *ctx, uint8_t *sensor_list)
Get the virtual sensor list.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
smartsens2_return_value_t
smartsens2_return_value_t
Smart Sens 2 Click return value data.
Definition: smartsens2.h:614
smartsens2_drv_interface_selection
void smartsens2_drv_interface_selection(smartsens2_cfg_t *cfg, smartsens2_drv_t drv_sel)
Smart Sens 2 driver interface setup function.
smartsens2_s
Smart Sens 2 Click context object.
Definition: smartsens2.h:563
smartsens2_s::table
struct smartsens2_fifo_parse_callback_table table[SMARTSENS2_N_VIRTUAL_SENSOR_MAX]
Definition: smartsens2.h:578
smartsens2_fifo_parse_callback_t
void(* smartsens2_fifo_parse_callback_t)(struct smartsens2_fifo_parse_data_info *callback_info, void *private_data)
Definition: smartsens2.h:482
smartsens2_fifo_buffer::read_pos
uint32_t read_pos
Definition: smartsens2.h:551
smartsens2_float_conv
Float converter union.
Definition: smartsens2.h:509
smartsens2_s::last_time_stamp
uint32_t last_time_stamp[SMARTSENS2_FIFO_TYPE_MAX]
Definition: smartsens2.h:579
smartsens2_sensor_info::fifo_max
union smartsens2_u32_conv fifo_max
Definition: smartsens2.h:529
smartsens2_boot_firmware
err_t smartsens2_boot_firmware(smartsens2_t *ctx)
Boot firmware image.
SMARTSENS2_ERROR
@ SMARTSENS2_ERROR
Definition: smartsens2.h:616
smartsens2_status_read
err_t smartsens2_status_read(smartsens2_t *ctx, uint16_t *cmd, uint8_t *cmd_buf, uint16_t *cmd_len)
Read Status and Debug FIFO.
smartsens2_set_virt_sensor_cfg
err_t smartsens2_set_virt_sensor_cfg(smartsens2_t *ctx, uint8_t sensor_id, float sample_rate, uint32_t latency)
Set configuration fro virtual sensor.
smartsens2_fifo_parse_callback_table::callback_ref
void * callback_ref
Definition: smartsens2.h:542
smartsens2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: smartsens2.h:602
smartsens2_sensor_info::power
uint8_t power
Definition: smartsens2.h:524
smartsens2_byte_read
err_t smartsens2_byte_read(smartsens2_t *ctx, uint8_t reg, uint8_t *data_out)
Byte reading function.
smartsens2_s::read_f
smartsens2_master_io_t read_f
Definition: smartsens2.h:576
SMARTSENS2_N_VIRTUAL_SENSOR_MAX
#define SMARTSENS2_N_VIRTUAL_SENSOR_MAX
Definition: smartsens2.h:267
smartsens2_u16_conv::u16_val
uint16_t u16_val
Definition: smartsens2.h:490
work_buffer
uint8_t work_buffer[WORK_BUFFER_SIZE]
Definition: main.c:74
smartsens2_master_io_t
err_t(* smartsens2_master_io_t)(struct smartsens2_s *, uint8_t, uint8_t *, uint8_t)
Smart Sens 2 Click driver interface.
Definition: smartsens2.h:480
smartsens2_fifo_buffer::buffer
uint8_t * buffer
Definition: smartsens2.h:555
smartsens2_sensor_info::driver_version
uint8_t driver_version
Definition: smartsens2.h:523
SMARTSENS2_OK
@ SMARTSENS2_OK
Definition: smartsens2.h:615
smartsens2_fifo_parse_data_info::data_size
uint8_t data_size
Definition: smartsens2.h:470
SMARTSENS2_FIFO_TYPE_MAX
@ SMARTSENS2_FIFO_TYPE_MAX
Definition: smartsens2.h:459
smartsens2_s::i2c
i2c_master_t i2c
Definition: smartsens2.h:568
smartsens2_fifo_parse_callback_table::callback
smartsens2_fifo_parse_callback_t callback
Definition: smartsens2.h:541
smartsens2_cfg_t::spi_speed
uint32_t spi_speed
Definition: smartsens2.h:601
smartsens2_update_firmware
err_t smartsens2_update_firmware(smartsens2_t *ctx)
Upload firmware image to the device.
smartsens2_fifo_type
smartsens2_fifo_type
Fifo type enum.
Definition: smartsens2.h:455
smartsens2_cfg_t::sck
pin_name_t sck
Definition: smartsens2.h:593
smartsens2_float_conv::u32_val
uint32_t u32_val
Definition: smartsens2.h:511
smartsens2_update_virtual_sensor_list
err_t smartsens2_update_virtual_sensor_list(smartsens2_t *ctx)
Update the callback table's information.
smartsens2_generic_write
err_t smartsens2_generic_write(smartsens2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Smart Sens 2 data writing function.
smartsens2_fifo_parse_callback_table
Callback prase.
Definition: smartsens2.h:539
smartsens2_s::int_pin
digital_in_t int_pin
Definition: smartsens2.h:566
smartsens2_sw_reset
err_t smartsens2_sw_reset(smartsens2_t *ctx)
SW Reset device.
smartsens2_fifo_parse_data_info::fifo_type
enum smartsens2_fifo_type fifo_type
Definition: smartsens2.h:469
smartsens2_s::write_f
smartsens2_master_io_t write_f
Definition: smartsens2.h:575
smartsens2_u32_conv::u32_val
uint32_t u32_val
Definition: smartsens2.h:500
smartsens2_sensor_info
Sensor info.
Definition: smartsens2.h:520
smartsens2_cfg_t::drv_sel
smartsens2_drv_t drv_sel
Definition: smartsens2.h:605
smartsens2_cmd_write
err_t smartsens2_cmd_write(smartsens2_t *ctx, uint16_t cmd, uint8_t *cmd_buf, uint16_t cmd_len)
Send command.
smartsens2_get_and_process_fifo
err_t smartsens2_get_and_process_fifo(smartsens2_t *ctx, uint8_t *work_buffer, uint32_t buffer_size)
Get and process the FIFO.
smartsens2_u32_conv::bytes
uint8_t bytes[4]
Definition: smartsens2.h:501
SMARTSENS2_FIFO_TYPE_WAKEUP
@ SMARTSENS2_FIFO_TYPE_WAKEUP
Definition: smartsens2.h:456
smartsens2_fifo_buffer::read_length
uint32_t read_length
Definition: smartsens2.h:552
smartsens2_u16_conv::bytes
uint8_t bytes[2]
Definition: smartsens2.h:491
smartsens2_cfg_t::int_pin
pin_name_t int_pin
Definition: smartsens2.h:596
smartsens2_fifo_parse_data_info::data_ptr
uint8_t * data_ptr
Definition: smartsens2.h:471
smartsens2_sensor_info::sensor_type
uint8_t sensor_type
Definition: smartsens2.h:521
smartsens2_fifo_buffer::remain_length
uint32_t remain_length
Definition: smartsens2.h:553
SMARTSENS2_DRV_SEL_SPI
@ SMARTSENS2_DRV_SEL_SPI
Definition: smartsens2.h:445
smartsens2_u32_conv
U32 converter union.
Definition: smartsens2.h:499
smartsens2_byte_write
err_t smartsens2_byte_write(smartsens2_t *ctx, uint8_t reg, uint8_t data_in)
Byte writing function.
smartsens2_fifo_buffer::buffer_size
uint32_t buffer_size
Definition: smartsens2.h:554
SMARTSENS_ERROR_TIMEOUT
@ SMARTSENS_ERROR_TIMEOUT
Definition: smartsens2.h:617
SMARTSENS2_FIFO_TYPE_NON_WAKEUP
@ SMARTSENS2_FIFO_TYPE_NON_WAKEUP
Definition: smartsens2.h:457
smartsens2_cfg_t::miso
pin_name_t miso
Definition: smartsens2.h:591
smartsens2_cfg_setup
void smartsens2_cfg_setup(smartsens2_cfg_t *cfg)
Smart Sens 2 configuration object setup function.
smartsens2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: smartsens2.h:603
SMARTSENS2_DRV_SEL_I2C
@ SMARTSENS2_DRV_SEL_I2C
Definition: smartsens2.h:446
smartsens2_cfg_t::mosi
pin_name_t mosi
Definition: smartsens2.h:592
smartsens2_sensor_info::min_rate
union smartsens2_float_conv min_rate
Definition: smartsens2.h:531
smartsens2_s::chip_select
pin_name_t chip_select
Definition: smartsens2.h:572
smartsens2_sensor_info::driver_id
uint8_t driver_id
Definition: smartsens2.h:522
smartsens2_cfg_t::sda
pin_name_t sda
Definition: smartsens2.h:590
smartsens2_fifo_parse_data_info
Parsing data info.
Definition: smartsens2.h:467
smartsens2_fifo_parse_data_info::time_stamp
uint32_t * time_stamp
Definition: smartsens2.h:472
smartsens2_cfg_t
Smart Sens 2 Click configuration object.
Definition: smartsens2.h:588
smartsens2_sensor_info::max_range
union smartsens2_u16_conv max_range
Definition: smartsens2.h:525
smartsens2_cfg_t::cs
pin_name_t cs
Definition: smartsens2.h:594
smartsens2_s::rst
digital_out_t rst
Definition: smartsens2.h:564
smartsens2_u16_conv
U16 converter union.
Definition: smartsens2.h:489
smartsens2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: smartsens2.h:598
smartsens2_float_conv::bytes
uint8_t bytes[4]
Definition: smartsens2.h:512
smartsens2_register_fifo_parse_callback
err_t smartsens2_register_fifo_parse_callback(smartsens2_t *ctx, uint8_t sensor_id, smartsens2_fifo_parse_callback_t callback, void *callback_ref)
Link a callback to virtual sensor.
smartsens2_get_parameter
err_t smartsens2_get_parameter(smartsens2_t *ctx, uint16_t parameter, uint8_t *parameter_buf, uint16_t *parameter_len)
Get command parameters response.
smartsens2_generic_read
err_t smartsens2_generic_read(smartsens2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Smart Sens 2 data reading function.
smartsens2_s::slave_address
uint8_t slave_address
Definition: smartsens2.h:571