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 CST816 touchscreen driver #5941

Merged
merged 17 commits into from
Mar 11, 2024
Merged

Add CST816 touchscreen driver #5941

merged 17 commits into from
Mar 11, 2024

Conversation

clydebarrow
Copy link
Contributor

@clydebarrow clydebarrow commented Dec 15, 2023

What does this implement/fix?

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#3459

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# Example config.yaml

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@probot-esphome
Copy link

Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration (spi) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@nielsnl68
Copy link
Contributor

Is it not better to break this PR into two parts one for the SPI and the other for the touchscreen driver?

@clydebarrow
Copy link
Contributor Author

Oh, the spi stuff was not supposed to be in there - needed it for testing the board (could not do it as an external component), and thought I had avoided checking it in but obviously slipped up! Thanks for the heads-up.

@guillempages
Copy link
Contributor

@clydebarrow I know you are on holiday (saw that on discord), and did not actually expect you to answer my comments so promptly. I just thought I'd write my thoughts in the PR.
Enjoy your holiday!

@dirkjankrijnders
Copy link

Hi, I'm working on a pull request for the cst820 #5641 which is very close to the cst816s. Maybe this can be one component?

@clydebarrow
Copy link
Contributor Author

Hi, I'm working on a pull request for the cst820 #5641 which is very close to the cst816s. Maybe this can be one component?

Yes looks like one component would cover both. Will look at it more after Xmas.

@bearpawmaxim
Copy link
Contributor

bearpawmaxim commented Jan 2, 2024

press all for corners and show the result?

Well, it is round, so touch sequence is the following (from 1 to 5):
20240102_135528

[13:54:38][I][cal:140]: x=111, y=111, x_raw=112, y_raw=112
[13:54:39][I][cal:140]: x=138, y=218, x_raw=139, y_raw=219
[13:54:40][I][cal:140]: x=3, y=100, x_raw=4, y_raw=101
[13:54:42][I][cal:140]: x=152, y=5, x_raw=153, y_raw=6
[13:54:43][I][cal:140]: x=237, y=109, x_raw=238, y_raw=110

Update: looks like the touchscreen zero is located in the upper right corner.

P.S.: no rotation is applied to the display

@clydebarrow
Copy link
Contributor Author

Touch now works, but binary sensor doesn't

Does that display have a binary sensor? Where would it be? IIRC the 816 implements it by reporting a touch outside the screen boundary.

@alantreadway
Copy link

Hi - I found this PR whilst trying to get a board with the designation ESP32-2432S024 up and working with ESPHome.

I followed the thread to try out this PR, and was hitting Chip type: Unknown - using the lambda provided by bearpawmaxim to log the chip id, I'm seeing: 0xB7 - not sure if this works (will try to fork and tweak now to confirm).

@clydebarrow
Copy link
Contributor Author

to log the chip id, I'm seeing: 0xB7

I have added that as CST820. Try it and see.

@bearpawmaxim
Copy link
Contributor

Does that display have a binary sensor?

Ah, I now understand what the binary sensor means.. I mistakenly thought that binary sensor should trigger when you touch the screen area and that touch lies within the binary's sensor coordinates.
Now it is clear for me.

@clydebarrow one more question.
Because my "chinese miracle" have touchscreen and display zero coordinates mismatch (it is rotated 90° clockwise).. Can't you provide the rotation ability?

@clydebarrow
Copy link
Contributor Author

clydebarrow commented Jan 3, 2024

Can't you provide the rotation ability?

https://deploy-preview-3487--esphome.netlify.app/components/touchscreen/

To rotate 90 or 270 you will need swap_xy and one of the mirror settings.

@alantreadway
Copy link

to log the chip id, I'm seeing: 0xB7

I have added that as CST820. Try it and see.

Thanks - I'm seeing Chip type: CST816S in the logs now, but that is the last message I see (tried with two different boards to rule out hardware failure) - not sure if I'm configuring things correctly, so it's unclear what is going on.

I don't really have time to dig into this further now, but when I do I can raise a PR if further changes are needed?

@codecov-commenter
Copy link

codecov-commenter commented Jan 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.50%. Comparing base (4d8b5ed) to head (1e5d616).
Report is 74 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #5941      +/-   ##
==========================================
- Coverage   53.70%   53.50%   -0.21%     
==========================================
  Files          50       50              
  Lines        9408     9515     +107     
  Branches     1654     1683      +29     
==========================================
+ Hits         5053     5091      +38     
- Misses       4056     4117      +61     
- Partials      299      307       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pixelwave
Copy link

I have the ESP32-2432S024C with CST820 touch controller as well and trying to get the touch functionality working. I got the screen displaying stuff with this code:

color:
  - id: my_red
    red: 100%
    green: 3%
    blue: 5%

spi:
 clk_pin: GPIO14
 mosi_pin: GPIO13
 miso_pin: GPIO12

display:
  - platform: ili9xxx
    model: TFT 2.4
    cs_pin: GPIO15
    dc_pin: GPIO2
    rotation: 90
    id: tft_ha
    lambda: |-
      it.fill(my_red);

output:
  - platform: ledc
    pin: 27
    id: gpio_27_backlight_pwm

light:
  - platform: monochromatic
    output: gpio_27_backlight_pwm
    name: "Display Backlight"
    id: back_light
    restore_mode: ALWAYS_ON

How do I get the touch now working / what files do I have to include in my ESPHome build? Sorry I am still learning ESPHome ... quite new to the syntax. If somebody could give me support that would be awesome.

@clydebarrow clydebarrow merged commit d6bcc46 into esphome:dev Mar 11, 2024
56 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2024
@clydebarrow clydebarrow deleted the cst816 branch April 24, 2024 00:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants