matter: add cmake support

A nuttx with the matter command can be compiled using cmake and enable CONFIG_MATTER option.
The matter compiled by the current script is just a lighting example of
a limited number of commands that can be tested by chip-tool.

After nuttx is connected to the LAN and the matter command is executed, other devices in the LAN, such as linux PCS, can run the following commands to scan, connect, turn on and off, adjust brightness and contrast, and so on.

chip-tool pairing onnetwork 1 20202021
chip-tool onoff on 1 1
chip-tool levelcontrol move-to-level 128 10 0 0 1 1
chip-tool colorcontrol move-to-hue-and-saturation 240 100 0 0 0 1 1

Depends on the following configuration options:
CONFIG_CRYPTO_MBEDTLS=y
CONFIG_DEV_URANDOM=y
CONFIG_LIBCXX=y
CONFIG_LIBM=y
CONFIG_NET_IPv6=y
CONFIG_NET_ICMPv6=y
CONFIG_NET_ICMPv6_AUTOCONF=y
CONFIG_NET_ICMPv6_NEIGHBOR=y
CONFIG_NET_ICMPv6_ROUTER=y
CONFIG_NET_ICMPv6_SOCKET=y
CONFIG_NET_IGMP=y
CONFIG_NET_MLD=y
CONFIG_NET_MLD_ROUTER=y

This initial version does not yet have Bluetooth and OTA support.

The community version needs to dynamically fetch the matter source code at compile time and apply the required nuttx adaptation patch.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu 2023-11-06 20:52:34 +08:00 committed by Xiang Xiao
parent 097411de49
commit 891c5e0cc8
3 changed files with 262 additions and 0 deletions

4
netutils/connectedhomeip/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/connectedhomeip
/inipp
/nlassert
/nlio

View File

@ -0,0 +1,248 @@
# ##############################################################################
# external/connectedhomeip/CMakeLists.txt
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you 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.
#
# ##############################################################################
if(CONFIG_MATTER)
include(ExternalProject)
get_filename_component(
CHIP_ROOT ${NUTTX_APPS_DIR}/netutils/connectedhomeip/connectedhomeip
REALPATH)
get_filename_component(GN_ROOT_TARGET ${CHIP_ROOT}/config/nuttx/chip-gn
REALPATH)
get_filename_component(COMMON_CMAKE_SOURCE_DIR
${CHIP_ROOT}/config/common/cmake REALPATH)
include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake)
include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake)
set(MATTER_INCDIR
${CMAKE_BINARY_DIR}/include
${CMAKE_BINARY_DIR}/include_arch
${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip/gen/include
${NUTTX_DIR}/include/libcxx
${NUTTX_DIR}/libs/libxx/libcxx/include
${NUTTX_DIR}/include
inipp
nlio/include
nlassert/include
connectedhomeip/src
connectedhomeip/src/include
connectedhomeip/src/lib/dnssd
connectedhomeip/src/app/util/mock/include
connectedhomeip/zzz_generated
connectedhomeip/zzz_generated/lighting-app
connectedhomeip/zzz_generated/app-common
connectedhomeip/src/platform/Linux
connectedhomeip/examples/platform/linux
connectedhomeip/third_party/jsoncpp/repo/include
connectedhomeip/examples/lighting-app/lighting-common/include
${NUTTX_APPS_DIR}/external/zblue/zblue/port/include
${NUTTX_APPS_DIR}/external/zblue/zblue/include
${NUTTX_APPS_DIR}/external/zblue/zblue/subsys/testsuite/ztest/include/
${NUTTX_APPS_DIR}/crypto/mbedtls/mbedtls/include)
set(MATTER_FLAGS
-DCHIP_HAVE_CONFIG_H
-fexceptions
-fpermissive
-std=c++17
-Wno-undef
-Wno-format
-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>
)
set(EXTERNAL_MATTER_INCDIR)
foreach(estring ${MATTER_INCDIR})
list(APPEND EXTERNAL_MATTER_INCDIR "\"${estring}\"")
endforeach()
matter_add_gn_arg_string("nuttx_ar" ${CMAKE_AR})
matter_add_gn_arg_string("nuttx_cc" ${CMAKE_C_COMPILER})
matter_add_gn_arg_string("nuttx_cxx" ${CMAKE_CXX_COMPILER})
matter_add_flags("-D__NuttX__ ")
if(CONFIG_ARCH_SIM)
if(CONFIG_SIM_M32)
matter_add_gn_arg_string("target_cpu" "x86")
else()
matter_add_gn_arg_string("target_cpu" "x86_64")
endif()
elseif(CONFIG_ARCH_ARM)
matter_add_gn_arg_string("target_cpu" "arm")
elseif(CONFIG_ARCH_RISCV)
matter_add_gn_arg_string("target_cpu" "riscv")
matter_add_gn_arg_string("riscv_arch" "${ARCHTYPE}${ARCHCPUEXTFLAGS}")
if(CONFIG_ARCH_DPFPU)
matter_add_gn_arg_string("riscv_abi" "${ARCHABITYPE}d")
elseif(CONFIG_ARCH_FPU)
matter_add_gn_arg_string("riscv_abi" "${ARCHABITYPE}f")
else()
matter_add_gn_arg_string("riscv_abi" "${ARCHABITYPE}")
endif()
if(CONFIG_ARCH_RV32)
if(${ARCHCPUEXTFLAGS} STREQUAL imc)
matter_add_gn_arg_string("riscv_cpu" "sifive-e20")
elseif(${ARCHCPUEXTFLAGS} STREQUAL imac)
matter_add_gn_arg_string("riscv_cpu" "sifive-e31")
elseif(${ARCHCPUEXTFLAGS} STREQUAL imafc)
matter_add_gn_arg_string("riscv_cpu" "sifive-e76")
endif()
else()
if(${ARCHCPUEXTFLAGS} STREQUAL imac)
matter_add_gn_arg_string("riscv_cpu" "sifive-s51")
elseif(${ARCHCPUEXTFLAGS} STREQUAL imafdc)
matter_add_gn_arg_string("riscv_cpu" "sifive-u54")
endif()
endif()
if(CONFIG_ARCH_RV64)
matter_add_flags("-mcmodel=medany")
endif()
endif()
matter_add_gn_arg_bool("chip_inet_config_enable_ipv4" CONFIG_NET_IPv4)
matter_add_gn_arg_bool("chip_enable_ble")
matter_add_gn_arg_bool("chip_example_lighting" true)
matter_add_gn_arg_bool("chip_config_network_layer_ble")
matter_common_gn_args(PROJECT_CONFIG_INC_DIR ${EXTERNAL_MATTER_INCDIR})
matter_generate_args_tmp_file()
matter_build(
chip
LIB_SHELL
${CONFIG_CHIP_LIB_SHELL}
LIB_PW_RPC
${CONFIG_CHIP_PW_RPC}
LIB_TESTS
${CONFIG_CHIP_BUILD_TESTS}
LIB_MBEDTLS)
add_custom_command(
OUTPUT connectedhomeip/third_party/pigweed/repo
COMMAND
test -e ${CHIP_ROOT}/third_party/pigweed/repo/.git || git clone
https://github.com/google/pigweed.git -b main
${CHIP_ROOT}/third_party/pigweed/repo)
add_custom_target(chippigweed ALL
DEPENDS connectedhomeip/third_party/pigweed/repo)
ExternalProject_Add_StepDependencies(chip-gn configure chippigweed)
add_custom_command(
OUTPUT ${CHIP_ROOT}/build_overrides/pigweed_environment.gni
COMMAND touch ${CHIP_ROOT}/build_overrides/pigweed_environment.gni)
add_custom_target(
chipnpigweedenv ALL
DEPENDS ${CHIP_ROOT}/build_overrides/pigweed_environment.gni)
ExternalProject_Add_StepDependencies(chip-gn configure chipnpigweedenv)
add_dependencies(chippigweed chipnpigweedenv)
add_custom_command(
OUTPUT connectedhomeip/third_party/nlassert/repo
COMMAND
test -e ${CHIP_ROOT}/third_party/nlassert/repo/.git || git clone
https://github.com/nestlabs/nlassert.git -b master
${CHIP_ROOT}/third_party/nlassert/repo)
add_custom_target(chipnlassert ALL
DEPENDS connectedhomeip/third_party/nlassert/repo)
ExternalProject_Add_StepDependencies(chip-gn configure chipnlassert)
add_custom_command(
OUTPUT connectedhomeip/third_party/nlio/repo
COMMAND
test -e ${CHIP_ROOT}/third_party/nlio/repo/.git || git clone
https://github.com/nestlabs/nlio.git -b master
${CHIP_ROOT}/third_party/nlio/repo)
add_custom_target(chipnlio ALL DEPENDS connectedhomeip/third_party/nlio/repo)
ExternalProject_Add_StepDependencies(chip-gn configure chipnlio)
add_custom_command(
OUTPUT connectedhomeip/third_party/nlunit-test/repo
COMMAND
test -e ${CHIP_ROOT}/third_party/nlunit-test/repo/.git || git clone
https://github.com/nestlabs/nlunit-test.git -b master
${CHIP_ROOT}/third_party/nlunit-test/repo)
add_custom_target(chipnlunit-test ALL
DEPENDS connectedhomeip/third_party/nlunit-test/repo)
ExternalProject_Add_StepDependencies(chip-gn configure chipnlunit-test)
set(JSONSRC
${CHIP_ROOT}/third_party/jsoncpp/repo/src/lib_json/json_writer.cpp
${CHIP_ROOT}/third_party/jsoncpp/repo/src/lib_json/json_value.cpp
${CHIP_ROOT}/third_party/jsoncpp/repo/src/lib_json/json_reader.cpp)
add_custom_command(
OUTPUT connectedhomeip/third_party/jsoncpp/repo ${JSONSRC}
COMMAND
test -e ${CHIP_ROOT}/third_party/jsoncpp/repo/.git || rm -r
${CHIP_ROOT}/third_party/jsoncpp/repo/src && test -e
${CHIP_ROOT}/third_party/jsoncpp/repo/.git || git clone
https://github.com/open-source-parsers/jsoncpp.git
${CHIP_ROOT}/third_party/jsoncpp/repo)
add_custom_target(chipjsoncpp ALL
DEPENDS connectedhomeip/third_party/jsoncpp/repo)
ExternalProject_Add_StepDependencies(chip-gn configure chipjsoncpp)
set(DEMOSRC
${CHIP_ROOT}/examples/lighting-app/linux/main.cpp
${CHIP_ROOT}/examples/lighting-app/linux/LightingAppCommandDelegate.cpp
${JSONSRC})
nuttx_add_application(
NAME
matter
SRCS
${DEMOSRC}
INCLUDE_DIRECTORIES
${MATTER_INCDIR}
COMPILE_FLAGS
${MATTER_FLAGS}
DEPENDS
chip-gn
STACKSIZE
16384
PRIORITY
100)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip/lib/libchipnuttx.a
COMMAND echo generate libchipnuttx.a)
add_custom_target(
libchipnuttx ALL
DEPENDS ${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip/lib/libchipnuttx.a
)
add_dependencies(libchipnuttx chip-gn)
nuttx_add_extra_library(
${CMAKE_BINARY_DIR}/apps/netutils/connectedhomeip/lib/libchipnuttx.a)
endif()

View File

@ -0,0 +1,10 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config MATTER
bool "Connected Home over IP (CHIP)"
default n
---help---
Enable the Connected Home over IP (CHIP)