diff --git a/drivers/w1/CMakeLists.txt b/drivers/w1/CMakeLists.txt index 39df95d374..63ed9b7e6a 100644 --- a/drivers/w1/CMakeLists.txt +++ b/drivers/w1/CMakeLists.txt @@ -6,7 +6,7 @@ zephyr_sources_ifdef(CONFIG_USERSPACE w1_handlers.c) zephyr_library_sources(w1_common.c) # drivers implementing link functions (read, write, reset) -# none implemented yet +zephyr_library_sources_ifdef(CONFIG_W1_TEST w1_test.c) # network functions: if(CONFIG_W1_NET) diff --git a/drivers/w1/Kconfig b/drivers/w1/Kconfig index f74a4241ff..a79bdc2524 100644 --- a/drivers/w1/Kconfig +++ b/drivers/w1/Kconfig @@ -22,6 +22,8 @@ config W1_INIT_PRIORITY help 1-Wire device driver initialization priority. +rsource "Kconfig.test" + config W1_NET bool "1-Wire network layer" default y diff --git a/drivers/w1/Kconfig.test b/drivers/w1/Kconfig.test new file mode 100644 index 0000000000..654f4d2dcd --- /dev/null +++ b/drivers/w1/Kconfig.test @@ -0,0 +1,8 @@ +# Copyright (c) 2022, Thomas Stranger +# SPDX-License-Identifier: Apache-2.0 + +DT_COMPAT_VND_W1 := vnd,w1 + +# Hidden option to enable the vnd,w1 1-Wire host driver used in testing. +config W1_TEST + def_bool $(dt_compat_enabled,$(DT_COMPAT_VND_W1)) diff --git a/drivers/w1/w1_test.c b/drivers/w1/w1_test.c new file mode 100644 index 0000000000..2b3b37b6a8 --- /dev/null +++ b/drivers/w1/w1_test.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022 Thomas Stranger + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT vnd_w1 + +/* + * This is not a real 1-Wire driver. It is only used to instantiate struct + * devices for the "vnd,w1" devicetree compatibe used in test code. + */ +#include + +struct w1_vnd_config { + /** w1 master config, common to all drivers */ + struct w1_master_config master_config; +}; + +struct w1_vnd_data { + /** w1 master data, common to all drivers */ + struct w1_master_data master_data; +}; + +static int w1_vnd_reset_bus(const struct device *dev) +{ + return -ENOTSUP; +} + +static int w1_vnd_read_bit(const struct device *dev) +{ + return -ENOTSUP; +} + +static int w1_vnd_write_bit(const struct device *dev, const bool bit) +{ + return -ENOTSUP; +} + +static int w1_vnd_read_byte(const struct device *dev) +{ + return -ENOTSUP; +} + +static int w1_vnd_write_byte(const struct device *dev, const uint8_t byte) +{ + return -ENOTSUP; +} + +static int w1_vnd_configure(const struct device *dev, + enum w1_settings_type type, uint32_t value) +{ + return -ENOTSUP; +} + +static const struct w1_driver_api w1_vnd_api = { + .reset_bus = w1_vnd_reset_bus, + .read_bit = w1_vnd_read_bit, + .write_bit = w1_vnd_write_bit, + .read_byte = w1_vnd_read_byte, + .write_byte = w1_vnd_write_byte, + .configure = w1_vnd_configure, +}; + +static int w1_vnd_init(const struct device *dev) +{ + return 0; +} + +#define W1_VND_INIT(n) \ +static const struct w1_vnd_config w1_vnd_cfg_##inst = { \ + .master_config.slave_count = W1_INST_SLAVE_COUNT(inst) \ +}; \ +static struct w1_vnd_data w1_vnd_data_##inst = {}; \ +DEVICE_DT_INST_DEFINE(n, &w1_vnd_init, NULL, &w1_vnd_data_##inst, \ + &w1_vnd_cfg_##inst, POST_KERNEL, \ + CONFIG_W1_INIT_PRIORITY, &w1_vnd_api); + +DT_INST_FOREACH_STATUS_OKAY(W1_VND_INIT) diff --git a/dts/bindings/test/vnd,w1.yaml b/dts/bindings/test/vnd,w1.yaml new file mode 100644 index 0000000000..8c89384a17 --- /dev/null +++ b/dts/bindings/test/vnd,w1.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2022 Thomas Stranger +# SPDX-License-Identifier: Apache-2.0 + +description: Test W1 bus master node + +compatible: "vnd,w1" + +include: [w1-master.yaml]