# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2019 Martin Jäger (Libre Solar)

#
# Invisible (board-specific) Kconfig symbols
#

config CONTROL_FREQUENCY
	int
	default 10
	help
	  Main control function frequency (Hz)

	  Frequencies higher than 10 Hz caused issues with MPPT control during lab test with
	  PV simulator. Might be different with actual solar panel.

config LIBRE_SOLAR_TYPE_ID
    int
    help
      Numeric Libre Solar hardware type ID

#
# Visible (user-configurable) Kconfig symbols
#

choice
    prompt "High-voltage terminal"
    depends on $(dt_compat_enabled,dcdc)
    help
      Select the device connected to the high-voltage
      side terminal of the DC/DC converter.

    config HV_TERMINAL_SOLAR
        bool "Solar panel"

    config HV_TERMINAL_NANOGRID
        bool "DC nanogrid"

    config HV_TERMINAL_GENERATOR
        bool "DC generator, e.g. wind turbine"

    config HV_TERMINAL_BATTERY
        bool "Battery, e.g. electric bicycle"
endchoice


choice
    prompt "Low-voltage terminal"
    help
      Select the device connected to the low-voltage side
      of the charge controller (usually battery terminal).

    config LV_TERMINAL_BATTERY
        depends on !HV_TERMINAL_BATTERY
        bool "Battery 12V/24V"

    config LV_TERMINAL_SOLAR
        depends on HV_TERMINAL_BATTERY || HV_TERMINAL_NANOGRID
        bool "Solar panel"
endchoice


choice
    prompt "PWM terminal"
    depends on $(dt_node_has_bool_prop,/outputs/pwm_switch,kconfig-flag)
    help
      Select the device connected to the PWM switch (currently
      only solar panel possible)

    config PWM_TERMINAL_SOLAR
        depends on LV_TERMINAL_BATTERY && !HV_TERMINAL_SOLAR
        bool "Solar panel"
endchoice


menu "Battery configuration"

choice
    prompt "Default battery cell type"
    default BAT_DEFAULT_TYPE_GEL
    help
      Select the type of the single cells inside the battery
      to determine voltage set points. Total voltage set points
      are multiplied with the selected number of cells.

    config BAT_DEFAULT_TYPE_FLOODED
        bool "Flooded (wet) lead-acid"

    config BAT_DEFAULT_TYPE_GEL
        bool "VRLA gel, maintainance-free"

    config BAT_DEFAULT_TYPE_AGM
        bool "AGM, maintainance-free"

    config BAT_DEFAULT_TYPE_LFP
        bool "LiFePO4 Li-ion, 3.3V nominal"

    config BAT_DEFAULT_TYPE_NMC
        bool "NMC/Graphite Li-ion, 3.7V nominal, 4.2V max"

    config BAT_DEFAULT_TYPE_NMC_HV
        bool "NMC/Graphite High Voltage Li-ion, 3.7V nominal, 4.35 max"
endchoice

# values must match enum BatType in bat_charger.h
config BAT_DEFAULT_TYPE
    int
    default 1 if BAT_DEFAULT_TYPE_FLOODED
    default 2 if BAT_DEFAULT_TYPE_GEL
    default 3 if BAT_DEFAULT_TYPE_AGM
    default 4 if BAT_DEFAULT_TYPE_LFP
    default 5 if BAT_DEFAULT_TYPE_NMC
    default 6 if BAT_DEFAULT_TYPE_NMC_HV

config BAT_DEFAULT_NUM_CELLS
	int "Default number of battery cells"
	default 6
	range 3 16
	help
      Typical choices:
      - 6 for 12V lead-acid battery
      - 4 for 12V LiFePO4 battery
      - 3 for 12V NMC Li-ion battery

      Remarks:
      - If you choose settings for 12V system, 24V systems
	    (2 batteries in series) are recognized automatically
      - Make sure the voltage of the used charge controller
        is not exceeded.

config BAT_DEFAULT_CAPACITY_AH
    int "Default battery capacity in Ah"
    range 10 200
    default 50

endmenu


menu "Extensions and interfaces"

config EXT_OLED_DISPLAY
    bool "OLED display at UEXT"

config EXT_OLED_BRIGHTNESS
    depends on EXT_OLED_DISPLAY
    int "OLED display brightness"
    range 1 255
    default 1

config EXT_THINGSET_SERIAL
    bool "ThingSet serial interface"

config EXT_THINGSET_SERIAL_RX_BUF_SIZE
    depends on EXT_THINGSET_SERIAL
    int "ThingSet serial RX buffer size"
    range 64 2048
    default 512

config EXT_THINGSET_SERIAL_TX_BUF_SIZE
    depends on EXT_THINGSET_SERIAL
    int "ThingSet serial TX buffer size"
    range 256 2048
    default 1024

config EXT_THINGSET_CAN
    depends on CAN
    bool "ThingSet CAN interface"

config THINGSET_EXPERT_PASSWORD
    depends on EXT_THINGSET_SERIAL || EXT_THINGSET_CAN
    string "ThingSet expert user password"
    default "expert123"

config THINGSET_MAKER_PASSWORD
    depends on EXT_THINGSET_SERIAL || EXT_THINGSET_CAN
    string "ThingSet maker password"
    default "maker456"

endmenu


menuconfig CUSTOMIZATION
    bool "Firmware customization"
    help
      Activating this option allows to overwrite existing firmware functions
      or add customizations independent of the master branch.
      Custom implementations should be stored in the
      src/custom subdirectory.

if CUSTOMIZATION

config CUSTOM_DATA_NODES_FILE
    bool "Use custom data nodes file"
    default n
    help
      Use a custom file instead of default data_nodes.cpp for
      ThingSet configuration.

endif
