From 40cbbdbb452d797bd7ca8e4b445b0087c7b32c22 Mon Sep 17 00:00:00 2001 From: victhor Date: Mon, 2 Feb 2026 16:09:18 +0100 Subject: [PATCH 1/9] 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 70f2ae381..393fd5435 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/9] 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 393fd5435..2e1915ff2 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/9] 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 2e1915ff2..9c69702c2 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/9] 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 9c69702c2..cab291560 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/9] 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 cab291560..95cf952cf 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/9] 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 95cf952cf..c850e8266 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 From ee9167553dac51c91eb813ced1efcdf8180a3a62 Mon Sep 17 00:00:00 2001 From: victhor Date: Sat, 14 Feb 2026 18:00:51 +0100 Subject: [PATCH 7/9] fix missing NEXT --- 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 8e370071d..f7627e9e1 100644 --- a/Inc/ST-LIB.hpp +++ b/Inc/ST-LIB.hpp @@ -92,7 +92,7 @@ template struct BuildCtx { X(GPIODomain, gpio) NEXT \ X(TimerDomain, tim) NEXT \ X(DMA_Domain, dma) NEXT \ - X(SPIDomain, spi, GPIODomain::Init::instances, DMA_Domain::Init::instances) \ + X(SPIDomain, spi, GPIODomain::Init::instances, DMA_Domain::Init::instances) NEXT \ X(DigitalOutputDomain, dout, GPIODomain::Init::instances) NEXT \ X(DigitalInputDomain, din, GPIODomain::Init::instances) NEXT \ X(MdmaPacketDomain, mdmaPacket, MPUDomain::Init::instances) NEXT \ From 2556ef24bd4e0b76afa56ad4ddc3c590d583d676 Mon Sep 17 00:00:00 2001 From: victhor Date: Sat, 14 Feb 2026 18:06:57 +0100 Subject: [PATCH 8/9] remove duplicated owner_index_of() --- Inc/ST-LIB.hpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Inc/ST-LIB.hpp b/Inc/ST-LIB.hpp index f7627e9e1..af301c1ae 100644 --- a/Inc/ST-LIB.hpp +++ b/Inc/ST-LIB.hpp @@ -187,20 +187,6 @@ template struct Board { #undef X } - template - static consteval std::size_t owner_index_of() { - constexpr auto owners = ctx.template owners_span(); - - if constexpr (I >= owners.size()) { - compile_error("Device not registered in domain"); - return 0; - } else { - return owners[I] == &Target ? I : owner_index_of(); - } - - static constexpr auto cfg = build(); - } - template static consteval std::size_t owner_index_of() { constexpr auto owners = ctx.template owners_span(); From d7f96f76666ad32cb314ad61e31c7ad65f34c314 Mon Sep 17 00:00:00 2001 From: victhor Date: Sat, 14 Feb 2026 18:08:05 +0100 Subject: [PATCH 9/9] restore accidentally deleted cfg --- Inc/ST-LIB.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Inc/ST-LIB.hpp b/Inc/ST-LIB.hpp index af301c1ae..1c6aa1064 100644 --- a/Inc/ST-LIB.hpp +++ b/Inc/ST-LIB.hpp @@ -157,6 +157,8 @@ template struct Board { }; } + static constexpr auto cfg = build(); + static void init() { #define NEXT ; #define X(domain, inst, ...) \