Skip to content
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

Supports auxiliary power control. #2774

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

XuGuohui
Copy link
Member

@XuGuohui XuGuohui commented May 23, 2024

Example App

#include "application.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

SerialLogHandler l(LOG_LEVEL_ALL);

uint8_t auxPwrPin = D23;

STARTUP(System.enableFeature(FEATURE_ETHERNET_DETECTION));

STARTUP({
    System.setPowerConfiguration(SystemPowerConfiguration().auxPowerControlPin(auxPwrPin).feature(SystemPowerFeature::PMIC_DETECTION));
});

void setup() {
    while (!Serial.isConnected()) {
        delay(100);
    }
    Log.info("Application started");
}

void loop() {
    if (Serial.available()) {
        char c = Serial.read();
        switch (c) {
            case 'i': {
                if_list* ifs = nullptr;
                if_get_list(&ifs);
                for (if_list* iface = ifs; iface != nullptr; iface = iface->next) {
                    if (iface->iface) {
                        uint8_t idx;
                        if_get_index(iface->iface, &idx);
                        Log.info("Interface %d: %s", idx, iface->iface->name);
                    }
                }
                if_free_list(ifs);
                break;
            }
            case 'p': {
                Log.info("Connecting to Particle Cloud...");
                Particle.connect();
                break;
            }
            case 'w': {
                Log.info("Connecting to Wi-Fi...");
                WiFi.connect();
                break;
            }
            case 'c': {
                Log.info("Connecting to Cellular...");
                Cellular.connect();
                break;
            }
            case 'e': {
                Log.info("Connecting to Ethernet...");
                Ethernet.connect();
                break;
            }
            case 'd': {
                Log.info("Connecting to Particle Cloud...");
                Particle.disconnect();
                break;
            }
            case 'o': {
                Log.info("Turning on the auxiliary power...");
                digitalWrite(auxPwrPin, HIGH);
                break;
            }
            case 'f': {
                Log.info("Turning off the auxiliary power...");
                digitalWrite(auxPwrPin, LOW);
                break;
            }
            default: break;
        }
    }
}

Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@XuGuohui XuGuohui marked this pull request as ready for review May 24, 2024 08:43
Copy link
Member

@scott-brust scott-brust left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested MSOM on an old EVB, with the onboard wiznet chip (just to make things easier)

I confirmed that the D23 / aux power pin is asserted on boot before setup() completes, and that the en2 netif is populated (because the EVB already powers it on by default).

I confirmed that when pulling the ethernet jumpers, and breaking ethernet communication to the msom, that the en2 netif is removed from the list of lwip IFs after boot.

I think the PR as currently written can be used for muon / m2 breakout to control the aux power at boot

hal/src/b5som/network/network.cpp Show resolved Hide resolved
system/src/main.cpp Show resolved Hide resolved
system/src/system_power_manager.cpp Show resolved Hide resolved

#if HAL_PLATFORM_POWER_MANAGEMENT_OPTIONAL
if (!detect()) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Log a warning here to make it clear PMIC isnt detected?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, previously this would call self->deinit();
Do we need to call this still in this case or if we are exiting during init, there is nothing to de-init at this point? (maybe just unconfigure the aux power control pin?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the previous goto exit, in which it calls self->deinit() is mainly for calling os_thread_exit() to exit the thread. But here is the very begining of the init() function, if the PMIC is not detected we can simply return. As for the aux power control pin, it is required when the power module for DC power supply is installed, on which there is no PMIC, but we still need to enable the aux power control pin.

system/src/system_power_manager.cpp Show resolved Hide resolved
hal/inc/power_hal.h Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants