diff --git a/tests/validation/i2c_master/i2c_master.ino b/tests/validation/i2c_master/i2c_master.ino index 3c7b2d9824a..9b4cc508a35 100644 --- a/tests/validation/i2c_master/i2c_master.ino +++ b/tests/validation/i2c_master/i2c_master.ino @@ -5,6 +5,11 @@ #include <Arduino.h> #include <unity.h> #include <Wire.h> +#include <vector> +#include <algorithm> +#include <WiFi.h> + +#include "sdkconfig.h" /* DS1307 functions */ @@ -24,6 +29,9 @@ static uint8_t read_month = 0; static uint16_t read_year = 0; static int peek_data = -1; +const char *ssid = "Wokwi-GUEST"; +const char *password = ""; + const auto BCD2DEC = [](uint8_t num) -> uint8_t { return ((num / 16 * 10) + (num % 16)); }; @@ -245,6 +253,42 @@ void test_api() { Wire.flush(); } +bool device_found() { + uint8_t err; + + for (uint8_t address = 1; address < 127; ++address) { + Wire.beginTransmission(address); + err = Wire.endTransmission(); + log_d("Address: 0x%02X, Error: %d", address, err); + if (err == 0) { + log_i("Found device at address: 0x%02X", address); + } else if (address == DS1307_ADDR) { + log_e("Failed to find DS1307"); + return false; + } + } + + return true; +} + +void scan_bus() { + TEST_ASSERT_TRUE(device_found()); +} + +#if SOC_WIFI_SUPPORTED +void scan_bus_with_wifi() { + // delete old config + WiFi.disconnect(true, true, 1000); + delay(1000); + WiFi.begin(ssid, password); + delay(5000); + bool found = device_found(); + WiFi.disconnect(true, true, 1000); + + TEST_ASSERT_TRUE(found); +} +#endif + /* Main */ void setup() { @@ -258,6 +302,10 @@ void setup() { log_d("Starting tests"); UNITY_BEGIN(); + RUN_TEST(scan_bus); +#if SOC_WIFI_SUPPORTED + RUN_TEST(scan_bus_with_wifi); +#endif RUN_TEST(rtc_set_time); RUN_TEST(rtc_run_clock); RUN_TEST(change_clock);