125 lines
2.7 KiB
C

/**
* @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 <stddef.h>
#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 D6
#define GPIO_PUMP D0
#define GPIO_CS_CAN 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
typedef enum eSystem_Status
{
sysStat_Startup,
sysStat_Normal,
sysStat_Rain,
sysStat_Purge,
sysStat_Error,
sysStat_Shutdown
} 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
} SpeedSource_t;
// String representation of SpeedSource enum
extern const char *SpeedSourceString[];
extern const size_t SpeedSourceString_Elements;
// Enum for GPS baud rates
typedef enum GPSBaudRate_e
{
BAUD_4800,
BAUD_9600,
BAUD_19200,
BAUD_38400,
BAUD_57600,
BAUD_115200
} GPSBaudRate_t;
// String representation of GPSBaudRate enum
extern const char *GPSBaudRateString[];
extern const size_t GPSBaudRateString_Elements;
// Enum for CAN bus sources
typedef enum CANSource_e
{
KTM_890_ADV_R_2021,
KTM_1290_SD_R_2023
} CANSource_t;
// String representation of CANSource enum
extern const char *CANSourceString[];
extern const size_t CANSourceString_Elements;
#define STARTUP_DELAY 2500
#define SHUTDOWN_DELAY_MS 2500
#endif