Make I2C and SPI drivers for nRF SoCs no longer dependent on Kconfig options that enable instances (i.e. I2C_x and SPI_x). Now these drivers enable hardware instances when corresponding nodes in devicetree are enabled (have status "okay"). For I2C, SPI, and UART drivers, instead of using Kconfig dependencies to prevent enabling of hardware instances that cannot be used together (e.g. SPIM1 and TWIM1), a file that signals invalid configurations with build assertions is added to compilation. Also dependencies on HAS_HW_NRF_* options are removed from Kconfigs of I2C, SPI, and UART drivers, as for hidden options that activate proper type of driver such dependencies are not actually helpful. Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
48 lines
1.6 KiB
C
48 lines
1.6 KiB
C
/*
|
|
* Copyright (c) 2020 Nordic Semiconductor ASA
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <kernel.h>
|
|
|
|
#define I2C_ENABLED(idx) (IS_ENABLED(CONFIG_I2C) && \
|
|
DT_HAS_NODE(DT_NODELABEL(i2c##idx)))
|
|
|
|
#define SPI_ENABLED(idx) (IS_ENABLED(CONFIG_SPI) && \
|
|
DT_HAS_NODE(DT_NODELABEL(spi##idx)))
|
|
|
|
#define UART_ENABLED(idx) (IS_ENABLED(CONFIG_SERIAL) && \
|
|
(IS_ENABLED(CONFIG_SOC_SERIES_NRF53X) || \
|
|
IS_ENABLED(CONFIG_SOC_SERIES_NRF91X)) && \
|
|
DT_HAS_NODE(DT_NODELABEL(uart##idx)))
|
|
|
|
/*
|
|
* In most Nordic SoCs, SPI and TWI peripherals with the same instance number
|
|
* share certain resources and therefore cannot be used at the same time (in
|
|
* nRF53 and nRF91 Series this limitation concerns UART peripherals as well).
|
|
* In nRF52810 though, there are only single instances of these peripherals
|
|
* and they are arranged in a different way, so this limitation does not apply.
|
|
*
|
|
* The build assertions below check if conflicting peripheral instances are not
|
|
* enabled simultaneously.
|
|
*/
|
|
|
|
#define CHECK(idx) \
|
|
!(I2C_ENABLED(idx) && SPI_ENABLED(idx)) && \
|
|
!(I2C_ENABLED(idx) && UART_ENABLED(idx)) && \
|
|
!(SPI_ENABLED(idx) && UART_ENABLED(idx))
|
|
|
|
#define MSG(idx) \
|
|
"Only one of the following peripherals can be enabled: " \
|
|
"SPI"#idx", SPIM"#idx", SPIS"#idx", TWI"#idx", TWIM"#idx", TWIS"#idx \
|
|
IF_ENABLED(CONFIG_SOC_SERIES_NRF53X, (", UARTE"#idx)) \
|
|
IF_ENABLED(CONFIG_SOC_SERIES_NRF91X, (", UARTE"#idx)) \
|
|
". Check nodes with status \"okay\" in zephyr.dts."
|
|
|
|
#if !IS_ENABLED(CONFIG_SOC_NRF52810)
|
|
BUILD_ASSERT(CHECK(0), MSG(0));
|
|
#endif
|
|
BUILD_ASSERT(CHECK(1), MSG(1));
|
|
BUILD_ASSERT(CHECK(2), MSG(2));
|
|
BUILD_ASSERT(CHECK(3), MSG(3));
|