Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use enum_from_bits #311

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 49 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ debug = "line-tables-only"

[patch.crates-io.maitake]
git = "https://github.com/hawkw/mycelium.git"
rev = "101a4abaa19afdd131b334a16d92c9fb4909c064"
rev = "13d0722429ef201f38e4ea47ea22d88f3f72c10e"

[patch.crates-io.mycelium-util]
git = "https://github.com/hawkw/mycelium.git"
rev = "101a4abaa19afdd131b334a16d92c9fb4909c064"
rev = "13d0722429ef201f38e4ea47ea22d88f3f72c10e"

# Use the `mycelium-bitfield` crate from the Mycelium monorepo rather than
# crates.io.
Expand All @@ -158,11 +158,11 @@ rev = "101a4abaa19afdd131b334a16d92c9fb4909c064"
# having both a Git dep and a crates.io dep seems unfortunate.
[patch.crates-io.mycelium-bitfield]
git = "https://github.com/hawkw/mycelium.git"
rev = "101a4abaa19afdd131b334a16d92c9fb4909c064"
rev = "13d0722429ef201f38e4ea47ea22d88f3f72c10e"

[patch.crates-io.cordyceps]
git = "https://github.com/hawkw/mycelium.git"
rev = "101a4abaa19afdd131b334a16d92c9fb4909c064"
rev = "13d0722429ef201f38e4ea47ea22d88f3f72c10e"

[patch.crates-io.bbq10kbd]
git = "https://github.com/hawkw/bbq10kbd"
Expand All @@ -180,4 +180,4 @@ rev = "5a8be302b4049a6ebc17bd712d97c85a9fd83f76"

[patch.crates-io.esp-hal-procmacros]
git = "https://github.com/esp-rs/esp-hal"
rev = "5a8be302b4049a6ebc17bd712d97c85a9fd83f76"
rev = "5a8be302b4049a6ebc17bd712d97c85a9fd83f76"
4 changes: 2 additions & 2 deletions platforms/allwinner-d1/d1-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sharp-display = []
[dependencies]
serde = { version = "1.0.178", features = ["derive"], default-features = false }
mnemos-bitslab = { path = "../../../source/bitslab" }
mycelium-bitfield = "0.1.3"
mycelium-bitfield = "0.1.5"

d1-pac = "0.0.31"
critical-section = "1.1.1"
Expand Down Expand Up @@ -46,4 +46,4 @@ default-features = false

[dev-dependencies]
proptest = "1"
proptest-derive = "0.4.0"
proptest-derive = "0.4.0"
47 changes: 2 additions & 45 deletions platforms/allwinner-d1/d1-core/src/drivers/twi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,52 +679,9 @@ impl TwiData {

unsafe impl Sync for IsrData {}

// TODO(eliza): this ought to go in `mycelium-bitfield` eventually
macro_rules! enum_try_from {
(
$(#[$meta:meta])* $vis:vis enum $name:ident<$repr:ty> {
$(
$(#[$var_meta:meta])*
$variant:ident = $value:expr
),* $(,)?
}
) => {
$(#[$meta])*
#[repr($repr)]
$vis enum $name {
$(
$(#[$var_meta])*
$variant = $value
),*
}


impl core::convert::TryFrom<$repr> for $name {
type Error = &'static str;

fn try_from(value: $repr) -> Result<Self, Self::Error> {
match value {
$(
$value => Ok(Self::$variant),
)*
_ => Err(concat!(
"invalid value for ",
stringify!($name),
": expected one of [",
$(
stringify!($value),
", ",
)* "]")
),
}
}
}
};
}

enum_try_from! {
mycelium_bitfield::enum_from_bits! {
/// Values of the `TWI_STAT` register.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
enum Status<u8> {
/// 0x00: Bus error
BusError = 0x00,
Expand Down
2 changes: 1 addition & 1 deletion platforms/beepy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ features = ["async-await"]
default-features = false

[dependencies.mycelium-bitfield]
version = "0.1.2"
version = "0.1.5"
4 changes: 2 additions & 2 deletions source/kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ default-features = false
version = "0.6.1"

[dependencies.mycelium-bitfield]
version = "0.1.2"
version = "0.1.5"

[build-dependencies]
vergen = { version = "8.0.0", features = ["cargo", "git", "gitcl", "rustc",] }
Expand All @@ -153,4 +153,4 @@ features = ["fmt", "env-filter"]

[dev-dependencies.postcard]
version = "1.0.1"
features = ["use-std"]
features = ["use-std"]
Loading