public static bool PortModeWrite(byte pin, SC18IM700GpioMode mode) { if (pin > 7) { return(false); } if (!TryPortRegRead(out SC18IM700GpioMode[] status)) { return(false); } status[pin] = mode; return(AllPortModeWrite(status)); }
/// <summary> /// IOポートの入出力設定の読み出し /// </summary> /// <param name="confdata">入出力設定の状態</param> /// <returns>入出力設定読み出しの成否</returns> private static bool TryPortRegRead(out SC18IM700GpioMode[] confdata) { confdata = new SC18IM700GpioMode[8]; if (!TryRegRead(SC18IM700Register.PortConf1, out byte portconf1) || !TryRegRead(SC18IM700Register.PortConf2, out byte portconf2)) { return(false); } for (var i = 0; i < 4; i++) { confdata[i] = (SC18IM700GpioMode)((portconf1 >> (i * 2)) & 3); confdata[i + 4] = (SC18IM700GpioMode)((portconf2 >> (i * 2)) & 3); } return(true); }
public static bool AllPortModeWrite(Byte mode = 0xFF) { if (!IsValid()) { return(false); } var status = new SC18IM700GpioMode[8]; for (var i = 0; i < 8; i++) { status[i] = ((mode >> i) & 1) == 1 ? SC18IM700GpioMode.Input : SC18IM700GpioMode.Output; } return(AllPortModeWrite(status)); }