\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 report asynchronous events on a pin change. 

All pins of the unit may be configured either for a rising, falling, or any change detection; due to a hardware limitation, the same pin number may not be used for event detection on different ports (e.g. A1 and B1) at the same time. In order to receive a pin change event, we must arm the pin first, using a command; it can be armed for a single event, or it may be re-armed automatically with a hold-off time. It is, further, possible to automatically arm selected pins on start-up, removing the need to arm them e.g. after the module restarts or is re-connected.

\subsection{Digital Input Configuration}

\begin{inicode}
[DI:in@2]
# Port name
port=A
# Pins (comma separated, supports ranges)
pins=10-8,3-0
# Pins with pull-up
pull-up=10,9
# Pins with pull-down
pull-down=0

# Trigger pins activated by rising/falling edge
trig-rise=10
trig-fall=
# Trigger pins auto-armed by default
auto-trigger=10
# Triggers hold-off time (ms)
hold-off=100
\end{inicode}

\subsection{Digital Input Events}

\begin{cmdlist}

	0 & \cname{PIN\_CHANGE}
	A pin change event. The payload includes a snapshot of all configured pins captured immediately after the change was registered.
	& \begin{cmdpld}
		\cfield{u16} changed pins
		\cfield{u16} port snapshot
	\end{cmdpld}

\end{cmdlist}

\subsection{Digital Input Commands}

\begin{cmdlist}
	0 & \cname{READ} Read the pins
	& \begin{cmdresp}
		\cfield{u16} pin states
	\end{cmdresp} \\

	1 & \cname{ARM\_SINGLE} Arm for a single event
	& \begin{cmdreq}
		\cfield{u16} pins to arm
	\end{cmdreq} \\

	2 & \cname{ARM\_AUTO} Arm with automatic re-arming after each event
	& \begin{cmdreq}
		\cfield{u16} pins to arm
	\end{cmdreq} \\

	3 & \cname{DISARM} Dis-arm selected pins
	& \begin{cmdreq}
		\cfield{u16} pins to dis-arm
	\end{cmdreq}
\end{cmdlist}
