From 14f78ffc0757589530c7cf95132e0b40246ed2f1 Mon Sep 17 00:00:00 2001 From: Mateusz Piesta Date: Thu, 11 Aug 2022 13:30:24 +0200 Subject: [PATCH] [BH-1552] Harmony crashes during startup Fixed crashing device. Bell temperature sensor refactor. --- module-bsp/CMakeLists.txt | 1 + module-bsp/board/linux/CMakeLists.txt | 1 - .../bell_temp_sensor/bell_temp_sensor.cpp | 46 ------ module-bsp/board/rt1051/bellpx/CMakeLists.txt | 1 - .../bellpx/bsp/bell_temp_sensor/CT7117.hpp | 39 ----- .../bsp/bell_temp_sensor/bell_temp_sensor.cpp | 144 ----------------- .../hal/battery_charger/BatteryCharger.cpp | 7 +- .../temperature_source/TemperatureSource.cpp | 62 ++++++-- .../bsp/bell_temp_sensor/bell_temp_sensor.hpp | 31 ---- module-bsp/devices/power/CW2015.cpp | 25 +-- module-bsp/devices/temperature/CT7117.cpp | 150 ++++++++++++++++++ module-bsp/devices/temperature/CT7117.hpp | 37 +++++ module-bsp/drivers/i2c/DriverI2C.hpp | 1 - module-utils/utility/Units.hpp | 5 +- 14 files changed, 260 insertions(+), 290 deletions(-) delete mode 100644 module-bsp/board/linux/bell_temp_sensor/bell_temp_sensor.cpp delete mode 100644 module-bsp/board/rt1051/bellpx/bsp/bell_temp_sensor/CT7117.hpp delete mode 100644 module-bsp/board/rt1051/bellpx/bsp/bell_temp_sensor/bell_temp_sensor.cpp delete mode 100644 module-bsp/bsp/bell_temp_sensor/bell_temp_sensor.hpp create mode 100644 module-bsp/devices/temperature/CT7117.cpp create mode 100644 module-bsp/devices/temperature/CT7117.hpp diff --git a/module-bsp/CMakeLists.txt b/module-bsp/CMakeLists.txt index 3dacf5c5ec026f7b85591162f5534c150155f94c..586dcbc231115b6a1ac9c6b8b705d72ae9622c5f 100644 --- a/module-bsp/CMakeLists.txt +++ b/module-bsp/CMakeLists.txt @@ -15,6 +15,7 @@ target_sources( devices/Device.cpp devices/power/CW2015.cpp devices/power/MP2639B.cpp + devices/temperature/CT7117.cpp drivers/dma/DriverDMA.cpp drivers/dmamux/DriverDMAMux.cpp drivers/gpio/DriverGPIO.cpp diff --git a/module-bsp/board/linux/CMakeLists.txt b/module-bsp/board/linux/CMakeLists.txt index 168c035eacd34dc772f15b698f50271621a58048..60b70488aba3f20357e29febcd73ba8b64d9b498 100644 --- a/module-bsp/board/linux/CMakeLists.txt +++ b/module-bsp/board/linux/CMakeLists.txt @@ -27,7 +27,6 @@ target_sources(module-bsp hal/temperature_source/TemperatureSource.cpp hal/battery_charger/BatteryCharger.cpp hal/key_input/KeyInput.cpp - bell_temp_sensor/bell_temp_sensor.cpp ${CMAKE_CURRENT_BINARY_DIR}/eink-config.h ) diff --git a/module-bsp/board/linux/bell_temp_sensor/bell_temp_sensor.cpp b/module-bsp/board/linux/bell_temp_sensor/bell_temp_sensor.cpp deleted file mode 100644 index 234d3e181a771fb40973f806b605ebca4c91f76d..0000000000000000000000000000000000000000 --- a/module-bsp/board/linux/bell_temp_sensor/bell_temp_sensor.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include "bsp/bell_temp_sensor/bell_temp_sensor.hpp" -#include - -namespace bsp::bell_temp_sensor -{ - bool isFahrenheit = false; - constexpr auto celsius_temperature_mock = 21.0; - constexpr auto fahrenheit_temperature_mock = (celsius_temperature_mock * 1.8) + 32; - - std::int32_t init(bool Fahrenheit) - { - isFahrenheit = Fahrenheit; - - return 0; - } - - void deinit() - {} - - bool standby() - { - return true; - } - - bool wakeup() - { - return true; - } - - Temperature readout() - { - if (isFahrenheit) - return fahrenheit_temperature_mock; - else - return celsius_temperature_mock; - } - - bool isPresent() - { - return true; - } - -} // namespace bsp::bell_temp_sensor diff --git a/module-bsp/board/rt1051/bellpx/CMakeLists.txt b/module-bsp/board/rt1051/bellpx/CMakeLists.txt index 4e004a9e7564d75e8f675ea449607d6a304152e1..d0e294285d242d1c189495de12bf377b1bde23b2 100644 --- a/module-bsp/board/rt1051/bellpx/CMakeLists.txt +++ b/module-bsp/board/rt1051/bellpx/CMakeLists.txt @@ -17,7 +17,6 @@ target_sources( bsp/audio/AW8898driver.cpp bsp/audio/CodecAW8898.cpp - bsp/bell_temp_sensor/bell_temp_sensor.cpp bsp/eink/eink_pin_config.cpp bsp/lpm/PowerProfile.cpp bsp/lpm/RT1051LPM.cpp diff --git a/module-bsp/board/rt1051/bellpx/bsp/bell_temp_sensor/CT7117.hpp b/module-bsp/board/rt1051/bellpx/bsp/bell_temp_sensor/CT7117.hpp deleted file mode 100644 index 5d5c41b5928b4bfb827d34a914405b5c5236b7f2..0000000000000000000000000000000000000000 --- a/module-bsp/board/rt1051/bellpx/bsp/bell_temp_sensor/CT7117.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once - -#include - -namespace bsp::bell_temp_sensor -{ - constexpr inline auto CT7117_DEVICE_ADDR = (0x90 >> 1); - constexpr inline auto CT7117_DEVICE_ID = 0x59; - - enum class CT7117_Registers - { - Temp = 0x00, - Config = 0x01, - Low_Temp_Set = 0x02, - High_Temp_Set = 0x03, - ID = 0x07 - }; - - enum class CT7117_Config_Reg - { - OTS = (1 << 15), - F1 = (1 << 12), - F0 = (1 << 11), - ALTM = (1 << 9), - SD = (1 << 8), - EM = (1 << 7), - RES1 = (1 << 6), - RES0 = (1 << 5), - TO = (1 << 4), - PEC = (1 << 3), - CR1 = (1 << 2), - CR0 = (1 << 1), - OS = (1 << 0) - }; - -} // namespace bsp::bell_temp_sensor diff --git a/module-bsp/board/rt1051/bellpx/bsp/bell_temp_sensor/bell_temp_sensor.cpp b/module-bsp/board/rt1051/bellpx/bsp/bell_temp_sensor/bell_temp_sensor.cpp deleted file mode 100644 index b539b09cff85881b69c9ca288372323486618dca..0000000000000000000000000000000000000000 --- a/module-bsp/board/rt1051/bellpx/bsp/bell_temp_sensor/bell_temp_sensor.cpp +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include "bsp/bell_temp_sensor/bell_temp_sensor.hpp" -#include "CT7117.hpp" -#include -#include -#include - -#include "fsl_common.h" -#include - -namespace bsp::bell_temp_sensor -{ - using namespace drivers; - - bool isFahrenheit = false; - - namespace - { - std::shared_ptr i2c; - bool isInitiated = false; - - drivers::I2CAddress addr = { - .deviceAddress = static_cast(CT7117_DEVICE_ADDR), .subAddress = 0, .subAddressSize = 1}; - - bool writeSingleRegister(std::uint32_t address, std::uint16_t *to_send) - { - addr.subAddress = address; - const auto write_success = i2c->Write(addr, reinterpret_cast(to_send), 2); - - return write_success == 1; - } - - ssize_t readSingleRegister(std::uint32_t address, std::uint16_t *readout) - { - addr.subAddress = address; - return i2c->Read(addr, reinterpret_cast(readout), 2); - } - - ssize_t readMeasurementRegisters(std::uint16_t *readout) - { - addr.subAddress = static_cast(CT7117_Registers::Temp); - return i2c->Read(addr, reinterpret_cast(readout), 2); - } - - auto gpio_pwren = DriverGPIO::Create(static_cast(BoardDefinitions::BELL_TEMP_SENSOR_PWR_GPIO), - DriverGPIOParams{}); - - } // namespace - - std::int32_t init(bool Fahrenheit) - { - isFahrenheit = Fahrenheit; - - LOG_DEBUG("Initializing Bell temperature sensor"); - - gpio_pwren->ConfPin( - DriverGPIOPinParams{.dir = DriverGPIOPinParams::Direction::Output, - .irqMode = DriverGPIOPinParams::InterruptMode::NoIntmode, - .defLogic = 1, - .pin = static_cast(BoardDefinitions::BELL_TEMP_SENSOR_PWR_PIN)}); - gpio_pwren->WritePin(static_cast(BoardDefinitions::BELL_TEMP_SENSOR_PWR_PIN), 1); // enable power - - if (isInitiated) { - return isPresent() ? kStatus_Success : kStatus_Fail; - } - - drivers::DriverI2CParams i2cParams; - i2cParams.baudrate = static_cast(BoardDefinitions::BELL_TEMP_SENSOR_I2C_BAUDRATE); - i2c = drivers::DriverI2C::Create(static_cast(BoardDefinitions::BELL_TEMP_SENSOR_I2C), - i2cParams); - - wakeup(); - - isInitiated = true; - - return isPresent() ? kStatus_Success : kStatus_Fail; - } - - void deinit() - { - standby(); - - gpio_pwren->WritePin(static_cast(BoardDefinitions::BELL_TEMP_SENSOR_PWR_PIN), 0); // disable power - } - - bool standby() - { - uint16_t reg = 0; - readSingleRegister(static_cast(CT7117_Registers::Config), ®); - reg |= static_cast(CT7117_Config_Reg::SD); - return writeSingleRegister(static_cast(CT7117_Registers::Config), ®); - } - - bool wakeup() - { - uint16_t reg = 0; - readSingleRegister(static_cast(CT7117_Registers::Config), ®); - reg &= ~(static_cast(CT7117_Config_Reg::SD)); - return writeSingleRegister(static_cast(CT7117_Registers::Config), ®); - } - - Temperature readout() - { - uint8_t reg[2] = {0, 0}; - float temp = 0.0; - - readSingleRegister(static_cast(CT7117_Registers::Temp), reinterpret_cast(®[0])); - uint16_t reg16 = - (static_cast(reg[0]) << 8) | (static_cast(reg[1]) & 0xFFE0); // 0.25 C resolution - - uint16_t integer = 0; - uint16_t fractional = 0; - - if (reg16 & 0x8000) { // sign bit present - integer = static_cast(((~reg16 + 1) & 0x7FFF) >> 7); // remove sign bit and shift to lower byte - fractional = static_cast(((~reg16 + 1) & 0x7F) * 0.78125); - temp = -1 * (static_cast(integer) + (static_cast(fractional) / 100.0)); - } - else { - integer = static_cast((reg16 & 0x7FFF) >> 7); // remove sign bit and shift to lower byte - fractional = static_cast((reg16 & 0x7F) * 0.78125); - temp = static_cast(integer) + (static_cast(fractional) / 100.0); - } - - if (isFahrenheit) - temp = (temp * 1.8) + 32.00; - - return temp; - } - - bool isPresent() - { - std::uint8_t readout; - addr.subAddress = static_cast(CT7117_Registers::ID); - i2c->Read(addr, reinterpret_cast(&readout), 1); - - LOG_DEBUG("Bell temperature sensor %s", (readout == CT7117_DEVICE_ID) ? "present" : "error !"); - - return readout == CT7117_DEVICE_ID; - } - -} // namespace bsp::bell_temp_sensor diff --git a/module-bsp/board/rt1051/bellpx/hal/battery_charger/BatteryCharger.cpp b/module-bsp/board/rt1051/bellpx/hal/battery_charger/BatteryCharger.cpp index 4b748851d98a7a8e382801d0331eb9f470a69375..b6793c94fe59645523892d5554b8c269be06e900 100644 --- a/module-bsp/board/rt1051/bellpx/hal/battery_charger/BatteryCharger.cpp +++ b/module-bsp/board/rt1051/bellpx/hal/battery_charger/BatteryCharger.cpp @@ -71,6 +71,7 @@ namespace hal::battery xQueueHandle notification_channel; inline static std::unique_ptr worker_queue; + std::shared_ptr i2c; std::shared_ptr charger_gpio_chgok; std::shared_ptr charger_gpio; mutable bsp::devices::power::MP2639B charger; @@ -80,8 +81,8 @@ namespace hal::battery }; BellBatteryCharger::BellBatteryCharger(xQueueHandle irqQueueHandle) - : notification_channel{irqQueueHandle}, charger_gpio_chgok{drivers::DriverGPIO::Create(charger_irq_gpio_chgok, - {})}, + : notification_channel{irqQueueHandle}, i2c{drivers::DriverI2C::Create(i2c_instance, i2c_params)}, + charger_gpio_chgok{drivers::DriverGPIO::Create(charger_irq_gpio_chgok, {})}, charger_gpio{drivers::DriverGPIO::Create(charger_irq_gpio, {})}, charger{MP2639B::Configuration{ charger_gpio, charger_irq_pin_mode, @@ -103,7 +104,7 @@ namespace hal::battery }}}, fuel_gauge_gpio{drivers::DriverGPIO::Create(fuel_gauge_irq_gpio_instance, {})}, - fuel_gauge{CW2015{*drivers::DriverI2C::Create(i2c_instance, i2c_params), battery_shutdown_threshold}} + fuel_gauge{CW2015{*i2c, battery_shutdown_threshold}} { reinit_timer = xTimerCreate("reinit_timer", reinit_poll_time, pdFALSE, this, [](TimerHandle_t xTimer) { diff --git a/module-bsp/board/rt1051/bellpx/hal/temperature_source/TemperatureSource.cpp b/module-bsp/board/rt1051/bellpx/hal/temperature_source/TemperatureSource.cpp index d2923ba48b3287da97cb58844e5fdfe9126b55a3..22321316e65227a965b75ff439775044aaca08f4 100644 --- a/module-bsp/board/rt1051/bellpx/hal/temperature_source/TemperatureSource.cpp +++ b/module-bsp/board/rt1051/bellpx/hal/temperature_source/TemperatureSource.cpp @@ -1,27 +1,69 @@ -// 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 -#include -#include "bsp/bell_temp_sensor/bell_temp_sensor.hpp" +#include "hal/temperature_source/TemperatureSource.hpp" +#include "hal/GenericFactory.hpp" +#include "devices/temperature/CT7117.hpp" +#include "drivers/gpio/DriverGPIO.hpp" +#include "board/BoardDefinitions.hpp" + +#include namespace hal::temperature { - class BellTemperatureSource : public AbstractTemperatureSource + using namespace drivers; + + class PowerEnable { public: - BellTemperatureSource() + PowerEnable() + { + power_pin = DriverGPIO::Create(static_cast(BoardDefinitions::BELL_TEMP_SENSOR_PWR_GPIO), + DriverGPIOParams{}); + + power_pin->ConfPin( + DriverGPIOPinParams{.dir = DriverGPIOPinParams::Direction::Output, + .irqMode = DriverGPIOPinParams::InterruptMode::NoIntmode, + .defLogic = 1, + .pin = static_cast(BoardDefinitions::BELL_TEMP_SENSOR_PWR_PIN)}); + + power_pin->WritePin(static_cast(BoardDefinitions::BELL_TEMP_SENSOR_PWR_PIN), 1); + } + ~PowerEnable() { - bsp::bell_temp_sensor::init(); + power_pin->WritePin(static_cast(BoardDefinitions::BELL_TEMP_SENSOR_PWR_PIN), 0); } - ~BellTemperatureSource() + + private: + std::shared_ptr power_pin; + }; + + class BellTemperatureSource : public AbstractTemperatureSource + { + public: + BellTemperatureSource() + : i2c{drivers::DriverI2C::Create( + static_cast(BoardDefinitions::BELL_TEMP_SENSOR_I2C), + {static_cast(BoardDefinitions::BELL_TEMP_SENSOR_I2C_BAUDRATE)})}, + ct7117{ct7117_id, *i2c} { - bsp::bell_temp_sensor::deinit(); + if (not ct7117.poll()) { + throw std::runtime_error("CT7117 chip not present"); + } + if (not ct7117.wakeup()) { + throw std::runtime_error("Waking up CT7117 failed"); + } } Result read() { - return bsp::bell_temp_sensor::readout(); + return ct7117.get_temperature(); } + + private: + static constexpr auto ct7117_id = (0x90 >> 1); + PowerEnable power_enable; + std::shared_ptr i2c; + bsp::devices::temperature::CT7117::CT7117 ct7117; }; std::shared_ptr AbstractTemperatureSource::Factory::create() diff --git a/module-bsp/bsp/bell_temp_sensor/bell_temp_sensor.hpp b/module-bsp/bsp/bell_temp_sensor/bell_temp_sensor.hpp deleted file mode 100644 index 77ff7428d02f6acc7d9cd2a5e568c3a7b389a4ea..0000000000000000000000000000000000000000 --- a/module-bsp/bsp/bell_temp_sensor/bell_temp_sensor.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once - -#include - -extern "C" -{ -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -} - -namespace bsp::bell_temp_sensor -{ - using Temperature = float; - - std::int32_t init(bool Fahrenheit = false); - - void deinit(); - - bool standby(); - - bool wakeup(); - - bool isPresent(); - - Temperature readout(); - -} // namespace bsp::bell_temp_sensor diff --git a/module-bsp/devices/power/CW2015.cpp b/module-bsp/devices/power/CW2015.cpp index fb94c718fc36a7e96a9681eaf8d60cce1df8afb0..74f068b63cb738be936941def1dc7b25ac496264 100644 --- a/module-bsp/devices/power/CW2015.cpp +++ b/module-bsp/devices/power/CW2015.cpp @@ -277,18 +277,19 @@ namespace bsp::devices::power BATTINFO profile{}; RetCodes ret_code{RetCodes::Ok}; - std::all_of(profile.cbegin(), profile.cend(), [this, ret_code, reg = BATTINFO::ADDRESS](const auto &e) mutable { - const auto result = read(reg++); - if (not result) { - ret_code = RetCodes::CommunicationError; - return false; - } - if (*result != e) { - ret_code = RetCodes::ProfileInvalid; - return false; - } - return true; - }); + std::all_of( + profile.cbegin(), profile.cend(), [this, &ret_code, reg = BATTINFO::ADDRESS](const auto &e) mutable { + const auto result = read(reg++); + if (not result) { + ret_code = RetCodes::CommunicationError; + return false; + } + if (*result != e) { + ret_code = RetCodes::ProfileInvalid; + return false; + } + return true; + }); return ret_code; } diff --git a/module-bsp/devices/temperature/CT7117.cpp b/module-bsp/devices/temperature/CT7117.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6731d24cc563692342a01f4cbf1b12e9a4e765bb --- /dev/null +++ b/module-bsp/devices/temperature/CT7117.cpp @@ -0,0 +1,150 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "CT7117.hpp" + +#include + +namespace +{ + enum class Registers + { + Temp = 0x00, + Config = 0x01, + Low_Temp_Set = 0x02, + High_Temp_Set = 0x03, + ID = 0x07 + }; + + enum class ConfigReg + { + OTS = (1 << 15), + F1 = (1 << 12), + F0 = (1 << 11), + ALTM = (1 << 9), + SD = (1 << 8), + EM = (1 << 7), + RES1 = (1 << 6), + RES0 = (1 << 5), + TO = (1 << 4), + PEC = (1 << 3), + CR1 = (1 << 2), + CR0 = (1 << 1), + OS = (1 << 0) + }; + + using namespace bsp::devices::temperature::CT7117; + + std::array to_bytes(const std::uint16_t value) + { + return {static_cast(value & 0xFF00 >> 8U), static_cast(value & 0xFF)}; + } + + std::uint16_t from_bytes(std::array bytes) + { + return bytes[0] << 8U | bytes[1]; + } + + ssize_t write_register16(const std::uint8_t dev_id, + drivers::DriverI2C &i2c, + const Registers address, + const std::uint16_t reg) + { + const drivers::I2CAddress addr = { + .deviceAddress = dev_id, .subAddress = static_cast(address), .subAddressSize = 1}; + + return i2c.Write(addr, &to_bytes(reg)[0], sizeof(reg)); + } + + std::optional read_register16(const std::uint8_t dev_id, + drivers::DriverI2C &i2c, + const Registers address) + { + const drivers::I2CAddress addr = { + .deviceAddress = dev_id, .subAddress = static_cast(address), .subAddressSize = 1}; + std::array ret_value{}; + + if (const auto result = i2c.Read(addr, &ret_value[0], ret_value.size()); result == ret_value.size()) { + return from_bytes(ret_value); + } + return std::nullopt; + } + + units::Temperature from_raw(const std::uint16_t raw) + { + auto is_sign_present = [](const std::uint16_t raw) { return ((raw & 0x8000) != 0); }; + + if (is_sign_present(raw)) { + const auto integer = + static_cast(((~raw + 1) & 0x7FFF) >> 7); // remove sign bit and shift to lower byte + const auto fractional = static_cast(((~raw + 1) & 0x7F) * 0.78125); + return -1 * (static_cast(integer) + (static_cast(fractional) / 100.0)); + } + else { + const auto integer = + static_cast((raw & 0x7FFF) >> 7); // remove sign bit and shift to lower byte + const auto fractional = static_cast((raw & 0x7F) * 0.78125); + return static_cast(integer) + (static_cast(fractional) / 100.0); + } + } + + std::uint16_t adjust_resolution(const std::uint16_t value) + { + /// Resolution = 0.25°C + return value & 0xFFE0; + } +} // namespace + +namespace bsp::devices::temperature::CT7117 +{ + + CT7117::CT7117(const std::uint8_t id, drivers::DriverI2C &i2c) : device_id{id}, i2c{i2c} + {} + + CT7117::~CT7117() + { + standby(); + } + + bool CT7117::standby() + { + auto reg = read_register16(device_id, i2c, Registers::Config); + if (not reg) { + return false; + } + *reg |= static_cast(ConfigReg::SD); + return write_register16(device_id, i2c, Registers::Config, *reg) == sizeof(*reg); + } + + bool CT7117::wakeup() + { + auto reg = read_register16(device_id, i2c, Registers::Config); + if (not reg) { + return false; + } + *reg &= ~(static_cast(ConfigReg::SD)); + return write_register16(device_id, i2c, Registers::Config, *reg) == sizeof(*reg); + } + + std::optional CT7117::get_temperature() const + { + auto reg = read_register16(device_id, i2c, Registers::Temp); + if (not reg) { + return std::nullopt; + } + + return from_raw(adjust_resolution(*reg)); + } + + bool CT7117::poll() const + { + constexpr auto DEVICE_ID = 0x59; + const drivers::I2CAddress reg = { + .deviceAddress = device_id, .subAddress = static_cast(Registers::ID), .subAddressSize = 1}; + + std::uint8_t id{}; + const auto id_size = sizeof id; + + return i2c.Read(reg, &id, id_size) == id_size and id == DEVICE_ID; + } +} // namespace bsp::devices::temperature::CT7117 diff --git a/module-bsp/devices/temperature/CT7117.hpp b/module-bsp/devices/temperature/CT7117.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2f69dc5b4a0f5c46df1d1c8e54c0f272d70bd6ab --- /dev/null +++ b/module-bsp/devices/temperature/CT7117.hpp @@ -0,0 +1,37 @@ +// 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 "drivers/i2c/DriverI2C.hpp" +#include + +#include + +namespace bsp::devices::temperature::CT7117 +{ + class CT7117 + { + public: + CT7117(std::uint8_t id, drivers::DriverI2C &i2c); + ~CT7117(); + CT7117(const CT7117 &) = delete; + CT7117(CT7117 &&) noexcept = default; + CT7117 &operator=(const CT7117 &) = delete; + CT7117 &operator=(CT7117 &&) noexcept = delete; + + /// Check if the chip is available, i.e is present on the I2C bus + bool poll() const; + /// Put the chip into low-power state + bool standby(); + /// Put the chip into normal/operational mode + bool wakeup(); + /// Return the current temperature in °C + std::optional get_temperature() const; + + private: + std::uint8_t device_id; + drivers::DriverI2C &i2c; + }; + +} // namespace bsp::devices::temperature::CT7117 diff --git a/module-bsp/drivers/i2c/DriverI2C.hpp b/module-bsp/drivers/i2c/DriverI2C.hpp index 646b3d8063099b06f0744fc374dae90e7b6a1241..c77073774fcc763e358b7f57f7f1e9659a6fccbe 100644 --- a/module-bsp/drivers/i2c/DriverI2C.hpp +++ b/module-bsp/drivers/i2c/DriverI2C.hpp @@ -37,7 +37,6 @@ namespace drivers struct DriverI2CParams { uint32_t baudrate; - // TODO:M.P add slave conf }; struct I2CAddress diff --git a/module-utils/utility/Units.hpp b/module-utils/utility/Units.hpp index c7351e627b9d0470a781186cfdc479d4a655ef85..d3684badedc9e143627034b9c47a54ed27cd7d43 100644 --- a/module-utils/utility/Units.hpp +++ b/module-utils/utility/Units.hpp @@ -7,6 +7,7 @@ namespace units { - using Voltage = std::uint32_t; /// mV - using SOC = std::uint8_t; /// 0-100% + using Voltage = std::uint32_t; /// mV + using SOC = std::uint8_t; /// 0-100% + using Temperature = float; } // namespace units