Skip to content

Commit

Permalink
ESP32/boards: Add support of ESP32 Wrover Kit in wifi-echo demo (#3304)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrishi authored and pull[bot] committed Dec 7, 2020
1 parent ac777dc commit 3802022
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
3 changes: 1 addition & 2 deletions examples/common/screen-framework/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ esp_err_t InitDisplay()

ESP_LOGI(TAG, "Display initialized (height %u, width %u)", DisplayHeight, DisplayWidth);

// for some reason this is backwards (turns out this is because of a 2019 update to the m5stack hw)
TFT_invertDisplay(INVERT_ON);
TFT_invertDisplay(INVERT_DISPLAY);

// prepare the display for brightness control
SetupBrightnessControl();
Expand Down
12 changes: 9 additions & 3 deletions examples/common/screen-framework/include/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@
#if CONFIG_DEVICE_TYPE_M5STACK

#define CONFIG_HAVE_DISPLAY 1
#define CONFIG_TFT_PREDEFINED_DISPLAY_TYPE 3
// for some reason this is backwards (turns out this is because of a 2019 update to the m5stack hw)
#define INVERT_DISPLAY INVERT_ON

#else // !CONFIG_DEVICE_TYPE_M5STACK
#elif CONFIG_DEVICE_TYPE_ESP32_WROVER_KIT

#define CONFIG_HAVE_DISPLAY 1
#define INVERT_DISPLAY INVERT_OFF

#else

#define CONFIG_HAVE_DISPLAY 0

#endif // !CONFIG_DEVICE_TYPE_M5STACK
#endif

#if CONFIG_HAVE_DISPLAY

Expand Down
5 changes: 4 additions & 1 deletion examples/wifi-echo/server/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ menu "WiFi Echo Demo"

config DEVICE_TYPE_ESP32_DEVKITC
bool "ESP32-DevKitC"
config DEVICE_TYPE_ESP32_WROVER_KIT
bool "ESP32-WROVER-KIT_V4.1"
config DEVICE_TYPE_M5STACK
bool "M5Stack"
endchoice
Expand Down Expand Up @@ -66,8 +68,9 @@ menu "WiFi Echo Demo"
config TFT_PREDEFINED_DISPLAY_TYPE
int
range 0 5
default 3 if DEVICE_TYPE_M5STACK
default 0 if DEVICE_TYPE_ESP32_DEVKITC
default 3 if DEVICE_TYPE_M5STACK
default 4 if DEVICE_TYPE_ESP32_WROVER_KIT

config RENDEZVOUS_MODE
int
Expand Down
59 changes: 33 additions & 26 deletions examples/wifi-echo/server/esp32/main/wifi-echo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ extern void startServer();
#define BUTTON_3_GPIO_NUM GPIO_NUM_37 // Right button on M5Stack
#define STATUS_LED_GPIO_NUM GPIO_NUM_MAX // No status LED on M5Stack

#elif CONFIG_DEVICE_TYPE_ESP32_WROVER_KIT

#define STATUS_LED_GPIO_NUM GPIO_NUM_26

#elif CONFIG_DEVICE_TYPE_ESP32_DEVKITC

#define BUTTON_1_GPIO_NUM GPIO_NUM_34 // Button 1 on DevKitC
#define BUTTON_2_GPIO_NUM GPIO_NUM_35 // Button 2 on DevKitC
#define BUTTON_3_GPIO_NUM GPIO_NUM_0 // Button 3 on DevKitC
#define STATUS_LED_GPIO_NUM GPIO_NUM_2 // Use LED1 (blue LED) as status LED on DevKitC

#else // !CONFIG_DEVICE_TYPE_ESP32_DEVKITC
Expand All @@ -79,15 +80,6 @@ extern void startServer();
// Used to indicate that an IP address has been added to the QRCode
#define EXAMPLE_VENDOR_TAG_IP 1

#if CONFIG_HAVE_DISPLAY

// Where to draw the connection status message
#define CONNECTION_MESSAGE 75
// Where to draw the IPv6 information
#define IPV6_INFO 85

#endif // CONFIG_HAVE_DISPLAY

LEDWidget statusLED1;
LEDWidget statusLED2;
BluetoothWidget bluetoothLED;
Expand All @@ -102,9 +94,13 @@ RendezvousDeviceDelegate * rendezvousDelegate = nullptr;

namespace {

#if CONFIG_DEVICE_TYPE_M5STACK

std::vector<Button> buttons = { Button(), Button(), Button() };
std::vector<gpio_num_t> button_gpios = { BUTTON_1_GPIO_NUM, BUTTON_2_GPIO_NUM, BUTTON_3_GPIO_NUM };

#endif

// Pretend these are devices with endpoints with clusters with attributes
typedef std::tuple<std::string, std::string> Attribute;
typedef std::vector<Attribute> Attributes;
Expand Down Expand Up @@ -140,7 +136,7 @@ void AddDevice(std::string name)
devices.emplace_back(std::move(device));
}

#if CONFIG_HAVE_DISPLAY
#if CONFIG_DEVICE_TYPE_M5STACK

class EditAttributeListModel : public ListScreen::Model
{
Expand Down Expand Up @@ -292,7 +288,7 @@ class CustomScreen : public Screen
}
};

