drivers: sensor: wsen_pdus_25131308XXXXX: add sensor driver

Add wsen_pdus_25131308XXXXX driver with
the corrected name and compatibility with
the hal update as well as added new features..

Signed-off-by: Wajdi ELMuhtadi <wajdi.elmuhtadi@we-online.com>
This commit is contained in:
Wajdi ELMuhtadi 2023-09-04 09:34:22 +02:00 committed by Benjamin Cabé
parent 5b09caa122
commit 01d9861d71
10 changed files with 267 additions and 0 deletions

View File

@ -257,6 +257,20 @@ SDHC
Sensors
=======
* The :dtcompatible:`we,wsen-pdus` driver has been renamed to
:dtcompatible:`we,wsen-pdus-25131308XXXXX`.
The Device Tree can be configured as follows:
.. code-block:: devicetree
&i2c0 {
pdus:pdus-25131308XXXXX@78 {
compatible = "we,wsen-pdus-25131308XXXXX";
reg = < 0x78 >;
sensor-type = < 4 >;
};
};
Serial
======

View File

@ -269,6 +269,11 @@ Drivers and Sensors
status = "okay";
};
* WE
* Replaced outdated :dtcompatible:`we,wsen-pdus` differential pressure sensor driver
and renamed it to :dtcompatible:`we,wsen-pdus-25131308XXXXX`.
* Serial
* SPI

View File

@ -4,4 +4,5 @@
# zephyr-keep-sorted-start
add_subdirectory_ifdef(CONFIG_WSEN_HIDS_2525020210002 wsen_hids_2525020210002)
add_subdirectory_ifdef(CONFIG_WSEN_PDUS_25131308XXXXX wsen_pdus_25131308XXXXX)
# zephyr-keep-sorted-stop

View File

@ -4,4 +4,5 @@
# zephyr-keep-sorted-start
source "drivers/sensor/wsen/wsen_hids_2525020210002/Kconfig"
source "drivers/sensor/wsen/wsen_pdus_25131308XXXXX/Kconfig"
# zephyr-keep-sorted-stop

View File

@ -0,0 +1,6 @@
# Copyright (c) 2024 Würth Elektronik eiSos GmbH & Co. KG
# SPDX-License-Identifier: Apache-2.0
zephyr_library()
zephyr_library_sources(wsen_pdus_25131308XXXXX.c)

View File

@ -0,0 +1,11 @@
# Copyright (c) 2024 Würth Elektronik eiSos GmbH & Co. KG
# SPDX-License-Identifier: Apache-2.0
config WSEN_PDUS_25131308XXXXX
bool "WSEN-PDUS-25131308XXXXX differential pressure sensor"
default y
depends on DT_HAS_WE_WSEN_PDUS_25131308XXXXX_ENABLED
select I2C
select HAS_WESENSORS
help
Enable driver for the WSEN-PDUS-25131308XXXXX I2C-based differential pressure sensor.

View File

