3-phase PV router
Loading...
Searching...
No Matches
utils_override.h File Reference

Compile-time utilities for managing override pins and index-to-bitmask mapping. More...

#include "config.h"
#include "type_traits.hpp"
Include dependency graph for utils_override.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  OverridePins< N, MaxPins >::Entry
 Internal structure representing a pin and its associated bitmask. More...
 
struct  KeyIndexPair< MaxPins >
 Structure holding a pin and its associated index list. More...
 
class  OverridePins< N, MaxPins >
 Manages override pins and their associated bitmasks for forced operation. More...
 
struct  PinList< MaxPins >
 Wrapper for a list of pins, constructible from variadic arguments. More...
 

Macros

#define VALIDATE_PINS(...)
 Helper macro to validate pins at compile time. Usage: VALIDATE_PINS(2, 3, 5) will cause a compile error if any pin is invalid.
 

Functions

constexpr uint16_t ALL_LOADS ()
 Returns a bitmask representing all load pins.
 
constexpr uint16_t ALL_LOADS_AND_RELAYS ()
 Returns a bitmask representing all loads and all relays.
 
constexpr uint16_t ALL_RELAYS ()
 Returns a bitmask representing all relay pins.
 
template<uint8_t... Pins>
constexpr bool are_pins_valid ()
 Compile-time validation function for pin values.
 
template<uint8_t... Pins>
constexpr uint16_t indicesToBitmask ()
 Helper to convert pins to a bitmask at compile-time.
 
constexpr uint8_t LOAD (uint8_t loadNum)
 Returns the pin number for a given load index at compile time.
 
template<uint8_t MaxPins, uint8_t N>
 OverridePins (const KeyIndexPair< MaxPins >(&)[N]) -> OverridePins< N, MaxPins >
 Deduction guide for OverridePins template. Allows template argument deduction from constructor arguments.
 
constexpr uint8_t RELAY (uint8_t relayNum)
 Returns the pin number for a given relay index at compile time.
 

Variables

constexpr uint16_t validPinMask { 0b11111111111100 }
 

Detailed Description

Compile-time utilities for managing override pins and index-to-bitmask mapping.

This header provides types and functions for representing and manipulating sets of override pins and their associated pins, all at compile time. It enables efficient bitmask computation and static configuration of pin mappings for embedded systems, such as PVRouter.

Pin features:

  • Compile-time conversion of index lists to bitmasks
  • Type-safe representation of pin/index associations
  • Static configuration of override pin mappings
  • Template deduction guide for convenient usage

Usage example:

{2, {1, 3}},
{3, {0, 2, 6}},
{4, {5}}
};
constexpr OverridePins<3, 8> pins{pairs};
Manages override pins and their associated bitmasks for forced operation.
constexpr OverridePins overridePins
Definition config.h:143
Author
Frédéric Metrich (frede.nosp@m.ric..nosp@m.metri.nosp@m.ch@l.nosp@m.ive.f.nosp@m.r)
Version
0.1
Date
2025-09-08

Definition in file utils_override.h.

Macro Definition Documentation

◆ VALIDATE_PINS

#define VALIDATE_PINS ( ...)
Value:
static_assert(are_pins_valid< __VA_ARGS__ >(), "Invalid pin(s) specified")
constexpr bool are_pins_valid()
Compile-time validation function for pin values.

Helper macro to validate pins at compile time. Usage: VALIDATE_PINS(2, 3, 5) will cause a compile error if any pin is invalid.

Definition at line 121 of file utils_override.h.

Function Documentation

◆ ALL_LOADS()

uint16_t ALL_LOADS ( )
constexpr

Returns a bitmask representing all load pins.

This helper is used to configure an override pin to control all loads at once.

Returns
Bitmask with all load pins set.

Definition at line 64 of file utils_override.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ALL_LOADS_AND_RELAYS()

uint16_t ALL_LOADS_AND_RELAYS ( )
constexpr

Returns a bitmask representing all loads and all relays.

This helper is used to configure an override pin to control the entire system (all loads and relays).

Returns
Bitmask with all load and relay pins set.

Definition at line 98 of file utils_override.h.

Here is the call graph for this function:

◆ ALL_RELAYS()

uint16_t ALL_RELAYS ( )
constexpr

Returns a bitmask representing all relay pins.

This helper is used to configure an override pin to control all relays at once.

Returns
Bitmask with all relay pins set.

Definition at line 81 of file utils_override.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ are_pins_valid()

template<uint8_t... Pins>
bool are_pins_valid ( )
constexpr

Compile-time validation function for pin values.

Template Parameters
PinsList of pins to validate.
Returns
true if all pins are valid, false otherwise.

Definition at line 112 of file utils_override.h.

◆ indicesToBitmask()

template<uint8_t... Pins>
uint16_t indicesToBitmask ( )
constexpr

Helper to convert pins to a bitmask at compile-time.

Template Parameters
PinsList of pins to set in the bitmask.
Returns
Bitmask with bits set at the specified pins.

Definition at line 129 of file utils_override.h.

◆ LOAD()

uint8_t LOAD ( uint8_t loadNum)
constexpr

Returns the pin number for a given load index at compile time.

Parameters
loadNumThe load index (0-based).
Returns
The pin number for the load.

Definition at line 42 of file utils_override.h.

◆ OverridePins()

template<uint8_t MaxPins, uint8_t N>
OverridePins ( const KeyIndexPair< MaxPins > (&)[N]) -> OverridePins< N, MaxPins >

Deduction guide for OverridePins template. Allows template argument deduction from constructor arguments.

◆ RELAY()

uint8_t RELAY ( uint8_t relayNum)
constexpr

Returns the pin number for a given relay index at compile time.

Parameters
relayNumThe relay index (0-based).
Returns
The pin number for the relay.

Definition at line 52 of file utils_override.h.

Variable Documentation

◆ validPinMask

uint16_t validPinMask { 0b11111111111100 }
constexpr

Definition at line 104 of file utils_override.h.