I have a chunk of code that toggles different functions on hardware pins,
that looks like this:
enum Function {
GPIO = 0,
F1 = 1,
F2 = 2,
F3 = 3,
}
fn set_mode(port: u8, pin: u8, fun: Function)
What I would like to have is an enum of human-readable values instead of
F1/F2/F3, e.g. for port 0, pin 0 I would like to have options of GPIO, RD1,
TXD3, SDA1, for port 0, pin 2 the options would be GPIO, TXD0, AD0.7, - (F3
missing).
I assume it would be possible to have a big enum of function names, that I
would later on map to function index, something like
let fun_idx: u8 = FUNCTIONS[port][pin][fun]
which is what C/C++ developers usually do (
https://github.com/arduino/Arduino/blob/master/hardware/arduino/variants/leonardo/pins_arduino.h--
the thing I don't like about arduino). I would really like to have
this
routing to be done in compile time, as it's just a plain waste of cycles
otherwise. Also, I would like to use static_assert to verify that the
selected function name is actually available for given port/pin combo.
Any ideas?
--
Sincerely,
Vladimir "Farcaller" Pouzanov
http://farcaller.net/
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev