\section{SIPO (Shift Register) Unit}

The shift registers driver unit is designed for the loading of data into serial-in/parallel-out (SIPO) shift registers, such as 74xx4094 or 74xx595. Those are commonly used to control segmented LED displays, LED user interfaces, etc. 

Those devices may be daisy-chained: the output of one is connected to the input of another, sharing the same clock and other signals, and they work together as one longer shift register.

A SIPO shift register has the following pins (possibly named differently with chips from different vendors):

\begin{itemize}
	\item \textit{Shift} -- \gls{SCK}; shifts the data in the register by one bit
	\item \textit{Data In} -- \gls{MOSI}; serial data to load into the register
	\item \textit{Data Out} -- output for daisy-chaining with other shift registers
	\item \textit{Store} -- latches the current register data and shows it on the output
	\item \textit{Clear} -- erases the latched data and clears the display
\end{itemize}

This unit automatically handles both the \textit{Shift} and \textit{Store} signals, provides access to the \textit{Clear} output, and is capable of loading multiple shift registers in parallel (an arrangement sometimes used instead of daisy-chaining). The polarity (active level) of all signals can be configured.

It is, additionally, possible to set the data lines to arbitrary ``idle'' level(s) before sending the \textit{Store} pulse; this may be latched and used for some additional feature on the user interface, such as a brightness control.


\subsection{SIPO Configuration}

\begin{inicode}
[SIPO:display@9]
# Shift pin & its active edge (1-rising,0-falling)
shift-pin=A1
shift-pol=1
# Store pin & its active edge
store-pin=A0
store-pol=1
# Clear pin & its active level
clear-pin=A2
clear-pol=0
# Data port and pins
data-port=A
data-pins=3
\end{inicode}

\subsection{SIPO Commands}

The WRITE and CLEAR\_DIRECT commands are the only ones normally used. The others provide manual control over all the output signals for debugging or testing.

\begin{cmdlist}
	0 & \cname{WRITE}
	Load the shift registers and leave the data outputs in the ``trailing data'' state before sending the \textit{Store} pulse.
	&
	\begin{cmdreq}
		\cfield{u16} trailing data (packed pins)
		\item For each output (same size)
		\begin{pldlist}
			\cfield{u8[]} data to load
		\end{pldlist}
	\end{cmdreq}
	\\

	1 & \cname{DIRECT\_DATA}
	Directly write to the data pin(s)
	&
    \begin{cmdreq}
		\cfield{u16} values to write (packed pins)
	\end{cmdreq} \\

	2 &
	\cname{DIRECT\_CLEAR}
	Pulse the \textit{Clear} pin & \\

	3 &
	\cname{DIRECT\_SHIFT}
	Pulse the \textit{Shift} pin & \\

	4 &
	\cname{DIRECT\_STORE}
	Pulse the \textit{Store} pin & \\
\end{cmdlist}



