Lokey

Internal Transports

An internal transport in Lokey is the mechanism used for communication between device parts in case of multi-part devices.

At the type level, an internal transport is defined by implementing the internal::Transport trait.

Responsibilities

An internal transport defines how it is initialized and how the communication between device parts works:

  • Configuration type: The transport-specific configuration type.
  • Microcontroller type: The microcontroller type the transport targets.
  • Initialization: How to create and initialize the transport.
  • Communication: How to send and receive messages between device parts.
  • Background tasks: Optional transport-level background work, typically running for the device lifetime.

Single-part devices

For devices that consist of a single part, the internal::empty::Transport type can be used, which implements the internal::Transport trait but does not actually do anything.

Example

use lokey::{Address, AnyState, Context, Device, McuCreator, internal, storage};

struct MyTransport<Mcu> {
    // ...
}

impl<Mcu> internal::Transport for MyTransport<Mcu>
where
    Mcu: 'static,
{
    type Config = TransportConfig;
    type Mcu = Mcu;

    async fn create<Storage>(
        config: Self::Config,
        address: Address,
        mcu: &'static Self::Mcu,
        storage: &'static Storage,
    ) -> Self
    where
        Storage: storage::Storage,
    {
        // Initialize the transport...
        Self {
            // ...
        }
    }

    async fn run<Device, State>(&self, context: Context<Device, State>)
    where
        Device: lokey::Device<Mcu = Self::Mcu>,
        State: AnyState,
        Self::Mcu: McuCreator<Device::StorageConfig>,
    {
        // Run background tasks...
    }

    async fn send(&self, message_bytes: &[u8]) {
        // Send the message to the other device parts...
    }

    async fn receive(&self, buf: &mut [u8]) -> usize {
        // Receive a message from the other device parts...
    }
}

Provided implementations

The following internal transport implementations are provided:

On this page