Skip to content

Refactor SHIFTREGISTER management for multiple instances#2112

Open
D-Fed11 wants to merge 4 commits into
openshwprojects:mainfrom
D-Fed11:feature/multi-shift-registers
Open

Refactor SHIFTREGISTER management for multiple instances#2112
D-Fed11 wants to merge 4 commits into
openshwprojects:mainfrom
D-Fed11:feature/multi-shift-registers

Conversation

@D-Fed11

@D-Fed11 D-Fed11 commented May 22, 2026

Copy link
Copy Markdown
Contributor

Support Multiple Independent Shift Register Instances

Motivation

This change was driven by a real-world device that uses 2 separate 74HC595 shift register chips connected to different GPIO pins on the BK7231N. The previous implementation only supported a single shift register instance, causing the second chip to be ignored when startDriver ShiftRegister was called a second time.

Changes

Modified the shift register driver to support up to 4 independent shift register instances, each with separate GPIO pins and channel mappings.

Files Modified

  1. src/driver/drv_shiftRegister.c

    • Replaced single global variables with a struct array (g_shiftRegs[MAX_SHIFT_REGISTERS])
    • Updated Shift_Init() to automatically find the next available slot instead of overwriting global state
    • Updated Shift_OnChannelChanged() to iterate through all active instances and route channel changes to the correct chip
  2. src/driver/drv_main.c

    • Modified DRV_StartDriver() to allow ShiftRegister to be re-initialized multiple times
    • Added special handling so subsequent startDriver ShiftRegister calls create new instances instead of being rejected

Usage Example

// First 74HC595 chip (pins 2, 3, 4, channels 10-17)
startDriver ShiftRegister 2 3 4 10 1 1 0

// Second 74HC595 chip (pins 19, 20, 21, channels 18-25)
startDriver ShiftRegister 19 20 21 18 1 1 0

D-Fed11 and others added 4 commits May 22, 2026 21:33
The #define directive on line 276 of src/obk_config.h was missing the # prefix,
causing preprocessor errors and cascading compilation failures. Added the missing
# to correctly enable the ShiftRegister driver.
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.

1 participant