From 2273e83c3ce43a4c9b69ec9231a4cd1a9e598c18 Mon Sep 17 00:00:00 2001
From: Federico Mandelli <federico.mandelli@skywarder.eu>
Date: Thu, 18 Jul 2024 13:34:15 +0200
Subject: [PATCH] [Sensors] changed bmx to not use fifo

---
 src/boards/Parafoil/Configs/SensorsConfig.h |  8 ++++----
 src/boards/Parafoil/Sensors/Sensors.cpp     | 14 +++++++-------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/boards/Parafoil/Configs/SensorsConfig.h b/src/boards/Parafoil/Configs/SensorsConfig.h
index fbc26d236..105e3aef6 100644
--- a/src/boards/Parafoil/Configs/SensorsConfig.h
+++ b/src/boards/Parafoil/Configs/SensorsConfig.h
@@ -45,10 +45,10 @@ constexpr Boardcore::BMX160Config::GyroscopeRange BMX160_GYRO_FSR_ENUM =
     Boardcore::BMX160Config::GyroscopeRange::DEG_1000;
 constexpr unsigned int BMX160_ACC_GYRO_ODR = 400;
 constexpr Boardcore::BMX160Config::OutputDataRate BMX160_ACC_GYRO_ODR_ENUM =
-    Boardcore::BMX160Config::OutputDataRate::HZ_400;
+    Boardcore::BMX160Config::OutputDataRate::HZ_200;
 constexpr unsigned int BMX160_MAG_ODR = 100;
 constexpr Boardcore::BMX160Config::OutputDataRate BMX160_MAG_ODR_ENUM =
-    Boardcore::BMX160Config::OutputDataRate::HZ_100;
+    Boardcore::BMX160Config::OutputDataRate::HZ_200;
 
 constexpr unsigned int BMX160_TEMP_DIVIDER = 1000;
 
@@ -117,8 +117,8 @@ constexpr float BATTERY_VOLTAGE_COEFF = (150 + 40.2) / 40.2;
 // BMX160_SAMPLE_PERIOD: Sample before the fifo is full, but slightly after the
 // watermark level (watermark + 30) ---> high slack due to scheduler
 // imprecision, avoid clearing the fifo before the interrupt
-constexpr unsigned int BMX160_SAMPLE_PERIOD =
-    BMX160_FIFO_FILL_TIME * (BMX160_FIFO_WATERMARK + 30) * 4 / 1024;  // [ms]
+constexpr unsigned int BMX160_SAMPLE_PERIOD = 10;
+// BMX160_FIFO_FILL_TIME * (BMX160_FIFO_WATERMARK + 30) * 4 / 1024;  // [ms]
 // BMX160_WITH_CORRECTION_SAMPLE_PERIOD should be lower than the
 // BMX160_SAMPLE_PERIOD and faster then the NAS update period.
 constexpr unsigned int BMX160_WITH_CORRECTION_SAMPLE_PERIOD = 10;  // [ms] 100Hz
diff --git a/src/boards/Parafoil/Sensors/Sensors.cpp b/src/boards/Parafoil/Sensors/Sensors.cpp
index a6a3b393b..a9d3e9b7c 100644
--- a/src/boards/Parafoil/Sensors/Sensors.cpp
+++ b/src/boards/Parafoil/Sensors/Sensors.cpp
@@ -1,5 +1,5 @@
 /* Copyright (c) 2024 Skyward Experimental Rocketry
- * Author: Matteo Pignataro, Angelo Prete
+ * Authors: Matteo Pignataro, Angelo Prete
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -166,10 +166,10 @@ bool Sensors::start()
         MAG_CALIBRATION_PERIOD);
 
     // Create sensor manager with populated map and configured scheduler
-    manager                      = new SensorManager(sensorMap, scheduler);
-    miosix::GpioPin interruptPin = miosix::sensors::bmx160::intr::getPin();
-    enableExternalInterrupt(interruptPin.getPort(), interruptPin.getNumber(),
-                            InterruptTrigger::FALLING_EDGE, 0);
+    manager = new SensorManager(sensorMap, scheduler);
+    // miosix::GpioPin interruptPin = miosix::sensors::bmx160::intr::getPin();
+    // enableExternalInterrupt(interruptPin.getPort(), interruptPin.getNumber(),
+    //                         InterruptTrigger::FALLING_EDGE, 0);
     return manager->start() && result != 0;
 }
 
@@ -207,10 +207,10 @@ void Sensors::bmx160Init()
     ModuleManager& modules = ModuleManager::getInstance();
 
     SPIBusConfig spiConfig;
-    spiConfig.clockDivider = SPI::ClockDivider::DIV_8;
+    spiConfig.clockDivider = SPI::ClockDivider::DIV_4;
 
     BMX160Config config;
-    config.fifoMode      = BMX160Config::FifoMode::HEADER;
+    config.fifoMode      = BMX160Config::FifoMode::DISABLED;
     config.fifoWatermark = BMX160_FIFO_WATERMARK;
     config.fifoInterrupt = BMX160Config::FifoInterruptPin::PIN_INT1;
 
-- 
GitLab