-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Tracking issue for ADC trait #377
Comments
the updated ADC peripherals would seem to have very similar constraints as sharing as a bus; one ADC peripheral with multiple channels that may be used in different places, and a need to be able to take ownership of the peripheral for more complex behaviors like interleaving or DMA. (i think this is also relevant to our previous timer / delay traits, though these do not always need to be exclusive you also often need to be able to duplicate delays or split timers into multiple drivers) |
Maybe having a trait for an "ADC device" is not really needed? We could just have this
If the hardware has a single multi-channel ADC it's up to the implementors to do the "sharing" for it. Via RefCell, Mutex, or whatever. Or it could be even a noop for MCU peripheral ADCs: hit the registers directly from
I don't think making traits for these is feasible, they're incredibly hardware dependent... |
what i'm mostly wondering is whether this is a consistent problem with spi / i2c / adc / etc. that we can extract in a consistent way, but yeah seems to me like
agreed, but the in the spi model you can still take exclusive ownership of the bus and do whatever is needed via the closure based approach. |
A complication in the case of ADCs is that some channel combinations can be configured to work in comparison mode, where the measurements taken correspond to the difference between two (otherwise-independent) channels. |
I'd strongly vote for a read() interface for ADC as this would abstract away how the ADC is connected. Could be a GPIO or via SPI. |
I would like to propose making the result type generic. Perhaps the vast majority of the time it's a u32, but making it such that it can be any unsigned would make this trait more universally applicable. |
So something like this, perhaps? trait AdcChannel {
/// The underlying word type for ADC conversions.
///
/// Typically, this is `u32` or `u16`.
type Word: Sized + Copy;
}
trait AdcChannelOneshot : AdcChannel + ErrorType {
/// Returns a single raw ADC reading.
///
/// Calling this method will initiate an ADC conversion,
/// block until that conversion is complete, and then return
/// the raw result (or an error).
///
/// The units are dependent on the hardware configuration,
/// and are outside of the scope of this trait.
fn read_oneshot(&mut self) -> Result<<Self as AdcChannel>::Word, <Self as ErrorType>::Error>;
}
trait AdcChannelOneshotMv : AdcChannel + ErrorType {
/// Returns a single ADC reading in millivolts.
///
/// Calling this method will initiate an ADC conversion,
/// block until that conversion is complete, and then return
/// the result (or an error).
fn read_oneshot_mv(&mut self) -> Result<<Self as AdcChannel>::Word, <Self as ErrorType>::Error>;
} And maybe some async versions: trait AdcChannelOneshotAsync : AdcChannel + ErrorType {
fn poll_read_oneshot(&mut self, cx: &mut Context<'_>)
-> Poll<Result<<Self as AdcChannel>::Word, <Self as ErrorType>::Error>>;
}
// Include traits like `AdcChannelOneshotAsyncExt` (to provide an
// `async_read_oneshot()` method and a `AdcChannelOneshotAsyncFuture`
// struct that would be returned by `async_read_oneshot()`... Having the ability to at least have reads be abstracted away helps make my code portable, so something like this would be very useful. |
The
ADC
traits (adc::Channel
andadc::OneShot
) available on the 0.2.x versions have been removed ahead of the 1.0.0 release. See: #376This issue servers as a tracking issue until we add them back/reject them.
The reasons were:
nb
-only.ADC traits as of the 0.2.7 release:
Relevant issues/PRs:
Adc
API #10Please feel free to participate, highlight your current use cases, problems and provide solutions.
The text was updated successfully, but these errors were encountered: