public IESP32 esp32_init(PinName en, PinName io0, PinName tx, PinName rx, bool debug, PinName rts, PinName cts, int baudrate) { if (esp != null) { return(esp); } Gpio gpio_en = null; if (en != PinName.NC) { var en_obj = new gpio_t(); gpio_en = (Gpio)CreateGpio(ref en_obj, en); gpio_en.SetDirection(PinDirection.PIN_OUTPUT); } Gpio gpio_io0 = null; if (io0 != PinName.NC) { var io0_obj = new gpio_t(); gpio_io0 = (Gpio)CreateGpio(ref io0_obj, io0); gpio_io0.SetDirection(PinDirection.PIN_OUTPUT); } var serial_obj = new serial_t(); var serial = (Serial)CreateSerial(ref serial_obj, tx, rx, rts, cts); serial.SetBaudRate(baudrate); esp = new ESP32Driver(this, gpio_en, gpio_io0, serial, debug); return(esp); }
private IUnitInterface CreateGpio(ref gpio_t obj, PinName pin) { if (pin == PinName.NC) { return(null); } if (!interfaces.TryGetValue(obj.id, out var uif)) { if (pin_if.ContainsKey(pin)) { throw new ArgumentException(); } uif = new Gpio(pin); obj.id = uif.GetHashCode(); interfaces.Add(obj.id, uif); if (pin == PinName.P4_5) { obj.fthandle = fthandle; obj.ftpin = 3; } } return(uif); }
public Task<GpIoOutputResponse> GpIoOutput(PinName pin, bool isOn) { RestRequest restRequest = GetRestRequest(ApiPaths.GpIoOutput, Method.GET); restRequest.AddUrlSegment("pin", pin.ToString()); restRequest.AddUrlSegment("ison", isOn.ToString()); return ProcessDefaultRequest<GpIoOutputResponse>(restRequest); }
public Task<SetupGpIoResponse> GpIoSetup(PinName pin, GpioDirection direction) { RestRequest restRequest = GetRestRequest(ApiPaths.SetupGpIo, Method.GET); restRequest.AddUrlSegment("pin", pin.ToString()); restRequest.AddUrlSegment("direction", direction.ToString()); return ProcessDefaultRequest<SetupGpIoResponse>(restRequest); }
public HardwareOutputState(PinName pin, string description) { this.Output = pin; this.PinName = pin.ToString(); this.Description = description; this.State = false; }
private IUnitInterface CreateI2C(ref i2c_t obj, PinName sda, PinName scl) { var p = PinMap.Peripheral(sda, PinMap.PinMap_I2C_SDA); if (p == (int)PinName.NC) { return(null); } var t = PinMap.Peripheral(scl, PinMap.PinMap_I2C_SCL); if ((t == (int)PinName.NC) || (p != t)) { return(null); } if (!interfaces.TryGetValue(obj.id, out var uif)) { if (pin_if.ContainsKey(sda) || pin_if.ContainsKey(scl)) { throw new ArgumentException(); } uif = new I2C((I2CName)p, sda, scl); obj.id = uif.GetHashCode(); interfaces.Add(obj.id, uif); if ((sda == PinName.P1_7) && (scl == PinName.P1_6)) { obj.fthandle = fthandle; obj.ftsda = 5; obj.ftscl = 4; } } return(uif); }
public ESP32Driver(ITestBench testBench, Gpio p_wifi_en, Gpio p_wifi_io0, Serial serial, bool debug) { this.testBench = testBench; _p_wifi_en = p_wifi_en; _p_wifi_io0 = p_wifi_io0; _serial = serial; _baudrate = serial.baudrate; _rts = serial.rts; _cts = serial.cts; _flow_control = serial.flow_control; _smutex = new object(); _parser = new ATCmdParser(testBench, serial, "\r\n"); _parser.oob("+IPD", new EventHandler(_packet_handler)); _parser.oob("0,CONNECT", new EventHandler(_connect_handler_0)); _parser.oob("1,CONNECT", new EventHandler(_connect_handler_1)); _parser.oob("2,CONNECT", new EventHandler(_connect_handler_2)); _parser.oob("3,CONNECT", new EventHandler(_connect_handler_3)); _parser.oob("4,CONNECT", new EventHandler(_connect_handler_4)); _parser.oob("0,CLOSED", new EventHandler(_closed_handler_0)); _parser.oob("1,CLOSED", new EventHandler(_closed_handler_1)); _parser.oob("2,CLOSED", new EventHandler(_closed_handler_2)); _parser.oob("3,CLOSED", new EventHandler(_closed_handler_3)); _parser.oob("4,CLOSED", new EventHandler(_closed_handler_4)); _parser.oob("WIFI ", new EventHandler(_connection_status_handler)); }
public SPI(SPIName spi, PinName mosi, PinName miso, PinName sclk, PinName ssel) { this.spi = spi; this.mosi = mosi; this.miso = miso; this.sclk = sclk; this.ssel = ssel; }
public I2S(I2SName i2s, PinName tx, PinName rx, PinName sck, PinName ws, PinName audio_clk) { this.i2s = i2s; this.tx = tx; this.rx = rx; this.sck = sck; this.ws = ws; this.audio_clk = audio_clk; }
/// <inheritdoc /> public void Write(PinName output, bool value) { this.logger.LogInformation($"> [{output.ToString()}] = '{value}'"); int pin = this.pins[output]; this.driver.Write(pin, value); this.outputsStates[output].State = value; }
public Serial(UARTName uart, PinName tx, PinName rx, PinName rts = PinName.NC, PinName cts = PinName.NC) { this.uart = uart; this.tx = tx; this.rx = rx; this.rts = rts; this.cts = cts; serial = new SerialPort(); }
public void gpio_irq_connect(uint id, PinName pin, gpio_event handler) { GPIOElement e = findElement(pin); if (e == null) { return; } e.connect(id, handler); }
public static int FindPeripheral(PinName pin, PinMap[] map) { foreach (var item in map) { if (item.pin == pin) { return(item.peripheral); } } return((int)PinName.NC); }
public static int FindFunction(PinName pin, PinMap[] map) { foreach (var item in map) { if (item.pin == pin) { return(item.function); } } return((int)PinName.NC); }
public void gpio_write(PinName pin, bool is_out, int value) { GPIOElement e = findElement(pin); if (e == null) { return; } e.IsOut = is_out; e.Value = value; }
public int gpio_read(PinName pin, bool is_out) { GPIOElement e = findElement(pin); if (e == null) { return(0); } e.IsOut = is_out; return(e.Value); }
GPIOElement findElement(PinName pin) { foreach (Control c in flowButtons.Controls) { GPIOElement e = c as GPIOElement; if (e.GetDevice().pin == pin) { return(e); } } return(null); }
public static int Peripheral(PinName pin, PinMap[] map) { int peripheral = (int)PinName.NC; if (pin == PinName.NC) { return((int)PinName.NC); } peripheral = FindPeripheral(pin, map); if ((int)PinName.NC == peripheral) // no mapping available { throw new Exception($"pinmap not found for peripheral {peripheral}"); } return(peripheral); }
public static int Function(PinName pin, PinMap[] map) { int function = (int)PinName.NC; if (pin == PinName.NC) { return((int)PinName.NC); } function = FindFunction(pin, map); if ((int)PinName.NC == function) // no mapping available { throw new Exception($"pinmap not found for function {function}"); } return(function); }
public static void Pinout(PinName pin, PinMap[] map) { if (pin == PinName.NC) { return; } foreach (var item in map) { if (item.pin == pin) { PinFunction(pin, item.function); PinMode(pin, TestBench.PinMode.PullNone); return; } } throw new Exception($"could not pinout {pin}"); }
private IUnitInterface CreateSPI(ref spi_t obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) { var p = PinMap.Peripheral(mosi, PinMap.PinMap_SPI_MOSI); if (p == (int)PinName.NC) { return(null); } var t = PinMap.Peripheral(miso, PinMap.PinMap_SPI_MISO); if ((t == (int)PinName.NC) || (t != p)) { return(null); } t = PinMap.Peripheral(sclk, PinMap.PinMap_SPI_SCLK); if ((t == (int)PinName.NC) || (t != p)) { return(null); } t = PinMap.Peripheral(ssel, PinMap.PinMap_SPI_SSEL); if ((t != (int)PinName.NC) && (t != p)) { return(null); } if (!interfaces.TryGetValue(obj.id, out var uif)) { if (pin_if.ContainsKey(mosi) || pin_if.ContainsKey(miso) || pin_if.ContainsKey(sclk) || pin_if.ContainsKey(ssel)) { throw new ArgumentException(); } uif = new SPI((SPIName)p, mosi, miso, sclk, ssel); obj.id = uif.GetHashCode(); interfaces.Add(obj.id, uif); if ((mosi == PinName.P4_6) && (miso == PinName.P4_7) && (sclk == PinName.P4_4)) { obj.fthandle = fthandle; } } return(uif); }
private IUnitInterface CreateI2S(ref i2s_t obj, PinName tx, PinName rx, PinName sck, PinName ws, PinName audio_clk) { var p = PinMap.Peripheral(tx, PinMap.PinMap_I2S_TX); if (p == (int)PinName.NC) { return(null); } var t = PinMap.Peripheral(rx, PinMap.PinMap_I2S_RX); if ((t == (int)PinName.NC) || (t != p)) { return(null); } t = PinMap.Peripheral(sck, PinMap.PinMap_I2S_SCK); if ((t == (int)PinName.NC) || (t != p)) { return(null); } t = PinMap.Peripheral(ws, PinMap.PinMap_I2S_WS); if ((t == (int)PinName.NC) || (t != p)) { return(null); } t = PinMap.Peripheral(audio_clk, PinMap.PinMap_I2S_AUDIO_CLK); if ((t != (int)PinName.NC) && (t != p)) { return(null); } if (!interfaces.TryGetValue(obj.id, out var uif)) { if (pin_if.ContainsKey(tx) || pin_if.ContainsKey(rx) || pin_if.ContainsKey(sck) || pin_if.ContainsKey(ws)) { throw new ArgumentException(); } uif = new I2S((I2SName)p, tx, rx, sck, ws, audio_clk); obj.id = uif.GetHashCode(); interfaces.Add(obj.id, uif); } return(uif); }
private IUnitInterface CreateAnalogIn(ref analogin_t obj, PinName pin) { var p = PinMap.Peripheral(pin, PinMap.PinMap_ADC); if (p == (int)PinName.NC) { return(null); } if (!interfaces.TryGetValue(obj.id, out var uif)) { if (pin_if.ContainsKey(pin)) { throw new ArgumentException(); } uif = new AnalogIn((ADCName)p, pin); obj.id = uif.GetHashCode(); interfaces.Add(obj.id, uif); } return(uif); }
private IUnitInterface CreateSerial(ref serial_t obj, PinName tx, PinName rx, PinName rts = PinName.NC, PinName cts = PinName.NC) { var p = PinMap.Peripheral(tx, PinMap.PinMap_UART_TX); if (p == (int)PinName.NC) { return(null); } var t = PinMap.Peripheral(rx, PinMap.PinMap_UART_RX); if ((t == (int)PinName.NC) || (p != t)) { return(null); } var r = PinMap.Peripheral(rts, PinMap.PinMap_UART_RTS); if ((rts != PinName.NC) && ((r == (int)PinName.NC) || (p != r))) { return(null); } var s = PinMap.Peripheral(cts, PinMap.PinMap_UART_CTS); if ((cts != PinName.NC) && ((s == (int)PinName.NC) || (p != s))) { return(null); } if (!interfaces.TryGetValue(obj.id, out var uif)) { if (pin_if.ContainsKey(tx) || pin_if.ContainsKey(rx)) { throw new ArgumentException(); } uif = new Serial((UARTName)p, tx, rx, rts, cts); obj.id = uif.GetHashCode(); interfaces.Add(obj.id, uif); } return(uif); }
public Target(PinName target, GpIO pin, bool isReverse = false) { _target = target; _pin = pin; _isReverse = isReverse; }
public I2C(I2CName i2c, PinName sda, PinName scl) { this.i2c = i2c; this.sda = sda; this.scl = scl; }
public virtual void SetPin(PinName target, bool isOn) { var targetFound = _configuration.Targets.FirstOrDefault(x => x.PinName == target); SetPin(targetFound, isOn); }
public SequencesGpIo(PinName pin, bool isOn) : this() { PinName = pin; IsOn = isOn; }
public static void PinFunction(PinName pin, int function) { if (pin == PinName.NC) { return; } int n = ((int)pin) >> 4; int bitmask = 1 << (((int)pin) & 0xf); if (gpio_multi_guard != pin) { #if false if (function == 0) { // means GPIO mode *PMC(n) &= ~bitmask; } else { int pipc_data = 1; // alt-function mode --function; if (function & (1 << 2)) { *PFCAE(n) |= bitmask; } else { *PFCAE(n) &= ~bitmask; } if (function & (1 << 1)) { *PFCE(n) |= bitmask; } else { *PFCE(n) &= ~bitmask; } if (function & (1 << 0)) { *PFC(n) |= bitmask; } else { *PFC(n) &= ~bitmask; } foreach (var Pipc_0_func in PinFunc.PIPC_0_tbl) { if ((Pipc_0_func->pin == pin) && ((Pipc_0_func->function - 1) == function)) { pipc_data = 0; if (Pipc_0_func->pm == 0) { *PMSR(n) = (bitmask << 16) | 0; } else if (Pipc_0_func->pm == 1) { *PMSR(n) = (bitmask << 16) | bitmask; } else { // Do Nothing } break; } Pipc_0_func++; } if (pipc_data == 1) { *PIPC(n) |= bitmask; } else { *PIPC(n) &= ~bitmask; } if (P1_0 <= pin && pin <= P1_7 && function == 0) { *PBDC(n) |= bitmask; } *PMC(n) |= bitmask; } #endif } else { gpio_multi_guard = PinName.NC; } }
public static void PinMode(PinName pin, PinMode pullNone) { //if (pin == PinName.NC) return; }
public virtual void setDevice(Device d) { _device = d; Pin = d.pin; label1.Text = String.Format("{0} ({1})", d.name, d.pin); }
public LightPin(string section, string color, PinName pin) { _section = section.ToLower(); _color = color.ToLower(); _pin = pin; }
public PwmOut(PWMName pwm, PinName pin) { this.pwm = pwm; this.pin = pin; }
public void SetPin(PinName target, bool isOn) { _log.Info(string.Format("Set PinName : {0} [{1}]", target, isOn ? "On" : "Off")); }
public PinFunc(PinName pin, int function, int pm) { this.pin = pin; this.function = function; this.pm = pm; }
public PinMap(PinName pin, I2SName peripheral, int function) : this(pin, (int)peripheral, function) { }
public PinMap(PinName pin, int peripheral, int function) { this.pin = pin; this.peripheral = (int)peripheral; this.function = function; }