Sensors I/O
The sensors layer ties the physical inputs to the board's runtime objects. It is where the CAN-Gateway decides which sensors exist on a given variant, how they are initialized, and which periodic or interrupt-driven hooks keep them updated.
The core implementation is found in repos/CAN-Gateway/Core/Src/App/SensorsIO/sensors.c with header definitions in repos/CAN-Gateway/Core/Inc/App/SensorsIO/sensors.h.
Compile-Time Board Variants
The same codebase compiles for both the front and rear physical PCB instances. The active variant is configured in repos/CAN-Gateway/Core/Inc/App/system_var.h by setting the DEVICE_TYPE preprocessor macro:
#define DEVICE_FRONT_GATEWAY 1
#define DEVICE_REAR_GATEWAY 2
#define DEVICE_TYPE DEVICE_FRONT_GATEWAY // Change here to toggle compiled variantVariant compilation alters sensor initialization lists and updates how signals map to the FDCAN structures.
Sensor Mapping Matrix
The board supports a wide range of analog and digital inputs, routed based on the compile-time configuration:
| Sensor Name | Front Gateway Variant | Rear Gateway Variant | Driver Class / Header | Input Hardware Peripheral |
|---|---|---|---|---|
| Wheel Speed | Front Right & Front Left | Rear Right & Rear Left | MX5051 | TIM4 period update / TIM2 input capture |
| Suspension Travel | Front Right & Front Left | Rear Right & Rear Left | KPM12J | ADC1 (DMA conversion) |
| APPS | APPS 1 & APPS 2 | N/A | APPS | ADC2 (DMA conversion) |
| Steering Angle | Steering displacement | N/A | steering | ADC2 (DMA conversion) |
| Brake Pressure | N/A | Brake line sensor | PU8702 | ADC2 (DMA conversion) |
| Current Sensor | N/A | JB Current (50A & 200A) | DHAB_S134 | ADC2 (DMA conversion) |
| Coolant Temp | N/A | Temp 1 & Temp 2 | GE1935 | ADC2 (DMA) & ADC1 (DMA) |
| Coolant Flow | N/A | Flow rate sensor | debit_2061 | EXTI Interrupt (GPIO pulse counter) |
| Digital Inputs | Ready-To-Drive (R2D) button | Shutdown Circuit (SDC) | debouncer | GPIO Digital Input |
NMOS Output Control & Hysteresis
The board manages high-side/low-side switching via on-board NMOS transistors (repos/CAN-Gateway/Core/Src/App/SensorsIO/nmos_vars.c):
- Front Gateway Variant: Controls the R2D button LED (
NMOS1_Pin) blinking period configured via CAN command. - Rear Gateway Variant:
- Brake LED Output (
NMOS1_Pin): Automatically driven based on PU8702 brake pressure with hysteresis to prevent output chatter:- Turn ON Threshold: Brake pressure
- Turn OFF Threshold: Brake pressure
- Hysteresis Band (
): Retains the previous output state.
- Turn ON Threshold: Brake pressure
- R2D Buzzer Output (
NMOS2_Pin): Controlled directly by incoming CAN message state.
- Brake LED Output (
Sensor Calibration & NVM Storage
Critical analog sensors require on-the-fly range calibration (such as APPS and steering sensors). The calibration sequences automatically register raw min/max voltages and save them to internal flash using the nimaltd/ee EEPROM Emulation Library.
For deep-dives into NVM configuration and calibration drivers, see:
