A nonblocking driver for the INA3221 3-channel voltage and current sensor:
https://eric.buddington.net/code/pico/I ... -05-05.hpp
- GPL
- C++-23
- uses a std::generator coroutine, which can be used in a range-for loop.
- incrementing the iterator resumes the coroutine
- dereferencing the iterator gives a std::optional<raw_dataset_t>, returning std::nullopt when it would otherwise block.
- includes device::wakeup_time, which is a 32-bit time in microseconds as a hint on when to poll next
- Uses *nonblocking* I2C, so will often leave transactions in flight. Probably won't play well with other I2C uses.
- no exceptions, maybe no heap usage (coroutine may malloc internally)
Basic usage:
https://eric.buddington.net/code/pico/I ... -05-05.hpp
- GPL
- C++-23
- uses a std::generator coroutine, which can be used in a range-for loop.
- incrementing the iterator resumes the coroutine
- dereferencing the iterator gives a std::optional<raw_dataset_t>, returning std::nullopt when it would otherwise block.
- includes device::wakeup_time, which is a 32-bit time in microseconds as a hint on when to poll next
- Uses *nonblocking* I2C, so will often leave transactions in flight. Probably won't play well with other I2C uses.
- no exceptions, maybe no heap usage (coroutine may malloc internally)
Basic usage:
Code:
INA3221::device ina3221 { .i2c = i2c0, .i2c_address = 0x40 }; for (auto raw : ina3221.streamer (INA3221::cfg::slow)) if (raw.has_value()) { constexpr uint32_t mohms = 100; int32_t mV = INA3221::voltage((**power_stream).v[0]).mV; int32_t uA = INA3221::current((**power_stream).c[0], mohms).uA; }
Statistics: Posted by Eric Buddington — Sun May 05, 2024 9:59 pm