From e1c9da85b9d72819dc23c82c95167437413bfebf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 29 Oct 2021 09:21:31 +1100 Subject: [PATCH] AP_BoardConfig: allow for heater polarity setting on FMU --- libraries/AP_BoardConfig/IMU_heater.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/AP_BoardConfig/IMU_heater.cpp b/libraries/AP_BoardConfig/IMU_heater.cpp index 5df93ad883..541e006232 100644 --- a/libraries/AP_BoardConfig/IMU_heater.cpp +++ b/libraries/AP_BoardConfig/IMU_heater.cpp @@ -27,6 +27,10 @@ extern const AP_HAL::HAL& hal; +#ifndef HAL_HEATER_GPIO_ON +#define HAL_HEATER_GPIO_ON 1 +#endif + void AP_BoardConfig::set_imu_temp(float current) { int8_t target = heater.imu_target_temperature.get(); @@ -37,7 +41,7 @@ void AP_BoardConfig::set_imu_temp(float current) if (target == -1) { // nothing to do, make sure heater is left off #if defined(HAL_HEATER_GPIO_PIN) - hal.gpio->write(HAL_HEATER_GPIO_PIN, false); + hal.gpio->write(HAL_HEATER_GPIO_PIN, !HAL_HEATER_GPIO_ON); #endif return; } @@ -57,7 +61,7 @@ void AP_BoardConfig::set_imu_temp(float current) // output as duty cycle to local pin. Use a random sequence to // prevent a periodic change to magnetic field bool heater_on = (get_random16() < uint32_t(heater.output) * 0xFFFFU / 100U); - hal.gpio->write(HAL_HEATER_GPIO_PIN, heater_on); + hal.gpio->write(HAL_HEATER_GPIO_PIN, heater_on?HAL_HEATER_GPIO_ON : !HAL_HEATER_GPIO_ON); #endif return; }