altos: Allow BMX160 to be used as primary accel
authorKeith Packard <keithp@keithp.com>
Thu, 28 May 2020 23:02:54 +0000 (16:02 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 28 May 2020 23:02:54 +0000 (16:02 -0700)
EasyTimer doesn't have a high-g part.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_bmx160.h
src/kernel/ao_data.h

index 9fc3334177b1208ad82f9e256f801fdf87177b32..c5bf0aff634fcd2ccf9453ba0757448517b81f21 100644 (file)
@@ -306,4 +306,6 @@ ao_bmx160_accel(int16_t sensor) {
        return (float) sensor * ((float) (BMX160_ACCEL_FULLSCALE * GRAVITY / 32767.0));
 }
 
+#define ao_bmx_accel_to_sample(accel) ((accel_t) (accel) * (32767.0f / (BMX160_ACCEL_FULLSCALE * GRAVITY)))
+
 #endif /* _BMX160_H_ */
index 988ac4897ecafbb8798ce1e1b5ceb2bf09368144..a22eee87cfe394bb2b879878328b63d282c475ae 100644 (file)
@@ -114,6 +114,9 @@ struct ao_data {
 #endif
 #if HAS_MPU9250
        struct ao_mpu9250_sample        mpu9250;
+#if !HAS_MMA655X
+       int16_t                         z_accel;
+#endif
 #endif
 #if HAS_HMC5883
        struct ao_hmc5883_sample        hmc5883;
@@ -132,6 +135,9 @@ struct ao_data {
 #endif
 #if HAS_BMX160
        struct ao_bmx160_sample         bmx160;
+#if !HAS_ADXL375
+       int16_t z_accel;
+#endif
 #endif
 };
 
@@ -188,20 +194,6 @@ typedef AO_ALT_TYPE        alt_t;
 
 #endif
 
-#if !HAS_BARO && HAS_ADC
-
-#define HAS_BARO       1
-
-typedef int16_t pres_t;
-typedef int16_t alt_t;
-
-#define ao_data_pres(packet)   ((packet)->adc.pres)
-#define ao_data_temp(packet)   ((packet)->adc.temp)
-#define pres_to_altitude(p)    ao_pres_to_altitude(p)
-#define ao_data_pres_cook(p)
-
-#endif
-
 /*
  * Need a few macros to pull data from the sensors:
  *
@@ -408,6 +400,20 @@ static inline float ao_convert_accel(int16_t sensor)
 
 #endif
 
+#if !HAS_ACCEL && HAS_MPU9250
+
+#define HAS_ACCEL      1
+
+typedef int16_t accel_t;
+
+/* MPU9250 is hooked up so that positive y is positive acceleration */
+#define ao_data_accel(packet)                  ((packet)->z_accel)
+#define ao_data_accel_cook(packet)             (-(packet)->mpu9250.accel_y)
+#define ao_data_set_accel(packet, accel)       ((packet)->z_accel = (accel))
+#define ao_data_accel_invert(a)                        (-(a))
+
+#endif
+
 #if !HAS_GYRO && HAS_MPU9250
 
 #define HAS_GYRO       1
@@ -441,6 +447,20 @@ static inline float ao_convert_accel(int16_t sensor)
 
 #endif
 
+#if !HAS_ACCEL && HAS_BMX160
+
+#define HAS_ACCEL      1
+
+typedef int16_t accel_t;
+
+#define ao_data_accel(packet)                  ((packet)->z_accel)
+#define ao_data_set_accel(packet, accel)       ((packet)->z_accel = (accel))
+#define ao_data_accel_invert(a)                        (-(a))
+
+#define ao_data_accel_to_sample(accel)         ao_bmx_accel_to_sample(accel)
+
+#endif
+
 #if !HAS_GYRO && HAS_BMX160
 
 #define HAS_GYRO       1