drivers/graphics/ihdgd: Move I2cBB creation to GpioPort

This commit is contained in:
bjorn3
2025-12-22 12:14:23 +01:00
parent a4a0fbd198
commit f9fa43df40
2 changed files with 30 additions and 22 deletions
+4 -10
View File
@@ -2,12 +2,11 @@ use common::io::{Io, MmioPtr, WriteOnly};
use common::timeout::Timeout;
use embedded_hal::prelude::*;
use std::sync::Arc;
use std::time::Duration;
use syscall::error::{Error, Result, EIO};
use crate::device::aux::Aux;
use crate::device::power::PowerWells;
use crate::device::{CallbackGuard, Gmbus, HalTimer};
use crate::device::{CallbackGuard, Gmbus};
use super::{GpioPort, MmioRegion};
@@ -269,14 +268,9 @@ impl Ddi {
};
let mut edid_data = [0; 128];
let i2c_freq = 100_000.0;
bitbang_hal::i2c::I2cBB::new(
unsafe { port.clock(gttmm)? },
unsafe { port.data(gttmm)? },
HalTimer::new(Duration::from_secs_f64(1.0 / i2c_freq)),
)
.write_read(0x50, &[0x00], &mut edid_data)
.map_err(|_err| Error::new(EIO))?;
unsafe { port.i2c(gttmm)? }
.write_read(0x50, &[0x00], &mut edid_data)
.map_err(|_err| Error::new(EIO))?;
Ok(edid_data)
};
+26 -12
View File
@@ -1,8 +1,12 @@
use std::convert::Infallible;
use std::time::Duration;
use common::io::{Io, MmioPtr};
use embedded_hal::blocking::i2c;
use embedded_hal::digital::v2 as digital;
use crate::device::HalTimer;
use super::MmioRegion;
const GPIO_DIR_MASK: u32 = 1 << 0;
@@ -35,18 +39,28 @@ pub enum GpioPort {
}
impl GpioPort {
pub unsafe fn clock(&self, gttmm: &MmioRegion) -> syscall::Result<GpioPin> {
Ok(GpioPin {
ctl: gttmm.mmio(*self as usize)?,
shift: GPIO_CLOCK_SHIFT,
})
}
pub unsafe fn data(&self, gttmm: &MmioRegion) -> syscall::Result<GpioPin> {
Ok(GpioPin {
ctl: gttmm.mmio(*self as usize)?,
shift: GPIO_DATA_SHIFT,
})
pub unsafe fn i2c(
&self,
gttmm: &MmioRegion,
) -> syscall::Result<bitbang_hal::i2c::I2cBB<GpioPin, GpioPin, HalTimer>> {
let i2c_freq = 100_000.0;
let (scl, sda) = unsafe {
(
GpioPin {
ctl: gttmm.mmio(*self as usize)?,
shift: GPIO_CLOCK_SHIFT,
},
GpioPin {
ctl: gttmm.mmio(*self as usize)?,
shift: GPIO_DATA_SHIFT,
},
)
};
Ok(bitbang_hal::i2c::I2cBB::new(
scl,
sda,
HalTimer::new(Duration::from_secs_f64(1.0 / i2c_freq)),
))
}
}