therealprof / display-interface

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

Should this crate allow reading #24

Open VersBinarii opened 2 years ago

VersBinarii commented 2 years ago

LCD controller such as ili9341 allows for reading pixel data (and other useful things) from it. This crate, while great great for simply sending data to display, makes it impossible to read data from it

Should it allow also for reading data

almindor commented 2 years ago

this would have to be a separate trait that the drivers would implement somehow since it's only available for some displays. What else besides pixels data itself would you consider to be useful for reading?

therealprof commented 2 years ago

Pixel data would be super useful to read back from a display internal framebuffer. There's still #12 which attempts to provide the ability to read back. I do think it would be feasible to add traits to allow reading back pixel or control data but the big question would be how a display driver or in extension the application via the display driver could use the data. I can see a few caveats for a truly generic and useful API so if you happen to have a specific usecase or even a complete application reading back from the display I'd really love to see and discuss it.

VersBinarii commented 2 years ago

I'm not trying to be smart and perhaps i'm missing some nuances of driver design but if a chip offers a set of data to be read there has to be a way to get them. @almindor I'm interested mainly in getting the pixel data. However this approach is weird to me a bit. Every register that is exposed for reading in this driver chip could be useful to someone at some stage. Driver should not "kindly" allow me to read some and not the other.

In my more specific case i'm using https://github.com/yuri91/ili9341-rs and https://github.com/VersBinarii/xpt2046. I was thinking of experimenting with the touch driver along with getting the pixel data to build an interactive GUI. So i could read the pixel data at the touch location to handle specific action. This could potentially save me complexity of juggling all GUI elements in memory, dealing with collision detection, etc

I have read through the discussion in https://github.com/therealprof/display-interface/pull/12 but admit i dont fully understand @therealprof reasons for rejecting it.

Anyway thanks for your work in this area and if this crate is not usefull in this particular case its still applicable to 99% of other cases

almindor commented 2 years ago

@VersBinarii I'm the author of the generic MIPIDSI rust driver. I conflated things a bit here, my main aim was to find out "generic use cases" for reading so I could implement it in the overall driver if the display-interface gets support for it in a trait.

I agree 100% that reading is paramount and that the DI should just provide a generic read function same as the write one right now.

therealprof commented 2 years ago

In my more specific case i'm using https://github.com/yuri91/ili9341-rs and https://github.com/VersBinarii/xpt2046. I was thinking of experimenting with the touch driver along with getting the pixel data to build an interactive GUI. So i could read the pixel data at the touch location to handle specific action. This could potentially save me complexity of juggling all GUI elements in memory, dealing with collision detection, etc

Not sure how this would work. How can you reverse engineer which GUI element the user clicked on by reading back the pixel color?

I have read through the discussion in #12 but admit i dont fully understand @therealprof reasons for rejecting it.

The problem is we need a universal trait that works with different peripheral interfaces in a useful way without complicating lives for everyone not requiring this ability.

The reason why I'm asking how you intend to use the ability to read back pixel data is because most of our users are using embedded-graphics to render graphics primitives (or even whole user interfaces) onto the display; as far as I'm aware there's no way to use an external in-display framebuffer with that.

I know a few people who would be very excited (including me) to add the ability to use a in-display framebuffer but I don't think anyone has invested the required brainpower to come up with a real use case and a high level concept to implement such a use case. This would help immensly to identify the stumble blocks.

Reading a single value might be an easy addition, but once you enter the world of iterators or sized arrays things get complicated very quickly and that's what we need.

VersBinarii commented 2 years ago

Reading a single value might be an easy addition, but once you enter the world of iterators or sized arrays things get complicated very quickly and that's what we need.

Then maybe this could be the start which will get people to use it and see where this leads ;) Anyway, i see your point.

@almindor I see. I misunderstood your question then.

therealprof commented 2 years ago

Then maybe this could be the start which will get people to use it and see where this leads ;)

It's super inefficient, I doubt people would even care about that enough to start using it.

almindor commented 2 years ago

I'm wondering if we should leave this issue open as a discussion place for this. I think reading will become required, might be a good idea to have a dedicated place to put in ideas on how to best handle it.

therealprof commented 2 years ago

I agree. Let's keep it open.