improved char display API

This commit was merged in pull request #41.
This commit is contained in:
2026-08-25 01:05:23 +02:00
parent a051bcd08a
commit e26b1f571d
3 changed files with 382 additions and 90 deletions
+9 -7
View File
@@ -1,11 +1,13 @@
use alloc::boxed::Box;
use embedded_hal_bus::i2c::AtomicDevice;
use embedded_hal_bus::util::AtomicCell;
use esp_hal::gpio::interconnect::PeripheralInput;
use esp_hal::i2c::master::Config;
use esp_hal::{gpio::interconnect::PeripheralOutput, i2c::master::I2c};
type InnerI2cBus = esp_hal::i2c::master::I2c<'static, esp_hal::Blocking>;
pub type I2cBus = &'static AtomicCell<InnerI2cBus>;
type InnerI2cBus<'a> = esp_hal::i2c::master::I2c<'a, esp_hal::Blocking>;
pub type I2cBus<'a> = &'a AtomicCell<InnerI2cBus<'a>>;
pub type I2cDevice<'a> = AtomicDevice<'a, esp_hal::i2c::master::I2c<'a, esp_hal::Blocking>>;
pub struct I2cBusPinConfiguration<I2C, SCL, SDA> {
pub i2c_peripheral: I2C,
@@ -13,13 +15,13 @@ pub struct I2cBusPinConfiguration<I2C, SCL, SDA> {
pub sda: SDA,
}
impl<I2C, SCL, SDA> I2cBusPinConfiguration<I2C, SCL, SDA>
impl<'a, I2C, SCL, SDA> I2cBusPinConfiguration<I2C, SCL, SDA>
where
I2C: esp_hal::i2c::master::Instance + 'static,
SCL: PeripheralOutput<'static> + PeripheralInput<'static>,
SDA: PeripheralOutput<'static> + PeripheralInput<'static>,
I2C: esp_hal::i2c::master::Instance + 'a,
SCL: PeripheralOutput<'a> + PeripheralInput<'a>,
SDA: PeripheralOutput<'a> + PeripheralInput<'a>,
{
pub fn build(self) -> I2cBus {
pub fn build(self) -> I2cBus<'a> {
let config = Config::default().with_frequency(esp_hal::time::Rate::from_khz(400));
let i2c = match I2c::new(self.i2c_peripheral, config) {
Ok(bus) => bus.with_sda(self.sda).with_scl(self.scl),