#endif // CONFIG_HAVE_DISPLAY
#endif // CONFIG_DEVICE_TYPE_M5STACK

void SetupPretendDevices()
{
Expand Down Expand Up @@ -508,6 +504,18 @@ extern "C" void app_main()
ESP_LOGI(TAG, "QR CODE: '%s'", qrCodeText.c_str());

#if CONFIG_HAVE_DISPLAY
// Initialize the display device.
err = InitDisplay();
if (err != ESP_OK)
{
ESP_LOGE(TAG, "InitDisplay() failed: %s", ErrorStr(err));
return;
}

// Initialize the screen manager
ScreenManager::Init();

#if CONFIG_DEVICE_TYPE_M5STACK
// Initialize the buttons.
for (int i = 0; i < buttons.size(); ++i)
{
Expand All @@ -519,16 +527,7 @@ extern "C" void app_main()
}
}

// Initialize the display device.
err = InitDisplay();
if (err != ESP_OK)
{
ESP_LOGE(TAG, "InitDisplay() failed: %s", ErrorStr(err));
return;
}

// Initialize the screen manager and push a rudimentary user interface.
ScreenManager::Init();
// Push a rudimentary user interface.
ScreenManager::PushScreen(chip::Platform::New<ListScreen>(
(chip::Platform::New<SimpleListModel>())
->Title("CHIP")
Expand Down Expand Up @@ -558,6 +557,14 @@ extern "C" void app_main()
->Item("For")
->Item("Demo")));

#elif CONFIG_DEVICE_TYPE_ESP32_WROVER_KIT

// Display the QR Code
QRCodeScreen qrCodeScreen(qrCodeText);
qrCodeScreen.Display();

#endif

// Connect the status LED to VLEDs.
{
int vled1 = ScreenManager::AddVLED(TFT_GREEN);
Expand All @@ -577,7 +584,7 @@ extern "C" void app_main()
// Run the UI Loop
while (true)
{
#if CONFIG_HAVE_DISPLAY
#if CONFIG_DEVICE_TYPE_M5STACK
// TODO consider refactoring this example to use FreeRTOS tasks

bool woken = false;
Expand All @@ -602,7 +609,7 @@ extern "C" void app_main()
}
}

#endif // CONFIG_HAVE_DISPLAY
#endif // CONFIG_DEVICE_TYPE_M5STACK

vTaskDelay(50 / portTICK_PERIOD_MS);
}
Expand Down

0 comments on commit 3802022

Please sign in to comment.