drivers: sensor: add diagnostics sensor for BD8LB600FS
Implement a sensor for the output diagnostics of the low side switch BD8LB600FS. Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
This commit is contained in:
parent
31450fcb12
commit
4e4049d939
8 changed files with 160 additions and 0 deletions
|
@ -17,6 +17,7 @@ add_subdirectory_ifdef(CONFIG_AMG88XX amg88xx)
|
|||
add_subdirectory_ifdef(CONFIG_AMS_AS5600 ams_as5600)
|
||||
add_subdirectory_ifdef(CONFIG_AMS_IAQ_CORE ams_iAQcore)
|
||||
add_subdirectory_ifdef(CONFIG_APDS9960 apds9960)
|
||||
add_subdirectory_ifdef(CONFIG_BD8LB600FS_DIAGNOSTICS bd8lb600fs)
|
||||
add_subdirectory_ifdef(CONFIG_BH1750 bh1750)
|
||||
add_subdirectory_ifdef(CONFIG_BMA280 bma280)
|
||||
add_subdirectory_ifdef(CONFIG_BMA4XX bma4xx)
|
||||
|
|
|
@ -97,6 +97,7 @@ source "drivers/sensor/amg88xx/Kconfig"
|
|||
source "drivers/sensor/ams_as5600/Kconfig"
|
||||
source "drivers/sensor/ams_iAQcore/Kconfig"
|
||||
source "drivers/sensor/apds9960/Kconfig"
|
||||
source "drivers/sensor/bd8lb600fs/Kconfig"
|
||||
source "drivers/sensor/bh1750/Kconfig"
|
||||
source "drivers/sensor/bma280/Kconfig"
|
||||
source "drivers/sensor/bma4xx/Kconfig"
|
||||
|
|
5
drivers/sensor/bd8lb600fs/CMakeLists.txt
Normal file
5
drivers/sensor/bd8lb600fs/CMakeLists.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
zephyr_library()
|
||||
|
||||
zephyr_library_sources(bd8lb600fs_diagnostics.c)
|
12
drivers/sensor/bd8lb600fs/Kconfig
Normal file
12
drivers/sensor/bd8lb600fs/Kconfig
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Copyright (c) 2024 SILA Embedded Solutions GmbH
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config BD8LB600FS_DIAGNOSTICS
|
||||
bool "Sensors of BD8LB600FS"
|
||||
default y
|
||||
depends on DT_HAS_ROHM_BD8LB600FS_DIAGNOSTICS_ENABLED
|
||||
select MFD
|
||||
help
|
||||
Enable driver for the open load detection, over current
|
||||
protection and thermal shutdown sensors of the low side
|
||||
switch BD8LB600FS.
|
77
drivers/sensor/bd8lb600fs/bd8lb600fs_diagnostics.c
Normal file
77
drivers/sensor/bd8lb600fs/bd8lb600fs_diagnostics.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2024 SILA Embedded Solutions GmbH
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT rohm_bd8lb600fs_diagnostics
|
||||
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zephyr/drivers/mfd/bd8lb600fs.h>
|
||||
#include <zephyr/drivers/sensor/bd8lb600fs.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include "bd8lb600fs_diagnostics.h"
|
||||
|
||||
LOG_MODULE_REGISTER(BD8LB600FS_DIAGNOSTICS, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
static int bd8lb600fs_diagnostics_sample_fetch(const struct device *dev, enum sensor_channel chan)
|
||||
{
|
||||
const struct bd8lb600fs_diagnostics_config *config = dev->config;
|
||||
struct bd8lb600fs_diagnostics_data *data = dev->data;
|
||||
|
||||
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);
|
||||
return mfd_bd8lb600fs_get_output_diagnostics(config->parent_dev, &data->old,
|
||||
&data->ocp_or_tsd);
|
||||
}
|
||||
|
||||
static int bd8lb600fs_diagnostics_channel_get(const struct device *dev, enum sensor_channel chan,
|
||||
struct sensor_value *val)
|
||||
{
|
||||
struct bd8lb600fs_diagnostics_data *data = dev->data;
|
||||
|
||||
switch (chan) {
|
||||
case SENSOR_CHAN_BD8LB600FS_OPEN_LOAD:
|
||||
val->val1 = data->old;
|
||||
val->val2 = 0;
|
||||
return 0;
|
||||
case SENSOR_CHAN_BD8LB600FS_OVER_CURRENT_OR_THERMAL_SHUTDOWN:
|
||||
val->val1 = data->ocp_or_tsd;
|
||||
val->val2 = 0;
|
||||
return 0;
|
||||
default:
|
||||
LOG_ERR("%s: requesting unsupported channel %i", dev->name, chan);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct sensor_driver_api bd8lb600fs_diagnostics_driver_api = {
|
||||
.sample_fetch = bd8lb600fs_diagnostics_sample_fetch,
|
||||
.channel_get = bd8lb600fs_diagnostics_channel_get,
|
||||
};
|
||||
|
||||
static int bd8lb600fs_diagnostics_init(const struct device *dev)
|
||||
{
|
||||
const struct bd8lb600fs_diagnostics_config *config = dev->config;
|
||||
|
||||
if (!device_is_ready(config->parent_dev)) {
|
||||
LOG_ERR("%s: parent device is not ready", dev->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BD8LB600FS_DIAGNOSTICS_DEFINE(inst) \
|
||||
static struct bd8lb600fs_diagnostics_data bd8lb600fs_diagnostics_data_##inst; \
|
||||
\
|
||||
static const struct bd8lb600fs_diagnostics_config bd8lb600fs_diagnostics_config_##inst = { \
|
||||
.parent_dev = DEVICE_DT_GET(DT_PARENT(DT_DRV_INST(inst))), \
|
||||
}; \
|
||||
\
|
||||
SENSOR_DEVICE_DT_INST_DEFINE( \
|
||||
inst, bd8lb600fs_diagnostics_init, NULL, &bd8lb600fs_diagnostics_data_##inst, \
|
||||
&bd8lb600fs_diagnostics_config_##inst, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \
|
||||
&bd8lb600fs_diagnostics_driver_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(BD8LB600FS_DIAGNOSTICS_DEFINE)
|
23
drivers/sensor/bd8lb600fs/bd8lb600fs_diagnostics.h
Normal file
23
drivers/sensor/bd8lb600fs/bd8lb600fs_diagnostics.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2024 SILA Embedded Solutions GmbH
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_DRIVERS_SENSOR_BD8LB600FS_BD8LB600FS_DIAGNOSTICS_H_
|
||||
#define ZEPHYR_DRIVERS_SENSOR_BD8LB600FS_BD8LB600FS_DIAGNOSTICS_H_
|
||||
|
||||
#include <zephyr/device.h>
|
||||
|
||||
struct bd8lb600fs_diagnostics_data {
|
||||
/* open load detection */
|
||||
uint32_t old;
|
||||
/* over current protection or thermal shutdown*/
|
||||
uint32_t ocp_or_tsd;
|
||||
};
|
||||
|
||||
struct bd8lb600fs_diagnostics_config {
|
||||
const struct device *parent_dev;
|
||||
};
|
||||
|
||||
#endif /* ZEPHYR_DRIVERS_SENSOR_BD8LB600FS_BD8LB600FS_DIAGNOSTICS_H_ */
|
17
dts/bindings/sensor/rohm,bd8lb600fs-diagnostics.yaml
Normal file
17
dts/bindings/sensor/rohm,bd8lb600fs-diagnostics.yaml
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Copyright (c) 2024 SILA Embedded Solutions GmbH
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: |
|
||||
Open load detection, over current protection and thermal shutdown
|
||||
sensor of the low side switch BD8LB600FS
|
||||
|
||||
compatible: "rohm,bd8lb600fs-diagnostics"
|
||||
|
||||
include: sensor-device.yaml
|
||||
|
||||
on-bus: bd8lb600fs
|
||||
|
||||
properties:
|
||||
"#sensor-cells":
|
||||
type: int
|
||||
const: 0
|
24
include/zephyr/drivers/sensor/bd8lb600fs.h
Normal file
24
include/zephyr/drivers/sensor/bd8lb600fs.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2024 SILA Embedded Solutions GmbH
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_BD8LB600FS_H_
|
||||
#define ZEPHYR_INCLUDE_DRIVERS_SENSOR_BD8LB600FS_H_
|
||||
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
|
||||
enum sensor_channel_bd8lb600fs {
|
||||
/**
|
||||
* Open load detected,
|
||||
* boolean with one bit per output
|
||||
*/
|
||||
SENSOR_CHAN_BD8LB600FS_OPEN_LOAD = SENSOR_ATTR_PRIV_START,
|
||||
/**
|
||||
* Over current protection or thermal shutdown,
|
||||
* boolean with one bit per output
|
||||
*/
|
||||
SENSOR_CHAN_BD8LB600FS_OVER_CURRENT_OR_THERMAL_SHUTDOWN,
|
||||
};
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_BD8LB600FS_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue