From f8d7b25648b24367424edb8d5a291cf2a3fa670d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Wed, 24 Feb 2021 08:54:51 +0100 Subject: [PATCH] DCDC: Update HV output switch handling --- boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts | 4 ++-- boards/arm/mppt_2420_rc/mppt_2420_rc.dts | 4 ++-- src/dcdc.cpp | 25 +++++++++++++--------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts index 989b908..a560c4d 100644 --- a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts +++ b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts @@ -62,8 +62,8 @@ pwms = <&pwm8 1 200000 PWM_POLARITY_NORMAL>; /* 200 us period = 5 kHz */ }; - hv-ext-sense { - label = "HV external sense and switch"; + hv-out { + label = "HV output sense and enable switch"; gpios = <&gpiob 12 GPIO_ACTIVE_LOW>; }; }; diff --git a/boards/arm/mppt_2420_rc/mppt_2420_rc.dts b/boards/arm/mppt_2420_rc/mppt_2420_rc.dts index 95fb013..073e090 100644 --- a/boards/arm/mppt_2420_rc/mppt_2420_rc.dts +++ b/boards/arm/mppt_2420_rc/mppt_2420_rc.dts @@ -48,8 +48,8 @@ gpios = <&gpiob 14 GPIO_ACTIVE_LOW>; }; - hv-ext-sense { - label = "HV external sense and switch"; + hv-out { + label = "HV output sense and enable switch"; gpios = <&gpiob 12 GPIO_ACTIVE_LOW>; }; }; diff --git a/src/dcdc.cpp b/src/dcdc.cpp index 5f55d45..3eca59a 100644 --- a/src/dcdc.cpp +++ b/src/dcdc.cpp @@ -9,6 +9,7 @@ #include #ifndef UNIT_TEST +#include #include #include @@ -29,8 +30,8 @@ extern DeviceStatus dev_stat; #if BOARD_HAS_DCDC -#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), hv_ext_sense)) -#define HV_EXT_SENSE_GPIO DT_CHILD(DT_PATH(outputs), hv_ext_sense) +#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), hv_out)) +#define HV_OUT_NODE DT_CHILD(DT_PATH(outputs), hv_out) #endif Dcdc::Dcdc(DcBus *high, DcBus *low, DcdcOperationMode op_mode) @@ -335,19 +336,23 @@ void Dcdc::fuse_destruction() void Dcdc::output_hvs_enable() { -#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), hv_ext_sense)) - const struct device *dev_hv_ext = device_get_binding(DT_GPIO_LABEL(HV_EXT_SENSE_GPIO, gpios)); - gpio_pin_configure(dev_hv_ext, DT_GPIO_PIN(HV_EXT_SENSE_GPIO, gpios), - DT_GPIO_FLAGS(HV_EXT_SENSE_GPIO, gpios) | GPIO_OUTPUT_ACTIVE); +#ifdef HV_OUT_NODE + const struct device *hv_out = DEVICE_DT_GET(DT_GPIO_CTLR(HV_OUT_NODE, gpios)); + if (device_is_ready(hv_out)) { + gpio_pin_configure(hv_out, DT_GPIO_PIN(HV_OUT_NODE, gpios), + DT_GPIO_FLAGS(HV_OUT_NODE, gpios) | GPIO_OUTPUT_ACTIVE); + } #endif } void Dcdc::output_hvs_disable() { -#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), hv_ext_sense)) - const struct device *dev_hv_ext = device_get_binding(DT_GPIO_LABEL(HV_EXT_SENSE_GPIO, gpios)); - gpio_pin_configure(dev_hv_ext, DT_GPIO_PIN(HV_EXT_SENSE_GPIO, gpios), - DT_GPIO_FLAGS(HV_EXT_SENSE_GPIO, gpios) | GPIO_OUTPUT_INACTIVE); +#ifdef HV_OUT_NODE + const struct device *hv_out = DEVICE_DT_GET(DT_GPIO_CTLR(HV_OUT_NODE, gpios)); + if (device_is_ready(hv_out)) { + gpio_pin_configure(hv_out, DT_GPIO_PIN(HV_OUT_NODE, gpios), + DT_GPIO_FLAGS(HV_OUT_NODE, gpios) | GPIO_OUTPUT_INACTIVE); + } #endif }