-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmake: modules: shields: Make it possible to give options to shield
This allows you to adapt the shield to your board at compile time. Signed-off-by: TOKITA Hiroshi <[email protected]>
- Loading branch information
Showing
4 changed files
with
488 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright (c) 2025 TOKITA Hiroshi | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef __DT_SHIELD_UTILS_H | ||
#define __DT_SHIELD_UTILS_H | ||
|
||
#include <zephyr/dt-bindings/dt-util.h> | ||
|
||
/** | ||
* @defgroup dts_shield_option_apis Shield option APIs | ||
* | ||
* Options included in a shield specifier are converted to a defined name | ||
* and value by the framework's rules. | ||
* This macro determine it is defined or not by the option name. | ||
* | ||
* @ingroup dts_apis | ||
* @{ | ||
*/ | ||
|
||
/** | ||
* Determines whether a specified option is defined. | ||
* | ||
* @param o option name | ||
*/ | ||
#define SHIELD_OPTION_EXISTS(o) \ | ||
IS_ENABLED( \ | ||
UTIL_CAT(UTIL_CAT(SHIELD_OPTION_, UTIL_CAT(SHIELD_DERIVED_NAME, \ | ||
UTIL_CAT(_, UTIL_CAT(o, _EXISTS)))))) | ||
|
||
/** | ||
* Get an option which is specified on the command line. | ||
* | ||
* Options included in a shield specifier are converted to a defined name | ||
* and value by the framework's rules. | ||
* This macro references it by the option name and gets the value. | ||
* | ||
* @param o option name | ||
*/ | ||
#define SHIELD_OPTION(o) \ | ||
COND_CODE_1(SHIELD_OPTION_EXISTS(o), \ | ||
(UTIL_CAT(SHIELD_OPTION_, \ | ||
UTIL_CAT(SHIELD_DERIVED_NAME, \ | ||
UTIL_CAT(_, o)))), \ | ||
(UTIL_CAT(SHIELD_OPTION_DEFAULT_, \ | ||
UTIL_CAT(SHIELD_BASE_NAME, \ | ||
UTIL_CAT(_, o))))) | ||
|
||
/* | ||
* Aliases for common options... | ||
*/ | ||
|
||
/** | ||
* Get an index parameter which is specified in the shield specifier. | ||
*/ | ||
#define SHIELD_INDEX COND_CODE_1(SHIELD_OPTION_EXISTS(__INDEX), \ | ||
(SHIELD_OPTION(__INDEX)), ()) | ||
|
||
#define SHIELD_CONN_EXISTS SHIELD_OPTION_EXISTS(CONN_TOKEN) | ||
|
||
/** | ||
* Get the `conn` option value. | ||
*/ | ||
#define SHIELD_CONN UTIL_CAT(SHIELD_OPTION(CONN_TOKEN), SHIELD_INDEX) | ||
|
||
#define SHIELD_LABEL_EXISTS SHIELD_OPTION_EXISTS(LABEL_TOKEN) | ||
|
||
/** | ||
* Get the `label` option value | ||
*/ | ||
#define SHIELD_LABEL SHIELD_OPTION(LABEL_TOKEN) | ||
|
||
#define SHIELD_ADDR_EXISTS SHIELD_OPTION_EXISTS(ADDR) | ||
|
||
/** | ||
* Get `addr` option value | ||
*/ | ||
#define SHIELD_ADDR SHIELD_OPTION(ADDR) | ||
|
||
/** | ||
* Get hexadecimal representation of `addr` option value | ||
*/ | ||
#define SHIELD_ADDR_HEX SHIELD_OPTION(ADDR_HEX) | ||
|
||
/** | ||
* Get addr option value with '0x' prefix | ||
*/ | ||
#define SHIELD_0X_ADDR UTIL_CAT(0x, SHIELD_OPTION(ADDR_HEX)) | ||
|
||
/* | ||
* Various utility macros... | ||
*/ | ||
|
||
#define SHIELD_CONVENTIONAL_LABEL_(stem) \ | ||
COND_CODE_1(SHIELD_OPTION_EXISTS(ADDR), \ | ||
(COND_CODE_1(SHIELD_OPTION_EXISTS(CONN), \ | ||
(UTIL_CAT(stem, \ | ||
UTIL_CAT(_, \ | ||
UTIL_CAT(SHIELD_ADDR, \ | ||
UTIL_CAT(_, SHIELD_CONN))))), \ | ||
(UTIL_CAT(stem, \ | ||
UTIL_CAT(_, SHIELD_ADDR))))), \ | ||
(COND_CODE_1(SHIELD_OPTION_EXISTS(CONN), \ | ||
(UTIL_CAT(stem, \ | ||
UTIL_CAT(_, SHIELD_CONN))), \ | ||
(stem)))) | ||
|
||
#define SHIELD_CONVENTIONAL_LABEL(stem) \ | ||
COND_CODE_1(SHIELD_OPTION_EXISTS(LABEL), \ | ||
(SHIELD_LABEL), \ | ||
(SHIELD_CONVENTIONAL_LABEL_(stem))) | ||
|
||
/** | ||
* @} | ||
*/ | ||
|
||
#endif /* __DT_SHIELD_UTILS_H */ |
Oops, something went wrong.