drivers: ds248x: Fix naming

ds248x no longer applies to all drivers. Therefore the naming indicates
compatibility with DS2482 and DS2484 drivers.

Also
- Fix some code formatting

Signed-off-by: Caspar Friedrich <c.s.w.friedrich@gmail.com>
This commit is contained in:
Caspar Friedrich 2022-10-07 23:33:23 +02:00 committed by Carles Cufí
parent 51e2d62297
commit 8b621e3bde
3 changed files with 51 additions and 55 deletions

View File

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

View File

@ -1,11 +1,11 @@
/*
* Copyright (c) 2022 Caspar Friedrich <c.s.w.friedrich@gmail.com>
* Copyright (c) 2023 Caspar Friedrich <c.s.w.friedrich@gmail.com>
*
* 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 <zephyr/drivers/i2c.h>
#include <zephyr/kernel.h>
@ -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, &reg);
ret = ds2482_84_read(spec, REG_NONE, &reg);
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, &reg);
ret = ds2482_84_read(spec, REG_NONE, &reg);
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, &reg);
ret = ds2482_84_read(spec, REG_NONE, &reg);
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, &reg);
ret = ds2482_84_read(spec, REG_NONE, &reg);
if (ret < 0) {
return ret;
}
} while (reg & STATUS_1WB_msk);
ret = ds248x_read(spec, REG_DATA, &reg);
ret = ds2482_84_read(spec, REG_DATA, &reg);
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, &reg);
ret = ds2482_84_read(spec, REG_NONE, &reg);
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, &reg);
ret = ds2482_84_write(spec, CMD_WCFG, &reg);
if (ret < 0) {
return ret;
}
ret = ds248x_read(spec, REG_NONE, &reg);
ret = ds2482_84_read(spec, REG_NONE, &reg);
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_ */

View File

@ -4,15 +4,15 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "w1_ds248x.h"
#include "w1_ds2482_84_common.h"
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/drivers/w1.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/pm/device.h>
#include <zephyr/kernel.h>
#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;