smartsens  2.0.0.0
smartsens.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 SMARTSENS_H
29 #define SMARTSENS_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_spi_master.h"
49 #include "spi_specifics.h"
50 
79 #define SMARTSENS_FLASHIMG 0 /*< Firmware image for flash include */
80 #define SMARTSENS_FLASH 1 /*< Boot firmware from flash */
81 #define SMARTSENS_RAM 0 /*< Upload and boot firmware from RAM */
82 
87 #define SMARTSENS_REG_COMMAND_INPUT 0x00
88 #define SMARTSENS_REG_WAKE_UP_FIFO 0x01
89 #define SMARTSENS_REG_NON_WAKE_UP_FIFO 0x02
90 #define SMARTSENS_REG_STATUS_DEBUG_FIFO 0x03
91 #define SMARTSENS_REG_CHIP_CTRL 0x05
92 #define SMARTSENS_REG_HOST_INTERFACE_CTRL 0x06
93 #define SMARTSENS_REG_HOST_INTERRUPT_CTRL 0x07
94 #define SMARTSENS_REG_RESET_REQUEST 0x14
95 #define SMARTSENS_REG_TIMESTAMP_EVENT_REQUEST 0x15
96 #define SMARTSENS_REG_HOST_CTRL 0x16
97 #define SMARTSENS_REG_HOST_STATUS 0x17
98 #define SMARTSENS_REG_HOST_CRC 0x18191A1B
99 #define SMARTSENS_REG_FUSER2_PRODUCT_ID 0x1C
100 #define SMARTSENS_REG_FUSER2_REVISION_ID 0x1D
101 #define SMARTSENS_REG_ROM_VERSION 0x1E1F
102 #define SMARTSENS_REG_KERNEL_VERSION 0x2021
103 #define SMARTSENS_REG_USER_VERSION 0x2223
104 #define SMARTSENS_REG_FEATURE_STATUS 0x24
105 #define SMARTSENS_REG_BOOT_STATUS 0x25
106 #define SMARTSENS_REG_HOST_INTERRUPT_TIMESTAMP 0x26 // Start of interrupt state. Length 5 Bytes. [0x26..0x2A]
107 #define SMARTSENS_REG_CHIP_ID 0x2B
108 #define SMARTSENS_REG_INTERRUPT_STATUS 0x2D
109 #define SMARTSENS_REG_ERROR_VALUE 0x2E
110 #define SMARTSENS_REG_ERROR_AUX 0x2F
111 #define SMARTSENS_REG_DEBUG_VALUE 0x30
112 #define SMARTSENS_REG_DEBUG_STATE 0x31
113 
118 #define SMARTSENS_CMD_DOWNLOAD_POST_MORTEM_DATA 0x0001
119 #define SMARTSENS_CMD_UPLOAD_TO_RAM 0x0002
120 #define SMARTSENS_CMD_BOOT_RAM 0x0003
121 #define SMARTSENS_CMD_ERASE_FLASH 0x0004
122 #define SMARTSENS_CMD_WRITE_FLASH 0x0005
123 #define SMARTSENS_CMD_BOOT_FLASH 0x0006
124 #define SMARTSENS_CMD_SET_SENSOR_DATA_INJECTION 0x0007
125 #define SMARTSENS_CMD_INJECT_SENSOR_DATA 0x0008
126 #define SMARTSENS_CMD_FIFO_FLUSH 0x0009
127 #define SMARTSENS_CMD_SOFT_PASS_THROUGH 0x000A
128 #define SMARTSENS_CMD_REQUEST_SENSOR_SELF_TEST 0x000B
129 #define SMARTSENS_CMD_REQUEST_SENSOR_FAST_OFFSET_COMPENSATION 0x000C
130 #define SMARTSENS_CMD_CONFIGURE_SENSOR 0x000D
131 #define SMARTSENS_CMD_CHANGE_SENSOR_DYNAMIC_RANGE 0x000E
132 #define SMARTSENS_CMD_SET_CHANGE_SENSITIVITY 0x000F
133 #define SMARTSENS_CMD_DEBUG_TEST 0x0010
134 #define SMARTSENS_CMD_DUT_CONTINUE 0x0011
135 #define SMARTSENS_CMD_DUT_START_TEST 0x0012
136 #define SMARTSENS_CMD_CTRL_FIFO_FORMAT 0x0015
137 #define SMARTSENS_CMD_RAISE_SPEED 0x0017
138 /*
139  * COMMANDS WITH PARAMETERS:
140  * 0x0100..0x01FF -> System Parameters
141  * 0x0200..0x02FF -> BSX Algorithm Parameters
142  * 0x0300..0x03FF -> Virual Sensor Information Parameters
143  * 0x0500..0x05FF -> Virtual Sensor Configuration Parameters
144  * 0x0800..0x0DFF -> Costumer Defined
145  * 0x0E00..0x0EFF -> Physical Sensor Control Parameters
146  */
147 // System Parameters
148 #define SMARTSENS_CMD_SYSTEM_PARAMETERS_READ_MASK 0x1000
149 #define SMARTSENS_CMD_META_EVENT_CTRL_NON_WAKE_UP_FIFO 0x0101
150 #define SMARTSENS_CMD_META_EVENT_CTRL_WAKE_UP_FIFO 0x0102
151 #define SMARTSENS_CMD_META_EVENT_CTRL_FIFO_CTRL 0x0103
152 #define SMARTSENS_CMD_META_EVENT_CTRL_FIRMWARE_VERSION 0x0104
153 #define SMARTSENS_CMD_META_EVENT_CTRL_TIMESTAMPS 0x0105
154 #define SMARTSENS_CMD_META_EVENT_CTRL_FRAMEWORK_STATUS 0x0106
155 #define SMARTSENS_CMD_META_EVENT_CTRL_VIRUAL_SENSOR_PRESENT 0x011F
156 #define SMARTSENS_CMD_META_EVENT_CTRL_PHYSICAL_SENSOR_PRESENT 0x0120
157 #define SMARTSENS_CMD_META_EVENT_CTRL_PHYSICAL_SENSOR_INFO 0x0121 //0x0121..0x0160
158 // BSX Algorithm Parameters
159 #define SMARTSENS_CMD_CALIBRATION_STATE_ACCELEROMETER 0x0201
160 #define SMARTSENS_CMD_CALIBRATION_STATE_GYROSCOPE 0x0203
161 #define SMARTSENS_CMD_CALIBRATION_STATE_MAGNETOMETER 0x0205
162 #define SMARTSENS_CMD_SIC_MATRIX 0x027D
163 #define SMARTSENS_CMD_BSX_VERSION 0x027E
164 // Virual Sensor Information Parameters
165 #define SMARTSENS_CMD_VIRTUAL_SENSOR_INFO 0x0300
166 
171 #define SMARTSENS_START_FLASH_ADR 0x00001F84
172  // smartsens_reg
174 
189 #define SMARTSENS_SENSOR_ID_CUSTOM_START 160
190 #define SMARTSENS_SENSOR_ID_CUSTOM_END 191
191 #define SMARTSENS_SENSOR_ID_MAX 200
192 #define SMARTSENS_SENSOR_ID_TBD SMARTSENS_SENSOR_ID_MAX - 1
193 #define SMARTSENS_SENSOR_ID_ACC_PASS 1 /* Accelerometer passthrough */
194 #define SMARTSENS_SENSOR_ID_ACC_RAW 3 /* Accelerometer uncalibrated */
195 #define SMARTSENS_SENSOR_ID_ACC 4 /* Accelerometer corrected */
196 #define SMARTSENS_SENSOR_ID_ACC_BIAS 5 /* Accelerometer offset */
197 #define SMARTSENS_SENSOR_ID_ACC_WU 6 /* Accelerometer corrected wake up */
198 #define SMARTSENS_SENSOR_ID_ACC_RAW_WU 7 /* Accelerometer uncalibrated wake up */
199 #define SMARTSENS_SENSOR_ID_GYRO_PASS 10 /* Gyroscope passthrough */
200 #define SMARTSENS_SENSOR_ID_GYRO_RAW 12 /* Gyroscope uncalibrated */
201 #define SMARTSENS_SENSOR_ID_GYRO 13 /* Gyroscope corrected */
202 #define SMARTSENS_SENSOR_ID_GYRO_BIAS 14 /* Gyroscope offset */
203 #define SMARTSENS_SENSOR_ID_GYRO_WU 15 /* Gyroscope wake up */
204 #define SMARTSENS_SENSOR_ID_GYRO_RAW_WU 16 /* Gyroscope uncalibrated wake up */
205 #define SMARTSENS_SENSOR_ID_MAG_PASS 19 /* Magnetometer passthrough */
206 #define SMARTSENS_SENSOR_ID_MAG_RAW 21 /* Magnetometer uncalibrated */
207 #define SMARTSENS_SENSOR_ID_MAG 22 /* Magnetometer corrected */
208 #define SMARTSENS_SENSOR_ID_MAG_BIAS 23 /* Magnetometer offset */
209 #define SMARTSENS_SENSOR_ID_MAG_WU 24 /* Magnetometer wake up */
210 #define SMARTSENS_SENSOR_ID_MAG_RAW_WU 25 /* Magnetometer uncalibrated wake up */
211 #define SMARTSENS_SENSOR_ID_GRA 28 /* Gravity vector */
212 #define SMARTSENS_SENSOR_ID_GRA_WU 29 /* Gravity vector wake up */
213 #define SMARTSENS_SENSOR_ID_LACC 31 /* Linear acceleration */
214 #define SMARTSENS_SENSOR_ID_LACC_WU 32 /* Linear acceleration wake up */
215 #define SMARTSENS_SENSOR_ID_RV 34 /* Rotation vector */
216 #define SMARTSENS_SENSOR_ID_RV_WU 35 /* Rotation vector wake up */
217 #define SMARTSENS_SENSOR_ID_GAMERV 37 /* Game rotation vector */
218 #define SMARTSENS_SENSOR_ID_GAMERV_WU 38 /* Game rotation vector wake up */
219 #define SMARTSENS_SENSOR_ID_GEORV 40 /* Geo-magnetic rotation vector */
220 #define SMARTSENS_SENSOR_ID_GEORV_WU 41 /* Geo-magnetic rotation vector wake up */
221 #define SMARTSENS_SENSOR_ID_ORI 43 /* Orientation */
222 #define SMARTSENS_SENSOR_ID_ORI_WU 44 /* Orientation wake up */
223 #define SMARTSENS_SENSOR_ID_TILT_DETECTOR 48 /* Tilt detector */
224 #define SMARTSENS_SENSOR_ID_STD 50 /* Step detector */
225 #define SMARTSENS_SENSOR_ID_STC 52 /* Step counter */
226 #define SMARTSENS_SENSOR_ID_STC_WU 53 /* Step counter wake up */
227 #define SMARTSENS_SENSOR_ID_SIG 55 /* Significant motion */
228 #define SMARTSENS_SENSOR_ID_WAKE_GESTURE 57 /* Wake gesture */
229 #define SMARTSENS_SENSOR_ID_GLANCE_GESTURE 59 /* Glance gesture */
230 #define SMARTSENS_SENSOR_ID_PICKUP_GESTURE 61 /* Pickup gesture */
231 #define SMARTSENS_SENSOR_ID_AR 63 /* Activity recognition */
232 #define SMARTSENS_SENSOR_ID_WRIST_TILT_GESTURE 67 /* Wrist tilt gesture */
233 #define SMARTSENS_SENSOR_ID_DEVICE_ORI 69 /* Device orientation */
234 #define SMARTSENS_SENSOR_ID_DEVICE_ORI_WU 70 /* Device orientation wake up */
235 #define SMARTSENS_SENSOR_ID_STATIONARY_DET 75 /* Stationary detect */
236 #define SMARTSENS_SENSOR_ID_MOTION_DET 77 /* Motion detect */
237 #define SMARTSENS_SENSOR_ID_ACC_BIAS_WU 91 /* Accelerometer offset wake up */
238 #define SMARTSENS_SENSOR_ID_GYRO_BIAS_WU 92 /* Gyroscope offset wake up */
239 #define SMARTSENS_SENSOR_ID_MAG_BIAS_WU 93 /* Magnetometer offset wake up */
240 #define SMARTSENS_SENSOR_ID_STD_WU 94 /* Step detector wake up */
241 #define SMARTSENS_SENSOR_ID_TEMP 128 /* Temperature */
242 #define SMARTSENS_SENSOR_ID_BARO 129 /* Barometer */
243 #define SMARTSENS_SENSOR_ID_HUM 130 /* Humidity */
244 #define SMARTSENS_SENSOR_ID_GAS 131 /* Gas */
245 #define SMARTSENS_SENSOR_ID_TEMP_WU 132 /* Temperature wake up */
246 #define SMARTSENS_SENSOR_ID_BARO_WU 133 /* Barometer wake up */
247 #define SMARTSENS_SENSOR_ID_HUM_WU 134 /* Humidity wake up */
248 #define SMARTSENS_SENSOR_ID_GAS_WU 135 /* Gas wake up */
249 #define SMARTSENS_SENSOR_ID_STC_HW 136 /* Hardware Step counter */
250 #define SMARTSENS_SENSOR_ID_STD_HW 137 /* Hardware Step detector */
251 #define SMARTSENS_SENSOR_ID_SIG_HW 138 /* Hardware Significant motion */
252 #define SMARTSENS_SENSOR_ID_STC_HW_WU 139 /* Hardware Step counter wake up */
253 #define SMARTSENS_SENSOR_ID_STD_HW_WU 140 /* Hardware Step detector wake up */
254 #define SMARTSENS_SENSOR_ID_SIG_HW_WU 141 /* Hardware Significant motion wake up */
255 #define SMARTSENS_SENSOR_ID_ANY_MOTION 142 /* Any motion */
256 #define SMARTSENS_SENSOR_ID_ANY_MOTION_WU 143 /* Any motion wake up */
257 #define SMARTSENS_SENSOR_ID_EXCAMERA 144 /* External camera trigger */
258 #define SMARTSENS_SENSOR_ID_GPS 145 /* GPS */
259 #define SMARTSENS_SENSOR_ID_LIGHT 146 /* Light */
260 #define SMARTSENS_SENSOR_ID_PROX 147 /* Proximity */
261 #define SMARTSENS_SENSOR_ID_LIGHT_WU 148 /* Light wake up */
262 #define SMARTSENS_SENSOR_ID_PROX_WU 149 /* Proximity wake up */
263 #define SMARTSENS_IS_SYS_ID( sid ) ( ( sid ) >= 224 )
264 #define SMARTSENS_SYS_ID_PADDING 0
265 #define SMARTSENS_SYS_ID_TS_SMALL_DELTA 251
266 #define SMARTSENS_SYS_ID_TS_LARGE_DELTA 252
267 #define SMARTSENS_SYS_ID_TS_FULL 253
268 #define SMARTSENS_SYS_ID_META_EVENT 254
269 #define SMARTSENS_SYS_ID_TS_SMALL_DELTA_WU 245
270 #define SMARTSENS_SYS_ID_TS_LARGE_DELTA_WU 246
271 #define SMARTSENS_SYS_ID_TS_FULL_WU 247
272 #define SMARTSENS_SYS_ID_META_EVENT_WU 248
273 #define SMARTSENS_SYS_ID_FILLER 255
274 #define SMARTSENS_SYS_ID_DEBUG_MSG 250
275 #define SMARTSENS_SYS_ID_SMARTSENS_LOG_UPDATE_SUB 243
276 #define SMARTSENS_SYS_ID_SMARTSENS_LOG_DOSTEP 244
277 #define SMARTSENS_N_VIRTUAL_SENSOR_MAX 256 /* Maximum no of available virtual sensor */
278 #define SMARTSENS_SPECIAL_SENSOR_ID_OFFSET 245 /* Special & debug virtual sensor id starts at 245 */
279 
284 #define SMARTSENS_META_EVENT_FLUSH_COMPLETE 1
285 #define SMARTSENS_META_EVENT_SAMPLE_RATE_CHANGED 2
286 #define SMARTSENS_META_EVENT_POWER_MODE_CHANGED 3
287 #define SMARTSENS_META_EVENT_ALGORITHM_EVENTS 5
288 #define SMARTSENS_META_EVENT_SENSOR_STATUS 6
289 #define SMARTSENS_META_EVENT_BSX_DO_STEPS_MAIN 7
290 #define SMARTSENS_META_EVENT_BSX_DO_STEPS_CALIB 8
291 #define SMARTSENS_META_EVENT_BSX_GET_OUTPUT_SIGNAL 9
292 #define SMARTSENS_META_EVENT_RESERVED1 10
293 #define SMARTSENS_META_EVENT_SENSOR_ERROR 11
294 #define SMARTSENS_META_EVENT_FIFO_OVERFLOW 12
295 #define SMARTSENS_META_EVENT_DYNAMIC_RANGE_CHANGED 13
296 #define SMARTSENS_META_EVENT_FIFO_WATERMARK 14
297 #define SMARTSENS_META_EVENT_RESERVED2 15
298 #define SMARTSENS_META_EVENT_INITIALIZED 16
299 #define SMARTSENS_META_TRANSFER_CAUSE 17
300 #define SMARTSENS_META_EVENT_SENSOR_FRAMEWORK 18
301 #define SMARTSENS_META_EVENT_RESET 19
302 #define SMARTSENS_META_EVENT_SPACER 20
303 
308 #define SMARTSENS_CHIP_ID_VALUE 0x70
309 #define SMARTSENS_FUSER2_PRODUCT_ID_VALUE 0x89
310 
315 #define SMARTSENS_BOOTSTATUS_FLASH_DETECTED 0x01
316 #define SMARTSENS_BOOTSTATUS_FLASH_VERIFY_DONE 0x02
317 #define SMARTSENS_BOOTSTATUS_FLASH_VERIFY_ERROR 0x04
318 #define SMARTSENS_BOOTSTATUS_NO_FLASH 0x08
319 #define SMARTSENS_BOOTSTATUS_HOST_INTERFACE_READY 0x10
320 #define SMARTSENS_BOOTSTATUS_HOST_FW_VERIFY_DONE 0x20
321 #define SMARTSENS_BOOTSTATUS_HOST_FW_VERIFY_ERROR 0x40
322 #define SMARTSENS_BOOTSTATUS_HOST_FW_IDLE 0x80
323 
328 #define SMARTSENS_HOSTSTATUS_POWER_STATE 0x01
329 #define SMARTSENS_HOSTSTATUS_HOST_PROTOCOL 0x02
330 #define SMARTSENS_HOSTSTATUS_HOST_CHANNEL_0 0x10
331 #define SMARTSENS_HOSTSTATUS_HOST_CHANNEL_1 0x20
332 #define SMARTSENS_HOSTSTATUS_HOST_CHANNEL_2 0x40
333 #define SMARTSENS_HOSTSTATUS_HOST_CHANNEL_3 0x80
334 
339 #define SMARTSENS_IST_MASK_ASSERTED 0x1
340 #define SMARTSENS_IST_MASK_FIFO_W 0x6
341 #define SMARTSENS_IST_MASK_FIFO_NW 0x18
342 #define SMARTSENS_IST_MASK_STATUS 0x20
343 #define SMARTSENS_IST_MASK_DEBUG 0x40
344 #define SMARTSENS_IST_MASK_RESET_FAULT 0x80
345 #define SMARTSENS_IST_FIFO_W_DRDY 0x2
346 #define SMARTSENS_IST_FIFO_W_LTCY 0x4
347 #define SMARTSENS_IST_FIFO_W_WM 0x6
348 #define SMARTSENS_IST_FIFO_NW_DRDY 0x8
349 #define SMARTSENS_IST_FIFO_NW_LTCY 0x10
350 #define SMARTSENS_IST_FIFO_NW_WM 0x18
351 #define SMARTSENS_IS_INT_FIFO_W( status ) ( status & SMARTSENS_IST_MASK_FIFO_W )
352 #define SMARTSENS_IS_INT_FIFO_NW( status ) ( status & SMARTSENS_IST_MASK_FIFO_NW )
353 #define SMARTSENS_IS_INT_STATUS( status ) ( status & SMARTSENS_IST_MASK_STATUS )
354 #define SMARTSENS_IS_INT_ASYNC_STATUS( status ) ( status & SMARTSENS_IST_MASK_DEBUG )
355 #define SMARTSENS_IS_INT_RESET( status ) ( status & SMARTSENS_IST_MASK_RESET_FAULT )
356 #define SMARTSENS_IST_MASK_FIFO ( SMARTSENS_IST_MASK_FIFO_W | SMARTSENS_IST_MASK_FIFO_NW )
357 #define SMARTSENS_IS_INT_FIFO( status ) ( status & SMARTSENS_IST_MASK_FIFO )
358 
363 #define SMARTSENS_ICTL_DISABLE_FIFO_W 0x01
364 #define SMARTSENS_ICTL_DISABLE_FIFO_NW 0x02
365 #define SMARTSENS_ICTL_DISABLE_STATUS_FIFO 0x04
366 #define SMARTSENS_ICTL_DISABLE_DEBUG 0x08
367 #define SMARTSENS_ICTL_DISABLE_FAULT 0x10
368 #define SMARTSENS_ICTL_ACTIVE_LOW 0x20
369 #define SMARTSENS_ICTL_EDGE 0x40
370 #define SMARTSENS_ICTL_OPEN_DRAIN 0x80
371 
376 #define SMARTSENS_HIF_CTRL_ABORT_TRANSFER_CHANNEL_0 0x01
377 #define SMARTSENS_HIF_CTRL_ABORT_TRANSFER_CHANNEL_1 0x02
378 #define SMARTSENS_HIF_CTRL_ABORT_TRANSFER_CHANNEL_2 0x04
379 #define SMARTSENS_HIF_CTRL_ABORT_TRANSFER_CHANNEL_3 0x08
380 #define SMARTSENS_HIF_CTRL_AP_SUSPENDED 0x10
381 #define SMARTSENS_HIF_CTRL_TIMESTAMP_EV_CTRL 0x40
382 #define SMARTSENS_HIF_CTRL_ASYNC_STATUS_CHANNEL 0x80
383 
388 #define SMARTSENS_LE2U16( x ) ( ( uint16_t )( ( x )[ 0 ] | ( x )[ 1 ] << 8 ) )
389 #define SMARTSENS_LE2S16( x ) ( ( int16_t )SMARTSENS_LE2U16( x ) )
390 #define SMARTSENS_LE2U24( x ) ( ( uint32_t )( ( x )[ 0 ] | \
391  ( uint32_t )( x )[ 1 ] << 8 | \
392  ( uint32_t )( x )[ 2 ] << 16 ) )
393 #define SMARTSENS_LE2U32( x ) ( ( uint32_t )( ( x )[ 0 ] | \
394  ( uint32_t )( x )[ 1 ] << 8 | \
395  ( uint32_t )( x )[ 2 ] << 16 | \
396  ( uint32_t )( x )[ 3 ] << 24 ) )
397 #define SMARTSENS_LE2S32( x ) ( ( int32_t )SMARTSENS_LE2U32( x ) )
398 #define SMARTSENS_LE2U40( x ) ( SMARTSENS_LE2U32( x ) | ( uint32_t )( x )[ 4 ] << 32 )
399 #define SMARTSENS_TIMESTAMP_TO_SEC( x ) ( ( uint32_t ) ( x * ( 15625.0 / UINT32_C( 1000000000 ) ) ) )
400 
406 #define SMARTSENS_SLAVE_ADDRESS_1 0x29
407 #define SMARTSENS_SLAVE_ADDRESS_0 0x28
408 
417 #define SMARTSENS_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
418 #define SMARTSENS_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
419  // smartsens_set
421 
436 #define SMARTSENS_MAP_MIKROBUS( cfg, mikrobus ) \
437  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
438  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
439  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
440  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
441  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
442  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
443  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
444  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
445  // smartsens_map // smartsens
448 
453 typedef enum
454 {
459 
465 {
470 };
471 
477 {
478  uint8_t sensor_id;
480  uint8_t data_size;
481  uint8_t *data_ptr;
482  uint32_t *time_stamp;
483 };
484 
490 typedef err_t ( *smartsens_master_io_t )( struct smartsens_s*, uint8_t, uint8_t*, uint8_t );
492 typedef void ( *smartsens_fifo_parse_callback_t )( struct smartsens_fifo_parse_data_info *callback_info, void *private_data );
493 
499 {
500  uint16_t u16_val;
501  uint8_t bytes[ 2 ];
502 };
503 
509 {
510  uint32_t u32_val;
511  uint8_t bytes[ 4 ];
512 };
513 
519 {
520  float f_val;
521  uint32_t u32_val;
522  uint8_t bytes[ 4 ];
523 };
524 
530 {
531  uint8_t sensor_type;
532  uint8_t driver_id;
533  uint8_t driver_version;
534  uint8_t power;
540  uint8_t event_size;
542 };
543 
549 {
550  uint8_t event_size;
553 };
554 
560 {
561  uint32_t read_pos;
562  uint32_t read_length;
563  uint32_t remain_length;
564  uint32_t buffer_size;
565  uint8_t *buffer;
566 };
567 
572 typedef struct smartsens_s
573 {
574  digital_out_t rst;
576  digital_in_t int_pin;
578  i2c_master_t i2c;
579  spi_master_t spi;
581  uint8_t slave_address;
582  pin_name_t chip_select;
590 
592 
597 typedef struct
598 {
599  pin_name_t scl;
600  pin_name_t sda;
601  pin_name_t miso;
602  pin_name_t mosi;
603  pin_name_t sck;
604  pin_name_t cs;
605  pin_name_t rst;
606  pin_name_t int_pin;
608  uint32_t i2c_speed;
609  uint8_t i2c_address;
611  uint32_t spi_speed;
612  spi_master_mode_t spi_mode;
613  spi_master_chip_select_polarity_t cs_polarity;
618 
623 typedef enum
624 {
628 
630 
647 
663 
679 
694 
710 err_t smartsens_generic_write ( smartsens_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
711 
727 err_t smartsens_generic_read ( smartsens_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
728 
741 err_t smartsens_byte_write ( smartsens_t *ctx, uint8_t reg, uint8_t data_in );
742 
755 err_t smartsens_byte_read ( smartsens_t *ctx, uint8_t reg, uint8_t *data_out );
756 
765 
780 err_t smartsens_cmd_write ( smartsens_t *ctx, uint16_t cmd, uint8_t *cmd_buf, uint16_t cmd_len );
781 
795 err_t smartsens_status_read ( smartsens_t *ctx, uint16_t *cmd, uint8_t *cmd_buf, uint16_t *cmd_len );
796 
809 err_t smartsens_get_parameter ( smartsens_t *ctx, uint16_t parameter,
810  uint8_t *parameter_buf, uint16_t *parameter_len );
811 
820 
832 
848 
863 
877 
888 
900 err_t smartsens_get_virt_sensor_list ( smartsens_t *ctx, uint8_t *sensor_list );
901 
914 err_t smartsens_set_virt_sensor_cfg( smartsens_t *ctx, uint8_t sensor_id, float sample_rate, uint32_t latency );
915 
926 err_t smartsens_get_and_process_fifo ( smartsens_t *ctx, uint8_t *work_buffer, uint32_t buffer_size );
927 
939 err_t smartsens_register_fifo_parse_callback ( smartsens_t *ctx, uint8_t sensor_id,
941 
942 #ifdef __cplusplus
943 }
944 #endif
945 #endif // SMARTSENS_H
946  // smartsens
948 
949 // ------------------------------------------------------------------------ END
smartsens_generic_write
err_t smartsens_generic_write(smartsens_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Smart Sens data writing function.
smartsens_status_read
err_t smartsens_status_read(smartsens_t *ctx, uint16_t *cmd, uint8_t *cmd_buf, uint16_t *cmd_len)
Read Status and Debug FIFO.
smartsens_register_fifo_parse_callback
err_t smartsens_register_fifo_parse_callback(smartsens_t *ctx, uint8_t sensor_id, smartsens_fifo_parse_callback_t callback, void *callback_ref)
Link a callback to virtual sensor.
smartsens_fifo_buffer::read_pos
uint32_t read_pos
Definition: smartsens.h:561
smartsens_master_io_t
err_t(* smartsens_master_io_t)(struct smartsens_s *, uint8_t, uint8_t *, uint8_t)
Smart Sens Click driver interface.
Definition: smartsens.h:490
smartsens_cfg_t::rst
pin_name_t rst
Definition: smartsens.h:605
smartsens_fifo_parse_callback_table::callback_ref
void * callback_ref
Definition: smartsens.h:552
smartsens_s::rst
digital_out_t rst
Definition: smartsens.h:574
smartsens_sensor_info::driver_version
uint8_t driver_version
Definition: smartsens.h:533
smartsens_cfg_t::cs
pin_name_t cs
Definition: smartsens.h:604
smartsens_u16_conv
U16 converter union.
Definition: smartsens.h:499
smartsens_t
struct smartsens_s smartsens_t
Smart Sens Click context object.
smartsens_s::slave_address
uint8_t slave_address
Definition: smartsens.h:581
smartsens_sensor_info::max_rate
union smartsens_float_conv max_rate
Definition: smartsens.h:537
smartsens_power_on_device
err_t smartsens_power_on_device(smartsens_t *ctx)
Power on device boot/upload firmware to device.
smartsens_fifo_parse_data_info::data_size
uint8_t data_size
Definition: smartsens.h:480
smartsens_byte_write
err_t smartsens_byte_write(smartsens_t *ctx, uint8_t reg, uint8_t data_in)
Byte writing function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
smartsens_s::read_f
smartsens_master_io_t read_f
Definition: smartsens.h:586
smartsens_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: smartsens.h:608
smartsens_float_conv
Float converter union.
Definition: smartsens.h:519
smartsens_reset
void smartsens_reset(smartsens_t *ctx)
Reset device.
smartsens_fifo_type
smartsens_fifo_type
Fifo type enum.
Definition: smartsens.h:465
smartsens_sensor_info::event_size
uint8_t event_size
Definition: smartsens.h:540
smartsens_float_conv::u32_val
uint32_t u32_val
Definition: smartsens.h:521
smartsens_s::spi
spi_master_t spi
Definition: smartsens.h:579
smartsens_cfg_t
Smart Sens Click configuration object.
Definition: smartsens.h:598
smartsens_s
Smart Sens Click context object.
Definition: smartsens.h:573
smartsens_s::int_pin
digital_in_t int_pin
Definition: smartsens.h:576
smartsens_sensor_info::max_range
union smartsens_u16_conv max_range
Definition: smartsens.h:535
smartsens_float_conv::bytes
uint8_t bytes[4]
Definition: smartsens.h:522
work_buffer
uint8_t work_buffer[WORK_BUFFER_SIZE]
Definition: main.c:62
SMARTSENS_FIFO_TYPE_MAX
@ SMARTSENS_FIFO_TYPE_MAX
Definition: smartsens.h:469
smartsens_float_conv::f_val
float f_val
Definition: smartsens.h:520
smartsens_update_virtual_sensor_list
err_t smartsens_update_virtual_sensor_list(smartsens_t *ctx)
Update the callback table's information.
smartsens_u32_conv::bytes
uint8_t bytes[4]
Definition: smartsens.h:511
smartsens_sw_reset
err_t smartsens_sw_reset(smartsens_t *ctx)
SW Reset device.
smartsens_cfg_t::scl
pin_name_t scl
Definition: smartsens.h:599
smartsens_drv_interface_selection
void smartsens_drv_interface_selection(smartsens_cfg_t *cfg, smartsens_drv_t drv_sel)
Smart Sens driver interface setup function.
smartsens_fifo_parse_data_info::data_ptr
uint8_t * data_ptr
Definition: smartsens.h:481
smartsens_cfg_t::int_pin
pin_name_t int_pin
Definition: smartsens.h:606
SMARTSENS_N_VIRTUAL_SENSOR_MAX
#define SMARTSENS_N_VIRTUAL_SENSOR_MAX
Definition: smartsens.h:277
smartsens_default_cfg
err_t smartsens_default_cfg(smartsens_t *ctx)
Smart Sens default configuration function.
smartsens_sensor_info
Sensor info.
Definition: smartsens.h:530
smartsens_sensor_info::power
uint8_t power
Definition: smartsens.h:534
SMARTSENS_FIFO_TYPE_STATUS
@ SMARTSENS_FIFO_TYPE_STATUS
Definition: smartsens.h:468
smartsens_s::chip_select
pin_name_t chip_select
Definition: smartsens.h:582
SMARTSENS_FIFO_TYPE_NON_WAKEUP
@ SMARTSENS_FIFO_TYPE_NON_WAKEUP
Definition: smartsens.h:467
smartsens_cfg_t::spi_speed
uint32_t spi_speed
Definition: smartsens.h:611
smartsens_s::write_f
smartsens_master_io_t write_f
Definition: smartsens.h:585
smartsens_cfg_t::drv_sel
smartsens_drv_t drv_sel
Definition: smartsens.h:615
smartsens_drv_t
smartsens_drv_t
Smart Sens Click driver selector.
Definition: smartsens.h:454
smartsens_get_parameter
err_t smartsens_get_parameter(smartsens_t *ctx, uint16_t parameter, uint8_t *parameter_buf, uint16_t *parameter_len)
Get command parameters response.
smartsens_cfg_t::sck
pin_name_t sck
Definition: smartsens.h:603
smartsens_return_value_t
smartsens_return_value_t
Smart Sens Click return value data.
Definition: smartsens.h:624
smartsens_get_virt_sensor_list
err_t smartsens_get_virt_sensor_list(smartsens_t *ctx, uint8_t *sensor_list)
Get the virtual sensor list.
smartsens_sensor_info::driver_id
uint8_t driver_id
Definition: smartsens.h:532
smartsens_update_firmware
err_t smartsens_update_firmware(smartsens_t *ctx)
Upload firmware image to the device.
smartsens_byte_read
err_t smartsens_byte_read(smartsens_t *ctx, uint8_t reg, uint8_t *data_out)
Byte reading function.
smartsens_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: smartsens.h:613
smartsens_s::table
struct smartsens_fifo_parse_callback_table table[SMARTSENS_N_VIRTUAL_SENSOR_MAX]
Definition: smartsens.h:588
SMARTSENS_DRV_SEL_SPI
@ SMARTSENS_DRV_SEL_SPI
Definition: smartsens.h:455
smartsens_generic_read
err_t smartsens_generic_read(smartsens_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Smart Sens data reading function.
smartsens_fifo_parse_callback_t
void(* smartsens_fifo_parse_callback_t)(struct smartsens_fifo_parse_data_info *callback_info, void *private_data)
Definition: smartsens.h:492
smartsens_cfg_t::mosi
pin_name_t mosi
Definition: smartsens.h:602
smartsens_cfg_t::i2c_address
uint8_t i2c_address
Definition: smartsens.h:609
smartsens_fifo_buffer::remain_length
uint32_t remain_length
Definition: smartsens.h:563
smartsens_fifo_parse_callback_table
Callback prase.
Definition: smartsens.h:549
smartsens_sensor_info::min_rate
union smartsens_float_conv min_rate
Definition: smartsens.h:541
SMARTSENS_FIFO_TYPE_WAKEUP
@ SMARTSENS_FIFO_TYPE_WAKEUP
Definition: smartsens.h:466
smartsens_get_and_process_fifo
err_t smartsens_get_and_process_fifo(smartsens_t *ctx, uint8_t *work_buffer, uint32_t buffer_size)
Get and process the FIFO.
smartsens_u16_conv::u16_val
uint16_t u16_val
Definition: smartsens.h:500
smartsens_fifo_buffer::buffer_size
uint32_t buffer_size
Definition: smartsens.h:564
smartsens_sensor_info::sensor_type
uint8_t sensor_type
Definition: smartsens.h:531
smartsens_fifo_parse_data_info::time_stamp
uint32_t * time_stamp
Definition: smartsens.h:482
SMARTSENS_DRV_SEL_I2C
@ SMARTSENS_DRV_SEL_I2C
Definition: smartsens.h:456
smartsens_set_virt_sensor_cfg
err_t smartsens_set_virt_sensor_cfg(smartsens_t *ctx, uint8_t sensor_id, float sample_rate, uint32_t latency)
Set configuration fro virtual sensor.
smartsens_sensor_info::resolution
union smartsens_u16_conv resolution
Definition: smartsens.h:536
smartsens_get_interrupt
uint8_t smartsens_get_interrupt(smartsens_t *ctx)
Get interrupt.
smartsens_cfg_t::miso
pin_name_t miso
Definition: smartsens.h:601
smartsens_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: smartsens.h:612
smartsens_cfg_setup
void smartsens_cfg_setup(smartsens_cfg_t *cfg)
Smart Sens configuration object setup function.
smartsens_fifo_parse_data_info::sensor_id
uint8_t sensor_id
Definition: smartsens.h:478
smartsens_cmd_write
err_t smartsens_cmd_write(smartsens_t *ctx, uint16_t cmd, uint8_t *cmd_buf, uint16_t cmd_len)
Send command.
smartsens_cfg_t::sda
pin_name_t sda
Definition: smartsens.h:600
smartsens_fifo_parse_callback_table::callback
smartsens_fifo_parse_callback_t callback
Definition: smartsens.h:551
SMARTSENS_ERROR
@ SMARTSENS_ERROR
Definition: smartsens.h:626
smartsens_boot_firmware
err_t smartsens_boot_firmware(smartsens_t *ctx)
Boot firmware image.
smartsens_fifo_buffer
Fifo buffer.
Definition: smartsens.h:560
smartsens_init
err_t smartsens_init(smartsens_t *ctx, smartsens_cfg_t *cfg)
Smart Sens initialization function.
smartsens_u32_conv
U32 converter union.
Definition: smartsens.h:509
smartsens_sensor_info::fifo_reserved
union smartsens_u32_conv fifo_reserved
Definition: smartsens.h:538
smartsens_u16_conv::bytes
uint8_t bytes[2]
Definition: smartsens.h:501
smartsens_s::i2c
i2c_master_t i2c
Definition: smartsens.h:578
smartsens_sensor_info::fifo_max
union smartsens_u32_conv fifo_max
Definition: smartsens.h:539
smartsens_fifo_buffer::buffer
uint8_t * buffer
Definition: smartsens.h:565
SMARTSENS_ERROR_TIMEOUT
@ SMARTSENS_ERROR_TIMEOUT
Definition: smartsens.h:627
smartsens_fifo_parse_data_info::fifo_type
enum smartsens_fifo_type fifo_type
Definition: smartsens.h:479
smartsens_s::drv_sel
smartsens_drv_t drv_sel
Definition: smartsens.h:583
smartsens_fifo_parse_data_info
Parsing data info.
Definition: smartsens.h:477
smartsens_u32_conv::u32_val
uint32_t u32_val
Definition: smartsens.h:510
smartsens_fifo_buffer::read_length
uint32_t read_length
Definition: smartsens.h:562
SMARTSENS_OK
@ SMARTSENS_OK
Definition: smartsens.h:625
smartsens_fifo_parse_callback_table::event_size
uint8_t event_size
Definition: smartsens.h:550
smartsens_s::last_time_stamp
uint32_t last_time_stamp[SMARTSENS_FIFO_TYPE_MAX]
Definition: smartsens.h:589