Skip to content

Commit c21f4e4

Browse files
committed
refac(d1): use mycelium_bitfield enum_from_bits (#311)
There's a comment in the TWI driver on a sui generis "generate `FromBits` for enums" macro saying "this should be in the `mycelium-bitfield` crate". It is now in that crate, so we should just use that.
1 parent e909aee commit c21f4e4

File tree

1 file changed

+2
-45
lines changed
  • platforms/allwinner-d1/d1-core/src/drivers

1 file changed

+2
-45
lines changed

platforms/allwinner-d1/d1-core/src/drivers/twi.rs

+2-45
Original file line numberDiff line numberDiff line change
@@ -679,52 +679,9 @@ impl TwiData {
679679

680680
unsafe impl Sync for IsrData {}
681681

682-
// TODO(eliza): this ought to go in `mycelium-bitfield` eventually
683-
macro_rules! enum_try_from {
684-
(
685-
$(#[$meta:meta])* $vis:vis enum $name:ident<$repr:ty> {
686-
$(
687-
$(#[$var_meta:meta])*
688-
$variant:ident = $value:expr
689-
),* $(,)?
690-
}
691-
) => {
692-
$(#[$meta])*
693-
#[repr($repr)]
694-
$vis enum $name {
695-
$(
696-
$(#[$var_meta])*
697-
$variant = $value
698-
),*
699-
}
700-
701-
702-
impl core::convert::TryFrom<$repr> for $name {
703-
type Error = &'static str;
704-
705-
fn try_from(value: $repr) -> Result<Self, Self::Error> {
706-
match value {
707-
$(
708-
$value => Ok(Self::$variant),
709-
)*
710-
_ => Err(concat!(
711-
"invalid value for ",
712-
stringify!($name),
713-
": expected one of [",
714-
$(
715-
stringify!($value),
716-
", ",
717-
)* "]")
718-
),
719-
}
720-
}
721-
}
722-
};
723-
}
724-
725-
enum_try_from! {
682+
mycelium_bitfield::enum_from_bits! {
726683
/// Values of the `TWI_STAT` register.
727-
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
684+
#[derive(Debug, Eq, PartialEq)]
728685
enum Status<u8> {
729686
/// 0x00: Bus error
730687
BusError = 0x00,

0 commit comments

Comments
 (0)