Xinyuan-LilyGO / LilyGo-EPD47

GNU General Public License v3.0
415 stars 122 forks source link

Touch works right - Making full class with events support #30

Closed martinberlin closed 3 years ago

martinberlin commented 3 years ago

Hi there @lewisxhe I'm trying to implement the touch for this epaper in my IDF component (For parallel is also based on EPDiy)

I started simply adding this repository as a library and compiled first the grayscale to confirm it works good. Connected the touch like described from Lilygo in a video and compiled touchtest demo adding a single like to print coordinates:

// Just after the getPoint(x, y, 0) call: Serial.printf("X:%d Y:%d\n", x, y);

All what I get in Serial is this:

X:495 Y:242
X:495 Y:242
X:493 Y:241
X:488 Y:239
readBytes error! -> Mostly happening after pressing one of the buttons
X:0 Y:540
readBytes error!
X:0 Y:540 
// From time to time something like this comes:
X:33 Y:62876 -> Clearly not the right Y value

// From time to time also crashes
Guru Meditation Error: Core  1 panic'ed (LoadStoreError). Exception was unhandled.
Core 1 register dump:
PC      : 0x400d2852  PS      : 0x00060030  A0      : 0x800d1270  A1      : 0x3ffb1f30  
A2      : 0x3ffc05f0  A3      : 0x0000000b  A4      : 0xc6c0a410  A5      : 0x00000000  
A6      : 0x19c8cda5  A7      : 0x40000000  A8      : 0x0004e0cc  A9      : 0x0329c041  
A10     : 0x3ffb1f34  A11     : 0x3ffb1f39  A12     : 0x00000035  A13     : 0x400f1704  
A14     : 0x3ffb1ee0  A15     : 0x00000002  SAR     : 0x0000000f  EXCCAUSE: 0x00000003  
EXCVADDR: 0x40000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000  

Backtrace: 0x400d2852:0x3ffb1f30 0x400d126d:0x3ffb1f80 0x400d65dd:0x3ffb1fb0 0x4008bd49:0x3ffb1fd0

Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5828
entry 0x400806ac
Started Touchscreen poll (restarted)

X & Y working correcly but not consistently. At some point I get "readBytes error!" and also from time to time it stops for some secods to read the touch signals.

As I side topic I do not understand why Lilygo purchases some touch controller from a provider, but is not able to supply either the Vendor specifications or a proper Technical specs PDF where we developers can properly get informed about the touch events and more. Touch is not only about Tapping and getting X & Y Coordinates, some touch interfaces also have gestures and return different events like Tap, Drag, Press, Release etc.

Second thing I don't understand correctly is why this is not like a standard I2C implementation as we can see for example in this Goodisplay FocalTech component initialization. Usually when starting communication with I2C, both temperature sensor and other touch components first thing they do is to check that the Vendor ID and Chip ID match. Otherwise might be hitting the wrong component or might be not connecting thus giving you an early warning after I2C is instantiated. And that's what I see on most I2C, but here is simply assuming is like this, can work is no problem but it shows a bit that you are implementing something that you don't understand completely. This lack of information summed to the fact that I cannot even get the Lilygo touch test demo working correctly makes the touch unusable for my intents right now.

If someone can help I will be really happy to get this moving forward and implement this differently using proper Rising edge interrupts instead of looping all the time over, that is first not the right way to do it, and secondly higher CPU intensive if you application does other things other than touch. Touch should be something that runs smooth on the background and is just triggered when TOUCH_INT pin goes HI (This is also uncommon, on other touch interfaces, same as Chip select INT is low when receiving an event) But is ok I'm just interested in getting this to work and getting the full technical information about the controller.

lewisxhe commented 3 years ago
  1. I can't add more functions to the touch, because the supplier only provides me with a simple sample program, and did not give me a data manual. I asked them for it, but they did not provide it.
  2. I have tested it and it will not fail to read
  3. I can provide you with the sample program that the supplier gave me to facilitate your research, but it is not helpful to me.

5_5_Touch.zip L58数据手册V1.0.pdf

martinberlin commented 3 years ago

I understand. But to implement touch you need at least press down and lift up events. Without that is completely useless. Because otherwise there is no real press of a button. you press and hold, then you repeat same button press multiple times. I’m sorry but if this L58 has not that then it was simply a poor choice for a touch controller. I will try to translate the PDF and sniff all that comes per I2C but as a consumer I shouldn’t need to reverse engineer your products to get them running. In the code I see just X and Y returning via I2C. If this is really the touch controller for a mobile screen it should have events, they need to be somewhere . Thanks for your time

lewisxhe commented 3 years ago

I feel helpless ! This is not my choice.

martinberlin commented 3 years ago

It's no problem, I just want to help, so maybe we can get the events somehow. But if we can not then at least this should be in the product description explained. Otherwise it can make other developers helpless too ;(

martinberlin commented 3 years ago

Updated my touch examples and the wiki. Added “tap simulation” with a timeout. Still does not work 100% correctly like having press and lift up evens but is more usable: https://github.com/martinberlin/cale-idf/wiki/Model-parallel-ED047TC1.h#touch-research

@lewisxhe I will sniff the I2C and try to discover if has events. But next time if the provider is not able to deliver proper documentation/examples then its simply not a good choice even if the price quality is great (looking at least). I know it was not your choice but at least who decides this should now!

lewisxhe commented 3 years ago

I have explained the problem to LilyGo, and the touch panel should be replaced later. Thank you for your contribution.

martinberlin commented 3 years ago

Waiting for another panel since mine is broken. Lilygo sent me a proposed solution so when it arrives I will test it and document it here. It seems that comes at least a press down /lift up event. Added it here in my component but I need to wait to test it: https://github.com/martinberlin/cale-idf/commit/fbf637181b3afd31e7f1d04637cd730ffb610d13

Thanks Lewis for the follow ups!

fonix232 commented 3 years ago

@martinberlin unfortunately this sort of poor component choosing is not unique to LilyGO. I see this in almost every custom design developer kit coming from China. Well tested components and systems are often canned for undocumented, "cheaper" counterparts, most of the time for no good reason.

For example, the M5Paper (M5Stack's version of the EPD47) has a bunch of questionable choices. The EPD is driven by an IT8951, an SPI-connected microcontroller (with lots of great capabilities, by the way!), which ends up saving a few pins only to cause a permanent 100-130mA drain when on. The AXP192 PMU is replaced with a lesser controller that has much less documentation, and can't even report events like charger connected, or charging complete. And one could go on.

To me, both of these boards seem like they were put together by a handful of teams with little to no communication with each other, often the solution just getting "slapped on", with little regards to compatibility with the rest of the system.

And then we end up with devices that look good on paper, but have fatal design flaws, issues that cannot be fixed in software. I for one would rather have a good hardware design that is a bit more expensive and has little software support initially, than to have a device that cannot be fixed due to faulty hardware.

martinberlin commented 3 years ago

I agree on your points. But I must say that this epaper proves to be quite nice, both in resolution, price and quality. I like it so far. I'm still waiting for my new touch. One point I dislike: This touch FPC connectors on the PCB are not the best quality. I understand you are not supposed to plug in and out the touch many times, but mine broke after just a few times. And when this tiny things brake it's impossible to repair.

The issue is that once you stick the touch, if it brakes the connector, you have a half usable epaper. I will update this when the touch arrives and I still have to confirm if it delivers press/release events that are necessary to detect the "TAP" event. Without that is very hard to make an usable button ;) And I will additionally make a supplement that can be 3D printed, to place the touch flat cable, in a position that is harder to brake.

martinberlin commented 3 years ago

@lewisxhe touch is now updated and supporting events in Cale-idf epaper component and my ESP-IDF component also: https://github.com/martinberlin/FT6X36-IDF Supports L58 touch.

Proof-of-concept video: https://twitter.com/martinfasani/status/1384244324922105864