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

[P137] Add predefined settings for M5StickC Plus #5228

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
4 changes: 3 additions & 1 deletion docs/source/Plugin/P137.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ Hardware outputs AXP192

* *LilyGO T-Beam* Settings for the LilyGO T-Beam series of GPS/LoRa devices with optional OLed display.

* *User defined* To be able to configure all available output pins the User defined option is available, f.e. when using a custom designed, or not yet supported, hardware setup.
* *M5Stack StickC Plus* Settings for the M5Stack StickC Plus hardware. (Not applicable for the M5Stack StickC Plus 2, as that unit doesn't have an AXP192 power management controller).

* *User defined* To be able to configure are available output pins the User defined option is available, f.e. when using a custom designed, or not yet supported, hardware setup.

When available, new predefined devices will be added. The User defined option will stay the last option.

Expand Down
Binary file modified docs/source/Plugin/P137_PredefinedDeviceOptions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/_P137_AXP192.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/**
* Changelog:
* 2025-01-21 tonhuisman: Bugfix: commands axp,ldo2,x to axp,dcdc3,x weren't working as intended
* 2025-01-18 tonhuisman: Add predefined config settings for M5Stack StickC Plus units
* 2022-12-27 tonhuisman: Add predefined config settings for LilyGO T-Beam LoRa units
* 2022-12-07 tonhuisman: Re-order device configuration to use PLUGIN_WEBFORM_LOAD_OUTPUT_SELECTOR
* Enable PluginStats feature
Expand Down Expand Up @@ -181,13 +183,15 @@ boolean Plugin_137(uint8_t function, struct EventStruct *event, String& string)
toString(P137_PredefinedDevices_e::M5Stack_StickC),
toString(P137_PredefinedDevices_e::M5Stack_Core2),
toString(P137_PredefinedDevices_e::LilyGO_TBeam),
toString(P137_PredefinedDevices_e::M5Stack_StickCPlus),
toString(P137_PredefinedDevices_e::UserDefined) // keep last and at 99 !!
};
const int predefinedValues[] = {
static_cast<int>(P137_PredefinedDevices_e::Unselected),
static_cast<int>(P137_PredefinedDevices_e::M5Stack_StickC),
static_cast<int>(P137_PredefinedDevices_e::M5Stack_Core2),
static_cast<int>(P137_PredefinedDevices_e::LilyGO_TBeam),
static_cast<int>(P137_PredefinedDevices_e::M5Stack_StickCPlus),
static_cast<int>(P137_PredefinedDevices_e::UserDefined) }; // keep last and at 99 !!
constexpr size_t optionCount = NR_ELEMENTS(predefinedValues);
FormSelectorOptions selector(optionCount, predefinedNames, predefinedValues);
Expand Down
33 changes: 24 additions & 9 deletions src/src/PluginStructs/P137_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ void P137_CheckPredefinedParameters(struct EventStruct *event) {
P137_REG_DCDC2_LDO2 = (P137_valueToSetting(-1, P137_CONST_MAX_DCDC2) << 16) | P137_valueToSetting(3300, P137_CONST_MAX_LDO);
P137_REG_DCDC3_LDO3 = (P137_valueToSetting(3300, P137_CONST_MAX_DCDC) << 16) | P137_valueToSetting(3300, P137_CONST_MAX_LDO);
P137_REG_LDOIO = P137_valueToSetting(3300, P137_CONST_MAX_LDOIO);
P137_CONFIG_DISABLEBITS = 0b1111111000; // NC pins disabled
P137_CONFIG_DISABLEBITS = 0b1111111000; // NC pins disabled
break;
}
case P137_PredefinedDevices_e::M5Stack_StickCPlus: // M5Stack StickC Plus
{
P137_REG_DCDC2_LDO2 = (P137_valueToSetting(-1, P137_CONST_MAX_DCDC2) << 16) | P137_valueToSetting(2800, P137_CONST_MAX_LDO);
P137_REG_DCDC3_LDO3 = (P137_valueToSetting(-1, P137_CONST_MAX_DCDC) << 16) | P137_valueToSetting(3000, P137_CONST_MAX_LDO);
P137_REG_LDOIO = P137_valueToSetting(2800, P137_CONST_MAX_LDOIO);
P137_CONFIG_DISABLEBITS = 0b1111110000; // NC pins disabled
break;
}
case P137_PredefinedDevices_e::UserDefined: // User defined
Expand Down Expand Up @@ -111,7 +119,7 @@ const __FlashStringHelper* toString(const P137_valueOptions_e value,
case P137_valueOptions_e::DCDC2: return displayString ? F("DCDC2 Voltage") : F("dcdc2voltage");
case P137_valueOptions_e::DCDC3: return displayString ? F("DCDC3 Voltage") : F("dcdc3voltage");
}
return F("*Undefined*");
return F("Undefined");
}

// **************************************************************************/
Expand All @@ -125,7 +133,7 @@ const __FlashStringHelper* toString(const P137_GPIOBootState_e value) {
case P137_GPIOBootState_e::Input: return F("Input");
case P137_GPIOBootState_e::PWM: return F("PWM");
}
return F("*Undefined*");
return F("Undefined");
}

