|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) [2020] by InvenSense, Inc. |
| 4 | + * |
| 5 | + * Permission to use, copy, modify, and/or distribute this software for any |
| 6 | + * purpose with or without fee is hereby granted. |
| 7 | + * |
| 8 | + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 11 | + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | + * |
| 16 | + */ |
| 17 | + |
| 18 | +#ifndef ICM456xx_H |
| 19 | +#define ICM456xx_H |
| 20 | + |
| 21 | +#include "Arduino.h" |
| 22 | +#include "SPI.h" |
| 23 | +#include "Wire.h" |
| 24 | + |
| 25 | +#define ICM45686 |
| 26 | + |
| 27 | +extern "C" { |
| 28 | +#include "./imu/inv_imu_driver_advanced.h" |
| 29 | +#include "./imu/inv_imu_edmp.h" |
| 30 | +#if defined(ICM45686S) || defined(ICM45605S) |
| 31 | +#include "./imu/inv_imu_edmp_gaf.h" |
| 32 | +#endif |
| 33 | +} |
| 34 | + |
| 35 | +enum { |
| 36 | + ICM456XX_APEX_TILT=0, |
| 37 | + ICM456XX_APEX_PEDOMETER, |
| 38 | + ICM456XX_APEX_TAP, |
| 39 | + ICM456XX_APEX_R2W, |
| 40 | + ICM456XX_APEX_NB, |
| 41 | +}; |
| 42 | + |
| 43 | +// This defines the handler called when retrieving a sample from the FIFO |
| 44 | +//typedef void (*ICM456xx_sensor_event_cb)(inv_imu_sensor_data_t *event); |
| 45 | +// This defines the handler called when receiving an irq |
| 46 | +typedef void (*ICM456xx_irq_handler)(void); |
| 47 | + |
| 48 | +class ICM456xx { |
| 49 | + public: |
| 50 | + ICM456xx(TwoWire &i2c,bool address_lsb, uint32_t freq); |
| 51 | + ICM456xx(TwoWire &i2c,bool address_lsb); |
| 52 | + ICM456xx(SPIClass &spi,uint8_t chip_select_id, uint32_t freq); |
| 53 | + ICM456xx(SPIClass &spi,uint8_t chip_select_id); |
| 54 | + int begin(); |
| 55 | + int startAccel(uint16_t odr, uint16_t fsr); |
| 56 | + int startGyro(uint16_t odr, uint16_t fsr); |
| 57 | + int getDataFromRegisters(inv_imu_sensor_data_t& data); |
| 58 | + int enableFifoInterrupt(uint8_t intpin, ICM456xx_irq_handler handler, uint8_t fifo_watermark); |
| 59 | + int getDataFromFifo(inv_imu_fifo_data_t& data); |
| 60 | +#if defined(ICM45686S) || defined(ICM45605S) |
| 61 | + int startGaf(uint8_t intpin, ICM456xx_irq_handler handler); |
| 62 | + int getGafData(inv_imu_edmp_gaf_outputs_t& gaf_outputs); |
| 63 | + int getGafData(float& quatW,float& quatX,float& quatY,float& quatZ); |
| 64 | +#endif |
| 65 | + int stopAccel(void); |
| 66 | + int stopGyro(void); |
| 67 | + int startTiltDetection(uint8_t intpin=2, ICM456xx_irq_handler handler=NULL); |
| 68 | + int startPedometer(uint8_t intpin=2, ICM456xx_irq_handler handler=NULL); |
| 69 | + int getPedometer(uint32_t& step_count, float& step_cadence, char*& activity); |
| 70 | + int startWakeOnMotion(uint8_t intpin, ICM456xx_irq_handler handler); |
| 71 | + int startTap(uint8_t intpin=2, ICM456xx_irq_handler handler=NULL); |
| 72 | + bool getTilt(void); |
| 73 | + int getTap(uint8_t& tap_count, uint8_t& axis, uint8_t& direction); |
| 74 | + int startRaiseToWake(uint8_t intpin=2, ICM456xx_irq_handler handler=NULL); |
| 75 | + int getRaiseToWake(void); |
| 76 | + int updateApex(void); |
| 77 | + int setApexInterrupt(uint8_t intpin, ICM456xx_irq_handler handler); |
| 78 | + inv_imu_edmp_int_state_t apex_status; |
| 79 | + |
| 80 | + protected: |
| 81 | + inv_imu_device_t icm_driver; |
| 82 | + accel_config0_accel_odr_t accel_freq_to_param(uint16_t accel_freq_hz); |
| 83 | + gyro_config0_gyro_odr_t gyro_freq_to_param(uint16_t gyro_freq_hz); |
| 84 | + accel_config0_accel_ui_fs_sel_t accel_fsr_g_to_param(uint16_t accel_fsr_g); |
| 85 | + gyro_config0_gyro_ui_fs_sel_t gyro_fsr_dps_to_param(uint16_t gyro_fsr_dps); |
| 86 | + int setup_irq(uint8_t intpin, ICM456xx_irq_handler handler); |
| 87 | + int startAPEX(dmp_ext_sen_odr_cfg_apex_odr_t edmp_odr, accel_config0_accel_odr_t accel_odr); |
| 88 | + uint32_t step_cnt_ovflw; |
| 89 | + bool apex_enable[ICM456XX_APEX_NB]; |
| 90 | + dmp_ext_sen_odr_cfg_apex_odr_t apex_edmp_odr; |
| 91 | + accel_config0_accel_odr_t apex_accel_odr; |
| 92 | +}; |
| 93 | + |
| 94 | +#endif // ICM456xx_H |
0 commit comments