-
I have a project that is essential a power/watt monitor using a ESP32-C3 with INA219 (single-channel) or INA3221 (triple-channel) via I2C. It will also display the metrics on an OLED screen driven with the SSD1309 over SPI. The question I have is how to architect my INA219/3221 implementations in a manner that it can be used by both the I have no issue writing the driver code itself for the INA219 family but right now it's hal-specific to ESP platform. I have been looking at the I am thinking, something like the following steps:
I am fairly new to embedded and Rust so pardon my ignorance. I just figure that there will invariably be people using these common ICs and having a pre-made agnostic driver would be much better than everyone re-implementing it. I did see there is an existing Any tips in the right direction would be appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Well,
In my new projects (like max31855 driver) I use only 3 and 4 variants (because all platforms I have already support 1.0 version of For your driver you could use |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for this! Between your explanation and repo I think I can piece together what to do. I'd rather "future proof" in a sense and support v1 stuff like you mentioned. I think that provides a good enough compromise of code-reuse without burdening myself as a library maintainer full-time, when in reality I just wanted to make it as part of a larger project. |
Beta Was this translation helpful? Give feedback.
-
Answer by @chvllad is really great and complete Only thing to add might be: EH1.0 is currently still alpha and there might be changes - so until it's finished there will be some maintenance needed - especially not every HAL will adopt every new alpha version immediately But besides that, EH1.0 is probably the way to go long-term Looking forward to your driver implementation |
Beta Was this translation helpful? Give feedback.
-
It's a work in progress, but is functional at the moment. INA3221 |
Beta Was this translation helpful? Give feedback.
Well,
embedded_hal
is the way to write platform agnostic drivers. But note, currently there are a lot of variants ofembedded_hal
, including:i2c
is not supported in this variant).In my new projects (like max31855 driver) I use only 3 and 4 variants (because all platforms I have already support 1.0 version of
embedded_hal
). But using 0.2 and 1.0 blocking traits probably will be the most universal way to support most of the platforms.For your driver you could use
I2C
trait (blocking 0.2, blocking 1.0, unstable async).esp-hal
al…