zephyr/tests/kconfig/functions/Kconfig
Grzegorz Swiderski 64bb8b6796 scripts: kconfig: Add hex variants of arithmetic functions
Functions like `add` and `sub` can only return base 10 integers, which
means they can't really be used to define Kconfig symbols of type `hex`.

For the same reason, there already exist pairs of devicetree functions
named e.g., `dt_node_reg_addr_(int|hex)` after different return types.

Introduce `add_hex`, `sub_hex`, and friends.

To avoid confusion, it should be possible for those new functions to
accept arguments in base 16 as well. It's actually easier to let all
arithmetic functions take their inputs in "any" base, by leveraging
Python's built-in: `int(..., base=0)`.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2025-06-17 16:09:41 +02:00

117 lines
1.9 KiB
Plaintext

# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2022 CSIRO
config KCONFIG_ARITHMETIC_ADD_10
int
default $(add, 10)
config KCONFIG_ARITHMETIC_ADD_10_3
hex
default $(add_hex, 10, 3)
config KCONFIG_ARITHMETIC_ADD_10_3_2
int
default $(add, 0xa, 3, 0b10)
config KCONFIG_ARITHMETIC_SUB_10
int
default $(sub, 10)
config KCONFIG_ARITHMETIC_SUB_10_3
hex
default $(sub_hex, 10, 3)
config KCONFIG_ARITHMETIC_SUB_10_3_2
int
default $(sub, 0xa, 3, 0b10)
config KCONFIG_ARITHMETIC_MUL_10
int
default $(mul, 10)
config KCONFIG_ARITHMETIC_MUL_10_3
hex
default $(mul_hex, 10, 3)
config KCONFIG_ARITHMETIC_MUL_10_3_2
int
default $(mul, 0xa, 3, 0b10)
config KCONFIG_ARITHMETIC_DIV_10
int
default $(div, 10)
config KCONFIG_ARITHMETIC_DIV_10_3
hex
default $(div_hex, 10, 3)
config KCONFIG_ARITHMETIC_DIV_10_3_2
int
default $(div, 0xa, 3, 0b10)
config KCONFIG_ARITHMETIC_MOD_10
int
default $(mod, 10)
config KCONFIG_ARITHMETIC_MOD_10_3
hex
default $(mod_hex, 10, 3)
config KCONFIG_ARITHMETIC_MOD_10_3_2
int
default $(mod, 0xa, 3, 0b10)
config KCONFIG_ARITHMETIC_INC_1
int
default $(inc, 1)
config KCONFIG_ARITHMETIC_INC_1_1
string
default "$(inc_hex, 1, 1)"
config KCONFIG_ARITHMETIC_INC_INC_1_1
string
default "$(inc, $(inc_hex, 0x1, 0b1))"
config KCONFIG_ARITHMETIC_DEC_1
int
default $(dec, 1)
config KCONFIG_ARITHMETIC_DEC_1_1
string
default "$(dec_hex, 1, 1)"
config KCONFIG_ARITHMETIC_DEC_DEC_1_1
string
default "$(dec, $(dec_hex, 0x1, 0b1))"
config KCONFIG_ARITHMETIC_ADD_INC_1_1
int
default $(add, $(inc_hex, 1, 1))
config KCONFIG_MIN_10
int
default $(min, 10)
config KCONFIG_MIN_10_3
hex
default $(min_hex, 10, 3)
config KCONFIG_MIN_10_3_2
int
default $(min, 0xa, 3, 0b10)
config KCONFIG_MAX_10
int
default $(max, 10)
config KCONFIG_MAX_10_3
hex
default $(max_hex, 10, 3)
config KCONFIG_MAX_10_3_2
int
default $(max, 0xa, 3, 0b10)
source "Kconfig.zephyr"