Skip to content

Commit b1d3070

Browse files
authored
Merge pull request #14 from arduino-libraries/ctrl-sw1/3
Allow software control of Buck/Boost SW1
2 parents 1bf0873 + 4cc32a1 commit b1d3070

File tree

6 files changed

+117
-0
lines changed

6 files changed

+117
-0
lines changed

src/PF1550.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,27 @@ void PF1550::configLDO3(Ldo3Voltage const ldo_3_volt, bool const enable, bool co
125125
else _control.turnLDO3Off(Ldo3Mode::Sleep);
126126
}
127127

128+
void PF1550::configSw1(Sw1Voltage const sw1_volt,
129+
Sw1Voltage const sw1_volt_standby,
130+
Sw1Voltage const sw1_volt_sleep,
131+
Sw1CurrentLimit const sw1_current_limit,
132+
bool const enable,
133+
bool const enable_in_standby,
134+
bool const enable_in_sleep)
135+
{
136+
_control.setSw1Voltage (sw1_volt);
137+
_control.setSw1VoltageStandby(sw1_volt_standby);
138+
_control.setSw1VoltageSleep (sw1_volt_sleep);
139+
_control.setSw1CurrentLimit (sw1_current_limit);
140+
141+
if(enable) _control.turnSw1On (Sw1Mode::Normal);
142+
else _control.turnSw1Off(Sw1Mode::Normal);
143+
if(enable_in_standby) _control.turnSw1On (Sw1Mode::Standby);
144+
else _control.turnSw1Off(Sw1Mode::Standby);
145+
if(enable_in_sleep) _control.turnSw1On (Sw1Mode::Sleep);
146+
else _control.turnSw1Off(Sw1Mode::Sleep);
147+
}
148+
128149
void PF1550::configSw2(Sw2Voltage const sw2_volt,
129150
Sw2Voltage const sw2_volt_standby,
130151
Sw2Voltage const sw2_volt_sleep,

src/PF1550.h

+14
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ class PF1550
6161
void configLDO2(Ldo2Voltage const ldo_2_volt, bool const enable, bool const enable_in_standby, bool const enable_in_sleep);
6262
void configLDO3(Ldo3Voltage const ldo_3_volt, bool const enable, bool const enable_in_standby, bool const enable_in_sleep);
6363

64+
void configSw1(Sw1Voltage const sw1_volt,
65+
Sw1Voltage const sw1_volt_standby,
66+
Sw1Voltage const sw1_volt_sleep,
67+
Sw1CurrentLimit const sw1_current_limit,
68+
bool const enable,
69+
bool const enable_in_standby,
70+
bool const enable_in_sleep)
71+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_NICLA_VISION)
72+
__attribute__ ((error("Erroneous usage of this API can cause board damage.")))
73+
#elif defined(ARDUINO_PORTENTA_H33)
74+
__attribute__ ((warning("Using this API you can turn off ESP32 (WiFi), SE051 (Crypto) and Ethernet PHY. Proceed with caution.")))
75+
#endif
76+
;
77+
6478
void configSw2(Sw2Voltage const sw2_volt,
6579
Sw2Voltage const sw2_volt_standby,
6680
Sw2Voltage const sw2_volt_sleep,

src/PF1550/PF1550_Control.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,41 @@ void PF1550_Control::turnLDO3Off(Ldo3Mode const mode)
118118
_io.clrBit(Register::PMIC_LDO3_CTRL, static_cast<uint8_t>(mode));
119119
}
120120

