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
rust
use crate::{Address, internal};
struct MyTransport<Mcu> {
// ...
}
impl<Mcu> internal::Transport for MyTransport<Mcu>
where
Mcu: 'static,
{
type Config = TransportConfig;
type Mcu = Mcu;
async fn create(
config: Self::Config,
mcu: &'static Self::Mcu,
address: Address,
) -> Self {
// Initialize the transport...
Self {
// ...
}
}
async fn run<Storage>(&self, storage: &'static Storage)
where
Storage: crate::storage::Storage,
{
// 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:
lokey::internal::empty::Transport– Internal transport that does nothinglokey_ble::internal::Transport– BLE (Bluetooth Low Energy) internal transport