mirror of
				https://github.com/thelsing/knx.git
				synced 2025-10-26 10:26:25 +01:00 
			
		
		
		
	Support configure UART speed for ESP IDF
This commit is contained in:
		
						commit
						49394ded41
					
				@ -123,8 +123,9 @@ extern "C" void app_main(void) {
 | 
			
		||||
 | 
			
		||||
    ESP_LOGI(TAG, "WiFi initialization finished.");
 | 
			
		||||
 | 
			
		||||
    // Set UART pins (example: RX=16, TX=17)
 | 
			
		||||
    knxPlatform.knxUartPins(16, 17);
 | 
			
		||||
    // Configure UART settings
 | 
			
		||||
    knxPlatform.knxUartPins(16, 17); // Set RX=16, TX=17
 | 
			
		||||
    knxPlatform.knxUartBaudRate(19200); // Set baud rate (can be changed to other values like 9600, 38400, etc.)
 | 
			
		||||
    knxPlatform.setupUart();
 | 
			
		||||
 | 
			
		||||
    // Set button ISR
 | 
			
		||||
 | 
			
		||||
@ -44,6 +44,12 @@ void Esp32IdfPlatform::knxUartPins(int8_t rxPin, int8_t txPin)
 | 
			
		||||
    _txPin = txPin;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Esp32IdfPlatform::knxUartBaudRate(uint32_t baudRate)
 | 
			
		||||
{
 | 
			
		||||
    _baudRate = baudRate;
 | 
			
		||||
    ESP_LOGI(KTAG, "UART baud rate set to %d", _baudRate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Esp32IdfPlatform::setNetif(esp_netif_t* netif)
 | 
			
		||||
{
 | 
			
		||||
    _netif = netif;
 | 
			
		||||
@ -66,7 +72,7 @@ void Esp32IdfPlatform::setupUart()
 | 
			
		||||
        return;
 | 
			
		||||
    uart_config_t uart_config;
 | 
			
		||||
    memset(&uart_config, 0, sizeof(uart_config));
 | 
			
		||||
    uart_config.baud_rate = 19200;
 | 
			
		||||
    uart_config.baud_rate = _baudRate; // Use configurable baud rate
 | 
			
		||||
    uart_config.data_bits = UART_DATA_8_BITS;
 | 
			
		||||
    uart_config.parity = UART_PARITY_EVEN;
 | 
			
		||||
    uart_config.stop_bits = UART_STOP_BITS_1;
 | 
			
		||||
@ -77,6 +83,7 @@ void Esp32IdfPlatform::setupUart()
 | 
			
		||||
    ESP_ERROR_CHECK(uart_param_config(_uart_num, &uart_config));
 | 
			
		||||
    ESP_ERROR_CHECK(uart_set_pin(_uart_num, _txPin, _rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
 | 
			
		||||
    _uart_installed = true;
 | 
			
		||||
    ESP_LOGI(KTAG, "UART initialized with baud rate %d", _baudRate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Esp32IdfPlatform::closeUart()
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,7 @@ class Esp32IdfPlatform : public Platform
 | 
			
		||||
 | 
			
		||||
    // uart
 | 
			
		||||
    void knxUartPins(int8_t rxPin, int8_t txPin);
 | 
			
		||||
    void knxUartBaudRate(uint32_t baudRate); // Add baud rate configuration
 | 
			
		||||
 | 
			
		||||
    // Call this after WiFi/Ethernet has started and received an IP.
 | 
			
		||||
    void setNetif(esp_netif_t* netif);
 | 
			
		||||
@ -74,6 +75,7 @@ class Esp32IdfPlatform : public Platform
 | 
			
		||||
    uart_port_t _uart_num;
 | 
			
		||||
    int8_t _rxPin = -1;
 | 
			
		||||
    int8_t _txPin = -1;
 | 
			
		||||
    uint32_t _baudRate = 19200; // Default baud rate, can be changed
 | 
			
		||||
    bool _uart_installed = false;
 | 
			
		||||
 | 
			
		||||
    // NVS (for EEPROM emulation)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user