31 #ifndef _ACCELEROMETER_H
32 #define _ACCELEROMETER_H
36 #include <STM32FreeRTOS.h>
39 #include "semaphore.hpp"
42 using namespace cpp_freertos;
44 #define ACCELEROMETER_SEMAPHORE_MAX_WAITING_TIME_MS (1000)
48 #define ACCELEROMETER_IIS328DQ_I2C_ADDR_DEFAULT (0x19)
49 #define ACCELEROMETER_WAIT_CHECK_HARDWARE (5)
50 #define ACCELEROMETER_MAX_CHECK_ATTEMPT (5)
52 #define IIS328DQ_ID 0x32
55 #define DRV_LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
56 #define DRV_BIG_ENDIAN __ORDER_BIG_ENDIAN__
57 #define DRV_BYTE_ORDER __BYTE_ORDER__
58 #define PROPERTY_DISABLE (0U)
59 #define PROPERTY_ENABLE (1U)
61 #define ARR_REG_FILTER 30
79 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
88 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
100 #define IIS328DQ_WHO_AM_I 0x0FU
101 #define IIS328DQ_CTRL_REG1 0x20U
104 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
110 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
119 #define IIS328DQ_CTRL_REG2 0x21U
122 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
128 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
137 #define IIS328DQ_CTRL_REG3 0x22U
140 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
147 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
157 #define IIS328DQ_CTRL_REG4 0x23U
160 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
166 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
175 #define IIS328DQ_CTRL_REG5 0x24U
178 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
181 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
182 uint8_t not_used_01 : 6;
187 #define IIS328DQ_HP_FILTER_RESET 0x25U
188 #define IIS328DQ_REFERENCE 0x26U
189 #define IIS328DQ_STATUS_REG 0x27U
192 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
201 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
213 #define IIS328DQ_OUT_X_L 0x28U
214 #define IIS328DQ_OUT_X_H 0x29U
215 #define IIS328DQ_OUT_Y_L 0x2AU
216 #define IIS328DQ_OUT_Y_H 0x2BU
217 #define IIS328DQ_OUT_Z_L 0x2CU
218 #define IIS328DQ_OUT_Z_H 0x2DU
219 #define IIS328DQ_INT1_CFG 0x30U
222 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
231 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
243 #define IIS328DQ_INT1_SRC 0x31U
246 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
255 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
256 uint8_t not_used_01 : 1;
267 #define IIS328DQ_INT1_THS 0x32U
270 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
273 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
274 uint8_t not_used_01 : 1;
279 #define IIS328DQ_INT1_DURATION 0x33U
282 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
285 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
286 uint8_t not_used_01 : 1;
291 #define IIS328DQ_INT2_CFG 0x34U
294 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
303 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
315 #define IIS328DQ_INT2_SRC 0x35U
318 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
327 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
328 uint8_t not_used_01 : 1;
339 #define IIS328DQ_INT2_THS 0x36U
342 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
345 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
346 uint8_t not_used_01 : 1;
351 #define IIS328DQ_INT2_DURATION 0x37U
354 #if DRV_BYTE_ORDER == DRV_LITTLE_ENDIAN
357 #elif DRV_BYTE_ORDER == DRV_BIG_ENDIAN
358 uint8_t not_used_01 : 1;
391 int32_t iis328dq_read_reg(uint8_t reg, uint8_t *data, uint16_t len);
392 int32_t iis328dq_write_reg(uint8_t reg, uint8_t *data, uint16_t len);
394 void push_raw_data(int16_t *data_raw);
397 float_t iis328dq_from_fs2_to_mg(int16_t lsb);
398 float_t iis328dq_from_fs2_to_mg(
coordinate request);
399 float_t iis328dq_from_fs4_to_mg(int16_t lsb);
400 float_t iis328dq_from_fs4_to_mg(
coordinate request);
401 float_t iis328dq_from_fs8_to_mg(int16_t lsb);
402 float_t iis328dq_from_fs8_to_mg(
coordinate request);
404 float_t iis328dq_from_fsx_to_inc(int16_t lsb);
405 float_t iis328dq_from_fsx_to_inc(
coordinate request);
407 int32_t iis328dq_axis_x_data_set(uint8_t val);
408 int32_t iis328dq_axis_x_data_get(uint8_t *val);
410 int32_t iis328dq_axis_y_data_set(uint8_t val);
411 int32_t iis328dq_axis_y_data_get(uint8_t *val);
413 int32_t iis328dq_axis_z_data_set(uint8_t val);
414 int32_t iis328dq_axis_z_data_get(uint8_t *val);
418 IIS328DQ_ODR_OFF = 0x00,
419 IIS328DQ_ODR_ON = 0x01,
420 IIS328DQ_ODR_Hz5 = 0x02,
421 IIS328DQ_ODR_1Hz = 0x03,
422 IIS328DQ_ODR_5Hz2 = 0x04,
423 IIS328DQ_ODR_5Hz = 0x05,
424 IIS328DQ_ODR_10Hz = 0x06,
425 IIS328DQ_ODR_50Hz = 0x01,
426 IIS328DQ_ODR_100Hz = 0x11,
427 IIS328DQ_ODR_400Hz = 0x21,
428 IIS328DQ_ODR_1kHz = 0x31,
430 int32_t iis328dq_data_rate_set(iis328dq_dr_t val);
431 int32_t iis328dq_data_rate_get(iis328dq_dr_t *val);
435 IIS328DQ_NORMAL_MODE = 0,
436 IIS328DQ_REF_MODE_ENABLE = 1,
438 int32_t iis328dq_reference_mode_set(iis328dq_hpm_t val);
439 int32_t iis328dq_reference_mode_get(iis328dq_hpm_t *val);
447 int32_t iis328dq_full_scale_set(iis328dq_fs_t val);
448 int32_t iis328dq_full_scale_get(iis328dq_fs_t *val);
450 int32_t iis328dq_block_data_update_set(uint8_t val);
451 int32_t iis328dq_block_data_update_get(uint8_t *val);
453 int32_t iis328dq_status_reg_get(iis328dq_status_reg_t *val);
455 int32_t iis328dq_flag_data_ready_get(uint8_t *val);
457 int32_t iis328dq_acceleration_raw_get(int16_t *val);
459 int32_t iis328dq_device_id_get(uint8_t *buff);
461 int32_t iis328dq_boot_set(uint8_t val);
462 int32_t iis328dq_boot_get(uint8_t *val);
466 IIS328DQ_ST_DISABLE = 0,
467 IIS328DQ_ST_POSITIVE = 1,
468 IIS328DQ_ST_NEGATIVE = 5,
470 int32_t iis328dq_self_test_set(iis328dq_st_t val);
471 int32_t iis328dq_self_test_get(iis328dq_st_t *val);
475 IIS328DQ_LSB_AT_LOW_ADD = 0,
476 IIS328DQ_MSB_AT_LOW_ADD = 1,
478 int32_t iis328dq_data_format_set(iis328dq_ble_t val);
479 int32_t iis328dq_data_format_get(iis328dq_ble_t *val);
483 IIS328DQ_CUT_OFF_8Hz = 0,
484 IIS328DQ_CUT_OFF_16Hz = 1,
485 IIS328DQ_CUT_OFF_32Hz = 2,
486 IIS328DQ_CUT_OFF_64Hz = 3,
488 int32_t iis328dq_hp_bandwidth_set(iis328dq_hpcf_t val);
489 int32_t iis328dq_hp_bandwidth_get(iis328dq_hpcf_t *val);
493 IIS328DQ_HP_DISABLE = 0,
494 IIS328DQ_HP_ON_OUT = 4,
495 IIS328DQ_HP_ON_INT1 = 1,
496 IIS328DQ_HP_ON_INT2 = 2,
497 IIS328DQ_HP_ON_INT1_INT2 = 3,
498 IIS328DQ_HP_ON_INT1_INT2_OUT = 7,
499 IIS328DQ_HP_ON_INT2_OUT = 6,
500 IIS328DQ_HP_ON_INT1_OUT = 5,
502 int32_t iis328dq_hp_path_set(iis328dq_hpen_t val);
503 int32_t iis328dq_hp_path_get(iis328dq_hpen_t *val);
505 int32_t iis328dq_hp_reset_get(
void);
507 int32_t iis328dq_hp_reference_value_set(uint8_t val);
508 int32_t iis328dq_hp_reference_value_get(uint8_t *val);
512 IIS328DQ_SPI_4_WIRE = 0,
513 IIS328DQ_SPI_3_WIRE = 1,
515 int32_t iis328dq_spi_mode_set(iis328dq_sim_t val);
516 int32_t iis328dq_spi_mode_get(iis328dq_sim_t *val);
520 IIS328DQ_PAD1_INT1_SRC = 0,
521 IIS328DQ_PAD1_INT1_OR_INT2_SRC = 1,
522 IIS328DQ_PAD1_DRDY = 2,
523 IIS328DQ_PAD1_BOOT = 3,
525 int32_t iis328dq_pin_int1_route_set(iis328dq_i1_cfg_t val);
526 int32_t iis328dq_pin_int1_route_get(iis328dq_i1_cfg_t *val);
530 IIS328DQ_INT1_PULSED = 0,
531 IIS328DQ_INT1_LATCHED = 1,
533 int32_t iis328dq_int1_notification_set(iis328dq_lir1_t val);
534 int32_t iis328dq_int1_notification_get(iis328dq_lir1_t *val);
538 IIS328DQ_PAD2_INT2_SRC = 0,
539 IIS328DQ_PAD2_INT1_OR_INT2_SRC = 1,
540 IIS328DQ_PAD2_DRDY = 2,
541 IIS328DQ_PAD2_BOOT = 3,
543 int32_t iis328dq_pin_int2_route_set(iis328dq_i2_cfg_t val);
544 int32_t iis328dq_pin_int2_route_get(iis328dq_i2_cfg_t *val);
548 IIS328DQ_INT2_PULSED = 0,
549 IIS328DQ_INT2_LATCHED = 1,
551 int32_t iis328dq_int2_notification_set(iis328dq_lir2_t val);
552 int32_t iis328dq_int2_notification_get(iis328dq_lir2_t *val);
556 IIS328DQ_PUSH_PULL = 0,
557 IIS328DQ_OPEN_DRAIN = 1,
559 int32_t iis328dq_pin_mode_set(iis328dq_pp_od_t val);
560 int32_t iis328dq_pin_mode_get(iis328dq_pp_od_t *val);
564 IIS328DQ_ACTIVE_HIGH = 0,
565 IIS328DQ_ACTIVE_LOW = 1,
567 int32_t iis328dq_pin_polarity_set(iis328dq_ihl_t val);
568 int32_t iis328dq_pin_polarity_get(iis328dq_ihl_t *val);
584 IIS328DQ_INT1_ON_THRESHOLD_OR = 0,
585 IIS328DQ_INT1_ON_THRESHOLD_AND = 1,
586 } iis328dq_int1_aoi_t;
587 int32_t iis328dq_int1_on_threshold_mode_set(iis328dq_int1_aoi_t val);
588 int32_t iis328dq_int1_on_threshold_mode_get(iis328dq_int1_aoi_t *val);
590 int32_t iis328dq_int1_src_get(iis328dq_int1_src_t *val);
592 int32_t iis328dq_int1_treshold_set(uint8_t val);
593 int32_t iis328dq_int1_treshold_get(uint8_t *val);
595 int32_t iis328dq_int1_dur_set(uint8_t val);
596 int32_t iis328dq_int1_dur_get(uint8_t *val);
612 IIS328DQ_INT2_ON_THRESHOLD_OR = 0,
613 IIS328DQ_INT2_ON_THRESHOLD_AND = 1,
614 } iis328dq_int2_aoi_t;
615 int32_t iis328dq_int2_on_threshold_mode_set(iis328dq_int2_aoi_t val);
616 int32_t iis328dq_int2_on_threshold_mode_get(iis328dq_int2_aoi_t *val);
618 int32_t iis328dq_int2_src_get(iis328dq_int2_src_t *val);
620 int32_t iis328dq_int2_treshold_set(uint8_t val);
621 int32_t iis328dq_int2_treshold_get(uint8_t *val);
623 int32_t iis328dq_int2_dur_set(uint8_t val);
624 int32_t iis328dq_int2_dur_get(uint8_t *val);
626 int32_t iis328dq_wkup_to_sleep_set(uint8_t val);
627 int32_t iis328dq_wkup_to_sleep_get(uint8_t *val);
631 IIS328DQ_6D_INT1_DISABLE = 0,
632 IIS328DQ_6D_INT1_MOVEMENT = 1,
633 IIS328DQ_6D_INT1_POSITION = 3,
634 } iis328dq_int1_6d_t;
635 int32_t iis328dq_int1_6d_mode_set(iis328dq_int1_6d_t val);
636 int32_t iis328dq_int1_6d_mode_get(iis328dq_int1_6d_t *val);
638 int32_t iis328dq_int1_6d_src_get(iis328dq_int1_src_t *val);
640 int32_t iis328dq_int1_6d_treshold_set(uint8_t val);
641 int32_t iis328dq_int1_6d_treshold_get(uint8_t *val);
645 IIS328DQ_6D_INT2_DISABLE = 0,
646 IIS328DQ_6D_INT2_MOVEMENT = 1,
647 IIS328DQ_6D_INT2_POSITION = 3,
648 } iis328dq_int2_6d_t;
649 int32_t iis328dq_int2_6d_mode_set(iis328dq_int2_6d_t val);
650 int32_t iis328dq_int2_6d_mode_get(iis328dq_int2_6d_t *val);
652 int32_t iis328dq_int2_6d_src_get(iis328dq_int2_src_t *val);
654 int32_t iis328dq_int2_6d_treshold_set(uint8_t val);
655 int32_t iis328dq_int2_6d_treshold_get(uint8_t *val);
#define ACCELEROMETER_IIS328DQ_I2C_ADDR_DEFAULT
BinarySemaphore * _wireLock
Accelerometer::iis328dq_dr_t module_power
module updating frequency (enabled)
uint8_t config_valid
Inizialization Byte Config.
float offset_y
offset_y to 0
float offset_x
offset_x to 0
float offset_z
offset_z to 0
iis328dq_status_reg_t status_reg
iis328dq_int1_ths_t int1_ths
iis328dq_ctrl_reg4_t ctrl_reg4
iis328dq_int2_cfg_t int2_cfg
iis328dq_ctrl_reg3_t ctrl_reg3
iis328dq_int2_src_t int2_src
iis328dq_ctrl_reg1_t ctrl_reg1
iis328dq_int1_cfg_t int1_cfg
iis328dq_int1_duration_t int1_duration
iis328dq_int1_src_t int1_src
iis328dq_int2_duration_t int2_duration
iis328dq_int2_ths_t int2_ths
iis328dq_ctrl_reg5_t ctrl_reg5
iis328dq_ctrl_reg2_t ctrl_reg2