121+
void PF1550_Control::setSw1Voltage(Sw1Voltage const sw1_volt)
122+
{
123+
writeReg(Register::PMIC_SW1_VOLT, static_cast<uint8_t>(sw1_volt));
124+
}
125+
126+
void PF1550_Control::setSw1VoltageStandby(Sw1Voltage const sw1_volt_standby)
127+
{
128+
writeReg(Register::PMIC_SW1_STBY_VOLT, static_cast<uint8_t>(sw1_volt_standby));
129+
}
130+
131+
void PF1550_Control::setSw1VoltageSleep(Sw1Voltage const sw1_volt_sleep)
132+
{
133+
writeReg(Register::PMIC_SW1_SLP_VOLT, static_cast<uint8_t>(sw1_volt_sleep));
134+
}
135+
136+
void PF1550_Control::setSw1CurrentLimit(Sw1CurrentLimit const sw1_current_limit)
137+
{
138+
uint8_t sw1_ctrl1_reg;
139+
_io.readRegister(Register::PMIC_SW1_CTRL1, &sw1_ctrl1_reg);
140+
sw1_ctrl1_reg &= ~REG_SW1_CTRL1_SW1_ILIM_mask;
141+
sw1_ctrl1_reg |= static_cast<uint8_t>(sw1_current_limit);
142+
143+
writeReg(Register::PMIC_SW1_CTRL1, sw1_ctrl1_reg);
144+
}
145+
146+
void PF1550_Control::turnSw1On(Sw1Mode const mode)
147+
{
148+
_io.setBit(Register::PMIC_SW1_CTRL, static_cast<uint8_t>(mode));
149+
}
150+
151+
void PF1550_Control::turnSw1Off(Sw1Mode const mode)
152+
{
153+
_io.clrBit(Register::PMIC_SW1_CTRL, static_cast<uint8_t>(mode));
154+
}
155+
121156
void PF1550_Control::setSw2Voltage(Sw2Voltage const sw2_volt)
122157
{
123158
writeReg(Register::PMIC_SW2_VOLT, static_cast<uint8_t>(sw2_volt));

src/PF1550/PF1550_Control.h

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class PF1550_Control
6565
void turnLDO3On (Ldo3Mode const mode);
6666
void turnLDO3Off (Ldo3Mode const mode);
6767

68+
/* SW1 Configuration ********************************************************/
69+
void setSw1Voltage (Sw1Voltage const sw1_volt);
70+
void setSw1VoltageStandby(Sw1Voltage const sw1_volt_standby);
71+
void setSw1VoltageSleep (Sw1Voltage const sw1_volt_sleep);
72+
void setSw1CurrentLimit (Sw1CurrentLimit const sw1_current_limit);
73+
void turnSw1On (Sw1Mode const mode);
74+
void turnSw1Off (Sw1Mode const mode);
75+
6876
/* SW2 Configuration ********************************************************/
6977
void setSw2Voltage (Sw2Voltage const sw2_volt);
7078
void setSw2VoltageStandby(Sw2Voltage const sw2_volt_standby);

src/PF1550/PF1550_Defines.h

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
#define REG_INT_CATEGORY_TEMP_INT_bp (6)
3434
#define REG_INT_CATEGORY_MISC_INT_bp (7)
3535

36+
/* SW1_CTRL1 ******************************************************************/
37+
#define REG_SW1_CTRL1_SW1_ILIM_mask (0x03)
38+
39+
/* SW1_CTRL *******************************************************************/
40+
#define REG_SW1_CTRL_SW1_EN_bp (0)
41+
#define REG_SW1_CTRL_SW1_STBY_EN_bp (1)
42+
#define REG_SW1_CTRL_SW1_OMODE_bp (2)
43+
3644
/* SW2_CTRL *******************************************************************/
3745
#define REG_SW2_CTRL_SW2_EN_bp (0)
3846
#define REG_SW2_CTRL_SW2_STBY_EN_bp (1)

src/PF1550/PF1550_Types.h

+31
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,37 @@ enum class IInputCurrentLimit : uint8_t
219219
I_1500_mA = (0x14 << 3),
220220
};
221221

222+
enum class Sw1Voltage : uint8_t
223+
{
224+
/* Output voltage with DVS disabled (OTP_SWx_DVS_SEL = 1).
225+
* This is necessary because otherwise we won't reach the
226+
* voltages required by Envie H747/C33 which is 3V1/3V3 for SW1.
227+
*/
228+
V_1_10 = 0x00,
229+
V_1_20 = 0x01,
230+
V_1_35 = 0x02,
231+
V_1_50 = 0x03,
232+
V_1_80 = 0x04,
233+
V_2_50 = 0x05,
234+
V_3_00 = 0x06,
235+
V_3_30 = 0x07,
236+
};
237+
238+
enum class Sw1CurrentLimit : uint8_t
239+
{
240+
I_1_0_A = 0x00,
241+
I_1_2_A = 0x01,
242+
I_1_5_A = 0x02,
243+
I_2_0_A = 0x03,
244+
};
245+
246+
enum class Sw1Mode : uint8_t
247+
{
248+
Normal = REG_SW1_CTRL_SW1_EN_bp,
249+
Standby = REG_SW1_CTRL_SW1_STBY_EN_bp,
250+
Sleep = REG_SW1_CTRL_SW1_OMODE_bp,
251+
};
252+
222253
enum class Sw2Voltage : uint8_t
223254
{
224255
/* Output voltage with DVS disabled (OTP_SWx_DVS_SEL = 1).

0 commit comments

Comments
 (0)