Skip to content

Commit

Permalink
Enhanced XPowersLibInterface #26
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Aug 30, 2024
1 parent 44fdd6e commit 84bb40b
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 48 deletions.
28 changes: 16 additions & 12 deletions src/XPowersAXP192.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,6 @@ typedef enum {
XPOWERS_AXP192_LONGPRESS_2500MS,
} xpowers_axp192_pekey_long_press_t;

typedef enum {
XPOWERS_AXP192_VBUS_VOL_LIM_4V,
XPOWERS_AXP192_VBUS_VOL_LIM_4V1,
XPOWERS_AXP192_VBUS_VOL_LIM_4V2,
XPOWERS_AXP192_VBUS_VOL_LIM_4V3,
XPOWERS_AXP192_VBUS_VOL_LIM_4V4,
XPOWERS_AXP192_VBUS_VOL_LIM_4V5,
XPOWERS_AXP192_VBUS_VOL_LIM_4V6,
XPOWERS_AXP192_VBUS_VOL_LIM_4V7,
} xpowers_axp192_vbus_vol_limit_t;

typedef enum {
XPOWERS_AXP192_CHG_CONS_TIMEOUT_7H,
XPOWERS_AXP192_CHG_CONS_TIMEOUT_8H,
Expand Down Expand Up @@ -271,14 +260,29 @@ public:
clrRegisterBit(XPOWERS_AXP192_IPS_SET, 6);
}

void setVbusVoltageLimit(xpowers_axp192_vbus_vol_limit_t opt)
/**
* @brief Set VBUS Voltage Input Limit.
* @param opt: View the related chip type xpowers_axp192_vbus_vol_limit_t enumeration
* parameters in "XPowersParams.hpp"
*/
void setVbusVoltageLimit(uint8_t opt)
{
int val = readRegister(XPOWERS_AXP192_IPS_SET);
if (val == -1)return;
val &= 0xC7;
writeRegister(XPOWERS_AXP192_IPS_SET, val | (opt << 3));
}

/**
* @brief Get VBUS Voltage Input Limit.
* @retval View the related chip type xpowers_axp192_vbus_vol_limit_t enumeration
* parameters in "XPowersParams.hpp"
*/
uint8_t getVbusVoltageLimit(void)
{
return (readRegister(XPOWERS_AXP192_IPS_SET) >> 3 ) & 0x7;
}

/**
* @brief Set VBUS Current Input Limit.
* @param opt: View the related chip type xpowers_axp192_vbus_cur_limit_t enumeration
Expand Down
28 changes: 16 additions & 12 deletions src/XPowersAXP202.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@ typedef enum {
XPOWERS_AXP202_LONGPRESS_2500MS,
} xpowers_axp202_pekey_long_press_t;

typedef enum {
XPOWERS_AXP202_VBUS_VOL_LIM_4V,
XPOWERS_AXP202_VBUS_VOL_LIM_4V1,
XPOWERS_AXP202_VBUS_VOL_LIM_4V2,
XPOWERS_AXP202_VBUS_VOL_LIM_4V3,
XPOWERS_AXP202_VBUS_VOL_LIM_4V4,
XPOWERS_AXP202_VBUS_VOL_LIM_4V5,
XPOWERS_AXP202_VBUS_VOL_LIM_4V6,
XPOWERS_AXP202_VBUS_VOL_LIM_4V7,
} xpowers_axp202_vbus_vol_limit_t;


typedef enum {
XPOWERS_AXP202_CHG_CONS_TIMEOUT_7H,
Expand Down Expand Up @@ -253,14 +242,29 @@ public:
clrRegisterBit(XPOWERS_AXP202_IPS_SET, 6);
}

void setVbusVoltageLimit(xpowers_axp202_vbus_vol_limit_t opt)
/**
* @brief Set VBUS Voltage Input Limit.
* @param opt: View the related chip type xpowers_axp202_vbus_vol_limit_t enumeration
* parameters in "XPowersParams.hpp"
*/
void setVbusVoltageLimit(uint8_t opt)
{
int val = readRegister(XPOWERS_AXP202_IPS_SET);
if (val == -1)return;
val &= 0xC7;
writeRegister(XPOWERS_AXP202_IPS_SET, val | (opt << 3));
}

/**
* @brief Get VBUS Voltage Input Limit.
* @retval View the related chip type xpowers_axp202_vbus_vol_limit_t enumeration
* parameters in "XPowersParams.hpp"
*/
uint8_t getVbusVoltageLimit(void)
{
return (readRegister(XPOWERS_AXP202_IPS_SET) >> 3 ) & 0x7;
}

/**
* @brief Set VBUS Current Input Limit.
* @param opt: View the related chip type xpowers_axp202_vbus_cur_limit_t enumeration
Expand Down
36 changes: 12 additions & 24 deletions src/XPowersAXP2101.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,6 @@ typedef enum {
XPOWERS_AXP2101_WDT_TIMEOUT_128S,
} xpowers_wdt_timeout_t;



typedef enum {
XPOWERS_AXP2101_VBUS_VOL_LIM_3V88,
XPOWERS_AXP2101_VBUS_VOL_LIM_3V96,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V04,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V12,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V20,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V28,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V36,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V44,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V52,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V60,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V68,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V76,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V84,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V92,
XPOWERS_AXP2101_VBUS_VOL_LIM_5V,
XPOWERS_AXP2101_VBUS_VOL_LIM_5V08,
} xpower_vbus_vol_limit_t;

typedef enum {
XPOWERS_AXP2101_VSYS_VOL_4V1,
XPOWERS_AXP2101_VSYS_VOL_4V2,
Expand Down Expand Up @@ -488,16 +467,25 @@ public:
return (val & 0x70) >> 4;
}

// Set the minimum common working voltage of the PMU VBUS input,
// below this value will turn off the PMU
void setVbusVoltageLimit(xpower_vbus_vol_limit_t opt)

/**
* @brief Set VBUS Voltage Input Limit.
* @param opt: View the related chip type xpowers_axp2101_vbus_vol_limit_t enumeration
* parameters in "XPowersParams.hpp"
*/
void setVbusVoltageLimit(uint8_t opt)
{
int val = readRegister(XPOWERS_AXP2101_INPUT_VOL_LIMIT_CTRL);
if (val == -1)return;
val &= 0xF0;
writeRegister(XPOWERS_AXP2101_INPUT_VOL_LIMIT_CTRL, val | (opt & 0x0F));
}

/**
* @brief Get VBUS Voltage Input Limit.
* @retval View the related chip type xpowers_axp2101_vbus_vol_limit_t enumeration
* parameters in "XPowersParams.hpp"
*/
uint8_t getVbusVoltageLimit(void)
{
return (readRegister(XPOWERS_AXP2101_INPUT_VOL_LIMIT_CTRL) & 0x0F);
Expand Down
16 changes: 16 additions & 0 deletions src/XPowersLibInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,22 @@ class XPowersLibInterface : public HasBatteryLevel
virtual uint8_t getVbusCurrentLimit(void) = 0;


/**
* @brief Set VBUS Voltage Input Limit.
* @param opt: View the related chip type xpowers_axpxxx_vbus_vol_limit_t enumeration
* parameters in "XPowersParams.hpp"
*
*/
virtual void setVbusVoltageLimit(uint8_t opt) = 0;

/**
* @brief Get VBUS Voltage Input Limit.
* @retval View the related chip type xpowers_axpxxx_vbus_vol_limit_t enumeration
* parameters in "XPowersParams.hpp"
*/
virtual uint8_t getVbusVoltageLimit(void) = 0;


// SYS
/**
* @brief Get PMU SYS main Voltage
Expand Down
45 changes: 45 additions & 0 deletions src/XPowersParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,51 @@ typedef enum {
XPOWERS_AXP202_VBUS_CUR_LIM_OFF,
} xpowers_axp202_vbus_cur_limit_t;


typedef enum {
XPOWERS_AXP192_VBUS_VOL_LIM_4V,
XPOWERS_AXP192_VBUS_VOL_LIM_4V1,
XPOWERS_AXP192_VBUS_VOL_LIM_4V2,
XPOWERS_AXP192_VBUS_VOL_LIM_4V3,
XPOWERS_AXP192_VBUS_VOL_LIM_4V4,
XPOWERS_AXP192_VBUS_VOL_LIM_4V5,
XPOWERS_AXP192_VBUS_VOL_LIM_4V6,
XPOWERS_AXP192_VBUS_VOL_LIM_4V7,
} xpowers_axp192_vbus_vol_limit_t;

typedef enum {
XPOWERS_AXP202_VBUS_VOL_LIM_4V,
XPOWERS_AXP202_VBUS_VOL_LIM_4V1,
XPOWERS_AXP202_VBUS_VOL_LIM_4V2,
XPOWERS_AXP202_VBUS_VOL_LIM_4V3,
XPOWERS_AXP202_VBUS_VOL_LIM_4V4,
XPOWERS_AXP202_VBUS_VOL_LIM_4V5,
XPOWERS_AXP202_VBUS_VOL_LIM_4V6,
XPOWERS_AXP202_VBUS_VOL_LIM_4V7,
} xpowers_axp202_vbus_vol_limit_t;

typedef enum {
XPOWERS_AXP2101_VBUS_VOL_LIM_3V88,
XPOWERS_AXP2101_VBUS_VOL_LIM_3V96,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V04,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V12,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V20,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V28,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V36,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V44,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V52,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V60,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V68,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V76,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V84,
XPOWERS_AXP2101_VBUS_VOL_LIM_4V92,
XPOWERS_AXP2101_VBUS_VOL_LIM_5V,
XPOWERS_AXP2101_VBUS_VOL_LIM_5V08,
} xpower_apx2101_vbus_vol_limit_t;




/**
* @brief XPowersLibInterface interrupt control mask parameters.
* Common interrupt interfaces
Expand Down

0 comments on commit 84bb40b

Please sign in to comment.