~aleteoryx/muditaos

7ad067d41bc061bbd25d0246b03265e316d09cfc — Maciej Gibowicz 4 years ago e747fb1
[EGD-8141] Fix brownout handling while charging

When the voltage dropped below the brownout threshold,
the system did not detect the battery charging
and displayed a window with the low battery icon all the time.
M module-bsp/board/rt1051/puretx/hal/battery_charger/BatteryCharger.cpp => module-bsp/board/rt1051/puretx/hal/battery_charger/BatteryCharger.cpp +26 -3
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "BatteryCharger.hpp"


@@ 6,10 6,25 @@
#include <bsp/battery_charger/battery_charger.hpp>
#include <hal/GenericFactory.hpp>

namespace
{
    constexpr uint16_t clearStatusTickTime_MS = 10000;

    void clearIrqStatusHandler(TimerHandle_t xTimer)
    {
        if (bsp::battery_charger::getStatusRegister()) {
            bsp::battery_charger::clearFuelGuageIRQ(
                static_cast<std::uint16_t>(bsp::battery_charger::batteryINTBSource::all));
        }
    }
} // namespace

namespace hal::battery
{
    BatteryCharger::BatteryCharger(AbstractBatteryCharger::BatteryChargerEvents &eventsHandler)
        : eventsHandler(eventsHandler)
        : eventsHandler(eventsHandler),
          timerHandle{xTimerCreate(
              "clearIrqStatusTimer", pdMS_TO_TICKS(clearStatusTickTime_MS), false, nullptr, clearIrqStatusHandler)}
    {}

    void BatteryCharger::init(xQueueHandle queueBatteryHandle, xQueueHandle queueChargerDetect)


@@ 73,7 88,15 @@ namespace hal::battery
                bsp::battery_charger::clearFuelGuageIRQ(
                    static_cast<std::uint16_t>(bsp::battery_charger::batteryINTBSource::minVAlert));

                eventsHandler.onBrownout();
                if (bsp::battery_charger::getChargeStatus()) {
                    if (xTimerIsTimerActive(timerHandle) == pdFALSE) {
                        xTimerStart(timerHandle, 0);
                        LOG_DEBUG("Battery Brownout detected while charging");
                    }
                }
                else {
                    eventsHandler.onBrownout();
                }
            }
            if (status & static_cast<std::uint16_t>(bsp::battery_charger::batteryINTBSource::SOCOnePercentChange)) {
                bsp::battery_charger::printFuelGaugeInfo();

M module-bsp/board/rt1051/puretx/hal/battery_charger/BatteryCharger.hpp => module-bsp/board/rt1051/puretx/hal/battery_charger/BatteryCharger.hpp +3 -1
@@ 1,9 1,10 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <hal/battery_charger/AbstractBatteryCharger.hpp>
#include <timers.h>

namespace hal::battery
{


@@ 21,6 22,7 @@ namespace hal::battery
        void checkBatteryChargerInterrupts();

        AbstractBatteryCharger::BatteryChargerEvents &eventsHandler;
        TimerHandle_t timerHandle;
    };

    BaseType_t INTBHandlerIRQ();