Store the configuration on the SD card
This commit is contained in:
25
mpu6050.c
25
mpu6050.c
@@ -14,6 +14,7 @@
|
||||
#include "timer.h"
|
||||
#include "panic.h"
|
||||
#include "log.h"
|
||||
#include "config.h"
|
||||
|
||||
i2c_result mpu6050_result;
|
||||
unsigned int mpu6050_generation;
|
||||
@@ -51,12 +52,13 @@ struct i2c_transaction mpu6050_whoami_transaction2 = {
|
||||
NULL
|
||||
};
|
||||
|
||||
/* Accelerometer scaling */
|
||||
#define AFS_SEL 2
|
||||
#define FS_SEL config.mpu6050.gyro_sensitivity
|
||||
#define AFS_SEL config.mpu6050.accel_sensitivity
|
||||
|
||||
|
||||
unsigned char mpu6050_init_command[] = {0x6B, 0x01};
|
||||
unsigned char mpu6050_accel_init_command[] = {0x1c, (AFS_SEL<<3)};
|
||||
unsigned char mpu6050_gyro_init_command[] = {0x1b, 0 /* (FS_SEL<<3) to be filled in at runtime */};
|
||||
unsigned char mpu6050_accel_init_command[] = {0x1c, 0 /* (AFS_SEL<<3) to be filled in at runtime */};
|
||||
unsigned char mpu6050_bypass_init_command[] = {0x37, 0x02};
|
||||
|
||||
struct i2c_transaction mpu6050_bypass_init_transaction = {
|
||||
@@ -77,13 +79,22 @@ struct i2c_transaction mpu6050_accel_init_transaction = {
|
||||
&mpu6050_bypass_init_transaction
|
||||
};
|
||||
|
||||
struct i2c_transaction mpu6050_gyro_init_transaction = {
|
||||
(0x68 << 1) + 0, /* write */
|
||||
2,
|
||||
mpu6050_gyro_init_command,
|
||||
&mpu6050_result,
|
||||
EVENT_MPU6050_I2C_COMPLETE,
|
||||
&mpu6050_accel_init_transaction
|
||||
};
|
||||
|
||||
struct i2c_transaction mpu6050_init_transaction = {
|
||||
(0x68 << 1) + 0, /* write */
|
||||
2,
|
||||
mpu6050_init_command,
|
||||
&mpu6050_result,
|
||||
EVENT_MPU6050_I2C_COMPLETE,
|
||||
&mpu6050_accel_init_transaction
|
||||
&mpu6050_gyro_init_transaction
|
||||
};
|
||||
|
||||
unsigned char mpu6050_sample_command[] = {0x3B};
|
||||
@@ -114,6 +125,10 @@ bool mpu6050_init(void)
|
||||
{
|
||||
event_register(EVENT_MPU6050_I2C_COMPLETE, mpu6050_event_handler);
|
||||
|
||||
/* Fill in sensitivity accordingly, as it's not known at compile time */
|
||||
mpu6050_gyro_init_command[1] = FS_SEL << 3;
|
||||
mpu6050_accel_init_command[1] = AFS_SEL << 3;
|
||||
|
||||
if (!i2c_start_transaction(&mpu6050_init_transaction))
|
||||
return FALSE;
|
||||
while (i2c_busy()) ;
|
||||
@@ -133,7 +148,7 @@ bool mpu6050_init(void)
|
||||
|
||||
/* A step of 131 = 1 degree. */
|
||||
/* Overall, this is LSB / rad/s */
|
||||
#define GYRO_STEP (131.0 / DEG_TO_RAD)
|
||||
#define GYRO_STEP (131.0 / DEG_TO_RAD / (float)(1<<FS_SEL))
|
||||
|
||||
/* LSB / degree C */
|
||||
#define TEMP_STEP 340.0
|
||||
|
||||
Reference in New Issue
Block a user