Skip to content

Commit

Permalink
[nrfconnect] Remove redundant defines from CHIPProjectConfig.h (#30190)
Browse files Browse the repository at this point in the history
* [nrfconnect] Remove redundant defines from CHIPProjectConfig.h

Most test device parameters can be configured via Kconfig,
so configuring them directly in CHIPProjectConfig.h is
unnecessary and confusing (it is unclear which source of the
configuration takes precedence).

Map Kconfig options to CHIP_DEVICE_XXX C defines
unconditionally to detect macro redefinitions. Then, remove
redundant defines from nRF Connect examples'
CHIPProjectConfig.h files.

* Fix chef build

* Restyled by autopep8

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed May 7, 2024
1 parent 2436647 commit 1146192
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@

#pragma once

// Use a default pairing code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00

// All clusters app has 3 group endpoints. This needs to defined here so that
// CHIP_CONFIG_MAX_GROUPS_PER_FABRIC is properly configured.
#define CHIP_CONFIG_MAX_GROUP_ENDPOINTS_PER_FABRIC 3
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@
*/

#pragma once

// Use a default pairing code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
16 changes: 14 additions & 2 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ def main() -> int:

shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}")

if options.build_target in "esp32 nrfconnect ameba telink".split():
if options.build_target in "esp32 ameba telink".split():
with open("project_include.cmake", "w") as f:
f.write(textwrap.dedent(f"""\
set(CONFIG_DEVICE_VENDOR_ID {options.vid})
Expand Down Expand Up @@ -713,8 +713,20 @@ def main() -> int:
nrf_build_cmds = ["west build -b nrf52840dk_nrf52840"]
if options.do_clean:
nrf_build_cmds.append("-p always")
nrf_build_cmds.append("--")
if options.do_rpc:
nrf_build_cmds.append("-- -DOVERLAY_CONFIG=rpc.overlay")
nrf_build_cmds.append("-DOVERLAY_CONFIG=rpc.overlay")
nrf_build_cmds.append(
f"-DCONFIG_CHIP_DEVICE_VENDOR_ID={options.vid}")
nrf_build_cmds.append(
f"-DCONFIG_CHIP_DEVICE_PRODUCT_ID={options.pid}")
nrf_build_cmds.append(
f"-DCONFIG_CHIP_DEVICE_PRODUCT_NAME='\"{options.pname}\"'")
nrf_build_cmds.append(
f"-DSAMPLE_NAME={options.sample_device_type_name}")
nrf_build_cmds.append(
f"-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING='\"{sw_ver_string}\"'")

shell.run_cmd(" ".join(nrf_build_cmds))

elif options.build_target == "silabs-thread":
Expand Down
4 changes: 0 additions & 4 deletions examples/chef/nrfconnect/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

#pragma once

// Use a default pairing code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00

// Enable support functions for parsing command-line arguments
#define CHIP_CONFIG_ENABLE_ARG_PARSER 1

Expand Down
25 changes: 6 additions & 19 deletions examples/chef/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,16 @@ get_filename_component(NRFCONNECT_COMMON ${CHIP_ROOT}/examples/platform/nrfconne
get_filename_component(CHEF ${CMAKE_CURRENT_SOURCE_DIR}/../ REALPATH)

include(${CHIP_ROOT}/config/nrfconnect/app/check-nrfconnect-version.cmake)
include(${CHEF}/project_include.cmake)

get_filename_component(GEN_DIR ${CHEF}/out/${SAMPLE_NAME}/zap-generated REALPATH)

set(CONF_FILE prj.conf)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID=${CONFIG_DEVICE_VENDOR_ID}")
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID=${CONFIG_DEVICE_PRODUCT_ID}")
if(NOT ${CONFIG_DEVICE_PRODUCT_NAME} STREQUAL "")
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME=\"${CONFIG_DEVICE_PRODUCT_NAME}\"")
endif()
if(NOT ${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING} STREQUAL "")
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\"${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING}\"")
endif()
message(STATUS "Vendor ID " ${CONFIG_DEVICE_VENDOR_ID})
message(STATUS "Product ID " ${CONFIG_DEVICE_PRODUCT_ID})
message(STATUS "Product Name " ${CONFIG_DEVICE_PRODUCT_NAME})
message(STATUS "SW Version String" ${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING})
message(STATUS "Vendor ID " ${CONFIG_CHIP_DEVICE_VENDOR_ID})
message(STATUS "Product ID " ${CONFIG_CHIP_DEVICE_PRODUCT_ID})
message(STATUS "Product Name " ${CONFIG_CHIP_DEVICE_PRODUCT_NAME})
message(STATUS "SW Version String" ${CONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING})

# Set Kconfig root files that will be processed as a first Kconfig for used child images.
set(mcuboot_KCONFIG_ROOT ${CHIP_ROOT}/config/nrfconnect/chip-module/Kconfig.mcuboot.root)
Expand Down Expand Up @@ -107,11 +98,7 @@ chip_configure_data_model(app
include(${CHIP_ROOT}/config/nrfconnect/app/flashing.cmake)


if (CONFIG_ENABLE_PW_RPC)

target_compile_options(app PRIVATE
"-DCONFIG_ENABLE_PW_RPC=1"
)
if (CONFIG_CHIP_PW_RPC)

# Make all targets created below depend on zephyr_interface to inherit MCU-related compilation flags
link_libraries($<BUILD_INTERFACE:zephyr_interface>)
Expand Down Expand Up @@ -231,4 +218,4 @@ target_link_libraries(app PRIVATE
pw_sys_io
)

endif(CONFIG_ENABLE_PW_RPC)
endif(CONFIG_CHIP_PW_RPC)
4 changes: 2 additions & 2 deletions examples/chef/nrfconnect/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <ChipShellCollection.h>
#endif

#ifdef CONFIG_ENABLE_PW_RPC
#ifdef CONFIG_CHIP_PW_RPC
#include "Rpc.h"
#endif

Expand All @@ -57,7 +57,7 @@ int main()
{
CHIP_ERROR err = CHIP_NO_ERROR;

#ifdef CONFIG_ENABLE_PW_RPC
#ifdef CONFIG_CHIP_PW_RPC
rpc::Init();
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,3 @@
#pragma once

#define CHIP_CONFIG_CONTROLLER_MAX_ACTIVE_DEVICES 2
/* Use a default pairing code if one hasn't been provisioned in flash. */
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

#pragma once

// Use a default pairing code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00

// Switching from Thread child to router may cause a few second packet stall.
// Until this is improved in OpenThread we need to increase the retransmission
// interval to survive the stall.
Expand Down
4 changes: 0 additions & 4 deletions examples/lock-app/nrfconnect/main/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@
*/

#pragma once

// Use a default pairing code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "pw_sys_io/sys_io.h"
#include <cassert>
#include <zephyr/console/console.h>
#include <zephyr/zephyr.h>
#include <zephyr/kernel.h>

#ifdef CONFIG_USB
#include <zephyr/usb/usb_device.h>
Expand Down
4 changes: 0 additions & 4 deletions examples/pump-app/nrfconnect/main/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@
*/

#pragma once

// Use a default pairing code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@
*/

#pragma once

// Use a default pairing code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
4 changes: 0 additions & 4 deletions examples/shell/nrfconnect/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

#pragma once

// Use a default pairing code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00

// Enable support functions for parsing command-line arguments
#define CHIP_CONFIG_ENABLE_ARG_PARSER 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@
*/

#pragma once

// Use a default pairing code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00
69 changes: 11 additions & 58 deletions src/platform/nrfconnect/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,22 @@

// ==================== Platform Adaptations ====================

#ifndef CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER CONFIG_CHIP_DEVICE_SERIAL_NUMBER
#endif

#ifndef CHIP_DEVICE_CONFIG_TEST_MANUFACTURING_DATE
#define CHIP_DEVICE_CONFIG_TEST_MANUFACTURING_DATE CONFIG_CHIP_DEVICE_MANUFACTURING_DATE
#endif

#ifndef CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION
#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION CONFIG_CHIP_DEVICE_HARDWARE_VERSION
#endif

#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE CONFIG_CHIP_DEVICE_SPAKE2_PASSCODE
#endif

#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR CONFIG_CHIP_DEVICE_DISCRIMINATOR
#endif

#ifndef CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING
#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING CONFIG_CHIP_DEVICE_HARDWARE_VERSION_STRING
#endif

#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_ITERATION_COUNT
#define CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_ITERATION_COUNT CONFIG_CHIP_DEVICE_SPAKE2_IT
#endif

#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_SALT
#define CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_SALT CONFIG_CHIP_DEVICE_SPAKE2_SALT
#endif

#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_VERIFIER
#define CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_VERIFIER CONFIG_CHIP_DEVICE_SPAKE2_TEST_VERIFIER
#endif

#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID
#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID CONFIG_CHIP_DEVICE_VENDOR_ID
#endif

#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID CONFIG_CHIP_DEVICE_PRODUCT_ID
#endif

#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME
#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME CONFIG_CHIP_DEVICE_VENDOR_NAME
#endif

#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID CONFIG_CHIP_DEVICE_PRODUCT_ID
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME CONFIG_CHIP_DEVICE_PRODUCT_NAME
#endif

#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION
#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION CONFIG_CHIP_DEVICE_HARDWARE_VERSION
#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING CONFIG_CHIP_DEVICE_HARDWARE_VERSION_STRING
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION CONFIG_CHIP_DEVICE_SOFTWARE_VERSION
#endif

#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING CONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING
#endif
#define CHIP_DEVICE_CONFIG_TEST_MANUFACTURING_DATE CONFIG_CHIP_DEVICE_MANUFACTURING_DATE
#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER CONFIG_CHIP_DEVICE_SERIAL_NUMBER
#define CHIP_DEVICE_CONFIG_DEVICE_TYPE CONFIG_CHIP_DEVICE_TYPE
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR CONFIG_CHIP_DEVICE_DISCRIMINATOR
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE CONFIG_CHIP_DEVICE_SPAKE2_PASSCODE
#define CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_ITERATION_COUNT CONFIG_CHIP_DEVICE_SPAKE2_IT
#define CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_SALT CONFIG_CHIP_DEVICE_SPAKE2_SALT
#define CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_VERIFIER CONFIG_CHIP_DEVICE_SPAKE2_TEST_VERIFIER

#ifdef CONFIG_NET_L2_OPENTHREAD
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD CONFIG_NET_L2_OPENTHREAD
Expand Down Expand Up @@ -249,10 +206,6 @@
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_TYPE 1
#endif // CONFIG_CHIP_COMMISSIONABLE_DEVICE_TYPE

#ifdef CONFIG_CHIP_DEVICE_TYPE
#define CHIP_DEVICE_CONFIG_DEVICE_TYPE CONFIG_CHIP_DEVICE_TYPE
#endif // CONFIG_CHIP_DEVICE_TYPE

#ifdef CONFIG_CHIP_EXTENDED_DISCOVERY
#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1
#endif // CONFIG_CHIP_EXTENDED_DISCOVERY
Expand Down

0 comments on commit 1146192

Please sign in to comment.