epaper.js icon indicating copy to clipboard operation
epaper.js copied to clipboard

[WIP] Adding Waveshare 12.48

Open clintandrewhall opened this issue 2 years ago • 6 comments

This PR is pretty much WIP until code owners can review and discuss the dependencies. Fixes https://github.com/samsonmking/epaper.js/issues/29

Summary

This PR adds the Waveshare 12.48 display to epaper.js.

IMG_2117

Caveats and Discussion

Dependency on BCM2835

This implementation works with the `` pin interface, but USE_DEV_LIB causes an infinite loop after M1 Busy Free. I haven't been able to get the pins to respond, and it doesn't appear like I'm the only one:

Related: https://github.com/waveshare/12.48inch-e-paper/issues/3

So for my testing, I used both wiringPi and BCM2835... since BCM2835 isn't deprecated, I figured that was the best way to go in the short-term.

Swapped Dimensions

For a reason I can't yet find, HEIGHT and WIDTH have to be swapped to a portrait aspect ratio. If they aren't you get things like overflowing red/black buffers, or flat-out gibberish.

Any advice from @samsonmking et al is, of course, appreciated!

clintandrewhall avatar Mar 01 '22 17:03 clintandrewhall

@clintandrewhall thanks for submitting this PR! I'll find some time to take a close look over the next couple of days.

I appreciate the thorough investigation into the different connectivity options. Too bad USE_DEV_LIB doesn't work... but agreed, sounds like a bug in Waveshare's implementation. Do you need to run as root when using BCM2835?

samsonmking avatar Mar 03 '22 03:03 samsonmking

@samsonmking Yeah, unfortunately. You have to make and install with sudo.

It occurred to me that, with a few changes, this could be maintained separately and "registered" with epaper.js rather than explicitly listed in the deviceMap Then someone could just install the dependencies and use it. Might make it easier to allow other devices in the future. Does that make sense?

If someone has some knowledge of C and how to debug the infinite loops for this device, I'm happy to test and report back!

clintandrewhall avatar Mar 03 '22 17:03 clintandrewhall

@clintandrewhall if you're up for it, I've got a couple thoughts about how we might track down with what's going on with USE_DEV_LIB. It's pretty convenient to be able to avoid external dependencies... especially when building on machines that aren't a Raspberry Pi (like Github Actions).

Few things to try:

  1. Edit RPI_sysfs_gpio.h here and set #define SYSFS_GPIO_DEBUG 1. This should enable additional logging. Please send along the output after rebuilding and re-running.
  2. What's the output of ls /sys/class/gpio? We're looking for a gpio5, which corresponds to EPD_M1_BUSY_PIN. If gpio5 isn't present, what is the output when you execute sudo echo 5 > /sys/class/gpio/export
  3. Can you forward along the output of sudo cat /sys/kernel/debug/gpio?

I was reading up on how the sysfs interface works. Looks like the waveshare code just writes to these files that the system drivers expose. Hopefully it's just something we can configure at the system level to get that pin working.

samsonmking avatar Mar 06 '22 18:03 samsonmking

@samsonmking Yep, here you go:

  1. https://gist.github.com/clintandrewhall/60e00a3f12319b773209999fef25108b
$ ls /sys/class/gpio
export  gpio13  gpio19  gpio24  gpio6        gpiochip504
gpio10  gpio17  gpio22  gpio27  gpiochip0    unexport
gpio11  gpio18  gpio23  gpio5   gpiochip100
$ sudo cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-53, parent: platform/3f200000.gpio, pinctrl-bcm2835:
 gpio-5   (                    |sysfs               ) in  lo
 gpio-6   (                    |sysfs               ) out hi
 gpio-7   (                    |spi0 CS1            ) out hi ACTIVE LOW
 gpio-8   (                    |spi0 CS0            ) out hi ACTIVE LOW
 gpio-10  (                    |sysfs               ) out lo
 gpio-11  (                    |sysfs               ) out lo
 gpio-13  (                    |sysfs               ) out lo
 gpio-17  (                    |sysfs               ) out hi
 gpio-18  (                    |sysfs               ) out hi
 gpio-19  (                    |sysfs               ) in  lo
 gpio-22  (                    |sysfs               ) out lo
 gpio-23  (                    |sysfs               ) out hi
 gpio-24  (                    |sysfs               ) in  lo
 gpio-27  (                    |sysfs               ) in  lo

gpiochip1: GPIOs 100-101, brcmvirt-gpio, can sleep:
 gpio-100 (                    |led0                ) out lo

gpiochip2: GPIOs 504-511, parent: platform/soc:firmware:expgpio, raspberrypi-exp-gpio, can sleep:
 gpio-509 (                    |cam1_regulator      ) out lo
 gpio-511 (                    |led1                ) in  hi

Let me know what you'd like to do next!

clintandrewhall avatar Mar 06 '22 19:03 clintandrewhall

@clintandrewhall have you happend to try building and running the provided c examples from Waveshare? I noticed they do some things in a slightly different order... for instance, clearing the display before displaying a new image. I think you'd:

  1. Edit the Makefile to enable USE_DEV_LIB
  2. In the root of the RaspberryPi/c directory run make
  3. Execute the example with ./epd

That'll help us isolate whether it's a problem with the Waveshare code itself, a driver / permissions issue, or an issue with the epaper.js implementation.

It looks like there is an updated fork of WiringPi. If we can't get DEV_LIB working, or it's too slow, that could be a viable option. I used WiringPi for this project in the past (before it was deprecated) and it didn't require any root privileges.

samsonmking avatar Mar 06 '22 22:03 samsonmking

@samsonmking I turned set SYSFS_GPIO_DEBUG to 1 and did as you said above, and it completely stalls after e-Paper clear...

The output is:

./epd
12.48inch e-Paper B demo
Write and read GPIO
Debug: Export: Pin11
Debug: Pin11:Output
Debug: Export: Pin10
Debug: Pin10:Output
Debug: Export: Pin8
Debug: Set Direction failed: Pin8
Debug: Export: Pin7
Debug: Set Direction failed: Pin7
Debug: Export: Pin17
Debug: Pin17:Output
Debug: Export: Pin18
Debug: Pin18:Output
Debug: Export: Pin13
Debug: Pin13:Output
Debug: Export: Pin22
Debug: Pin22:Output
Debug: Export: Pin6
Debug: Pin6:Output
Debug: Export: Pin23
Debug: Pin23:Output
Debug: Export: Pin5
Debug: Pin5:intput
Debug: Export: Pin19
Debug: Pin19:intput
Debug: Export: Pin27
Debug: Pin27:intput
Debug: Export: Pin24
Debug: Pin24:intput
Debug: Write failed : Pin8,value = 1
Debug: Write failed : Pin7,value = 1
Debug: Write failed : Pin8,value = 1
Debug: Write failed : Pin7,value = 1
Debug: Write failed : Pin8,value = 0

with Debug: Write failed : Pin[7 or 8],value = [0 or 1] just repeating over and over again. Eventually it adds e-Paper init... and e-Paper clear..., but will just spit out the failed writes until I kill it.

clintandrewhall avatar Mar 07 '22 02:03 clintandrewhall