TeXitoi / keyberon

A rust crate to create a pure rust keyboard firmware.
MIT License
1.08k stars 79 forks source link

Why the move to "fully const layouts"? #88

Open riskable opened 2 years ago

riskable commented 2 years ago

This change has been a nightmare for me so I'm curious what benefit it provides? My code used to be able to take simple arguments like:

pub fn event_scanner(
    config: &mut Config,
    layout: &mut Layout<CustomActions>,
    states: &mut PeripheralStates,
    now: Instant<u64, 1, 1000000>,
) { do_stuff_here() }

Now I have to change all my functions that deal with layout to be like this:

pub fn event_scanner<const C: usize, const R: usize, const L: usize>(
    config: &mut Config,
    layout: &mut Layout<C, R, L, CustomActions>,
    states: &mut PeripheralStates,
    now: Instant<u64, 1, 1000000>,
) { do_stuff_here() }

Also, whenever an end user implementing my firmware for a specific board wants to call one of these functions they have to make a complicated call like this:

action.execute::<16, 3, 4>(config, layout, states, now);

...and know ahead of time (somehow) how many layers their end users will have configured (they'll know how many rows/columns since that'll be specific to their hardware). It's super unergonomic and rather inflexible.

TeXitoi commented 2 years ago

@Skelebot ?

For reference, the corresponding PR: https://github.com/TeXitoi/keyberon/pull/67