You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current implementation of this driver takes ownership of a Delay in order to block get_compensated_sample() and alike operations. While this is fine as a very simple solution, not all implementations of embedded_hal provide multiple Delay object, e.g. atsamd implementation only provides one Delay which is using Systick as delay provider.
Instead of replacing the API to borrow a Delay whenever an operation need it, the API could be changed to be non-blocking by using a Timer:
It's not clear how to use human time (milliseconds) with the trait CountDown. Most embedded-hal implementations use clock as a time reference, hence Time = Herz. Because external trait cannot be implemented for external types, something like the following is not possible:
mod my_device {pubstructMyDevice<T>(T,)impl<T,U>MyDevice<T>whereT: hal::timer::CountDown<Time=U>U:From<Milliseconds>{pubfnnew(timer:T) -> Self{letmut dev = Self(timer);
dev.start(Milliseconds(3));(dev)}pubfnwait(&mutself) -> Result<(),Void>{(self.timer.wait())}}pubstructMilliseconds(u8);}// ...fnmain(){}// Not possibleimplFrom<my_device::Milliseconds>for hal::Herz{fnfrom(duration: my_device::Milliseconds) -> Self{Herz(duration.0*1000)}}
Adding a conversion trait could be a solution however that doesn't sound really like a good one.
Current implementation of this driver takes ownership of a
Delay
in order to blockget_compensated_sample()
and alike operations. While this is fine as a very simple solution, not all implementations ofembedded_hal
provide multipleDelay
object, e.g. atsamd implementation only provides oneDelay
which is usingSystick
as delay provider.Instead of replacing the API to borrow a
Delay
whenever an operation need it, the API could be changed to be non-blocking by using aTimer
:Where
get_sample``returns
nb::WouldBlock ` as long as a conversion is ongoing, allowing user's code to do other operation in the mean time.The text was updated successfully, but these errors were encountered: