public BP_RESPONSE ModeSPI(BP_SPI_SPEED speed, BP_SPI_CLOCK_POLARITY polarity, BP_SPI_CLOCK_EDGE edge, BP_SPI_INPUT_PHASE phase, BP_CS_POLARITY cs, BP_OUTPUT output) { m_mode = BP_MODE.SPI; BP_RESPONSE response = BP_RESPONSE.Disconnect; if (IsConnected && (response = SendWait("m5")) == BP_RESPONSE.OK && (response = SendWait((int)speed)) == BP_RESPONSE.OK && (response = SendWait((int)polarity)) == BP_RESPONSE.OK && (response = SendWait((int)edge)) == BP_RESPONSE.OK && (response = SendWait((int)phase)) == BP_RESPONSE.OK && (response = SendWait((int)cs)) == BP_RESPONSE.OK ) { response = SendWait((int)output); } return(response); }
private void SetMode_Click(object sender, EventArgs e) { if (bpPort != null) { ClearSatus(); string mode = Mode.SelectedItem as string; switch (mode) { case "HiZ": DisplayStatus(bpPort.ModeHiZ()); break; case "1-WIRE": DisplayStatus(bpPort.ModeWIRE1()); break; case "UART": { BP_UART_SPEED speed = BP_UART_SPEED.BPS_115200; if (cbUART300.Checked) { speed = BP_UART_SPEED.BPS_300; } else if (cbUart1200.Checked) { speed = BP_UART_SPEED.BPS_1200; } else if (cbUart2400.Checked) { speed = BP_UART_SPEED.BPS_2400; } else if (cbUart4800.Checked) { speed = BP_UART_SPEED.BPS_4800; } else if (cbUart9600.Checked) { speed = BP_UART_SPEED.BPS_9600; } else if (cbUart19200.Checked) { speed = BP_UART_SPEED.BPS_19200; } else if (cbUart38400.Checked) { speed = BP_UART_SPEED.BPS_38400; } else if (cbUart57600.Checked) { speed = BP_UART_SPEED.BPS_57600; } else if (cbUart115200.Checked) { speed = BP_UART_SPEED.BPS_115200; } BP_UART_PROTOCOL protocol = BP_UART_PROTOCOL.Data_8_None; if (cbUart8Even.Checked) { protocol = BP_UART_PROTOCOL.Data_8_Even; } else if (cbUart8None.Checked) { protocol = BP_UART_PROTOCOL.Data_8_None; } else if (cbUart8Odd.Checked) { protocol = BP_UART_PROTOCOL.Data_8_Odd; } else if (cbUart9None.Checked) { protocol = BP_UART_PROTOCOL.Data_9_None; } BP_UART_STOP stop = cbUartStop2.Checked ? BP_UART_STOP.Stop_2 : BP_UART_STOP.Stop_1; BP_UART_POLARITY polarity = cbUartIdle0.Checked ? BP_UART_POLARITY.Idle_0 : BP_UART_POLARITY.Idle_1; BP_OUTPUT output = cbUartOutOC.Checked ? BP_OUTPUT.OpenDrain : BP_OUTPUT.Normal; DisplayStatus(bpPort.ModeUART(speed, protocol, stop, polarity, output)); } break; case "I2C": { BP_I2C_SPEED speed = BP_I2C_SPEED.I2C_100KHz; if (cbI2C5.Checked) { speed = BP_I2C_SPEED.I2C_5KHz; } else if (cbI2C50.Checked) { speed = BP_I2C_SPEED.I2C_50KHz; } else if (cbI2C100.Checked) { speed = BP_I2C_SPEED.I2C_100KHz; } else { speed = BP_I2C_SPEED.I2C_400KHz; } DisplayStatus(bpPort.ModeI2C(speed)); } break; case "SPI": { BP_SPI_SPEED speed = BP_SPI_SPEED.Speed_125KHz; if (cbSpi30.Checked) { speed = BP_SPI_SPEED.Speed_30KHz; } else if (cbSpi125.Checked) { speed = BP_SPI_SPEED.Speed_125KHz; } else if (cbSpi250.Checked) { speed = BP_SPI_SPEED.Speed_250KHz; } else if (cbSpi1000.Checked) { speed = BP_SPI_SPEED.Speed_1MHz; } BP_SPI_CLOCK_POLARITY polarity = cbSpiPolarityLow.Checked ? BP_SPI_CLOCK_POLARITY.Low : BP_SPI_CLOCK_POLARITY.High; BP_SPI_CLOCK_EDGE edge = cbSpiEdgeIdle.Checked ? BP_SPI_CLOCK_EDGE.Idle : BP_SPI_CLOCK_EDGE.Active; BP_SPI_INPUT_PHASE phase = cbSpiInputMiddle.Checked ? BP_SPI_INPUT_PHASE.Middle : BP_SPI_INPUT_PHASE.End; BP_CS_POLARITY cs = cbSpiCsPositive.Checked ? BP_CS_POLARITY.Positive : BP_CS_POLARITY.Negative; BP_OUTPUT output = cbSpiOutOC.Checked ? BP_OUTPUT.OpenDrain : BP_OUTPUT.Normal; DisplayStatus(bpPort.ModeSPI(speed, polarity, edge, phase, cs, output)); } break; case "2WIRE": { BP_WIRE_SPEED speed = BP_WIRE_SPEED.Speed_5KHz; if (cb2W5.Checked) { speed = BP_WIRE_SPEED.Speed_5KHz; } else if (cb2W50.Checked) { speed = BP_WIRE_SPEED.Speed_50KHz; } else if (cb2W100.Checked) { speed = BP_WIRE_SPEED.Speed_100KHz; } else { speed = BP_WIRE_SPEED.Speed_400KHz; } BP_OUTPUT output = cb2WOutOC.Checked ? BP_OUTPUT.OpenDrain : BP_OUTPUT.Normal; DisplayStatus(bpPort.ModeWIRE2(speed, output)); } break; case "3WIRE": { BP_WIRE_SPEED speed = BP_WIRE_SPEED.Speed_5KHz; if (cb3W5.Checked) { speed = BP_WIRE_SPEED.Speed_5KHz; } else if (cb3W50.Checked) { speed = BP_WIRE_SPEED.Speed_50KHz; } else if (cb3W100.Checked) { speed = BP_WIRE_SPEED.Speed_100KHz; } else { speed = BP_WIRE_SPEED.Speed_400KHz; } BP_CS_POLARITY cs = cb3WCsPositive.Checked ? BP_CS_POLARITY.Positive : BP_CS_POLARITY.Negative; BP_OUTPUT output = cb3WOutOC.Checked ? BP_OUTPUT.OpenDrain : BP_OUTPUT.Normal; DisplayStatus(bpPort.ModeWIRE3(speed, cs, output)); } break; case "LCD": DisplayStatus(bpPort.ModeLCD()); break; case "DIO": DisplayStatus(bpPort.ModeDIO()); break; } } }
public BP_RESPONSE ModeSPI(BP_SPI_SPEED speed, BP_SPI_CLOCK_POLARITY polarity, BP_SPI_CLOCK_EDGE edge, BP_SPI_INPUT_PHASE phase, BP_CS_POLARITY cs, BP_OUTPUT output) { m_mode = BP_MODE.SPI; BP_RESPONSE response = BP_RESPONSE.Disconnect; if (IsConnected && (response = SendWait("m5")) == BP_RESPONSE.OK && (response = SendWait((int)speed)) == BP_RESPONSE.OK && (response = SendWait((int)polarity)) == BP_RESPONSE.OK && (response = SendWait((int)edge)) == BP_RESPONSE.OK && (response = SendWait((int)phase)) == BP_RESPONSE.OK && (response = SendWait((int)cs)) == BP_RESPONSE.OK ) response = SendWait((int)output); return response; }