1 /* 2 * Copyright (c) 2021 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * nRF SoC specific helpers for pinctrl driver 10 */ 11 12 #ifndef ZEPHYR_SOC_ARM_NORDIC_NRF_COMMON_PINCTRL_SOC_H_ 13 #define ZEPHYR_SOC_ARM_NORDIC_NRF_COMMON_PINCTRL_SOC_H_ 14 15 #include <zephyr/devicetree.h> 16 #include <zephyr/dt-bindings/pinctrl/nrf-pinctrl.h> 17 #include <zephyr/types.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /** @cond INTERNAL_HIDDEN */ 24 25 /** Type for nRF pin. */ 26 typedef uint32_t pinctrl_soc_pin_t; 27 28 /** 29 * @brief Utility macro to initialize each pin. 30 * 31 * @param node_id Node identifier. 32 * @param prop Property name. 33 * @param idx Property entry index. 34 */ 35 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ 36 (DT_PROP_BY_IDX(node_id, prop, idx) | \ 37 ((NRF_PULL_DOWN * DT_PROP(node_id, bias_pull_down)) << NRF_PULL_POS) |\ 38 ((NRF_PULL_UP * DT_PROP(node_id, bias_pull_up)) << NRF_PULL_POS) | \ 39 (DT_PROP(node_id, nordic_drive_mode) << NRF_DRIVE_POS) | \ 40 ((NRF_LP_ENABLE * DT_PROP(node_id, low_power_enable)) << NRF_LP_POS) |\ 41 (DT_PROP(node_id, nordic_invert) << NRF_INVERT_POS) \ 42 ), 43 44 /** 45 * @brief Utility macro to initialize state pins contained in a given property. 46 * 47 * @param node_id Node identifier. 48 * @param prop Property name describing state pins. 49 */ 50 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ 51 {DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), \ 52 DT_FOREACH_PROP_ELEM, psels, \ 53 Z_PINCTRL_STATE_PIN_INIT)} 54 55 /** 56 * @brief Utility macro to obtain pin function. 57 * 58 * @param pincfg Pin configuration bit field. 59 */ 60 #define NRF_GET_FUN(pincfg) (((pincfg) >> NRF_FUN_POS) & NRF_FUN_MSK) 61 62 /** 63 * @brief Utility macro to obtain pin inversion flag. 64 * 65 * @param pincfg Pin configuration bit field. 66 */ 67 #define NRF_GET_INVERT(pincfg) (((pincfg) >> NRF_INVERT_POS) & NRF_INVERT_MSK) 68 69 /** 70 * @brief Utility macro to obtain pin low power flag. 71 * 72 * @param pincfg Pin configuration bit field. 73 */ 74 #define NRF_GET_LP(pincfg) (((pincfg) >> NRF_LP_POS) & NRF_LP_MSK) 75 76 /** 77 * @brief Utility macro to obtain pin drive mode. 78 * 79 * @param pincfg Pin configuration bit field. 80 */ 81 #define NRF_GET_DRIVE(pincfg) (((pincfg) >> NRF_DRIVE_POS) & NRF_DRIVE_MSK) 82 83 /** 84 * @brief Utility macro to obtain pin pull configuration. 85 * 86 * @param pincfg Pin configuration bit field. 87 */ 88 #define NRF_GET_PULL(pincfg) (((pincfg) >> NRF_PULL_POS) & NRF_PULL_MSK) 89 90 /** 91 * @brief Utility macro to obtain port and pin combination. 92 * 93 * @param pincfg Pin configuration bit field. 94 */ 95 #define NRF_GET_PIN(pincfg) (((pincfg) >> NRF_PIN_POS) & NRF_PIN_MSK) 96 97 /** @endcond */ 98 99 #ifdef __cplusplus 100 } 101 #endif 102 103 #endif /* ZEPHYR_SOC_ARM_NORDIC_NRF_COMMON_PINCTRL_SOC_H_ */ 104