diff --git a/soc/raspberrypi/rpi_pico/common/binary_info.c b/soc/raspberrypi/rpi_pico/common/binary_info.c index 0cf4b482da582de..7f31b80119951c2 100644 --- a/soc/raspberrypi/rpi_pico/common/binary_info.c +++ b/soc/raspberrypi/rpi_pico/common/binary_info.c @@ -7,13 +7,7 @@ #include #include -#if defined(CONFIG_SOC_RP2040) -#include -#elif defined(CONFIG_SOC_RP2350A) -#include -#elif defined(CONFIG_SOC_RP2350B) -#include -#endif +#include #include @@ -232,6 +226,8 @@ #define EXPR_EQ(n, m) UTIL_CAT(UTIL_CAT(UTIL_CAT(EXPR_EQ_, n), _), m) +/* utils for pin encoding calcluation */ + #ifdef CONFIG_SOC_RP2040 #define PIN_ENCODE(n, idx, offset) ((uint32_t)PIN_NUM(n, idx) << (2 + (idx + offset + 1) * 5)) #define MAX_PIN_ENTRY 4 @@ -243,6 +239,8 @@ #define PIN_NUM(n, idx) ((DT_PROP_BY_IDX(n, pinmux, idx) >> RP2_PIN_NUM_POS) & RP2_PIN_NUM_MASK) #define PIN_FUNC(n, idx) (DT_PROP_BY_IDX(n, pinmux, idx) & RP2_ALT_FUNC_MASK) +/* Recurrence formula for calculating pin offsets for each group */ + #define OFFSET_TO_GROUP_IDX_N(n, i, x) \ EXPR_ADD(COND_CODE_1(DT_NODE_HAS_PROP(DT_CHILD_BY_IDX(n, i), pinmux), \ (DT_PROP_LEN(DT_CHILD_BY_IDX(n, i), pinmux)), (0)), x) @@ -260,11 +258,15 @@ #define OFFSET_TO_GROUP_IDX(n, i) UTIL_CAT(OFFSET_TO_GROUP_IDX_, i)(n) #define COUNT_ALL_PINS(n) OFFSET_TO_GROUP_IDX_8(n) +/* Iterate groups and subgroups */ + #define EACH_PINCTRL_SUBGROUP(n, fn, sep, ...) \ DT_FOREACH_PROP_ELEM_SEP_VARGS(n, pinmux, fn, sep, __VA_ARGS__) #define EACH_PINCTRL_GROUP(n, sep, fn, ...) \ DT_FOREACH_CHILD_SEP_VARGS(n, EACH_PINCTRL_SUBGROUP, sep, fn, sep, __VA_ARGS__) +/* Encode the pins in a group */ + #define IS_LAST_PIN(end, idx, off) EXPR_EQ(end, EXPR_ADD(1, EXPR_ADD(idx, off))) #define PIN_ENTRY(n, p, i, offset) \ COND_CODE_1(DT_PROP_HAS_IDX(n, p, i), (PIN_ENCODE(n, i, offset)), (0)) @@ -276,9 +278,13 @@ end) #define ENCODE_GROUP_PINS(n) (EACH_PINCTRL_GROUP(n, (|), ENCODE_EACH_PIN, COUNT_ALL_PINS(n))) +/* Get group-wide pin functions */ + #define EACH_PIN_FUNC(n, p, i, _) PIN_FUNC(n, i) #define GROUP_PIN_FUNC(n) (EACH_PINCTRL_GROUP(n, (|), EACH_PIN_FUNC)) +/* Check if pin functions are all equal within a group */ + #define EACH_PIN_FUNC_IS(n, p, i, func) (PIN_FUNC(n, i) == func) #define ALL_PIN_FUNC_IS(n, pinfunc) (EACH_PINCTRL_GROUP(n, (&&), EACH_PIN_FUNC_IS, pinfunc)) @@ -373,7 +379,7 @@ bi_decl(bi_string(BINARY_INFO_TAG_RASPBERRY_PI, BINARY_INFO_ID_RP_BOOT2_NAME, (uint32_t)PICO_BOOT_STAGE2_NAME)); #endif -#ifndef NDEBUG +#ifdef CONFIG_DEBUG bi_decl(bi_program_build_attribute((uint32_t) "Debug")); #else bi_decl(bi_program_build_attribute((uint32_t) "Release"));