// **************************************************************************/
Expand All @@ -135,11 +143,12 @@ const __FlashStringHelper* toString(const P137_PredefinedDevices_e device) {
switch (device) {
case P137_PredefinedDevices_e::Unselected: return F("Select an option to set default values");
case P137_PredefinedDevices_e::M5Stack_StickC: return F("M5Stack StickC");
case P137_PredefinedDevices_e::M5Stack_Core2: return F("M5Stack Core2 v1.0 (Default)");
case P137_PredefinedDevices_e::LilyGO_TBeam: return F("LilyGO T-Beam v1.1");
case P137_PredefinedDevices_e::M5Stack_Core2: return F("M5Stack Core2 (Default)");
case P137_PredefinedDevices_e::LilyGO_TBeam: return F("LilyGO T-Beam");
case P137_PredefinedDevices_e::M5Stack_StickCPlus: return F("M5Stack StickC Plus");
case P137_PredefinedDevices_e::UserDefined: return F("User defined");
}
return F("*Undefined*");
return F("Undefined");
}

// **************************************************************************/
Expand Down Expand Up @@ -259,7 +268,10 @@ bool P137_data_struct::plugin_write(struct EventStruct *event,

if (isInitialized() && equals(cmd, F("axp"))) { // Command trigger
cmd = parseString(string, 2); // sub command
const int subcommand_i = GetCommandCode(cmd.c_str(), P137_subcommands);
const int subcommand_i = GetCommandCode(cmd.c_str(), P137_subcommands);

if (subcommand_i < 0) { return success; } // fail fast

const P137_subcommands_e subcmd = static_cast<P137_subcommands_e>(subcommand_i);

const String var3 = parseString(string, 3);
Expand All @@ -268,7 +280,8 @@ bool P137_data_struct::plugin_write(struct EventStruct *event,
const bool state3 = !empty3 && (event->Par2 == 0 || event->Par2 == 1);
success = true;

if ((event->Par2 >= 0) && (event->Par2 <= P137_CONST_100_PERCENT) && !empty3 && empty4) {
if ((event->Par2 >= 0) && (event->Par2 <= P137_CONST_100_PERCENT) && !empty3 && empty4 &&
(subcmd >= P137_subcommands_e::ldo2perc) && (subcmd <= P137_subcommands_e::dcdc3perc)) {
// percentage 0..100, 0 turns off

switch (subcmd) {
Expand Down Expand Up @@ -322,7 +335,9 @@ bool P137_data_struct::plugin_write(struct EventStruct *event,
success = false;
break;
}
} else if ((event->Par2 >= 0) && (event->Par3 <= P137_CONST_MAX_LDO) && (event->Par2 < event->Par3) && !empty3 && !empty4) {
} else
if ((event->Par2 >= 0) && (event->Par3 <= P137_CONST_MAX_LDO) && (event->Par2 < event->Par3) && !empty3 && !empty4 &&
(subcmd >= P137_subcommands_e::ldo2map) && (subcmd <= P137_subcommands_e::dcdc3map)) {
// map range <low>,<high>

switch (subcmd) {
Expand Down
11 changes: 6 additions & 5 deletions src/src/PluginStructs/P137_data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ enum class P137_GPIOBootState_e: uint8_t { // Will be applied by subtracting 1 !
};

enum class P137_PredefinedDevices_e : uint8_t {
Unselected = 0u,
M5Stack_StickC = 1u,
M5Stack_Core2 = 2u,
LilyGO_TBeam = 3u,
UserDefined = 99u // Keep as last
Unselected = 0u,
M5Stack_StickC = 1u,
M5Stack_Core2 = 2u,
LilyGO_TBeam = 3u,
M5Stack_StickCPlus = 4u,
UserDefined = 99u // Keep as last
};

int16_t P137_settingToValue(uint16_t data,
Expand Down
Loading