drivers: w1: add vnd,w1 driver for ci testing

This commit adds the vnd,w1 dummy host driver used for ci builds of
1-wire devices.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
This commit is contained in:
Thomas Stranger 2022-03-06 12:19:09 +01:00 committed by Carles Cufí
parent bb4f7b5a31
commit ae8543269a
5 changed files with 98 additions and 1 deletions

View file

@ -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)

View file

@ -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

8
drivers/w1/Kconfig.test Normal file
View file

@ -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))

79
drivers/w1/w1_test.c Normal file
View file

@ -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 <zephyr/drivers/w1.h>
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)

View file

@ -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]