Skip to content

Commit

Permalink
Add preliminary ESP32 platform support (project-chip#411)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
sagar-apple and restyled-commits authored Apr 21, 2020
1 parent 5daed72 commit 52106cc
Show file tree
Hide file tree
Showing 39 changed files with 8,996 additions and 132 deletions.
839 changes: 839 additions & 0 deletions build/esp32/components/chip/Kconfig

Large diffs are not rendered by default.

182 changes: 182 additions & 0 deletions build/esp32/components/chip/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#
# Copyright (c) 2020 Project CHIP Authors
# Copyright (c) 2018 Nest Labs, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Description:
# Component makefile for building CHIP within the ESP32 ESP-IDF environment.
#

# ==================================================
# General settings
# ==================================================

# CHIP source root directory
CHIP_ROOT ?= $(realpath $(COMPONENT_PATH)/../../../..)

# Archtecture for which CHIP will be built.
HOST_ARCH := xtensa-unknown-linux-gnu

# Directory into which the CHIP build system will place its output.
OUTPUT_DIR := $(BUILD_DIR_BASE)/chip
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))

# Directory containing esp32-specific CHIP project configuration files.
PROJECT_CONFIG_DIR := $(CHIP_ROOT)/build/config/esp32

# Architcture on which CHIP is being built.
BUILD_ARCH := $(shell $(CHIP_ROOT)/third_party/nlbuild-autotools/repo/third_party/autoconf/config.guess | sed -e 's/[[:digit:].]*$$//g')

# Directory containing the esp32-specific LwIP component sources.
LWIP_COMPONENT_DIR ?= $(PROJECT_PATH)/components/lwip


# ==================================================
# Compilation flags specific to building CHIP
# ==================================================

# Include directories to be searched when building CHIP.
INCLUDES := $(OUTPUT_DIR)/src/include \
$(OUTPUT_DIR)/src/include/CHIP/DeviceLayer/ESP32 \
$(CHIP_ROOT)/src/adaptations/device-layer/trait-support \
$(COMPONENT_INCLUDES)

# Compiler flags for building CHIP
CFLAGS += $(addprefix -I,$(INCLUDES))
CPPFLAGS += $(addprefix -I,$(INCLUDES))
CXXFLAGS += $(addprefix -I,$(INCLUDES))

INSTALL := /usr/bin/install
INSTALLFLAGS := -C -v


# ==================================================
# Utility Functions
# ==================================================

QuoteChar = "

DoubleQuoteStr = $(QuoteChar)$(subst $(QuoteChar),\$(QuoteChar),$(subst \,\\,$(1)))$(QuoteChar)


# ==================================================
# CHIP configuration options
# ==================================================

# ESP-IDF's project.mk fails to define RANLIB appropriately, so we define it here.
RANLIB := $(call dequote,$(CONFIG_TOOLPREFIX))ranlib

CONFIGURE_OPTIONS := AR="$(AR)" CC="$(CC)" CXX="$(CXX)" LD="$(LD)" OBJCOPY="$(OBJCOPY)" RANLIB="$(RANLIB)" \
INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
CFLAGS=$(call DoubleQuoteStr, $(CFLAGS)) \
CPPFLAGS=$(call DoubleQuoteStr, $(CPPFLAGS)) \
CXXFLAGS=$(call DoubleQuoteStr, $(CXXFLAGS)) \
--prefix=$(OUTPUT_DIR) \
--exec-prefix=$(OUTPUT_DIR) \
--host=$(HOST_ARCH) \
--build=$(BUILD_ARCH) \
--with-device-layer=esp32 \
--with-network-layer=all \
--with-target-network=lwip \
--with-lwip=$(LWIP_COMPONENT_DIR) \
--with-inet-endpoint="tcp udp tun dns" \
--with-openssl=no \
--with-logging-style=external \
--with-chip-project-includes= \
--with-chip-system-project-includes= \
--with-chip-inet-project-includes= \
--with-chip-ble-project-includes= \
--with-chip-warm-project-includes= \
--disable-tests \
--disable-tools \
--disable-docs \
--disable-java \
--disable-device-manager

# Enable debug and disable optimization if ESP-IDF Optimization Level is set to Debug.
ifeq ($(CONFIG_OPTIMIZATION_LEVEL_DEBUG),y)
CONFIGURE_OPTIONS += --enable-debug --enable-optimization=no
else
CONFIGURE_OPTIONS += --enable-optimization=yes
endif


# ==================================================
# Configuration for the CHIP ESF-IDF Component
# ==================================================

# Header directories to be included when building other components that use CHIP.
# Note that these must be relative to the component source directory.
COMPONENT_ADD_INCLUDEDIRS = project-config \
$(REL_OUTPUT_DIR)/include

# Linker flags to be included when building other components that use CHIP.
COMPONENT_ADD_LDFLAGS = -L$(OUTPUT_DIR)/lib \
-lCHIP \
-lInetLayer \
-lmincrypt \
-lnlfaultinjection \
-lSystemLayer \
-luECC \
-lWarm \
-lDeviceLayer

# Tell the ESP-IDF build system that the CHIP component defines its own build
# and clean targets.
COMPONENT_OWNBUILDTARGET = 1
COMPONENT_OWNCLEANTARGET = 1


# ==================================================
# Build Rules
# ==================================================

.PHONY : check-config-args-updated
check-config-args-updated : | $(OUTPUT_DIR)
echo $(CHIP_ROOT)/configure $(CONFIGURE_OPTIONS) > $(OUTPUT_DIR)/config.args.tmp; \
(test -r $(OUTPUT_DIR)/config.args && cmp -s $(OUTPUT_DIR)/config.args.tmp $(OUTPUT_DIR)/config.args) || \
mv $(OUTPUT_DIR)/config.args.tmp $(OUTPUT_DIR)/config.args; \
rm -f $(OUTPUT_DIR)/config.args.tmp;

