Split the monolithic IbusEsp32 class into composable layers: - KLineTransport: UART, GPIO ISR, ring buffers, idle detection - IbusHandler: BMW I/K-Bus FSM, source filtering, packet callback - IbusEsp32: thin facade preserving the original API Library renamed from IbusEsp32 to AutoWire. Existing sniffer sketch (main.cpp) requires zero changes. All 3 ESP32 environments build cleanly (esp32dev, esp32-c3, esp32-s3).
61 lines
1.4 KiB
C
61 lines
1.4 KiB
C
#pragma once
|
|
|
|
// BMW I/K-Bus interface configuration
|
|
// All values can be overridden via platformio.ini build_flags (-D flags)
|
|
|
|
// --- UART pin assignments ---
|
|
#ifndef IBUS_RX_PIN
|
|
#define IBUS_RX_PIN 16
|
|
#endif
|
|
|
|
#ifndef IBUS_TX_PIN
|
|
#define IBUS_TX_PIN 17
|
|
#endif
|
|
|
|
#ifndef IBUS_LED_PIN
|
|
#define IBUS_LED_PIN 2
|
|
#endif
|
|
|
|
#ifndef IBUS_UART_NUM
|
|
#define IBUS_UART_NUM 1
|
|
#endif
|
|
|
|
// --- Protocol timing ---
|
|
// Bus must be quiet for this long before we can transmit (microseconds)
|
|
#ifndef IBUS_IDLE_TIMEOUT_US
|
|
#define IBUS_IDLE_TIMEOUT_US 1500
|
|
#endif
|
|
|
|
// Minimum gap between our own transmitted packets (milliseconds)
|
|
#ifndef IBUS_PACKET_GAP_MS
|
|
#define IBUS_PACKET_GAP_MS 10
|
|
#endif
|
|
|
|
// Periodic timer resolution for idle detection (microseconds)
|
|
// Smaller = more responsive but more CPU overhead. 250us gives
|
|
// worst-case detection at idle_timeout + 250us = 1.75ms, well
|
|
// within the ~10ms inter-packet budget on a busy bus.
|
|
#ifndef IBUS_IDLE_CHECK_US
|
|
#define IBUS_IDLE_CHECK_US 250
|
|
#endif
|
|
|
|
// --- Buffer sizes ---
|
|
#ifndef IBUS_RX_BUFFER_SIZE
|
|
#define IBUS_RX_BUFFER_SIZE 256
|
|
#endif
|
|
|
|
#ifndef IBUS_TX_BUFFER_SIZE
|
|
#define IBUS_TX_BUFFER_SIZE 128
|
|
#endif
|
|
|
|
// --- Protocol constants ---
|
|
#define IBUS_BAUD 9600
|
|
#define IBUS_FRAMING SERIAL_8E1
|
|
|
|
// Message length byte must be between these values (inclusive)
|
|
#define IBUS_MIN_LENGTH 0x03
|
|
#define IBUS_MAX_LENGTH 0x24
|
|
|
|
// Maximum raw message size (source + length + up to 36 body bytes)
|
|
#define IBUS_MAX_MSG 40
|