pub struct Twi<'a> { /* private fields */ }
Expand description
Provides access to the TWI (aka I2C).
See: Twi::attach_slave()
and Twi::detach_slave()
.
Implementations§
Source§impl<'a> Twi<'a>
impl<'a> Twi<'a>
Sourcepub fn attach_slave(&mut self, slave: impl TwiSlave + 'static) -> TwiSlaveId
pub fn attach_slave(&mut self, slave: impl TwiSlave + 'static) -> TwiSlaveId
Attaches given slave into this TWI, executing it for each packet received on this interface - slave can then decide whether to respond or ignore the packet.
When multiple slaves are attached, they all get executed in the order of the attachment until any slave responds (if any).
See the twi.rs
example for usage.
See also: Self::attach_slave_fn()
.
Sourcepub fn attach_slave_fn(
&mut self,
slave: impl FnMut(TwiPacket) -> Option<TwiPacket> + 'static,
) -> TwiSlaveId
pub fn attach_slave_fn( &mut self, slave: impl FnMut(TwiPacket) -> Option<TwiPacket> + 'static, ) -> TwiSlaveId
Shortcut for Self::attach_slave()
that allows to create a device
with just a function:
let mut avr = AvrTester::test();
avr.twi0().attach_slave_fn(|packet| {
if packet.addr != 0x33 {
return None;
}
if packet.is_start() || packet.is_stop() {
return Some(packet.respond_ack());
}
if packet.is_write() {
todo!();
}
if packet.is_read() {
todo!();
}
None
});
See Self::attach_slave()
for details.
Sourcepub fn detach_slave(&mut self, id: TwiSlaveId)
pub fn detach_slave(&mut self, id: TwiSlaveId)
Detaches given slave from this TWI, preventing it from being executed again.
See: Self::attach_slave()
.
Auto Trait Implementations§
impl<'a> Freeze for Twi<'a>
impl<'a> !RefUnwindSafe for Twi<'a>
impl<'a> !Send for Twi<'a>
impl<'a> !Sync for Twi<'a>
impl<'a> Unpin for Twi<'a>
impl<'a> !UnwindSafe for Twi<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more