Skip to content

Extended ShiftRegisterKeys to support multiple data pins with shared clock and latch - #8143

Merged
dhalbert merged 8 commits into
adafruit:mainfrom
kolkmvd:ShiftRegister-multi-data-pin
Jul 19, 2023
Merged

Extended ShiftRegisterKeys to support multiple data pins with shared clock and latch#8143
dhalbert merged 8 commits into
adafruit:mainfrom
kolkmvd:ShiftRegister-multi-data-pin

Conversation

@kolkmvd

@kolkmvd kolkmvd commented Jul 6, 2023

Copy link
Copy Markdown

Added support for multiple data pins which share the same latch and clock, e.g.

k = keypad.ShiftRegisterKeys(
    latch=board.GP2,
    clock=board.GP3,
    data=[ board.GP10, board.GP0 ],
    key_count=[ 32, 16 ],
    value_when_pressed=False,
)

Backwards compatible, data can also be a single pin instead of a list. The key_count numbers are consecutive, e.g. in the example the first key of GP0 will have number 32.

Signed-off-by: Marco van der Kolk <marco.git@vdkolk.nl>
@kolkmvd kolkmvd changed the title Extended to support multiple data pins with shared clock and latch Extended ShiftRegisterKeys to support multiple data pins with shared clock and latch Jul 6, 2023
@kolkmvd kolkmvd closed this Jul 6, 2023
@kolkmvd kolkmvd reopened this Jul 6, 2023
@kolkmvd kolkmvd closed this Jul 6, 2023
Signed-off-by: Marco van der Kolk <marco.git@vdkolk.nl>
@kolkmvd kolkmvd reopened this Jul 6, 2023
@tannewt
tannewt requested a review from dhalbert July 7, 2023 16:43
Marco van der Kolk and others added 3 commits July 8, 2023 15:21
@kolkmvd
kolkmvd marked this pull request as draft July 10, 2023 10:36
@kolkmvd
kolkmvd marked this pull request as ready for review July 10, 2023 20:17
Marco van der Kolk added 2 commits July 11, 2023 11:18
Signed-off-by: Marco van der Kolk <marco.git@vdkolk.nl>
Signed-off-by: Marco van der Kolk <marco.git@vdkolk.nl>
@dhalbert

Copy link
Copy Markdown
Collaborator

I will review this, but I have a hw question: why use parallel shift registers instead of chaining them as a single long shift register? Is it to reduce latency?

@kolkmvd

kolkmvd commented Jul 11, 2023

Copy link
Copy Markdown
Author

I will review this, but I have a hw question: why use parallel shift registers instead of chaining them as a single long shift register? Is it to reduce latency?

No in this case there are 4 independent and optionally connected button controllers. Each button controller has 32 switches (4x HC165 chained) and has a free independent physical location. All max 4 controllers are individually connected to the same control board with a 2meter wire (with 5 strands). So save 3x latch+clock pins on the microcontroller, but also to have equal priority for all controllers, the board has parallel data pins. Also when you would daisy chain these controllers it makes it more complex to figure out which ones are connected and it would require a latch+clock return wire.

I did not think of latency, guess the shifting is quite fast.

@dhalbert

Copy link
Copy Markdown
Collaborator

Makes sense, thanks. For things like keyboards, some people claim latency issues, but we are often skeptical. Yes, shift registers are fast.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, and you have tested (I did not set this up to test.)

One q re API


//| key_count: int
//| """The number of keys that are being scanned. (read-only)
//| """The total number of keys that are being scanned. (read-only)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For the user code, would it be more useful to return a tuple in the case of multiple shift registers? Instead of doing a gc_alloc, you could create a tuple, and you can index into that, and return it for .key_count. (I was thinking about a new .key_counts, but the input arg is still key_count, so it would not be consistent.)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How important is it to have a different key count per shift register? Is this needed for a real in-the-wild design, or is it more a hypothetical?

Another alternative would be to have a single argument giving the maximum count of keys. "shift register 0" would be 0..(n-1), "shift register 1" would be n..(2*n-1) and so on. Unused positions would need to be hard-wired to the non-pressed state (not an undefined state or the pressed state), and some key numbers would be unused if the real number of keys per shift register is "ragged" (e.g., 3, 5, 3, 6, or whatever).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The current use case i have is ragged, but I could live in my case with a single key_count and ignore unused keys (which would i my case be signalled as pressed and end up in the event queue). I believe the key_count() function is also used to allocate the currently_pressed / previously_pressed stuff for the toplevel keypad code, so a tuple might not work.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If this is needed to support already existing hardware then I'm not opposed to incorporating a feature that supports ragged shift registers.

@kolkmvd
kolkmvd requested a review from dhalbert July 18, 2023 21:50

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the discussion. I'll merge!

@dhalbert
dhalbert merged commit 74eb360 into adafruit:main Jul 19, 2023
@kolkmvd

kolkmvd commented Jul 19, 2023

Copy link
Copy Markdown
Author

Thanks for merging!

@kolkmvd
kolkmvd deleted the ShiftRegister-multi-data-pin branch July 19, 2023 14:04
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