imxrt-rs/imxrt-hal

Configure/Release

teburd opened this issue · 3 comments

Configuring a peripheral should be undoable in some way to return it back to its default state.

The C SDK does this using _init/_deinit pairs for peripherals, we can probably do this using type states and similar calls, instead perhaps using configure/release as the call pair.

Really we are doing clock, so perhaps unclock is the right term to use here anyways

There's really a few possible States a peripheral may be in beyond clocked, but the goal is the same, a reversal of the peripheral states from Unclocked -> Clocked -> Configured and back

The 0.5 imxrt-hal release drops the (un)clocked states from imxrt-hal type system, and it separates CCM configurations from driver initialization. I think there's room to re-explore these (un)clocked typestate ideas, and I figured this could come later.

Nearly all 0.5 drivers have a release() method to take back ownership of the imxrt-ral instance and other components. Almost all of these methods are documented as "this simply releases the registers / resources as-is." If users want to take back ownership of registers in known, good states, they can do that by first calling reset(), a separate method implemented on drivers.

let mut lpuart = Lpuart::new(inst, pins);

// Use the driver...

lpuart.reset(); // Puts inst into a known reset state.
let (inst, pins) = lpuart.release();

I figured the "release as-is" semantics might be useful for some advanced use-cases. But, beyond driver initialization, there's no explicit guarantees of how the driver manipulates the peripherals, so user who chooses to skip the reset() call may be taking a risk. If this approach doesn't work out, we could combine reset and release into one method.

I think this should be enough to say we have configure / release APIs. Re-open if I'm misunderstanding / didn't hit the mark.


As a separate, somewhat related note: I added APIs to construct / use drivers without imxrt-iomuxc pad objects. This precedent means we don't necessarily need imxrt-iomuxc support to develop new drivers / chips. A driver constructed without pins releases the unit object, ().