File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -124,23 +124,12 @@ end
124124
125125# --- Flush ---
126126
127- function _reverse_byte (b:: UInt8 )
128- b = ((b & 0xF0 ) >> 4 ) | ((b & 0x0F ) << 4 )
129- b = ((b & 0xCC ) >> 2 ) | ((b & 0x33 ) << 2 )
130- b = ((b & 0xAA ) >> 1 ) | ((b & 0x55 ) << 1 )
131- b
132- end
133-
134127function flush! (chain:: ShiftRegisterChain )
135- # OSR shifts left (MSB first). Bytes go out in the right order,
136- # but bits within each byte land reversed on Q0-Q7.
137- # Reverse bits within each byte so shadow bit 0 → Q0.
138- v = chain. state & 0x00FFFFFF
139- b0 = _reverse_byte (UInt8 ( v & 0xFF ))
140- b1 = _reverse_byte (UInt8 ((v >> 8 ) & 0xFF ))
141- b2 = _reverse_byte (UInt8 ((v >> 16 ) & 0xFF ))
142- swapped = (UInt32 (b2) << 16 ) | (UInt32 (b1) << 8 ) | UInt32 (b0)
143- shift_out! (chain. sm, swapped << (32 - NBITS))
128+ # OSR shifts left (MSB first). 74HC595 clocks SER → Q0 → Q7,
129+ # so first bit in ends up at Q7, last bit at Q0.
130+ # MSB-first means bit 7 goes first → Q7, bit 0 last → Q0.
131+ # No bit reversal needed — natural alignment.
132+ shift_out! (chain. sm, (chain. state & 0x00FFFFFF ) << (32 - NBITS))
144133end
145134
146135# --- Bulk writes (update shadow + flush) ---
You can’t perform that action at this time.
0 commit comments