Skip to content

Commit 735f543

Browse files
Show a QRCode and status on the M5Stack's display (project-chip#890)
* Add display support for the ESP32 * Attempt to use real payload * Restyled by clang-format * Leave the DevKit-C as the default device * Fix the ESP build in CI * Update docs * Restyled by prettier-markdown * Minor tweak to docs * Restyled by prettier-markdown * Fix missing word in doc Co-authored-by: Restyled.io <commits@restyled.io>
1 parent ab814a9 commit 735f543

File tree

17 files changed

+779
-15
lines changed

17 files changed

+779
-15
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ third_party/nlfaultinjection/
2727
third_party/nlio/
2828
third_party/nlunit-test/
2929
third_party/mbedtls/
30+
examples/common/m5stack-tft/
31+
examples/common/QRCode/repo
3032

3133
# Example specific rules
3234
examples/**/sdkconfig

config/esp32/components/chip/component.mk

+4-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ COMPONENT_ADD_INCLUDEDIRS = project-config \
142142
$(REL_CHIP_ROOT)/src/lib \
143143
$(REL_CHIP_ROOT)/src/ \
144144
$(REL_CHIP_ROOT)/src/system \
145-
$(IDF_PATH)/components/mbedtls/mbedtls/include
145+
$(IDF_PATH)/components/mbedtls/mbedtls/include \
146+
$(REL_CHIP_ROOT)/src/app \
146147

147148

148149
# Linker flags to be included when building other components that use CHIP.
@@ -151,7 +152,8 @@ COMPONENT_ADD_LDFLAGS = -L$(OUTPUT_DIR)/lib/ \
151152
-lInetLayer \
152153
-lSystemLayer \
153154
-lDeviceLayer \
154-
-lChipCrypto
155+
-lChipCrypto \
156+
-lSetupPayload
155157

156158
# Tell the ESP-IDF build system that the CHIP component defines its own build
157159
# and clean targets.

examples/common/QRCode/component.mk

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Copyright (c) 2020 Project CHIP Authors
3+
# Copyright (c) 2018 Nest Labs, Inc.
4+
# All rights reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# Description:
19+
# Component makefile for the QRCode component used by the CHIP
20+
# ESP32 demo applications.
21+
#
22+
23+
CFLAGS += -Wno-unknown-pragmas
24+
25+
COMPONENT_ADD_INCLUDEDIRS := repo/c
26+
COMPONENT_SRCDIRS := repo/c
27+
COMPONENT_OBJS := repo/c/qrcodegen.o
+19-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1+
#
2+
# Copyright (c) 2020 Project CHIP Authors
3+
# All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
117
#
218
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
319
# project subdirectory.
420
#
521

622
PROJECT_NAME := chip-wifi-echo
723

8-
EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/third_party/connectedhomeip/config/esp32/components
24+
EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/third_party/connectedhomeip/config/esp32/components \
25+
$(PROJECT_PATH)/../../../common/m5stack-tft/repo/components \
26+
$(PROJECT_PATH)/../../../common/QRCode \
927

1028
include $(IDF_PATH)/make/project.mk

examples/wifi-echo/server/esp32/README.md

