mirror of
				https://github.com/thelsing/knx.git
				synced 2025-10-26 10:26:25 +01:00 
			
		
		
		
	Merge pull request #268 from mgeramb/setUartPins
Allow to set uart pins for RP2040 and ESP32 platform
This commit is contained in:
		
						commit
						a1b7e5d459
					
				@ -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();
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user