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