Skip to content

Commit 2bde84f

Browse files
committed
sensor: ina230: optional current and power inversion
Add a devicetree property to invert the direction of reported power and current flow, if needed to match the convention of some subsystem. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 321698b commit 2bde84f

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

drivers/sensor/ti/ina23x/ina230.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ static DEVICE_API(sensor, ina230_driver_api) = {
289289
static struct ina230_data drv_data_##type##inst; \
290290
static const struct ina230_config drv_config_##type##inst = { \
291291
.bus = I2C_DT_SPEC_INST_GET(inst), \
292-
.current_lsb = DT_INST_PROP(inst, current_lsb_microamps), \
292+
.current_lsb = DT_INST_PROP(inst, current_lsb_microamps) * \
293+
COND_CODE_1(DT_INST_PROP(inst, direction_invert), (-1), (1)), \
293294
.uv_lsb = type##_BUS_VOLTAGE_UV_LSB, \
294295
.conv_duration_us = CONV_DURATION_US(inst), \
295296
.config = (DT_INST_PROP_OR(inst, high_precision, 0) << 12) | \

drivers/sensor/ti/ina23x/ina230.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct ina230_data {
5252

5353
struct ina230_config {
5454
struct i2c_dt_spec bus;
55-
uint32_t current_lsb;
55+
int32_t current_lsb;
5656
uint32_t uv_lsb;
5757
uint32_t conv_duration_us;
5858
uint16_t config;

dts/bindings/sensor/ti,ina230.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ properties:
7171
default: 0
7272
# default alert limit is 0V
7373
description: Alert register, default matches the power-on reset value
74+
75+
direction-invert:
76+
type: boolean
77+
description: Invert the direction of reported current and power flow

0 commit comments

Comments
 (0)