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); }
public void serial_putc(ref serial_t obj, int c) { if (!interfaces.TryGetValue(obj.id, out var uif)) { throw new ArgumentException(); } ((Serial)uif).PutC(c); }
public int serial_writable(ref serial_t obj) { if (!interfaces.TryGetValue(obj.id, out var uif)) { throw new ArgumentException(); } return(((Serial)uif).IsWritable() ? 1 : 0); }
public void serial_format(ref serial_t obj, int data_bits, SerialParity parity, int stop_bits) { if (!interfaces.TryGetValue(obj.id, out var uif)) { throw new ArgumentException(); } ((Serial)uif).SetFormat(data_bits, parity, stop_bits); }
public int serial_getc(ref serial_t obj) { if (!interfaces.TryGetValue(obj.id, out var uif)) { throw new ArgumentException(); } return(((Serial)uif).GetC()); }
public void serial_baud(ref serial_t obj, int baudrate) { if (!interfaces.TryGetValue(obj.id, out var uif)) { throw new ArgumentException(); } ((Serial)uif).SetBaudRate(baudrate); }
private void DeleteSerial(ref serial_t obj) { if (!interfaces.TryGetValue(obj.id, out var uif)) { return; } pin_if.Remove(((Serial)uif).tx); pin_if.Remove(((Serial)uif).rx); interfaces.Remove(obj.id); }
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 void serial_free(ref serial_t obj) { DeleteSerial(ref obj); }
public void serial_init(ref serial_t obj, PinName tx, PinName rx) { CreateSerial(ref obj, tx, rx); }