From 40cbbdbb452d797bd7ca8e4b445b0087c7b32c22 Mon Sep 17 00:00:00 2001 From: victhor Date: Mon, 2 Feb 2026 16:09:18 +0100 Subject: [PATCH 1/6] feat: Update xlist --- Inc/ST-LIB.hpp | 126 ++++++++++++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 58 deletions(-) diff --git a/Inc/ST-LIB.hpp b/Inc/ST-LIB.hpp index 70f2ae38..393fd543 100644 --- a/Inc/ST-LIB.hpp +++ b/Inc/ST-LIB.hpp @@ -83,11 +83,30 @@ template struct BuildCtx { } }; -using DomainsCtx = BuildCtx; +/* DomainXList params: + * - First param: Domain name + * - Second param: instance name + * - Third param: true if it needs the nº of instances to be templated, + * false otherwise (mainly for MPUdomain) + * - Rest: any dependencies on previous domains + */ +#define DomainXList \ + X(MPUDomain, mpu, true) NEXT \ + X(GPIODomain, gpio, false) NEXT \ + X(TimerDomain, tim, false) NEXT \ + X(DigitalOutputDomain, dout, false, GPIODomain::Init::instances) NEXT \ + X(DigitalInputDomain, din, false, GPIODomain::Init::instances) NEXT \ + X(MdmaPacketDomain, mdmaPacket, false, MPUDomain::Init::instances) NEXT \ + /* X(ADCDomain, adc, false) NEXT */ \ + X(SdDomain, sd, false, MPUDomain::Init::instances, DigitalInputDomain::Init::instances) + +#define NEXT , +#define X(domain, inst, is_templated, ...) domain + +using DomainCtx = BuildCtx; + +#undef NEXT +#undef X template struct Board { static consteval auto build_ctx() { @@ -102,71 +121,62 @@ template struct Board { return ctx.template span().size(); } + static consteval auto build() { - constexpr std::size_t mpuN = domain_size(); - constexpr std::size_t gpioN = domain_size(); - constexpr std::size_t timN = domain_size(); - constexpr std::size_t doutN = domain_size(); - constexpr std::size_t dinN = domain_size(); - constexpr std::size_t mdmaPacketN = domain_size(); - constexpr std::size_t sdN = domain_size(); - // ... +#define NEXT ; +#define X(domain, inst, is_templated, ...) \ + constexpr std::size_t inst##N = domain_size(); + + DomainXList; + +#undef NEXT +#undef X struct ConfigBundle { - std::array mpu_cfgs; - std::array gpio_cfgs; - std::array tim_cfgs; - std::array dout_cfgs; - std::array din_cfgs; - std::array mdma_packet_cfgs; - std::array sd_cfgs; - // ... +#define NEXT ; +#define X(domain, inst, is_templated, ...) \ + std::array inst##_cfgs + + DomainXList; + +#undef NEXT +#undef X }; return ConfigBundle{ - .mpu_cfgs = MPUDomain::template build( - ctx.template span()), - .gpio_cfgs = - GPIODomain::template build(ctx.template span()), - .tim_cfgs = - TimerDomain::template build(ctx.template span()), - .dout_cfgs = DigitalOutputDomain::template build( - ctx.template span()), - .din_cfgs = DigitalInputDomain::template build( - ctx.template span()), - .mdma_packet_cfgs = MdmaPacketDomain::template build( - ctx.template span()), - .sd_cfgs = SdDomain::template build( - ctx.template span()), - // ... +#define NEXT , +#define X(domain, inst, is_templated, ...) \ + .inst##_cfgs = domain::template build(ctx.template span()) + + DomainXList, + +#undef NEXT +#undef X }; } static constexpr auto cfg = build(); static void init() { - constexpr std::size_t mpuN = domain_size(); - constexpr std::size_t gpioN = domain_size(); - constexpr std::size_t timN = domain_size(); - constexpr std::size_t doutN = domain_size(); - constexpr std::size_t dinN = domain_size(); - constexpr std::size_t mdmaPacketN = domain_size(); - constexpr std::size_t sdN = domain_size(); - // ... - - MPUDomain::Init::init(); - GPIODomain::Init::init(cfg.gpio_cfgs); - TimerDomain::Init::init(cfg.tim_cfgs); - DigitalOutputDomain::Init::init(cfg.dout_cfgs, - GPIODomain::Init::instances); - DigitalInputDomain::Init::init(cfg.din_cfgs, - GPIODomain::Init::instances); - MdmaPacketDomain::Init::init(cfg.mdma_packet_cfgs, - MPUDomain::Init::instances); - SdDomain::Init::init(cfg.sd_cfgs, - MPUDomain::Init::instances, - DigitalInputDomain::Init::instances); - // ... +#define NEXT ; +#define X(domain, inst, is_templated, ...) \ + constexpr std::size_t inst##N = domain_size(); + + DomainXList; + +#undef X + +#define X(domain, inst, is_templated, ...) \ + if constexpr(is_templated) { \ + domain::Init::init(__VA_ARGS__); \ + } else { \ + domain::Init::init(cfg.inst##_cfgs, ##__VA_ARGS__); \ + } + + DomainXList; + +#undef NEXT +#undef X } template From cbaaca673274cd703250be140f66a572e262318b Mon Sep 17 00:00:00 2001 From: victhor Date: Mon, 2 Feb 2026 16:20:28 +0100 Subject: [PATCH 2/6] fix xlist hopefully --- Inc/ST-LIB.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Inc/ST-LIB.hpp b/Inc/ST-LIB.hpp index 393fd543..2e1915ff 100644 --- a/Inc/ST-LIB.hpp +++ b/Inc/ST-LIB.hpp @@ -168,7 +168,7 @@ template struct Board { #define X(domain, inst, is_templated, ...) \ if constexpr(is_templated) { \ - domain::Init::init(__VA_ARGS__); \ + domain::Init::init(##__VA_ARGS__); \ } else { \ domain::Init::init(cfg.inst##_cfgs, ##__VA_ARGS__); \ } From 4068ac4de9aebe310e9282312b958e3dfe528203 Mon Sep 17 00:00:00 2001 From: victhor Date: Mon, 2 Feb 2026 16:23:37 +0100 Subject: [PATCH 3/6] I give up, no arguments >:( --- Inc/ST-LIB.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Inc/ST-LIB.hpp b/Inc/ST-LIB.hpp index 2e1915ff..9c69702c 100644 --- a/Inc/ST-LIB.hpp +++ b/Inc/ST-LIB.hpp @@ -168,7 +168,7 @@ template struct Board { #define X(domain, inst, is_templated, ...) \ if constexpr(is_templated) { \ - domain::Init::init(##__VA_ARGS__); \ + domain::Init::init(); \ } else { \ domain::Init::init(cfg.inst##_cfgs, ##__VA_ARGS__); \ } From e00bbb98cf1910e08e9d851331081f8853bfdda0 Mon Sep 17 00:00:00 2001 From: victhor Date: Mon, 2 Feb 2026 16:28:45 +0100 Subject: [PATCH 4/6] No templated, this should hopefully work --- Inc/ST-LIB.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Inc/ST-LIB.hpp b/Inc/ST-LIB.hpp index 9c69702c..cab29156 100644 --- a/Inc/ST-LIB.hpp +++ b/Inc/ST-LIB.hpp @@ -167,12 +167,12 @@ template struct Board { #undef X #define X(domain, inst, is_templated, ...) \ - if constexpr(is_templated) { \ - domain::Init::init(); \ - } else { \ + if constexpr(!is_templated) { \ domain::Init::init(cfg.inst##_cfgs, ##__VA_ARGS__); \ } + /* Any templated go here since I couldn't get it to compile otherwise */ + MPUDomain::Init::init(); DomainXList; #undef NEXT From 0be4c2f49615e3c82b8164b0a1a3771493433588 Mon Sep 17 00:00:00 2001 From: victhor Date: Mon, 2 Feb 2026 16:36:43 +0100 Subject: [PATCH 5/6] This could work? --- Inc/ST-LIB.hpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Inc/ST-LIB.hpp b/Inc/ST-LIB.hpp index cab29156..95cf952c 100644 --- a/Inc/ST-LIB.hpp +++ b/Inc/ST-LIB.hpp @@ -86,22 +86,22 @@ template struct BuildCtx { /* DomainXList params: * - First param: Domain name * - Second param: instance name - * - Third param: true if it needs the nº of instances to be templated, - * false otherwise (mainly for MPUdomain) * - Rest: any dependencies on previous domains */ #define DomainXList \ - X(MPUDomain, mpu, true) NEXT \ - X(GPIODomain, gpio, false) NEXT \ - X(TimerDomain, tim, false) NEXT \ - X(DigitalOutputDomain, dout, false, GPIODomain::Init::instances) NEXT \ - X(DigitalInputDomain, din, false, GPIODomain::Init::instances) NEXT \ - X(MdmaPacketDomain, mdmaPacket, false, MPUDomain::Init::instances) NEXT \ - /* X(ADCDomain, adc, false) NEXT */ \ - X(SdDomain, sd, false, MPUDomain::Init::instances, DigitalInputDomain::Init::instances) + X_TEMPLATED(MPUDomain, mpu) NEXT \ + X(GPIODomain, gpio) NEXT \ + X(TimerDomain, tim) NEXT \ + X(DigitalOutputDomain, dout, GPIODomain::Init::instances) NEXT \ + X(DigitalInputDomain, din, GPIODomain::Init::instances) NEXT \ + X(MdmaPacketDomain, mdmaPacket, MPUDomain::Init::instances) NEXT \ + /* X(ADCDomain, adc) NEXT */ \ + X(SdDomain, sd, MPUDomain::Init::instances, DigitalInputDomain::Init::instances) + +#define X_TEMPLATED X #define NEXT , -#define X(domain, inst, is_templated, ...) domain +#define X(domain, inst, ...) domain using DomainCtx = BuildCtx; @@ -124,7 +124,7 @@ template struct Board { static consteval auto build() { #define NEXT ; -#define X(domain, inst, is_templated, ...) \ +#define X(domain, inst, ...) \ constexpr std::size_t inst##N = domain_size(); DomainXList; @@ -134,7 +134,7 @@ template struct Board { struct ConfigBundle { #define NEXT ; -#define X(domain, inst, is_templated, ...) \ +#define X(domain, inst, ...) \ std::array inst##_cfgs DomainXList; @@ -145,7 +145,7 @@ template struct Board { return ConfigBundle{ #define NEXT , -#define X(domain, inst, is_templated, ...) \ +#define X(domain, inst, ...) \ .inst##_cfgs = domain::template build(ctx.template span()) DomainXList, @@ -159,23 +159,23 @@ template struct Board { static void init() { #define NEXT ; -#define X(domain, inst, is_templated, ...) \ +#define X(domain, inst, ...) \ constexpr std::size_t inst##N = domain_size(); DomainXList; #undef X -#define X(domain, inst, is_templated, ...) \ - if constexpr(!is_templated) { \ - domain::Init::init(cfg.inst##_cfgs, ##__VA_ARGS__); \ - } +#undef X_TEMPLATED +#define X_TEMPLATED(domain, inst, ...) \ + domain::Init::init(##__VA_ARGS__); +#define X(domain, inst, ...) \ + domain::Init::init(cfg.inst##_cfgs, ##__VA_ARGS__); - /* Any templated go here since I couldn't get it to compile otherwise */ - MPUDomain::Init::init(); DomainXList; #undef NEXT +#undef X_TEMPLATED #undef X } From 0e836813436c978484aee97af878c19432cbcb87 Mon Sep 17 00:00:00 2001 From: victhor Date: Mon, 2 Feb 2026 16:39:42 +0100 Subject: [PATCH 6/6] DomainCtx -> DomainsCtx --- Inc/ST-LIB.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Inc/ST-LIB.hpp b/Inc/ST-LIB.hpp index 95cf952c..c850e826 100644 --- a/Inc/ST-LIB.hpp +++ b/Inc/ST-LIB.hpp @@ -103,7 +103,7 @@ template struct BuildCtx { #define NEXT , #define X(domain, inst, ...) domain -using DomainCtx = BuildCtx; +using DomainsCtx = BuildCtx; #undef NEXT #undef X