Skip to content

Suggestion: Clarify how multiple data pins work in keypad.ShiftRegisterKeys #9714

@aseanwatson

Description

@aseanwatson

I was looking into using keypad.ShiftRegisterKeys and found the documentation confusing. I had to check the source code to understand how it works.

https://github.com/adafruit/circuitpython/blob/55823ba3b07f3a3dc80ec4bb010c2fceb5338c62/shared-bindings/keypad/ShiftRegisterKeys.c#L49C1-L58C111 Says:

//|         Create a `Keys` object that will scan keys attached to a parallel-in serial-out shift register
//|         like the 74HC165 or CD4021.
//|         Note that you may chain shift registers to load in as many values as you need.
//|         Furthermore, you can put multiple shift registers in parallel and share clock and latch.
//|
//|         Key number 0 is the first (or more properly, the zero-th) bit read. In the
//|         74HC165, this bit is labeled ``Q7``. Key number 1 will be the value of ``Q6``, etc.
//|         With multiple data pins, key numbers of the next pin are sequentially to the current pin.
//|
//|         An `EventQueue` is created when this object is created and is available in the `events` attribute.

Can we replace:

With multiple data pins, key numbers of the next pin are sequentially to the current pin.

with something like:

Key numbers are sequenced such that there are key_count[0] values read from data[0], followed by key_count[1] values read from data[1], etc.

Also, can we add to:

//| :param Union[microcontroller.Pin, Sequence[microcontroller.Pin]] data: the incoming shift register data pin(s)

to get:

//| :param Union[microcontroller.Pin, Sequence[microcontroller.Pin]] data: the incoming shift register data pin(s). When one Microcontroller.Pin is given, it is equivalent to a single element sequence.

And add to:

//| :param Union[int, Sequence[int]] key_count: number of data lines to clock in (per data pin)

to get:

//| :param Union[int, Sequence[int]] key_count: number of data lines to clock in (per data pin). When one int is given, it is equivalent to a single element sequence.

I'm happy to do a PR for you, if you agree this is what it should say (or give me feedback).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions