/**
 * \file    sys_defs.h
 * \brief   System definitions
 * 
 * \par     Copyright (c) 2019 UWE Technologies Corp., Ltd. All Rights Reserved.
 * \author  NB1
 * \date    2019-06-27
 * \version 
 * 
 * \history 
 *  Date        Note
 *  2019-06-27  Original Creation
 * 
 */
 
#ifndef __SYS_DEFS_H_
#define __SYS_DEFS_H_


/** Enable SC8812A power chip */
#define SYS_POWER_CHIP_SC8812A_ENABLED      (0)

/** Enable internal 431 power control */
#define SYS_POWER_431_ENABLED               (0)

/** Voltage control by PWM */
#define SYS_PWM_CTRL_VOLT_ENABLED           (0)
#define SYS_PWM_STEP_CTRL_VOLT_ENABLED      (1)
#define SYS_PWM_INDEX_FOR_VOLT_CTRL         (1)


/** Default voltage factor, 
 *  for PWM     - configure initial PWM duty
 *  for 431     - configure initial 431 control value
 *  for SCxxxx  - configure VBUSREF_I_SET
 */
#define SYS_DEF_PWM_PER                     (0x0528)
#define SYS_DEF_PWM_DUTY_5V                 (0x04AE0528UL)
#define SYS_DEF_PWM_DUTY_9V                 (0x03800528UL)
#define SYS_DEF_PWM_DUTY_12V                (0x02810528UL)
#define SYS_DEF_PWM_DUTY_15V                (0x01A80528UL)
#define SYS_DEF_PWM_DUTY_20V                (0x001A0528UL)
#define SYS_DEF_PWM_DUTY_STEP_VOLT          (12)

#define SYS_PPS_VOLT_MIN                    (5000U)
#define SYS_PPS_PWM_DUTY_MIN                (SYS_DEF_PWM_DUTY_5V)
/** 3.3-5.9V PWM duty */
#define SYS_PPS_0_PWM_DUTY_MIN              (SYS_PPS_PWM_DUTY_MIN)
#define SYS_PPS_0_PWM_DUTY_MAX              (0x04690528UL)
/** 3.3-11V PWM duty */
#define SYS_PPS_1_PWM_DUTY_MIN              (SYS_PPS_PWM_DUTY_MIN)
#define SYS_PPS_1_PWM_DUTY_MAX              (0x02D60528UL)
/** 3.3-16V PWM duty */
#define SYS_PPS_2_PWM_DUTY_MIN              (SYS_PPS_PWM_DUTY_MIN)
#define SYS_PPS_2_PWM_DUTY_MAX              (0x01590528UL)
/** 3.3-21V PWM duty */
#define SYS_PPS_3_PWM_DUTY_MIN              (SYS_PPS_PWM_DUTY_MIN)
#define SYS_PPS_3_PWM_DUTY_MAX              (0x000B0528UL)

#define SYS_PPS_VOLT_STEP                   (20)


/** System IBUS sample resister: 10 milliohm */
#define SYS_IBUS_SAMPLE_RESISTER            (10)


/** Enable or disable OLED display mode */
#define SYS_OLED_DISPLAY_ENABLED			(0)


/** System reset to factory default enabled */
#define SYS_RESET_TO_FACTORY_ENABLED        (1)
/** System reset to factory default pin holding time(ms) */
#define SYS_RESET_TO_FACTORY_PIN_HOLDING_TIME   (10000000UL)


/** Voltage compensation enabled */
#define SYS_VOLTAGE_COMPENSATION_ENABLED            (0)


/** Quick charge enabled */
#define SYS_QUICK_CHARGE_ENABLED            (0)


#define SYS_POWER_BANK_ENABLED              (0)
#define SYS_POWER_BANK_POWER_DOWN_DETECT    (1)
#define SYS_POWER_BANK_AUTO_POWER_DOWN_EN   (1)
#define SYS_POWER_BANK_POWER_DOWN_DETECT_DURATION   (3000000UL)     /* 3s, system tick */
#define SYS_POWER_BANK_POWER_DOWN_DETECT_DURATION_UL    (10000000UL) /* 10s, system tick */
#define SYS_POWER_BANK_AUTO_POWER_DOWN_DELAY        (300U)  /* 30s, pd tick */
#define SYS_POWER_BANK_IDLE_DETECT_DURATION        (50U)  /* 5s, pd tick */
#define SYS_POWER_BANK_BATTERY_CELL_CFG     (1)
#define SYS_POWER_BANK_CHECK_DEAD_BATTERY_CNT   (2)
#define SYS_POWER_BANK_DICCHARGE_CURRENT_COMPENSATION_RATIO (1.1)
#define SYS_POWER_BANK_DICCHARGE_CURRENT_COMPENSATION_RATIO2 (1.2)
#define SYS_POWER_BANK_CURRENT_COMPENSATION (100U)
#define SYS_POWER_BANK_CURRENT_COMPENSATION_2 (100U)
#define SYS_POWER_BANK_VOLTAGE_COMPENSATION (200U)
#define SYS_POWER_BANK_CHARGE_RATIO         (0.90)

// system force power off when low current mode entered 4 hours about, unit is 100ms
#define SYS_LOW_CURRENT_MODE_FORCE_POWER_OFF_TIME       (144000UL)


/** Enable or disable system voltage over protection control */
#define SYS_OVP_CTL_ENABLED                 (0)

#define SYS_OCP_CURRENT_MAX_COMPENSATION    (500)


/** Enable or disable system power limitation, base on hardware design */
#define SYS_POWER_LIMITED_ENABLED           (0)

/** Enabled HUB */
#define SYS_HUB_ENABLED                     (0)


#define SYS_LED_ENABLED                     (1)

/** Enable or disable 7-segment display mode */
#define SYS_SMG_DISPLAY_ENABLED			    (0)

#if SYS_HUB_ENABLED  /* modified by James Gan - 2019-11-22 */
#define SYS_HUB_LED_ENABLED                 (1)
#else
#define SYS_HUB_LED_ENABLED                 (0)
#endif /* #if SYS_HUB_ENABLED */

#define SYS_LED_NUM                         (11)

#define SYS_LED_DISPLAY_DURATION_ENABLED    (1)

// System LED display duration, 40s, unit is 100ms
#define SYS_LED_DISPLAY_DURATION            (400)

// System LED short display duration, 10s, unit is 100ms
#define SYS_LED_DISPLAY_DURATION_SHORT      (100)


#define SYS_CAPACITY_PARA_SAVE_TO_FLASH  	(1)
#define SYS_CAPACITY_PARA_SAVE_ADDR         (0x3000)


#define SYS_BAT_CAP_INTEGRAL_METHOD_ENABLED (1)


#define SYS_OVERTEMP_DECTION_ENABLED        (1)


#define SYS_POWER_POLICY_DISABLED           (0)

/** Current sense resistance value of sample resister (milli-ohm) */
#define SYS_CURRENT_SENCE_SAMPLE_RESISTER   (10)


#define SYS_POWER_KEY_DOUBLE_CLICK_CTRL     (0)


#define SYS_POWER_SOURCE_NO_CURRENT_HRST    (0)

/** Enabled watchdog */
#define SYS_WDT_ENABLED                     (1)


#endif /* #ifndef __SYS_DEFS_H_ */

