diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index e8fe54f..2828d99 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -1,3 +1,4 @@ +# Source: https://github.com/per1234/.github/blob/main/workflow-templates/compile-examples-private.md name: Compile Examples # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows @@ -22,9 +23,9 @@ on: env: UNIVERSAL_SKETCH_PATHS: | - - examples/Battery - - examples/Charger - - examples/Standby_WakeFromPin + - examples/Battery + - examples/Charger + - examples/Standby_WakeFromPin SKETCHES_REPORTS_PATH: sketches-reports SKETCHES_REPORTS_ARTIFACT_NAME: sketches-reports @@ -41,18 +42,17 @@ jobs: matrix: board: - - fqbn: arduino:renesas_portenta:portenta_c33 - platforms: | - - name: arduino:renesas_portenta - artifact-name-suffix: arduino-renesas_portenta-portenta_c33 - additional-sketch-paths: examples/ChargStandby_WakeFromRTC_C33er - fqbn: arduino:mbed_portenta:envie_m7 platforms: | - name: arduino:mbed_portenta artifact-name-suffix: arduino-mbed_portenta-envie_m7 + additional-sketch-paths: examples/Standby_WakeFromRTC_C33 + - fqbn: arduino:renesas_portenta:portenta_c33 + platforms: | + - name: arduino:renesas_portenta + artifact-name-suffix: arduino-renesas_portenta-portenta_c33 additional-sketch-paths: examples/Standby_WakeFromRTC_H7 - steps: - name: Checkout repository uses: actions/checkout@v4 @@ -64,10 +64,8 @@ jobs: fqbn: ${{ matrix.board.fqbn }} platforms: ${{ matrix.board.platforms }} libraries: | - # Install the library from the local path. - source-path: ./ - # - name: Arduino_PF1550 - - source-url: https://github.com/arduino-libraries/Arduino_PF1550.git + - name: Arduino_PF1550 - source-url: https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33.git sketch-paths: | ${{ env.UNIVERSAL_SKETCH_PATHS }} @@ -79,29 +77,5 @@ jobs: uses: actions/upload-artifact@v4 with: if-no-files-found: error + name: sketches-report-${{ matrix.board.artifact-name-suffix }} path: ${{ env.SKETCHES_REPORTS_PATH }} - name: ${{ env.SKETCHES_REPORTS_ARTIFACT_NAME }} - - report-size-deltas: - needs: build - # Run even if some compilations failed. - if: always() && github.event_name == 'pull_request' - runs-on: ubuntu-latest - permissions: - pull-requests: write - - steps: - - name: Download sketches reports artifact - id: download-artifact - continue-on-error: true # If compilation failed for all boards then there are no artifacts - uses: actions/download-artifact@v4 - with: - name: ${{ env.SKETCHES_REPORTS_ARTIFACT_NAME }} - path: ${{ env.SKETCHES_REPORTS_PATH }} - - - name: Comment size deltas report to PR - uses: arduino/report-size-deltas@v1 - # If actions/download-artifact failed, there are no artifacts to report from. - if: steps.download-artifact.outcome == 'success' - with: - sketches-reports-source: ${{ env.SKETCHES_REPORTS_PATH }} \ No newline at end of file diff --git a/examples/DeepSleep_WakeFromRTC_H7/DeepSleep_WakeFromRTC_H7.ino b/examples/DeepSleep_WakeFromRTC_H7/DeepSleep_WakeFromRTC_H7.ino deleted file mode 100644 index f1082c5..0000000 --- a/examples/DeepSleep_WakeFromRTC_H7/DeepSleep_WakeFromRTC_H7.ino +++ /dev/null @@ -1,83 +0,0 @@ -/* - Charger Demo - - This sketch demonstrates how to use the PowerManagement library enable low power modes on the Arduino Portenta H7. - * In the setup() function, it enters standby mode and waits for a wakeup event from the RTC. - * The loop() functionit is not used in this sketch. - - IMPORTANT: Please note that this sketch has to be uploaded to the M4 core too in order to achieve the lowest power consumption. - - Requirements: - - Arduino Arduino Portenta H7 - - Arduino IDE - - PowerManagement library (installable from the Arduino Library Manager) - - Usage: - - 1. Connect a battery to the board. - - 2. Upload the Sketch to the M4 core: - - Open the provided sketch in the Arduino IDE. - - Select your board type and port from the "Tools" menu. - - Select the M4 core from the "Tools" menu. - - Click the "Upload" button to upload the sketch to your board. - - 3. Upload the Sketch to the M7 core: - - Select the M7 core from the "Tools" menu. - - Click the "Upload" button to upload the sketch to your board. - - 4. Observer LED behavior: - - The blue LED will turn on when the board is awake. - - The blue LED will turn off when the board goes to sleep. - - The red LED will blink if the board fails to initialize. -*/ - -#include "Arduino_PowerManagement.h" -#include "MAX1726Driver.h" - -Board board; -Charger charger; -MAX1726Driver fuelgauge(&Wire1); - -void setup() { - // When uploading this sketch to the M4 core, it just goes to standby mode. - #if defined(ARDUINO_GENERIC_STM32H747_M4) - board.standByUntilWakeupEvent(); - return; - #endif - - charger.begin(); - - // Turn off the built-in LED - pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN, HIGH); - - // Turn on the blue LED to show that the board is still awake - pinMode(LEDB, OUTPUT); - digitalWrite(LEDB, LOW); - - if(!board.begin()){ - // If the board fails to initialize, it will blink the red LED - pinMode(LEDR, OUTPUT); - while (true){ - digitalWrite(LEDR, LOW); - delay(1000); - digitalWrite(LEDR, HIGH); - delay(1000); - } - } - - charger.setEnabled(false); // -> Please measure if it makes a difference - delay(10000); // -> Give time to take the measurement - - // Takes 45s to get into shutdown mode - fuelgauge.setOperationMode(FuelGaugeOperationMode::shutdown); - - // The LED should go off when the board goes to sleep - board.setAllPeripheralsPower(false); - - board.enableWakeupFromRTC(0, 0, 60); // Go to standby for 60 seconds - board.standByUntilWakeupEvent(); -} - -void loop() {} \ No newline at end of file diff --git a/examples/Powershell/Powershell.ino b/examples/Powershell/Powershell.ino deleted file mode 100644 index 5ed77cb..0000000 --- a/examples/Powershell/Powershell.ino +++ /dev/null @@ -1,238 +0,0 @@ -#include "PowerManagement.h" -#include -#include - -PowerManagement manager; -Battery battery; -Board board; -Charger charger; - - -std::vector splitString(String input) { - std::vector args; - int start = 0; - int end = input.indexOf(' '); - while (end >= 0) { - args.push_back(input.substring(start, end)); - start = end + 1; - end = input.indexOf(' ', start); - } - args.push_back(input.substring(start)); - return args; -} - - -void printChargerStatus(){ - ChargingState status = charger.getState(); - - switch (status) { - case ChargingState::PreCharge: - Serial.println("precharge"); - // Additional code specific to precharge - break; - case ChargingState::FastChargeConstantCurrent: - Serial.println("fast-charge constant current"); - // Additional code specific to fast-charge CC - break; - case ChargingState::FastChargeConstantVoltage: - Serial.println("fast-charge constant voltage"); - // Additional code specific to fast-charge CV - break; - case ChargingState::EndOfCharge: - Serial.println("end-of-charge"); - // Additional code specific to end-of-charge - break; - case ChargingState::Done: - Serial.println("done"); - // Additional code specific to done - break; - case ChargingState::TimerFaultError: - Serial.println("timer fault"); - // Additional code specific to timer fault - break; - case ChargingState::ThermistorSuspendError: - Serial.println("thermistor suspend"); - // Additional code specific to thermistor suspend - break; - case ChargingState::ChargerDisabled: - Serial.println("off"); - // Additional code specific to off - break; - case ChargingState::BatteryOvervoltageError: - Serial.println("overvoltage condition"); - // Additional code specific to battery overvoltage condition - break; - case ChargingState::ChargerBypassed: - Serial.println("disabled"); - // Additional code specific to linear only - break; - default: - Serial.println("unknown"); - // Additional code for handling unknown status - break; - } -} - -void status(){ - - Serial.println("BOARD: \n--------------------------"); - Serial.print("* Powered by usb: "); Serial.println(board.isUSBPowered()); - Serial.print("* Powered by battery: "); Serial.println(board.isBatteryPowered()); - Serial.println(); - - Serial.println("CHARGER: \n--------------------------"); - Serial.print("* Charger status: "); printChargerStatus(); - Serial.println(); - - Serial.println("BATTERY: \n--------------------------"); - Serial.println( - "* Voltage: " + String(battery.voltage()) + "mV \n" + - "* Current: " + String(battery.current()) + "mA \n" + - "* Percentage: " + String(battery.percentage()) + "% \n" + - "* Remaining Capacity: " + String(battery.remainingCapacity()) + "mAh \n" + - "* Temperature: " + String(battery.temperature()) + "\n" + - "\n"); -} - - -void setRailVoltage(std::vector args){ - String rail = args[1]; - float voltage = atof(args[2].c_str()); - - if(rail == "C33_reference"){ - #if defined(ARDUINO_PORTENTA_C33) - if(board.setReferenceVoltage(voltage)) Serial.println("Successfully changed reference voltage"); - else Serial.println("Failed to set reference voltage"); - #else - Serial.println("Current board is not an arduino portenta c33"); - #endif - } else if (rail == "C33_external"){ - #if defined(ARDUINO_PORTENTA_C33) - if(board.setExternalVoltage(voltage)) Serial.println("Successfully set external voltage"); - else Serial.println("Failed to set external voltage"); - #else - Serial.println("Current board is not an arduino portenta c33"); - #endif - - } else if (rail == "H7_external"){ - #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GENERIC_STM32H747_M4) - board.setExternalVoltage(voltage); - #else - Serial.println("Current board is not an arduino portenta h7"); - #endif - - } else if (rail == "nicla_external"){ - #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GENERIC_STM32H747_M4) - board.setExternalVoltage(voltage); - #else - Serial.println("Current board is not an arduino nicla vision"); - #endif - - } -} - -void toggleRail(std::vector args){ - String rail = args[1]; - bool on = atoi(args[2].c_str()) == 1; - - if (rail == "C33_external"){ - #if defined(ARDUINO_PORTENTA_C33) - board.setExternalPowerEnabled(on); - #else - Serial.println("Current board is not an arduino portenta c33"); - #endif - - } else if (rail == "C33_communication"){ - #if defined(ARDUINO_PORTENTA_C33) - board.setCommunicationPeripheralsPower(on); - #else - Serial.println("Current board is not an arduino portenta c33"); - #endif - - } else if (rail == "H7_external"){ - #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GENERIC_STM32H747_M4) - board.setExternalPowerEnabled(on); - #else - Serial.println("Current board is not an arduino portenta h7"); - #endif - - } else if (rail == "nicla_external"){ - #if defined(ARDUINO_NICLA_VISION) - board.setExternalPowerEnabled(on); - #else - Serial.println("Current board is not an arduino nicla vision"); - #endif - - } else if (rail == "nicla_camera"){ - #if defined(ARDUINO_NICLA_VISION) - board.setCameraPowerEnabled(on); - #else - Serial.println("Current board is not an arduino nicla vision"); - #endif - } -} - -void toggleCharger(std::vector args){ - bool on = atoi(args[1].c_str()) == 1; - Serial.println(on); - - - if(on){ - if(charger.enable()){ - Serial.println("> Charger enabled"); - } else { - Serial.println("> Error enabling charger"); - } - - } else { - charger.disable(); - Serial.println("> Charger disabled"); - } -} - - - -void setup() { - Serial.begin(115200); - while (!Serial); - - manager = PowerManagement(); - manager.begin(); - - battery = manager.getBattery(); - board = manager.getBoard(); - charger = manager.getCharger(); - - - #if !defined(ARDUINO_NICLA_VISION) - charger.setChargeCurrent(0.2); - charger.setChargeVoltage(4.2); - charger.setEndOfChargeCurrent(0.005); - #endif -} - -void loop() { - if (Serial.available() > 0) { - String input = Serial.readString(); - input.trim(); - std::vector args = splitString(input); - - if (args.size() > 0) { - String command = args[0]; - if (command == "toggle_rail") { - toggleRail(args); - } else if (command == "set_rail_voltage") { - setRailVoltage(args); - } else if (command == "toggle_charger") { - toggleCharger(args); - } else if (command == "status") { - status(); - - } else { - Serial.println("Unknown command: " + command); - } - - Serial.println(); - } - } -} \ No newline at end of file diff --git a/examples/Powershell/README.md b/examples/Powershell/README.md deleted file mode 100644 index 9a21dd2..0000000 --- a/examples/Powershell/README.md +++ /dev/null @@ -1,78 +0,0 @@ -# Power ManagemtnInteractive Shell - -This sketch demonstrates the usage of the Power Management library to control and monitor power-related features of different Arduino boards. The sketch allows you to interact with various power management functionalities such as battery monitoring, charging control, and voltage rail adjustments. - -## Instructions - -1. Upload the sketch to your Arduino board. -2. Open the serial monitor at a baud rate of 115200. -3. Use the provided commands to interact with power management features. - -## Commands and Parameters - -### Toggle Rail -Toggle the state of a specific power rail. - -Command: `toggle_rail ` - -- ``: Specify the name of the power rail to toggle. - - Options: `C33_external`, `C33_communication`, `H7_external`, `nicla_external`, `nicla_camera` -- ``: Specify whether to turn the rail on or off. - - Options: `1` (on) or `0` (off) - -### Set Rail Voltage -Set the voltage of a specific power rail. - -Command: `set_rail_voltage ` - -- ``: Specify the name of the power rail to set the voltage for. - - Options: `C33_reference`, `C33_analog`, `C33_external`, `H7_external`, `nicla_external` -- ``: Specify the voltage value to set for the rail. - - Note: Voltage values must be within the acceptable range for the specific rail. - -### Toggle Charger -Toggle the state of the battery charger. - -Command: `toggle_charger ` - -- ``: Specify whether to enable or disable the charger. - - Options: `1` (on) or `0` (off) - -### Status -Display the status of the board, charger, and battery metrics. - -Command: `status` - -## Notes - -- Make sure to follow the guidelines for voltage and rail names to avoid unexpected behavior. -- Be cautious when adjusting voltage values, as incorrect values may damage your board or battery. - -## Example Usage - -1. To turn on the external power rail on a Portenta C33: - ``` - toggle_rail C33_external 1 - ``` - -2. To set the reference voltage to 1.20V on a Portenta C33: - ``` - set_rail_voltage C33_reference 1.20 - ``` - -3. To enable the charger: - ``` - toggle_charger 1 - ``` - -4. To view the status of the board, charger, and battery metrics: - ``` - status - ``` - -## License - -This sketch and library are provided under the [MIT License](LICENSE). -``` - -Feel free to modify and expand upon this template to suit your specific project and requirements. \ No newline at end of file diff --git a/examples/Standby_WakeFromPin/Standby_WakeFromPin.ino b/examples/Standby_WakeFromPin/Standby_WakeFromPin.ino index 9d35812..74ecb82 100644 --- a/examples/Standby_WakeFromPin/Standby_WakeFromPin.ino +++ b/examples/Standby_WakeFromPin/Standby_WakeFromPin.ino @@ -3,37 +3,31 @@ #include "Arduino_PowerManagement.h" -#define WAKE_PIN A3 -#define GOTO_SLEEP_PIN 0 +#define PORTENTA_C33_WAKEUP_PIN A3 +#define GOTO_SLEEP_PIN D0 volatile bool shouldGoToSleep = false; Board board; -Charger charger; void setup() { board = Board(); - charger = Charger(); board.begin(); - charger.begin(); + board.setAllPeripheralsPower(true); // Allows to use a button to put the device into sleep mode attachInterrupt(digitalPinToInterrupt(GOTO_SLEEP_PIN), goToSleep, RISING); #if defined(ARDUINO_PORTENTA_C33) - // On Portenta C33, you can specify which pin to use to wake up the device from sleep mode - // Please read the documentation to understand which pins can be used to wake up the device. - board.enableWakeupFromPin(WAKE_UP_PIN, RISING); + // On Portenta C33, you can specify which pin to use to wake up the device from sleep mode + // Please read the documentation to understand which pins can be used to wake up the device. + board.enableWakeupFromPin(PORTENTA_C33_WAKEUP_PIN, RISING); #elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GENERIC_STM32H747_M4) || defined(ARDUINO_NICLA_VISION) - // On Portenta only pin GPIO0 can be used to wake up the device from sleep mode - board.enableWakeupFromPin(); + // On Portenta only pin GPIO0 can be used to wake up the device from sleep mode + board.enableWakeupFromPin(); #endif + - // TODO why is this needed? Why true? -> Peripherals still off after reset? - // only necessary for C33 - board.setAllPeripheralsPower(true); - // TODO why is this needed? - charger.setEnabled(false); pinMode(LEDB, OUTPUT); } @@ -45,9 +39,7 @@ void goToSleep(){ void loop() { if(shouldGoToSleep){ shouldGoToSleep = false; - - // TODO why is this here? - //board.setAllPeripheralsPower(false); + board.setAllPeripheralsPower(false); // turn off peripherals before going to sleep board.standByUntilWakeupEvent(); } else { // Show that the board is awake by blinking the LED diff --git a/examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino b/examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino index 20a96a4..0d8a0ee 100644 --- a/examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino +++ b/examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino @@ -25,7 +25,6 @@ void setup() { pinMode(LEDB, OUTPUT); // Used to indicate that the board is awake - if(!board.begin()){ while (true){ blinkLed(LEDR); @@ -33,8 +32,8 @@ void setup() { } board.setAllPeripheralsPower(true); // TODO: Check if this is necessary - // Turn on the blue LED to show that the board is still awake - digitalWrite(LEDB, LOW); + + digitalWrite(LEDB, LOW); // Turn on the blue LED to show that the board is still awake RTC.begin(); if (!RTC.isRunning()) { @@ -48,7 +47,7 @@ void setup() { // board.enableWakeupFromRTC(0, 0, 10, [](){}); // Sleep for 10 seconds board.enableWakeupFromRTC(0, 0, 10); // Sleep for 10 seconds - delay(1000); // Let the user see that the board is ready to sleep + delay(1000); // Keep the board awake for 1 second, so we can se it working board.setAllPeripheralsPower(false); board.standByUntilWakeupEvent(); diff --git a/examples/Standby_WakeFromRTC_H7/Standby_WakeFromRTC_H7.ino b/examples/Standby_WakeFromRTC_H7/Standby_WakeFromRTC_H7.ino index 213d040..9a31a08 100644 --- a/examples/Standby_WakeFromRTC_H7/Standby_WakeFromRTC_H7.ino +++ b/examples/Standby_WakeFromRTC_H7/Standby_WakeFromRTC_H7.ino @@ -36,7 +36,6 @@ #include "MAX1726Driver.h" Board board; -Charger charger; MAX1726Driver fuelgauge(&Wire1); void blinkLed(int ledPin, int delayTime = 1000){ @@ -62,12 +61,6 @@ void setup() { // Turn on the blue LED to show that the board is still awake digitalWrite(LEDB, LOW); - if(!charger.begin()){ - // If the charger fails to initialize, it will blink the red LED - while (true){ - blinkLed(LEDR); - } - } if(!board.begin()){ // If the board fails to initialize, it will blink the red LED @@ -76,17 +69,15 @@ void setup() { } } - delay(10000); // -> Give time to take the measurement - charger.setEnabled(false); // -> Please measure if it makes a difference - delay(10000); // -> Give time to take the measurement // Takes 45s to get into shutdown mode fuelgauge.setOperationMode(FuelGaugeOperationMode::shutdown); - + delay(10000); // keep the board awake for 10 seconds, so we can se it working + // The LED should go off when the board goes to sleep board.setAllPeripheralsPower(false); - board.enableWakeupFromRTC(0, 0, 60); // Go to standby for 60 seconds + board.enableWakeupFromRTC(0, 0, 10); // Go to standby for 10 seconds board.standByUntilWakeupEvent(); } diff --git a/src/Battery.cpp b/src/Battery.cpp index 98074b4..45bc813 100644 --- a/src/Battery.cpp +++ b/src/Battery.cpp @@ -52,8 +52,6 @@ bool Battery::awaitDataReady(uint16_t timeout){ return false; } - // TODO Remove the print statement - Serial.println("Waiting for the battery gauge to be ready..."); delay(100); // Wait for the data to be ready. This takes 710ms from power-up } } diff --git a/src/Battery.h b/src/Battery.h index 6dc06ce..38a23c3 100644 --- a/src/Battery.h +++ b/src/Battery.h @@ -146,7 +146,7 @@ class Battery { int16_t averagePower(); /** - * @brief Reads the current temperature of the internal die. + * @brief Reads the current temperature of the internal die of the battery gauge chip. * @return The current temperature in degrees Celsius. */ uint8_t internalTemperature(); diff --git a/src/Board.cpp b/src/Board.cpp index 1a08e55..42f3e40 100644 --- a/src/Board.cpp +++ b/src/Board.cpp @@ -70,15 +70,13 @@ bool Board::begin() { bool Board::isUSBPowered() { uint16_t registerValue = PMIC.readPMICreg(Register::CHARGER_VBUS_SNS); - // TODO: Check which one works - // return bitRead(registerValue, 2) == 0; return bitRead(registerValue, 5) == 1; // — VBUS is valid -> USB powered } bool Board::isBatteryPowered() { uint8_t registerValue = PMIC.readPMICreg(Register::CHARGER_BATT_SNS); uint8_t batteryPower = extractBits(registerValue, 0, 2); - return batteryPower == 0; // No valid VBUS input -> battery powered + return batteryPower == 0; } void Board::setExternalPowerEnabled(bool on) { @@ -212,76 +210,49 @@ void Board::standByUntilWakeupEvent(){ void Board::setAllPeripheralsPower(bool on){ #if defined(ARDUINO_PORTENTA_C33) + // The power architecture on the C33 puts peripherals on sepparate power lanes which are independent, so we can turn off the peripherals separately. + // Turning these rails will not interfere with your sketch. this -> setCommunicationPeripheralsPower(on); this -> setExternalPowerEnabled(on); this -> setAnalogDigitalConverterPower(on); - if(!on){ - // I2C needs to be shut down because the PMIC would still try - // to communicate with the MCU. - Wire3.end(); - } #else if defined(ARDUINO_PORTENTA_H7) - // TODO Can we extract this into functions? + // On the H7 several chips need different voltages, so we cannot turn the lanes that are dependent on each other separately. + // This should only be used when going into standby mode, as turning off the USB-C PHY, Ethernet or Video bridge might cause undefined behaviour. if(on){ PMIC.getControl() -> turnLDO2On(Ldo2Mode::Normal); - PMIC.getControl() -> turnLDO2On(Ldo2Mode::Sleep); - PMIC.getControl() -> turnLDO2On(Ldo2Mode::Standby); PMIC.getControl() -> turnLDO1On(Ldo1Mode::Normal); - PMIC.getControl() -> turnLDO1On(Ldo1Mode::Sleep); - PMIC.getControl() -> turnLDO1On(Ldo1Mode::Standby); PMIC.getControl() -> turnLDO3On(Ldo3Mode::Normal); - PMIC.getControl() -> turnLDO3On(Ldo3Mode::Sleep); - PMIC.getControl() -> turnLDO3On(Ldo3Mode::Standby); PMIC.getControl() -> turnSw1On(Sw1Mode::Normal); - PMIC.getControl() -> turnSw1On(Sw1Mode::Sleep); - PMIC.getControl() -> turnSw1On(Sw1Mode::Standby); } else { PMIC.getControl() -> turnLDO2Off(Ldo2Mode::Normal); - PMIC.getControl() -> turnLDO2Off(Ldo2Mode::Sleep); - PMIC.getControl() -> turnLDO2Off(Ldo2Mode::Standby); PMIC.getControl() -> turnLDO1Off(Ldo1Mode::Normal); - PMIC.getControl() -> turnLDO1Off(Ldo1Mode::Sleep); - PMIC.getControl() -> turnLDO1Off(Ldo1Mode::Standby); PMIC.getControl() -> turnLDO3Off(Ldo3Mode::Normal); - PMIC.getControl() -> turnLDO3Off(Ldo3Mode::Sleep); - PMIC.getControl() -> turnLDO3Off(Ldo3Mode::Standby); PMIC.getControl() -> turnSw1Off(Sw1Mode::Normal); - PMIC.getControl() -> turnSw1Off(Sw1Mode::Sleep); - PMIC.getControl() -> turnSw1Off(Sw1Mode::Standby); - // I2C needs to be shut down because the PMIC would still try - // to communicate with the MCU. - Wire1.end(); } - #endif } - +// void Board::setAnalogDigitalConverterPower(bool on){ -// TODO Not available on the Portenta H7? -#if defined(ARDUINO_PORTENTA_C33) - if(on){ - PMIC.getControl()->turnLDO1On(Ldo1Mode::Normal); - PMIC.getControl()->turnLDO1On(Ldo1Mode::Sleep); - PMIC.getControl()->turnLDO1On(Ldo1Mode::Standby); - } else { - PMIC.getControl()->turnLDO1Off(Ldo1Mode::Normal); - PMIC.getControl()->turnLDO1Off(Ldo1Mode::Sleep); - PMIC.getControl()->turnLDO1Off(Ldo1Mode::Standby); - } -#endif + #if defined(ARDUINO_PORTENTA_C33) + if(on){ + PMIC.getControl()->turnLDO1On(Ldo1Mode::Normal); + } else { + PMIC.getControl()->turnLDO1Off(Ldo1Mode::Normal); + } + #endif + // On the H7 the ADC is powered by the main MCU power lane, so we cannot turn it off independently. } void Board::setCommunicationPeripheralsPower(bool on){ - // TODO: Why do we only use the normal mode here? - if(on){ - PMIC.getControl()->turnSw1On(Sw1Mode::Normal); - // PMIC.getControl()->turnSw1On(Sw1Mode::Sleep); - // PMIC.getControl()->turnSw1On(Sw1Mode::Standby); - } else { - PMIC.getControl()->turnSw1Off(Sw1Mode::Normal); - // PMIC.getControl()->turnSw1Off(Sw1Mode::Sleep); - // PMIC.getControl()->turnSw1Off(Sw1Mode::Standby); - } + #if defined(ARDUINO_PORTENTA_C33) + if(on){ + PMIC.getControl()->turnSw1On(Sw1Mode::Normal); + } else { + PMIC.getControl()->turnSw1Off(Sw1Mode::Normal); + } + #endif + // On the H7 the communication peripherals are powered by the main MCU power lane, + // so we cannot turn them off independently. } diff --git a/src/Board.h b/src/Board.h index e1aef8d..d80b61a 100644 --- a/src/Board.h +++ b/src/Board.h @@ -13,6 +13,9 @@ #include "Arduino_LowPowerPortentaC33.h" #include "RTC.h" #elif defined(ARDUINO_PORTENTA_H7) || defined(ARDUINO_NICLA_VISION) + // When used standalone the LowPowerPortentaH7 library will turn off the Ethernet interface to avoid issues with the line termination resistors, + // but in this library we can turn of the Ethernet interface using the PMIC, so we set the NO_ETHERNET_TURN_OFF flag to avoid turning off the Ethernet interface from both sides. + #define NO_ETHERNET_TURN_OFF #include "Arduino_LowPowerPortentaH7.h" #endif @@ -147,24 +150,23 @@ class Board { #if defined(ARDUINO_PORTENTA_C33) - // TODO Restarts after waking up.? /** * Put the device into sleep mode until a wakeup event occurs * This sleep mode is ideal for applications requiring periodic wake-ups or * brief intervals of inactivity and reduces consumption to a range between * 6mA and 18mA depending on the state of the peripherals. - * This sleep mode resumes the operation from the last operation. + * This sleep mode resumes the operation from the last operation without resetting the board. * A wakeup event can be an interrupt on a pin or the RTC, * depending on what you set with enableWakeupFromPin() and enableWakeupFromRTC(). */ void sleepUntilWakeupEvent(); #endif - // TODO measurements are board specific. Need adjustments for Portenta H7. + /** * Put the device into standby mode until a wakeup event occurs. * For scenarios demanding drastic power conservation, the standby Mode significantly reduces - * the board's power usage to range between 90uA and 11mA depending on the state of the peripherals. + * the board's power usage to micro amperes range depending on the state of the peripherals. * This mode restarts the board on wake-up, effectively running the setup() function again. * A wakeup event can be an interrupt on a pin or the RTC, depending on what * you set with enableWakeupFromPin() and enableWakeupFromRTC(). diff --git a/src/MAX1726Driver.h b/src/MAX1726Driver.h index 9165860..4a65a41 100644 --- a/src/MAX1726Driver.h +++ b/src/MAX1726Driver.h @@ -1,5 +1,4 @@ #include "WireUtils.h" -// TODO extract into a separate header file and check how PF1550Driver is implemented #include "BatteryConstants.h" enum class FuelGaugeOperationMode