\section{Digital Input}

The digital input unit is the input counterpart of the digital output unit. 

In addition to reading the immediate digital levels of the selected pins, this unit can generate asynchronous events on a pin change. The state of the entire input port, together with a microsecond timestamp (as is the case for all asynchronous events), is reported to the host either on a rising, falling, or any pin change. 

The pin change event can be configured independently for each pin. In order to receive a pin change event, it must be armed first; The pin can be armed for a single event, or it may be re-armed automatically with a hold-off time. It's further possible to automatically arm selected pin triggers on start-up.


\subsection{Digital Input Configuration}

\begin{inicode}
	[DI:in@2]	
	# Port name
	port=A
	# Pins (comma separated, supports ranges)
	pins=0
	# Pins with pull-up
	pull-up=
	# Pins with pull-down
	pull-down=
	
	# Trigger pins activated by rising/falling edge
	trig-rise=
	trig-fall=
	# Trigger pins auto-armed by default
	auto-trigger=
	# Triggers hold-off time (ms)
	hold-off=100
\end{inicode}

\subsection{Digital Input Events}

\begin{tabularx}{\textwidth}{p{\fldwcode}Xp{\fldwpld}}
	\toprule
	\textbf{Code} & \textbf{Meaning} & \textbf{Payload}  \\	
	\midrule	
	
	0 & \flname{PIN\_CHANGE}
	A pin change event. The payload includes a snapshot of all configured pins captured immediately after the change was registered.
	& \makecell[tl]{
		\fld{u16} changed pins \\
		\fld{u16} port snapshot
	} \\	
	\bottomrule
\end{tabularx}

\subsection{Digital Input Commands}

\begin{tabularx}{\textwidth}{p{\fldwcode}Xp{\fldwpld}}
	\toprule
	\textbf{Code} & \textbf{Function} & \textbf{Payload}  \\	
	\midrule	
	
	0 & \flname{READ} Read the pins
	& \makecell[tl]{
		\fldresp
		\fld{u16} pin states
	} \\

	1 & \flname{ARM\_SINGLE} Arm for a single event
	& \makecell[tl]{
		\fldreq
		\fld{u16} pins to arm
	} \\

	2 & \flname{ARM\_AUTO} Arm with automatic re-arming after each event
	& \makecell[tl]{
		\fldreq
		\fld{u16} pins to arm
	} \\

	3 & \flname{DISARM} Dis-arm selected pins
	& \makecell[tl]{
		\fldreq
		\fld{u16} pins to dis-arm
	} \\
	\bottomrule
\end{tabularx}
