menu "DALI Component"

config DALI_PHY_COUNT
    int "Maximum DALI buses"
    range 1 16
    default 16
    help
        Maximum number of DALI PHY buses managed by this component.

config DALI_DEFAULT_BAUDRATE
    int "Default DALI baudrate"
    range 400 2400
    default 1200
    help
        Default baudrate used during initialization.

config DALI_TIMER_RESOLUTION_HZ
    int "Native DALI timer resolution Hz"
    range 1000000 8000000
    default 3000000
    help
        GPTimer resolution for native DALI Manchester timing. The default 3 MHz
        allows a 1200 bps half-bit period of 416.67 us to be represented as
        1250 timer ticks.

config DALI_CUSTOM_HALF_BIT_TIME_X100_US
    int "Custom native DALI half-bit time x100 us"
    range 0 500000
    default 0
    help
        Development override for the native DALI half-bit period, expressed in
        1/100 us. Set to 0 to derive the value from the configured baudrate.
        Standard 1200 bps DALI is 41667, meaning 416.67 us.

config DALI_TX_STOP_CONDITION_US
    int "Custom TX stop condition us"
    range 0 10000
    default 0
    help
        Development override for the native TX stop-condition wait. Set to 0 to
        use the scaled standard timing.

config DALI_RX_STOP_CONDITION_US
    int "Custom RX stop condition us"
    range 0 10000
    default 0
    help
        Development override for the native RX stop-condition wait. Set to 0 to
        use the scaled standard timing.

config DALI_QUERY_RESPONSE_TIMEOUT_MS
    int "DALI query response timeout ms"
    range 10 100
    default 25
    help
        Time to wait for a complete backward frame after a forward query has
        finished transmitting. DALI backward frames start 5.5-10.5 ms after the
        forward frame and last about 9.95 ms, so 25 ms leaves margin without the
        legacy 50 ms no-response delay.

config DALI_DOUBLE_SEND_DELAY_MS
    int "Double-send delay ms"
    range 0 100
    default 10
    help
        Delay between the two frames sent by dali_send_double(), measured after
        the first frame has completed. Exposed for development tuning.

config DALI_FORWARD_ACTIVITY_WAIT_MS
    int "Forward-frame wait after bus activity ms"
    range 0 1000
    default 25
    help
        Minimum delay before sending a 2- to 4-byte forward frame after normal
        bus activity. This is the native queue anti-collision wait.

config DALI_FORWARD_AFTER_BACKWARD_WAIT_MS
    int "Forward-frame wait after backward frame ms"
    range 0 1000
    default 5
    help
        Minimum delay before sending a 2- to 4-byte forward frame after the last
        valid 1-byte backward frame received by the native bus.

config DALI_FORWARD_MAX_WAIT_MS
    int "Forward-frame maximum queue wait ms"
    range 0 5000
    default 50
    help
        Maximum time the native queue waits for a forward-frame send window. If
        no valid send window is reached before this timeout, the frame is
        dropped with an error status.

config DALI_BACKWARD_IDLE_TIMEOUT_MS
    int "Backward-frame idle wait timeout ms"
    range 0 1000
    default 9
    help
        Time a 1-byte backward frame waits for an idle bus before being sent
        anyway. Backward frame sends are not echo-verified because collisions
        during addressing responses are valid DALI behavior.

config DALI_BUS_POWER_CHECK_INTERVAL_MS
    int "Bus power-down check interval ms"
    range 10 5000
    default 100
    help
        Interval used to resample the RX pin while the native DALI bus is marked
        power-down. This lets the HAL recover when the bus was already powered
        before gateway startup and no RX edge is generated.

config DALI_BUS_ABNORMAL_REPORT_INTERVAL_MS
    int "Legacy bus abnormal report interval ms"
    range 0 60000
    default 1000
    help
        Interval for publishing the legacy two-byte FF FD bus-abnormal raw frame
        while the native DALI bus is power-down. Set to 0 to disable the report.

choice DALI_LOG_LEVEL_CHOICE
    prompt "DALI log level"
    default DALI_LOG_LEVEL_WARN
    help
        Runtime log level applied to the native DALI HAL ESP-IDF log tag.

config DALI_LOG_LEVEL_NONE
    bool "No output"

config DALI_LOG_LEVEL_ERROR
    bool "Error"

config DALI_LOG_LEVEL_WARN
    bool "Warning"

config DALI_LOG_LEVEL_INFO
    bool "Info"

config DALI_LOG_LEVEL_DEBUG
    bool "Debug"

config DALI_LOG_LEVEL_VERBOSE
    bool "Verbose"

endchoice

config DALI_LOG_LEVEL
    int
    default 0 if DALI_LOG_LEVEL_NONE
    default 1 if DALI_LOG_LEVEL_ERROR
    default 2 if DALI_LOG_LEVEL_WARN
    default 3 if DALI_LOG_LEVEL_INFO
    default 4 if DALI_LOG_LEVEL_DEBUG
    default 5 if DALI_LOG_LEVEL_VERBOSE

choice DALI_TX_ACTIVE_LEVEL
    prompt "DALI TX pin active level"
    default DALI_TX_ACTIVE_LOW
    help
        Select the physical GPIO level that drives the DALI bus active. The
        native gateway default is TX active low.

config DALI_TX_ACTIVE_LOW
    bool "Active low"

config DALI_TX_ACTIVE_HIGH
    bool "Active high"

endchoice

choice DALI_RX_ACTIVE_LEVEL
    prompt "DALI RX pin active level"
    default DALI_RX_ACTIVE_HIGH
    help
        Select the physical GPIO level read when the DALI bus is active. The
        native gateway default is RX active high.

config DALI_RX_ACTIVE_LOW
    bool "Active low"

config DALI_RX_ACTIVE_HIGH
    bool "Active high"

endchoice

config DALI_API_QUEUE_LEN
    int "Global API queue length"
    range 1 64
    default 10

config DALI_TX_QUEUE_LEN
    int "Per-bus TX queue length"
    range 1 16
    default 1

config DALI_TX_REPLY_QUEUE_LEN
    int "Per-bus TX reply queue length"
    range 1 32
    default 4

config DALI_RX_QUEUE_LEN
    int "Per-bus RX queue length"
    range 1 128
    default 50

config DALI_DEBUG_QUEUE_LEN
    int "Debug queue length"
    range 1 256
    default 100

config DALI_ENABLE_DEBUG_TASK
    bool "Enable debug task"
    default n
    help
        When enabled, starts a low-priority task that prints RX timing traces.

config DALI_DALI_TASK_STACK_SIZE
    int "DALI task stack size"
    range 1024 8192
    default 4096

config DALI_DALI_TASK_PRIORITY
    int "DALI task priority"
    range 1 24
    default 2

config DALI_DEBUG_TASK_STACK_SIZE
    int "Debug task stack size"
    range 1024 8192
    default 2048

config DALI_DEBUG_TASK_PRIORITY
    int "Debug task priority"
    range 1 24
    default 1

endmenu