+26-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ messaging is supported in CHIP.
1818
The CHIP demo application is intended to work on two categories of ESP32
1919
devices: the
2020
[ESP32-DevKitC](https://www.espressif.com/en/products/hardware/esp32-devkitc/overview),
21-
and the [M5Stack](http://m5stack.com). Support for the
22-
[M5Stack](http://m5stack.com) is still a Work in Progress.
21+
and the [M5Stack](http://m5stack.com). On the [M5Stack](http://m5stack.com) this
22+
example displays a CHIP QRCode with the device's Soft-AP SSID encoded in the TLV
23+
section.
2324

2425
## Building the Example Application
2526

@@ -45,13 +46,25 @@ step. To install these components manually, follow these steps:
4546
Currently building in VSCode _and_ deploying from native is not supported, so
4647
make sure the IDF_PATH has been exported(See the manual setup steps above).
4748

48-
- In the root of the example directory, source `idf.sh` and use the
49-
`defconfig` make target to configure the application with defaults.
49+
- In the root of the example directory, sync the dependencies and source
50+
`idf.sh`. Note: This does not have to be repeated for incremental builds.
5051

52+
$ make -C third_party/connectedhomeip -f Makefile-bootstrap repos
5153
$ source idf.sh
54+
55+
- Next, if you want to use the M5Stack with its display and show a QRCode run
56+
`menuconfig`.
57+
58+
$ idf make menuconfig
59+
60+
While in the configurator, navigate to `WiFi Echo Demo`->`Device Type` and
61+
select `M5Stack`.
62+
63+
Otherwise, run the default config.
64+
5265
$ idf make defconfig
5366

54-
- Run make to build the demo application
67+
- Run make to build the demo application.
5568

5669
$ idf make
5770

@@ -105,6 +118,10 @@ There are two ways to use the Echo Server running on the device.
105118
I (5524) chip[DL]: SYSTEM_EVENT_STA_GOT_IP
106119
I (5524) chip[DL]: IPv4 address changed on WiFi station interface: <IP_ADDRESS>...
107120

121+
Note: If you are using the M5Stack, the screen will display the server's IP
122+
Address and Port if it successfully conencts to the configured 2.4GHz
123+
Network.
124+
108125
5. Then running the following command will ping the ESP32 and cause it to echo.
109126
If necessary replace the `<IP_ADDRESS>` with the address printed by the
110127
device in the monitor.
@@ -120,9 +137,10 @@ your network configuration. To erase it, simply run.
120137

121138
Alternatively, you can connect to the ESP32's Soft-AP directly.
122139

123-
1. After the application has been flashed, connect the ESP32's Soft-AP. It's
124-
usually something like `CHIP_DEMO-XXXX` where the last 4 digits are from the
125-
device's MAC address.
140+
1. After the application has been flashed, connect the ESP32's Soft-AP. If you
141+
use the M5Stack, the Soft-AP's SSID is encoded in the TLV section of the
142+
QRCode on screen. It's usually something like `CHIP_DEMO-XXXX` where the
143+
last 4 digits are from the device's MAC address.
126144

127145
2. Once you're connected, the server's IP can be found at the gateway address
128146
and at the listed port number(Default: `8000`).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
*
3+
* Copyright (c) 2020 Project CHIP Authors
4+
* Copyright (c) 2018 Nest Labs, Inc.
5+
* All rights reserved.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#include "driver/gpio.h"
21+
#include "esp_log.h"
22+
#include "esp_system.h"
23+
24+
#include "Button.h"
25+
#include <platform/CHIPDeviceLayer.h>
26+
#include <support/CodeUtils.h>
27+
28+
extern const char * TAG;
29+
30+
esp_err_t Button::Init(gpio_num_t gpioNum, uint16_t debouncePeriod)
31+
{
32+
esp_err_t err;
33+
34+
mGPIONum = gpioNum;
35+
mDebouncePeriod = debouncePeriod / portTICK_PERIOD_MS;
36+
mState = false;
37+
mLastState = false;
38+
39+
err = gpio_set_direction(gpioNum, GPIO_MODE_INPUT);
40+
SuccessOrExit(err);
41+
42+
Poll();
43+
44+
exit:
45+
return err;
46+
}
47+
48+
bool Button::Poll()
49+
{
50+
uint32_t now = xTaskGetTickCount();
51+
52+
bool newState = gpio_get_level(mGPIONum) == 0;
53+
54+
if (newState != mLastState)
55+
{
56+
mLastState = newState;
57+
mLastReadTime = now;
58+
}
59+
60+
else if (newState != mState && (now - mLastReadTime) >= mDebouncePeriod)
61+
{
62+
mState = newState;
63+
mPrevStateDur = now - mStateStartTime;
64+
mStateStartTime = now;
65+
return true;
66+
}
67+
68+
return false;
69+
}
70+
71+
uint32_t Button::GetStateDuration()
72+
{
73+
return (xTaskGetTickCount() - mStateStartTime) * portTICK_PERIOD_MS;
74+
}

0 commit comments

Comments
 (0)