-
Notifications
You must be signed in to change notification settings - Fork 25
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
add PwmPin
mock
#52
add PwmPin
mock
#52
Conversation
this contains some basic test coverage using `embedded-hal-mock` but requires dbrgn/embedded-hal-mock#52 to support the `PwmPin` trait. for the time being the PR branch is being used as a git dependency, this should be changed back to a normal dependency once the PR has been merged and a new release of `embedded-hal-mock` has been published.
The (Note: I'm happy to merge PRs for 0.2 as well, but that mock will become obsolete once e-h 1.0 is out.) |
hm, i wasn't aware of that (never looked into e-h 1.0 so far). i'll have to dig into that (probably in the next few days). |
I think |
@dbrgn: i've updated the PR a while ago so that it now should build fine with rust 1.31. i've also pushed the e-h 1.0 ticket but so far no updates there. would it be ok for you to take this into 0.x for the time being? based on the e-h discussions it seems that some form of |
@dbrgn any chance that you could already review this for e-h 0.x while the e-h 1.x discussion is ongoing? as e-h 1.x will anyway look differently it'll require a different implementation here (if i don't forget i'll probably provide it here as well once a solution lands in e-h 1.x). |
Sorry, I missed your original comment. Thanks for the reminder! I'll take a look tonight. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments. Once these things are fixed, I can tag a new release soon!
this extends the `Pin::Mock` to also cover the [`PwmPin`][] trait. some observations on this commit: * i took the liberty of just hardcoding the `PwmPin::Duty` to be an `u16` (wrapped in the `PwmDuty` type because it's used in other places here in the module as well). i don't see an easy way to make this configurable because i'd have to add it as a generic attribute to `Pin` and then it'd have to be defined by everyone using it (unnecessary for all non-PWM use-cases). but i think this should be acceptable as `u16` probably covers most/all use-cases. * the current code features quite some code duplication (essentially the method check implementations are all the same for all setters / all getters). i've continued this for now but it might be worth a refactoring in the future (i haven't touched it because i'm not sure if there's some strategic decision behind this?) * there's a `TransactionKind::is_get` API for which i don't really see the reason (why not just check it directly?). i've decided to not copy that approach for the others as it'd IMHO just bloat the code and i'd instead suggest to remove `TransactionKind::is_get` at a later point. * `PwmPin` only exists on `embedded-hal` 0.x, it is currently missing from the planned 1.0 release. see rust-embedded/embedded-hal#358 for the discussion on this. once it has (hopefully) been re-added there a corresponding mock can be provided here also for 1.x. [`PwmPin`]: https://docs.rs/embedded-hal/0.2.7/embedded_hal/trait.PwmPin.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your review! i've fixed all your findings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻 thanks for the updates!
@rursprung 0.9.0 is released! |
this extends the
Pin::Mock
to also cover thePwmPin
trait.some observations on this commit:
PwmPin::Duty
to be anu16
(wrapped in thePwmDuty
type because it's used in otherplaces here in the module as well). i don't see an easy way to make
this configurable because i'd have to add it as a generic attribute to
Pin
and then it'd have to be defined by everyone using it(unnecessary for all non-PWM use-cases). but i think this should be
acceptable as u16 probably covers most/all use-cases.
method check implementations are all the same for all setters / all
getters). i've continued this for now but it might be worth a
refactoring in the future (i haven't touched it because i'm not sure
if there's some strategic decision behind this?)
TransactionKind::is_get
API for which i don't really seethe reason (why not just check it directly?). i've decided to not copy
that approach for the others as it'd IMHO just bloat the code and i'd
instead suggest to remove
TransactionKind::is_get
at a later point.PwmPin
only exists onembedded-hal
0.x, it is currently missingfrom the planned 1.0 release. see Tracking issue for PWM traits rust-embedded/embedded-hal#358 for
the discussion on this. once it has (hopefully) been re-added there a
corresponding mock can be provided here also for 1.x.