From 2b6ff5702d2da694ce9a83fd08593c9f717dd1e7 Mon Sep 17 00:00:00 2001 From: victhor Date: Mon, 8 Dec 2025 12:34:55 +0100 Subject: [PATCH] fix: Use an XList for the domains in ST-LIB Unfortunately the dummy is necessary but now we only need to specify a domain in a single place had to add ## to __VA_ARGS__ for it to remove the comma when there are no varargs this does not work in msvc unless -Zc:preprocessor is specified because their implementation of macros works differently --- Inc/ST-LIB.hpp | 59 ++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/Inc/ST-LIB.hpp b/Inc/ST-LIB.hpp index dff92504d..6cfef0654 100644 --- a/Inc/ST-LIB.hpp +++ b/Inc/ST-LIB.hpp @@ -69,8 +69,19 @@ template struct BuildCtx { } }; -using DomainsCtx = BuildCtx; +#define DomainXList \ + X(GPIODomain, gpio) \ + X(DigitalOutputDomain, dout, GPIODomain::Init::instances) \ + X(DigitalInputDomain, din, GPIODomain::Init::instances) + +// Do not use this class +struct Dummy { + static const std::size_t max_instances{1}; + struct Entry { uint32_t dummy; }; +}; + +#define X(x, y, ...) x, +using DomainsCtx = BuildCtx; template struct Board { static consteval auto build_ctx() { @@ -85,44 +96,36 @@ template struct Board { return ctx.template span().size(); } +#undef X +#define X(x, y, ...) constexpr std::size_t y##N = domain_size(); + static consteval auto build() { - constexpr std::size_t gpioN = domain_size(); - constexpr std::size_t doutN = domain_size(); - constexpr std::size_t dinN = domain_size(); - // ... + DomainXList; +#undef X +#define X(x, y, ...) std::array y##_cfgs; struct ConfigBundle { - std::array gpio_cfgs; - std::array dout_cfgs; - std::array din_cfgs; - // ... + DomainXList }; +#undef X +#define X(x, y, ...) .y##_cfgs = x::template build(ctx.template span()), return ConfigBundle{ - .gpio_cfgs = - GPIODomain::template build(ctx.template span()), - .dout_cfgs = DigitalOutputDomain::template build( - ctx.template span()), - .din_cfgs = DigitalInputDomain::template build( - ctx.template span()), - // ... + DomainXList }; } static constexpr auto cfg = build(); +#undef X +#define X(x, y, ...) constexpr std::size_t y##N = domain_size(); static void init() { - constexpr std::size_t gpioN = domain_size(); - constexpr std::size_t doutN = domain_size(); - constexpr std::size_t dinN = domain_size(); - // ... - - GPIODomain::Init::init(cfg.gpio_cfgs); - DigitalOutputDomain::Init::init(cfg.dout_cfgs, - GPIODomain::Init::instances); - DigitalInputDomain::Init::init(cfg.din_cfgs, - GPIODomain::Init::instances); - // ... + DomainXList; + +#undef X +#define X(x, y, ...) x::Init::init(cfg.y##_cfgs, ##__VA_ARGS__); + + DomainXList; } template