Module avr_oxide::devices::serialbus

source ·
Expand description

Exposes the underlying TWI device interface in a userland-safe way.

This is essentially a thread-safe wrapper around the underlying TWI HAL. To send commands to the bus, you need to get a SerialBusClient instance using the SerialBus::client() method. Once you have a client, you can issue commands using the various methods provided by SerialBusClient.

Only one instance of SerialBus can exist per physical device, but there may be multiple instances of SerialBusClient for different client devices.

§Usage

use avr_oxide::hardware;
use avr_oxide::devices::serialbus::SerialBusClient;

#[avr_oxide::main(chip="atmega4809")]
pub fn main() {
  let supervisor = avr_oxide::oxide::instance();
  let bus = StaticWrap::new(OxideSerialBus::using_bus(hardware::twi::twi0::instance().mux(hardware::twi::twi0::TwiPins::MasterASlaveC).mode(InterfaceMode::I2C, PortSpeed::Fast)));
  supervisor.listen(bus.borrow());
  let mut i2c_device = OxideSerialBus::client(bus.borrow(), TwiAddr::addr(0xa0));

  static COMMAND_BUFFER: [u8;6] = [0x00u8,0x00u8,0xdeu8,0xadu8,0xbeu8,0xefu8];
  i2c_device.write_from(&COMMAND_BUFFER);

Structs§

Traits§