diff --git a/drivers/w1/CMakeLists.txt b/drivers/w1/CMakeLists.txt index 9abf95acfd7..9556acd809c 100644 --- a/drivers/w1/CMakeLists.txt +++ b/drivers/w1/CMakeLists.txt @@ -10,8 +10,8 @@ zephyr_library_sources(w1_common.c) zephyr_library_sources_ifdef(CONFIG_W1_DS2484 w1_ds2484.c) zephyr_library_sources_ifdef(CONFIG_W1_DS2485 w1_ds2485.c) zephyr_library_sources_ifdef(CONFIG_W1_DS2477_85_COMMON w1_ds2477_85_common.c) -zephyr_library_sources_ifdef(CONFIG_W1_TEST w1_test.c) -zephyr_library_sources_ifdef(CONFIG_W1_ZEPHYR_SERIAL w1_zephyr_serial.c) +zephyr_library_sources_ifdef(CONFIG_W1_TEST w1_test.c) +zephyr_library_sources_ifdef(CONFIG_W1_ZEPHYR_SERIAL w1_zephyr_serial.c) # network functions: if(CONFIG_W1_NET) diff --git a/drivers/w1/w1_ds248x.h b/drivers/w1/w1_ds2482_84_common.h similarity index 65% rename from drivers/w1/w1_ds248x.h rename to drivers/w1/w1_ds2482_84_common.h index 860bf45aee8..bd8f8691a47 100644 --- a/drivers/w1/w1_ds248x.h +++ b/drivers/w1/w1_ds2482_84_common.h @@ -1,11 +1,11 @@ /* - * Copyright (c) 2022 Caspar Friedrich + * Copyright (c) 2023 Caspar Friedrich * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef ZEPHYR_DRIVERS_W1_W1_DS248X_H_ -#define ZEPHYR_DRIVERS_W1_W1_DS248X_H_ +#ifndef ZEPHYR_DRIVERS_W1_W1_DS2482_84_H_ +#define ZEPHYR_DRIVERS_W1_W1_DS2482_84_H_ #include #include @@ -75,14 +75,14 @@ /* * Channel Selection Codes (read back values), DS2482-800 only */ -#define CHSL_IO0_RB 0xb8 -#define CHSL_IO1_RB 0xb1 -#define CHSL_IO2_RB 0xaa -#define CHSL_IO3_RB 0xa3 -#define CHSL_IO4_RB 0x9c -#define CHSL_IO5_RB 0x95 -#define CHSL_IO6_RB 0x8e -#define CHSL_IO7_RB 0x87 +#define CHSL_RB_IO0 0xb8 +#define CHSL_RB_IO1 0xb1 +#define CHSL_RB_IO2 0xaa +#define CHSL_RB_IO3 0xa3 +#define CHSL_RB_IO4 0x9c +#define CHSL_RB_IO5 0x95 +#define CHSL_RB_IO6 0x8e +#define CHSL_RB_IO7 0x87 /* * Port Configuration Register, DS2484 only @@ -102,7 +102,7 @@ #define BIT_CLR_msk 0 #define BIT_SET_msk BIT(7) -static inline int ds248x_write(const struct i2c_dt_spec *spec, uint8_t cmd, uint8_t *data) +static inline int ds2482_84_write(const struct i2c_dt_spec *spec, uint8_t cmd, const uint8_t *data) { int ret; @@ -116,7 +116,7 @@ static inline int ds248x_write(const struct i2c_dt_spec *spec, uint8_t cmd, uint return 0; } -static inline int ds248x_read(const struct i2c_dt_spec *spec, uint8_t rp, uint8_t *reg) +static inline int ds2482_84_read(const struct i2c_dt_spec *spec, uint8_t rp, uint8_t *reg) { int ret; @@ -135,7 +135,7 @@ static inline int ds248x_read(const struct i2c_dt_spec *spec, uint8_t rp, uint8_ case REG_DATA: __fallthrough; case REG_STATUS: - ret = ds248x_write(spec, CMD_SRP, &rp); + ret = ds2482_84_write(spec, CMD_SRP, &rp); if (ret < 0) { return ret; } @@ -152,19 +152,19 @@ static inline int ds248x_read(const struct i2c_dt_spec *spec, uint8_t rp, uint8_ return 0; } -static inline int ds248x_reset_bus(const struct i2c_dt_spec *spec) +static inline int ds2482_84_reset_bus(const struct i2c_dt_spec *spec) { int ret; uint8_t reg; - ret = ds248x_write(spec, CMD_1WRS, NULL); + ret = ds2482_84_write(spec, CMD_1WRS, NULL); if (ret < 0) { return ret; } do { - ret = ds248x_read(spec, REG_NONE, ®); + ret = ds2482_84_read(spec, REG_NONE, ®); if (ret < 0) { return ret; } @@ -173,19 +173,19 @@ static inline int ds248x_reset_bus(const struct i2c_dt_spec *spec) return reg & STATUS_PPD_msk ? 1 : 0; } -static inline int ds248x_reset_device(const struct i2c_dt_spec *spec) +static inline int ds2482_84_reset_device(const struct i2c_dt_spec *spec) { int ret; uint8_t reg; - ret = ds248x_write(spec, CMD_DRST, NULL); + ret = ds2482_84_write(spec, CMD_DRST, NULL); if (ret < 0) { return ret; } do { - ret = ds248x_read(spec, REG_NONE, ®); + ret = ds2482_84_read(spec, REG_NONE, ®); if (ret < 0) { return ret; } @@ -194,60 +194,56 @@ static inline int ds248x_reset_device(const struct i2c_dt_spec *spec) return 0; } -static int ds248x_single_bit(const struct i2c_dt_spec *spec, uint8_t bit_msk) +static inline int ds2482_84_single_bit(const struct i2c_dt_spec *spec, uint8_t bit_msk) { int ret; uint8_t reg; - ret = ds248x_write(spec, CMD_1WSB, &bit_msk); + ret = ds2482_84_write(spec, CMD_1WSB, &bit_msk); if (ret < 0) { return ret; } do { - ret = ds248x_read(spec, REG_NONE, ®); + ret = ds2482_84_read(spec, REG_NONE, ®); if (ret < 0) { return ret; } } while (reg & STATUS_1WB_msk); - return reg & STATUS_SBR_msk; + return reg & STATUS_SBR_msk ? 1 : 0; } -static inline int ds248x_read_bit(const struct i2c_dt_spec *spec) +static inline int ds2482_84_read_bit(const struct i2c_dt_spec *spec) { - int ret = ds248x_single_bit(spec, BIT_SET_msk); - - return ret > 1 ? 1 : ret; + return ds2482_84_single_bit(spec, BIT_SET_msk); } -static inline int ds248x_write_bit(const struct i2c_dt_spec *spec, bool bit) +static inline int ds2482_84_write_bit(const struct i2c_dt_spec *spec, bool bit) { - int ret = ds248x_single_bit(spec, bit ? BIT_SET_msk : BIT_CLR_msk); - - return ret > 0 ? 0 : ret; + return ds2482_84_single_bit(spec, bit ? BIT_SET_msk : BIT_CLR_msk); } -static inline int ds248x_read_byte(const struct i2c_dt_spec *spec) +static inline int ds2482_84_read_byte(const struct i2c_dt_spec *spec) { int ret; uint8_t reg; - ret = ds248x_write(spec, CMD_1WRB, NULL); + ret = ds2482_84_write(spec, CMD_1WRB, NULL); if (ret < 0) { return ret; } do { - ret = ds248x_read(spec, REG_NONE, ®); + ret = ds2482_84_read(spec, REG_NONE, ®); if (ret < 0) { return ret; } } while (reg & STATUS_1WB_msk); - ret = ds248x_read(spec, REG_DATA, ®); + ret = ds2482_84_read(spec, REG_DATA, ®); if (ret < 0) { return ret; } @@ -255,19 +251,19 @@ static inline int ds248x_read_byte(const struct i2c_dt_spec *spec) return reg; } -static inline int ds248x_write_byte(const struct i2c_dt_spec *spec, uint8_t byte) +static inline int ds2482_84_write_byte(const struct i2c_dt_spec *spec, uint8_t byte) { int ret; uint8_t reg; - ret = ds248x_write(spec, CMD_1WWB, &byte); + ret = ds2482_84_write(spec, CMD_1WWB, &byte); if (ret < 0) { return ret; } do { - ret = ds248x_read(spec, REG_NONE, ®); + ret = ds2482_84_read(spec, REG_NONE, ®); if (ret < 0) { return ret; } @@ -276,7 +272,7 @@ static inline int ds248x_write_byte(const struct i2c_dt_spec *spec, uint8_t byte return 0; } -static inline int ds248x_write_config(const struct i2c_dt_spec *spec, uint8_t cfg) +static inline int ds2482_84_write_config(const struct i2c_dt_spec *spec, uint8_t cfg) { int ret; @@ -286,12 +282,12 @@ static inline int ds248x_write_config(const struct i2c_dt_spec *spec, uint8_t cf return -EINVAL; } - ret = ds248x_write(spec, CMD_WCFG, ®); + ret = ds2482_84_write(spec, CMD_WCFG, ®); if (ret < 0) { return ret; } - ret = ds248x_read(spec, REG_NONE, ®); + ret = ds2482_84_read(spec, REG_NONE, ®); if (ret < 0) { return ret; } @@ -299,4 +295,4 @@ static inline int ds248x_write_config(const struct i2c_dt_spec *spec, uint8_t cf return (reg == cfg) ? 0 : -EIO; } -#endif /* ZEPHYR_DRIVERS_W1_W1_DS248X_H_ */ +#endif /* ZEPHYR_DRIVERS_W1_W1_DS2482_84_H_ */ diff --git a/drivers/w1/w1_ds2484.c b/drivers/w1/w1_ds2484.c index 6065d22cc64..97460a0e621 100644 --- a/drivers/w1/w1_ds2484.c +++ b/drivers/w1/w1_ds2484.c @@ -4,15 +4,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "w1_ds248x.h" +#include "w1_ds2482_84_common.h" #include #include #include #include +#include #include #include -#include #define DT_DRV_COMPAT maxim_ds2484 @@ -34,35 +34,35 @@ static int ds2484_reset_bus(const struct device *dev) { const struct ds2484_config *config = dev->config; - return ds248x_reset_bus(&config->i2c_spec); + return ds2482_84_reset_bus(&config->i2c_spec); } static int ds2484_read_bit(const struct device *dev) { const struct ds2484_config *config = dev->config; - return ds248x_read_bit(&config->i2c_spec); + return ds2482_84_read_bit(&config->i2c_spec); } static int ds2484_write_bit(const struct device *dev, bool bit) { const struct ds2484_config *config = dev->config; - return ds248x_write_bit(&config->i2c_spec, bit); + return ds2482_84_write_bit(&config->i2c_spec, bit); } static int ds2484_read_byte(const struct device *dev) { const struct ds2484_config *config = dev->config; - return ds248x_read_byte(&config->i2c_spec); + return ds2482_84_read_byte(&config->i2c_spec); } static int ds2484_write_byte(const struct device *dev, uint8_t byte) { const struct ds2484_config *config = dev->config; - return ds248x_write_byte(&config->i2c_spec, byte); + return ds2482_84_write_byte(&config->i2c_spec, byte); } static int ds2484_configure(const struct device *dev, enum w1_settings_type type, uint32_t value) @@ -81,7 +81,7 @@ static int ds2484_configure(const struct device *dev, enum w1_settings_type type return -EINVAL; } - return ds248x_write_config(&config->i2c_spec, data->reg_device_config); + return ds2482_84_write_config(&config->i2c_spec, data->reg_device_config); } #ifdef CONFIG_PM_DEVICE @@ -132,7 +132,7 @@ static int ds2484_init(const struct device *dev) return -ENODEV; } - ret = ds248x_reset_device(&config->i2c_spec); + ret = ds2482_84_reset_device(&config->i2c_spec); if (ret < 0) { LOG_ERR("Device reset failed: %d", ret); return ret; @@ -140,7 +140,7 @@ static int ds2484_init(const struct device *dev) WRITE_BIT(data->reg_device_config, DEVICE_APU_pos, config->apu); - ret = ds248x_write_config(&config->i2c_spec, data->reg_device_config); + ret = ds2482_84_write_config(&config->i2c_spec, data->reg_device_config); if (ret < 0) { LOG_ERR("Device config update failed: %d", ret); return ret;