diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index c027c7c0d1070..316f0c70f48ba 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -5064,6 +5064,15 @@ West: labels: - "area: West" +"West project: Arduino-Core-Zephyr": + status: maintained + maintainers: + - dhruvag2000 + files: + - snippets/arduino-core/ + labels: + - manifest-arduino-api + "West project: acpica": status: maintained maintainers: @@ -5253,6 +5262,15 @@ West: labels: - "area: Storage" +"West project: gsoc-2022-arduino-core": + status: maintained + maintainers: + - dhruvag2000 + files: + - snippets/arduino-core/ + labels: + - manifest-arduino-api + "West project: hal_adi": status: maintained maintainers: diff --git a/dts/bindings/adc/arduino,uno-adc.yaml b/dts/bindings/adc/arduino,uno-adc.yaml index 854e640914a4f..6d409b861b13f 100644 --- a/dts/bindings/adc/arduino,uno-adc.yaml +++ b/dts/bindings/adc/arduino,uno-adc.yaml @@ -13,20 +13,4 @@ description: | compatible: "arduino,uno-adc" -include: base.yaml - -properties: - io-channel-map: - type: compound - required: true - - io-channel-map-mask: - type: compound - - io-channel-map-pass-thru: - type: compound - - "#io-channel-cells": - type: int - required: true - description: Number of items to expect in an ADC specifier +include: [base.yaml, io-channel-nexus.yaml] diff --git a/dts/bindings/gpio/gpio-nexus.yaml b/dts/bindings/gpio/gpio-nexus.yaml index a1bcbc61e5ae0..de8153b0f9a89 100644 --- a/dts/bindings/gpio/gpio-nexus.yaml +++ b/dts/bindings/gpio/gpio-nexus.yaml @@ -9,10 +9,10 @@ properties: required: true gpio-map-mask: - type: compound + type: array gpio-map-pass-thru: - type: compound + type: array "#gpio-cells": type: int diff --git a/dts/bindings/iio/io-channel-nexus.yaml b/dts/bindings/iio/io-channel-nexus.yaml new file mode 100644 index 0000000000000..d34ca7b5be607 --- /dev/null +++ b/dts/bindings/iio/io-channel-nexus.yaml @@ -0,0 +1,20 @@ +# Copyright (c) 2025 TOKITA Hiroshi +# SPDX-License-Identifier: Apache-2.0 + +# Common fields for io-channel nexus + +properties: + io-channel-map: + type: compound + required: true + + io-channel-map-mask: + type: array + + io-channel-map-pass-thru: + type: array + + "#io-channel-cells": + type: int + required: true + description: Number of items to expect in the io-channel specifier, such as ADC channels. diff --git a/dts/bindings/interrupt-controller/interrupt-nexus.yaml b/dts/bindings/interrupt-controller/interrupt-nexus.yaml new file mode 100644 index 0000000000000..cc7d6060fd023 --- /dev/null +++ b/dts/bindings/interrupt-controller/interrupt-nexus.yaml @@ -0,0 +1,20 @@ +# Copyright (c) 2025 TOKITA Hiroshi +# SPDX-License-Identifier: Apache-2.0 + +# Common fields for interrupt nexus nodes + +properties: + interrupt-map: + type: compound + required: true + + interrupt-map-mask: + type: array + + interrupt-map-pass-thru: + type: array + + "#interrupt-cells": + type: int + required: true + description: Number of items to expect in a interrupt specifier diff --git a/dts/bindings/pcie/host/pci-host-ecam-generic.yaml b/dts/bindings/pcie/host/pci-host-ecam-generic.yaml index fea7d35ef17a5..0a42b180665a3 100644 --- a/dts/bindings/pcie/host/pci-host-ecam-generic.yaml +++ b/dts/bindings/pcie/host/pci-host-ecam-generic.yaml @@ -5,7 +5,7 @@ description: PCIe Controller in ECAM mode compatible: "pci-host-ecam-generic" -include: pcie-controller.yaml +include: [pcie-controller.yaml, interrupt-nexus.yaml] properties: reg: @@ -22,11 +22,5 @@ properties: definition of non-prefetchable memory. One or both of prefetchable Memory and IO Space may also be provided. - interrupt-map-mask: - type: array - - interrupt-map: - type: compound - bus-range: type: array diff --git a/dts/bindings/test/vnd,gpio-nexus.yaml b/dts/bindings/test/vnd,gpio-nexus.yaml new file mode 100644 index 0000000000000..2274be7451da1 --- /dev/null +++ b/dts/bindings/test/vnd,gpio-nexus.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2025, TOKITA Hiroshi +# SPDX-License-Identifier: Apache-2.0 + +description: VND GPIO nexus + +include: [gpio-nexus.yaml] + +compatible: "vnd,gpio-nexus" diff --git a/dts/bindings/test/vnd,intr-nexus.yaml b/dts/bindings/test/vnd,intr-nexus.yaml new file mode 100644 index 0000000000000..f3b194c558385 --- /dev/null +++ b/dts/bindings/test/vnd,intr-nexus.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2025, TOKITA Hiroshi +# SPDX-License-Identifier: Apache-2.0 + +description: VND interrupt nexus + +include: [interrupt-nexus.yaml] + +compatible: "vnd,intr-nexus" diff --git a/include/zephyr/devicetree.h b/include/zephyr/devicetree.h index ded261d66cd08..c0c650e11971d 100644 --- a/include/zephyr/devicetree.h +++ b/include/zephyr/devicetree.h @@ -5570,5 +5570,6 @@ #include #include #include +#include #endif /* ZEPHYR_INCLUDE_DEVICETREE_H_ */ diff --git a/include/zephyr/devicetree/map.h b/include/zephyr/devicetree/map.h new file mode 100644 index 0000000000000..3afca063412bb --- /dev/null +++ b/include/zephyr/devicetree/map.h @@ -0,0 +1,331 @@ +/* + * Copyright (c) 2025 TOKITA Hiroshi + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DEVICETREE_MAP_H_ +#define ZEPHYR_INCLUDE_DEVICETREE_MAP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup devicetree-map Devicetree Map API + * + * @brief Helper macros for handling map properties. + * + * This module provides helper macros that facilitate interrupt mapping and + * specifier mapping based on DeviceTree specifications. It enables the extraction + * and interpretation of mapping data represented as phandle-arrays. + * + * In a typical DeviceTree fragment, properties ending with "-map" specify: + * - The child specifier to be mapped. + * - The parent node (phandle) to which the mapping applies. + * - The parent specifier associated with the mapping. + * + * For example, when the following DeviceTree snippet is defined: + * + * @code{.dts} + * n: node { + * gpio-map = <0 1 &gpio0 2 3>, <4 5 &gpio0 6 7>; + * }; + * @endcode + * + * In the first mapping entry: + * - `0 1` are the child specifiers. + * - &gpio0 is the parent node. + * - `2 3` are the parent specifiers. + * + * Since map properties are implemented as phandle-arrays, macros such as + * DT_PHANDLE_BY_IDX() and DT_PHA_BY_IDX() can be used to access individual elements. + * + * Both child and parent specifiers are treated as cells in a phandle-array. + * By default, each group of specifiers is given a sequential cell name + * (child_specifier_0, child_specifier_1, ..., parent_specifier_0, ...). + * + * If cell names are specified in dt-bindings, they will be used for the child specifier cell names. + * Parent specifiers always use the default naming convention. + * + * Example usage: + * + * A mapping entry is a phandle-array whose elements can be referenced as follows: + * - Child specifiers can be accessed via names such as `child_specifier_0`, + * `child_specifier_1`, ... + * - The parent node is accessed via DT_PHANDLE_BY_IDX(). + * - Parent specifiers are accessed via names such as `parent_specifier_0`, + * `parent_specifier_1`, ... + * + * @code{.c} + * int cspec_0 = DT_PHA_BY_IDX(DT_NODELABEL(n), gpio_map, 0, child_specifier_0); // 0 + * int cspec_1 = DT_PHA_BY_IDX(DT_NODELABEL(n), gpio_map, 0, child_specifier_1); // 1 + * const struct device *parent = + * device_get_binding(DT_PHANDLE_BY_IDX(DT_NODELABEL(n), gpio_map, 0)); // &gpio0 + * int pspec_0 = DT_PHA_BY_IDX(DT_NODELABEL(n), gpio_map, 0, parent_specifier_0); // 2 + * int pspec_1 = DT_PHA_BY_IDX(DT_NODELABEL(n), gpio_map, 0, parent_specifier_1); // 3 + * @endcode + * + * The map helper API also provides the following macros for convenient access to + * specific parts of a mapping entry: + * - DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX() + * - DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX() + * - DT_MAP_PARENT_ARG_BY_IDX() + * + * These macros extract, respectively, the child specifier arguments, the parent specifier + * arguments, and the parent node argument from a mapping element identified by its node ID, + * property name, and index. + * + * For instance: + * + * @code{.c} + * #define SRC_AND_DST(node_id, prop, idx) \ + * { GET_ARG_N(1, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(node_id, prop, idx)), \ + * GET_ARG_N(1, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(node_id, prop, idx)) } + * + * int src_and_dst[2][] = { + * DT_FOREACH_PROP_ELEM_SEP(DT_NODELABEL(n), gpio_map, SRC_AND_DST, (,)) + * }; + * @endcode + * + * The above expansion yields: + * + * @code{.c} + * int src_and_dst[2][] = {{0, 2}, {4, 6}}; + * @endcode + * + * @ingroup devicetree + * @{ + */ + +/** + * @brief Extracts a specified range of arguments. + * + * This helper macro first skips a given number of arguments and then selects + * the first @p len arguments from the remaining list. + * + * @param start The number of arguments to skip. + * @param len The number of arguments to extract after skipping. + * @param ... The list of input arguments. + */ +#define DT_MAP_HELPER_DO_ARGS_RANGE(start, len, ...) \ + GET_ARGS_FIRST_N(len, GET_ARGS_LESS_N(start, __VA_ARGS__)) + +/** + * @brief Extracts a range of mapping arguments for a specific field. + * + * This macro concatenates the field name with the appropriate suffixes to determine + * the starting index and length of the arguments for a map entry, and then extracts + * those arguments. + * + * @param name The mapping field name (e.g., CHILD_SPECIFIER, PARENT). + * @param node_id The node identifier. + * @param prop The property name in lowercase and underscores. + * @param idx The index of the mapping entry. + * @param ... Additional arguments corresponding to the mapping entry. + */ +#define DT_MAP_HELPER_ARGS_RANGE(name, node_id, prop, idx, ...) \ + DT_MAP_HELPER_DO_ARGS_RANGE(DT_CAT3(DT_MAP_, name, _POS_BY_IDX)(node_id, prop, idx), \ + DT_CAT3(DT_MAP_, name, _LEN_BY_IDX)(node_id, prop, idx), \ + __VA_ARGS__) + +/** + * @brief Retrieves the mapping entry at the specified index. + * + * @param node_id The node identifier. + * @param prop The property name in lowercase with underscores. + * @param idx The mapping entry index. + * @return The mapping entry as a list of comma-separated values. + */ +#define DT_MAP_BY_IDX(node_id, prop, idx) DT_CAT5(node_id, _P_, prop, _MAP_IDX_, idx) + +/** + * @brief Retrieves the first mapping entry. + * @see DT_MAP_BY_IDX + */ +#define DT_MAP(node_id, prop) DT_MAP_BY_IDX(node_id, prop, 0) + +/** + * @brief Returns the number of mapping entries for the given property. + * + * @param node_id The node identifier. + * @param prop The property name in lowercase with underscores. + * @return The total count of mapping entries. + */ +#define DT_MAP_LEN(node_id, prop) DT_CAT4(node_id, _P_, prop, _MAP_LEN) + +/** + * @brief Retrieves the starting index of the child specifier cell within a mapping entry. + * + * @param node_id The node identifier. + * @param prop The property name. + * @param idx The mapping entry index. + * @return The starting index of the child specifier cell. + */ +#define DT_MAP_CHILD_SPECIFIER_POS_BY_IDX(node_id, prop, idx) \ + DT_CAT7(node_id, _P_, prop, _MAP_IDX_, idx, _, CHILD_SPECIFIER_POS) + +/** + * @brief Retrieves the starting index of the child specifier cell within the first mapping entry. + * @see DT_MAP_CHILD_SPECIFIER_POS_BY_IDX + */ +#define DT_MAP_CHILD_SPECIFIER_POS(node_id, prop) \ + DT_MAP_CHILD_SPECIFIER_POS_BY_IDX(node_id, prop, 0) + +/** + * @brief Returns the length (number of cells) of the child specifier within a mapping entry. + * + * @param node_id The node identifier. + * @param prop The property name. + * @param idx The mapping entry index. + * @return The length (in cells) of the child specifier. + */ +#define DT_MAP_CHILD_SPECIFIER_LEN_BY_IDX(node_id, prop, idx) \ + DT_CAT7(node_id, _P_, prop, _MAP_IDX_, idx, _, CHILD_SPECIFIER_LEN) + +/** + * @brief Returns the length (number of cells) of the child specifier within the first mapping + * entry. + * @see DT_MAP_CHILD_SPECIFIER_LEN_BY_IDX + */ +#define DT_MAP_CHILD_SPECIFIER_LEN(node_id, prop) \ + DT_MAP_CHILD_SPECIFIER_LEN_BY_IDX(node_id, prop, 0) + +/** + * @brief Retrieves the starting index of the parent cell in a mapping entry. + * + * @param node_id The node identifier. + * @param prop The property name. + * @param idx The mapping entry index. + * @return The starting index of the parent cell. + */ +#define DT_MAP_PARENT_POS_BY_IDX(node_id, prop, idx) \ + DT_CAT7(node_id, _P_, prop, _MAP_IDX_, idx, _, PARENT_POS) + +/** + * @brief Retrieves the starting index of the parent cell in the first mapping entry. + * @see DT_MAP_PARENT_POS_BY_IDX + */ +#define DT_MAP_PARENT_POS(node_id, prop) DT_MAP_PARENT_POS_BY_IDX(node_id, prop, 0) + +/** + * @brief Returns the length (number of cells) of the parent cell in a mapping entry. + * + * @param node_id The node identifier. + * @param prop The property name. + * @param idx The mapping entry index. + * @return The length (in cells) of the parent cell. + */ +#define DT_MAP_PARENT_LEN_BY_IDX(node_id, prop, idx) \ + DT_CAT7(node_id, _P_, prop, _MAP_IDX_, idx, _, PARENT_LEN) + +/** + * @brief Returns the length (number of cells) of the parent cell in the first mapping entry. + * @see DT_MAP_PARENT_LEN_BY_IDX + */ +#define DT_MAP_PARENT_LEN(node_id, prop) DT_MAP_PARENT_LEN_BY_IDX(node_id, prop, 0) + +/** + * @brief Retrieves the starting index of the parent specifier cell within a mapping entry. + * + * @param node_id The node identifier. + * @param prop The property name. + * @param idx The mapping entry index. + * @return The starting index of the parent specifier cell. + */ +#define DT_MAP_PARENT_SPECIFIER_POS_BY_IDX(node_id, prop, idx) \ + DT_CAT7(node_id, _P_, prop, _MAP_IDX_, idx, _, PARENT_SPECIFIER_POS) + +/** + * @brief Retrieves the starting index of the parent specifier cell within the first mapping entry. + * @see DT_MAP_PARENT_SPECIFIER_POS_BY_IDX + */ +#define DT_MAP_PARENT_SPECIFIER_POS(node_id, prop) \ + DT_MAP_PARENT_SPECIFIER_POS_BY_IDX(node_id, prop, 0) + +/** + * @brief Returns the length (number of cells) of the parent specifier in a mapping entry. + * + * @param node_id The node identifier. + * @param prop The property name. + * @param idx The mapping entry index. + * @return The length (in cells) of the parent specifier. + */ +#define DT_MAP_PARENT_SPECIFIER_LEN_BY_IDX(node_id, prop, idx) \ + DT_CAT7(node_id, _P_, prop, _MAP_IDX_, idx, _, PARENT_SPECIFIER_LEN) + +/** + * @brief Returns the length (number of cells) of the parent specifier of the first mapping entry. + * @see DT_MAP_PARENT_SPECIFIER_LEN_BY_IDX + */ +#define DT_MAP_PARENT_SPECIFIER_LEN(node_id, prop) \ + DT_MAP_PARENT_SPECIFIER_LEN_BY_IDX(node_id, prop, 0) + +/** + * @brief Extracts the child specifier arguments from a mapping entry. + * + * This macro returns the comma-separated list of arguments for the child specifier. + * + * @param node_id The node identifier. + * @param prop The property name in lowercase with underscores. + * @param idx The mapping entry index. + * @return The child specifier arguments. + */ +#define DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(node_id, prop, idx) \ + DT_MAP_HELPER_ARGS_RANGE(CHILD_SPECIFIER, node_id, prop, idx, \ + DT_MAP_BY_IDX(node_id, prop, idx)) + +/** + * @brief Extracts the child specifier arguments from the first mapping entry. + * @see DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX + */ +#define DT_MAP_CHILD_SPECIFIER_ARGS(node_id, prop) \ + DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(node_id, prop, 0) + +/** + * @brief Extracts the parent node argument from a mapping entry. + * + * @param node_id The node identifier. + * @param prop The property name in lowercase with underscores. + * @param idx The mapping entry index. + * @return The parent node argument. + */ +#define DT_MAP_PARENT_ARG_BY_IDX(node_id, prop, idx) \ + DT_MAP_HELPER_ARGS_RANGE(PARENT, node_id, prop, idx, DT_MAP_BY_IDX(node_id, prop, idx)) + +/** + * @brief Extracts the parent node argument from the first mapping entry. + * @see DT_MAP_PARENT_ARG_BY_IDX + */ +#define DT_MAP_PARENT_ARG(node_id, prop) DT_MAP_PARENT_ARG_BY_IDX(node_id, prop, 0) + +/** + * @brief Extracts the parent specifier arguments from a mapping entry. + * + * This macro returns the comma-separated list of arguments for the parent specifier. + * + * @param node_id The node identifier. + * @param prop The property name in lowercase with underscores. + * @param idx The mapping entry index. + * @return The parent specifier arguments. + */ +#define DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(node_id, prop, idx) \ + DT_MAP_HELPER_ARGS_RANGE(PARENT_SPECIFIER, node_id, prop, idx, \ + DT_MAP_BY_IDX(node_id, prop, idx)) + +/** + * @brief Extracts the parent specifier arguments of the first mapping entry. + * @see DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX + */ +#define DT_MAP_PARENT_SPECIFIER_ARGS(node_id, prop) \ + DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(node_id, prop, 0) + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_DEVICETREE_MAP_H_ */ diff --git a/include/zephyr/sys/util_loops.h b/include/zephyr/sys/util_loops.h index 8c71edd16f363..afe2c004a6087 100644 --- a/include/zephyr/sys/util_loops.h +++ b/include/zephyr/sys/util_loops.h @@ -1051,6 +1051,388 @@ _47, _48, _49, _50, _51, _52, _53, _54, _55, \ _56, _57, _58, _59, _60, _61, _62, _63, ...) __VA_ARGS__ +#define Z_GET_ARGS_FIRST_0(...) + +#define Z_GET_ARGS_FIRST_1(_0, ...) _0 + +#define Z_GET_ARGS_FIRST_2(_0, _1, ...) _0, _1 + +#define Z_GET_ARGS_FIRST_3(_0, _1, _2, ...) _0, _1, _2 + +#define Z_GET_ARGS_FIRST_4(_0, _1, _2, _3, ...) _0, _1, _2, _3 + +#define Z_GET_ARGS_FIRST_5(_0, _1, _2, _3, _4, ...) _0, _1, _2, _3, _4 + +#define Z_GET_ARGS_FIRST_6(_0, _1, _2, _3, _4, _5, ...) _0, _1, _2, _3, _4, _5 + +#define Z_GET_ARGS_FIRST_7(_0, _1, _2, _3, _4, _5, _6, ...) _0, _1, _2, _3, _4, _5, _6 + +#define Z_GET_ARGS_FIRST_8(_0, _1, _2, _3, _4, _5, _6, _7, ...) _0, _1, _2, _3, _4, _5, _6, _7 + +#define Z_GET_ARGS_FIRST_9(_0, _1, _2, _3, _4, _5, _6, _7, _8, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8 + +#define Z_GET_ARGS_FIRST_10(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9 + +#define Z_GET_ARGS_FIRST_11(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10 + +#define Z_GET_ARGS_FIRST_12(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11 + +#define Z_GET_ARGS_FIRST_13(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12 + +#define Z_GET_ARGS_FIRST_14(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13 + +#define Z_GET_ARGS_FIRST_15(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14 + +#define Z_GET_ARGS_FIRST_16(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15 + +#define Z_GET_ARGS_FIRST_17(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16 + +#define Z_GET_ARGS_FIRST_18(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17 + +#define Z_GET_ARGS_FIRST_19(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18 + +#define Z_GET_ARGS_FIRST_20(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19 + +#define Z_GET_ARGS_FIRST_21(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20 + +#define Z_GET_ARGS_FIRST_22(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21 + +#define Z_GET_ARGS_FIRST_23(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22 + +#define Z_GET_ARGS_FIRST_24(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23 + +#define Z_GET_ARGS_FIRST_25(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24 + +#define Z_GET_ARGS_FIRST_26(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25 + +#define Z_GET_ARGS_FIRST_27(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26 + +#define Z_GET_ARGS_FIRST_28(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27 + +#define Z_GET_ARGS_FIRST_29(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28 + +#define Z_GET_ARGS_FIRST_30(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29 + +#define Z_GET_ARGS_FIRST_31(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30 + +#define Z_GET_ARGS_FIRST_32(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31 + +#define Z_GET_ARGS_FIRST_33(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32 + +#define Z_GET_ARGS_FIRST_34(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33 + +#define Z_GET_ARGS_FIRST_35(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34 + +#define Z_GET_ARGS_FIRST_36(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35 + +#define Z_GET_ARGS_FIRST_37(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36 + +#define Z_GET_ARGS_FIRST_38(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37 + +#define Z_GET_ARGS_FIRST_39(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38 + +#define Z_GET_ARGS_FIRST_40(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39 + +#define Z_GET_ARGS_FIRST_41(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40 + +#define Z_GET_ARGS_FIRST_42(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41 + +#define Z_GET_ARGS_FIRST_43(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42 + +#define Z_GET_ARGS_FIRST_44(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43 + +#define Z_GET_ARGS_FIRST_45(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44 + +#define Z_GET_ARGS_FIRST_46(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45 + +#define Z_GET_ARGS_FIRST_47(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46 + +#define Z_GET_ARGS_FIRST_48(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47 + +#define Z_GET_ARGS_FIRST_49(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48 + +#define Z_GET_ARGS_FIRST_50(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49 + +#define Z_GET_ARGS_FIRST_51(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50 + +#define Z_GET_ARGS_FIRST_52(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51 + +#define Z_GET_ARGS_FIRST_53(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52 + +#define Z_GET_ARGS_FIRST_54(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52, _53 + +#define Z_GET_ARGS_FIRST_55(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52, _53, _54 + +#define Z_GET_ARGS_FIRST_56(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52, _53, _54, _55 + +#define Z_GET_ARGS_FIRST_57(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52, _53, _54, _55, _56 + +#define Z_GET_ARGS_FIRST_58(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, \ + ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52, _53, _54, _55, _56, _57 + +#define Z_GET_ARGS_FIRST_59(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, \ + _58, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52, _53, _54, _55, _56, _57, _58 + +#define Z_GET_ARGS_FIRST_60(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, \ + _58, _59, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52, _53, _54, _55, _56, _57, _58, _59 + +#define Z_GET_ARGS_FIRST_61(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, \ + _58, _59, _60, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52, _53, _54, _55, _56, _57, _58, _59, _60 + +#define Z_GET_ARGS_FIRST_62(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, \ + _58, _59, _60, _61, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52, _53, _54, _55, _56, _57, _58, _59, _60, _61 + +#define Z_GET_ARGS_FIRST_63(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, \ + _58, _59, _60, _61, _62, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62 + +#define Z_GET_ARGS_FIRST_64(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, \ + _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, \ + _58, _59, _60, _61, _62, _63, ...) \ + _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, \ + _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, \ + _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63 + #define Z_FOR_EACH_IDX_FIXED_ARG_EXEC(idx, x, fixed_arg0, fixed_arg1) \ fixed_arg0(idx, x, fixed_arg1) diff --git a/include/zephyr/sys/util_macro.h b/include/zephyr/sys/util_macro.h index c8901e21454ae..cba3a6140a76a 100644 --- a/include/zephyr/sys/util_macro.h +++ b/include/zephyr/sys/util_macro.h @@ -400,6 +400,16 @@ extern "C" { */ #define GET_ARGS_LESS_N(N, ...) Z_GET_ARGS_LESS_##N(__VA_ARGS__) +/** + * @brief Get the first N arguments from the argument list. + * + * @param N Number of arguments to take. + * @param ... Variable list of arguments. + * + * @return argument list only contains first N arguments. + */ +#define GET_ARGS_FIRST_N(N, ...) Z_GET_ARGS_FIRST_##N(__VA_ARGS__) + /** * @brief Like a || b, but does evaluation and * short-circuiting at C preprocessor time. diff --git a/samples/modules/arduino-core/analog_input/CMakeLists.txt b/samples/modules/arduino-core/analog_input/CMakeLists.txt new file mode 100644 index 0000000000000..312d485f5b23e --- /dev/null +++ b/samples/modules/arduino-core/analog_input/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(analog_input) + +target_sources(app PRIVATE src/main.cpp) +zephyr_compile_options(-Wno-unused-variable -Wno-comment) diff --git a/samples/modules/arduino-core/analog_input/README.rst b/samples/modules/arduino-core/analog_input/README.rst new file mode 100644 index 0000000000000..51349e4835269 --- /dev/null +++ b/samples/modules/arduino-core/analog_input/README.rst @@ -0,0 +1,24 @@ +.. _analog_input: + +Analog Input +############ + +Overview +******** + +The analog_input sample blinks the LED with control of the period +by the voltage of the input pin. +Inputting high voltage to blink the LED slowly. +Blink the LED fast on input voltage is low. +When the input is 0V, LED light. + +Building and Running +******************** + +Build and flash analog_input sample as follows, + +```sh +$> west build -p -b arduino_nano_33_ble sample/analog_input/ + +$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac +``` diff --git a/samples/modules/arduino-core/analog_input/prj.conf b/samples/modules/arduino-core/analog_input/prj.conf new file mode 100644 index 0000000000000..7db482019c0b2 --- /dev/null +++ b/samples/modules/arduino-core/analog_input/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ADC=y +CONFIG_ARDUINO_API=y diff --git a/samples/modules/arduino-core/analog_input/sample.yaml b/samples/modules/arduino-core/analog_input/sample.yaml new file mode 100644 index 0000000000000..c180454ab6402 --- /dev/null +++ b/samples/modules/arduino-core/analog_input/sample.yaml @@ -0,0 +1,22 @@ +sample: + name: Arduino Analog Input sample + +common: + tags: + - arduino-core + required_snippets: + - arduino-core + platform_allow: + - arduino_mkrzero/samd21g18a + - arduino_nano_33_ble/nrf52840 + - arduino_nano_33_ble/nrf52840/sense + - arduino_nano_33_iot/samd21g18a + - beagleconnect_freedom/cc1352p7 + - cc3220sf_launchxl/cc3220sf + - nrf52840dk/nrf52840 + - nrf9160dk/nrf9160 + - rpi_pico/rp2040 + +tests: + sample.arduino-core.analog_impot.build: + build_only: true diff --git a/samples/modules/arduino-core/analog_input/src/main.cpp b/samples/modules/arduino-core/analog_input/src/main.cpp new file mode 100644 index 0000000000000..9cc23dae6c59b --- /dev/null +++ b/samples/modules/arduino-core/analog_input/src/main.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 TOKITA Hiroshi + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +const int analog_input = A0; // select the input pin for the potentiometer +const int ledPin = LED_BUILTIN; // select the pin for the LED +const float wait_factor = 1.f; + +void setup() { + pinMode(ledPin, OUTPUT); +} + +void loop() { + int value = 0; + + value = analogRead(analog_input); + + /* Blinks slowly when the input voltage is high */ + + digitalWrite(ledPin, HIGH); + delay(value * wait_factor); + + digitalWrite(ledPin, LOW); + delay(value * wait_factor); +} diff --git a/samples/modules/arduino-core/attach_interrupt/CMakeLists.txt b/samples/modules/arduino-core/attach_interrupt/CMakeLists.txt new file mode 100644 index 0000000000000..63ad712c28159 --- /dev/null +++ b/samples/modules/arduino-core/attach_interrupt/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(attach_interrupt) + +target_sources(app PRIVATE src/main.cpp) + +zephyr_compile_options(-Wno-unused-variable -Wno-comment) diff --git a/samples/modules/arduino-core/attach_interrupt/README.rst b/samples/modules/arduino-core/attach_interrupt/README.rst new file mode 100644 index 0000000000000..f85d738a13f00 --- /dev/null +++ b/samples/modules/arduino-core/attach_interrupt/README.rst @@ -0,0 +1,22 @@ +.. _attach_interrupt-sample: + +AttachInterrupt +###### + +Overview +******** + +This sample demonstrates how to use attachInterrupt API. + +Building and Running +******************** + +Build and flash attachInterrupt sample as follows, + +```sh +$> west build -p -b arduino_nano_33_ble samples/basic/attach_interrupt/ -DZEPHYR_EXTRA_MODULES=/home/$USER/zephyrproject/modules/lib/Arduino-Core-Zephyr + +$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac +``` + +Turn on the LED by detecting interrupts. And Turn off the next interrupt. diff --git a/samples/modules/arduino-core/attach_interrupt/prj.conf b/samples/modules/arduino-core/attach_interrupt/prj.conf new file mode 100644 index 0000000000000..f93fa32189f54 --- /dev/null +++ b/samples/modules/arduino-core/attach_interrupt/prj.conf @@ -0,0 +1 @@ +CONFIG_ARDUINO_API=y diff --git a/samples/modules/arduino-core/attach_interrupt/sample.yaml b/samples/modules/arduino-core/attach_interrupt/sample.yaml new file mode 100644 index 0000000000000..7414947d4e5f9 --- /dev/null +++ b/samples/modules/arduino-core/attach_interrupt/sample.yaml @@ -0,0 +1,22 @@ +sample: + name: Attach Interrupt sample + +common: + tags: + - arduino-core + required_snippets: + - arduino-core + platform_allow: + - arduino_mkrzero/samd21g18a + - arduino_nano_33_ble/nrf52840 + - arduino_nano_33_ble/nrf52840/sense + - arduino_nano_33_iot/samd21g18a + - beagleconnect_freedom/cc1352p7 + - cc3220sf_launchxl/cc3220sf + - nrf52840dk/nrf52840 + - nrf9160dk/nrf9160 + - rpi_pico/rp2040 + +tests: + sample.arduino-core.attach_interrupt.build: + build_only: true diff --git a/samples/modules/arduino-core/attach_interrupt/src/main.cpp b/samples/modules/arduino-core/attach_interrupt/src/main.cpp new file mode 100644 index 0000000000000..3d803dbb68513 --- /dev/null +++ b/samples/modules/arduino-core/attach_interrupt/src/main.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 TOKITA Hiroshi + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +const pin_size_t ledPin = LED_BUILTIN; +const pin_size_t interruptPin = 2; +PinStatus state = LOW; + +void blink() { + state = (state == LOW) ? HIGH : LOW; + digitalWrite(ledPin, state); +} + +void setup() { + pinMode(ledPin, OUTPUT); + pinMode(interruptPin, INPUT_PULLUP); + attachInterrupt(interruptPin, blink, CHANGE); +} + +void loop() { +} diff --git a/samples/modules/arduino-core/blinky_arduino/CMakeLists.txt b/samples/modules/arduino-core/blinky_arduino/CMakeLists.txt new file mode 100644 index 0000000000000..90682ce03b7a6 --- /dev/null +++ b/samples/modules/arduino-core/blinky_arduino/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(blinky_arduino) + +target_sources(app PRIVATE src/main.cpp) diff --git a/samples/modules/arduino-core/blinky_arduino/README.rst b/samples/modules/arduino-core/blinky_arduino/README.rst new file mode 100644 index 0000000000000..339ad923961e1 --- /dev/null +++ b/samples/modules/arduino-core/blinky_arduino/README.rst @@ -0,0 +1,71 @@ +.. _blinky-sample: + +Blinky +###### + +Overview +******** + +This Arduino Blinky sample blinks an LED forever using the ``ArduinoAPI``. + +Requirements +************ + +Your board must: + +#. Have an LED connected via a GPIO pin (these are called "User LEDs" on many of + Zephyr's :ref:`boards`). +#. Have the LED configured using the ``led0`` devicetree alias. + +Building and Running +******************** + +Build and flash Blinky as follows, + +```sh +$> west build -p -b arduino_nano_33_ble samples/basic/arduino-blinky/ -DZEPHYR_EXTRA_MODULES=/home/$USER/zephyrproject/modules/lib/Arduino-Core-Zephyr + +$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac +``` + +After flashing, the LED starts to blink. If a runtime error occurs, the sample +exits without printing to the console. + +Adding board support +******************** + +To add support for your board, add something like this to your devicetree: + +.. code-block:: DTS + + / { + aliases { + led0 = &myled0; + }; + + leds { + compatible = "gpio-leds"; + myled0: led_0 { + gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; + }; + }; + }; + +The above sets your board's ``led0`` alias to use pin 13 on GPIO controller +``gpio0``. The pin flags :c:macro:`GPIO_ACTIVE_HIGH` mean the LED is on when +the pin is set to its high state, and off when the pin is in its low state. + +Tips: + +- See :dtcompatible:`gpio-leds` for more information on defining GPIO-based LEDs + in devicetree. + +- If you're not sure what to do, check the devicetrees for supported boards which + use the same SoC as your target. See :ref:`get-devicetree-outputs` for details. + +- See :zephyr_file:`include/zephyr/dt-bindings/gpio/gpio.h` for the flags you can use + in devicetree. + +- If the LED is built in to your board hardware, the alias should be defined in + your :ref:`BOARD.dts file `. Otherwise, you can + define one in a :ref:`devicetree overlay `. diff --git a/samples/modules/arduino-core/blinky_arduino/prj.conf b/samples/modules/arduino-core/blinky_arduino/prj.conf new file mode 100644 index 0000000000000..290d61a3c51ef --- /dev/null +++ b/samples/modules/arduino-core/blinky_arduino/prj.conf @@ -0,0 +1,2 @@ +CONFIG_GPIO=y +CONFIG_ARDUINO_API=y diff --git a/samples/modules/arduino-core/blinky_arduino/sample.yaml b/samples/modules/arduino-core/blinky_arduino/sample.yaml new file mode 100644 index 0000000000000..c8a41fc88ac8e --- /dev/null +++ b/samples/modules/arduino-core/blinky_arduino/sample.yaml @@ -0,0 +1,22 @@ +sample: + name: Arduino blinky sample + +common: + tags: + - arduino-core + required_snippets: + - arduino-core + platform_allow: + - arduino_mkrzero/samd21g18a + - arduino_nano_33_ble/nrf52840 + - arduino_nano_33_ble/nrf52840/sense + - arduino_nano_33_iot/samd21g18a + - beagleconnect_freedom/cc1352p7 + - cc3220sf_launchxl/cc3220sf + - nrf52840dk/nrf52840 + - nrf9160dk/nrf9160 + - rpi_pico/rp2040 + +tests: + sample.arduino-core.blinky_arduino.build: + build_only: true diff --git a/samples/modules/arduino-core/blinky_arduino/src/main.cpp b/samples/modules/arduino-core/blinky_arduino/src/main.cpp new file mode 100644 index 0000000000000..ef68d31329f93 --- /dev/null +++ b/samples/modules/arduino-core/blinky_arduino/src/main.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 John Doe + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* Blink inbuilt LED example */ + +#include + +/* 1000 msec = 1 sec */ +#define SLEEP_TIME_MS 1000 + +void setup() { pinMode(LED_BUILTIN, OUTPUT); } + +void loop() { + digitalWrite(LED_BUILTIN, HIGH); + delay(SLEEP_TIME_MS); + digitalWrite(LED_BUILTIN, LOW); + delay(SLEEP_TIME_MS); +} diff --git a/samples/modules/arduino-core/button_press_led/CMakeLists.txt b/samples/modules/arduino-core/button_press_led/CMakeLists.txt new file mode 100644 index 0000000000000..9e90b7600e28a --- /dev/null +++ b/samples/modules/arduino-core/button_press_led/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(button_press_led) + +target_sources(app PRIVATE src/main.cpp) + +zephyr_compile_options(-Wno-unused-variable -Wno-comment) diff --git a/samples/modules/arduino-core/button_press_led/README.rst b/samples/modules/arduino-core/button_press_led/README.rst new file mode 100644 index 0000000000000..4d70f104e890a --- /dev/null +++ b/samples/modules/arduino-core/button_press_led/README.rst @@ -0,0 +1,67 @@ +Button press LED +###### + +Overview +******** + +This Arduino sample turns ON an LED if button pressed using the ``ArduinoAPI``. + +Requirements +************ + +Your board must: + +#. Have an LED connected via a GPIO pin (these are called "User LEDs" on many of + Zephyr's :ref:`boards`). +#. Have the LED configured using the ``led0`` devicetree alias. +#. Have a button connected to pin ``D9`` of the arduino externally (pulled down by default) + +Building and Running +******************** + +Build and flash as follows, + +```sh +$> west build -p -b arduino_nano_33_ble samples/button_press_led -DZEPHYR_EXTRA_MODULES=/home/$USER/zephyrproject/modules/lib/Arduino-Core-Zephyr + +$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac +``` + +Adding board support +******************** + +To add support for your board, add something like this to your devicetree: + +.. code-block:: DTS + + / { + aliases { + led0 = &myled0; + }; + + leds { + compatible = "gpio-leds"; + myled0: led_0 { + gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; + }; + }; + }; + +The above sets your board's ``led0`` alias to use pin 13 on GPIO controller +``gpio0``. The pin flags :c:macro:`GPIO_ACTIVE_HIGH` mean the LED is on when +the pin is set to its high state, and off when the pin is in its low state. + +Tips: + +- See :dtcompatible:`gpio-leds` for more information on defining GPIO-based LEDs + in devicetree. + +- If you're not sure what to do, check the devicetrees for supported boards which + use the same SoC as your target. See :ref:`get-devicetree-outputs` for details. + +- See :zephyr_file:`include/zephyr/dt-bindings/gpio/gpio.h` for the flags you can use + in devicetree. + +- If the LED is built in to your board hardware, the alias should be defined in + your :ref:`BOARD.dts file `. Otherwise, you can + define one in a :ref:`devicetree overlay `. diff --git a/samples/modules/arduino-core/button_press_led/prj.conf b/samples/modules/arduino-core/button_press_led/prj.conf new file mode 100644 index 0000000000000..290d61a3c51ef --- /dev/null +++ b/samples/modules/arduino-core/button_press_led/prj.conf @@ -0,0 +1,2 @@ +CONFIG_GPIO=y +CONFIG_ARDUINO_API=y diff --git a/samples/modules/arduino-core/button_press_led/sample.yaml b/samples/modules/arduino-core/button_press_led/sample.yaml new file mode 100644 index 0000000000000..bf77062f1632d --- /dev/null +++ b/samples/modules/arduino-core/button_press_led/sample.yaml @@ -0,0 +1,22 @@ +sample: + name: Button press LED sample + +common: + tags: + - arduino-core + required_snippets: + - arduino-core + platform_allow: + - arduino_mkrzero/samd21g18a + - arduino_nano_33_ble/nrf52840 + - arduino_nano_33_ble/nrf52840/sense + - arduino_nano_33_iot/samd21g18a + - beagleconnect_freedom/cc1352p7 + - cc3220sf_launchxl/cc3220sf + - nrf52840dk/nrf52840 + - nrf9160dk/nrf9160 + - rpi_pico/rp2040 + +tests: + sample.arduino-core.button_press_led.build: + build_only: true diff --git a/samples/modules/arduino-core/button_press_led/src/main.cpp b/samples/modules/arduino-core/button_press_led/src/main.cpp new file mode 100644 index 0000000000000..8aeb23db5e6ed --- /dev/null +++ b/samples/modules/arduino-core/button_press_led/src/main.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 John Doe + * SPDX-License-Identifier: Apache-2.0 + */ + +/* Button Press turns on inbuilt LED example */ + +#include + +const int buttonPin = D9; // the number of the pushbutton pin +const int ledPin = 13; // the number of the LED pin + +// variables will change: +int buttonState = 0; // variable for reading the pushbutton status + +void setup() { + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); + // initialize the pushbutton pin as an input: + pinMode(buttonPin, INPUT); +} + +void loop() { + // read the state of the pushbutton value: + buttonState = digitalRead(buttonPin); + + // check if the pushbutton is pressed. If it is, the buttonState is HIGH: + if (buttonState == HIGH) { + // turn LED on: + digitalWrite(ledPin, HIGH); + } else { + // turn LED off: + digitalWrite(ledPin, LOW); + } +} diff --git a/samples/modules/arduino-core/fade/CMakeLists.txt b/samples/modules/arduino-core/fade/CMakeLists.txt new file mode 100644 index 0000000000000..c76c4cdbb5404 --- /dev/null +++ b/samples/modules/arduino-core/fade/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(fade) + +target_sources(app PRIVATE src/app.cpp) + +zephyr_compile_options(-Wno-unused-variable -Wno-comment) diff --git a/samples/modules/arduino-core/fade/README.rst b/samples/modules/arduino-core/fade/README.rst new file mode 100644 index 0000000000000..8de33953495f4 --- /dev/null +++ b/samples/modules/arduino-core/fade/README.rst @@ -0,0 +1,21 @@ +.. _fade: + +Fade +#### + +Overview +******** + +The Fade sample gradually increases/decreases the voltage of the output pin. +When connecting the LED to the output pin, the LED blinks gradually. + +Building and Running +******************** + +Build and flash Fade sample as follows, + +```sh +$> west build -p -b arduino_nano_33_ble samples/basic/fade/ -DZEPHYR_EXTRA_MODULES=/home/$USER/zephyrproject/modules/lib/Arduino-Core-Zephyr + +$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac +``` diff --git a/samples/modules/arduino-core/fade/prj.conf b/samples/modules/arduino-core/fade/prj.conf new file mode 100644 index 0000000000000..cd969855c83e2 --- /dev/null +++ b/samples/modules/arduino-core/fade/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ARDUINO_API=y +CONFIG_PWM=y diff --git a/samples/modules/arduino-core/fade/sample.yaml b/samples/modules/arduino-core/fade/sample.yaml new file mode 100644 index 0000000000000..10317bb55d007 --- /dev/null +++ b/samples/modules/arduino-core/fade/sample.yaml @@ -0,0 +1,22 @@ +sample: + name: fade sample + +common: + tags: + - arduino-core + required_snippets: + - arduino-core + platform_allow: + - arduino_mkrzero/samd21g18a + - arduino_nano_33_ble/nrf52840 + - arduino_nano_33_ble/nrf52840/sense + - arduino_nano_33_iot/samd21g18a + - beagleconnect_freedom/cc1352p7 + - cc3220sf_launchxl/cc3220sf + - nrf52840dk/nrf52840 + - nrf9160dk/nrf9160 + - rpi_pico/rp2040 + +tests: + sample.arduino-core.fade.build: + build_only: true diff --git a/samples/modules/arduino-core/fade/src/app.cpp b/samples/modules/arduino-core/fade/src/app.cpp new file mode 100644 index 0000000000000..e812dcd0ab571 --- /dev/null +++ b/samples/modules/arduino-core/fade/src/app.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 TOKITA Hiroshi + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +const int led = 3; // PWM output pin. +const int increments = 5; +const int wait_ms = 10; + +void setup() { + /* Pin that use as the PWM output need not be configured by pinMode() */ +} + +void loop() { + int value = 0; + while (value < 256) { + analogWrite(led, value); + value += increments; + delay(wait_ms); + } + + value = 255; + while (value >= 0) { + analogWrite(led, value); + value -= increments; + delay(wait_ms); + } +} diff --git a/samples/modules/arduino-core/hello_arduino/CMakeLists.txt b/samples/modules/arduino-core/hello_arduino/CMakeLists.txt new file mode 100644 index 0000000000000..d38ccc30de75a --- /dev/null +++ b/samples/modules/arduino-core/hello_arduino/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(hello_world) + +target_sources(app PRIVATE src/app.cpp) + +zephyr_compile_options(-Wno-unused-variable -Wno-comment) diff --git a/samples/modules/arduino-core/hello_arduino/README.rst b/samples/modules/arduino-core/hello_arduino/README.rst new file mode 100644 index 0000000000000..ce5423d6f0448 --- /dev/null +++ b/samples/modules/arduino-core/hello_arduino/README.rst @@ -0,0 +1,33 @@ +.. _hello_world: + +Hello World +########### + +Overview +******** + +A simple sample that can be used with any :ref:`supported board ` and +prints "Hello World" to the console. + +Building and Running +******************** + +This application can be built and executed on QEMU as follows: + +.. zephyr-app-commands:: + :zephyr-app: samples/hello_world + :host-os: unix + :board: qemu_x86 + :goals: run + :compact: + +To build for another board, change "qemu_x86" above to that board's name. + +Sample Output +============= + +.. code-block:: console + + Hello World! x86 + +Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`. diff --git a/samples/modules/arduino-core/hello_arduino/prj.conf b/samples/modules/arduino-core/hello_arduino/prj.conf new file mode 100644 index 0000000000000..f93fa32189f54 --- /dev/null +++ b/samples/modules/arduino-core/hello_arduino/prj.conf @@ -0,0 +1 @@ +CONFIG_ARDUINO_API=y diff --git a/samples/modules/arduino-core/hello_arduino/sample.yaml b/samples/modules/arduino-core/hello_arduino/sample.yaml new file mode 100644 index 0000000000000..d13883ce74e84 --- /dev/null +++ b/samples/modules/arduino-core/hello_arduino/sample.yaml @@ -0,0 +1,22 @@ +sample: + name: Hello Arduino sample + +common: + tags: + - arduino-core + required_snippets: + - arduino-core + platform_allow: + - arduino_mkrzero/samd21g18a + - arduino_nano_33_ble/nrf52840 + - arduino_nano_33_ble/nrf52840/sense + - arduino_nano_33_iot/samd21g18a + - beagleconnect_freedom/cc1352p7 + - cc3220sf_launchxl/cc3220sf + - nrf52840dk/nrf52840 + - nrf9160dk/nrf9160 + - rpi_pico/rp2040 + +tests: + sample.arduino-core.hello_arduino.build: + build_only: true diff --git a/samples/modules/arduino-core/hello_arduino/src/app.cpp b/samples/modules/arduino-core/hello_arduino/src/app.cpp new file mode 100644 index 0000000000000..f4f7b1fdc68c6 --- /dev/null +++ b/samples/modules/arduino-core/hello_arduino/src/app.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 John Doe + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "zephyrSerial.h" + + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); // dummy as of now, need to study and refer https://docs.zephyrproject.org/latest/hardware/peripherals/uart.html +} +void loop() { + char c = 'D'; + size_t ret1; + size_t ret2; + ret1 = Serial.print(c); + ret2 = Serial.println("Hello, World!"); + printk("Sizes: %d %d\n", ret1, ret2); + Serial.println(); + ret1 = Serial.print("My letter is: "); + ret2 = Serial.println(c); + printk("Sizes: %d %d\n", ret1, ret2); + Serial.println(); + char myString[] = "Will it print?"; + ret1 = Serial.println(myString); + printk("Size: %d \n\n\n", ret1); + delay(1000); // 1 second delay +} diff --git a/samples/modules/arduino-core/i2cdemo/CMakeLists.txt b/samples/modules/arduino-core/i2cdemo/CMakeLists.txt new file mode 100644 index 0000000000000..9ebd0885515cf --- /dev/null +++ b/samples/modules/arduino-core/i2cdemo/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(i2cdemo) + +target_sources(app PRIVATE src/main.cpp) + +zephyr_compile_options(-Wno-unused-variable -Wno-comment) diff --git a/samples/modules/arduino-core/i2cdemo/README.rst b/samples/modules/arduino-core/i2cdemo/README.rst new file mode 100644 index 0000000000000..f74e543cb5fc7 --- /dev/null +++ b/samples/modules/arduino-core/i2cdemo/README.rst @@ -0,0 +1,28 @@ +i2c demo +###### + +Overview +******** + +This Arduino i2c sample gets data from an ADXL345 sensor connected over ``i2c0``. + +Requirements +************ + +Your board must: + +#. Have at least 1 i2c port. +#. Have the ADXL345 sensor connected to the I2C port. + +Building and Running +******************** + +Build and flash Blinky as follows, + +```sh +$> west build -p -b arduino_nano_33_ble samples/i2cdemo + +$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac +``` + +After flashing, probe the UART pin (TX) and you should be able to see X, Y and Z values if everything goes well. diff --git a/samples/modules/arduino-core/i2cdemo/prj.conf b/samples/modules/arduino-core/i2cdemo/prj.conf new file mode 100644 index 0000000000000..d546d03658d70 --- /dev/null +++ b/samples/modules/arduino-core/i2cdemo/prj.conf @@ -0,0 +1,6 @@ +CONFIG_GPIO=y +CONFIG_ARDUINO_API=y +CONFIG_I2C=y +CONFIG_NEWLIB_LIBC=y +CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y +CONFIG_RING_BUFFER=y diff --git a/samples/modules/arduino-core/i2cdemo/sample.yaml b/samples/modules/arduino-core/i2cdemo/sample.yaml new file mode 100644 index 0000000000000..2a1f0169f25b9 --- /dev/null +++ b/samples/modules/arduino-core/i2cdemo/sample.yaml @@ -0,0 +1,22 @@ +sample: + name: I2C demo sample + +common: + tags: + - arduino-core + required_snippets: + - arduino-core + platform_allow: + - arduino_mkrzero/samd21g18a + - arduino_nano_33_ble/nrf52840 + - arduino_nano_33_ble/nrf52840/sense + - arduino_nano_33_iot/samd21g18a + - beagleconnect_freedom/cc1352p7 + - cc3220sf_launchxl/cc3220sf + - nrf52840dk/nrf52840 + - nrf9160dk/nrf9160 + - rpi_pico/rp2040 + +tests: + sample.arduino-core.i2cdemo.build: + build_only: true diff --git a/samples/modules/arduino-core/i2cdemo/src/main.cpp b/samples/modules/arduino-core/i2cdemo/src/main.cpp new file mode 100644 index 0000000000000..477eec777471c --- /dev/null +++ b/samples/modules/arduino-core/i2cdemo/src/main.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2025 John Doe + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "Wire.h" + +void setup() +{ + printf("\n\nSetup begins\n"); + Wire.begin(); + // initialize the LED pin as an output: + + // initialize the pushbutton pin as an input: + // pinMode(buttonPin, INPUT); + // pinMode(ledPin, OUTPUT); + Wire.beginTransmission(0x53); + Wire.write(0x2C); + Wire.write(0x08); + Wire.endTransmission(); + + Wire.beginTransmission(0x53); + Wire.write(0x31); + Wire.write(0x08); + Wire.endTransmission(); + + Wire.beginTransmission(0x53); + Wire.write(0x2D); + Wire.write(0x08); + Wire.endTransmission(); + printf("\n\nSetup COMPLETE\n\n\n"); +} + +void loop() +{ + Wire.beginTransmission(0x53); +Wire.write(0x32); +Wire.endTransmission(); +// printf("\n\nrequesting from 53\n\n\n"); +Wire.requestFrom(0x53, 1); +byte x0 = Wire.read(); + +Wire.beginTransmission(0x53); +Wire.write(0x33); +Wire.endTransmission(); +Wire.requestFrom(0x53, 1); +byte x1 = Wire.read(); +x1 = x1 & 0x03; + +uint16_t x = (x1 << 8) + x0; +int16_t xf = x; +if(xf > 511) +{ +xf = xf - 1024; +} +float xa = xf * 0.004; +printf("\n\nX = %f\n",static_cast(xa)); +// Serial.print("X = "); +// Serial.print(xa); +// Serial.print(" g"); +// Serial.println(); + + +Wire.beginTransmission(0x53); +Wire.write(0x34); +Wire.endTransmission(); +Wire.requestFrom(0x53, 1); +byte y0 = Wire.read(); + +Wire.beginTransmission(0x53); +Wire.write(0x35); +Wire.endTransmission(); +Wire.requestFrom(0x53, 1); +byte y1 = Wire.read(); +y1 = y1 & 0x03; + +uint16_t y = (y1 << 8) + y0; +int16_t yf = y; +if(yf > 511) +{ +yf = yf - 1024; +} +float ya = yf * 0.004; +// printk("Y = %f\n",ya); +printf("Y = %f\n",static_cast(ya)); +// printf("\n\nYa = %f\n\n\n",ya); +// Serial.print("Y = "); +// Serial.print(ya); +// Serial.print(" g"); +// Serial.println(); + +Wire.beginTransmission(0x53); +Wire.write(0x36); +Wire.endTransmission(); +Wire.requestFrom(0x53, 1); +byte z0 = Wire.read(); + +Wire.beginTransmission(0x53); +Wire.write(0x37); +Wire.endTransmission(); +Wire.requestFrom(0x53, 1); +byte z1 = Wire.read(); +z1 = z1 & 0x03; + +uint16_t z = (z1 << 8) + z0; +int16_t zf = z; +if(zf > 511) +{ +zf = zf - 1024; +} +float za = zf * 0.004; +printf("Z = %f\n\n",static_cast(za)); +// Serial.print("Z = "); +// Serial.print(za); +// Serial.print(" g"); +// Serial.println(); +// Serial.println(); +delay(500); + +} diff --git a/samples/modules/arduino-core/serial_event/CMakeLists.txt b/samples/modules/arduino-core/serial_event/CMakeLists.txt new file mode 100644 index 0000000000000..f09ac49dce9c4 --- /dev/null +++ b/samples/modules/arduino-core/serial_event/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(serial_event) + +target_sources(app PRIVATE src/app.cpp) + +zephyr_compile_options(-Wno-unused-variable -Wno-comment) diff --git a/samples/modules/arduino-core/serial_event/README.rst b/samples/modules/arduino-core/serial_event/README.rst new file mode 100644 index 0000000000000..e4dde00802ac9 --- /dev/null +++ b/samples/modules/arduino-core/serial_event/README.rst @@ -0,0 +1,20 @@ +.. _serial_event: + +Serial Event +############ + +Overview +******** + +The serial_event sample echo back serial input data. + +Building and Running +******************** + +Build and flash serial_event sample as follows, + +```sh +$> west build -p -b arduino_nano_33_ble sample/serial_event/ + +$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac +``` diff --git a/samples/modules/arduino-core/serial_event/prj.conf b/samples/modules/arduino-core/serial_event/prj.conf new file mode 100644 index 0000000000000..f93fa32189f54 --- /dev/null +++ b/samples/modules/arduino-core/serial_event/prj.conf @@ -0,0 +1 @@ +CONFIG_ARDUINO_API=y diff --git a/samples/modules/arduino-core/serial_event/sample.yaml b/samples/modules/arduino-core/serial_event/sample.yaml new file mode 100644 index 0000000000000..f1c0b1e9b3e8f --- /dev/null +++ b/samples/modules/arduino-core/serial_event/sample.yaml @@ -0,0 +1,22 @@ +sample: + name: Serial Event sample + +common: + tags: + - arduino-core + required_snippets: + - arduino-core + platform_allow: + - arduino_mkrzero/samd21g18a + - arduino_nano_33_ble/nrf52840 + - arduino_nano_33_ble/nrf52840/sense + - arduino_nano_33_iot/samd21g18a + - beagleconnect_freedom/cc1352p7 + - cc3220sf_launchxl/cc3220sf + - nrf52840dk/nrf52840 + - nrf9160dk/nrf9160 + - rpi_pico/rp2040 + +tests: + sample.arduino-core.serial_event.build: + build_only: true diff --git a/samples/modules/arduino-core/serial_event/src/app.cpp b/samples/modules/arduino-core/serial_event/src/app.cpp new file mode 100644 index 0000000000000..602d378a6359a --- /dev/null +++ b/samples/modules/arduino-core/serial_event/src/app.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 TOKITA Hiroshi + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +void setup() { + Serial.begin(115200); +} + +void loop() { +} + +void serialEvent() { + while(Serial.available()) { + Serial.print((char)Serial.read()); + } +} diff --git a/samples/modules/arduino-core/spi_controller/CMakeLists.txt b/samples/modules/arduino-core/spi_controller/CMakeLists.txt new file mode 100644 index 0000000000000..57696a7a899c1 --- /dev/null +++ b/samples/modules/arduino-core/spi_controller/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(spi_controller) + +target_sources(app PRIVATE src/app.cpp) + +zephyr_compile_options(-Wno-unused-variable -Wno-comment) diff --git a/samples/modules/arduino-core/spi_controller/README.rst b/samples/modules/arduino-core/spi_controller/README.rst new file mode 100644 index 0000000000000..8d2aad338c628 --- /dev/null +++ b/samples/modules/arduino-core/spi_controller/README.rst @@ -0,0 +1,9 @@ +.. _spi_controller: + +SPI Controller +############### + +Overview +******** + +A simple sample that sends incrementing byte to SPI peripheral. diff --git a/samples/modules/arduino-core/spi_controller/prj.conf b/samples/modules/arduino-core/spi_controller/prj.conf new file mode 100644 index 0000000000000..b4ab9858f4f5d --- /dev/null +++ b/samples/modules/arduino-core/spi_controller/prj.conf @@ -0,0 +1,6 @@ +CONFIG_CPP=y +CONFIG_ARDUINO_API=y +CONFIG_SPI=y +CONFIG_LOG=y +CONFIG_LOG_OUTPUT=y +CONFIG_LOG_MODE_IMMEDIATE=y diff --git a/samples/modules/arduino-core/spi_controller/sample.yaml b/samples/modules/arduino-core/spi_controller/sample.yaml new file mode 100644 index 0000000000000..929a1475a37de --- /dev/null +++ b/samples/modules/arduino-core/spi_controller/sample.yaml @@ -0,0 +1,22 @@ +sample: + name: SPI controller sample + +common: + tags: + - arduino-core + required_snippets: + - arduino-core + platform_allow: + - arduino_mkrzero/samd21g18a + - arduino_nano_33_ble/nrf52840 + - arduino_nano_33_ble/nrf52840/sense + - arduino_nano_33_iot/samd21g18a + - beagleconnect_freedom/cc1352p7 + - cc3220sf_launchxl/cc3220sf + - nrf52840dk/nrf52840 + - nrf9160dk/nrf9160 + - rpi_pico/rp2040 + +tests: + sample.arduino-core.spi_controller.build: + build_only: true diff --git a/samples/modules/arduino-core/spi_controller/src/app.cpp b/samples/modules/arduino-core/spi_controller/src/app.cpp new file mode 100644 index 0000000000000..d03065124af04 --- /dev/null +++ b/samples/modules/arduino-core/spi_controller/src/app.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Ayush Singh + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "SPI.h" +#include + +#define CHIPSELECT 3 + +static uint8_t data = 0; + +void setup() { + SPI.begin(); + pinMode(CHIPSELECT, OUTPUT); + digitalWrite(CHIPSELECT, HIGH); +} + +void loop() { + SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0)); + digitalWrite(CHIPSELECT, LOW); + SPI.transfer(data++); + digitalWrite(CHIPSELECT, HIGH); + SPI.endTransaction(); + delay(1000); +} diff --git a/samples/modules/arduino-core/threads_arduino/CMakeLists.txt b/samples/modules/arduino-core/threads_arduino/CMakeLists.txt new file mode 100644 index 0000000000000..de5f17f68ff7d --- /dev/null +++ b/samples/modules/arduino-core/threads_arduino/CMakeLists.txt @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(threads) + +target_sources(app PRIVATE src/main.cpp) + +zephyr_compile_options(-Wno-unused-variable -Wno-comment) diff --git a/samples/modules/arduino-core/threads_arduino/README.rst b/samples/modules/arduino-core/threads_arduino/README.rst new file mode 100644 index 0000000000000..62d2a905eaa7a --- /dev/null +++ b/samples/modules/arduino-core/threads_arduino/README.rst @@ -0,0 +1,47 @@ +.. _arduino_nano_33_ble_multi_thread_blinky: + +Basic Thread Example +#################### + +Overview +******** + +This example demonstrates spawning multiple threads using +:c:func:`K_THREAD_DEFINE`. It spawns three threads. Each thread is then defined +at compile time using :c:func:`K_THREAD_DEFINE`. + +These three each control an LED. These LEDs, ``LED_BUILTIN``, ``D10`` and ``D11``, have +loop control and timing logic controlled by separate functions. + +- ``blink0()`` controls ``LED_BUILTIN`` and has a 100ms sleep cycle +- ``blink1()`` controls ``D11`` and has a 1000ms sleep cycle +- ``loop()`` controls ``D10`` and has a 300ms sleep cycle + +Requirements +************ + +The board must have two LEDs connected via GPIO pins and one builtin LED. These are called "User +LEDs" on many of Zephyr's :ref:`boards`. The LEDs must be mapped using the ```` +``LED_BUILTIN``, ``D10`` and ``D11`` to the :ref:`devicetree ` aliases, in the +variants folder. + +You will see one of these errors if you try to build this sample for an +unsupported board: + +.. code-block:: none + + Unsupported board: LED_BUILTIN devicetree alias is not defined + Unsupported board: D11 devicetree alias is not defined + +Building +******** + +For example, to build this sample for :ref:`arduino_nano_33_ble`: + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/arduino-threads + :board: arduino_nano_33_ble + :goals: build flash + :compact: + +Change ``arduino_nano_33_ble`` appropriately for other supported boards. diff --git a/samples/modules/arduino-core/threads_arduino/prj.conf b/samples/modules/arduino-core/threads_arduino/prj.conf new file mode 100644 index 0000000000000..2d0830d4efd2f --- /dev/null +++ b/samples/modules/arduino-core/threads_arduino/prj.conf @@ -0,0 +1,3 @@ +CONFIG_HEAP_MEM_POOL_SIZE=256 +CONFIG_GPIO=y +CONFIG_ARDUINO_API=y diff --git a/samples/modules/arduino-core/threads_arduino/sample.yaml b/samples/modules/arduino-core/threads_arduino/sample.yaml new file mode 100644 index 0000000000000..e582747fc40cf --- /dev/null +++ b/samples/modules/arduino-core/threads_arduino/sample.yaml @@ -0,0 +1,22 @@ +sample: + name: Threads Arduino sample + +common: + tags: + - arduino-core + required_snippets: + - arduino-core + platform_allow: + - arduino_mkrzero/samd21g18a + - arduino_nano_33_ble/nrf52840 + - arduino_nano_33_ble/nrf52840/sense + - arduino_nano_33_iot/samd21g18a + - beagleconnect_freedom/cc1352p7 + - cc3220sf_launchxl/cc3220sf + - nrf52840dk/nrf52840 + - nrf9160dk/nrf9160 + - rpi_pico/rp2040 + +tests: + sample.arduino-core.threads_arduino.build: + build_only: true diff --git a/samples/modules/arduino-core/threads_arduino/src/main.cpp b/samples/modules/arduino-core/threads_arduino/src/main.cpp new file mode 100644 index 0000000000000..7fa0165005149 --- /dev/null +++ b/samples/modules/arduino-core/threads_arduino/src/main.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Dhruva Gole + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/* size of stack area used by each thread */ +#define STACKSIZE 1024 + +/* scheduling priority used by each thread */ +#define PRIORITY 7 + +void blink0(void) +{ + while (1) { + digitalWrite(LED_BUILTIN, HIGH); + delay(100); + digitalWrite(LED_BUILTIN, LOW); + delay(100); + } +} + +void blink1(void) +{ + while (1) { + digitalWrite(D11, HIGH); + delay(1000); + digitalWrite(D11, LOW); + delay(1000); + } +} + +K_THREAD_DEFINE(blink0_id, STACKSIZE, blink0, NULL, NULL, NULL, PRIORITY, 0, 0); +K_THREAD_DEFINE(blink1_id, STACKSIZE, blink1, NULL, NULL, NULL, PRIORITY, 0, 0); +K_THREAD_DEFINE(blink2_id, STACKSIZE, loop, NULL, NULL, NULL, PRIORITY, 0, 0); + +void setup() +{ + pinMode(LED_BUILTIN, OUTPUT); + pinMode(D11, OUTPUT); + pinMode(D10, OUTPUT); +} +void loop() +{ + digitalWrite(D10, HIGH); + delay(300); + digitalWrite(D10, LOW); + delay(300); +} diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py index e3913dd585b79..42df47315942a 100755 --- a/scripts/dts/gen_defines.py +++ b/scripts/dts/gen_defines.py @@ -288,6 +288,7 @@ def write_special_props(node: edtlib.Node) -> None: write_pinctrls(node) write_fixed_partitions(node) write_gpio_hogs(node) + write_maps(node) def write_ranges(node: edtlib.Node) -> None: @@ -579,6 +580,72 @@ def write_gpio_hogs(node: edtlib.Node) -> None: out_dt_define(macro, val) +def write_maps(node: edtlib.Node) -> None: + if len(node.maps) == 0: + return + + out_comment("Map properties:") + + basename = str2ident(node.maps[0].basename) + macro = f"{node.z_path_id}_P_{basename}_map" + macro2val = {} + + for i, cd in enumerate(node.maps): + if basename != str2ident(cd.basename): + err(f"Map basename mismatch: {basename} != {str2ident(cd.basename)}") + + macro2val.update(controller_and_data_macros(cd, i, macro, "")) + + prop_id = f"{basename}_map" + plen = len(node.maps) + # DT_N__P__FOREACH_PROP_ELEM + macro2val[f"{macro}_FOREACH_PROP_ELEM(fn)"] = ' \\\n\t'.join( + f'fn(DT_{node.z_path_id}, {prop_id}, {i})' for i in range(plen) + ) + + # DT_N__P__FOREACH_PROP_ELEM_SEP + macro2val[f"{macro}_FOREACH_PROP_ELEM_SEP(fn, sep)"] = ' DT_DEBRACKET_INTERNAL sep \\\n\t'.join( + f'fn(DT_{node.z_path_id}, {prop_id}, {i})' for i in range(plen) + ) + + # DT_N__P__FOREACH_PROP_ELEM_VARGS + macro2val[f"{macro}_FOREACH_PROP_ELEM_VARGS(fn, ...)"] = ' \\\n\t'.join( + f'fn(DT_{node.z_path_id}, {prop_id}, {i}, __VA_ARGS__)' for i in range(plen) + ) + + # DT_N__P__FOREACH_PROP_ELEM_SEP_VARGS + macro2val[f"{macro}_FOREACH_PROP_ELEM_SEP_VARGS(fn, sep, ...)"] = ( + ' DT_DEBRACKET_INTERNAL sep \\\n\t'.join( + f'fn(DT_{node.z_path_id}, {prop_id}, {i}, __VA_ARGS__)' for i in range(plen) + ) + ) + + macro2val[f"{macro}_LEN"] = plen + macro2val[f"{macro}_EXISTS"] = 1 + + for i, cd in enumerate(node.maps): + parent_specifier_len = len([k for k in cd.data if k.startswith('parent_specifier_')]) + child_specifiers = list(cd.data.values())[:-parent_specifier_len] + parent_specifiers = list(cd.data.values())[-parent_specifier_len:] + child_specifier_len = len(child_specifiers) + + args = [] + args.extend([str(v) for v in child_specifiers]) + args.extend(["DT_" + node_z_path_id(cd.controller)]) + args.extend([str(v) for v in parent_specifiers]) + + macro2val[f"{macro}_MAP_IDX_{i}"] = ", ".join(args) + macro2val[f"{macro}_MAP_IDX_{i}_CHILD_SPECIFIER_POS"] = 0 + macro2val[f"{macro}_MAP_IDX_{i}_CHILD_SPECIFIER_LEN"] = child_specifier_len + macro2val[f"{macro}_MAP_IDX_{i}_PARENT_POS"] = child_specifier_len + macro2val[f"{macro}_MAP_IDX_{i}_PARENT_LEN"] = 1 + macro2val[f"{macro}_MAP_IDX_{i}_PARENT_SPECIFIER_POS"] = child_specifier_len + 1 + macro2val[f"{macro}_MAP_IDX_{i}_PARENT_SPECIFIER_LEN"] = parent_specifier_len + + for mc, val in macro2val.items(): + out_dt_define(mc, val) + + def write_vanilla_props(node: edtlib.Node) -> None: # Writes macros for any and all properties defined in the # "properties" section of the binding for the node. diff --git a/scripts/dts/python-devicetree/src/devicetree/edtlib.py b/scripts/dts/python-devicetree/src/devicetree/edtlib.py index 916cdc230d236..e9091388312d4 100644 --- a/scripts/dts/python-devicetree/src/devicetree/edtlib.py +++ b/scripts/dts/python-devicetree/src/devicetree/edtlib.py @@ -1321,6 +1321,97 @@ def gpio_hogs(self) -> list[ControllerAndData]: return res + @property + def maps(self) -> list[ControllerAndData]: + res: list[ControllerAndData] = [] + + def count_cells_num(node: dtlib_Node, specifier: str) -> int: + """ + Calculate the number of cells in the node. + When calculating the number of interrupt cells, + add up the values of the address cells. + """ + + if node is None: + _err("node is None.") + + num = node.props[f"#{specifier}-cells"].to_num() + + if specifier == "interrupt": + parent_props = None + if node.parent: + parent_props = node.parent.props + + if "#address-cells" in node.props: + num = num + node.props["#address-cells"].to_num() + elif parent_props and "#address-cells" in parent_props: + num = num + parent_props["#address-cells"].to_num() + else: + _err("Neither the node nor its parent has `#address-cells` property") + + return num + + for prop in [v for k, v in self._node.props.items() if k.endswith("-map")]: + specifier_space = prop.name[:-4] # Strip '-map' + raw = prop.value + while raw: + if len(raw) < 4: + # Not enough room for phandle + _err("bad value for " + repr(prop)) + + child_specifier_num = count_cells_num(prop.node, specifier_space) + + child_specifiers = to_nums(raw[: 4 * child_specifier_num]) + raw = raw[4 * child_specifier_num :] + phandle = to_num(raw[:4]) + raw = raw[4:] + + controller_node = prop.node.dt.phandle2node.get(phandle) + if controller_node is None: + _err(f"controller node cannot be found from phandle:{phandle}") + + controller: Node = self.edt._node2enode[controller_node] + if controller is None: + _err("controller cannot be found from: " + repr(controller_node)) + + parent_specifier_num = count_cells_num(controller_node, specifier_space) + parent_specifiers = to_nums(raw[: 4 * parent_specifier_num]) + raw = raw[4 * parent_specifier_num :] + + # Although this is rare, if a cell-name is specified for the map node, + # it will be reflected. + # If not specified, the name of child_specifier_[i] will be set. + values: dict[str, int] = {} + for i, v in enumerate(child_specifiers): + cell_name = f"child_specifier_{i}" + if (self._binding and + self._binding.specifier2cells and + specifier_space in self._binding.specifier2cells and + i < len(self._binding.specifier2cells[specifier_space])): + cell_name = self._binding.specifier2cells[specifier_space][i] + + values[cell_name] = v + + # The cell name for parent_specifier cannot be determined. + # For convenience, we assign it the name parent_specifier_[i]. + for i, v in enumerate(parent_specifiers): + values[f"parent_specifier_{i}"] = v + + res.append( + ControllerAndData( + node=self, + controller=controller, + data=values, + name=None, + basename=specifier_space, + ) + ) + + if len(raw) != 0: + _err(f"unexpected prop.value remainings: {raw}") + + return res + @property def has_child_binding(self) -> bool: """ diff --git a/scripts/dts/python-devicetree/tests/test_edtlib.py b/scripts/dts/python-devicetree/tests/test_edtlib.py index f26b5fa158150..6e9c5914889b3 100644 --- a/scripts/dts/python-devicetree/tests/test_edtlib.py +++ b/scripts/dts/python-devicetree/tests/test_edtlib.py @@ -130,6 +130,116 @@ def test_interrupts(): edtlib.ControllerAndData(node=node, controller=edt.get_node('/interrupt-map-bitops-test/controller'), data={'one': 3, 'two': 2}, name=None, basename=None) ] + +def test_maps(): + '''Tests for the maps property.''' + with from_here(): + edt = edtlib.EDT("test.dts", ["test-bindings"]) + + nexus = edt.get_node("/interrupt-map-test/nexus") + controller_0 = edt.get_node("/interrupt-map-test/controller-0") + controller_1 = edt.get_node("/interrupt-map-test/controller-1") + controller_2 = edt.get_node("/interrupt-map-test/controller-2") + + assert nexus.maps == [ + edtlib.ControllerAndData( + node=nexus, + controller=controller_0, + data={ + "child_specifier_0": 0, + "child_specifier_1": 0, + "child_specifier_2": 0, + "child_specifier_3": 0, + "parent_specifier_0": 0, + "parent_specifier_1": 0, + }, + name=None, + basename="interrupt", + ), + edtlib.ControllerAndData( + node=nexus, + controller=controller_1, + data={ + "child_specifier_0": 0, + "child_specifier_1": 0, + "child_specifier_2": 0, + "child_specifier_3": 1, + "parent_specifier_0": 0, + "parent_specifier_1": 0, + "parent_specifier_2": 0, + "parent_specifier_3": 1, + }, + name=None, + basename="interrupt", + ), + edtlib.ControllerAndData( + node=nexus, + controller=controller_2, + data={ + "child_specifier_0": 0, + "child_specifier_1": 0, + "child_specifier_2": 0, + "child_specifier_3": 2, + "parent_specifier_0": 0, + "parent_specifier_1": 0, + "parent_specifier_2": 0, + "parent_specifier_3": 0, + "parent_specifier_4": 0, + "parent_specifier_5": 2, + }, + name=None, + basename="interrupt", + ), + edtlib.ControllerAndData( + node=nexus, + controller=controller_0, + data={ + "child_specifier_0": 0, + "child_specifier_1": 1, + "child_specifier_2": 0, + "child_specifier_3": 0, + "parent_specifier_0": 0, + "parent_specifier_1": 3, + }, + name=None, + basename="interrupt", + ), + edtlib.ControllerAndData( + node=nexus, + controller=controller_1, + data={ + "child_specifier_0": 0, + "child_specifier_1": 1, + "child_specifier_2": 0, + "child_specifier_3": 1, + "parent_specifier_0": 0, + "parent_specifier_1": 0, + "parent_specifier_2": 0, + "parent_specifier_3": 4, + }, + name=None, + basename="interrupt", + ), + edtlib.ControllerAndData( + node=nexus, + controller=controller_2, + data={ + "child_specifier_0": 0, + "child_specifier_1": 1, + "child_specifier_2": 0, + "child_specifier_3": 2, + "parent_specifier_0": 0, + "parent_specifier_1": 0, + "parent_specifier_2": 0, + "parent_specifier_3": 0, + "parent_specifier_4": 0, + "parent_specifier_5": 5, + }, + name=None, + basename="interrupt", + ), + ] + def test_ranges(): '''Tests for the ranges property''' with from_here(): diff --git a/snippets/arduino-core/README.rst b/snippets/arduino-core/README.rst new file mode 100644 index 0000000000000..9bf28fb344fa1 --- /dev/null +++ b/snippets/arduino-core/README.rst @@ -0,0 +1,20 @@ +.. _arduino_core: + +ArduinoCore: universal snippet for ArduinoCore +############################################## + +Overview +******** + +This snippet will enable the necessary settings for ArduinoCore. + +Programming +*********** + +Correct snippet designation for ArduinoCore must +be entered when you invoke ``west build``. +For example: + +.. code-block:: console + + west build -b arduino_nano_33_ble -S arduino_core diff --git a/snippets/arduino-core/arduino-core.conf b/snippets/arduino-core/arduino-core.conf new file mode 100644 index 0000000000000..f93fa32189f54 --- /dev/null +++ b/snippets/arduino-core/arduino-core.conf @@ -0,0 +1 @@ +CONFIG_ARDUINO_API=y diff --git a/snippets/arduino-core/boards/arduino_mkrzero_samd21g18a.overlay b/snippets/arduino-core/boards/arduino_mkrzero_samd21g18a.overlay new file mode 100644 index 0000000000000..89869442f3987 --- /dev/null +++ b/snippets/arduino-core/boards/arduino_mkrzero_samd21g18a.overlay @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2022 Dhruva Gole + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/ { + zephyr,user { + digital-pin-gpios = <&arduino_mkr_header 0 0>, + <&arduino_mkr_header 1 0>, + <&arduino_mkr_header 2 0>, + <&arduino_mkr_header 3 0>, + <&arduino_mkr_header 4 0>, + <&arduino_mkr_header 5 0>, + <&arduino_mkr_header 6 0>, + <&arduino_mkr_header 7 0>, + <&arduino_mkr_header 8 0>, + <&arduino_mkr_header 9 0>, + <&arduino_mkr_header 10 0>, + <&arduino_mkr_header 11 0>, + <&arduino_mkr_header 12 0>, + <&arduino_mkr_header 13 0>, + <&arduino_mkr_header 14 0>, /* D14 / A0 */ + <&arduino_mkr_header 15 0>, + <&arduino_mkr_header 16 0>, + <&arduino_mkr_header 17 0>, + <&arduino_mkr_header 18 0>, /* D18 / A4 / I2C-SDA */ + <&arduino_mkr_header 19 0>, /* D19 / A5 / I2C-SCL */ + <&arduino_mkr_header 20 0>, + <&arduino_mkr_header 21 0>, + <&portb 8 0>; + + pwm-pin-gpios = <&arduino_mkr_header 2 0>, + <&arduino_mkr_header 3 0>; + + adc-pin-gpios = <&arduino_mkr_header 15 0>, + <&arduino_mkr_header 16 0>, + <&arduino_mkr_header 17 0>, + <&arduino_mkr_header 18 0>, + <&arduino_mkr_header 19 0>, + <&arduino_mkr_header 20 0>, + <&arduino_mkr_header 21 0>; + + pwms = <&tcc0 2 255>, + <&tcc0 3 255>; + + io-channels = <&adc 0>, + <&adc 10>, + <&adc 11>, + <&adc 4>, + <&adc 5>, + <&adc 6>, + <&adc 7>; + + gpio-ports = <&porta>, <&portb>; + serials = <&sercom5>; + i2cs = <&sercom0>; + }; +}; + +&pinctrl { + pwm_default: pwm_default { + group1 { + pinmux = , + ; + }; + }; + + adc_default: adc_default { + group1 { + pinmux = , + , + , + , + , + , + ; + }; + }; +}; + +&tcc0 { + status = "okay"; + compatible = "atmel,sam0-tcc-pwm"; + prescaler = <2>; + #pwm-cells = <2>; + + pinctrl-0 = <&pwm_default>; + pinctrl-names = "default"; +}; + +&adc { + status = "okay"; + pinctrl-0 = <&adc_default>; + pinctrl-names = "default"; + + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0x0>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <0>; + }; + + channel@4 { + reg = <0x4>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <4>; + }; + + channel@5 { + reg = <0x5>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <5>; + }; + + channel@6 { + reg = <0x6>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <6>; + }; + + channel@7 { + reg = <0x7>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <7>; + }; + + channel@a { + reg = <0xa>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <10>; + }; + + channel@b { + reg = <0xb>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <11>; + }; +}; diff --git a/snippets/arduino-core/boards/arduino_nano_33_ble_nrf52840.overlay b/snippets/arduino-core/boards/arduino_nano_33_ble_nrf52840.overlay new file mode 100644 index 0000000000000..5dadc8012415b --- /dev/null +++ b/snippets/arduino-core/boards/arduino_nano_33_ble_nrf52840.overlay @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2022 Dhruva Gole + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + zephyr,user { + digital-pin-gpios = <&arduino_nano_header 0 0>, + <&arduino_nano_header 1 0>, + <&arduino_nano_header 2 0>, + <&arduino_nano_header 3 0>, + <&arduino_nano_header 4 0>, + <&arduino_nano_header 5 0>, + <&arduino_nano_header 6 0>, + <&arduino_nano_header 7 0>, + <&arduino_nano_header 8 0>, + <&arduino_nano_header 9 0>, + <&arduino_nano_header 10 0>, + <&arduino_nano_header 11 0>, + <&arduino_nano_header 12 0>, + <&arduino_nano_header 13 0>, + <&arduino_nano_header 14 0>, /* D14 / A0 */ + <&arduino_nano_header 15 0>, + <&arduino_nano_header 16 0>, + <&arduino_nano_header 17 0>, + <&arduino_nano_header 18 0>, /* D18 / A4 / I2C-SDA */ + <&arduino_nano_header 19 0>, /* D19 / A5 / I2C-SCL */ + <&arduino_nano_header 20 0>, + <&arduino_nano_header 21 0>; + + pwm-pin-gpios = <&arduino_nano_header 3 0>, + <&arduino_nano_header 5 0>, + <&arduino_nano_header 6 0>, + <&arduino_nano_header 13 0>, + <&arduino_nano_header 9 0>, + <&arduino_nano_header 10 0>, + <&arduino_nano_header 11 0>; + + adc-pin-gpios = <&arduino_nano_header 14 0>, + <&arduino_nano_header 15 0>, + <&arduino_nano_header 16 0>, + <&arduino_nano_header 17 0>, + <&arduino_nano_header 18 0>, + <&arduino_nano_header 19 0>, + <&arduino_nano_header 20 0>, + <&arduino_nano_header 21 0>; + + pwms = <&pwm1 1 255 PWM_POLARITY_NORMAL>, + <&pwm1 2 255 PWM_POLARITY_NORMAL>, + <&pwm1 3 255 PWM_POLARITY_NORMAL>, + <&pwm2 0 255 PWM_POLARITY_NORMAL>, + <&pwm2 1 255 PWM_POLARITY_NORMAL>, + <&pwm2 2 255 PWM_POLARITY_NORMAL>, + <&pwm2 3 255 PWM_POLARITY_NORMAL>; + + io-channels = <&adc 2>, + <&adc 3>, + <&adc 6>, + <&adc 5>, + <&adc 7>, + <&adc 0>, + <&adc 4>, + <&adc 1>; + + gpio-ports = <&gpio0>, <&gpio1>; + serials = <&uart0>; + i2cs = <&arduino_nano_i2c>; + }; +}; + +&adc { + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.02 */ + zephyr,resolution = <10>; + }; + + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.03 */ + zephyr,resolution = <10>; + }; + + channel@2 { + reg = <2>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.04 */ + zephyr,resolution = <10>; + }; + + channel@3 { + reg = <3>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.05 */ + zephyr,resolution = <10>; + }; + + channel@4 { + reg = <4>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.28 */ + zephyr,resolution = <10>; + }; + + channel@5 { + reg = <5>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.29 */ + zephyr,resolution = <10>; + }; + + channel@6 { + reg = <6>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.30 */ + zephyr,resolution = <10>; + }; + + channel@7 { + reg = <7>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.31 */ + zephyr,resolution = <10>; + }; +}; + +&pinctrl { + pwm1_default: pwm1_default { + group1 { + psels = , /* keep original config */ + , + , + ; + nordic,invert; + }; + }; + + pwm1_sleep: pwm1_sleep { + group1 { + psels = , /* keep original config */ + , + , + ; + low-power-enable; + }; + }; + + pwm2_default: pwm2_default { + group1 { + psels = , /* keep original config */ + , + , + ; + nordic,invert; + }; + }; + + pwm2_sleep: pwm2_sleep { + group1 { + psels = , /* keep original config */ + , + , + ; + low-power-enable; + }; + }; +}; + +&pwm1 { + status = "okay"; + pinctrl-0 = <&pwm1_default>; + pinctrl-1 = <&pwm1_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&pwm2 { + status = "okay"; + pinctrl-0 = <&pwm2_default>; + pinctrl-1 = <&pwm2_sleep>; + pinctrl-names = "default", "sleep"; +}; diff --git a/snippets/arduino-core/boards/arduino_nano_33_ble_nrf52840_sense.overlay b/snippets/arduino-core/boards/arduino_nano_33_ble_nrf52840_sense.overlay new file mode 100644 index 0000000000000..5dadc8012415b --- /dev/null +++ b/snippets/arduino-core/boards/arduino_nano_33_ble_nrf52840_sense.overlay @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2022 Dhruva Gole + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + zephyr,user { + digital-pin-gpios = <&arduino_nano_header 0 0>, + <&arduino_nano_header 1 0>, + <&arduino_nano_header 2 0>, + <&arduino_nano_header 3 0>, + <&arduino_nano_header 4 0>, + <&arduino_nano_header 5 0>, + <&arduino_nano_header 6 0>, + <&arduino_nano_header 7 0>, + <&arduino_nano_header 8 0>, + <&arduino_nano_header 9 0>, + <&arduino_nano_header 10 0>, + <&arduino_nano_header 11 0>, + <&arduino_nano_header 12 0>, + <&arduino_nano_header 13 0>, + <&arduino_nano_header 14 0>, /* D14 / A0 */ + <&arduino_nano_header 15 0>, + <&arduino_nano_header 16 0>, + <&arduino_nano_header 17 0>, + <&arduino_nano_header 18 0>, /* D18 / A4 / I2C-SDA */ + <&arduino_nano_header 19 0>, /* D19 / A5 / I2C-SCL */ + <&arduino_nano_header 20 0>, + <&arduino_nano_header 21 0>; + + pwm-pin-gpios = <&arduino_nano_header 3 0>, + <&arduino_nano_header 5 0>, + <&arduino_nano_header 6 0>, + <&arduino_nano_header 13 0>, + <&arduino_nano_header 9 0>, + <&arduino_nano_header 10 0>, + <&arduino_nano_header 11 0>; + + adc-pin-gpios = <&arduino_nano_header 14 0>, + <&arduino_nano_header 15 0>, + <&arduino_nano_header 16 0>, + <&arduino_nano_header 17 0>, + <&arduino_nano_header 18 0>, + <&arduino_nano_header 19 0>, + <&arduino_nano_header 20 0>, + <&arduino_nano_header 21 0>; + + pwms = <&pwm1 1 255 PWM_POLARITY_NORMAL>, + <&pwm1 2 255 PWM_POLARITY_NORMAL>, + <&pwm1 3 255 PWM_POLARITY_NORMAL>, + <&pwm2 0 255 PWM_POLARITY_NORMAL>, + <&pwm2 1 255 PWM_POLARITY_NORMAL>, + <&pwm2 2 255 PWM_POLARITY_NORMAL>, + <&pwm2 3 255 PWM_POLARITY_NORMAL>; + + io-channels = <&adc 2>, + <&adc 3>, + <&adc 6>, + <&adc 5>, + <&adc 7>, + <&adc 0>, + <&adc 4>, + <&adc 1>; + + gpio-ports = <&gpio0>, <&gpio1>; + serials = <&uart0>; + i2cs = <&arduino_nano_i2c>; + }; +}; + +&adc { + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.02 */ + zephyr,resolution = <10>; + }; + + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.03 */ + zephyr,resolution = <10>; + }; + + channel@2 { + reg = <2>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.04 */ + zephyr,resolution = <10>; + }; + + channel@3 { + reg = <3>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.05 */ + zephyr,resolution = <10>; + }; + + channel@4 { + reg = <4>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.28 */ + zephyr,resolution = <10>; + }; + + channel@5 { + reg = <5>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.29 */ + zephyr,resolution = <10>; + }; + + channel@6 { + reg = <6>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.30 */ + zephyr,resolution = <10>; + }; + + channel@7 { + reg = <7>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.31 */ + zephyr,resolution = <10>; + }; +}; + +&pinctrl { + pwm1_default: pwm1_default { + group1 { + psels = , /* keep original config */ + , + , + ; + nordic,invert; + }; + }; + + pwm1_sleep: pwm1_sleep { + group1 { + psels = , /* keep original config */ + , + , + ; + low-power-enable; + }; + }; + + pwm2_default: pwm2_default { + group1 { + psels = , /* keep original config */ + , + , + ; + nordic,invert; + }; + }; + + pwm2_sleep: pwm2_sleep { + group1 { + psels = , /* keep original config */ + , + , + ; + low-power-enable; + }; + }; +}; + +&pwm1 { + status = "okay"; + pinctrl-0 = <&pwm1_default>; + pinctrl-1 = <&pwm1_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&pwm2 { + status = "okay"; + pinctrl-0 = <&pwm2_default>; + pinctrl-1 = <&pwm2_sleep>; + pinctrl-names = "default", "sleep"; +}; diff --git a/snippets/arduino-core/boards/arduino_nano_33_iot_samd21g18a.overlay b/snippets/arduino-core/boards/arduino_nano_33_iot_samd21g18a.overlay new file mode 100644 index 0000000000000..c6ef831a25488 --- /dev/null +++ b/snippets/arduino-core/boards/arduino_nano_33_iot_samd21g18a.overlay @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2022 Dhruva Gole + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/ { + zephyr,user { + digital-pin-gpios = <&arduino_nano_header 0 0>, + <&arduino_nano_header 1 0>, + <&arduino_nano_header 2 0>, + <&arduino_nano_header 3 0>, + <&arduino_nano_header 4 0>, + <&arduino_nano_header 5 0>, + <&arduino_nano_header 6 0>, + <&arduino_nano_header 7 0>, + <&arduino_nano_header 8 0>, + <&arduino_nano_header 9 0>, + <&arduino_nano_header 10 0>, + <&arduino_nano_header 11 0>, + <&arduino_nano_header 12 0>, + <&arduino_nano_header 13 0>, + <&arduino_nano_header 14 0>, /* D14 / A0 */ + <&arduino_nano_header 15 0>, + <&arduino_nano_header 16 0>, + <&arduino_nano_header 17 0>, + <&arduino_nano_header 18 0>, /* D18 / A4 / I2C-SDA */ + <&arduino_nano_header 19 0>, /* D19 / A5 / I2C-SCL */ + <&arduino_nano_header 20 0>, + <&arduino_nano_header 21 0>; + + pwm-pin-gpios = <&arduino_nano_header 6 0>, + <&arduino_nano_header 5 0>, + <&arduino_nano_header 17 0>, + <&arduino_nano_header 12 0>, + <&arduino_nano_header 2 0>, + <&arduino_nano_header 3 0>, + <&arduino_nano_header 9 0>, + <&arduino_nano_header 10 0>; + + adc-pin-gpios = <&arduino_nano_header 14 0>, + <&arduino_nano_header 15 0>, + <&arduino_nano_header 16 0>, + <&arduino_nano_header 17 0>, + <&arduino_nano_header 18 0>, + <&arduino_nano_header 19 0>, + <&arduino_nano_header 20 0>, + <&arduino_nano_header 21 0>; + + pwms = <&tcc0 0 255>, + <&tcc0 1 255>, + <&tcc0 2 255>, + <&tcc0 3 255>, + <&tcc0 4 255>, + <&tcc0 5 255>, + <&tcc0 6 255>, + <&tcc0 7 255>; + + io-channels = <&adc 0>, + <&adc 10>, + <&adc 11>, + <&adc 4>, + <&adc 5>, + <&adc 6>, + <&adc 7>; + + gpio-ports = <&porta>, <&portb>; + serials = <&sercom5>; + i2cs = <&arduino_nano_i2c>; + }; +}; + +&pinctrl { + pwm_default: pwm_default { + group1 { + pinmux = , + , + , + , + , + , + , + ; + }; + }; + + adc_default: adc_default { + group1 { + pinmux = , + , + , + , + , + , + , + ; + }; + }; +}; + +&tcc0 { + status = "okay"; + compatible = "atmel,sam0-tcc-pwm"; + prescaler = <2>; + #pwm-cells = <2>; + + pinctrl-0 = <&pwm_default>; + pinctrl-names = "default"; +}; + +&adc { + status = "okay"; + pinctrl-0 = <&adc_default>; + pinctrl-names = "default"; + + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0x0>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <0>; + }; + + channel@2 { + reg = <0x2>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <2>; + }; + + channel@3 { + reg = <0x3>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <3>; + }; + + channel@a { + reg = <0xa>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <10>; + }; + + channel@b { + reg = <0xb>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <11>; + }; + + channel@12 { + reg = <0x12>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <18>; + }; + + channel@13 { + reg = <0x13>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <10>; + zephyr,input-positive = <19>; + }; +}; diff --git a/snippets/arduino-core/boards/beagleconnect_freedom_cc1352p7.overlay b/snippets/arduino-core/boards/beagleconnect_freedom_cc1352p7.overlay new file mode 100644 index 0000000000000..15f009617b174 --- /dev/null +++ b/snippets/arduino-core/boards/beagleconnect_freedom_cc1352p7.overlay @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 Ayush Singh + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + zephyr,user { + digital-pin-gpios = + <&gpio0 16 GPIO_ACTIVE_HIGH>, /* D0 - MB1 INT */ + <&gpio0 20 GPIO_ACTIVE_HIGH>, /* D1 - MB2 INT */ + <&gpio0 17 GPIO_ACTIVE_HIGH>, /* D2 - MB1 PWM */ + <&gpio0 28 GPIO_ACTIVE_HIGH>, /* D3 - MB1 CS - A5 */ + <&gpio0 21 GPIO_ACTIVE_HIGH>, /* D4 - MB2 UART1 RX */ + <&gpio0 22 GPIO_ACTIVE_HIGH>, /* D5 - MB2 UART1 TX */ + <&gpio0 19 GPIO_ACTIVE_HIGH>, /* D6 - MB2 PWM */ + <&gpio0 27 GPIO_ACTIVE_HIGH>, /* D7 - MB2 CS - A4 */ + <&gpio0 9 GPIO_ACTIVE_HIGH>, /* D8 - MB1/2 PICO */ + <&gpio0 10 GPIO_ACTIVE_HIGH>, /* D9 - MB1/2 SCK */ + <&gpio0 11 GPIO_ACTIVE_HIGH>, /* D10 - MB1/2 POCI */ + <&gpio0 26 GPIO_ACTIVE_HIGH>, /* D11 - MB1/2 SDA - A2 */ + <&gpio0 25 GPIO_ACTIVE_HIGH>, /* D12 - MB1/2 SCL - A3 */ + <&gpio0 12 GPIO_ACTIVE_HIGH>, /* D13 - MB1 UART0 RX */ + <&gpio0 13 GPIO_ACTIVE_HIGH>, /* D14 - MB1 UART0 TX */ + <&gpio0 23 GPIO_ACTIVE_HIGH>, /* D15 - MB1 AN - A0 */ + <&gpio0 24 GPIO_ACTIVE_HIGH>, /* D16 - MB2 AN - A1 */ + <&gpio0 5 GPIO_ACTIVE_HIGH>, /* D17 - MB2 RST */ + <&gpio0 6 GPIO_ACTIVE_HIGH>, /* D18 - MB1 RST */ + <&gpio0 7 GPIO_ACTIVE_HIGH>, /* D19 - on-board sensor INT */ + <&gpio0 8 GPIO_ACTIVE_HIGH>, /* D20 - flash CS */ + <&gpio0 14 GPIO_ACTIVE_HIGH>, /* D21 - on-board sensor I2C-en */ + <&gpio0 15 GPIO_ACTIVE_HIGH>, /* D22 - BOOT button */ + <&gpio0 18 GPIO_ACTIVE_HIGH>; /* D23 - LINK LED */ + + pwm-pin-gpios = + <&gpio0 17 GPIO_ACTIVE_HIGH>, /* D2 - MB1 PWM */ + <&gpio0 19 GPIO_ACTIVE_HIGH>; /* D6 - MB2 PWM */ + + pwms = <&pwm0 0 255 PWM_POLARITY_NORMAL>, + <&pwm1 0 255 PWM_POLARITY_NORMAL>; + + adc-pin-gpios = + <&gpio0 23 GPIO_ACTIVE_HIGH>, /* D15 - MB1 AN - A0 */ + <&gpio0 24 GPIO_ACTIVE_HIGH>, /* D16 - MB2 AN - A1 */ + <&gpio0 26 GPIO_ACTIVE_HIGH>, /* D11 - MB1/2 SDA - A2 */ + <&gpio0 25 GPIO_ACTIVE_HIGH>, /* D12 - MB1/2 SCL - A3 */ + <&gpio0 27 GPIO_ACTIVE_HIGH>, /* D7 - MB2 CS - A4 */ + <&gpio0 28 GPIO_ACTIVE_HIGH>; /* D3 - MB1 CS - A5 */ + + io-channels = <&adc0 0x09>, <&adc0 0x0a>, <&adc0 0x0b>, + <&adc0 0x0c>, <&adc0 0x0d>, <&adc0 0x0e>; + + adc-pin-gpios = + <&gpio0 23 GPIO_ACTIVE_HIGH>, /* D15 - MB1 AN - A0 */ + <&gpio0 24 GPIO_ACTIVE_HIGH>, /* D16 - MB2 AN - A1 */ + <&gpio0 26 GPIO_ACTIVE_HIGH>, /* D11 - MB1/2 SDA - A2 */ + <&gpio0 25 GPIO_ACTIVE_HIGH>, /* D12 - MB1/2 SCL - A3 */ + <&gpio0 27 GPIO_ACTIVE_HIGH>, /* D7 - MB2 CS - A4 */ + <&gpio0 28 GPIO_ACTIVE_HIGH>; /* D3 - MB1 CS - A5 */ + + gpio-ports = <&gpio0>; + serials = <&uart0 &uart1>; + i2cs = <&i2c0>; + spis = <&spi0>; + }; +}; diff --git a/snippets/arduino-core/boards/cc3220sf_launchxl_cc3220sf.overlay b/snippets/arduino-core/boards/cc3220sf_launchxl_cc3220sf.overlay new file mode 100644 index 0000000000000..743a525461dd5 --- /dev/null +++ b/snippets/arduino-core/boards/cc3220sf_launchxl_cc3220sf.overlay @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 Dhruva Gole + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + zephyr,user { + digital-pin-gpios = <&boosterpack_header 4 0>, /* GPIO_12 */ + <&boosterpack_header 5 0>, /* GPIO_06 */ + <&boosterpack_header 7 0>, /* GPIO_14 */ + <&boosterpack_header 9 0>, /* I2C_SCL | YELLOW_LED */ + <&boosterpack_header 10 0>, /* I2C_SDA | GREEN_LED */ + <&boosterpack_header 11 0>, /* GPIO_22 */ + <&boosterpack_header 12 0>, /* GPIO_01 */ + <&boosterpack_header 13 0>, /* GPIO_25 */ + <&boosterpack_header 14 0>, /* GPIO_15 */ + <&boosterpack_header 15 0>, /* GPIO_16 */ + <&boosterpack_header 17 0>, /* GPIO_31 */ + <&boosterpack_header 18 0>, /* GPIO_17 */ + <&boosterpack_header 19 0>, /* GPIO_28 */ + <&boosterpack_header 23 0>, /* GPIO_02 | AIN0 */ + <&boosterpack_header 24 0>, /* GPIO_05 | AIN3 */ + <&boosterpack_header 25 0>, /* GPIO_03 | AIN1 */ + <&boosterpack_header 26 0>, /* GPIO_04 | AIN2 */ + <&boosterpack_header 27 0>, /* GPIO_08 */ + <&boosterpack_header 28 0>, /* GPIO_30 */ + <&boosterpack_header 29 0>, /* GPIO_09 | RED_LED | I2S_DOUT*/ + <&boosterpack_header 30 0>, /* GPIO_00 */ + <&boosterpack_header 31 0>, /* GPIO_24 */ + <&boosterpack_header 32 0>; /* GPIO_23 */ + + gpio-ports = <&gpioa0>, <&gpioa1>, <&gpioa2>, <&gpioa3>; + serials = <&boosterpack_serial>; + i2cs = <&boosterpack_i2c>; + }; +}; diff --git a/snippets/arduino-core/boards/nrf52840dk_nrf52840.overlay b/snippets/arduino-core/boards/nrf52840dk_nrf52840.overlay new file mode 100644 index 0000000000000..35702cf2d22d8 --- /dev/null +++ b/snippets/arduino-core/boards/nrf52840dk_nrf52840.overlay @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2022 Mike Szczys + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + zephyr,user { + digital-pin-gpios = <&arduino_header 6 0>, /* Digital */ + <&arduino_header 7 0>, + <&arduino_header 8 0>, + <&arduino_header 9 0>, + <&arduino_header 10 0>, + <&arduino_header 11 0>, + <&arduino_header 12 0>, + <&arduino_header 13 0>, + <&arduino_header 14 0>, + <&arduino_header 15 0>, + <&arduino_header 16 0>, + <&arduino_header 17 0>, + <&arduino_header 18 0>, + <&arduino_header 19 0>, + <&arduino_header 20 0>, + <&arduino_header 21 0>, + <&arduino_header 0 0>, /* Analog */ + <&arduino_header 1 0>, + <&arduino_header 2 0>, + <&arduino_header 3 0>, + <&arduino_header 4 0>, + <&arduino_header 5 0>, + <&gpio0 13 GPIO_ACTIVE_LOW>; + + pwm-pin-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>, + <&arduino_header 9 0>, + <&arduino_header 11 0>, + <&arduino_header 12 0>, + <&arduino_header 15 0>, + <&arduino_header 16 0>, + <&arduino_header 17 0>; + + adc-pin-gpios = <&arduino_header 0 0>, + <&arduino_header 1 0>, + <&arduino_header 2 0>, + <&arduino_header 3 0>, + <&arduino_header 4 0>, + <&arduino_header 5 0>; + + pwms = <&pwm0 1 255 PWM_POLARITY_NORMAL>, + <&pwm0 2 255 PWM_POLARITY_NORMAL>, + <&pwm0 3 255 PWM_POLARITY_NORMAL>, + <&pwm1 0 255 PWM_POLARITY_NORMAL>, + <&pwm1 1 255 PWM_POLARITY_NORMAL>, + <&pwm1 2 255 PWM_POLARITY_NORMAL>; + + io-channels = <&arduino_adc 0>, + <&arduino_adc 1>, + <&arduino_adc 2>, + <&arduino_adc 3>, + <&arduino_adc 4>, + <&arduino_adc 5>; + + gpio-ports = <&gpio0>, <&gpio1>; + }; +}; + +&adc { + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.02 */ + zephyr,resolution = <10>; + }; + + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.03 */ + zephyr,resolution = <10>; + }; + + channel@2 { + reg = <2>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.04 */ + zephyr,resolution = <10>; + }; + + channel@3 { + reg = <3>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.05 */ + zephyr,resolution = <10>; + }; + + channel@4 { + reg = <4>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.28 */ + zephyr,resolution = <10>; + }; + + channel@5 { + reg = <5>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.29 */ + zephyr,resolution = <10>; + }; + + channel@6 { + reg = <6>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.30 */ + zephyr,resolution = <10>; + }; + + channel@7 { + reg = <7>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.31 */ + zephyr,resolution = <10>; + }; +}; + +&pinctrl { + pwm0_default: pwm0_default { + group1 { + psels = , /* keep original config */ + , + , + ; + nordic,invert; + }; + }; + + pwm0_sleep: pwm0_sleep { + group1 { + psels = , /* keep original config */ + , + , + ; + low-power-enable; + }; + }; + + pwm1_default: pwm1_default { + group1 { + psels = , + , + ; + nordic,invert; + }; + }; + + pwm1_sleep: pwm1_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; +}; + +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_default>; + pinctrl-1 = <&pwm0_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&pwm1 { + status = "okay"; + pinctrl-0 = <&pwm1_default>; + pinctrl-1 = <&pwm1_sleep>; + pinctrl-names = "default", "sleep"; +}; diff --git a/snippets/arduino-core/boards/nrf9160dk_nrf9160.overlay b/snippets/arduino-core/boards/nrf9160dk_nrf9160.overlay new file mode 100644 index 0000000000000..f39e262d8ebd7 --- /dev/null +++ b/snippets/arduino-core/boards/nrf9160dk_nrf9160.overlay @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2022 Mike Szczys + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + zephyr,user { + digital-pin-gpios = + <&arduino_header 6 0>, /* Digital */ + <&arduino_header 7 0>, + <&arduino_header 8 0>, + <&arduino_header 9 0>, + <&arduino_header 10 0>, + <&arduino_header 11 0>, + <&arduino_header 12 0>, + <&arduino_header 13 0>, + <&arduino_header 14 0>, + <&arduino_header 15 0>, + <&arduino_header 16 0>, + <&arduino_header 17 0>, + <&arduino_header 18 0>, + <&arduino_header 19 0>, + <&arduino_header 20 0>, + <&arduino_header 21 0>, + <&arduino_header 0 0>, /* Analog */ + <&arduino_header 1 0>, + <&arduino_header 2 0>, + <&arduino_header 3 0>, + <&arduino_header 4 0>, + <&arduino_header 5 0>, + <&gpio0 13 GPIO_ACTIVE_LOW>; + + pwm-pin-gpios = + <&gpio0 13 GPIO_ACTIVE_LOW>, + <&arduino_header 9 0>, + <&arduino_header 11 0>, + <&arduino_header 12 0>, + <&arduino_header 15 0>, + <&arduino_header 16 0>, + <&arduino_header 17 0>; + + adc-pin-gpios = + <&arduino_header 0 0>, + <&arduino_header 1 0>, + <&arduino_header 2 0>, + <&arduino_header 3 0>, + <&arduino_header 4 0>, + <&arduino_header 5 0>; + + pwms = + <&pwm0 1 255 PWM_POLARITY_NORMAL>, + <&pwm0 2 255 PWM_POLARITY_NORMAL>, + <&pwm0 3 255 PWM_POLARITY_NORMAL>, + <&pwm1 0 255 PWM_POLARITY_NORMAL>, + <&pwm1 1 255 PWM_POLARITY_NORMAL>, + <&pwm1 2 255 PWM_POLARITY_NORMAL>; + + io-channels = + <&arduino_adc 0>, + <&arduino_adc 1>, + <&arduino_adc 2>, + <&arduino_adc 3>, + <&arduino_adc 4>, + <&arduino_adc 5>; + + gpio-ports = <&gpio0>; + }; +}; + +&adc { + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.02 */ + zephyr,resolution = <10>; + }; + + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.03 */ + zephyr,resolution = <10>; + }; + + channel@2 { + reg = <2>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.04 */ + zephyr,resolution = <10>; + }; + + channel@3 { + reg = <3>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.05 */ + zephyr,resolution = <10>; + }; + + channel@4 { + reg = <4>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.28 */ + zephyr,resolution = <10>; + }; + + channel@5 { + reg = <5>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.29 */ + zephyr,resolution = <10>; + }; + + channel@6 { + reg = <6>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.30 */ + zephyr,resolution = <10>; + }; + + channel@7 { + reg = <7>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; /* P0.31 */ + zephyr,resolution = <10>; + }; +}; + +&pinctrl { + pwm0_default: pwm0_default { + group1 { + psels = , /* keep original config */ + , + , + ; + nordic,invert; + }; + }; + + pwm0_sleep: pwm0_sleep { + group1 { + psels = , /* keep original config */ + , + , + ; + low-power-enable; + }; + }; + + pwm1_default: pwm1_default { + group1 { + psels = , + , + ; + nordic,invert; + }; + }; + + pwm1_sleep: pwm1_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; +}; + +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_default>; + pinctrl-1 = <&pwm0_sleep>; + pinctrl-names = "default", "sleep"; +}; + +&pwm1 { + status = "okay"; + pinctrl-0 = <&pwm1_default>; + pinctrl-1 = <&pwm1_sleep>; + pinctrl-names = "default", "sleep"; +}; diff --git a/snippets/arduino-core/boards/rpi_pico_rp2040.overlay b/snippets/arduino-core/boards/rpi_pico_rp2040.overlay new file mode 100644 index 0000000000000..d51c154fa2e35 --- /dev/null +++ b/snippets/arduino-core/boards/rpi_pico_rp2040.overlay @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2024 TOKITA Hiroshi + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/ { + zephyr,user { + digital-pin-gpios = <&pico_header 0 0>, + <&pico_header 1 0>, + <&pico_header 2 0>, + <&pico_header 3 0>, + <&pico_header 4 0>, + <&pico_header 5 0>, + <&pico_header 6 0>, + <&pico_header 7 0>, + <&pico_header 8 0>, + <&pico_header 9 0>, + <&pico_header 10 0>, + <&pico_header 11 0>, + <&pico_header 12 0>, + <&pico_header 13 0>, + <&pico_header 14 0>, + <&pico_header 15 0>, + <&pico_header 16 0>, + <&pico_header 17 0>, + <&pico_header 18 0>, + <&pico_header 19 0>, + <&pico_header 20 0>, + <&pico_header 21 0>, + <&pico_header 22 0>, + <&gpio0 23 0>, + <&gpio0 24 0>, + <&gpio0 25 0>, + <&pico_header 26 0>, + <&pico_header 27 0>, + <&pico_header 28 0>; + + pwm-pin-gpios = <&pico_header 2 0>, + <&pico_header 3 0>, + <&pico_header 7 0>, + <&pico_header 8 0>, + <&pico_header 10 0>, + <&pico_header 11 0>, + <&pico_header 12 0>, + <&pico_header 13 0>, + <&pico_header 14 0>, + <&pico_header 15 0>, + <&pico_header 20 0>, + <&pico_header 21 0>, + <&pico_header 22 0>, + <&gpio0 25 0>; + + adc-pin-gpios = <&pico_header 26 0>, + <&pico_header 27 0>, + <&pico_header 28 0>; + + pwms = <&pwm 2 255 PWM_POLARITY_NORMAL>, + <&pwm 3 255 PWM_POLARITY_NORMAL>, + <&pwm 7 255 PWM_POLARITY_NORMAL>, + <&pwm 8 255 PWM_POLARITY_NORMAL>, + <&pwm 10 255 PWM_POLARITY_NORMAL>, + <&pwm 11 255 PWM_POLARITY_NORMAL>, + <&pwm 12 255 PWM_POLARITY_NORMAL>, + <&pwm 13 255 PWM_POLARITY_NORMAL>, + <&pwm 14 255 PWM_POLARITY_NORMAL>, + <&pwm 15 255 PWM_POLARITY_NORMAL>, + <&pwm 4 255 PWM_POLARITY_NORMAL>, + <&pwm 5 255 PWM_POLARITY_NORMAL>, + <&pwm 6 255 PWM_POLARITY_NORMAL>, + <&pwm 9 255 PWM_POLARITY_NORMAL>; + + io-channels = <&adc 0>, + <&adc 1>, + <&adc 2>; + + gpio-ports = <&gpio0>; + serials = <&pico_serial>; + i2cs = <&pico_i2c0>; + spis = <&pico_spi>; + }; +}; + +&pinctrl { + pwm_ch1a_default: pwm_ch1a_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch1b_default: pwm_ch1b_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch2a_default: pwm_ch2a_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch2b_default: pwm_ch2b_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch3a_default: pwm_ch3a_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch3b_default: pwm_ch3b_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch4a_default: pwm_ch4a_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch5a_default: pwm_ch5a_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch5b_default: pwm_ch5b_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch6a_default: pwm_ch6a_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch6b_default: pwm_ch6b_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch7a_default: pwm_ch7a_default { + group1 { + pinmux = ; + }; + }; + + pwm_ch7b_default: pwm_ch7b_default { + group1 { + pinmux = ; + }; + }; +}; + +&pwm { + status = "okay"; + divider-frac-4 = <15>; + divider-int-4 = <255>; +}; + +&adc { + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <12>; + }; + + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <12>; + }; + + channel@2 { + reg = <2>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <12>; + }; +}; diff --git a/snippets/arduino-core/snippet.yml b/snippets/arduino-core/snippet.yml new file mode 100644 index 0000000000000..f65acd9ea9b4c --- /dev/null +++ b/snippets/arduino-core/snippet.yml @@ -0,0 +1,32 @@ +name: arduino-core +append: + EXTRA_CONF_FILE: arduino-core.conf + +boards: + arduino_mkrzero/samd21g18a: + append: + EXTRA_DTC_OVERLAY_FILE: boards/arduino_mkrzero_samd21g18a.overlay + arduino_nano_33_ble/nrf52840: + append: + EXTRA_DTC_OVERLAY_FILE: boards/arduino_nano_33_ble_nrf52840.overlay + arduino_nano_33_ble/nrf52840/sense: + append: + EXTRA_DTC_OVERLAY_FILE: boards/arduino_nano_33_ble_nrf52840_sense.overlay + arduino_nano_33_iot/samd21g18a: + append: + EXTRA_DTC_OVERLAY_FILE: boards/arduino_nano_33_iot_samd21g18a.overlay + beagleconnect_freedom/cc1352p7: + append: + EXTRA_DTC_OVERLAY_FILE: boards/beagleconnect_freedom_cc1352p7.overlay + cc3220sf_launchxl/cc3220sf: + append: + EXTRA_DTC_OVERLAY_FILE: boards/cc3220sf_launchxl_cc3220sf.overlay + nrf52840dk/nrf52840: + append: + EXTRA_DTC_OVERLAY_FILE: boards/nrf52840dk_nrf52840.overlay + nrf9160dk/nrf9160: + append: + EXTRA_DTC_OVERLAY_FILE: boards/nrf9160dk_nrf9160.overlay + rpi_pico/rp2040: + append: + EXTRA_DTC_OVERLAY_FILE: boards/rpi_pico_rp2040.overlay diff --git a/tests/lib/devicetree/api/app.overlay b/tests/lib/devicetree/api/app.overlay index 950ca9b403555..a2961f115a13d 100644 --- a/tests/lib/devicetree/api/app.overlay +++ b/tests/lib/devicetree/api/app.overlay @@ -921,4 +921,49 @@ compatible = "vnd,non-deprecated-label"; label = "FOO"; }; + + gpio-map-test { + connector { + compatible = "vnd,gpio-nexus"; + #gpio-cells = <2>; + gpio-map = <1 2 &{/gpio-map-test/parent} 3 + 4 5 &{/gpio-map-test/parent} 6>; + gpio-map-mask = <0xffffffff 0xffffffc0>; + gpio-map-pass-thru = <0x0 0x3f>; + }; + parent { + compatible = "gpio-dst"; + gpio-controller; + #gpio-cells = <1>; + }; + }; + + interrupt-map-test { + #address-cells = <2>; + #size-cells = <0>; + + controller-0@0 { + compatible = "vnd,cpu-intc"; + reg = <0x0 0x0>; + #address-cells = <1>; + #interrupt-cells = <1>; + interrupt-controller; + }; + controller-1@1 { + compatible = "vnd,intc"; + reg = <0x0 0x1>; + #address-cells = <2>; + #interrupt-cells = <2>; + interrupt-controller; + }; + nexus { + compatible = "vnd,intr-nexus"; + #interrupt-cells = <2>; + interrupt-map = < + 0 0 1 2 &{/interrupt-map-test/controller-0@0} 3 4 + 0 0 5 6 &{/interrupt-map-test/controller-1@1} 7 8 9 0 + 0 1 9 8 &{/interrupt-map-test/controller-0@0} 7 6 + 0 1 5 4 &{/interrupt-map-test/controller-1@1} 3 2 1 0>; + }; + }; }; diff --git a/tests/lib/devicetree/api/src/main.c b/tests/lib/devicetree/api/src/main.c index 98189ebe582cc..38acae5be4387 100644 --- a/tests/lib/devicetree/api/src/main.c +++ b/tests/lib/devicetree/api/src/main.c @@ -111,6 +111,9 @@ #define TEST_SUBPARTITION_1 DT_PATH(test, test_mtd_ffeeddcc, flash_20000000, partitions, \ partition_100, partition_40) +#define TEST_GPIO_CONNECTOR DT_PATH(gpio_map_test, connector) +#define TEST_INTERRUPT_NEXUS DT_PATH(interrupt_map_test, nexus) + #define ZEPHYR_USER DT_PATH(zephyr_user) #define TA_HAS_COMPAT(compat) DT_NODE_HAS_COMPAT(TEST_ARRAYS, compat) @@ -3832,4 +3835,87 @@ ZTEST(devicetree_api, test_interrupt_controller) zassert_true(DT_SAME_NODE(DT_INST_IRQ_INTC(0), TEST_INTC), ""); } +#define INTERRUPT_NEXUS_CHECK_0(n, p, i, ...) \ + zassert_equal(NUM_VA_ARGS(DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 4); \ + zassert_equal(GET_ARG_N(1, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 0); \ + zassert_equal(GET_ARG_N(2, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 0); \ + zassert_equal(GET_ARG_N(3, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 1); \ + zassert_equal(GET_ARG_N(4, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 2); \ + zassert_equal(NUM_VA_ARGS(DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 2); \ + zassert_equal(GET_ARG_N(1, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 3); \ + zassert_equal(GET_ARG_N(2, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 4); \ + zassert_equal(NUM_VA_ARGS(DT_MAP_PARENT_ARG_BY_IDX(n, p, i)), 1); \ + zassert_str_equal(STRINGIFY(DT_MAP_PARENT_ARG_BY_IDX(n, p, i)), \ + "DT_N_S_interrupt_map_test_S_controller_0_0"); + +#define INTERRUPT_NEXUS_CHECK_1(n, p, i, ...) \ + zassert_equal(NUM_VA_ARGS(DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 4); \ + zassert_equal(GET_ARG_N(1, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 0); \ + zassert_equal(GET_ARG_N(2, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 0); \ + zassert_equal(GET_ARG_N(3, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 5); \ + zassert_equal(GET_ARG_N(4, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 6); \ + zassert_equal(NUM_VA_ARGS(DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 4); \ + zassert_equal(GET_ARG_N(1, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 7); \ + zassert_equal(GET_ARG_N(2, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 8); \ + zassert_equal(GET_ARG_N(3, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 9); \ + zassert_equal(GET_ARG_N(4, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 0); \ + zassert_equal(NUM_VA_ARGS(DT_MAP_PARENT_ARG_BY_IDX(n, p, i)), 1); \ + zassert_str_equal(STRINGIFY(DT_MAP_PARENT_ARG_BY_IDX(n, p, i)), \ + "DT_N_S_interrupt_map_test_S_controller_1_1"); + +#define INTERRUPT_NEXUS_CHECK_2(n, p, i, ...) \ + zassert_equal(NUM_VA_ARGS(DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 4); \ + zassert_equal(GET_ARG_N(1, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 0); \ + zassert_equal(GET_ARG_N(2, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 1); \ + zassert_equal(GET_ARG_N(3, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 9); \ + zassert_equal(GET_ARG_N(4, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 8); \ + zassert_equal(NUM_VA_ARGS(DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 2); \ + zassert_equal(GET_ARG_N(1, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 7); \ + zassert_equal(GET_ARG_N(2, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 6); \ + zassert_equal(NUM_VA_ARGS(DT_MAP_PARENT_ARG_BY_IDX(n, p, i)), 1); \ + zassert_str_equal(STRINGIFY(DT_MAP_PARENT_ARG_BY_IDX(n, p, i)), \ + "DT_N_S_interrupt_map_test_S_controller_0_0"); + +#define INTERRUPT_NEXUS_CHECK_3(n, p, i, ...) \ + zassert_equal(NUM_VA_ARGS(DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 4); \ + zassert_equal(GET_ARG_N(1, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 0); \ + zassert_equal(GET_ARG_N(2, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 1); \ + zassert_equal(GET_ARG_N(3, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 5); \ + zassert_equal(GET_ARG_N(4, DT_MAP_CHILD_SPECIFIER_ARGS_BY_IDX(n, p, i)), 4); \ + zassert_equal(NUM_VA_ARGS(DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 4); \ + zassert_equal(GET_ARG_N(1, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 3); \ + zassert_equal(GET_ARG_N(2, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 2); \ + zassert_equal(GET_ARG_N(3, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 1); \ + zassert_equal(GET_ARG_N(4, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)), 0); \ + zassert_str_equal(STRINGIFY(DT_MAP_PARENT_ARG_BY_IDX(n, p, i)), \ + "DT_N_S_interrupt_map_test_S_controller_1_1"); + +#define INTERRUPT_NEXUS_CHECK(...) \ + UTIL_CAT(INTERRUPT_NEXUS_CHECK_, GET_ARG_N(3, __VA_ARGS__))(__VA_ARGS__) + +ZTEST(devicetree_api, test_map) +{ + zassert_equal(DT_PROP_LEN(TEST_GPIO_CONNECTOR, gpio_map), 2); + zassert_equal(DT_PHA_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map, 0, child_specifier_0), 1); + zassert_equal(DT_PHA_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map, 0, child_specifier_1), 2); + zassert_str_equal(STRINGIFY(DT_PHANDLE_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map, 0)), + "DT_N_S_gpio_map_test_S_parent"); + zassert_equal(DT_PHA_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map, 0, parent_specifier_0), 3); + zassert_equal(DT_PHA_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map, 1, child_specifier_0), 4); + zassert_equal(DT_PHA_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map, 1, child_specifier_1), 5); + zassert_str_equal(STRINGIFY(DT_PHANDLE_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map, 1)), + "DT_N_S_gpio_map_test_S_parent"); + zassert_equal(DT_PHA_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map, 1, parent_specifier_0), 6); + + zassert_equal(DT_PROP_LEN(TEST_GPIO_CONNECTOR, gpio_map_mask), 2); + zassert_equal(DT_PROP_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map_mask, 0), 0xffffffff); + zassert_equal(DT_PROP_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map_mask, 1), 0xffffffc0); + zassert_equal(DT_PROP_LEN(TEST_GPIO_CONNECTOR, gpio_map_pass_thru), 2); + zassert_equal(DT_PROP_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map_pass_thru, 0), 0x0); + zassert_equal(DT_PROP_BY_IDX(TEST_GPIO_CONNECTOR, gpio_map_pass_thru, 1), 0x3f); + + DT_FOREACH_PROP_ELEM_VARGS(TEST_INTERRUPT_NEXUS, interrupt_map, INTERRUPT_NEXUS_CHECK, + 9999); +} + ZTEST_SUITE(devicetree_api, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/lib/devicetree/api/testcase.yaml b/tests/lib/devicetree/api/testcase.yaml index ded886833ac87..2759a047ab7d6 100644 --- a/tests/lib/devicetree/api/testcase.yaml +++ b/tests/lib/devicetree/api/testcase.yaml @@ -5,6 +5,7 @@ tests: # will mostly likely be the fastest. platform_allow: - native_sim + - native_sim/native/64 - qemu_x86 - qemu_x86_64 - qemu_cortex_m3 diff --git a/tests/unit/util/main.c b/tests/unit/util/main.c index 6da45befcabaf..d976b8a8e8d2e 100644 --- a/tests/unit/util/main.c +++ b/tests/unit/util/main.c @@ -527,6 +527,28 @@ ZTEST(util, test_GET_ARGS_LESS_N) { zassert_equal(c[0], 3); } +ZTEST(util, test_GET_ARGS_FIRST_N) +{ + uint8_t a[] = {GET_ARGS_FIRST_N(0, 1, 2, 3)}; + uint8_t b[] = {GET_ARGS_FIRST_N(1, 1, 2, 3)}; + uint8_t c[] = {GET_ARGS_FIRST_N(2, 1, 2, 3)}; + uint8_t d[] = {GET_ARGS_FIRST_N(3, 1, 2, 3)}; + + zassert_equal(sizeof(a), 0); + + zassert_equal(sizeof(b), 1); + zassert_equal(b[0], 1); + + zassert_equal(sizeof(c), 2); + zassert_equal(c[0], 1); + zassert_equal(c[1], 2); + + zassert_equal(sizeof(d), 3); + zassert_equal(d[0], 1); + zassert_equal(d[1], 2); + zassert_equal(d[2], 3); +} + ZTEST(util, test_mixing_GET_ARG_and_FOR_EACH) { #undef TEST_MACRO #define TEST_MACRO(x) x, diff --git a/west.yml b/west.yml index 7b89aeaf6f871..14921bd7f19c6 100644 --- a/west.yml +++ b/west.yml @@ -30,6 +30,10 @@ manifest: # Please add items below based on alphabetical order # zephyr-keep-sorted-start re(^\s+\- name:) projects: + - name: Arduino-Core-Zephyr + path: modules/lib/Arduino-Zephyr-API + revision: global_pin_number_api + url: https://github.com/soburi/gsoc-2022-arduino-core - name: acpica revision: 8d24867bc9c9d81c81eeac59391cda59333affd4 path: modules/lib/acpica