if (!pin.getSupportedPinModes().contains(mode)) {
throw new InvalidPinModeException(pin, "Invalid pin mode [" + mode.getName() + "]; pin [" + pin.getName() + "] does not support this mode.");
}
if (!pin.getSupportedPinModes().contains(mode)) {
throw new UnsupportedPinModeException(pin, mode);
}
// cache mode
getPinCache(pin).setMode(mode);
}