34 #include "generated/modules.h"
41 #if !defined IMU_MPU9250_GYRO_LOWPASS_FILTER && !defined IMU_MPU9250_ACCEL_LOWPASS_FILTER && !defined IMU_MPU9250_SMPLRT_DIV
42 #if (PERIODIC_FREQUENCY >= 60) && (PERIODIC_FREQUENCY <= 120)
47 #define IMU_MPU9250_GYRO_LOWPASS_FILTER MPU9250_DLPF_GYRO_41HZ
48 #define IMU_MPU9250_ACCEL_LOWPASS_FILTER MPU9250_DLPF_ACCEL_41HZ
49 #define IMU_MPU9250_SMPLRT_DIV 9
50 PRINT_CONFIG_MSG(
"Gyro/Accel output rate is 100Hz at 1kHz internal sampling")
51 #elif (PERIODIC_FREQUENCY == 512) || (PERIODIC_FREQUENCY == 500)
56 #define IMU_MPU9250_GYRO_LOWPASS_FILTER MPU9250_DLPF_GYRO_250HZ
57 #define IMU_MPU9250_ACCEL_LOWPASS_FILTER MPU9250_DLPF_ACCEL_184HZ
58 #define IMU_MPU9250_SMPLRT_DIV 3
62 #define IMU_MPU9250_SMPLRT_DIV 9
63 #define IMU_MPU9250_GYRO_LOWPASS_FILTER MPU9250_DLPF_GYRO_41HZ
64 #define IMU_MPU9250_ACCEL_LOWPASS_FILTER MPU9250_DLPF_ACCEL_41HZ
65 PRINT_CONFIG_MSG(
"Gyro/Accel output rate is 100Hz at 1kHz internal sampling")
66 #warning "Non-default PERIODIC_FREQUENCY: please define IMU_MPU9250_GYRO_LOWPASS_FILTER, IMU_MPU9250_ACCEL_LOWPASS_FILTER and IMU_MPU9250_SMPLRT_DIV."
77 #ifndef IMU_MPU9250_CHAN_X
78 #define IMU_MPU9250_CHAN_X 0
81 #ifndef IMU_MPU9250_CHAN_Y
82 #define IMU_MPU9250_CHAN_Y 1
85 #ifndef IMU_MPU9250_CHAN_Z
86 #define IMU_MPU9250_CHAN_Z 2
90 #ifndef IMU_MPU9250_X_SIGN
91 #define IMU_MPU9250_X_SIGN 1
94 #ifndef IMU_MPU9250_Y_SIGN
95 #define IMU_MPU9250_Y_SIGN 1
98 #ifndef IMU_MPU9250_Z_SIGN
99 #define IMU_MPU9250_Z_SIGN 1
103 #ifndef IMU_MPU9250_READ_MAG
104 #define IMU_MPU9250_READ_MAG TRUE
107 #ifndef IMU_MPU9250_MAG_STARTUP_DELAY
108 #define IMU_MPU9250_MAG_STARTUP_DELAY 1
133 #if IMU_MPU9250_READ_MAG
172 #define Int16FromBuf(_buf,_idx) ((int16_t)(_buf[_idx] | (_buf[_idx+1] << 8)))
193 #if IMU_MPU9250_READ_MAG
205 AbiSendMsgIMU_GYRO_RAW(
IMU_MPU9250_ID, now_ts, &rates, 1, IMU_MPU9250_PERIODIC_FREQ, NAN);
206 AbiSendMsgIMU_ACCEL_RAW(
IMU_MPU9250_ID, now_ts, &accel, 1, IMU_MPU9250_PERIODIC_FREQ, NAN);
214 mpu_set(mpu, _reg, _val);
Main include for ABI (AirBorneInterface).
#define AK8963_CNTL1_CM_2
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
enum SPIClockPolarity cpol
clock polarity control
enum SPIClockPhase cpha
clock phase control
enum SPISlaveSelect select
slave selection behavior
SPICallback before_cb
NULL or function called before the transaction.
SPICallback after_cb
NULL or function called after the transaction.
enum SPIDataSizeSelect dss
data transfer word size
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
uint16_t input_length
number of data words to read
enum SPIClockDiv cdiv
prescaler of main clock to use as SPI clock
volatile uint8_t * input_buf
pointer to receive buffer for DMA
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
enum SPIBitOrder bitorder
MSB/LSB order.
uint16_t output_length
number of data words to write
enum SPITransactionStatus status
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
@ SPICpolIdleHigh
CPOL = 1.
@ SPISelectUnselect
slave is selected before transaction and unselected after
SPI transaction structure.
void imu_set_defaults_accel(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct Int32Vect3 *scale)
Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to...
void imu_set_defaults_gyro(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Rates *neutral, const struct Int32Rates *scale)
Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ...
Inertial Measurement Unit interface.
#define IMU_MPU9250_ACCEL_RANGE
#define IMU_MPU9250_GYRO_RANGE
#define IMU_MPU9250_MAG_STARTUP_DELAY
#define IMU_MPU9250_GYRO_LOWPASS_FILTER
#define IMU_MPU9250_X_SIGN
#define IMU_MPU9250_CHAN_X
bool imu_mpu9250_configure_mag_slave(Mpu9250ConfigSet mpu_set, void *mpu)
function to configure akm8963 mag
void imu_mpu9250_periodic(void)
#define IMU_MPU9250_Y_SIGN
#define IMU_MPU9250_ACCEL_LOWPASS_FILTER
void mpu_wait_slave4_ready_cb(struct spi_transaction *t)
void imu_mpu9250_init(void)
void mpu_wait_slave4_ready(void)
#define IMU_MPU9250_Z_SIGN
#define IMU_MPU9250_SMPLRT_DIV
#define IMU_MPU9250_CHAN_Z
#define IMU_MPU9250_CHAN_Y
static void mpu_set_and_wait(Mpu9250ConfigSet mpu_set, void *mpu, uint8_t _reg, uint8_t _val)
struct ImuMpu9250 imu_mpu9250
#define Int16FromBuf(_buf, _idx)
void imu_mpu9250_event(void)
IMU driver for the MPU9250 using SPI.
struct spi_transaction wait_slave4_trans
volatile uint8_t wait_slave4_rx_buf[2]
volatile uint8_t wait_slave4_tx_buf[1]
volatile bool slave4_ready
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
const struct Int32Vect3 MPU9250_ACCEL_SENS_FRAC[4][2]
const struct Int32Rates MPU9250_GYRO_SENS_FRAC[4][2]
enum Mpu9250DLPFGyro dlpf_gyro_cfg
Digital Low Pass Filter for gyroscope.
Mpu9250I2cSlaveConfigure configure
void(* Mpu9250ConfigSet)(void *mpu, uint8_t _reg, uint8_t _val)
Configuration function prototype.
uint8_t i2c_mst_delay
MPU I2C slaves delayed sample rate.
enum Mpu9250MstClk i2c_mst_clk
MPU I2C master clock speed.
uint8_t nb_slaves
number of used I2C slaves
enum Mpu9250GyroRanges gyro_range
deg/s Range
uint8_t nb_bytes
number of bytes to read starting with MPU9250_REG_INT_STATUS
enum Mpu9250DLPFAccel dlpf_accel_cfg
Digital Low Pass Filter for accelerometer.
uint8_t smplrt_div
Sample rate divider.
enum Mpu9250AccelRanges accel_range
g Range
struct Mpu9250I2cSlave slaves[MPU9250_I2C_NB_SLAVES]
I2C slaves.
struct Mpu9250Config config
union Mpu9250_I2c::@344 data_rates
uint8_t data_ext[MPU9250_BUFFER_EXT_LEN]
union Mpu9250_I2c::@343 data_accel
volatile bool data_available
data ready flag
#define MPU9250_REG_I2C_SLV4_ADDR
#define MPU9250_I2C_SLV4_DONE
#define MPU9250_REG_I2C_MST_STATUS
#define MPU9250_REG_I2C_SLV0_ADDR
#define MPU9250_REG_I2C_SLV4_REG
#define MPU9250_REG_I2C_SLV4_DO
#define MPU9250_REG_I2C_SLV4_CTRL
#define MPU9250_REG_I2C_SLV0_CTRL
#define MPU9250_REG_I2C_SLV0_REG
void mpu9250_spi_init(struct Mpu9250_Spi *mpu, struct spi_periph *spi_p, uint8_t slave_idx)
void mpu9250_spi_event(struct Mpu9250_Spi *mpu)
static void mpu9250_spi_periodic(struct Mpu9250_Spi *mpu)
convenience function: read or start configuration if not already initialized
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
Architecture independent SPI (Serial Peripheral Interface) API.
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.