Skip to content

countio: add selectable rise and fall detection, pulls - #5803

Merged
dhalbert merged 1 commit into
adafruit:mainfrom
dhalbert:countio-enhancements
Jan 1, 2022
Merged

dhalbert merged 1 commit into
adafruit:mainfrom
dhalbert:countio-enhancements

Conversation

@dhalbert

@dhalbert dhalbert commented Dec 31, 2021 •

Copy link
Copy Markdown
Collaborator
  • Addresses countio enhancements #5606.

  • Add selectable counting of rising or falling edges, or both (both is not possible on RP2040).

  • Add ability to specify a pull-up or pull-down.

  • The default was supposed to be falling, though on RP2040 it appears to have been rising. Fixed RP2040 to be consistent.

  • Renamed pin argument of Counter() to be pin instead of pin_a. Not sure why it was pin_a. That may be a leftover of something else.

  • Remove common_hal_countio_counter_reset(), since it can be done by common_hal_countio_counter_set_count(pin, 0).

  • Introduce countio.Edge enumeration. The alternative was to provide rise and fall boolean arguments to Counter(), but seems more consistent with other such multi-value arguments.

  • Unrelated: Fix some kind of accidental typo for the symbolic link for tests/pyboard.py -> ../tools/cpboard.py. The symoblic link included a literal newline character, which is not obvious from the file comparison below.

Tested on all the implemented platforms: raspberrypi, espressif, atmel-samd, nrf:

  • Pulls tested manually.
  • Slight variants of this test program used on different boards:
import board
import time
from countio import Counter, Edge
from digitalio import DigitalInOut

tx = DigitalInOut(board.TX)
tx.switch_to_output(False)

a0 = Counter(board.A0, edge=Edge.RISE)
a2 = Counter(board.A2, edge=Edge.FALL)
a4 = Counter(board.A4, edge=Edge.RISE_AND_FALL)

while True:
    print(f"tx: {tx.value}, a0 (rise): {a0.count}, a2 (fall): {a2.count}, a4 (r/f): {a4.count}")
    tx.value = not tx.value
    time.sleep(1)

@dhalbert
dhalbert requested review from jepler and tannewt December 31, 2021 21:56

@jepler jepler left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not tested, but did read through the changes. Looks good from here.

@dhalbert
dhalbert merged commit d166834 into adafruit:main Jan 1, 2022
@dhalbert
dhalbert deleted the countio-enhancements branch January 1, 2022 04:46
@tonsofpcs tonsofpcs mentioned this pull request Jan 4, 2022
4 tasks done
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.

2 participants