Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CST716/CST718S touch sensor used in P8 #1130

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

StarGate01
Copy link
Contributor

This PR has been broken out of #1050, and depends on / includes #1128 .

  • Add support for the CST716 touch driver chip, as well as the factory fused operating modes of the CST816S.
  • Fused mode can be configured using the compile-time variable DRIVER_TOUCH.

Comment on lines 108 to 111
void TouchHandler::UpdateLvglTouchPoint() {
if (info.touching) {
#if defined(DRIVER_TOUCH_GESTURE)
// GESTURE config only generates a single event / state change
// so the LVGL wrapper is used to generate a successive release state update
lvgl.SetNewTap(info.x, info.y);
#else
if (!isCancelled) {
lvgl.SetNewTouchPoint(info.x, info.y, true);
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I don't have these devices to test, I think this function may be able to be simplified further. On the PineTime, a swipe immediately switches the screen and isCancelled is used to ignore the rest of the touch until it has been released. On the other devices the swipe event only occurs on release if I understand correctly, so parts of this could be removed.

Having preprocessor in the middle of a function isn't very nice, so depending on how different the drivers end up being, we can see if it is worth creating separate files for them or create new functions that are only included in certain builds.

Copy link
Contributor Author

@StarGate01 StarGate01 Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending on how different the drivers end up being,

This PR covers all three behaviors of the CST71X chips. The extent of differences between the behaviors wont change (as long as the hardware does not), so the drivers won't diverge further than they did in this PR.

I decided against splitting the drivers into multiple files / classes, because that would have lead to a high amount of code duplication. The only pre-processor macros added are in TouchHandler.cpp, at https://github.com/InfiniTimeOrg/InfiniTime/blob/a3f1b93df25d80031baeb2d094497c2e915ad5d6/src/touchhandler/TouchHandler.cpp#L73= to select how events should be interpreted, and on https://github.com/InfiniTimeOrg/InfiniTime/blob/a3f1b93df25d80031baeb2d094497c2e915ad5d6/src/touchhandler/TouchHandler.cpp#L110= which you already commented on.

I think you are correct in that GESTURE drivers don't use isCanceled at all, since an event is only dispatched at gesture release. I am not quite sure how we could improve the code though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it would lead to a lot of code duplication. Firstly ConvertGesture() could be moved to Cst816s.cpp for example. Then there's not that much code left in the first place and while there are only two pre-processor macros, they end up touching a large portion of the code. It would also be easier to find optimizations if they were separated and freely let them diverge. For example removing isCancelled from GESTURE and perhaps REPORT if possible.

If the end of UpdateLvglTouchPoints(), which is responsible for the release event, doesn't do anything on GESTURE, the entire function could be replaced with a simpler one for better visibility.

Copy link
Contributor

@Riksu9000 Riksu9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TouchHandler received some changes recently. TouchHandler should probably be a part of the driver, since it's just processing the touch screen data into an InfiniTime format, but that's not necessarily in the scope of this PR. This PR should be rebased, all unnecessary changes should be removed, and preprocessor shouldn't modify the behavior of functions, but can be used to pick which function to call. Then we may be able to merge this.

This function sends a tap down and tap up event to LVGL,
despite being called only once.
The P8 smartwatches use the CST716 or CST816S chips in various modes.

The device ID of these chips cannot be used for runtime detection,
because it does not give the hardware revision / firmware configuration.
@StarGate01 StarGate01 marked this pull request as draft May 13, 2024 14:09
Copy link

Build checks have not completed. Possible reasons for this are:

  1. The checks need to be approved by a maintainer
  2. The branch has conflicts
  3. The firmware build has failed

@ildar
Copy link

ildar commented Jun 4, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants