Skip to content

Allow software control of Buck/Boost SW1 #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/PF1550.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,27 @@ void PF1550::configLDO3(Ldo3Voltage const ldo_3_volt, bool const enable, bool co
else _control.turnLDO3Off(Ldo3Mode::Sleep);
}

void PF1550::configSw1(Sw1Voltage const sw1_volt,
Sw1Voltage const sw1_volt_standby,
Sw1Voltage const sw1_volt_sleep,
Sw1CurrentLimit const sw1_current_limit,
bool const enable,
bool const enable_in_standby,
bool const enable_in_sleep)
{
_control.setSw1Voltage (sw1_volt);
_control.setSw1VoltageStandby(sw1_volt_standby);
_control.setSw1VoltageSleep (sw1_volt_sleep);
_control.setSw1CurrentLimit (sw1_current_limit);

if(enable) _control.turnSw1On (Sw1Mode::Normal);
else _control.turnSw1Off(Sw1Mode::Normal);
if(enable_in_standby) _control.turnSw1On (Sw1Mode::Standby);
else _control.turnSw1Off(Sw1Mode::Standby);
if(enable_in_sleep) _control.turnSw1On (Sw1Mode::Sleep);
else _control.turnSw1Off(Sw1Mode::Sleep);
}

void PF1550::configSw2(Sw2Voltage const sw2_volt,
Sw2Voltage const sw2_volt_standby,
Sw2Voltage const sw2_volt_sleep,
Expand Down
14 changes: 14 additions & 0 deletions src/PF1550.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ class PF1550
void configLDO2(Ldo2Voltage const ldo_2_volt, bool const enable, bool const enable_in_standby, bool const enable_in_sleep);
void configLDO3(Ldo3Voltage const ldo_3_volt, bool const enable, bool const enable_in_standby, bool const enable_in_sleep);

void configSw1(Sw1Voltage const sw1_volt,
Sw1Voltage const sw1_volt_standby,
Sw1Voltage const sw1_volt_sleep,
Sw1CurrentLimit const sw1_current_limit,
bool const enable,
bool const enable_in_standby,
bool const enable_in_sleep)
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_NICLA_VISION)
__attribute__ ((error("Erroneous usage of this API can cause board damage.")))
#elif defined(ARDUINO_PORTENTA_H33)
__attribute__ ((warning("Using this API you can turn off ESP32 (WiFi), SE051 (Crypto) and Ethernet PHY. Proceed with caution.")))
#endif
;

void configSw2(Sw2Voltage const sw2_volt,
Sw2Voltage const sw2_volt_standby,
Sw2Voltage const sw2_volt_sleep,
Expand Down
35 changes: 35 additions & 0 deletions src/PF1550/PF1550_Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,41 @@ void PF1550_Control::turnLDO3Off(Ldo3Mode const mode)
_io.clrBit(Register::PMIC_LDO3_CTRL, static_cast<uint8_t>(mode));
}

void PF1550_Control::setSw1Voltage(Sw1Voltage const sw1_volt)
{
writeReg(Register::PMIC_SW1_VOLT, static_cast<uint8_t>(sw1_volt));
}

void PF1550_Control::setSw1VoltageStandby(Sw1Voltage const sw1_volt_standby)
{
writeReg(Register::PMIC_SW1_STBY_VOLT, static_cast<uint8_t>(sw1_volt_standby));
}

void PF1550_Control::setSw1VoltageSleep(Sw1Voltage const sw1_volt_sleep)
{
writeReg(Register::PMIC_SW1_SLP_VOLT, static_cast<uint8_t>(sw1_volt_sleep));
}

void PF1550_Control::setSw1CurrentLimit(Sw1CurrentLimit const sw1_current_limit)
{
uint8_t sw1_ctrl1_reg;
_io.readRegister(Register::PMIC_SW1_CTRL1, &sw1_ctrl1_reg);
sw1_ctrl1_reg &= ~REG_SW1_CTRL1_SW1_ILIM_mask;
sw1_ctrl1_reg |= static_cast<uint8_t>(sw1_current_limit);

writeReg(Register::PMIC_SW1_CTRL1, sw1_ctrl1_reg);
}

void PF1550_Control::turnSw1On(Sw1Mode const mode)
{
_io.setBit(Register::PMIC_SW1_CTRL, static_cast<uint8_t>(mode));
}

void PF1550_Control::turnSw1Off(Sw1Mode const mode)
{
_io.clrBit(Register::PMIC_SW1_CTRL, static_cast<uint8_t>(mode));
}

void PF1550_Control::setSw2Voltage(Sw2Voltage const sw2_volt)
{
writeReg(Register::PMIC_SW2_VOLT, static_cast<uint8_t>(sw2_volt));
Expand Down
8 changes: 8 additions & 0 deletions src/PF1550/PF1550_Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ class PF1550_Control
void turnLDO3On (Ldo3Mode const mode);
void turnLDO3Off (Ldo3Mode const mode);

/* SW1 Configuration ********************************************************/
void setSw1Voltage (Sw1Voltage const sw1_volt);
void setSw1VoltageStandby(Sw1Voltage const sw1_volt_standby);
void setSw1VoltageSleep (Sw1Voltage const sw1_volt_sleep);
void setSw1CurrentLimit (Sw1CurrentLimit const sw1_current_limit);
void turnSw1On (Sw1Mode const mode);
void turnSw1Off (Sw1Mode const mode);

/* SW2 Configuration ********************************************************/
void setSw2Voltage (Sw2Voltage const sw2_volt);
void setSw2VoltageStandby(Sw2Voltage const sw2_volt_standby);
Expand Down
8 changes: 8 additions & 0 deletions src/PF1550/PF1550_Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
#define REG_INT_CATEGORY_TEMP_INT_bp (6)
#define REG_INT_CATEGORY_MISC_INT_bp (7)

/* SW1_CTRL1 ******************************************************************/
#define REG_SW1_CTRL1_SW1_ILIM_mask (0x03)

/* SW1_CTRL *******************************************************************/
#define REG_SW1_CTRL_SW1_EN_bp (0)
#define REG_SW1_CTRL_SW1_STBY_EN_bp (1)
#define REG_SW1_CTRL_SW1_OMODE_bp (2)

/* SW2_CTRL *******************************************************************/
#define REG_SW2_CTRL_SW2_EN_bp (0)
#define REG_SW2_CTRL_SW2_STBY_EN_bp (1)
Expand Down
31 changes: 31 additions & 0 deletions src/PF1550/PF1550_Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,37 @@ enum class IInputCurrentLimit : uint8_t
I_1500_mA = (0x14 << 3),
};

enum class Sw1Voltage : uint8_t
{
/* Output voltage with DVS disabled (OTP_SWx_DVS_SEL = 1).
* This is necessary because otherwise we won't reach the
* voltages required by Envie H747/C33 which is 3V1/3V3 for SW1.
*/
V_1_10 = 0x00,
V_1_20 = 0x01,
V_1_35 = 0x02,
V_1_50 = 0x03,
V_1_80 = 0x04,
V_2_50 = 0x05,
V_3_00 = 0x06,
V_3_30 = 0x07,
};

enum class Sw1CurrentLimit : uint8_t
{
I_1_0_A = 0x00,
I_1_2_A = 0x01,
I_1_5_A = 0x02,
I_2_0_A = 0x03,
};

enum class Sw1Mode : uint8_t
{
Normal = REG_SW1_CTRL_SW1_EN_bp,
Standby = REG_SW1_CTRL_SW1_STBY_EN_bp,
Sleep = REG_SW1_CTRL_SW1_OMODE_bp,
};

enum class Sw2Voltage : uint8_t
{
/* Output voltage with DVS disabled (OTP_SWx_DVS_SEL = 1).
Expand Down