Skip to content

Commit 52106cc

Browse files
Add preliminary ESP32 platform support (#411)
* Add helper mk files for ESP32 * Rename to CHIP * Add ESP32 Device Layer source files * Rename files and fix formatting * Add ESP32 platform includes * Fix names and format * Add missing source file * Fix bad filename * Restyled by astyle * Restyled by clang-format * Restyled by whitespace * Add missing CHIP copyright Co-authored-by: Restyled.io <[email protected]>
1 parent 5daed72 commit 52106cc

39 files changed

+8996
-132
lines changed

build/esp32/components/chip/Kconfig

+839
Large diffs are not rendered by default.
+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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 building CHIP within the ESP32 ESP-IDF environment.
20+
#
21+
22+
# ==================================================
23+
# General settings
24+
# ==================================================
25+
26+
# CHIP source root directory
27+
CHIP_ROOT ?= $(realpath $(COMPONENT_PATH)/../../../..)
28+
29+
# Archtecture for which CHIP will be built.
30+
HOST_ARCH := xtensa-unknown-linux-gnu
31+
32+
# Directory into which the CHIP build system will place its output.
33+
OUTPUT_DIR := $(BUILD_DIR_BASE)/chip
34+
REL_OUTPUT_DIR := $(shell perl -e 'use File::Spec; use Cwd; print File::Spec->abs2rel(Cwd::realpath($$ARGV[0]), Cwd::realpath($$ARGV[1])) . "\n"' $(OUTPUT_DIR) $(COMPONENT_PATH))
35+
36+
# Directory containing esp32-specific CHIP project configuration files.
37+
PROJECT_CONFIG_DIR := $(CHIP_ROOT)/build/config/esp32
38+
39+
# Architcture on which CHIP is being built.
40+
BUILD_ARCH := $(shell $(CHIP_ROOT)/third_party/nlbuild-autotools/repo/third_party/autoconf/config.guess | sed -e 's/[[:digit:].]*$$//g')
41+
42+
# Directory containing the esp32-specific LwIP component sources.
43+
LWIP_COMPONENT_DIR ?= $(PROJECT_PATH)/components/lwip
44+
45+
46+
# ==================================================
47+
# Compilation flags specific to building CHIP
48+
# ==================================================
49+
50+
# Include directories to be searched when building CHIP.
51+
INCLUDES := $(OUTPUT_DIR)/src/include \
52+
$(OUTPUT_DIR)/src/include/CHIP/DeviceLayer/ESP32 \
53+
$(CHIP_ROOT)/src/adaptations/device-layer/trait-support \
54+
$(COMPONENT_INCLUDES)
55+
56+
# Compiler flags for building CHIP
57+
CFLAGS += $(addprefix -I,$(INCLUDES))
58+
CPPFLAGS += $(addprefix -I,$(INCLUDES))
59+
CXXFLAGS += $(addprefix -I,$(INCLUDES))
60+
61+
INSTALL := /usr/bin/install
62+
INSTALLFLAGS := -C -v
63+
64+
65+
# ==================================================
66+
# Utility Functions
67+
# ==================================================
68+
69+
QuoteChar = "
70+
71+
DoubleQuoteStr = $(QuoteChar)$(subst $(QuoteChar),\$(QuoteChar),$(subst \,\\,$(1)))$(QuoteChar)
72+
73+
74+
# ==================================================
75+
# CHIP configuration options
76+
# ==================================================
77+
78+
# ESP-IDF's project.mk fails to define RANLIB appropriately, so we define it here.
79+
RANLIB := $(call dequote,$(CONFIG_TOOLPREFIX))ranlib
80+
81+
CONFIGURE_OPTIONS := AR="$(AR)" CC="$(CC)" CXX="$(CXX)" LD="$(LD)" OBJCOPY="$(OBJCOPY)" RANLIB="$(RANLIB)" \
82+
INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
83+
CFLAGS=$(call DoubleQuoteStr, $(CFLAGS)) \
84+
CPPFLAGS=$(call DoubleQuoteStr, $(CPPFLAGS)) \
85+
CXXFLAGS=$(call DoubleQuoteStr, $(CXXFLAGS)) \
86+
--prefix=$(OUTPUT_DIR) \
87+
--exec-prefix=$(OUTPUT_DIR) \
88+
--host=$(HOST_ARCH) \
89+
--build=$(BUILD_ARCH) \
90+
--with-device-layer=esp32 \
91+
--with-network-layer=all \
92+
--with-target-network=lwip \
93+
--with-lwip=$(LWIP_COMPONENT_DIR) \
94+
--with-inet-endpoint="tcp udp tun dns" \
95+
--with-openssl=no \
96+
--with-logging-style=external \
97+
--with-chip-project-includes= \
98+
--with-chip-system-project-includes= \
99+
--with-chip-inet-project-includes= \
100+
--with-chip-ble-project-includes= \
101+
--with-chip-warm-project-includes= \
102+
--disable-tests \
103+
--disable-tools \
104+
--disable-docs \
105+
--disable-java \
106+
--disable-device-manager
107+
108+
# Enable debug and disable optimization if ESP-IDF Optimization Level is set to Debug.
109+
ifeq ($(CONFIG_OPTIMIZATION_LEVEL_DEBUG),y)
110+
CONFIGURE_OPTIONS += --enable-debug --enable-optimization=no
111+
else
112+
CONFIGURE_OPTIONS += --enable-optimization=yes
113+
endif
114+
115+
116+
# ==================================================
117+
# Configuration for the CHIP ESF-IDF Component
118+
# ==================================================
119+
120+
# Header directories to be included when building other components that use CHIP.
121+
# Note that these must be relative to the component source directory.
122+
COMPONENT_ADD_INCLUDEDIRS = project-config \
123+
$(REL_OUTPUT_DIR)/include
124+
125+
# Linker flags to be included when building other components that use CHIP.
126+
COMPONENT_ADD_LDFLAGS = -L$(OUTPUT_DIR)/lib \
127+
-lCHIP \
128+
-lInetLayer \
129+
-lmincrypt \
130+
-lnlfaultinjection \
131+
-lSystemLayer \
132+
-luECC \
133+
-lWarm \
134+
-lDeviceLayer
135+
136+
# Tell the ESP-IDF build system that the CHIP component defines its own build
137+
# and clean targets.
138+
COMPONENT_OWNBUILDTARGET = 1
139+
COMPONENT_OWNCLEANTARGET = 1
140+
141+
142+
# ==================================================
143+
# Build Rules
144+
# ==================================================
145+
146+
.PHONY : check-config-args-updated
147+
check-config-args-updated : | $(OUTPUT_DIR)
148+
echo $(CHIP_ROOT)/configure $(CONFIGURE_OPTIONS) > $(OUTPUT_DIR)/config.args.tmp; \
149+
(test -r $(OUTPUT_DIR)/config.args && cmp -s $(OUTPUT_DIR)/config.args.tmp $(OUTPUT_DIR)/config.args) || \
150+
mv $(OUTPUT_DIR)/config.args.tmp $(OUTPUT_DIR)/config.args; \
151+
rm -f $(OUTPUT_DIR)/config.args.tmp;
152+
153+
$(OUTPUT_DIR)/config.args : check-config-args-updated
154+
@: # Null action required to work around make's crazy timestamp caching behavior.
155+
156+
$(CHIP_ROOT)/configure : $(CHIP_ROOT)/configure.ac
157+
echo "BOOTSTRAP CHIP..."
158+
(cd $(CHIP_ROOT) && ./bootstrap)
159+
160+
$(OUTPUT_DIR)/config.status : $(CHIP_ROOT)/configure $(OUTPUT_DIR)/config.args
161+
echo "CONFIGURE CHIP..."
162+
(cd $(OUTPUT_DIR) && $(CHIP_ROOT)/configure $(CONFIGURE_OPTIONS))
163+
164+
configure-chip : $(OUTPUT_DIR)/config.status
165+
166+
$(OUTPUT_DIR) :
167+
echo "MKDIR $@"
168+
@mkdir -p "$@"
169+
170+
build-chip : configure-chip
171+
echo "BUILD CHIP..."
172+
MAKEFLAGS= make -C $(OUTPUT_DIR) --no-print-directory all
173+
174+
install-chip : | build-chip
175+
echo "INSTALL CHIP..."
176+
MAKEFLAGS= make -C $(OUTPUT_DIR) --no-print-directory install
177+
178+
build : build-chip install-chip
179+
180+
clean:
181+
echo "RM $(OUTPUT_DIR)"
182+
rm -rf $(OUTPUT_DIR)

src/include/platform/CHIPDeviceEvent.h

+33-22
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@
2727

2828
namespace chip {
2929
namespace DeviceLayer {
30-
3130
namespace DeviceEventType {
3231

3332
enum
3433
{
35-
kFlag_IsPublic = 0x8000,
36-
kFlag_IsPlatformSpecific = 0x4000,
37-
kFlag_Reserved1 = 0x2000,
38-
kFlag_Reserved2 = 0x1000,
39-
kMaxEventNum = 0x0FFF,
34+
kFlag_IsPublic = 0x8000,
35+
kFlag_IsPlatformSpecific = 0x4000,
36+
kFlag_Reserved1 = 0x2000,
37+
kFlag_Reserved2 = 0x1000,
38+
kMaxEventNum = 0x0FFF,
4039
};
4140

4241
/**
@@ -53,35 +52,47 @@ enum EventTypeRanges
5352
* Denotes a range of event types that are publicly visible to applications. Events in this
5453
* range a generic to all platforms.
5554
*/
56-
kRange_Public = kFlag_IsPublic,
55+
kRange_Public = kFlag_IsPublic,
5756

5857
/**
5958
* Public, Platform-specific Event Range
6059
*
6160
* Denotes a range of platform-specific event types that are publicly visible to applications.
6261
*/
63-
kRange_PublicPlatformSpecific = kFlag_IsPublic | kFlag_IsPlatformSpecific,
62+
kRange_PublicPlatformSpecific = kFlag_IsPublic | kFlag_IsPlatformSpecific,
6463

6564
/**
6665
* Internal Event Range
6766
*
6867
* Denotes a range of event types that are internal to the chip Device Layer. Events in this
6968
* range a generic to all platforms.
7069
*/
71-
kRange_Internal = 0,
70+
kRange_Internal = 0,
7271

7372
/**
7473
* Internal, Platform-specific Event Range
7574
*
7675
* Denotes a range of platform-specific event types that are internal to the chip Device Layer.
7776
*/
78-
kRange_InternalPlatformSpecific = kFlag_IsPlatformSpecific,
77+
kRange_InternalPlatformSpecific = kFlag_IsPlatformSpecific,
7978
};
8079

81-
inline bool IsPublic(uint16_t eventType) { return (eventType & kFlag_IsPublic) != 0; }
82-
inline bool IsInternal(uint16_t eventType) { return (eventType & kFlag_IsPublic) == 0; }
83-
inline bool IsPlatformSpecific(uint16_t eventType) { return (eventType & kFlag_IsPlatformSpecific) != 0; }
84-
inline bool IsPlatformGeneric(uint16_t eventType) { return (eventType & kFlag_IsPlatformSpecific) == 0; }
80+
inline bool IsPublic(uint16_t eventType)
81+
{
82+
return (eventType & kFlag_IsPublic) != 0;
83+
}
84+
inline bool IsInternal(uint16_t eventType)
85+
{
86+
return (eventType & kFlag_IsPublic) == 0;
87+
}
88+
inline bool IsPlatformSpecific(uint16_t eventType)
89+
{
90+
return (eventType & kFlag_IsPlatformSpecific) != 0;
91+
}
92+
inline bool IsPlatformGeneric(uint16_t eventType)
93+
{
94+
return (eventType & kFlag_IsPlatformSpecific) == 0;
95+
}
8596

8697
/**
8798
* Public Event Types
@@ -96,7 +107,7 @@ enum PublicEventTypes
96107
*
97108
* Signals a change in connectivity of the device's WiFi station interface.
98109
*/
99-
kWiFiConnectivityChange = kRange_Public,
110+
kWiFiConnectivityChange = kRange_Public,
100111

101112
/**
102113
* Thread Connectivity Change
@@ -205,7 +216,7 @@ enum PublicEventTypes
205216
*/
206217
enum InternalEventTypes
207218
{
208-
kEventTypeNotSet = kRange_Internal,
219+
kEventTypeNotSet = kRange_Internal,
209220
kNoOp,
210221
kCallWorkFunct,
211222
kChipSystemLayerEvent,
@@ -227,9 +238,9 @@ static_assert(kEventTypeNotSet == 0, "kEventTypeNotSet must be defined as 0");
227238
*/
228239
enum ConnectivityChange
229240
{
230-
kConnectivity_NoChange = 0,
231-
kConnectivity_Established = 1,
232-
kConnectivity_Lost = -1
241+
kConnectivity_NoChange = 0,
242+
kConnectivity_Established = 1,
243+
kConnectivity_Lost = -1
233244
};
234245

235246
/**
@@ -239,9 +250,9 @@ enum ConnectivityChange
239250
*/
240251
enum ActivityChange
241252
{
242-
kActivity_NoChange = 0,
243-
kActivity_Started = 1,
244-
kActivity_Stopped = -1,
253+
kActivity_NoChange = 0,
254+
kActivity_Started = 1,
255+
kActivity_Stopped = -1,
245256
};
246257

247258
inline ConnectivityChange GetConnectivityChange(bool prevState, bool newState)

0 commit comments

Comments
 (0)