@ -0,0 +1,157 @@
/*
* Copyright (c) 2024 Würth Elektronik eiSos GmbH & Co. KG
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT we_wsen_pdus_25131308xxxxx
#include <stdlib.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/logging/log.h>
#include "wsen_pdus_25131308XXXXX.h"
LOG_MODULE_REGISTER(WSEN_PDUS_25131308XXXXX, CONFIG_SENSOR_LOG_LEVEL);
static int pdus_25131308XXXXX_sample_fetch(const struct device *dev, enum sensor_channel chan)
{
struct pdus_25131308XXXXX_data *data = dev->data;
uint16_t pressure_dummy;
switch (chan) {
case SENSOR_CHAN_ALL: {
if (PDUS_getRawPressureAndTemperature(&data->sensor_interface, &data->pressure,
&data->temperature) != WE_SUCCESS) {
LOG_ERR("Failed to fetch data sample");
return -EIO;
}
break;
}
case SENSOR_CHAN_AMBIENT_TEMP: {
if (PDUS_getRawPressureAndTemperature(&data->sensor_interface, &pressure_dummy,
&data->temperature) != WE_SUCCESS) {
LOG_ERR("Failed to fetch data sample");
return -EIO;
}
break;
}
case SENSOR_CHAN_PRESS: {
if (PDUS_getRawPressure(&data->sensor_interface, &data->pressure) != WE_SUCCESS) {
LOG_ERR("Failed to fetch data sample");
return -EIO;
}
break;
}
default:
LOG_ERR("Fetching is not supported on channel %d.", chan);
return -ENOTSUP;
}
return 0;
}
static int pdus_25131308XXXXX_channel_get(const struct device *dev, enum sensor_channel chan,
struct sensor_value *value)
{
struct pdus_25131308XXXXX_data *data = dev->data;
const struct pdus_25131308XXXXX_config *config = dev->config;
switch (chan) {
case SENSOR_CHAN_AMBIENT_TEMP: {
int32_t temperature_mega = ((int32_t)(data->temperature - T_MIN_VAL_PDUS)) * 4272;
value->val1 = temperature_mega / 1000000;
value->val2 = temperature_mega % 1000000;
break;
}
case SENSOR_CHAN_PRESS: {
int32_t pressure_temp = ((int32_t)(data->pressure - P_MIN_VAL_PDUS));
/*
* these values are conversion factors based on the sensor type defined in the user
* manual of the respective sensor
*/
switch (config->sensor_type) {
case PDUS_pdus0:
value->val1 = ((pressure_temp * 763) - 10000000) / 100000000;
value->val2 = (((pressure_temp * 763) - 10000000) % 100000000) / 100;
break;
case PDUS_pdus1:
value->val1 = ((pressure_temp * 763) - 10000000) / 10000000;
value->val2 = (((pressure_temp * 763) - 10000000) % 10000000) / 10;
break;
case PDUS_pdus2:
value->val1 = ((pressure_temp * 763) - 10000000) / 1000000;
value->val2 = ((pressure_temp * 763) - 10000000) % 1000000;
break;
case PDUS_pdus3:
value->val1 = (pressure_temp * 3815) / 1000000;
value->val2 = (pressure_temp * 3815) % 1000000;
break;
case PDUS_pdus4:
value->val1 = ((pressure_temp * 4196) - 10000000) / 100000;
value->val2 =
((pressure_temp * 4196) - 10000000) % 100000 * (1000000 / 100000);
break;
case PDUS_pdus5:
value->val1 = (pressure_temp * 5722) / 100000;
value->val2 = (pressure_temp * 5722) % 100000 * (1000000 / 100000);
break;
default:
LOG_ERR("Sensor type doesn't exist");
return -ENOTSUP;
}
break;
}
default:
LOG_ERR("Channel not supported %d", chan);
return -ENOTSUP;
}
return 0;
}
static DEVICE_API(sensor, pdus_25131308XXXXX_driver_api) = {
.sample_fetch = pdus_25131308XXXXX_sample_fetch,
.channel_get = pdus_25131308XXXXX_channel_get
};
static int pdus_25131308XXXXX_init(const struct device *dev)
{
struct pdus_25131308XXXXX_data *data = dev->data;
const struct pdus_25131308XXXXX_config *config = dev->config;
/* Initialize WE sensor interface */
PDUS_getDefaultInterface(&data->sensor_interface);
data->sensor_interface.interfaceType = WE_i2c;
if (!i2c_is_ready_dt(&config->bus_cfg.i2c)) {
LOG_ERR("I2C bus device not ready");
return -ENODEV;
}
data->sensor_interface.handle = (void *)&config->bus_cfg.i2c;
return 0;
}
/*
* Main instantiation macro.
*/
#define PDUS_25131308XXXXX_DEFINE(inst) \
static struct pdus_25131308XXXXX_data pdus_25131308XXXXX_data_##inst; \
static const struct pdus_25131308XXXXX_config pdus_25131308XXXXX_config_##inst = { \
.bus_cfg = \
{ \
.i2c = I2C_DT_SPEC_INST_GET(inst), \
}, \
.sensor_type = (PDUS_SensorType_t)DT_INST_ENUM_IDX(inst, sensor_type)}; \
SENSOR_DEVICE_DT_INST_DEFINE(inst, pdus_25131308XXXXX_init, NULL, \
&pdus_25131308XXXXX_data_##inst, \
&pdus_25131308XXXXX_config_##inst, POST_KERNEL, \
CONFIG_SENSOR_INIT_PRIORITY, &pdus_25131308XXXXX_driver_api);
DT_INST_FOREACH_STATUS_OKAY(PDUS_25131308XXXXX_DEFINE)

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 Würth Elektronik eiSos GmbH & Co. KG
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_DRIVERS_SENSOR_WSEN_PDUS_25131308XXXXX_WSEN_PDUS_25131308XXXXX_H_
#define ZEPHYR_DRIVERS_SENSOR_WSEN_PDUS_25131308XXXXX_WSEN_PDUS_25131308XXXXX_H_
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/sensor.h>
#include <weplatform.h>
#include "WSEN_PDUS_25131308XXX01_hal.h"
#include <zephyr/drivers/i2c.h>
struct pdus_25131308XXXXX_data {
/* WE sensor interface configuration */
WE_sensorInterface_t sensor_interface;
/* Last pressure sample */
uint16_t pressure;
/* Last temperature sample */
uint16_t temperature;
};
struct pdus_25131308XXXXX_config {
union {
const struct i2c_dt_spec i2c;
} bus_cfg;
PDUS_SensorType_t sensor_type;
};
#endif /* ZEPHYR_DRIVERS_SENSOR_WSEN_PDUS_25131308XXXXX_WSEN_PDUS_25131308XXXXX_H_ */

View File

@ -0,0 +1,29 @@
# Copyright (c) 2024 Würth Elektronik eiSos GmbH & Co. KG
# SPDX-License-Identifier: Apache-2.0
description: |
Würth Elektronik WSEN-PDUS-25131308XXXXX differential pressure sensor
compatible: "we,wsen-pdus-25131308XXXXX"
include: [sensor-device.yaml, i2c-device.yaml]
properties:
sensor-type:
type: int
required: true
enum:
- 0
- 1
- 2
- 3
- 4
- 5
description: |
PDUS sensor product variant (pressure measurement range).
0 - order code 2513130810001, range = -0.1 to +0.1 kPa
1 - order code 2513130810101 (5V VCC) + 2513130810102 (3.3V VCC), range = -1 to +1 kPa
2 - order code 2513130810201, range = -10 to +10 kPa
3 - order code 2513130810301, range = 0 to 100 kPa
4 - order code 2513130810401 (5V VCC) + 2513130810402 (3.3V VCC), range = -100 to +1000 kPa
5 - order code 2513130815401, range = 0 to +1500 kPa

View File

@ -677,6 +677,12 @@ test_i2c_s11059: s11059@64 {
integration-time = <546000>;
};
test_i2c_wsen_pdus_25131308XXXXX: wsen_pdus_25131308XXXXX@65 {
compatible = "we,wsen-pdus-25131308XXXXX";
reg = <0x65>;
sensor-type = < 4 >;
};
test_i2c_veml7700: veml7700@66 {
compatible = "vishay,veml7700";
reg = <0x66>;