34 #if defined(PIOS_INCLUDE_MPU)
37 #include "physical_constants.h"
41 #ifndef PIOS_MPU_SPI_HIGH_SPEED
42 #define PIOS_MPU_SPI_HIGH_SPEED 20000000 // should result in 10.5MHz clock on F4 targets like Sparky2
43 #endif // PIOS_MPU_SPI_HIGH_SPEED
44 #define PIOS_MPU_SPI_LOW_SPEED 300000
63 #if defined(PIOS_INCLUDE_I2C) || defined(__DOXYGEN__)
64 static const uint8_t pios_mpu_i2c_addr[] = {
73 enum pios_mpu_com_driver {
82 enum pios_mpu_dev_magic {
83 PIOS_MPU_DEV_MAGIC = 0xa9dd94b4
92 enum pios_mpu_com_driver com_driver_type;
95 uint32_t com_slave_addr;
99 enum pios_mpu_dev_magic
magic;
102 #ifdef PIOS_INCLUDE_MPU_MAG
107 #endif // PIOS_INCLUDE_MPU_MAG
108 volatile uint32_t interrupt_count;
109 volatile uint8_t sensor_ready;
112 #define SENSOR_ACCEL (1 << 0)
113 #define SENSOR_MAG (1 << 1)
116 static struct pios_mpu_dev *mpu_dev;
122 static struct pios_mpu_dev *PIOS_MPU_Alloc(
const struct pios_mpu_cfg *
cfg);
124 #ifdef PIOS_INCLUDE_MPU_MAG
128 static int32_t PIOS_MPU_Mag_Probe(
void);
129 #endif // PIOS_INCLUDE_MPU_MAG
134 static int32_t PIOS_MPU_Validate(
struct pios_mpu_dev *dev);
139 static int32_t PIOS_MPU_Reset();
146 static int32_t PIOS_MPU_ReadReg(uint8_t reg);
147 static int32_t PIOS_MPU_WriteReg(uint8_t reg, uint8_t
data);
149 #if defined(PIOS_INCLUDE_SPI) || defined(__DOXYGEN__)
155 static int32_t PIOS_MPU_ClaimBus(
bool lowspeed);
161 static int32_t PIOS_MPU_ReleaseBus(
bool lowspeed);
167 static int32_t PIOS_MPU_SPI_Probe(
enum pios_mpu_type *detected_device);
168 #endif // defined(PIOS_INCLUDE_SPI) || defined(__DOXYGEN__)
170 #if defined(PIOS_INCLUDE_I2C) || defined(__DOXYGEN__)
176 static int32_t PIOS_MPU_I2C_Probe(
enum pios_mpu_type *detected_device);
177 #endif // defined(PIOS_INCLUDE_I2C) || defined(__DOXYGEN__)
179 static int PIOS_MPU_parse_data(
struct pios_mpu_dev *
p);
181 static bool PIOS_MPU_callback_gyro(
void *ctx,
void *output,
182 int ms_to_wait,
int *next_call)
184 struct pios_mpu_dev *dev = (
struct pios_mpu_dev *)ctx;
195 if (PIOS_MPU_parse_data(dev)) {
199 memcpy(output, &dev->gyro_data,
sizeof(dev->gyro_data));
204 static bool PIOS_MPU_callback_accel(
void *ctx,
void *output,
205 int ms_to_wait,
int *next_call)
207 struct pios_mpu_dev *dev = (
struct pios_mpu_dev *)ctx;
214 if (!(dev->sensor_ready & SENSOR_ACCEL)) {
218 memcpy(output, &dev->accel_data,
sizeof(dev->accel_data));
219 dev->sensor_ready &= ~SENSOR_ACCEL;
224 #if defined(PIOS_INCLUDE_MPU_MAG)
225 static bool PIOS_MPU_callback_mag(
void *ctx,
void *output,
226 int ms_to_wait,
int *next_call)
228 struct pios_mpu_dev *dev = (
struct pios_mpu_dev *)ctx;
236 if (!(dev->sensor_ready & SENSOR_MAG)) {
240 memcpy(output, &dev->mag_data,
sizeof(dev->mag_data));
241 dev->sensor_ready &= ~SENSOR_MAG;
245 #endif // PIOS_INCLUDE_MPU_MAG
247 static struct pios_mpu_dev *PIOS_MPU_Alloc(
const struct pios_mpu_cfg *
cfg)
249 struct pios_mpu_dev *dev;
251 dev = (
struct pios_mpu_dev *)
PIOS_malloc(
sizeof(*mpu_dev));
255 *dev = (
struct pios_mpu_dev) {
256 .magic = PIOS_MPU_DEV_MAGIC
260 if (dev->data_ready_sema == NULL) {
268 static int32_t PIOS_MPU_Validate(
struct pios_mpu_dev *dev)
272 if (dev->magic != PIOS_MPU_DEV_MAGIC)
277 static int32_t PIOS_MPU_CheckWhoAmI(
enum pios_mpu_type *detected_device)
286 if (((uint8_t) retval) == pios_mpu_whoami[
i]) {
287 *detected_device =
i;
295 static int32_t PIOS_MPU_Reset()
309 if (mpu_dev->com_driver_type == PIOS_MPU_COM_SPI) {
320 static int32_t PIOS_MPU_Config(
struct pios_mpu_cfg const *cfg)
346 #ifdef PIOS_INCLUDE_MPU_MAG
353 static int32_t PIOS_MPU_Mag_WriteReg(uint8_t reg, uint8_t
data)
367 uint32_t timeout = 0;
386 static uint8_t PIOS_MPU_Mag_ReadReg(uint8_t reg)
400 uint32_t timeout = 0;
406 }
while ((status & PIOS_MPU_I2C_MST_SLV4_DONE) == 0);
411 static void PIOS_MPU_Mag_Trigger(
void)
430 static int32_t PIOS_MPU_Mag_Config(
void)
449 PIOS_MPU_Mag_Trigger();
459 static int32_t PIOS_MPU_Mag_Probe(
void)
468 #endif // PIOS_INCLUDE_MPU_MAG
470 static int32_t PIOS_MPU_Common_Init(
void)
473 if (PIOS_MPU_Reset() != 0)
476 #ifdef PIOS_INCLUDE_MPU_MAG
478 if (mpu_dev->cfg->use_internal_mag) {
479 mpu_dev->use_mag =
true;
480 if (PIOS_MPU_Mag_Probe() == 0) {
484 if (PIOS_MPU_Mag_Config() != 0)
493 mpu_dev->use_mag =
false;
496 mpu_dev->use_mag =
false;
498 #endif // PIOS_INCLUDE_MPU_MAG
501 if (PIOS_MPU_Config(mpu_dev->cfg) != 0)
508 if (!mpu_dev->cfg->skip_startup_irq_check) {
509 for (
int i=0;
i<2;
i++) {
510 uint32_t ref_val = mpu_dev->interrupt_count;
513 while (mpu_dev->interrupt_count == ref_val) {
526 PIOS_MPU_callback_gyro, mpu_dev);
531 PIOS_MPU_callback_accel, mpu_dev);
534 #ifdef PIOS_INCLUDE_MPU_MAG
535 if (mpu_dev->use_mag) {
537 PIOS_MPU_callback_mag, mpu_dev);
541 #endif // PIOS_INCLUDE_MPU_MAG
571 mpu_dev->gyro_range = range;
586 mpu_dev->accel_range = range;
595 static float PIOS_MPU_GetGyroScale(
void)
597 switch (mpu_dev->gyro_range) {
599 return 1.0f / 131.0f;
614 static float PIOS_MPU_GetAccelScale(
void)
616 switch (mpu_dev->accel_range) {
618 return GRAVITY / 16384.0f;
620 return GRAVITY / 8192.0f;
622 return GRAVITY / 4096.0f;
624 return GRAVITY / 2048.0f;
636 else if (bandwidth <= 10)
638 else if (bandwidth <= 20)
640 else if (bandwidth <= 41)
642 else if (bandwidth <= 92)
649 else if (bandwidth <= 10)
651 else if (bandwidth <= 20)
653 else if (bandwidth <= 42)
655 else if (bandwidth <= 98)
662 else if (bandwidth <= 10)
664 else if (bandwidth <= 20)
666 else if (bandwidth <= 92)
672 else if (bandwidth <= 176)
674 else if (bandwidth <= 250)
697 else if (bandwidth <= 10)
699 else if (bandwidth <= 20)
701 else if (bandwidth <= 41)
703 else if (bandwidth <= 92)
705 else if (bandwidth <= 184)
712 else if (bandwidth <= 10)
714 else if (bandwidth <= 21)
716 else if (bandwidth <= 45)
718 else if (bandwidth <= 99)
720 else if (bandwidth <= 218)
732 uint16_t internal_rate = 1000;
735 if (samplerate_hz > internal_rate)
736 samplerate_hz = internal_rate;
739 int32_t divisor = (int32_t)(((
float)internal_rate / samplerate_hz) + 0.5f) - 1;
749 samplerate_hz = internal_rate / (1 + divisor);
756 #ifdef PIOS_INCLUDE_MPU_MAG
757 if (mpu_dev->use_mag) {
765 #endif // PIOS_INCLUDE_MPU_MAG
773 return mpu_dev->mpu_type;
776 #if defined(PIOS_INCLUDE_I2C)
777 static int32_t PIOS_MPU_I2C_Probe(
enum pios_mpu_type *detected_device)
780 for (
int i = 0;
i <
NELEMENTS(pios_mpu_i2c_addr);
i++) {
781 mpu_dev->com_slave_addr = pios_mpu_i2c_addr[
i];
782 retval = PIOS_MPU_CheckWhoAmI(detected_device);
792 mpu_dev = PIOS_MPU_Alloc(cfg);
800 mpu_dev->com_driver_type = PIOS_MPU_COM_I2C;
801 mpu_dev->i2c_driver_id = i2c_id;
804 if (PIOS_MPU_I2C_Probe(&mpu_dev->mpu_type) != 0)
807 return PIOS_MPU_Common_Init();
810 static int32_t PIOS_MPU_I2C_Read(uint8_t address, uint8_t *buffer, uint8_t len)
812 uint8_t addr_buffer[] = {
819 .addr = mpu_dev->com_slave_addr,
821 .len =
sizeof(addr_buffer),
826 .addr = mpu_dev->com_slave_addr,
836 static int32_t PIOS_MPU_I2C_Write(uint8_t address, uint8_t buffer)
846 .addr = mpu_dev->com_slave_addr,
855 #endif // defined(PIOS_INCLUDE_I2C)
857 #if defined(PIOS_INCLUDE_SPI)
862 mpu_dev = PIOS_MPU_Alloc(cfg);
870 mpu_dev->com_driver_type = PIOS_MPU_COM_SPI;
871 mpu_dev->spi_driver_id = spi_id;
872 mpu_dev->com_slave_addr = slave_num;
875 int32_t ret = PIOS_MPU_SPI_Probe(&mpu_dev->mpu_type);
881 return PIOS_MPU_Common_Init();
884 static int32_t PIOS_MPU_SPI_Probe(
enum pios_mpu_type *detected_device)
886 int32_t retval = PIOS_MPU_CheckWhoAmI(detected_device);
890 static int32_t PIOS_MPU_ClaimBus(
bool lowspeed)
892 if (PIOS_MPU_Validate(mpu_dev) != 0)
906 static int32_t PIOS_MPU_ReleaseBus(
bool lowspeed)
908 if (PIOS_MPU_Validate(mpu_dev) != 0)
921 static int32_t PIOS_MPU_SPI_Read(uint8_t address, uint8_t *buffer)
923 if (PIOS_MPU_ClaimBus(
true) != 0)
929 PIOS_MPU_ReleaseBus(
true);
934 static int32_t PIOS_MPU_SPI_Write(uint8_t address, uint8_t buffer)
936 if (PIOS_MPU_ClaimBus(
true) != 0)
942 PIOS_MPU_ReleaseBus(
true);
946 #endif // defined(PIOS_INCLUDE_SPI)
948 static int32_t PIOS_MPU_WriteReg(uint8_t reg, uint8_t data)
950 #if defined(PIOS_INCLUDE_I2C)
951 if (mpu_dev->com_driver_type == PIOS_MPU_COM_I2C)
952 return PIOS_MPU_I2C_Write(reg, data);
953 #endif // defined(PIOS_INCLUDE_I2C)
954 #if defined(PIOS_INCLUDE_SPI)
955 if (mpu_dev->com_driver_type == PIOS_MPU_COM_SPI)
956 return PIOS_MPU_SPI_Write(reg, data);
957 #endif // defined(PIOS_INCLUDE_SPI)
962 static int32_t PIOS_MPU_ReadReg(uint8_t reg)
967 #if defined(PIOS_INCLUDE_I2C)
968 if (mpu_dev->com_driver_type == PIOS_MPU_COM_I2C)
969 retval = PIOS_MPU_I2C_Read(reg, &data,
sizeof(data));
970 #endif // defined(PIOS_INCLUDE_I2C)
971 #if defined(PIOS_INCLUDE_SPI)
972 if (mpu_dev->com_driver_type == PIOS_MPU_COM_SPI)
973 retval = PIOS_MPU_SPI_Read(reg, &data);
974 #endif // defined(PIOS_INCLUDE_SPI)
984 if (PIOS_MPU_Validate(mpu_dev) != 0)
989 mpu_dev->interrupt_count++;
1001 static int PIOS_MPU_parse_data(
struct pios_mpu_dev *
p)
1004 IDX_SPI_DUMMY_BYTE = 0,
1019 #ifdef PIOS_INCLUDE_MPU_MAG
1028 #endif // PIOS_INCLUDE_MPU_MAG
1032 uint8_t mpu_rec_buf[BUFFER_SIZE];
1034 #ifdef PIOS_INCLUDE_SPI
1036 #endif // PIOS_INCLUDE_SPI
1038 #ifdef PIOS_INCLUDE_MPU_MAG
1041 uint8_t transfer_size;
1047 if (mpu_dev->use_mag) {
1048 if (mpu_dev->do_full_mag) {
1049 transfer_size = BUFFER_SIZE;
1053 transfer_size = IDX_MAG_ST1 + 1;
1056 transfer_size = IDX_GYRO_ZOUT_L + 1;
1059 uint8_t transfer_size = BUFFER_SIZE;
1060 #endif // PIOS_INCLUDE_MPU_MAG
1062 #if defined(PIOS_INCLUDE_SPI)
1063 if (mpu_dev->com_driver_type == PIOS_MPU_COM_SPI) {
1065 if (PIOS_MPU_ClaimBus(
false) != 0)
1069 PIOS_MPU_ReleaseBus(
false);
1073 PIOS_MPU_ReleaseBus(
false);
1075 #endif // defined(PIOS_INCLUDE_SPI)
1077 #if defined(PIOS_INCLUDE_I2C)
1078 if (mpu_dev->com_driver_type == PIOS_MPU_COM_I2C) {
1083 #endif // defined(PIOS_INCLUDE_I2C)
1085 float accel_x = (int16_t)(mpu_rec_buf[IDX_ACCEL_XOUT_H] << 8 | mpu_rec_buf[IDX_ACCEL_XOUT_L]);
1086 float accel_y = (int16_t)(mpu_rec_buf[IDX_ACCEL_YOUT_H] << 8 | mpu_rec_buf[IDX_ACCEL_YOUT_L]);
1087 float accel_z = (int16_t)(mpu_rec_buf[IDX_ACCEL_ZOUT_H] << 8 | mpu_rec_buf[IDX_ACCEL_ZOUT_L]);
1088 float gyro_x = (int16_t)(mpu_rec_buf[IDX_GYRO_XOUT_H] << 8 | mpu_rec_buf[IDX_GYRO_XOUT_L]);
1089 float gyro_y = (int16_t)(mpu_rec_buf[IDX_GYRO_YOUT_H] << 8 | mpu_rec_buf[IDX_GYRO_YOUT_L]);
1090 float gyro_z = (int16_t)(mpu_rec_buf[IDX_GYRO_ZOUT_H] << 8 | mpu_rec_buf[IDX_GYRO_ZOUT_L]);
1104 #ifdef PIOS_INCLUDE_MPU_MAG
1105 float mag_x = (int16_t)(mpu_rec_buf[IDX_MAG_XOUT_H] << 8 | mpu_rec_buf[IDX_MAG_XOUT_L]);
1106 float mag_y = (int16_t)(mpu_rec_buf[IDX_MAG_YOUT_H] << 8 | mpu_rec_buf[IDX_MAG_YOUT_L]);
1107 float mag_z = (int16_t)(mpu_rec_buf[IDX_MAG_ZOUT_H] << 8 | mpu_rec_buf[IDX_MAG_ZOUT_L]);
1110 #endif // PIOS_INCLUDE_MPU_MAG
1122 switch (mpu_dev->cfg->orientation) {
1124 accel_data->
x = accel_y;
1125 accel_data->
y = accel_x;
1126 accel_data->
z = -accel_z;
1127 gyro_data->
x = gyro_y;
1128 gyro_data->
y = gyro_x;
1129 gyro_data->
z = -gyro_z;
1130 #ifdef PIOS_INCLUDE_MPU_MAG
1131 mag_data->
x = mag_x;
1132 mag_data->
y = mag_y;
1133 mag_data->
z = mag_z;
1134 #endif // PIOS_INCLUDE_MPU_MAG
1137 accel_data->
x = -accel_x;
1138 accel_data->
y = accel_y;
1139 accel_data->
z = -accel_z;
1140 gyro_data->
x = -gyro_x;
1141 gyro_data->
y = gyro_y;
1142 gyro_data->
z = -gyro_z;
1143 #ifdef PIOS_INCLUDE_MPU_MAG
1144 mag_data->
x = -mag_y;
1145 mag_data->
y = mag_x;
1146 mag_data->
z = mag_z;
1147 #endif // PIOS_INCLUDE_MPU_MAG
1150 accel_data->
x = -accel_y;
1151 accel_data->
y = -accel_x;
1152 accel_data->
z = -accel_z;
1153 gyro_data->
x = -gyro_y;
1154 gyro_data->
y = -gyro_x;
1155 gyro_data->
z = -gyro_z;
1156 #ifdef PIOS_INCLUDE_MPU_MAG
1157 mag_data->
x = -mag_x;
1158 mag_data->
y = -mag_y;
1159 mag_data->
z = mag_z;
1160 #endif // PIOS_INCLUDE_MPU_MAG
1163 accel_data->
x = accel_x;
1164 accel_data->
y = -accel_y;
1165 accel_data->
z = -accel_z;
1166 gyro_data->
x = gyro_x;
1167 gyro_data->
y = -gyro_y;
1168 gyro_data->
z = -gyro_z;
1169 #ifdef PIOS_INCLUDE_MPU_MAG
1170 mag_data->
x = mag_y;
1171 mag_data->
y = -mag_x;
1172 mag_data->
z = mag_z;
1173 #endif // PIOS_INCLUDE_MPU_MAG
1176 accel_data->
x = accel_y;
1177 accel_data->
y = -accel_x;
1178 accel_data->
z = accel_z;
1179 gyro_data->
x = gyro_y;
1180 gyro_data->
y = -gyro_x;
1181 gyro_data->
z = gyro_z;
1182 #ifdef PIOS_INCLUDE_MPU_MAG
1183 mag_data->
x = mag_x;
1184 mag_data->
y = -mag_y;
1185 mag_data->
z = -mag_z;
1186 #endif // PIOS_INCLUDE_MPU_MAG
1190 accel_data->
x = accel_x;
1191 accel_data->
y = accel_y;
1192 accel_data->
z = accel_z;
1193 gyro_data->
x = gyro_x;
1194 gyro_data->
y = gyro_y;
1195 gyro_data->
z = gyro_z;
1196 #ifdef PIOS_INCLUDE_MPU_MAG
1197 mag_data->
x = mag_y;
1198 mag_data->
y = mag_x;
1199 mag_data->
z = -mag_z;
1200 #endif // PIOS_INCLUDE_MPU_MAG
1204 accel_data->
x = -accel_y;
1205 accel_data->
y = accel_x;
1206 accel_data->
z = accel_z;
1207 gyro_data->
x = -gyro_y;
1208 gyro_data->
y = gyro_x;
1209 gyro_data->
z = gyro_z;
1210 #ifdef PIOS_INCLUDE_MPU_MAG
1211 mag_data->
x = -mag_x;
1212 mag_data->
y = mag_y;
1213 mag_data->
z = -mag_z;
1214 #endif // PIOS_INCLUDE_MPU_MAG
1218 accel_data->
x = -accel_x;
1219 accel_data->
y = -accel_y;
1220 accel_data->
z = accel_z;
1221 gyro_data->
x = -gyro_x;
1222 gyro_data->
y = -gyro_y;
1223 gyro_data->
z = gyro_z;
1224 #ifdef PIOS_INCLUDE_MPU_MAG
1225 mag_data->
x = -mag_y;
1226 mag_data->
y = -mag_x;
1227 mag_data->
z = -mag_z;
1228 #endif // PIOS_INCLUDE_MPU_MAG
1232 int16_t raw_temp = (int16_t)(mpu_rec_buf[IDX_TEMP_OUT_H] << 8 | mpu_rec_buf[IDX_TEMP_OUT_L]);
1235 temperature = 21.0f + ((float)raw_temp) / 333.87f;
1237 temperature = 35.0f + ((float)raw_temp + 512.0
f) / 340.0f;
1242 mpu_dev->sensor_ready |= SENSOR_ACCEL;
1244 #ifdef PIOS_INCLUDE_MPU_MAG
1245 if (mpu_dev->use_mag) {
1246 if (mpu_dev->do_full_mag) {
1247 mpu_dev->mag_age = 0;
1269 mpu_dev->sensor_ready |= SENSOR_MAG;
1272 mpu_dev->do_full_mag =
false;
1275 if (mpu_dev->mag_age > 3) {
1276 mpu_dev->do_full_mag =
true;
1281 #endif // PIOS_INCLUDE_MPU_MAG
1285 #endif // PIOS_INCLUDE_MPU
int32_t PIOS_MPU_I2C_Init(pios_mpu_dev_t *dev, pios_i2c_t i2c_id, const struct pios_mpu_cfg *cfg)
Initialize the MPU-xxxx 6/9-axis sensor on I2C.
#define PIOS_MPU_AK89XX_ADDR
#define PIOS_MPU_I2CMSTDELAY_ESSHADOW
#define PIOS_MPU_SLV4_DI_REG
#define PIOS_MPU_AK89XX_ST1_DRDY
uint32_t PIOS_DELAY_DiffuS(uint32_t raw)
Subtract raw time from now and convert to us.
int32_t PIOS_MPU_SetSampleRate(uint16_t samplerate_hz)
#define PIOS_MPU_I2C_MST_STATUS_REG
#define PIOS_MPU_USERCTL_I2C_MST_EN
void PIOS_SENSORS_SetMaxGyro(int32_t rate)
Set the maximum gyro rate in deg/s.
Main PiOS header to include all the compiled in PiOS options.
#define PIOS_MPU_I2CMSTDELAY_SLV1EN
int32_t PIOS_SPI_RC_PinSet(pios_spi_t spi_dev, uint32_t slave_id, bool pin_value)
enum pios_mpu_type PIOS_MPU_GetType(void)
Which type of MPU was detected?
int32_t PIOS_EXTI_Init(const struct pios_exti_cfg *cfg)
int32_t PIOS_SPI_ClaimBus(pios_spi_t spi_dev)
#define PIOS_MPU_AK89XX_WHOAMI_REG
#define PIOS_MPU_AK89XX_ST2_HOFL
pios_mpu6500_accel_filter
#define PIOS_MPU_ACCEL_X_OUT_MSB
void * PIOS_malloc(size_t size)
bool PIOS_Semaphore_Give_FromISR(struct pios_semaphore *sema, bool *woken)
#define PIOS_MPU_ACCEL_CFG2_REG
uint16_t default_samplerate
#define PIOS_MPU_SLV0_REG_REG
struct pios_mpu_dev * pios_mpu_dev_t
#define PIOS_MPU_INT_CFG_REG
#define PIOS_MPU_AK8963_CNTL2_REG
#define PIOS_MPU_PWR_MGMT_REG
uint8_t data[XFER_BYTES_PER_PACKET]
void PIOS_EXTI_DeInit(const struct pios_exti_cfg *cfg)
static struct flyingpicmd_cfg_fa cfg
int32_t PIOS_MPU_SPI_Init(pios_mpu_dev_t *dev, pios_spi_t spi_id, uint32_t slave_num, const struct pios_mpu_cfg *cfg)
Initialize the MPU-xxxx 6/9-axis sensor on SPI.
#define PIOS_MPU_AK8963_ST2_BITM
#define PIOS_MPU_SLV0_ADDR_REG
static float gyro_scale[3]
#define PIOS_MPU_INT_EN_REG
int32_t PIOS_MPU_SetAccelRange(enum pios_mpu_accel_range range)
#define PIOS_MPU_INT_CLR_ANYRD
#define PIOS_MPU_SLV4_REG_REG
#define PIOS_MPU_DLPF_CFG_REG
struct pios_semaphore * PIOS_Semaphore_Create(void)
Creates a binary semaphore.
#define PIOS_MPU_SLV4_DO_REG
#define PIOS_MPU_I2C_MST_SLV4_NACK
static float accel_scale[3]
#define PIOS_MPU_AK89XX_WHOAMI_ID
Pios sensor structure for generic accel data.
struct pios_i2c_adapter * pios_i2c_t
#define PIOS_MPU_I2CSLV_EN
uint8_t PIOS_SPI_TransferByte(pios_spi_t spi_dev, uint8_t b)
int32_t PIOS_SPI_SetClockSpeed(pios_spi_t spi_dev, uint32_t speed)
int32_t PIOS_SPI_TransferBlock(pios_spi_t spi_dev, const uint8_t *send_buffer, uint8_t *receive_buffer, uint16_t len)
static float mag_scale[3]
#define PIOS_MPU_USERCTL_DIS_I2C
#define PIOS_MPU_PWRMGMT_PLL_X_CLK
#define PIOS_MPU_SLV0_CTRL_REG
int32_t PIOS_I2C_Transfer(pios_i2c_t i2c_id, const struct pios_i2c_txn txn_list[], uint32_t num_txns)
#define PIOS_MPU_PWRMGMT_IMU_RST
#define PIOS_MPU_SLV4_CTRL_REG
#define PIOS_MPU_SMPLRT_DIV_REG
int32_t PIOS_SENSORS_RegisterCallback(enum pios_sensor_type type, PIOS_SENSOR_Callback_t callback, void *ctx)
Register a callback-based sensor with the PIOS_SENSORS interface.
Pios sensor structure for generic gyro data.
#define PIOS_MPU_AK89XX_ST1_REG
void PIOS_MPU_SetGyroBandwidth(uint16_t bandwidth)
Sets the bandwidth desired from the gyro. The driver will automatically select the lowest bandwidth l...
#define PIOS_MPU_AK8963_CNTL2_SRST
#define PIOS_MPU_GYRO_CFG_REG
#define PIOS_MPU_SLV1_ADDR_REG
void PIOS_free(void *buf)
#define PIOS_MPU_USER_CTRL_REG
Pios sensor structure for generic mag data.
void PIOS_MPU_SetAccelBandwidth(uint16_t bandwidth)
Sets the bandwidth desired from the accelerometer. The driver will automatically select the lowest ba...
#define PIOS_MPU_SLV1_DO_REG
#define PIOS_MPU_ACCEL_CFG_REG
void PIOS_SENSORS_SetSampleRate(enum pios_sensor_type type, uint32_t sample_rate)
Set the sample rate of a sensor (Hz)
bool PIOS_Semaphore_Take(struct pios_semaphore *sema, uint32_t timeout_ms)
Takes binary semaphore.
#define PIOS_MPU_SLV1_CTRL_REG
Includes PiOS and core architecture components.
bool PIOS_MPU_IRQHandler(void)
The IMU interrupt handler. Fetches new data from the IMU.
#define PIOS_MPU_AK8975_ST2_DERR
#define PIOS_MPU_SLV4_ADDR_REG
int32_t PIOS_SPI_ReleaseBus(pios_spi_t spi_dev)
#define PIOS_MPU_AK8963_MODE_CONTINUOUS_FAST_16B
#define PIOS_MPU_I2C_MST_DELAY_CTRL
#define PIOS_MPU_INTEN_DATA_RDY
#define PIOS_MPU_AK8975_MODE_SINGLE_12B
#define PIOS_MPU_AK89XX_CNTL1_REG
#define PIOS_MPU_SLV1_REG_REG
#define PIOS_Assert(test)
#define PIOS_MPU_I2C_MST_SLV4_DONE
int32_t PIOS_DELAY_WaitmS(uint32_t mS)
int32_t PIOS_MPU_SetGyroRange(enum pios_mpu_gyro_range range)
uint32_t PIOS_DELAY_GetRaw()
Get the raw delay timer, useful for timing.