variegated-board-cfg

Crates.iovariegated-board-cfg
lib.rsvariegated-board-cfg
version0.1.2
sourcesrc
created_at2024-10-08 20:37:25.275184
updated_at2024-10-08 20:40:40.35313
descriptionStore pin and other HAL configurations for your embedded project in a TOML file.
homepage
repositoryhttps://github.com/variegated-coffee/variegated-board-cfg
max_upload_size
id1401662
size11,239
Magnus Nordlander (magnusnordlander)

documentation

README

Variegated Board Cfg

Substantial credits go to James Munns for the toml-cfg crate, Adam Greig for the assign-resources crate, and Adin Ackerman for the procedural overhaul PR for assign-resources.

Example configuration

lib.rs

#[variegated_board_cfg::config_section("hid_bus")]
struct HidBus {
    tx_pin: (),
    rx_pin: impl embassy_rp::peripherals::Pin, // Forces a compile error if the type of rx_pin doesn't implement Pin
    uart: (),
    baud_rate: u32,
}

board-cfg.toml

[hid_bus]
tx_pin = "embassy_rp::peripherals::PIN_0"
rx_pin = "embassy_rp::peripherals::PIN_1"
uart = "embassy_rp::peripherals::UART0"
baud_rate = 115200

Expansion

type HidBusTxPin = embassy_rp::peripherals::PIN_0;
type HidBusRxPin = embassy_rp::peripherals::PIN_1;
type HidBusUart = embassy_rp::peripherals::UART0;

struct HidBus {
    tx_pin: HidBusTxPin,
    rx_pin: HidBusRxPin,
    uart: HidBusUart,
    baud_rate: u32,
}

impl HidBus where HidBusRxPin: embassy_rp::peripherals::Pin {

}

macro_rules! hid_bus {
    ($P : ident) => {
        HidBus {
            tx_pin: $P.PIN_0,
            rx_pin: $P.PIN_1,
            uart: $P.UART0,
            baud_rate: 115200
        }
    };
}

Commit count: 5

cargo fmt