From dc4576c8b48602cc47101bda55157857b48b4906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Mon, 20 Jul 2020 08:42:54 +0200 Subject: [PATCH] Remove all board.h files Final updates to devicetree files (adding temperature sensor information) make board.h files obsolete. --- boards/arm/mppt_1210_hus/board.h | 15 ------ boards/arm/mppt_1210_hus/mppt_1210_hus.dts | 4 +- boards/arm/mppt_2420_hpx/board.h | 54 ---------------------- boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts | 2 +- boards/arm/mppt_2420_lc/board.h | 16 ------- boards/arm/mppt_2420_lc/mppt_2420_lc.dts | 4 +- boards/arm/mppt_2420_rc/board.h | 14 ------ boards/arm/mppt_2420_rc/mppt_2420_rc.dts | 4 +- boards/arm/pwm_2420_lus/board.h | 18 -------- boards/arm/pwm_2420_lus/pwm_2420_lus.dts | 2 +- src/bat_charger.cpp | 1 - src/daq.cpp | 17 ++++--- src/daq_driver.c | 1 - src/data_nodes.cpp | 1 - src/dcdc.cpp | 1 - src/device_status.cpp | 1 - src/eeprom.cpp | 1 - src/ext/oled.cpp | 1 - src/half_bridge.cpp | 1 - src/hardware.cpp | 1 - src/load.cpp | 1 - src/load_driver.c | 3 +- src/main.cpp | 1 - src/pwm_switch.cpp | 1 - src/pwm_switch_driver.c | 1 - src/setup.cpp | 1 - src/setup.h | 1 - test/autoconf.h | 21 +++++++++ test/board.h | 40 ---------------- test/devicetree_unfixed.h | 2 + test/zephyr.h | 1 + 31 files changed, 45 insertions(+), 187 deletions(-) delete mode 100644 boards/arm/mppt_1210_hus/board.h delete mode 100644 boards/arm/mppt_2420_hpx/board.h delete mode 100644 boards/arm/mppt_2420_lc/board.h delete mode 100644 boards/arm/mppt_2420_rc/board.h delete mode 100644 boards/arm/pwm_2420_lus/board.h create mode 100644 test/autoconf.h delete mode 100644 test/board.h diff --git a/boards/arm/mppt_1210_hus/board.h b/boards/arm/mppt_1210_hus/board.h deleted file mode 100644 index d1763fd..0000000 --- a/boards/arm/mppt_1210_hus/board.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2019 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef MPPT_1210_HUS_H -#define MPPT_1210_HUS_H - -// typical value for Semitec 103AT-5 thermistor: 3435 -#define NTC_BETA_VALUE 3435 -#define NTC_SERIES_RESISTOR 10000.0 - - -#endif diff --git a/boards/arm/mppt_1210_hus/mppt_1210_hus.dts b/boards/arm/mppt_1210_hus/mppt_1210_hus.dts index 9025f95..06e720a 100755 --- a/boards/arm/mppt_1210_hus/mppt_1210_hus.dts +++ b/boards/arm/mppt_1210_hus/mppt_1210_hus.dts @@ -115,7 +115,7 @@ temp-bat { io-channels = <&adc1 7>; - multiplier = <1>; + multiplier = <10000>; divider = <1>; }; @@ -127,7 +127,7 @@ temp-mcu { io-channels = <&adc1 18>; - multiplier = <1>; + multiplier = <10000>; divider = <1>; }; }; diff --git a/boards/arm/mppt_2420_hpx/board.h b/boards/arm/mppt_2420_hpx/board.h deleted file mode 100644 index e7418c0..0000000 --- a/boards/arm/mppt_2420_hpx/board.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2020 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef MPPT_2420_HPX_H -#define MPPT_2420_HPX_H - -// pin definition only needed in adc_dma.cpp to detect if they are present on the PCB -//#define PIN_ADC_TEMP_FETS PA_5 - -// typical value for Semitec 103AT-5 thermistor: 3435 -#define NTC_BETA_VALUE 3435 -#define NTC_SERIES_RESISTOR 10000.0 -/* -// position in the array written by the DMA controller -enum { - // ADC1 - ADC_POS_V_LOW, - ADC_POS_V_HIGH, - ADC_POS_V_SC_SENSE, - ADC_POS_V_PWM, - ADC_POS_TEMP_FETS, - ADC_POS_VREF_MCU, - ADC_POS_TEMP_MCU, - // ADC2 - ADC_POS_I_DCDC, - ADC_POS_I_LOAD, - ADC_POS_I_PWM, - NUM_ADC_CH // trick to get the number of elements -}; - -// selected ADC channels (has to match with below arrays) -#define NUM_ADC_1_CH 7 -#define NUM_ADC_2_CH 3 - -static const uint32_t adc_1_sequence[] = { - LL_ADC_CHANNEL_12, // V_LOW - LL_ADC_CHANNEL_15, // V_HIGH - LL_ADC_CHANNEL_11, // V_SC_SENSE - LL_ADC_CHANNEL_4, // V_PWM - LL_ADC_CHANNEL_6, // TEMP_FETS - LL_ADC_CHANNEL_VREFINT, // VREF_MCU - LL_ADC_CHANNEL_TEMPSENSOR_ADC1, // TEMP_MCU -}; - -static const uint32_t adc_2_sequence[] = { - LL_ADC_CHANNEL_1, // I_DCDC - LL_ADC_CHANNEL_2, // I_LOAD - LL_ADC_CHANNEL_5, // I_PWM -}; -*/ -#endif diff --git a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts index b0f959d..f978c51 100644 --- a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts +++ b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts @@ -102,7 +102,7 @@ temp-fets { io-channels = <&adc1 6>; - multiplier = <1>; + multiplier = <10000>; // 10k NTC series resistor divider = <1>; }; diff --git a/boards/arm/mppt_2420_lc/board.h b/boards/arm/mppt_2420_lc/board.h deleted file mode 100644 index 2122faa..0000000 --- a/boards/arm/mppt_2420_lc/board.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2017 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef MPPT_2420_LC_H -#define MPPT_2420_LC_H - -#define CONFIG_CAN 1 - -// typical value for Semitec 103AT-5 thermistor: 3435 -#define NTC_BETA_VALUE 3435 -#define NTC_SERIES_RESISTOR 10000.0 - -#endif diff --git a/boards/arm/mppt_2420_lc/mppt_2420_lc.dts b/boards/arm/mppt_2420_lc/mppt_2420_lc.dts index e768123..1142930 100755 --- a/boards/arm/mppt_2420_lc/mppt_2420_lc.dts +++ b/boards/arm/mppt_2420_lc/mppt_2420_lc.dts @@ -85,13 +85,13 @@ temp-bat { io-channels = <&adc1 0>; - multiplier = <1>; + multiplier = <10000>; // 10k NTC series resistor divider = <1>; }; temp-fets { io-channels = <&adc1 1>; - multiplier = <1>; + multiplier = <10000>; // 10k NTC series resistor divider = <1>; }; diff --git a/boards/arm/mppt_2420_rc/board.h b/boards/arm/mppt_2420_rc/board.h deleted file mode 100644 index 0d6e6d5..0000000 --- a/boards/arm/mppt_2420_rc/board.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2020 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef MPPT_2420_RC_H -#define MPPT_2420_RC_H - -// typical value for Semitec 103AT-5 thermistor: 3435 -#define NTC_BETA_VALUE 3435 -#define NTC_SERIES_RESISTOR 10000.0 - -#endif diff --git a/boards/arm/mppt_2420_rc/mppt_2420_rc.dts b/boards/arm/mppt_2420_rc/mppt_2420_rc.dts index 665df69..d5dcb6e 100644 --- a/boards/arm/mppt_2420_rc/mppt_2420_rc.dts +++ b/boards/arm/mppt_2420_rc/mppt_2420_rc.dts @@ -82,13 +82,13 @@ temp-fets { io-channels = <&adc1 2>; - multiplier = <1>; + multiplier = <10000>; // 10k NTC series resistor divider = <1>; }; temp-bat { io-channels = <&adc1 14>; - multiplier = <1>; + multiplier = <10000>; // 10k NTC series resistor divider = <1>; }; diff --git a/boards/arm/pwm_2420_lus/board.h b/boards/arm/pwm_2420_lus/board.h deleted file mode 100644 index 4e1fb28..0000000 --- a/boards/arm/pwm_2420_lus/board.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2018 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef PWM_2420_LUS_H -#define PWM_2420_LUS_H - -#define PIN_I_LOAD_COMP PB_4 - -#define PIN_EXT_BTN PB_12 - -// typical value for Semitec 103AT-5 thermistor: 3435 -#define NTC_BETA_VALUE 3435 -#define NTC_SERIES_RESISTOR 8200.0 - -#endif diff --git a/boards/arm/pwm_2420_lus/pwm_2420_lus.dts b/boards/arm/pwm_2420_lus/pwm_2420_lus.dts index 53c9980..71f18f5 100644 --- a/boards/arm/pwm_2420_lus/pwm_2420_lus.dts +++ b/boards/arm/pwm_2420_lus/pwm_2420_lus.dts @@ -123,7 +123,7 @@ temp-bat { io-channels = <&adc1 7>; - multiplier = <1>; + multiplier = <8200>; // 8.2k NTC series resistor divider = <1>; }; diff --git a/src/bat_charger.cpp b/src/bat_charger.cpp index 5159bbb..7495580 100644 --- a/src/bat_charger.cpp +++ b/src/bat_charger.cpp @@ -11,7 +11,6 @@ #include // for fabs function #include -#include "board.h" #include "helper.h" #include "device_status.h" diff --git a/src/daq.cpp b/src/daq.cpp index ad0cd31..97a0d66 100644 --- a/src/daq.cpp +++ b/src/daq.cpp @@ -14,7 +14,9 @@ #include "mcu.h" #include "setup.h" #include "debug.h" -#include "board.h" // contains defines for pins + +// typical value for Semitec 103AT-5 thermistor: 3435 +#define NTC_BETA_VALUE 3435 #if DT_NODE_EXISTS(DT_PATH(dcdc)) static float dcdc_current_offset; @@ -57,14 +59,17 @@ static inline float adc_scaled(uint32_t channel, int32_t vref, const float gain, return adc_raw_to_voltage(adc_raw_filtered(channel) - offset, vref) * gain; } -static inline float ntc_temp(uint32_t channel, int32_t vref) +static inline float ntc_temp(uint32_t channel, int32_t vref, float ntc_series_resistor) { /** \todo Improved (faster) temperature calculation: https://www.embeddedrelated.com/showarticle/91.php */ - float v_temp = adc_raw_to_voltage(adc_raw_filtered(channel), vref) * 1000; // voltage read by ADC (mV) - float rts = NTC_SERIES_RESISTOR * v_temp / (vref - v_temp); // resistance of NTC (Ohm) + // voltage read by ADC (mV) + float v_temp = adc_raw_to_voltage(adc_raw_filtered(channel), vref) * 1000; + + // resistance of NTC (Ohm) + float rts = ntc_series_resistor * v_temp / (vref - v_temp); return 1.0/(1.0/(273.15+25) + 1.0/NTC_BETA_VALUE*log(rts/10000.0)) - 273.15; // °C } @@ -186,7 +191,7 @@ void daq_update() #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(adc_inputs), temp_bat)) // battery temperature calculation - float bat_temp = ntc_temp(ADC_POS(temp_bat), vref); + float bat_temp = ntc_temp(ADC_POS(temp_bat), vref, ADC_GAIN(temp_bat)); if (bat_temp > -50) { // external sensor connected: take measured value @@ -202,7 +207,7 @@ void daq_update() #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(adc_inputs), temp_fets)) // MOSFET temperature calculation - dcdc.temp_mosfets = ntc_temp(ADC_POS(temp_fets), vref); + dcdc.temp_mosfets = ntc_temp(ADC_POS(temp_fets), vref, ADC_GAIN(temp_fets)); #endif // internal MCU temperature diff --git a/src/daq_driver.c b/src/daq_driver.c index 2b967e2..cd3283e 100644 --- a/src/daq_driver.c +++ b/src/daq_driver.c @@ -35,7 +35,6 @@ #endif #include "dcdc.h" // for low-level control function called by DMA -#include "board.h" #include "debug.h" #if defined(CONFIG_SOC_SERIES_STM32F0X) || defined(CONFIG_SOC_SERIES_STM32L0X) diff --git a/src/data_nodes.cpp b/src/data_nodes.cpp index 148bc95..ba4b430 100644 --- a/src/data_nodes.cpp +++ b/src/data_nodes.cpp @@ -17,7 +17,6 @@ #include "setup.h" -#include "board.h" #include "version.h" // can be used to configure custom data objects in separate file instead diff --git a/src/dcdc.cpp b/src/dcdc.cpp index f832884..ee63ea2 100644 --- a/src/dcdc.cpp +++ b/src/dcdc.cpp @@ -16,7 +16,6 @@ #include // for min/max function #include -#include "board.h" #include "device_status.h" #include "debug.h" #include "helper.h" diff --git a/src/device_status.cpp b/src/device_status.cpp index 362b2aa..8f5f262 100644 --- a/src/device_status.cpp +++ b/src/device_status.cpp @@ -11,7 +11,6 @@ #include // for fabs function #include -#include "board.h" #include "setup.h" #include "helper.h" diff --git a/src/eeprom.cpp b/src/eeprom.cpp index 7abb7b8..370e75e 100644 --- a/src/eeprom.cpp +++ b/src/eeprom.cpp @@ -15,7 +15,6 @@ #endif #include "mcu.h" -#include "board.h" #include "thingset.h" #include "data_nodes.h" #include "helper.h" diff --git a/src/ext/oled.cpp b/src/ext/oled.cpp index c32dfe2..9d1003b 100644 --- a/src/ext/oled.cpp +++ b/src/ext/oled.cpp @@ -19,7 +19,6 @@ #include "setup.h" #include "half_bridge.h" -#include "board.h" #include "oled_ssd1306.h" // implement specific extension inherited from ExtInterface diff --git a/src/half_bridge.cpp b/src/half_bridge.cpp index 13bde3b..e00a1e8 100644 --- a/src/half_bridge.cpp +++ b/src/half_bridge.cpp @@ -9,7 +9,6 @@ #include #include "mcu.h" -#include "board.h" static uint16_t tim_arr; // auto-reload register (defines PWM frequency) static uint16_t tim_ccr_min; // capture/compare register min/max diff --git a/src/hardware.cpp b/src/hardware.cpp index 5925ce1..86950c0 100644 --- a/src/hardware.cpp +++ b/src/hardware.cpp @@ -7,7 +7,6 @@ #include "hardware.h" #include "mcu.h" -#include "board.h" #include "load.h" #include "half_bridge.h" #include "leds.h" diff --git a/src/load.cpp b/src/load.cpp index 331cac6..e98557f 100644 --- a/src/load.cpp +++ b/src/load.cpp @@ -10,7 +10,6 @@ #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), load)) || UNIT_TEST -#include "board.h" #include "leds.h" #include "device_status.h" #include "debug.h" diff --git a/src/load_driver.c b/src/load_driver.c index 6117b4a..7217558 100644 --- a/src/load_driver.c +++ b/src/load_driver.c @@ -31,11 +31,12 @@ static struct device *dev_load; static struct device *dev_usb; #endif -#include "board.h" #include "hardware.h" #include "debug.h" #include "leds.h" +/* TODO: porting and testing of comparator copied from mbed */ + #if defined(PIN_I_LOAD_COMP) && PIN_LOAD_DIS == PB_2 static void lptim_init() { diff --git a/src/main.cpp b/src/main.cpp index d3ad83b..957d9c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,6 @@ #include #include "thingset.h" // handles access to internal data via communication interfaces -#include "board.h" // hardware-specific settings #include "setup.h" #include "helper.h" diff --git a/src/pwm_switch.cpp b/src/pwm_switch.cpp index b5fa5e7..d0b9e19 100644 --- a/src/pwm_switch.cpp +++ b/src/pwm_switch.cpp @@ -11,7 +11,6 @@ #include #include -#include "board.h" #include "mcu.h" #include "daq.h" #include "debug.h" diff --git a/src/pwm_switch_driver.c b/src/pwm_switch_driver.c index 47b979f..7b05dc9 100644 --- a/src/pwm_switch_driver.c +++ b/src/pwm_switch_driver.c @@ -11,7 +11,6 @@ #include #include -#include "board.h" #include "daq.h" #include "debug.h" #include "helper.h" diff --git a/src/setup.cpp b/src/setup.cpp index 0a83941..77ea147 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -12,7 +12,6 @@ #include #include "thingset.h" // handles access to internal data via communication interfaces -#include "board.h" // hardware-specific settings #include "half_bridge.h" // PWM generation for DC/DC converter #include "hardware.h" // hardware-related functions like load switch, LED control, watchdog, etc. diff --git a/src/setup.h b/src/setup.h index 3c8520a..83c61c6 100644 --- a/src/setup.h +++ b/src/setup.h @@ -14,7 +14,6 @@ #include "power_port.h" #include "pwm_switch.h" #include "thingset.h" -#include "board.h" extern DcBus lv_bus; extern PowerPort lv_terminal; diff --git a/test/autoconf.h b/test/autoconf.h new file mode 100644 index 0000000..750c5d8 --- /dev/null +++ b/test/autoconf.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2018 Martin Jäger / Libre Solar + * + * SPDX-License-Identifier: Apache-2.0 + */ + +// PWM charge controller +#define CONFIG_PWM_TERMINAL_SOLAR 1 + +// MPPT buck/boost or nanogrid mode +#define CONFIG_HV_TERMINAL_SOLAR 1 +#define CONFIG_HV_TERMINAL_NANOGRID 0 + +// battery always assumed to be at low-voltage terminal (might need to be changed for boost mode) +#define CONFIG_LV_TERMINAL_BATTERY 1 + +#define CONFIG_THINGSET_EXPERT_PASSWORD "expert123" +#define CONFIG_THINGSET_MAKER_PASSWORD "maker456" + +// Values that are otherwise defined by Kconfig +#define CONFIG_CONTROL_FREQUENCY 10 // Hz diff --git a/test/board.h b/test/board.h deleted file mode 100644 index 7bf27c3..0000000 --- a/test/board.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2018 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef PCB_STUB_H -#define PCB_STUB_H - -// PWM charge controller -#define CONFIG_PWM_TERMINAL_SOLAR DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), pwm_switch)) - -// MPPT buck/boost or nanogrid mode -#define CONFIG_HV_TERMINAL_SOLAR DT_NODE_EXISTS(DT_PATH(dcdc)) -#define CONFIG_HV_TERMINAL_NANOGRID 0 - -// battery always assumed to be at low-voltage terminal (might need to be changed for boost mode) -#define CONFIG_LV_TERMINAL_BATTERY 1 - -// basic battery configuration -#define BATTERY_TYPE BAT_TYPE_GEL ///< GEL most suitable for general batteries (see battery.h for other types) -#define BATTERY_NUM_CELLS 6 ///< For lead-acid batteries: 6 for 12V system, 12 for 24V system -#define BATTERY_CAPACITY 40 ///< Cell capacity or sum of parallel cells capacity (Ah) - -#define CONFIG_DEVICE_ID 12345678 - -#define CONFIG_THINGSET_EXPERT_PASSWORD "expert123" -#define CONFIG_THINGSET_MAKER_PASSWORD "maker456" - -// Values that are otherwise defined by Kconfig -#define CONFIG_CONTROL_FREQUENCY 10 // Hz - -// pin definition only needed in adc_dma.cpp to detect if they are present on the PCB -#define PIN_ADC_TEMP_BAT - -// typical value for Semitec 103AT-5 thermistor: 3435 -#define NTC_BETA_VALUE 3435 -#define NTC_SERIES_RESISTOR 8200.0 - -#endif diff --git a/test/devicetree_unfixed.h b/test/devicetree_unfixed.h index 3b3596a..5e19f8c 100644 --- a/test/devicetree_unfixed.h +++ b/test/devicetree_unfixed.h @@ -36,6 +36,8 @@ * ADC */ #define DT_N_S_adc_inputs_S_temp_bat_EXISTS 1 +#define DT_N_S_adc_inputs_S_temp_bat_P_multiplier 10000 +#define DT_N_S_adc_inputs_S_temp_bat_P_divider 1 #define DT_N_S_adc_inputs_S_v_high_P_multiplier 105600 #define DT_N_S_adc_inputs_S_v_high_P_divider 5600 diff --git a/test/zephyr.h b/test/zephyr.h index b0bb3b5..8e56c91 100644 --- a/test/zephyr.h +++ b/test/zephyr.h @@ -13,6 +13,7 @@ #include "devicetree.h" #include "devicetree_unfixed.h" +#include "autoconf.h" #ifndef __deprecated #define __deprecated __attribute__((deprecated))