$(OUTPUT_DIR)/config.args : check-config-args-updated
@: # Null action required to work around make's crazy timestamp caching behavior.

$(CHIP_ROOT)/configure : $(CHIP_ROOT)/configure.ac
echo "BOOTSTRAP CHIP..."
(cd $(CHIP_ROOT) && ./bootstrap)

$(OUTPUT_DIR)/config.status : $(CHIP_ROOT)/configure $(OUTPUT_DIR)/config.args
echo "CONFIGURE CHIP..."
(cd $(OUTPUT_DIR) && $(CHIP_ROOT)/configure $(CONFIGURE_OPTIONS))

configure-chip : $(OUTPUT_DIR)/config.status

$(OUTPUT_DIR) :
echo "MKDIR $@"
@mkdir -p "$@"

build-chip : configure-chip
echo "BUILD CHIP..."
MAKEFLAGS= make -C $(OUTPUT_DIR) --no-print-directory all

install-chip : | build-chip
echo "INSTALL CHIP..."
MAKEFLAGS= make -C $(OUTPUT_DIR) --no-print-directory install

build : build-chip install-chip

clean:
echo "RM $(OUTPUT_DIR)"
rm -rf $(OUTPUT_DIR)
55 changes: 33 additions & 22 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@

namespace chip {
namespace DeviceLayer {

namespace DeviceEventType {

enum
{
kFlag_IsPublic = 0x8000,
kFlag_IsPlatformSpecific = 0x4000,
kFlag_Reserved1 = 0x2000,
kFlag_Reserved2 = 0x1000,
kMaxEventNum = 0x0FFF,
kFlag_IsPublic = 0x8000,
kFlag_IsPlatformSpecific = 0x4000,
kFlag_Reserved1 = 0x2000,
kFlag_Reserved2 = 0x1000,
kMaxEventNum = 0x0FFF,
};

/**
Expand All @@ -53,35 +52,47 @@ enum EventTypeRanges
* Denotes a range of event types that are publicly visible to applications. Events in this
* range a generic to all platforms.
*/
kRange_Public = kFlag_IsPublic,
kRange_Public = kFlag_IsPublic,

/**
* Public, Platform-specific Event Range
*
* Denotes a range of platform-specific event types that are publicly visible to applications.
*/
kRange_PublicPlatformSpecific = kFlag_IsPublic | kFlag_IsPlatformSpecific,
kRange_PublicPlatformSpecific = kFlag_IsPublic | kFlag_IsPlatformSpecific,

/**
* Internal Event Range
*
* Denotes a range of event types that are internal to the chip Device Layer. Events in this
* range a generic to all platforms.
*/
kRange_Internal = 0,
kRange_Internal = 0,

/**
* Internal, Platform-specific Event Range
*
* Denotes a range of platform-specific event types that are internal to the chip Device Layer.
*/
kRange_InternalPlatformSpecific = kFlag_IsPlatformSpecific,
kRange_InternalPlatformSpecific = kFlag_IsPlatformSpecific,
};

inline bool IsPublic(uint16_t eventType) { return (eventType & kFlag_IsPublic) != 0; }
inline bool IsInternal(uint16_t eventType) { return (eventType & kFlag_IsPublic) == 0; }
inline bool IsPlatformSpecific(uint16_t eventType) { return (eventType & kFlag_IsPlatformSpecific) != 0; }
inline bool IsPlatformGeneric(uint16_t eventType) { return (eventType & kFlag_IsPlatformSpecific) == 0; }
inline bool IsPublic(uint16_t eventType)
{
return (eventType & kFlag_IsPublic) != 0;
}
inline bool IsInternal(uint16_t eventType)
{
return (eventType & kFlag_IsPublic) == 0;
}
inline bool IsPlatformSpecific(uint16_t eventType)
{
return (eventType & kFlag_IsPlatformSpecific) != 0;
}
inline bool IsPlatformGeneric(uint16_t eventType)
{
return (eventType & kFlag_IsPlatformSpecific) == 0;
}

/**
* Public Event Types
Expand All @@ -96,7 +107,7 @@ enum PublicEventTypes
*
* Signals a change in connectivity of the device's WiFi station interface.
*/
kWiFiConnectivityChange = kRange_Public,
kWiFiConnectivityChange = kRange_Public,

/**
* Thread Connectivity Change
Expand Down Expand Up @@ -205,7 +216,7 @@ enum PublicEventTypes
*/
enum InternalEventTypes
{
kEventTypeNotSet = kRange_Internal,
kEventTypeNotSet = kRange_Internal,
kNoOp,
kCallWorkFunct,
kChipSystemLayerEvent,
Expand All @@ -227,9 +238,9 @@ static_assert(kEventTypeNotSet == 0, "kEventTypeNotSet must be defined as 0");
*/
enum ConnectivityChange
{
kConnectivity_NoChange = 0,
kConnectivity_Established = 1,
kConnectivity_Lost = -1
kConnectivity_NoChange = 0,
kConnectivity_Established = 1,
kConnectivity_Lost = -1
};

/**
Expand All @@ -239,9 +250,9 @@ enum ConnectivityChange
*/
enum ActivityChange
{
kActivity_NoChange = 0,
kActivity_Started = 1,
kActivity_Stopped = -1,
kActivity_NoChange = 0,
kActivity_Started = 1,
kActivity_Stopped = -1,
};

inline ConnectivityChange GetConnectivityChange(bool prevState, bool newState)
Expand Down
Loading

0 comments on commit 52106cc

Please sign in to comment.