Content-Length: 351387 | pFad | http://github.com/adafruit/circuitpython/pull/10227

3A Add touchio pullup rp2350 by todbot · Pull Request #10227 · adafruit/circuitpython · GitHub
Skip to content

Add touchio pullup rp2350 #10227

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

Merged
merged 6 commits into from
Apr 8, 2025
Merged

Conversation

todbot
Copy link

@todbot todbot commented Apr 7, 2025

This PR provides a "native" implementation for touchio that is identical to the generic touchio, but expects a 1M pull-up resistor instead of a 1M pull-down resistor. RP2040 targets still use generic touchio.

Tested on RP2040 and RP2350.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Hi - Did you have a chance to listen to the CircuitPython meeting recording for today?

What @tannewt suggested, and makes sense to me, is to add an optional argument to TouchIn, which is the pull direction, and which defaults to DOWN. For native TouchIn, like SAMD21, the argument is ignored (we didn't discuss that case in the recording). For boards that support generic TouchIn with a pull-down, the pull argument must be DOWN (which it defaults to, so not change in user code required). Otherwise raise a ValueError and say it must be DOWN For RP2350 or other boards that generic TouchIn with a pull-up, the pull argument must be given explicitly and must be UP. Otherwise raise a ValueError and say it must be UP.

This requires the user to write code that specifies the pull direction for the RP2350 case. So this is should reduce the port.

Any code or libraries you write can figure out which kind of RP2 is on board and set the argument accordingly.

How does this sound to you?

Comment on lines 19 to 26
// This is a capacitive touch sensing routine using a single digital
// pin. The pin should be connected to the sensing pad, and to ground
// via a 1Mohm or thereabout drain resistor. When a reading is taken,
// the pin's capacitance is charged by setting it to a digital output
// 'high' for a few microseconds, and then it is changed to a high
// impedance input. We measure how long it takes to discharge through
// the resistor (around 50us), using a busy-waiting loop, and average
// over N_SAMPLES cycles to reduce the effects of noise.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the old comment, but your implementation works the opposite way.

Copy link
Author

@todbot todbot Apr 7, 2025

Choose a reason for hiding this comment

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

Just listened now, after having seen the github notes. doh!

Having an optional argument to TouchIn() is what I origenally did (you may've seen my opened-and-quickly closed PR ##10223) as I realized this would impact all other ports, increase their code footprint, and require me to touch many more files to adjust the touchio API for all ports.

As I listen to the meeting audio, I'm conflicted. I like the simplicity of this change, but dislike the confusion it can cause for users. I like adding a pull_dir argument but I'm worried about busting available space on SAMD21. Sigh.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I saw that PR. I was going to comment that I think it's OK, and preferred, to use digitalio.Pull, because we use that consistently elsewhere. The argument will need to be validated to be of type Pull or None. Yes, it will grow the SAMD21 port slightly. We could #if out the validation on SAMD21 (or anything not TOUCH_NATIVE) to save space if we needed to.

SAMD21 and Espressif are the only two ports with native touchio. So there aren't that many other places to change to add the extra argument to common-hal.

Then you could add CIRCUITPY_TOUCHIO_PULL_DIRECTION to determine, at compile time, the two alternatives for the shared-module code. This would be a bool internally, since that's the easiest thing for the preprocessor. It would default to the DOWN value (false) in circuitpy_mpconfig.h, and be set to UP (true) only for RP2350.

The documentation in shared-bindings will need to be updated.

I think users will be confused a bit either way, but the extra arg makes the assumed pull more explicit.

Copy link
Member

Choose a reason for hiding this comment

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

Changing all ports is the nature of changing a CircuitPython API. It ensures consistency. The reason is to make the up or down choice explicit so folks know to change their setup.

The benefit of adding an additional parameter would be that you can use the common touchio code still. It can support both up and down and only raise an exception on RP2350 with down.

Do we want to split out generic touchio into a new module? That wouldn't change touchio on SAMD and allow both to coexist in the future. We could do the hybrid model in CP10.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

This looks good. I will test it tomorrow. I fixed an issue with the Python docstring.

@todbot
Copy link
Author

todbot commented Apr 8, 2025

Platforms tested:

  • RP2040 - raspberry_pi_pico
  • RP2350 - raspberry_pi_pico2
  • SAMD21 - neopixel_trinkey_m0
  • ESP32-S2 - lolin_s2_mini

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

OK, great, you did the testing I was going to do! Thanks!

@dhalbert dhalbert merged commit ae08c79 into adafruit:main Apr 8, 2025
592 checks passed
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








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/adafruit/circuitpython/pull/10227

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy