caemor / epd-waveshare

Drivers for various EPDs from Waveshare and others
ISC License
225 stars 135 forks source link

How should new devices be added? #168

Closed wsndshx closed 1 year ago

wsndshx commented 1 year ago

I noticed it was mentioned in #26

Steps that need to be done to add a display generally: (e.g for the 4in2 (b)/red one) Get the Command table from the datasheet (e.g here: https://www.waveshare.com/wiki/4.2inch_e-Paper_Module_(B)#Datasheets ) and add it to a command enum like here (https://github.com/caemor/epd-waveshare/blob/master/src/epd4in2/command.rs) in a epd4in2b folder. This can also be found in waveshares new github repo (e.g.: https://github.com/waveshare/e-Paper/blob/master/4.2inch_e-paper_b%26c_code/wiringpi/obj/EPD_4in2b.h but be aware of quite a lot of copy&paste errors like the wrong ifndef epd2in7b at the top and better crosscheck it once more)

Optional: Add the LUT constants (like https://github.com/caemor/epd-waveshare/blob/master/src/epd4in2/constants.rs) if you can find any. But since the color ones only allow the default refresh they are most likely not included in the repos. This is also not too important/optional.

Add following constants from the next four lines to epd4in2b/mod.rs (https://github.com/caemor/epd-waveshare/blob/master/src/epd4in2/mod.rs#L61): width, height, default_background_color (twice for red/black displays?), is_busy_low

Implement WaveshareDisplay and InternalWiAdditions trait for your EPD4in2_Red struct. See https://github.com/caemor/epd-waveshare/blob/master/src/epd4in2/mod.rs#L76 and following for examples and crosscheck it with the waveshare repos for the differences between different devices

The Traits that need to be implemented are explained here: https://github.com/caemor/epd-waveshare/blob/master/src/traits.rs

Maybe some adoptions for either a twice as big sized buffer or double buffers need to be made.

Communication is handled by the DisplayInterface and is working the same through all waveshare displays that I know besides that the busy_low pin is sometimes inverted.

Now you can already draw to the display, but you might want to use the embedded_graphics ;-)

Implement the graphics traits (Drawing & Display) e.g. like here: https://github.com/caemor/epd-waveshare/blob/master/src/epd4in2/graphics.rs

The graphics.rs file is handling most of the graphics stuff for you: https://github.com/caemor/epd-waveshare/blob/master/src/graphics.rs

But most likely there also need to be done some changes for the multicolor display.

Further stuff:

Most likely Red and Yellow Versions of the same size work completely the same and just show a different color (I still need to check that)

Naming of function/traits: If you have better names for some of the traits/functions or think that some don't really match with what they do I am always happy with improvements.

But when I adapted my 2.9inch(d) according to the above steps, I found folders of other similar devices, such as "src\epd2in9" and "src\epd2in9_v2", there is only one " mod.rs" file, but no "command.rs" and "constants.rs" files. Under what circumstances can these two files be ignored?

Some information about the new equipment:

wsndshx commented 1 year ago

hmmm, after cross-comparing their content, I seem to understand!