-- | Like 'withPin', but for 'InterruptPin's. The pin is opened for
-- input, is input mode is set to the specified 'PinInputMode' value,
-- and its interrupt mode is set to the specified 'PinInterruptMode'
-- value.
--
-- If the optional active level argument is 'Nothing', then the pin's
-- active level is unchanged from its current state. Otherwise, the
-- pin's active level is set to the specified level.
--
-- It is an error to call this action if any of the following are true:
--
-- * The pin cannot be configured for input.
--
-- * The pin does not support the specified input mode.
--
-- * The pin does not support interrupts.
withInterruptPin :: (MaskGpioM h m) => Pin -> PinInputMode -> PinInterruptMode -> Maybe PinActiveLevel -> (InterruptPin h -> m a) -> m a
withInterruptPin p inputMode interruptMode l action =
  withPin p $ \h ->
    do setPinInputMode h inputMode
       setPinInterruptMode h interruptMode
       maybeSetPinActiveLevel h l
       action $ InterruptPin h

-- | Like 'readPin'.
withInterruptPin :: (MaskGpioM h m) => Pin -> PinInputMode -> PinInterruptMode -> Maybe PinActiveLevel -> (InterruptPin h -> m a) -> m a
withInterruptPin p inputMode interruptMode l action =
  withPin p $ \h ->
    do setPinInputMode h inputMode
       setPinInterruptMode h interruptMode
       maybeSetPinActiveLevel h l
       action $ InterruptPin h

-- | Like 'readPin'.
withInterruptPin p inputMode interruptMode l action =
  withPin p $ \h ->
    do setPinInputMode h inputMode
       setPinInterruptMode h interruptMode
       maybeSetPinActiveLevel h l
       action $ InterruptPin h

-- | Like 'readPin'.