Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasssvaz committed Sep 17, 2024
1 parent 169979e commit fdad0c3
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 116 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def test_cpu(dut):
def test_cpu_misc(dut):
dut.expect_unity_test_output(timeout=120)
113 changes: 0 additions & 113 deletions tests/validation/deep_sleep/deep_sleep.ino

This file was deleted.

2 changes: 0 additions & 2 deletions tests/validation/deep_sleep/test_deep_sleep.py

This file was deleted.

File renamed without changes.
161 changes: 161 additions & 0 deletions tests/validation/sleep/sleep.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* This sketch tests the deep sleep functionality of the ESP32
*/

#include <Arduino.h>
#include "driver/rtc_io.h"
#include "driver/uart.h"

// Timer
#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 1 /* Time ESP32 will go to sleep (in seconds) */

// Touchpad
#if CONFIG_IDF_TARGET_ESP32
#define THRESHOLD 1000 /* Greater the value, more the sensitivity */
#else
#define THRESHOLD 0 /* Lower the value, more the sensitivity */
#endif

// External wakeup
#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex

#if CONFIG_IDF_TARGET_ESP32H2
#define WAKEUP_GPIO GPIO_NUM_7 // Only RTC IO are allowed
#else
#define WAKEUP_GPIO GPIO_NUM_4 // Only RTC IO are allowed
#endif

RTC_DATA_ATTR int bootCount = 0;

void print_wakeup_reason() {
esp_sleep_wakeup_cause_t wakeup_reason;

wakeup_reason = esp_sleep_get_wakeup_cause();

Serial.print("Wakeup reason: ");

switch (wakeup_reason) {
case ESP_SLEEP_WAKEUP_EXT0: Serial.println("rtc_io"); break;
case ESP_SLEEP_WAKEUP_EXT1: Serial.println("rtc_cntl"); break;
case ESP_SLEEP_WAKEUP_TIMER: Serial.println("timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP: Serial.println("ulp"); break;
case ESP_SLEEP_WAKEUP_GPIO: Serial.println("gpio"); break;
case ESP_SLEEP_WAKEUP_UART: Serial.println("uart"); break;
default: Serial.println("power_up"); break;
}
}

void setup_timer() {
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
}

void setup_touchpad() {
touchSleepWakeUpEnable(T1, THRESHOLD);
}

void setup_rtc_io() {
esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1);
rtc_gpio_pullup_en(WAKEUP_GPIO);
rtc_gpio_pulldown_dis(WAKEUP_GPIO);
}

void setup_rtc_cntl() {
esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);
rtc_gpio_pulldown_dis(WAKEUP_GPIO);
rtc_gpio_pullup_en(WAKEUP_GPIO);
}

void setup_gpio() {
esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_ON);
rtc_gpio_pullup_dis(WAKEUP_GPIO);
rtc_gpio_pulldown_en(WAKEUP_GPIO);
gpio_wakeup_enable(WAKEUP_GPIO, GPIO_INTR_HIGH_LEVEL);
esp_sleep_enable_gpio_wakeup();
}

void setup_uart() {
uart_set_wakeup_threshold(UART_NUM_0, 9); // wake up with "aaa" string (9 positive edges)
esp_sleep_enable_uart_wakeup(UART_NUM_0);
}



void setup() {
Serial.begin(115200);
while (!Serial) {
delay(10);
}

//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));

//Print the wakeup reason for ESP32
print_wakeup_reason();
Serial.flush();
}

void loop() {
// Disable all configured wakeup sources
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);

if(Serial.available() > 0) {
String command = Serial.readString();
command.trim();

if (command == "timer_deep") {
// Test timer wakeup from deep sleep
setup_timer();
esp_deep_sleep_start();
Serial.println("FAIL");
while(1);
} else if (command == "touchpad_deep") {
// Test touchpad wakeup from deep sleep
setup_touchpad();
esp_deep_sleep_start();
Serial.println("FAIL");
while(1);
} else if (command == "rtc_io_deep") {
// Test external wakeup from deep sleep using RTC IO
setup_rtc_io();
esp_deep_sleep_start();
Serial.println("FAIL");
while(1);
} else if (command == "rtc_cntl_deep") {
// Test external wakeup from deep sleep using RTC controller
setup_rtc_cntl();
esp_deep_sleep_start();
Serial.println("FAIL");
while(1);
} else if (command == "timer_light") {
// Test timer wakeup from light sleep
setup_timer();
} else if (command == "touchpad_light") {
// Test touchpad wakeup from light sleep
setup_touchpad();
} else if (command == "rtc_io_light") {
// Test external wakeup from light sleep using RTC IO
setup_rtc_io();
} else if (command == "rtc_cntl_light") {
// Test external wakeup from light sleep using RTC controller
setup_rtc_cntl();
} else if (command == "gpio_light") {
// Test external wakeup from light sleep using GPIO
setup_gpio();
} else if (command == "uart_light") {
// Test external wakeup from light sleep using UART
setup_uart();
} else {
Serial.println("FAIL");
while(1);
}

esp_light_sleep_start();
Serial.println("Woke up from light sleep");
print_wakeup_reason();
Serial.flush();
rtc_gpio_hold_dis(WAKEUP_GPIO);
}
}
40 changes: 40 additions & 0 deletions tests/validation/sleep/test_sleep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import logging

capabilities = {
"timer": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"],
"touchpad": ["esp32", "esp32s2", "esp32s3", "esp32c3"],
"rtc_io": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"],
"rtc_cntl": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"],
"gpio": ["esp32", "esp32s2", "esp32s3"],
"uart": ["esp32", "esp32s2", "esp32s3", "esp32c3", "esp32c6", "esp32h2"]
}

def test_sleep(dut):
LOGGER = logging.getLogger(__name__)

# Deep Sleep
boot_count = 1
dut.expect_exact("Boot number: {}".format(boot_count))
dut.expect_exact("Wakeup reason: power_up")

for capability, devices in capabilities.items():
if dut.app.target in devices and capability not in ["gpio", "uart"]:
LOGGER.info("Testing {} deep sleep capability".format(capability))
boot_count += 1
dut.write("{}_deep".format(capability))
dut.expect_exact("Boot number: {}".format(boot_count))
dut.expect_exact("Wakeup reason: {}".format(capability))

# Light Sleep
for capability, devices in capabilities.items():
if dut.app.target in devices:
LOGGER.info("Testing {} light sleep capability".format(capability))
dut.write("{}_light".format(capability))
if capability == "uart":
dut.write("aaa") # Send 9 positive edges
dut.expect_exact("Woke up from light sleep")
dut.expect_exact("Wakeup reason: {}".format(capability))




0 comments on commit fdad0c3

Please sign in to comment.