Skip to content

Conversation

JalonWong
Copy link

Fix #119

@JalonWong JalonWong requested a review from a team as a code owner August 18, 2025 15:29
@JalonWong JalonWong changed the title Add mutex-trait-based implementations of SpiDevice and I2c Add mutex-traits-based implementations of SpiDevice and I2c Aug 18, 2025
@FeldrinH
Copy link

What exactly are the mutex/mutex-trait crates? I took a quick peek at them and they don't really seem to be used by anything in the ecosystem and are maintained under the tosc-rs GitHub organization (which I have never heard of before), rather than rust-embedded.

@JalonWong
Copy link
Author

JalonWong commented Aug 21, 2025

@FeldrinH
There is a mutex-trait under rust-embedded, but it's archived. It recommends the mutex-traits. I found it decent, so I suggest that you consider bringing it into the ecosystem.

@@ -37,6 +37,7 @@ embedded-hal-async = { version = "1.0.0", path = "../embedded-hal-async", option
critical-section = { version = "1.0" }
defmt-03 = { package = "defmt", version = "0.3", optional = true }
portable-atomic = {version = "1.3", default-features = false, optional = true, features = ["require-cas"]}
mutex = "1.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused:

The mutex crate itself contains the following explanation of the relationship between mutex and mutex-traits:

The mutex-traits crate should be used by library crates that want to be generic over different ways of exclusive access.

The mutex crate should be used by applications that need to select which implementation is appropriate for their use case.

As embedded-hal-bus is a library, shouldn't it depend on mutex-traits?

But then, I don't get how code like MutexTraitsDevice implementations should be written without using the mutex crate. So this is more likely a documentation issue in mutex and mutex-traits (or just me being particularly slow today) than an actual issue with this pull request.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mutex-traits is used in the library that wants to provide a mutex implementation. For example a RTOS library. embedded-hal-bus should use mutex crate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generic Mutex Trait
3 participants