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

added power serial cmds, wakeup cardputer by pressing any key (#64) #85

Merged
merged 2 commits into from
Jul 26, 2024

Conversation

eadmaster
Copy link
Contributor

also fixed "tts" command typo

@eadmaster
Copy link
Contributor Author

not sure what caused this:

/home/runner/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/m5stack-cplus2/firmware.elf section `.iram0.text' will not fit in region `iram0_0_seg'
/home/runner/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: IRAM0 segment data does not fit.
/home/runner/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: region `iram0_0_seg' overflowed by 2264 bytes

@Niximkk
Copy link
Contributor

Niximkk commented Jul 26, 2024

@Niximkk
Copy link
Contributor

Niximkk commented Jul 26, 2024

If the app allocates more static IRAM than available, then the app will fail to build, and linker errors such as section '.iram0.text' will not fit in region 'iram0_0_seg', IRAM0 segment data does not fit, and region 'iram0_0_seg' overflowed by 84-bytes will be seen. If this happens, it is necessary to find ways to reduce static IRAM usage in order to link the application.
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/performance/ram-usage.html#optimize-iram-usage

Any idea what could have caused it?

@eadmaster
Copy link
Contributor Author

my only hypothesis is this new symbol i've added in the code esp_deep_sleep_start().

@Niximkk
Copy link
Contributor

Niximkk commented Jul 26, 2024

prob... I believe that the m5 libraries have a power off function.

@eadmaster
Copy link
Contributor Author

m5 libraries have a power off function.

i couldn't find any, deepsleep is closest thing .
esp8266/Arduino#929
https://esp32.com/viewtopic.php?t=5624

@Niximkk
Copy link
Contributor

Niximkk commented Jul 26, 2024

Power:
    M5.Power.setPowerBoostKeepOn()
    M5.Power.setCharge(uint8_t mode);
    M5.Power.setPowerBoostKeepOn(bool en);
    M5.Power.isChargeFull();
    M5.Power.setWakeupButton(uint8_t button);
    M5.Power.powerOFF();

@Niximkk
Copy link
Contributor

Niximkk commented Jul 26, 2024

@Niximkk
Copy link
Contributor

Niximkk commented Jul 26, 2024

void M5Stack::powerOFF() {
M5.Power.deepSleep();
}

@Niximkk
Copy link
Contributor

Niximkk commented Jul 26, 2024

void POWER::deepSleep(uint64_t time_in_us) {
    // Keep power keep boost on
    setPowerBoostKeepOn(true);

    // power off the Lcd
    M5.Lcd.setBrightness(0);
    M5.Lcd.sleep();

    // ESP32 into deep sleep
    esp_sleep_enable_ext0_wakeup((gpio_num_t)_wakeupPin, LOW);

    if (time_in_us > 0) {
        esp_sleep_enable_timer_wakeup(time_in_us);
    } else {
        esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
    }

    while (digitalRead(_wakeupPin) == LOW) {
        delay(10);
    }

    (time_in_us == 0) ? esp_deep_sleep_start() : esp_deep_sleep(time_in_us);
}

@eadmaster
Copy link
Contributor Author

eadmaster commented Jul 26, 2024

internally, both M5.Power.deepSleep and powerOFF are still calling esp_deep_sleep_start, not sure if it will make any difference for this issue
https://github.com/m5stack/M5Stack/blob/master/src/utility/Power.cpp#L449

(My guess is i have to remove the call to esp_deep_sleep_start() completely.)

@pr3y
Copy link
Owner

pr3y commented Jul 26, 2024

Whats the issue on using what is already on src/core/PowerSave.cpp? is deep sleep better somehow?

/* Put device on sleep mode */
void sleepModeOn(){
  isSleeping = true;
  setCpuFrequencyMhz(80);
  turnOffDisplay();
  delay(200);
}

/* Wake up device */
void sleepModeOff(){
  isSleeping = false;
  setCpuFrequencyMhz(240);
  getBrightness();
  delay(200);
}

@eadmaster
Copy link
Contributor Author

Whats the issue on using what is already on src/core/PowerSave.cpp? is deep sleep better somehow?

/* Put device on sleep mode */
void sleepModeOn(){
  isSleeping = true;
  setCpuFrequencyMhz(80);
  turnOffDisplay();
  delay(200);
}

/* Wake up device */
void sleepModeOff(){
  isSleeping = false;
  setCpuFrequencyMhz(240);
  getBrightness();
  delay(200);
}

that's different, i am already using that code for the power sleep command btw.

@bmorcelli
Copy link
Collaborator

Deep sleep doesn't work properly on the StickCs, because they need to set up the RTC chip to "wake up", and it will work more like a turn-off with scheduled event,... so i don't recommend

to turn off the StickCs we can use:
StickC puls 1.1:
axp192.PowerOff();

StickC Plus 2:
digitalWrite(4, LOW);

for the cardputer I must do some research here

@eadmaster
Copy link
Contributor Author

for the cardputer I must do some research here

for the cardputer i've found esp_deep_sleep_start() without setting up the RTC wakeup it is very close to a "software poweroff" (e.g. you can only power-cycle/reset the device to restart)

@bmorcelli
Copy link
Collaborator

  if(cmd_str == "power off" ) {
    // closest thing https://github.com/esp8266/Arduino/issues/929
    //ESP.deepSleep(0);
    #if defined(STICK_C_PLUS)
    axp192.PowerOff();
    #elif defined(STICK_C_PLUS2)
    digitalWrite(4,LOW);
    #else
    esp_deep_sleep_start();  // only wake up via hardware reset
    #endif
    return;
  }

This fixed the problem here for me

@eadmaster
Copy link
Contributor Author

  if(cmd_str == "power off" ) {
    // closest thing https://github.com/esp8266/Arduino/issues/929
    //ESP.deepSleep(0);
    #if defined(STICK_C_PLUS)
    axp192.PowerOff();
    #elif defined(STICK_C_PLUS2)
    digitalWrite(4,LOW);
    #else
    esp_deep_sleep_start();  // only wake up via hardware reset
    #endif
    return;
  }

This fixed the problem here for me

ok, commit the changes

@bmorcelli
Copy link
Collaborator

In the line 10, include the libs like this:

#ifndef STICK_C_PLUS
  #include <ESP8266Audio.h>
  #include <ESP8266SAM.h>
#endif

Before starting the music command use:

#ifndef STICK_C_PLUS // at line ~203
  if(cmd_str.startsWith("music_player " ) || cmd_str.startsWith("tts" ) || cmd_str.startsWith("say" ) ) {
    // TODO: move in audio.cpp module

and after the code finish it with #endif, at line ~298 aproximately... the StickC Plus 1.1 binaty will be at 0x235000 size (fitting the target partition size of 0x260000

@eadmaster
Copy link
Contributor Author

ok, so the music player is disabled on the STICK_C_PLUS target.

@pr3y pr3y merged commit b728503 into pr3y:main Jul 26, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants