[][src]Crate shared_bus_rtic

Introduction

This crate provides a means of sharing an I2C or SPI bus between multiple drivers.

Notice

Note that all of the drivers that use the same underlying bus must be stored within a single resource (e.g. as one larger struct) within the RTIC resources. This ensures that RTIC will prevent one driver from interrupting another while they are using the same underlying bus.

This crate also provides convenience types for working with shared-bus RTIC resources.

Usage Example


use shared_bus_rtic::SharedBus;

struct SharedBusResources<T> {
    device: Device<SharedBus<T>>,
    other_device: OtherDevice<SharedBus<T>>,
}

// ...

// Replace this type with the type of your bus (e.g. hal::i2c::I2c<...>).
type BusType = ();

struct Resources {
    shared_bus_resources: SharedBusResources<BusType>,
}

#[init]
fn init(c: init::Context) -> init::LateResources {
    // TODO: Define your custom bus here.
    let bus: BusType = ();

    // Construct the bus manager.
    let manager = shared_bus_rtic::new!(bus, BusType);

    // Construct all of your devices that use the shared bus.
    let device = Device::new(manager.acquire());
    let other_device = OtherDevice::new(manager.acquire());

    init::LateResources {
        shared_bus_resources: SharedBusResources { device, other_device },
    }
}

Macros

new

Provides a method of generating a shared bus.

Structs

CommonBus

Type Definitions

SharedBus

A convenience type to use for declaring the underlying bus type.