Skip to content
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

Allow reclaiming display pins #118

Merged

Conversation

bugadani
Copy link
Contributor

@bugadani bugadani commented May 25, 2020

  • Check that you've added documentation to any new methods
  • Rebase from master if you're not already up to date
  • Add or modify an example if there are changes to the public API
  • Add a CHANGELOG.md entry in the Unreleased section under the appropriate heading (Added, Fixed, Changed, etc)
  • Run rustfmt on the project with cargo fmt --all - CI will not pass without this step
  • Check that your branch is up to date with master and that CI is passing once the PR is opened

PR description

Hi!

I have a device that can physically cut supply to the display. In order to do that, I must ensure that the pins are floating or low, so I must be able to deconstruct the display driver to reclaim the pins.

This is a no-brainer implementation of the above functionality. Any feedback is welcome, if there is a better place to do this, or if the feature is already there but I'm blind. I've also bumped the display-interface dependencies because I rely on those as well.

Other todo items will be checked once this PR can get a green light.

Thank you :)

@jamwaffles
Copy link
Collaborator

Hi, sorry for the late review! Two issues I found while testing this PR:

  1. You actually end up needing to call disp.release().release() to free up the interface, however...
  2. ... ssd1306::mode::displaymode::DisplayModeTrait must be imported for the first release() to be resolved.

@therealprof Do you have any thoughts on this?

@therealprof
Copy link
Collaborator

I think either way should be fine (single or double-release that is).

@bugadani
Copy link
Contributor Author

In fact, to release everything, I need 3 :)

let interface = graphics_mode.release().release();
let (spi, dc, cs) = interface.release();

Personally, I don't mind these. It's kind of an onion that we have to peel, but in the end, everything should release just its own resources IMO.

Although, on second thought, the user doesn't necessarily face/know about the DisplayProperties object that is returned by GraphicsMode::release() - it was actually a surprise for me, I thought, based on the Builder interface, that the SPIInterface object would be returned...

Anyway, this PR is kind of the minimal change to implement a functionality I need, without breaking existing API. I admit, using it is kinda unwieldy.

@jamwaffles
Copy link
Collaborator

In fact, to release everything, I need 3 :)

Ah jeez that's not good 😂

Although, on second thought, the user doesn't necessarily face/know about the DisplayProperties object that is returned by GraphicsMode::release()

Yeah, it's a somewhat internal object to the driver, even though it's pub.

How about changing DisplayModeTrait<DI>::release to free the actual interface resource and add DisplayModeTrait<DI>::into_mode<MODE: DisplayModeTrait<DI>>(self) -> MODE to convert display modes?

@bugadani
Copy link
Contributor Author

My concern with that is breaking existing code. But if you think that can be justified, it sounds fine.

@jamwaffles
Copy link
Collaborator

I'd be ok with that personally. I don't think the current release method is used much/at all in the wild. @therealprof might have a different opinion though

@therealprof
Copy link
Collaborator

I think it is wildly used but I don't mind breakage for quality-of-life improvements at all. In the end we're still learning and evolving the whole ecosystem quite a bit...

@bugadani
Copy link
Contributor Author

All right, I'll cook something up soon :) Thanks!

@bugadani
Copy link
Contributor Author

bugadani commented May 27, 2020

I've implemented release as discussed, but not into_mode yet. Currently, DisplayMode has a similar into method that is used to covert the object that Builder returns, but nothing else. I wonder if DisplayMode shouldn't be removed and the Into trait implemented for DisplayModeTrait object.

Also, this still needs use ssd1306::mode::displaymode::DisplayModeTrait

@bugadani bugadani marked this pull request as draft May 27, 2020 11:17
@therealprof
Copy link
Collaborator

Yeah, I guess we can remove some more layers some time.

@bugadani bugadani mentioned this pull request May 27, 2020
6 tasks
@bugadani bugadani force-pushed the feature/dep-update branch 2 times, most recently from 0c9a13e to 90f67a1 Compare May 27, 2020 15:16
@bugadani bugadani marked this pull request as ready for review May 27, 2020 15:16
@bugadani bugadani mentioned this pull request May 28, 2020
6 tasks
@therealprof
Copy link
Collaborator

@jamwaffles How do we want to proceed with this with #119 in mind? Land it before or defer until #119 is in?

@jamwaffles
Copy link
Collaborator

I don't have a lot of bandwidth to check the conflicts at the moment, but my gut feeling would be to land #119 first

@bugadani
Copy link
Contributor Author

bugadani commented Jun 7, 2020

This doesnt have conflicts and 119 is easy to rebase, but their order matters little IMO

Copy link
Collaborator

@jamwaffles jamwaffles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After another quick look, I think we should rename .properties() to .into_properties() or something else that conveys the consumption of the display into a Properties object. Currently, .properties() sounds to me like it should return a reference or something else non-destructive.

@bugadani
Copy link
Contributor Author

bugadani commented Jun 7, 2020

I think we should rename .properties() to .into_properties()

Agreed & done.

@bugadani bugadani force-pushed the feature/dep-update branch from 5797b98 to 3a84fce Compare June 8, 2020 08:36
@bugadani
Copy link
Contributor Author

bugadani commented Jun 8, 2020

uh I didn't notice 08a7b70 accidentally made it in #119... sorry about that, I guess I messed up rebasing :/ Anyway, I updated this one failed to update this one, looks like

Copy link
Collaborator

@jamwaffles jamwaffles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some small issues

CHANGELOG.md Outdated Show resolved Hide resolved
src/mode/graphics.rs Outdated Show resolved Hide resolved
src/mode/terminal.rs Outdated Show resolved Hide resolved
src/mode/displaymode.rs Outdated Show resolved Hide resolved
Co-authored-by: James Waples <[email protected]>
@bugadani bugadani force-pushed the feature/dep-update branch from 9a2dd19 to 91c5249 Compare June 8, 2020 08:47
@jamwaffles jamwaffles merged commit 385b903 into rust-embedded-community:master Jun 8, 2020
@jamwaffles
Copy link
Collaborator

Thanks!

@bugadani bugadani deleted the feature/dep-update branch June 8, 2020 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants