Merge pull request #268 from mgeramb/setUartPins

Allow to set uart pins for RP2040 and ESP32 platform
This commit is contained in:
thelsing 2023-12-26 13:11:07 +01:00 committed by GitHub
commit a1b7e5d459
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 0 deletions

View File

@ -10,17 +10,42 @@
#define KNX_SERIAL Serial1
#endif
#ifndef KNX_UART_RX_PIN
#define KNX_UART_RX_PIN -1
#endif
#ifndef KNX_UART_TX_PIN
#define KNX_UART_TX_PIN -1
#endif
Esp32Platform::Esp32Platform()
#ifndef KNX_NO_DEFAULT_UART
: ArduinoPlatform(&KNX_SERIAL)
#endif
{
#ifndef KNX_NO_DEFAULT_UART
knxUartPins(KNX_UART_RX_PIN, KNX_UART_TX_PIN);
#endif
}
Esp32Platform::Esp32Platform(HardwareSerial* s) : ArduinoPlatform(s)
{
}
void Esp32Platform::knxUartPins(int8_t rxPin, int8_t txPin)
{
_rxPin = rxPin;
_txPin = txPin;
}
// ESP specific uart handling with pins
void Esp32Platform::setupUart()
{
_knxSerial->begin(19200, SERIAL_8E1, _rxPin, _txPin);
while (!_knxSerial)
;
}
uint32_t Esp32Platform::currentIpAddress()
{
return WiFi.localIP();

View File

@ -10,6 +10,10 @@ public:
Esp32Platform();
Esp32Platform(HardwareSerial* s);
// uart
void knxUartPins(int8_t rxPin, int8_t txPin);
void setupUart() override;
// ip stuff
uint32_t currentIpAddress() override;
uint32_t currentSubnetMask() override;
@ -36,6 +40,8 @@ public:
void commitToEeprom();
private:
WiFiUDP _udp;
int8_t _rxPin = -1;
int8_t _txPin = -1;
};
#endif

View File

@ -49,11 +49,22 @@ A RAM-buffered Flash can be use by defining USE_RP2040_LARGE_EEPROM_EMULATION
#define KNX_SERIAL Serial1
#endif
#ifndef KNX_UART_RX_PIN
#define KNX_UART_RX_PIN UART_PIN_NOT_DEFINED
#endif
#ifndef KNX_UART_TX_PIN
#define KNX_UART_TX_PIN UART_PIN_NOT_DEFINED
#endif
RP2040ArduinoPlatform::RP2040ArduinoPlatform()
#ifndef KNX_NO_DEFAULT_UART
: ArduinoPlatform(&KNX_SERIAL)
#endif
{
#ifndef KNX_NO_DEFAULT_UART
knxUartPins(KNX_UART_RX_PIN, KNX_UART_TX_PIN);
#endif
#ifndef USE_RP2040_EEPROM_EMULATION
_memoryType = Flash;
#endif
@ -66,6 +77,18 @@ RP2040ArduinoPlatform::RP2040ArduinoPlatform( HardwareSerial* s) : ArduinoPlatfo
#endif
}
void RP2040ArduinoPlatform::knxUartPins(pin_size_t rxPin, pin_size_t txPin)
{
SerialUART* serial = dynamic_cast<SerialUART*>(_knxSerial);
if(serial)
{
if (rxPin != UART_PIN_NOT_DEFINED)
serial->setRX(rxPin);
if (txPin != UART_PIN_NOT_DEFINED)
serial->setTX(txPin);
}
}
void RP2040ArduinoPlatform::setupUart()
{
SerialUART* serial = dynamic_cast<SerialUART*>(_knxSerial);

View File

@ -22,6 +22,8 @@ public:
RP2040ArduinoPlatform();
RP2040ArduinoPlatform( HardwareSerial* s);
// uart
void knxUartPins(pin_size_t rxPin, pin_size_t txPin);
void setupUart();
// unique serial number