embedded_platform/i2c/
initialize.rs1use core::future;
3use core::pin;
4use core::task;
5
6#[derive(Debug)]
8#[must_use = "futures do nothing unless you `.await` or poll them"]
9pub struct Initialize<A, SDA, SCL>
10where
11 A: super::I2cBusMapping<SDA, SCL> + Unpin,
12 SDA: Unpin,
13 SCL: Unpin,
14{
15 mapping: A,
16 sda: SDA,
17 scl: SCL,
18}
19
20pub fn initialize<A, SDA, SCL>(mapping: A, sda: SDA, scl: SCL) -> Initialize<A, SDA, SCL>
22where
23 A: super::I2cBusMapping<SDA, SCL> + Unpin,
24 SDA: Unpin,
25 SCL: Unpin,
26{
27 Initialize { mapping, sda, scl }
28}
29
30impl<A, SDA, SCL> future::Future for Initialize<A, SDA, SCL>
31where
32 A: super::I2cBusMapping<SDA, SCL> + Unpin,
33 SDA: Unpin,
34 SCL: Unpin,
35{
36 type Output = Result<A::Bus, A::Error>;
37
38 fn poll(mut self: pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
39 let this = &mut *self;
40 pin::Pin::new(&mut this.mapping).poll_initialize(cx, &mut this.sda, &mut this.scl)
41 }
42}