-
Notifications
You must be signed in to change notification settings - Fork 230
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
ADC API does not allow non-unit channels #110
Comments
I made the choice but it wasn't based on any kind of a deep analysis, it was just how it shook out (and, for me, it worked). I'm 100% in favor of this change, and afaik nobody else has impl'd these traits so imo the sooner the better to minimize breakage. Perhaps this change could get wrapped into #100? |
Hi, I am also trying out these traits in a driver I started for ADS1x1x ADCs. It is a bit cumbersome but the benefit for this driver is that the What is ugly is that the internal enum needs to be public (although I hid it in the docs and the user could not do much with it) because it is part of the public interface through the EDIT: The channel reference being mutable is also something that looks weird in my use case: let measurement = block!(adc.read(&mut channel::DifferentialA0A1)).unwrap(); |
For a bit of context about why the channel method even exists, it’s due to this bug |
Adding a It is both v new and unproven (#10, #101 ), I think this is exactly the situation @rust-embedded/hal maybe a quick vote before going down either path?
|
It looks like #192 made this situation less likely to be addressed, since it removed the associated function entirely in favor of an associated constant. @eldruin or @ryankurte, is it fair to assume that this issue will not be resolved any time soon? |
Uh, thank you for bringing this up. Would it be necessary for the reference to be mutable? |
@eldruin Oh good to hear. For my part I don't think the reference needs to be mutable, it's simply to support a generic pin enum that would dispatch to the appropriate concrete pin type. The assumption that a concrete pin has a static channel is still valid. My reading of the OP's report is that a shared reference would be sufficient there, too, but @chrysn perhaps if you're still following this issue you'd like to weigh in? One concern I have is that by forcing all usage through a dynamic code path, there would be a runtime cost even in the common, static case. There are a few too many moving pieces for me here for me to convince myself one way or the other. |
If the returned value is just meant to be an ID I don't see why it would need mutability. In fact I'd say mutability would give the implementation power it should not have. The ID should be an inert value and the
I'm pretty sure the static case will always get optimized out. |
I made a PR doing this at #242. |
I got fired from my last job in the embedded space and have been taking a hiatus from embedded Rust, but this PR has gotten me to pick it back up. I'm glad to see it getting some love. :) |
I'm just implementing the unproven ADC traits for RIOT and found an issue with Channel::channel:
As the channel() function does not even take a &self reference, there can't be implementations of it that are not fully contained in the type (ie. only really works for zero-sized types). Now the zero-sized types are a major plus of embedded Rust, but this signature precludes the use of eg. numeric channels as would be convenient when wrapping an operating system's ADCs.
I suggest adding a &self or &mut self argument to the .channel() function to make it usable as a method.
I don't understand the rationale behind there not being a self argument in or the existence of the channel method at all there in the first place, so I can't tell what it breaks. The example in the OneShot trait would need to say
_pin.channel()
instead ofPIN::channel()
-- but also there I don't see the rationale for not doing that in the first place.(For the RIOT wrappers, until I can publish the code I'd like to point to, things look like this:
)
The text was updated successfully, but these errors were encountered: