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 "type_traits.hpp"
#include "config_types.h"
#include "utils_bits.h"
#include "load_map.h"
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  OverrideTable< N, MaxPins >::Entry
 Internal structure representing a pin and its associated bitmasks. More...
 
class  OverrideTable< N, MaxPins >
 Manages override pins and their associated bitmasks for forced operation. More...
 
class  TargetMap< NL, NR, D >
 What the target codes of config.h stand for, once the load map and the relays are known. 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

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.
 
template<uint8_t N>
constexpr uint32_t localLoadsMask (const uint8_t(&loadMap)[N])
 Bitmask of the pins of every local load (lower 16 bits).
 
template<uint8_t N>
constexpr uint8_t overridePinOf (const uint8_t(&loadMap)[N], uint8_t loadNum)
 Override pin of a load: its physical pin if local, a virtual pin if remote.
 
template<uint8_t MaxPins, uint8_t N>
 OverrideTable (const KeyIndexPair< MaxPins >(&)[N]) -> OverrideTable< N, MaxPins >
 Deduction guide for OverrideTable, from plain pins. Allows template argument deduction from constructor arguments.
 
template<uint8_t N>
constexpr uint32_t remoteLoadsMask (const uint8_t(&loadMap)[N])
 Bitmask of every remote load (bit 16 + remote rank).
 

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

config.h writes the override pins with codes (OverridePins, in config_types.h): TargetMap turns each code into its pins, and OverrideTable holds the resulting bitmasks.

Usage example, with plain pins:

constexpr OverrideTable table{ { { 2, { 5, 6 } },
{ 3, { 7 } } } };
Manages override pins and their associated bitmasks for forced operation.
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.2
Date
2026-11-21

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 110 of file utils_override.h.

Function Documentation

◆ 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 101 of file utils_override.h.

Here is the caller graph for this function:

◆ 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 118 of file utils_override.h.

Here is the caller graph for this function:

◆ localLoadsMask()

template<uint8_t N>
uint32_t localLoadsMask ( const uint8_t(&) loadMap[N])
constexpr

Bitmask of the pins of every local load (lower 16 bits).

Definition at line 65 of file utils_override.h.

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

◆ overridePinOf()

template<uint8_t N>
uint8_t overridePinOf ( const uint8_t(&) loadMap[N],
uint8_t loadNum )
constexpr

Override pin of a load: its physical pin if local, a virtual pin if remote.

The virtual pin is REMOTE_PIN_BASE + the load's rank among the remote loads, which is also its bit in the remote override bitmask.

Parameters
loadMapThe packed load map.
loadNumIndex into the map.

Definition at line 54 of file utils_override.h.

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

◆ OverrideTable()

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

Deduction guide for OverrideTable, from plain pins. Allows template argument deduction from constructor arguments.

◆ remoteLoadsMask()

template<uint8_t N>
uint32_t remoteLoadsMask ( const uint8_t(&) loadMap[N])
constexpr

Bitmask of every remote load (bit 16 + remote rank).

Definition at line 82 of file utils_override.h.

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

Variable Documentation

◆ validPinMask

uint16_t validPinMask { 0b11111111111100 }
constexpr

Definition at line 93 of file utils_override.h.