#pragma once
#include "main.h"

#define PSU_MAX_VOLTAGE 1000 //1V/bit
#define PSU_MIN_VOLTAGE 150 //1V/bit
#define PSU_MAX_CURRENT 133  //1A/bit
#define PSU_MIN_CURRENT 1  //1A/bit
#define PSU_MAX_POWER   40000 //1W/bit

#define PSU_NUM 1

/* Dynamic LV clamp (CS60 hv_limit): active only on overload at low bus voltage. */
#define PSU_LV_CLAMP_V              499u
#define PSU_HV_LIMIT_ON_THRESHOLD   480u
#define PSU_HV_LIMIT_OFF_THRESHOLD  495u
#define PSU_HV_SWITCH_DELAY_MS      1000u
#define PSU_HV_LOAD_CURRENT         300u   /* 30.0 A, MeasuredCurrent is 0.1 A/bit */
#define PSU_HV_LIMIT_MAX_COUNT      3u

/* Fast discharge: PSU off/on cycle on step-down setpoint (unloaded bus). */
#define PSD_ENABLE                    1u
#define PSD_MAX_CMD_CURRENT_0P1A      20u   /* 2.0 A */
#define PSD_MAX_MEASURED_CURRENT_0P1A   30u   /* 3.0 A */
#define PSD_MEASURED_LATCH_MS         500u
#define PSD_MIN_VOLTAGE_STEP_V        50u
#define PSD_DISCHARGE_MARGIN_V        15u
#define PSD_DEBOUNCE_MS               2000u
#define PSD_MAX_PER_SESSION           4u
#define PSD_OFF_TIMEOUT_MS            10000u /* как PSU_WAIT_ACK_OFF */
#define PSD_ON_TIMEOUT_MS             10000u
#define PSD_ON_RETRY_MS               500u   /* повтор SET+ON в ON_WAIT */
#define PSD_PRECHARGE_TOLERANCE_V     40u   /* ~±10% for 350 V precharge window */
