Skip to content

Commit 6e076ce

Browse files
authored
Add IMU_USE_SPI_ICM45686 (#37)
1 parent 49c6821 commit 6e076ce

33 files changed

+11455
-6
lines changed

src/madflight/imu/ICM4xxxx/ICM45686/ICM45686.cpp

Lines changed: 786 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2023, InvenSense, Inc.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)