/** * @file common.h * * @brief Header file for common definitions and macros in the ChainLube application. * * This file defines common macros, GPIO configurations, and other shared constants * for the ChainLube project. It includes definitions for GPIO pins, OTA delays, pulse lengths, * and other common settings used across the project. * * @author Marcel Peterkau * @date 09.01.2024 */ #ifndef _COMMON_H_ #define _COMMON_H_ #include #define Q(x) #x #define QUOTE(x) Q(x) #define SET_BIT(value, bitPosition) ((value) |= (1U << (bitPosition))) // Conditional compilation based on PCB revision #if PCB_REV == 1 #define GPIO_BUTTON D7 #define GPIO_LED D8 #define GPIO_TRIGGER D6 #define GPIO_PUMP D5 #elif PCB_REV == 2 #define GPIO_BUTTON D7 #define GPIO_LED D8 #define GPIO_TRIGGER D6 #define GPIO_PUMP D5 #define GPIO_CS_CAN -1 #elif PCB_REV == 3 #define GPIO_BUTTON D4 #define GPIO_LED D3 #define GPIO_TRIGGER D6 #define GPIO_PUMP D0 #define GPIO_CS_CAN D8 #elif PCB_REV == 4 #define GPIO_BUTTON D4 #define GPIO_LED D3 #define GPIO_TRIGGER D8 #define GPIO_PUMP D0 #define GPIO_CS_CAN D8 #define GPIO_CE_KLINE D8 #endif #ifndef HOST_NAME #define HOST_NAME "ChainLube_%06X" // Use printf-Formatting - Chip-ID (uin32_t) will be added #endif #ifndef OTA_DELAY #define OTA_DELAY 50 // ticks -> 10ms / tick #endif #define LUBE_PULSE_LENGHT_MS 160 #define LUBE_PULSE_PAUSE_MS 340 // Pump pulse parameters // -> 2Hz PumpPulse // -> 49.7cc / h @ 2Hz // -> 49.7 ml / h @ 2Hz // -> 828.4µl / min @ 2Hz // -> 828.3µl / 60s // -> 13.81µl / 1s // -> 6.90µl / Pulse #define DEFAULT_PUMP_DOSE 7 // --- System status enum with sentinel --- typedef enum eSystem_Status { sysStat_Startup, sysStat_Normal, sysStat_Rain, sysStat_Wash, sysStat_Purge, sysStat_Error, sysStat_Shutdown, SYSSTAT_COUNT // <- sentinel (must be last) } tSystem_Status; // Enum for different sources of speed input typedef enum SpeedSource_e { #ifdef FEATURE_ENABLE_TIMER SOURCE_TIME, #endif SOURCE_IMPULSE, SOURCE_GPS, SOURCE_CAN, SOURCE_OBD2_KLINE, SOURCE_OBD2_CAN, SPEEDSOURCE_COUNT // <- sentinel (must be last) } SpeedSource_t; // Enum for GPS baud rates typedef enum GPSBaudRate_e { BAUD_4800, BAUD_9600, BAUD_19200, BAUD_38400, BAUD_57600, BAUD_115200, GPSBAUDRATE_COUNT // <- sentinel (must be last) } GPSBaudRate_t; // Enum for CAN bus sources typedef enum CANSource_e { KTM_890_ADV_R_2021, KTM_1290_SD_R_2023, TRIUMPH_SPEED_TWIN_1200_RS_2025, CANSOURCE_COUNT // <- sentinel (must be last) } CANSource_t; // String tables (kept internal to the module) extern const char * const SystemStatusString[SYSSTAT_COUNT]; extern const char * const SpeedSourceString[SPEEDSOURCE_COUNT]; extern const char * const GPSBaudRateString[GPSBAUDRATE_COUNT]; extern const char * const CANSourceString[CANSOURCE_COUNT]; // Safe getters (centralized bounds check) const char* ToString(SpeedSource_t v); const char* ToString(GPSBaudRate_t v); const char* ToString(CANSource_t v); const char* ToString(tSystem_Status v); #define STARTUP_DELAY 2500 #define SHUTDOWN_DELAY_MS 2500 #endif