Add OpenKNX IDF component with TPUart integration

- Created CMakeLists.txt for the OpenKNX IDF component, ensuring dependencies on OpenKNX and TPUart submodules.
- Implemented Arduino compatibility header for basic functions like millis, delay, pinMode, and digitalRead.
- Developed EspIdfPlatform class for network interface management and multicast communication.
- Added EtsMemoryLoader for loading ETS memory snapshots and managing associations.
- Introduced TpuartUartInterface for UART communication with methods for reading, writing, and managing callbacks.
- Implemented arduino_compat.cpp for Arduino-like functionality on ESP-IDF.
- Created source files for platform and memory loader implementations.
- Updated submodules for knx, knx_dali_gw, and tpuart.

Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
Tony
2026-05-11 07:05:40 +08:00
parent 1b8753636f
commit 70367f53ca
20 changed files with 1359 additions and 20 deletions
+59
View File
@@ -0,0 +1,59 @@
#pragma once
#include <stdint.h>
#ifndef DEC
#define DEC 10
#endif
#ifndef HEX
#define HEX 16
#endif
#ifndef INPUT
#define INPUT 0x0
#endif
#ifndef OUTPUT
#define OUTPUT 0x1
#endif
#ifndef INPUT_PULLUP
#define INPUT_PULLUP 0x2
#endif
#ifndef INPUT_PULLDOWN
#define INPUT_PULLDOWN 0x3
#endif
#ifndef LOW
#define LOW 0x0
#endif
#ifndef HIGH
#define HIGH 0x1
#endif
#ifndef CHANGE
#define CHANGE 2
#endif
#ifndef FALLING
#define FALLING 3
#endif
#ifndef RISING
#define RISING 4
#endif
using uint = unsigned int;
uint32_t millis();
uint32_t micros();
void delay(uint32_t millis);
void delayMicroseconds(unsigned int howLong);
void pinMode(uint32_t pin, uint32_t mode);
void digitalWrite(uint32_t pin, uint32_t value);
uint32_t digitalRead(uint32_t pin);
typedef void (*voidFuncPtr)(void);
void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode);
@@ -0,0 +1,59 @@
#pragma once
#include "knx/platform.h"
#include "esp_netif.h"
#include "lwip/sockets.h"
#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>
namespace gateway::openknx {
class EspIdfPlatform : public Platform {
public:
explicit EspIdfPlatform(TPUart::Interface::Abstract* interface = nullptr,
const char* nvs_namespace = "openknx");
~EspIdfPlatform() override;
void networkInterface(esp_netif_t* netif);
esp_netif_t* networkInterface() const;
uint32_t currentIpAddress() override;
uint32_t currentSubnetMask() override;
uint32_t currentDefaultGateway() override;
void macAddress(uint8_t* data) override;
uint32_t uniqueSerialNumber() override;
void restart() override;
void fatalError() override;
void setupMultiCast(uint32_t addr, uint16_t port) override;
void closeMultiCast() override;
bool sendBytesMultiCast(uint8_t* buffer, uint16_t len) override;
int readBytesMultiCast(uint8_t* buffer, uint16_t maxLen) override;
int readBytesMultiCast(uint8_t* buffer, uint16_t maxLen, uint32_t& src_addr,
uint16_t& src_port) override;
bool sendBytesUniCast(uint32_t addr, uint16_t port, uint8_t* buffer,
uint16_t len) override;
uint8_t* getEepromBuffer(uint32_t size) override;
void commitToEeprom() override;
private:
esp_netif_t* effectiveNetif() const;
void loadEeprom(size_t size);
esp_netif_t* netif_{nullptr};
int udp_sock_{-1};
sockaddr_in multicast_remote_{};
sockaddr_in last_remote_{};
bool has_last_remote_{false};
std::vector<uint8_t> eeprom_;
std::string nvs_namespace_;
bool eeprom_loaded_{false};
};
} // namespace gateway::openknx
@@ -0,0 +1,21 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
namespace gateway::openknx {
struct EtsAssociation {
uint16_t group_address{0};
uint16_t group_object_number{0};
};
struct EtsMemorySnapshot {
bool configured{false};
std::vector<EtsAssociation> associations;
};
EtsMemorySnapshot LoadEtsMemorySnapshot(const std::string& nvs_namespace);
} // namespace gateway::openknx
@@ -0,0 +1,14 @@
#pragma once
#include "openknx_idf/ets_memory_loader.h"
#include "openknx_idf/esp_idf_platform.h"
#include "openknx_idf/tpuart_uart_interface.h"
#include "knx/bau07B0.h"
#include "knx_facade.h"
namespace gateway::openknx {
using DaliGatewayDevice = KnxFacade<EspIdfPlatform, Bau07B0>;
} // namespace gateway::openknx
@@ -0,0 +1,41 @@
#pragma once
#include "TPUart/Interface/Abstract.h"
#include "driver/uart.h"
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <functional>
namespace gateway::openknx {
class TpuartUartInterface : public TPUart::Interface::Abstract {
public:
TpuartUartInterface(uart_port_t uart_port, int tx_pin, int rx_pin,
size_t rx_buffer_size = 512, size_t tx_buffer_size = 512);
~TpuartUartInterface();
void begin(int baud) override;
void end() override;
bool available() override;
bool availableForWrite() override;
bool write(char value) override;
int read() override;
bool overflow() override;
void flush() override;
bool hasCallback() override;
void registerCallback(std::function<bool()> callback) override;
private:
uart_port_t uart_port_;
int tx_pin_;
int rx_pin_;
size_t rx_buffer_size_;
size_t tx_buffer_size_;
std::atomic_bool overflow_{false};
std::function<bool()> callback_;
};
} // namespace gateway::openknx