therealprof / display-interface

Rust crates providing a generic interface for display drivers and some default implementations (GPIO, SPI and I2C)
Apache License 2.0
73 stars 27 forks source link

No way to force pin states for low power mode #4

Closed bugadani closed 4 years ago

bugadani commented 4 years ago

Hi!

On my board I need to be able to coerce the D/C and CS pins to a low or floating state before entering shutdown mode. It would be nice to have some means to do this, either by deconstructing the interface and getting back the pins, or having some sort of power state control built in that is able to power down the display somehow.

I guess this is a request that basically needs to bubble up to ~embedded-graphics~ the (in my case) SSD1306 driver as well...

Edit well I found a workaround, when the SSD1306 driver will get a release based on this library, sending the display on command will allow me to work around my "issue".

therealprof commented 4 years ago

Well, embedded-graphics really doesn't have any control over the display, that'd be something the display driver has to implement. But it the display-interface drivers should have a release function which gives the pins back.

I guess if you know what you're doing you could make the pins the floating before going to sleep and setting them back up into the correct mode after waking up.

Patches to implement release on the D-I drivers would be very welcome.

bugadani commented 4 years ago

embedded-graphics really doesn't have any control over the display

Right.

I have found a workaround but I'll think about how to implement this in the coming days. Thanks!

almindor commented 4 years ago

This is a bit of a mess since some pins/interfaces are owned by the DI and some are owned by the driver and it differs by type (e.g. DI::spi vs DI::i2c etc.)

I think the most straightforward solution would be for each DI to have a deconstructor, possibly forced by the trait (not sure how viable this is since each DI has a different list of things to return).

As for the drivers they would need to deconstruct into DI + anything extra so to get the full primitives list you'd do (as a SPI DI + RST in driver example):

let (di, rst) = driver.release();
let (spi, dc) = di.release();
almindor commented 4 years ago

I've just release v0.4.1 of the ST7789 driver with a release function returning the DI and RST pin like described above.

therealprof commented 4 years ago

I think the most straightforward solution would be for each DI to have a deconstructor, possibly forced by the trait (not sure how viable this is since each DI has a different list of things to return).

I don't see any way to turn that into a trait but I fully agree with the assessment.

therealprof commented 4 years ago

Also released new patch versions of the included DI impls with the new release() method.

almindor commented 4 years ago

We could enforce this by way of associated type as described here: https://users.rust-lang.org/t/trait-enforced-deconstruction/42768

Not sure if it's worth doing tho since it complicates the traits.

therealprof commented 4 years ago

You mean as proposed by #6? ;)

I don't see any benefit of this as there's no internal use of the Deconstructable trait.