Lokey

Devices

A device in Lokey represents a concrete hardware target (for example a keyboard, a mouse, or a MIDI controller board).

At the type level, a device is defined by implementing the Device trait.

Responsibilities

A device type defines the hardware-specific foundation used by the rest of the framework:

  • Microcontroller: The microcontroller type and its configuration.
  • Storage: The storage configuration used for persistent storage. The storage type itself is determined by the MCU's McuCreator implementation for that configuration.
  • External transport: The external transport implementation and its configuration. See External Transports.
  • Internal transport: The internal transport implementation and its configuration. See Internal Transports.

INFO

While the device should provide sensible defaults for microcontroller, storage, and transport configuration, these values can still be overridden through the lokey::device macro when needed.

Additionally, a device type defines which components it supports and provides each component with the required hardware resources through the ComponentSupport trait. For example, when adding support for lokey_keyboard::Scanner, the implementation provides the microcontroller pins connected to the keys.

See the next chapter for more information about components and the ComponentSupport trait.

Example

use lokey::Device;
use lokey::external::NoMessage;
use lokey::storage::DefaultStorageConfig;
use lokey_nrf::Nrf;

pub struct MyDevice;

impl Device for MyDevice {
    type Mcu = Nrf;
    type StorageConfig = lokey::storage::DefaultStorageConfig;
    type ExternalTransport = lokey_usb::external::Transport<Nrf, MyMessage, NoMessage>;
    type InternalTransport = lokey::internal::empty::Transport<Nrf>;

    // Optional
    fn mcu_config() -> embassy_nrf::config::Config {
        Default::default()
    }

    fn storage_config() -> Self::StorageConfig {
        DefaultStorageConfig {
            flash_page_range: 0xF0..0x100,
        }
    }

    fn external_transport_config() -> <Self::ExternalTransport as lokey::external::Transport>::Config {
        Default::default()
    }

    fn internal_transport_config() -> <Self::InternalTransport as lokey::internal::Transport>::Config {
        lokey::internal::empty::TransportConfig
    }
}

Multi-part devices

For multi-part device setups (e.g. split keyboards), each part should be modeled as its own device type.

On this page