diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 18d94b6e6..1285ccc2f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,6 +67,8 @@ jobs: target: esp32 - path: 'components/math/example' target: esp32 + - path: 'components/max1704x/example' + target: esp32 - path: 'components/monitor/example' target: esp32 - path: 'components/mcp23x17/example' diff --git a/components/max1704x/CMakeLists.txt b/components/max1704x/CMakeLists.txt new file mode 100644 index 000000000..5ae0fe990 --- /dev/null +++ b/components/max1704x/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register( + INCLUDE_DIRS "include" + REQUIRES "logger" "math" + ) diff --git a/components/max1704x/example/CMakeLists.txt b/components/max1704x/example/CMakeLists.txt new file mode 100644 index 000000000..c079bf090 --- /dev/null +++ b/components/max1704x/example/CMakeLists.txt @@ -0,0 +1,21 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +# add the component directories that we want to use +set(EXTRA_COMPONENT_DIRS + "../../../components/" +) + +set( + COMPONENTS + "main esptool_py i2c task max1704x" + CACHE STRING + "List of components to include" + ) + +project(max1704x_example) + +set(CMAKE_CXX_STANDARD 20) diff --git a/components/max1704x/example/README.md b/components/max1704x/example/README.md new file mode 100644 index 000000000..9efcc89b0 --- /dev/null +++ b/components/max1704x/example/README.md @@ -0,0 +1,34 @@ +# MAX1704X Example + +This example shows how to use the MAX1704X driver to control + +## How to use example + +### Hardware Required + +This example requires a connection (via I2C) to a dev board which has a MAX1704X +battery gauge chip. The example was tested with a QtPy ESP32s3 dev board and a +MAX1704X breakout board from Adafruit, but can be configured (using +`menuconfig`) to run on any ESP board by configuring the I2C pins and selecting +`CUSTOM` hardware. + +- [MAX17048 Breakout board from Adafruit](https://www.adafruit.com/product/5580) +- [QtPy ESP32 Pico](https://www.adafruit.com/product/5395) + +### Build and Flash + +Build the project and flash it to the board, then run monitor tool to view serial output: + +``` +idf.py -p PORT flash monitor +``` + +(Replace PORT with the name of the serial port to use.) + +(To exit the serial monitor, type ``Ctrl-]``.) + +See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. + +## Example Output + +![CleanShot 2024-01-09 at 08 24 25](https://github.com/esp-cpp/espp/assets/213467/13699053-ba1d-4af3-a5e0-dbcbd772b2d7) diff --git a/components/max1704x/example/main/CMakeLists.txt b/components/max1704x/example/main/CMakeLists.txt new file mode 100644 index 000000000..a941e22ba --- /dev/null +++ b/components/max1704x/example/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRC_DIRS "." + INCLUDE_DIRS ".") diff --git a/components/max1704x/example/main/Kconfig.projbuild b/components/max1704x/example/main/Kconfig.projbuild new file mode 100644 index 000000000..dfc846b7d --- /dev/null +++ b/components/max1704x/example/main/Kconfig.projbuild @@ -0,0 +1,39 @@ +menu "Example Configuration" + + choice EXAMPLE_HARDWARE + prompt "Hardware" + default EXAMPLE_HARDWARE_QTPYPICO + help + Select the hardware to run this example on. + + config EXAMPLE_HARDWARE_QTPYPICO + depends on IDF_TARGET_ESP32 + bool "Qt Py PICO" + + config EXAMPLE_HARDWARE_QTPYS3 + depends on IDF_TARGET_ESP32S3 + bool "Qt Py S3" + + config EXAMPLE_HARDWARE_CUSTOM + bool "Custom" + endchoice + + config EXAMPLE_I2C_SCL_GPIO + int "SCL GPIO Num" + range 0 50 + default 19 if EXAMPLE_HARDWARE_QTPYPICO + default 40 if EXAMPLE_HARDWARE_QTPYS3 + default 19 if EXAMPLE_HARDWARE_CUSTOM + help + GPIO number for I2C Master clock line. + + config EXAMPLE_I2C_SDA_GPIO + int "SDA GPIO Num" + range 0 50 + default 22 if EXAMPLE_HARDWARE_QTPYPICO + default 41 if EXAMPLE_HARDWARE_QTPYS3 + default 22 if EXAMPLE_HARDWARE_CUSTOM + help + GPIO number for I2C Master data line. + +endmenu diff --git a/components/max1704x/example/main/max1704x_example.cpp b/components/max1704x/example/main/max1704x_example.cpp new file mode 100644 index 000000000..a3a5afc6b --- /dev/null +++ b/components/max1704x/example/main/max1704x_example.cpp @@ -0,0 +1,71 @@ +#include +#include + +#include "i2c.hpp" +#include "logger.hpp" +#include "max1704x.hpp" +#include "task.hpp" + +using namespace std::chrono_literals; + +extern "C" void app_main(void) { + + //! [max1704x example] + espp::Logger logger({.tag = "Max1704x example", .level = espp::Logger::Verbosity::INFO}); + // make the I2C that we'll use to communicate + logger.info("initializing i2c driver..."); + espp::I2c i2c({ + .port = I2C_NUM_0, + .sda_io_num = (gpio_num_t)CONFIG_EXAMPLE_I2C_SDA_GPIO, + .scl_io_num = (gpio_num_t)CONFIG_EXAMPLE_I2C_SCL_GPIO, + }); + // now make the max1704x which handles GPIO + espp::Max1704x max1704x({.write = std::bind(&espp::I2c::write, &i2c, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3), + .read = std::bind(&espp::I2c::read, &i2c, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3), + .log_level = espp::Logger::Verbosity::WARN}); + std::error_code ec; + + // and finally, make the task to periodically poll the max1704x and print + // the state. NOTE: the Max1704x does not internally manage its own state + // update, so whatever rate we use here is the rate at which the state will + // update. + auto task_fn = [&](std::mutex &m, std::condition_variable &cv) { + // NOTE: sleeping in this way allows the sleep to exit early when the + // task is being stopped / destroyed + { + std::unique_lock lk(m); + cv.wait_for(lk, 50ms); + } + static auto start = std::chrono::high_resolution_clock::now(); + auto now = std::chrono::high_resolution_clock::now(); + auto seconds = std::chrono::duration(now - start).count(); + std::error_code ec; + auto voltage = max1704x.get_battery_voltage(ec); + if (ec) { + return false; + } + auto soc = max1704x.get_battery_percentage(ec); + if (ec) { + return false; + } + auto charge_rate = max1704x.get_battery_charge_rate(ec); + if (ec) { + return false; + } + fmt::print("{:0.2f}, {:0.2f}, {:0.2f}, {:0.2f}\n", seconds, voltage, soc, charge_rate); + // don't want to stop the task + return false; + }; + auto task = espp::Task({.name = "Max1704x Task", + .callback = task_fn, + .stack_size_bytes = 5 * 1024, + .log_level = espp::Logger::Verbosity::WARN}); + fmt::print("%time(s), voltage (V), SoC (%), Charge Rate (%/hr)\n"); + task.start(); + //! [max1704x example] + while (true) { + std::this_thread::sleep_for(100ms); + } +} diff --git a/components/max1704x/example/sdkconfig.defaults b/components/max1704x/example/sdkconfig.defaults new file mode 100644 index 000000000..7d75f8d01 --- /dev/null +++ b/components/max1704x/example/sdkconfig.defaults @@ -0,0 +1,11 @@ +CONFIG_FREERTOS_HZ=1000 + +# ESP32-specific +# +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ=240 + +# Common ESP-related +# +CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 diff --git a/components/max1704x/include/max1704x.hpp b/components/max1704x/include/max1704x.hpp new file mode 100644 index 000000000..d7b115e06 --- /dev/null +++ b/components/max1704x/include/max1704x.hpp @@ -0,0 +1,284 @@ +#pragma once + +#include +#include + +#include "logger.hpp" + +namespace espp { +/** + * @brief Class to interface with the MAX1704x battery fuel gauge. + * @details This class is used to interface with the MAX1704x battery fuel + * gauge. It is used to get the battery voltage, state of charge, and + * charge/discharge rate. + * @see + * https://cdn-learn.adafruit.com/assets/assets/000/114/607/original/MAX17048-MAX17049.pdf?1661966692 + * + * @section max1704x_ex1 MAX1704X Example + * @snippet max1704x_example.cpp max1704x example + */ +class Max1704x { +public: + static constexpr uint8_t DEFAULT_ADDRESS = 0x36; ///< Default address of the MAX1704x. + + /** + * @brief Function to write bytes to the device. + * @param dev_addr Address of the device to write to. + * @param data Pointer to array of bytes to write. + * @param data_len Number of data bytes to write. + * @return True if successful, false otherwise. + */ + typedef std::function write_fn; + + /** + * @brief Function to read bytes from the device. + * @param dev_addr Address of the device to write to. + * @param data Pointer to array of bytes to read into. + * @param data_len Number of data bytes to read. + * @return True if successful, false otherwise. + */ + typedef std::function read_fn; + + enum class AlertStatus { + SOC_CHANGE = 0x20, ///< Alert for state of charge change + SOC_LOW = 0x10, ///< Alert for state of charge low + VOLTAGE_RESET = 0x08, ///< Alert for voltage reset dip + VOLTAGE_LOW = 0x04, ///< Alert for voltage low + VOLTAGE_HIGH = 0x02, ///< Alert for voltage high + }; + + /** + * @brief Configuration for the MAX1704x. + */ + struct Config { + uint8_t device_address{DEFAULT_ADDRESS}; ///< Address of the MAX1704x. + write_fn write; //< Function to write bytes to the device. + read_fn read; //< Function to read bytes from the device. + bool auto_init{true}; ///< Whether to automatically initialize the MAX1704x. + Logger::Verbosity log_level{Logger::Verbosity::WARN}; ///< Log level for the MAX1704x. + }; + + /** + * @brief Construct a new Max1704x object. + * @param config Configuration for the MAX1704x. + */ + explicit Max1704x(const Config &config) + : address_(config.device_address), write_(config.write), read_(config.read), + logger_({.tag = "Max1704x", .level = config.log_level}) { + if (config.auto_init) { + std::error_code ec; + initalize(ec); + if (ec) { + logger_.error("Failed to initialize MAX1704x: {}", ec.message()); + } + } + } + + /** + * @brief Delete the Max1704x object. + */ + ~Max1704x(); + + /** + * @brief Initialize the MAX1704x. + */ + void initalize(std::error_code &ec) { + std::scoped_lock lock(mutex_); + // Get the IC version + version_ = get_version(ec); + if (ec) { + return; + } + // Get the chip ID + chip_id_ = get_chip_id(ec); + if (ec) { + return; + } + logger_.info("MAX1704x version: 0x{:04X}, chip ID: 0x{:02X}", version_, chip_id_); + ec.clear(); + } + + /** + * @brief Get the IC version. + * @param ec Error code set if an error occurs. + * @return The IC version. + */ + uint16_t get_version(std::error_code &ec) { + std::scoped_lock lock(mutex_); + uint16_t data = read_register(Register::VERSION, ec); + if (ec) { + return 0; + } + ec.clear(); + return data; + } + + /** + * @brief Get the Chip ID. + * @param ec Error code set if an error occurs. + * @return The chip ID. + */ + uint8_t get_chip_id(std::error_code &ec) { + std::scoped_lock lock(mutex_); + uint16_t data = read_register(Register::CHIPID, ec); + if (ec) { + return 0; + } + ec.clear(); + return data; + } + + /** + * @brief Get the battery voltage. + * @param ec Error code set if an error occurs. + * @return The battery voltage in V. + */ + float get_battery_voltage(std::error_code &ec) { + std::scoped_lock lock(mutex_); + uint16_t data = read_register(Register::VCELL, ec); + if (ec) { + return 0; + } + ec.clear(); + return (float)data * CELL_VOLTAGE_FACTOR; + } + + /** + * @brief Get the battery state of charge. + * @details This is the percentage of battery charge remaining. + * @param ec Error code set if an error occurs. + * @return The battery state of charge in %. + */ + float get_battery_percentage(std::error_code &ec) { + std::scoped_lock lock(mutex_); + uint16_t data = read_register(Register::SOC, ec); + if (ec) { + return 0; + } + ec.clear(); + return (float)data * CELL_SOC_FACTOR; + } + + /** + * @brief Get the battery charge or discharge rate. + * @details This is the rate at which the battery is charging or + * discharging. A positive value indicates charging. A negative + * value indicates discharging. Units are in % per hour. + * @param ec Error code set if an error occurs. + * @return The battery charge or discharge rate in %/hr. + */ + float get_battery_charge_rate(std::error_code &ec) { + std::scoped_lock lock(mutex_); + int16_t data = read_register(Register::CRATE, ec); + if (ec) { + return 0; + } + ec.clear(); + return (float)data * CELL_CRATE_FACTOR; + } + + /** + * @brief Get the alert status. + * @details This is the current alert status of the battery. + * @param ec Error code set if an error occurs. + * @return The battery alert status as an AlertStatus. + */ + AlertStatus get_alert_status(std::error_code &ec) { + std::scoped_lock lock(mutex_); + uint16_t data = read_register(Register::STATUS, ec); + if (ec) { + return AlertStatus::SOC_CHANGE; + } + ec.clear(); + return (AlertStatus)(data & 0x7F); + } + + /** + * @brief Clear the alert status. + * @details This clears the alert status of the battery. + * @param flags_to_clear The flags to clear. + * @param ec Error code set if an error occurs. + */ + void clear_alert_status(uint8_t flags_to_clear, std::error_code &ec) { + std::scoped_lock lock(mutex_); + uint8_t data = read_register(Register::STATUS, ec); + if (ec) { + return; + } + data &= ~flags_to_clear; + write_register(Register::STATUS, data, ec); + } + +protected: + static constexpr float CELL_VOLTAGE_FACTOR = + 78.125f / 1000000.0f; ///< Factor to convert cell voltage to V. 78.125uV per bit. + static constexpr float CELL_SOC_FACTOR = + 1.0f / 256.0f; ///< Factor to convert cell state of charge to %. + static constexpr float CELL_CRATE_FACTOR = + 0.208f; ///< Factor to convert cell charge rate to %/hr. + + enum class Register { + VCELL = 0x02, ///< Register that holds cell voltage + SOC = 0x04, ///< Register that holds cell state of charge + MODE = 0x06, ///< Register that manages mode. Default is 0x0000 + VERSION = 0x08, ///< Register that has IC version + HIBRT = 0x0A, ///< Register that manages hibernation. Default is 0x8030 + CONFIG = 0x0C, ///< Register that manages configuration. Default is 0x971C + VALRT = 0x14, ///< Register that holds voltage alert values + CRATE = 0x16, ///< Register that holds cell charge rate + VRESET = 0x18, ///< Register that holds reset voltage setting + CHIPID = 0x19, ///< Register that holds semi-unique chip ID + STATUS = 0x1A, ///< Register that holds current alert/status + CMD = 0xFE ///< Register that can be written for special commands + }; + + enum class Alert { + SOC_CHANGE = 0x20, ///< Alert for state of charge change + SOC_LOW = 0x10, ///< Alert for state of charge low + VOLTAGE_RESET = 0x08, ///< Alert for voltage reset dip + VOLTAGE_LOW = 0x04, ///< Alert for voltage low + VOLTAGE_HIGH = 0x02, ///< Alert for voltage high + }; + + void write_register(const Register reg, const uint8_t data, std::error_code &ec) { + std::scoped_lock lock(mutex_); + uint8_t buf[2]; + buf[0] = (uint8_t)reg; + buf[1] = (uint8_t)data; + if (!write_(address_, buf, sizeof(buf))) { + logger_.error("Failed to write register 0x{:02X}", (uint8_t)reg); + ec = std::make_error_code(std::errc::io_error); + return; + } + ec.clear(); + } + + uint16_t read_register(const Register reg, std::error_code &ec) { + std::scoped_lock lock(mutex_); + // write the address + if (!write_(address_, (uint8_t *)®, 1)) { + ec = std::make_error_code(std::errc::io_error); + logger_.error("Failed to write register 0x{:02X}", (uint8_t)reg); + return 0; + } + // and read the data + uint8_t data[2]; + if (!read_(address_, data, 2)) { + ec = std::make_error_code(std::errc::io_error); + logger_.error("Failed to read register 0x{:02X}", (uint8_t)reg); + return 0; + } + ec.clear(); + return (data[0] << 8) | data[1]; + } + + uint16_t version_{0}; ///< IC version + uint8_t chip_id_{0}; ///< Chip ID + + uint8_t address_; + write_fn write_; + read_fn read_; + std::recursive_mutex mutex_; + Logger logger_; +}; +} // namespace espp diff --git a/doc/Doxyfile b/doc/Doxyfile index eb4642dd7..ae2f6f6d7 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -48,6 +48,7 @@ EXAMPLE_PATH += $(PROJECT_PATH)/components/led/example/main/led_example.cpp EXAMPLE_PATH += $(PROJECT_PATH)/components/led_strip/example/main/led_strip_example.cpp EXAMPLE_PATH += $(PROJECT_PATH)/components/logger/example/main/logger_example.cpp EXAMPLE_PATH += $(PROJECT_PATH)/components/math/example/main/math_example.cpp +EXAMPLE_PATH += $(PROJECT_PATH)/components/max1704x/example/main/max1704x_example.cpp EXAMPLE_PATH += $(PROJECT_PATH)/components/monitor/example/main/monitor_example.cpp EXAMPLE_PATH += $(PROJECT_PATH)/components/mcp23x17/example/main/mcp23x17_example.cpp EXAMPLE_PATH += $(PROJECT_PATH)/components/mt6701/example/main/mt6701_example.cpp @@ -128,6 +129,7 @@ INPUT += $(PROJECT_PATH)/components/math/include/fast_math.hpp INPUT += $(PROJECT_PATH)/components/math/include/gaussian.hpp INPUT += $(PROJECT_PATH)/components/math/include/range_mapper.hpp INPUT += $(PROJECT_PATH)/components/math/include/vector2d.hpp +INPUT += $(PROJECT_PATH)/components/max1704x/include/max1704x.hpp INPUT += $(PROJECT_PATH)/components/ndef/include/ndef.hpp INPUT += $(PROJECT_PATH)/components/mcp23x17/include/mcp23x17.hpp INPUT += $(PROJECT_PATH)/components/mt6701/include/mt6701.hpp diff --git a/doc/en/battery/bldc_driver.rst b/doc/en/battery/bldc_driver.rst new file mode 100644 index 000000000..8ea158696 --- /dev/null +++ b/doc/en/battery/bldc_driver.rst @@ -0,0 +1,13 @@ +BLDC Driver +*********** + +The `BldcDriver` component wraps around the `ESP MCPWM Peripheral +`_ +to provide full 6 PWM control over a 3 phase brushless dc motor. + +.. ---------------------------- API Reference ---------------------------------- + +API Reference +------------- + +.. include-build-file:: inc/bldc_driver.inc diff --git a/doc/en/battery/bldc_motor.rst b/doc/en/battery/bldc_motor.rst new file mode 100644 index 000000000..a910d98f0 --- /dev/null +++ b/doc/en/battery/bldc_motor.rst @@ -0,0 +1,29 @@ +BLDC Motor +********** + +The `BldcMotor` implements the Field-Oriented Control (FOC) algorithm with +support for multiple transforms to drive voltage (such as Sinusoidal and Space +Vector). It supports the following motion control configurations (which can be +changed dynamically): + +* Closed-loop angle +* Closed-loop velocity +* Open-loop angle +* Open-loop velocity + +Note: currently the code has some support for Torque control, but that requires +current sense - for which I don't yet have the hardware to support the +development of. + +The `BldcMotor` should be configured with a `BldcDriver` and optional `Sensor` +(for angle & speed of the motor), and optional `CurrentSensor` (for measuring +the phase currents of the motor and providing torque control). + +.. ---------------------------- API Reference ---------------------------------- + +API Reference +------------- + +.. include-build-file:: inc/bldc_motor.inc +.. include-build-file:: inc/bldc_types.inc +.. include-build-file:: inc/sensor_direction.inc diff --git a/doc/en/battery/index.rst b/doc/en/battery/index.rst new file mode 100644 index 000000000..d72e3a5b8 --- /dev/null +++ b/doc/en/battery/index.rst @@ -0,0 +1,11 @@ +Battery APIs +************ + +.. toctree:: + :maxdepth: 1 + + max1704x + +These components provide a common interface to battery devices. They provide +functions for monitoring the battery level and charging status, and for +configuring the battery charging parameters. diff --git a/doc/en/battery/max1704x.rst b/doc/en/battery/max1704x.rst new file mode 100644 index 000000000..f3db1fddf --- /dev/null +++ b/doc/en/battery/max1704x.rst @@ -0,0 +1,32 @@ +MAX1704X +******** + +The MAX17048/MAX17049 ICs are tiny, micropower current fuel gauges for +lithium-ion (Li+) batteries in handheld and portable equipment. The MAX17048 +operates with a single lithium cell and the MAX17049 with two lithium cells in +series. + +The ICs use the sophisticated Li+ battery-modeling algorithm ModelGauge™ to +track the battery relative state-of-charge (SOC) continuously over widely varying +charge and discharge conditions. The ModelGauge algorithm eliminates +current-sense resistor and battery-learn cycles required in traditional fuel +gauges. Temperature compensation is implemented using the system +microcontroller. + +The ICs automatically detect when the battery enters a low-current state and +enters low-power 3µA hibernate mode, while still providing accurate fuel +gauging. The ICs automatically exit hibernate mode when the system returns to +active state. + +On battery insertion, the ICs debounce initial voltage measurements to improve +the initial SOC estimate, thus allowing them to be located on system side. SOC, +voltage, and rate information is accessed using the I2C interface. The ICs are +available in a tiny 0.9mm x 1.7mm, 8-bump wafer-level package (WLP), or a 2mm x +2mm, 8-pin TDFN package. + +.. ---------------------------- API Reference ---------------------------------- + +API Reference +------------- + +.. include-build-file:: inc/max1704x.inc diff --git a/doc/en/index.rst b/doc/en/index.rst index 52ef2cf6d..eeb4db2e4 100644 --- a/doc/en/index.rst +++ b/doc/en/index.rst @@ -11,6 +11,7 @@ This is the documentation for esp-idf c++ components, ESPP (`espp `_ +to provide full 6 PWM control over a 3 phase brushless dc motor. + +.. ---------------------------- API Reference ---------------------------------- + +API Reference +------------- + +.. include-build-file:: inc/bldc_driver.inc diff --git a/docs/_sources/battery/bldc_motor.rst.txt b/docs/_sources/battery/bldc_motor.rst.txt new file mode 100644 index 000000000..a910d98f0 --- /dev/null +++ b/docs/_sources/battery/bldc_motor.rst.txt @@ -0,0 +1,29 @@ +BLDC Motor +********** + +The `BldcMotor` implements the Field-Oriented Control (FOC) algorithm with +support for multiple transforms to drive voltage (such as Sinusoidal and Space +Vector). It supports the following motion control configurations (which can be +changed dynamically): + +* Closed-loop angle +* Closed-loop velocity +* Open-loop angle +* Open-loop velocity + +Note: currently the code has some support for Torque control, but that requires +current sense - for which I don't yet have the hardware to support the +development of. + +The `BldcMotor` should be configured with a `BldcDriver` and optional `Sensor` +(for angle & speed of the motor), and optional `CurrentSensor` (for measuring +the phase currents of the motor and providing torque control). + +.. ---------------------------- API Reference ---------------------------------- + +API Reference +------------- + +.. include-build-file:: inc/bldc_motor.inc +.. include-build-file:: inc/bldc_types.inc +.. include-build-file:: inc/sensor_direction.inc diff --git a/docs/_sources/battery/index.rst.txt b/docs/_sources/battery/index.rst.txt new file mode 100644 index 000000000..d72e3a5b8 --- /dev/null +++ b/docs/_sources/battery/index.rst.txt @@ -0,0 +1,11 @@ +Battery APIs +************ + +.. toctree:: + :maxdepth: 1 + + max1704x + +These components provide a common interface to battery devices. They provide +functions for monitoring the battery level and charging status, and for +configuring the battery charging parameters. diff --git a/docs/_sources/battery/max1704x.rst.txt b/docs/_sources/battery/max1704x.rst.txt new file mode 100644 index 000000000..f3db1fddf --- /dev/null +++ b/docs/_sources/battery/max1704x.rst.txt @@ -0,0 +1,32 @@ +MAX1704X +******** + +The MAX17048/MAX17049 ICs are tiny, micropower current fuel gauges for +lithium-ion (Li+) batteries in handheld and portable equipment. The MAX17048 +operates with a single lithium cell and the MAX17049 with two lithium cells in +series. + +The ICs use the sophisticated Li+ battery-modeling algorithm ModelGauge™ to +track the battery relative state-of-charge (SOC) continuously over widely varying +charge and discharge conditions. The ModelGauge algorithm eliminates +current-sense resistor and battery-learn cycles required in traditional fuel +gauges. Temperature compensation is implemented using the system +microcontroller. + +The ICs automatically detect when the battery enters a low-current state and +enters low-power 3µA hibernate mode, while still providing accurate fuel +gauging. The ICs automatically exit hibernate mode when the system returns to +active state. + +On battery insertion, the ICs debounce initial voltage measurements to improve +the initial SOC estimate, thus allowing them to be located on system side. SOC, +voltage, and rate information is accessed using the I2C interface. The ICs are +available in a tiny 0.9mm x 1.7mm, 8-bump wafer-level package (WLP), or a 2mm x +2mm, 8-pin TDFN package. + +.. ---------------------------- API Reference ---------------------------------- + +API Reference +------------- + +.. include-build-file:: inc/max1704x.inc diff --git a/docs/_sources/index.rst.txt b/docs/_sources/index.rst.txt index 52ef2cf6d..eeb4db2e4 100644 --- a/docs/_sources/index.rst.txt +++ b/docs/_sources/index.rst.txt @@ -11,6 +11,7 @@ This is the documentation for esp-idf c++ components, ESPP (`espp - + @@ -90,6 +90,7 @@ +
  • Battery APIs
  • BLDC APIs
  • Button APIs
  • Controller APIs
  • @@ -145,7 +146,7 @@
  • ADC APIs »
  • ADC Types
  • - Edit on GitHub + Edit on GitHub

  • @@ -173,13 +174,13 @@

    Header File - +
    -

    © Copyright 2022 - 2023, William Emfinger.

    +

    © Copyright 2022 - 2024, William Emfinger.

    +
  • Battery APIs
  • BLDC APIs
  • Button APIs
  • Controller APIs
  • @@ -146,7 +147,7 @@
  • ADC APIs »
  • ADS1x15 I2C ADC
  • - Edit on GitHub + Edit on GitHub

  • @@ -163,7 +164,7 @@

    API Reference

    Header File

    @@ -588,7 +589,7 @@

    ADS1X15 Example -

    © Copyright 2022 - 2023, William Emfinger.

    +

    © Copyright 2022 - 2024, William Emfinger.

    +
  • Battery APIs
  • BLDC APIs
  • Button APIs
  • Controller APIs
  • @@ -146,7 +147,7 @@
  • ADC APIs »
  • ADS7138 I2C ADC
  • - Edit on GitHub + Edit on GitHub

  • @@ -168,7 +169,7 @@

    API Reference

    Header File

    @@ -1178,7 +1179,7 @@

    ADS7138 Example -

    © Copyright 2022 - 2023, William Emfinger.

    +

    © Copyright 2022 - 2024, William Emfinger.

    +
  • Battery APIs
  • BLDC APIs
  • Button APIs
  • Controller APIs
  • @@ -146,7 +147,7 @@
  • ADC APIs »
  • Continuous ADC
  • - Edit on GitHub + Edit on GitHub

  • @@ -168,7 +169,7 @@

    API Reference

    Header File

    @@ -356,7 +357,7 @@

    Continuous ADC Example -

    © Copyright 2022 - 2023, William Emfinger.

    +

    © Copyright 2022 - 2024, William Emfinger.

    +
  • Battery APIs
  • BLDC APIs
  • Button APIs
  • Controller APIs
  • @@ -138,7 +139,7 @@
  • »
  • ADC APIs
  • - Edit on GitHub + Edit on GitHub

  • @@ -172,7 +173,7 @@

    ADC APIs -

    © Copyright 2022 - 2023, William Emfinger.

    +

    © Copyright 2022 - 2024, William Emfinger.

    +
  • Battery APIs
  • BLDC APIs
  • Button APIs
  • Controller APIs
  • @@ -146,7 +147,7 @@
  • ADC APIs »
  • Oneshot ADC
  • - Edit on GitHub + Edit on GitHub

  • @@ -167,7 +168,7 @@

    API Reference

    Header File

    @@ -310,7 +311,7 @@

    Oneshot ADC Example -

    © Copyright 2022 - 2023, William Emfinger.

    +

    © Copyright 2022 - 2024, William Emfinger.

    +
  • Battery APIs
  • BLDC APIs
  • Button APIs
  • Controller APIs
  • @@ -146,7 +147,7 @@
  • ADC APIs »
  • TLA2528 I2C ADC
  • - Edit on GitHub + Edit on GitHub

  • @@ -168,7 +169,7 @@

    API Reference

    Header File

    @@ -887,7 +888,7 @@

    TLA2528 Example -

    © Copyright 2022 - 2023, William Emfinger.

    +

    © Copyright 2022 - 2024, William Emfinger.

    @@ -417,7 +418,7 @@

    Classes -

    © Copyright 2022 - 2023, William Emfinger.

    +

    © Copyright 2022 - 2024, William Emfinger.

    @@ -568,13 +569,13 @@

    Example Usage

    Header File

    Header File

    @@ -591,7 +592,7 @@

    Header File -

    © Copyright 2022 - 2023, William Emfinger.

    +

    © Copyright 2022 - 2024, William Emfinger.