Skip to content

Commit 742ff1b

Browse files
committed
Add destructor for Board
1 parent e771c95 commit 742ff1b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Diff for: src/Board.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ Board::Board() {
5050
#endif
5151
}
5252

53+
Board::~Board() {
54+
#if defined(ARDUINO_PORTENTA_C33)
55+
delete lowPower;
56+
#endif
57+
}
58+
5359
bool Board::begin() {
5460
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION)
5561
if (CM7_CPUID == HAL_GetCurrentCPUID()){
@@ -64,13 +70,15 @@ bool Board::begin() {
6470

6571
bool Board::isUSBPowered() {
6672
uint16_t registerValue = PMIC.readPMICreg(Register::CHARGER_VBUS_SNS);
67-
return bitRead(registerValue, 2) == 0;
73+
// TODO: Check which one works
74+
// return bitRead(registerValue, 2) == 0;
75+
return bitRead(registerValue, 5) == 1; // — VBUS is valid -> USB powered
6876
}
6977

7078
bool Board::isBatteryPowered() {
7179
uint8_t registerValue = PMIC.readPMICreg(Register::CHARGER_BATT_SNS);
7280
uint8_t batteryPower = extractBits(registerValue, 0, 2);
73-
return batteryPower == 0;
81+
return batteryPower == 0; // No valid VBUS input -> battery powered
7482
}
7583

7684
void Board::setExternalPowerEnabled(bool on) {

Diff for: src/Board.h

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class Board {
4949
*/
5050
Board();
5151

52+
/**
53+
* @brief Destroy the Board object.
54+
*/
55+
~Board();
56+
5257
/**
5358
* @brief Initializes the board by initiating the PMIC.
5459
*

0 commit comments

Comments
 (0)