Closed GrantM11235 closed 3 years ago
That's a good improvement, I like it.
Nit: Your example impl of set_value
doesn't match the trait definition.
NB: I have been meaning to add support for parallel busses to embedded-hal
but never got to it. Maybe it's time to revive this idea?
Looks like a great alternative to me, but I'll have to say that this still doesn't fully fix #18, because the user can still implement a custom OutputBus
that doesn't drive all pins low when instantiated
@therealprof
That's a good improvement, I like it.
Thanks!
Nit: Your example impl of
set_value
doesn't match the trait definition.
Oops, fixed
NB: I have been meaning to add support for parallel busses to
embedded-hal
but never got to it. Maybe it's time to revive this idea?
An embedded-hal
trait would be great! I saw that there is a digital::OutputPort
RFC, I plan to add some of my thoughts there.
@andresovela
Looks like a great alternative to me
Thanks!
but I'll have to say that this still doesn't fully fix #18, because the user can still implement a custom OutputBus that doesn't drive all pins low when instantiated
The OutputBus
trait doesn't require the bus to have any specific value until the first time that set_value
is called. #18 is fixed for Generic8BitBus
by synchronizing the state of the pins with the value of self.last
, it does this by setting self.last
to all ones before calling self.set_value(0)
which forces all pins to zero regardless of their previous state.
An implementation of OutputBus
that unconditionally sets all pins, like my example, will never exhibit the symptoms of #18
I will be sure to make a note of all of this when I write the docs.
The OutputBus trait doesn't require the bus to have any specific value until the first time that set_value is called. #18 is fixed for Generic8BitBus by synchronizing the state of the pins with the value of self.last, it does this by setting self.last to all ones before calling self.set_value(0) which forces all pins to zero regardless of their previous state.
Yeah I know, I'm not arguing that Generic8BitBus
has the problem described in #18.
An implementation of OutputBus that unconditionally sets all pins, like my example, will never exhibit the symptoms of #18
This is already the case. A user implementing a PGPIO8BitInterface
that unconditionally sets all pins to 0 in the beginning will never see #18.
Anyway, now that I think about it, with your implementation this is a non-issue, because if such a problem comes up it will be the user's fault and not this crate's fault, since the user has the responsibility of implementing this correctly.
Anyway, now that I think about it, with your implementation this is a non-issue, because if such a problem comes up it will be the user's fault and not this crate's fault, since the user has the responsibility of implementing this correctly.
Exactly :wink:
I think this is a great PR. Is this ready to be merged?
It is now! :+1:
Let me know if I should squash anything.
A squash would be nice, yes.
OutputBus
This PR changes
PGPIO8BitInterface
to use a simpleOutputBus
trait instead of a bunch of individual pins:Generic8BitBus
This PR also provides an
OutputBus
implementation that can be constructed from 8OutputPin
s:or
(Note that the construction is fallible because it attempts to set all the pins low, which fixes #18)
Custom OutputBus
For reference, here is an example of an optimized
OutputBus
implementation for an stm32f1 with a bus on pins PB0 through PB7Pros
PGPIO8BitInterface
doesn't take a million arguments anymoreOutputBus
with much higher performanceCons
OutputBus
before they can construct aPGPIO8BitInterface
. This is slightly more verbose, but it is more readable in my opinionTodo