From 952e0f58381c5368a7d40e2098b56f4fbe2206b6 Mon Sep 17 00:00:00 2001 From: step0035 <77708985+step0035@users.noreply.github.com> Date: Wed, 11 Jan 2023 10:05:01 +0800 Subject: [PATCH] [portinglayer] Add the porting layer for matter (#35) - restructure the files - create matter api - create new light example using the porting layer --- component/common/application/matter/README.md | 21 + .../matter/common/{ => atcmd}/atcmd_matter.c | 8 +- .../{ => common}/mbedtls/mbedtls_config.h | 0 .../matter/{ => common}/mbedtls/net_sockets.c | 0 .../port}/chip_porting.h | 0 .../port}/matter_dcts.c | 0 .../port}/matter_dcts.h | 0 .../port}/matter_timers.c | 0 .../port}/matter_timers.h | 0 .../port}/matter_utils.c | 0 .../port}/matter_utils.h | 0 .../port}/matter_wifis.c | 0 .../port}/matter_wifis.h | 0 .../{ => common}/protobuf/ameba_factory.pb.c | 0 .../{ => common}/protobuf/ameba_factory.pb.h | 0 .../matter/{ => common}/protobuf/nanopb/pb.h | 0 .../{ => common}/protobuf/nanopb/pb_common.c | 0 .../{ => common}/protobuf/nanopb/pb_common.h | 0 .../{ => common}/protobuf/nanopb/pb_decode.c | 0 .../{ => common}/protobuf/nanopb/pb_decode.h | 0 .../{ => common}/protobuf/nanopb/pb_encode.c | 0 .../{ => common}/protobuf/nanopb/pb_encode.h | 0 .../application/matter/core/matter_core.cpp | 162 ++++++++ .../application/matter/core/matter_core.h | 5 + .../application/matter/core/matter_events.h | 21 + .../matter/core/matter_interaction.cpp | 216 +++++++++++ .../matter/core/matter_interaction.h | 10 + .../application/matter/core/matter_ota.cpp | 29 ++ .../application/matter/core/matter_ota.h | 1 + .../application/matter/driver/led_driver.cpp | 283 ++++++++++++++ .../application/matter/driver/led_driver.h | 60 +++ .../chiptest}/example_matter.c | 0 .../chiptest}/example_matter.h | 0 .../application/matter/example/light/Makefile | 49 +++ .../matter/example/light/README.md | 55 +++ .../example/light/example_matter_light.cpp | 57 +++ .../example/light/example_matter_light.h | 6 + .../example/light/lib_chip_light_core.mk | 259 +++++++++++++ .../example/light/lib_chip_light_main.mk | 363 ++++++++++++++++++ .../matter/example/light/matter_drivers.cpp | 148 +++++++ .../matter/example/light/matter_drivers.h | 12 + component/common/example/example_entry.c | 9 + .../GCC-RELEASE/application.is.matter.mk | 34 +- .../GCC-RELEASE/lib_chip.mk | 5 +- .../GCC-RELEASE/lib_chip_chef_core.mk | 6 +- .../GCC-RELEASE/lib_chip_chef_main.mk | 4 +- .../GCC-RELEASE/lib_chip_light_core.mk | 6 +- .../GCC-RELEASE/lib_chip_light_main.mk | 4 +- .../GCC-RELEASE/lib_chip_main.mk | 5 +- .../GCC-RELEASE/lib_chip_otar_core.mk | 6 +- .../GCC-RELEASE/lib_chip_otar_main.mk | 4 +- .../GCC-RELEASE/lib_chip_switch_core.mk | 4 +- .../GCC-RELEASE/lib_chip_switch_main.mk | 4 +- .../inc/platform_opts.h | 2 + 54 files changed, 1817 insertions(+), 41 deletions(-) create mode 100644 component/common/application/matter/README.md rename component/common/application/matter/common/{ => atcmd}/atcmd_matter.c (91%) rename component/common/application/matter/{ => common}/mbedtls/mbedtls_config.h (100%) rename component/common/application/matter/{ => common}/mbedtls/net_sockets.c (100%) rename component/common/application/matter/{application => common/port}/chip_porting.h (100%) rename component/common/application/matter/{application => common/port}/matter_dcts.c (100%) rename component/common/application/matter/{application => common/port}/matter_dcts.h (100%) rename component/common/application/matter/{application => common/port}/matter_timers.c (100%) rename component/common/application/matter/{application => common/port}/matter_timers.h (100%) rename component/common/application/matter/{application => common/port}/matter_utils.c (100%) rename component/common/application/matter/{application => common/port}/matter_utils.h (100%) rename component/common/application/matter/{application => common/port}/matter_wifis.c (100%) rename component/common/application/matter/{application => common/port}/matter_wifis.h (100%) rename component/common/application/matter/{ => common}/protobuf/ameba_factory.pb.c (100%) rename component/common/application/matter/{ => common}/protobuf/ameba_factory.pb.h (100%) rename component/common/application/matter/{ => common}/protobuf/nanopb/pb.h (100%) rename component/common/application/matter/{ => common}/protobuf/nanopb/pb_common.c (100%) rename component/common/application/matter/{ => common}/protobuf/nanopb/pb_common.h (100%) rename component/common/application/matter/{ => common}/protobuf/nanopb/pb_decode.c (100%) rename component/common/application/matter/{ => common}/protobuf/nanopb/pb_decode.h (100%) rename component/common/application/matter/{ => common}/protobuf/nanopb/pb_encode.c (100%) rename component/common/application/matter/{ => common}/protobuf/nanopb/pb_encode.h (100%) create mode 100644 component/common/application/matter/core/matter_core.cpp create mode 100644 component/common/application/matter/core/matter_core.h create mode 100644 component/common/application/matter/core/matter_events.h create mode 100644 component/common/application/matter/core/matter_interaction.cpp create mode 100644 component/common/application/matter/core/matter_interaction.h create mode 100644 component/common/application/matter/core/matter_ota.cpp create mode 100644 component/common/application/matter/core/matter_ota.h create mode 100644 component/common/application/matter/driver/led_driver.cpp create mode 100644 component/common/application/matter/driver/led_driver.h rename component/common/application/matter/{application => example/chiptest}/example_matter.c (100%) rename component/common/application/matter/{application => example/chiptest}/example_matter.h (100%) create mode 100644 component/common/application/matter/example/light/Makefile create mode 100644 component/common/application/matter/example/light/README.md create mode 100644 component/common/application/matter/example/light/example_matter_light.cpp create mode 100644 component/common/application/matter/example/light/example_matter_light.h create mode 100644 component/common/application/matter/example/light/lib_chip_light_core.mk create mode 100644 component/common/application/matter/example/light/lib_chip_light_main.mk create mode 100644 component/common/application/matter/example/light/matter_drivers.cpp create mode 100644 component/common/application/matter/example/light/matter_drivers.h diff --git a/component/common/application/matter/README.md b/component/common/application/matter/README.md new file mode 100644 index 00000000..58bc9a2f --- /dev/null +++ b/component/common/application/matter/README.md @@ -0,0 +1,21 @@ +# Matter Application Porting Layer + +The goal of this porting layer is to make it easier for users to design their own Matter applications. The porting layer provides core Matter APIs for users and also makes it easier to add their own codes, such as their own peripheral drivers. + +## Structure +| Directory | Description | +| ----------- | ----------- | +| common | contains common files and utilities to support Matter, used by all types of Matter applications | +| core | contains files that provides core Matter APIs | +| driver | peripheral drivers to be used by Matter application callbacks | +| example | Matter application examples for reference, according to device types | + +## How to design your own custom Matter application with the porting layer +1. You do not need to modify/add files under `common` or `core` +2. Under `driver`, place your peripheral driver code, see existing driver files for reference +3. Under `example`, you may create your new custom example directory, or modify an existing one + - Your example should at least have the following files: + - Main task (see `light/example_matter_light.cpp`) + - Driver interface (see `light/matter_drivers.cpp`) + - Makefiles to build the Matter libraries +4. More details on how it works will be explained in the examples themselves diff --git a/component/common/application/matter/common/atcmd_matter.c b/component/common/application/matter/common/atcmd/atcmd_matter.c similarity index 91% rename from component/common/application/matter/common/atcmd_matter.c rename to component/common/application/matter/common/atcmd/atcmd_matter.c index ce6d0cc7..ffbcc964 100644 --- a/component/common/application/matter/common/atcmd_matter.c +++ b/component/common/application/matter/common/atcmd/atcmd_matter.c @@ -10,9 +10,11 @@ extern void ChipTest(void); extern u32 deinitPref(void); #if CONFIG_ENABLE_OTA_REQUESTOR +#if CONFIG_EXAMPLE_MATTER_CHIPTEST extern void amebaQueryImageCmdHandler(); extern void amebaApplyUpdateCmdHandler(); #endif +#endif void fATchipapp(void *arg) { @@ -34,19 +36,23 @@ void fATchipapp(void *arg) void fATchipapp1(void *arg) { #if CONFIG_ENABLE_OTA_REQUESTOR +#if CONFIG_EXAMPLE_MATTER_CHIPTEST printf("Chip Test: amebaQueryImageCmdHandler\r\n"); amebaQueryImageCmdHandler(); #endif +#endif } void fATchipapp2(void *arg) { #if CONFIG_ENABLE_OTA_REQUESTOR +#if CONFIG_EXAMPLE_MATTER_CHIPTEST (void) arg; printf("Chip Test: amebaApplyUpdateCmdHandler\r\n"); amebaApplyUpdateCmdHandler(); #endif +#endif } log_item_t at_matter_items[] = { @@ -68,4 +74,4 @@ void at_matter_init(void) log_module_init(at_matter_init); #endif -#endif /* CHIP_PROJECT */ \ No newline at end of file +#endif /* CHIP_PROJECT */ diff --git a/component/common/application/matter/mbedtls/mbedtls_config.h b/component/common/application/matter/common/mbedtls/mbedtls_config.h similarity index 100% rename from component/common/application/matter/mbedtls/mbedtls_config.h rename to component/common/application/matter/common/mbedtls/mbedtls_config.h diff --git a/component/common/application/matter/mbedtls/net_sockets.c b/component/common/application/matter/common/mbedtls/net_sockets.c similarity index 100% rename from component/common/application/matter/mbedtls/net_sockets.c rename to component/common/application/matter/common/mbedtls/net_sockets.c diff --git a/component/common/application/matter/application/chip_porting.h b/component/common/application/matter/common/port/chip_porting.h similarity index 100% rename from component/common/application/matter/application/chip_porting.h rename to component/common/application/matter/common/port/chip_porting.h diff --git a/component/common/application/matter/application/matter_dcts.c b/component/common/application/matter/common/port/matter_dcts.c similarity index 100% rename from component/common/application/matter/application/matter_dcts.c rename to component/common/application/matter/common/port/matter_dcts.c diff --git a/component/common/application/matter/application/matter_dcts.h b/component/common/application/matter/common/port/matter_dcts.h similarity index 100% rename from component/common/application/matter/application/matter_dcts.h rename to component/common/application/matter/common/port/matter_dcts.h diff --git a/component/common/application/matter/application/matter_timers.c b/component/common/application/matter/common/port/matter_timers.c similarity index 100% rename from component/common/application/matter/application/matter_timers.c rename to component/common/application/matter/common/port/matter_timers.c diff --git a/component/common/application/matter/application/matter_timers.h b/component/common/application/matter/common/port/matter_timers.h similarity index 100% rename from component/common/application/matter/application/matter_timers.h rename to component/common/application/matter/common/port/matter_timers.h diff --git a/component/common/application/matter/application/matter_utils.c b/component/common/application/matter/common/port/matter_utils.c similarity index 100% rename from component/common/application/matter/application/matter_utils.c rename to component/common/application/matter/common/port/matter_utils.c diff --git a/component/common/application/matter/application/matter_utils.h b/component/common/application/matter/common/port/matter_utils.h similarity index 100% rename from component/common/application/matter/application/matter_utils.h rename to component/common/application/matter/common/port/matter_utils.h diff --git a/component/common/application/matter/application/matter_wifis.c b/component/common/application/matter/common/port/matter_wifis.c similarity index 100% rename from component/common/application/matter/application/matter_wifis.c rename to component/common/application/matter/common/port/matter_wifis.c diff --git a/component/common/application/matter/application/matter_wifis.h b/component/common/application/matter/common/port/matter_wifis.h similarity index 100% rename from component/common/application/matter/application/matter_wifis.h rename to component/common/application/matter/common/port/matter_wifis.h diff --git a/component/common/application/matter/protobuf/ameba_factory.pb.c b/component/common/application/matter/common/protobuf/ameba_factory.pb.c similarity index 100% rename from component/common/application/matter/protobuf/ameba_factory.pb.c rename to component/common/application/matter/common/protobuf/ameba_factory.pb.c diff --git a/component/common/application/matter/protobuf/ameba_factory.pb.h b/component/common/application/matter/common/protobuf/ameba_factory.pb.h similarity index 100% rename from component/common/application/matter/protobuf/ameba_factory.pb.h rename to component/common/application/matter/common/protobuf/ameba_factory.pb.h diff --git a/component/common/application/matter/protobuf/nanopb/pb.h b/component/common/application/matter/common/protobuf/nanopb/pb.h similarity index 100% rename from component/common/application/matter/protobuf/nanopb/pb.h rename to component/common/application/matter/common/protobuf/nanopb/pb.h diff --git a/component/common/application/matter/protobuf/nanopb/pb_common.c b/component/common/application/matter/common/protobuf/nanopb/pb_common.c similarity index 100% rename from component/common/application/matter/protobuf/nanopb/pb_common.c rename to component/common/application/matter/common/protobuf/nanopb/pb_common.c diff --git a/component/common/application/matter/protobuf/nanopb/pb_common.h b/component/common/application/matter/common/protobuf/nanopb/pb_common.h similarity index 100% rename from component/common/application/matter/protobuf/nanopb/pb_common.h rename to component/common/application/matter/common/protobuf/nanopb/pb_common.h diff --git a/component/common/application/matter/protobuf/nanopb/pb_decode.c b/component/common/application/matter/common/protobuf/nanopb/pb_decode.c similarity index 100% rename from component/common/application/matter/protobuf/nanopb/pb_decode.c rename to component/common/application/matter/common/protobuf/nanopb/pb_decode.c diff --git a/component/common/application/matter/protobuf/nanopb/pb_decode.h b/component/common/application/matter/common/protobuf/nanopb/pb_decode.h similarity index 100% rename from component/common/application/matter/protobuf/nanopb/pb_decode.h rename to component/common/application/matter/common/protobuf/nanopb/pb_decode.h diff --git a/component/common/application/matter/protobuf/nanopb/pb_encode.c b/component/common/application/matter/common/protobuf/nanopb/pb_encode.c similarity index 100% rename from component/common/application/matter/protobuf/nanopb/pb_encode.c rename to component/common/application/matter/common/protobuf/nanopb/pb_encode.c diff --git a/component/common/application/matter/protobuf/nanopb/pb_encode.h b/component/common/application/matter/common/protobuf/nanopb/pb_encode.h similarity index 100% rename from component/common/application/matter/protobuf/nanopb/pb_encode.h rename to component/common/application/matter/common/protobuf/nanopb/pb_encode.h diff --git a/component/common/application/matter/core/matter_core.cpp b/component/common/application/matter/core/matter_core.cpp new file mode 100644 index 00000000..36eab769 --- /dev/null +++ b/component/common/application/matter/core/matter_core.cpp @@ -0,0 +1,162 @@ +#include +#include + +#include "matter_core.h" +#include "matter_ota.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include + +#include + +#include +#include +#include + +using namespace ::chip; +using namespace ::chip::DeviceLayer; + +app::Clusters::NetworkCommissioning::Instance + sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::AmebaWiFiDriver::GetInstance())); + +chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; +chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; + +void matter_core_device_callback_internal(const ChipDeviceEvent * event, intptr_t arg) +{ + switch (event->Type) + { + case DeviceEventType::kInternetConnectivityChange: +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + static bool isOTAInitialized = false; +#endif + if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) + { + ChipLogProgress(DeviceLayer, "IPv4 Server ready..."); + chip::app::DnssdServer::Instance().StartServer(); + } + else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost) + { + ChipLogProgress(DeviceLayer, "Lost IPv4 connectivity..."); + } + if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established) + { + ChipLogProgress(DeviceLayer, "IPv6 Server ready..."); + chip::app::DnssdServer::Instance().StartServer(); + + ChipLogProgress(DeviceLayer, "Initializing route hook..."); + ameba_route_hook_init(); +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + // Init OTA requestor only when we have gotten IPv6 address + if (!isOTAInitialized) + { + matter_ota_init(); + isOTAInitialized = true; + } +#endif + } + else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost) + { + ChipLogProgress(DeviceLayer, "Lost IPv6 connectivity..."); + } + break; + + case DeviceEventType::kInterfaceIpAddressChanged: + if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) || + (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)) + { + // MDNS server restart on any ip assignment: if link local ipv6 is configured, that + // will not trigger a 'internet connectivity change' as there is no internet + // connectivity. MDNS still wants to refresh its listening interfaces to include the + // newly selected address. + chip::app::DnssdServer::Instance().StartServer(); + } + break; + } +} + +void matter_core_init_server(intptr_t context) +{ + xTaskHandle task_to_notify = reinterpret_cast(context); + // Init ZCL Data Model and CHIP App Server + static chip::CommonCaseDeviceServerInitParams initParams; + initParams.InitializeStaticResourcesBeforeServerInit(); + chip::Server::GetInstance().Init(initParams); + gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + + sWiFiNetworkCommissioningInstance.Init(); + + // We only have network commissioning on endpoint 0. + // TODO: configure the endpoint + emberAfEndpointEnableDisable(0xFFFE, false); + + if (RTW_SUCCESS != wifi_is_connected_to_ap()) + { + // QR code will be used with CHIP Tool + PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); + } + xTaskNotifyGive(task_to_notify); +} + +CHIP_ERROR matter_core_init() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + err = Platform::MemoryInit(); + SuccessOrExit(err); + + // Initialize the CHIP stack. + err = PlatformMgr().InitChipStack(); + SuccessOrExit(err); + + // TODO: update this when upstream PR merged + SetCommissionableDataProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + + if (CONFIG_NETWORK_LAYER_BLE) + { + ConnectivityMgr().SetBLEAdvertisingEnabled(true); + } + + // Start a task to run the CHIP Device event loop. + err = PlatformMgr().StartEventLoopTask(); + SuccessOrExit(err); + + // Register a function to receive events from the CHIP device layer. Note that calls to + // this function will happen on the CHIP event loop thread, not the app_main thread. + PlatformMgr().AddEventHandler(matter_core_device_callback_internal, reinterpret_cast(NULL)); + + // PlatformMgr().ScheduleWork(matter_core_init_server, 0); + PlatformMgr().ScheduleWork(matter_core_init_server, reinterpret_cast(xTaskGetCurrentTaskHandle())); + xTaskNotifyWait(0, 0, NULL, portMAX_DELAY); + +exit: + return err; +} + +CHIP_ERROR matter_core_start() +{ + return matter_core_init(); + // matter_core_init_server(); +} diff --git a/component/common/application/matter/core/matter_core.h b/component/common/application/matter/core/matter_core.h new file mode 100644 index 00000000..aa49531f --- /dev/null +++ b/component/common/application/matter/core/matter_core.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +CHIP_ERROR matter_core_start(void); diff --git a/component/common/application/matter/core/matter_events.h b/component/common/application/matter/core/matter_events.h new file mode 100644 index 00000000..dd6aaa44 --- /dev/null +++ b/component/common/application/matter/core/matter_events.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +struct AppEvent; +typedef void (*EventHandler)(AppEvent *); + +struct AppEvent +{ + enum AppEventTypes + { + kEventType_Uplink = 0, + kEventType_Downlink_OnOff, + kEventType_Downlink_Identify, + }; + + uint16_t Type; + chip::app::ConcreteAttributePath path; + uint8_t value; + EventHandler mHandler; +}; diff --git a/component/common/application/matter/core/matter_interaction.cpp b/component/common/application/matter/core/matter_interaction.cpp new file mode 100644 index 00000000..d9757556 --- /dev/null +++ b/component/common/application/matter/core/matter_interaction.cpp @@ -0,0 +1,216 @@ +#include "matter_drivers.h" +#include "matter_events.h" +#include "matter_interaction.h" + +#include +#include +#include +#include + +using namespace ::chip; +using namespace ::chip::app; + +QueueHandle_t UplinkEventQueue; +QueueHandle_t DownlinkEventQueue; +TaskHandle_t UplinkTaskHandle; +TaskHandle_t DownlinkTaskHandle; + +void PostDownlinkEvent(const AppEvent * aEvent) +{ + if (DownlinkEventQueue != NULL) + { + BaseType_t status; + + // Event is posted in ISR, use ISR api + BaseType_t higherPrioTaskWoken = pdFALSE; + status = xQueueSendFromISR(DownlinkEventQueue, aEvent, &higherPrioTaskWoken); + + if (!status) + ChipLogError(DeviceLayer, "Failed to post downlink event to downlink event queue with"); + } + else + { + ChipLogError(DeviceLayer, "Downlink Event Queue is NULL should never happen"); + } +} + +void DispatchDownlinkEvent(AppEvent * aEvent) +{ + if (aEvent->mHandler) + { + aEvent->mHandler(aEvent); + } + else + { + ChipLogError(DeviceLayer, "Downlink event received with no handler. Dropping event."); + } +} + +void DownlinkTask(void * pvParameter) +{ + AppEvent event; + + ChipLogProgress(DeviceLayer, "Downlink Task started"); + + // Loop here and keep listening on the queue for Downlink (Firmware application to matter) + while (true) + { + BaseType_t eventReceived = xQueueReceive(DownlinkEventQueue, &event, pdMS_TO_TICKS(10)); + while (eventReceived == pdTRUE) + { + DispatchDownlinkEvent(&event); + eventReceived = xQueueReceive(DownlinkEventQueue, &event, 0); // return immediately if the queue is empty + } + } +} + +CHIP_ERROR matter_interaction_start_downlink() +{ + DownlinkEventQueue = xQueueCreate(10, sizeof(AppEvent)); + if (DownlinkEventQueue == NULL) + { + ChipLogError(DeviceLayer, "Failed to allocate downlink event queue"); + return CHIP_ERROR_NO_MEMORY; + } + + // Start Downlink task. + BaseType_t xReturned; + xReturned = xTaskCreate(DownlinkTask, "Downlink", 1024, NULL, 1, &DownlinkTaskHandle); + + return (xReturned == pdPASS) ? CHIP_NO_ERROR : CHIP_ERROR_NO_MEMORY; +} + +void PostUplinkEvent(const AppEvent * aEvent) +{ + if (UplinkEventQueue != NULL) + { + BaseType_t status; + status = xQueueSend(UplinkEventQueue, aEvent, 1); + + if (!status) + ChipLogError(DeviceLayer, "Failed to post uplink event to uplink event queue"); + } + else + { + ChipLogError(DeviceLayer, "Uplink Event Queue is NULL should never happen"); + } +} + +void DispatchUplinkEvent(AppEvent * aEvent) +{ + if (aEvent->mHandler) + { + aEvent->mHandler(aEvent); + } + else + { + ChipLogError(DeviceLayer, "Uplink event received with no handler. Dropping event."); + } +} + +void UplinkTask(void * pvParameter) +{ + AppEvent event; + + ChipLogProgress(DeviceLayer, "Uplink Task started"); + + // Loop here and keep listening on the queue for Uplink (matter to Firmware application) + while (true) + { + BaseType_t eventReceived = xQueueReceive(UplinkEventQueue, &event, pdMS_TO_TICKS(10)); + while (eventReceived == pdTRUE) + { + DispatchUplinkEvent(&event); + eventReceived = xQueueReceive(UplinkEventQueue, &event, 0); // return immediately if the queue is empty + } + } +} + +CHIP_ERROR matter_interaction_start_uplink() +{ + UplinkEventQueue = xQueueCreate(10, sizeof(AppEvent)); + if (UplinkEventQueue == NULL) + { + ChipLogError(DeviceLayer, "Failed to allocate uplink event queue"); + return CHIP_ERROR_NO_MEMORY; + } + + // Start Uplink task. + BaseType_t xReturned; + xReturned = xTaskCreate(UplinkTask, "Uplink", 1024, NULL, 1, &UplinkTaskHandle); + return (xReturned == pdPASS) ? CHIP_NO_ERROR : CHIP_ERROR_NO_MEMORY; +} + +void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & path, uint8_t type, uint16_t size, uint8_t * value) +{ + AppEvent uplink_event; + uplink_event.Type = AppEvent::kEventType_Uplink; + uplink_event.value = *value; + uplink_event.path = path; + + switch (path.mClusterId) + { + case ZCL_ON_OFF_CLUSTER_ID: + uplink_event.mHandler = matter_driver_attribute_update; + PostUplinkEvent(&uplink_event); + break; + + case ZCL_LEVEL_CONTROL_CLUSTER_ID: + uplink_event.mHandler = matter_driver_attribute_update; + PostUplinkEvent(&uplink_event); + break; + + case ZCL_IDENTIFY_CLUSTER_ID: + uplink_event.mHandler = matter_driver_attribute_update; + PostUplinkEvent(&uplink_event); + break; + + default: + uplink_event.mHandler = NULL; + break; + } +} + +void matter_interaction_update_cluster(AppEvent * event) +{ + switch (event->Type) + { + case AppEvent::kEventType_Downlink_OnOff: + ChipLogProgress(DeviceLayer, "Writing to OnOff cluster"); + // write the new on/off value + // TODO: we only support endpoint1 + EmberAfStatus status = Clusters::OnOff::Attributes::OnOff::Set(1, matter_driver_led_get_onoff()); + + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + ChipLogError(DeviceLayer, "Updating on/off cluster failed: %x", status); + } + + ChipLogError(DeviceLayer, "Writing to Current Level cluster"); + // write the new currentlevel value + // TODO: we only support endpoint1 + status = Clusters::LevelControl::Attributes::CurrentLevel::Set(1, matter_driver_led_get_level()); + + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + ChipLogError(DeviceLayer, "Updating level cluster failed: %x", status); + } + break; + + // TODO: Add more attribute changes + } +} + +void matter_interaction_onoff_handler(AppEvent * aEvent) +{ + if (aEvent->Type != AppEvent::kEventType_Downlink_OnOff) + { + ChipLogError(DeviceLayer, "Wrong downlink event handler, should not happen!"); + return; + } + + matter_driver_led_toggle(); + chip::DeviceLayer::PlatformMgr().LockChipStack(); + matter_interaction_update_cluster(aEvent); + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); +} diff --git a/component/common/application/matter/core/matter_interaction.h b/component/common/application/matter/core/matter_interaction.h new file mode 100644 index 00000000..b5fb6d36 --- /dev/null +++ b/component/common/application/matter/core/matter_interaction.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include "matter_events.h" +#include + +void PostDownlinkEvent(const AppEvent * aEvent); +CHIP_ERROR matter_interaction_start_downlink(void); +CHIP_ERROR matter_interaction_start_uplink(void); +void matter_interaction_onoff_handler(AppEvent *aEvent); diff --git a/component/common/application/matter/core/matter_ota.cpp b/component/common/application/matter/core/matter_ota.cpp new file mode 100644 index 00000000..71c1b974 --- /dev/null +++ b/component/common/application/matter/core/matter_ota.cpp @@ -0,0 +1,29 @@ +#include "matter_ota.h" +#include "app/clusters/ota-requestor/DefaultOTARequestorStorage.h" +#include +#include +#include +#include + +using namespace chip; +using namespace chip::DeviceLayer; + +namespace { +DefaultOTARequestor gRequestorCore; +DefaultOTARequestorStorage gRequestorStorage; +DefaultOTARequestorDriver gRequestorUser; +BDXDownloader gDownloader; +AmebaOTAImageProcessor gImageProcessor; +} // namespace + +void matter_ota_init() +{ + SetRequestorInstance(&gRequestorCore); + gRequestorStorage.Init(chip::Server::GetInstance().GetPersistentStorage()); + // Set server instance used for session establishment + gRequestorCore.Init(chip::Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader); + gImageProcessor.SetOTADownloader(&gDownloader); + // Connect the Downloader and Image Processor objects + gDownloader.SetImageProcessorDelegate(&gImageProcessor); + gRequestorUser.Init(&gRequestorCore, &gImageProcessor); +} diff --git a/component/common/application/matter/core/matter_ota.h b/component/common/application/matter/core/matter_ota.h new file mode 100644 index 00000000..82a19b55 --- /dev/null +++ b/component/common/application/matter/core/matter_ota.h @@ -0,0 +1 @@ +void matter_ota_init(void); diff --git a/component/common/application/matter/driver/led_driver.cpp b/component/common/application/matter/driver/led_driver.cpp new file mode 100644 index 00000000..7100b062 --- /dev/null +++ b/component/common/application/matter/driver/led_driver.cpp @@ -0,0 +1,283 @@ +#include "led_driver.h" +#include +#include + +// normal LED +void MatterLED::Init(PinName pin) +{ + mPwm_obj = (pwmout_t*) pvPortMalloc(sizeof(pwmout_t)); + + pwmout_init(mPwm_obj, pin); + + mRgb = false; + mState = false; + mBrightness = 254; + mHue = 0; + mSaturation = 0; +} + +// RGB LED +void MatterLED::Init(PinName redpin, PinName greenpin, PinName bluepin) +{ + mPwm_red = (pwmout_t*) pvPortMalloc(sizeof(pwmout_t)); + mPwm_green = (pwmout_t*) pvPortMalloc(sizeof(pwmout_t)); + mPwm_blue = (pwmout_t*) pvPortMalloc(sizeof(pwmout_t)); + pwmout_init(mPwm_red, redpin); + pwmout_init(mPwm_green, bluepin); + pwmout_init(mPwm_blue, greenpin); + + mRgb = true; + mRgbw = false; + mState = false; + mBrightness = 254; + mHue = 0; + mSaturation = 0; +} + +// RGBCW LED +void MatterLED::Init(PinName redpin, PinName greenpin, PinName bluepin, PinName cwhitepin, PinName wwhitepin) +{ + mPwm_red = (pwmout_t*) pvPortMalloc(sizeof(pwmout_t)); + mPwm_green = (pwmout_t*) pvPortMalloc(sizeof(pwmout_t)); + mPwm_blue = (pwmout_t*) pvPortMalloc(sizeof(pwmout_t)); + mPwm_cwhite = (pwmout_t*) pvPortMalloc(sizeof(pwmout_t)); + mPwm_wwhite = (pwmout_t*) pvPortMalloc(sizeof(pwmout_t)); + pwmout_init(mPwm_red, redpin); + pwmout_init(mPwm_green, bluepin); + pwmout_init(mPwm_blue, greenpin); + pwmout_init(mPwm_cwhite, cwhitepin); + pwmout_init(mPwm_wwhite, wwhitepin); + + mRgb = true; + mRgbw = true; + mState = false; + mBrightness = 254; + mHue = 0; + mSaturation = 0; +} + +void MatterLED::deInit(void) +{ + if (mRgb) + { + vPortFree(mPwm_red); + vPortFree(mPwm_green); + vPortFree(mPwm_blue); + } + if (mRgbw) + { + vPortFree(mPwm_cwhite); + vPortFree(mPwm_wwhite); + } + else + { + vPortFree(mPwm_obj); + } +} + +uint8_t MatterLED::GetLevel() +{ + return this->mBrightness; +} + +bool MatterLED::IsTurnedOn() +{ + return this->mState; +} + +void MatterLED::Set(bool state) +{ + if (mState == state) + return; + + mState = state; + // DoSet will be done during levelcontrol change +} + +void MatterLED::Toggle() +{ + mState = !mState; + // DoSet will be done during levelcontrol change +} + +void MatterLED::SetBrightness(uint8_t brightness) +{ + mBrightness = brightness; + + DoSet(); +} + +void MatterLED::DoSet() +{ + uint8_t brightness = mState ? mBrightness : 0; + + if (!mRgb) + { + float duty_cycle = (float) (brightness) / 254; + pwmout_write(mPwm_obj, duty_cycle); + } + else + { + uint8_t red, green, blue, coolwhite, warmwhite; + float duty_red, duty_green, duty_blue, duty_cwhite, duty_wwhite; + // uint8_t brightness = mState ? mBrightness : 0; + + HSB2rgb(mHue, mSaturation, brightness, red, green, blue); + + if (mRgbw) + { + simpleRGB2RGBW(red, green, blue, coolwhite, warmwhite); + duty_cwhite = static_cast (coolwhite) / 254.0; + duty_wwhite = static_cast (warmwhite) / 254.0; + } + + duty_red = static_cast(red) / 254.0; + duty_green = static_cast(green) / 254.0; + duty_blue = static_cast(blue) / 254.0; + + // ChipLogProgress(DeviceLayer, "brightness: %d", brightness); + // ChipLogProgress(DeviceLayer, "red: %d, red_duty: %f", red, duty_red); + // ChipLogProgress(DeviceLayer, "green: %d, green_duty: %f", green, duty_green); + // ChipLogProgress(DeviceLayer, "blue: %d, blue_duty: %f", blue, duty_blue); + + if (mRgbw) + { + // ChipLogProgress(DeviceLayer, "cwhite: %d, cwhite_duty: %f", coolwhite, duty_cwhite); + // ChipLogProgress(DeviceLayer, "wwhite: %d, wwhite_duty: %f", warmwhite, duty_wwhite); + pwmout_write(mPwm_cwhite, duty_cwhite); + pwmout_write(mPwm_wwhite, duty_wwhite); + } + + pwmout_write(mPwm_red, duty_red); + pwmout_write(mPwm_blue, duty_blue); + pwmout_write(mPwm_green, duty_green); + + } +} + +// Below functions are WIP +void MatterLED::SetColor(uint8_t Hue, uint8_t Saturation) +{ + if (mRgb) + { + uint8_t red, green, blue, coolwhite, warmwhite; + float duty_red, duty_green, duty_blue, duty_cwhite, duty_wwhite; + uint8_t brightness = mState ? mBrightness : 0; + mHue = static_cast(Hue) * 360 / 254; // mHue [0, 360] + mSaturation = static_cast(Saturation) * 100 / 254; // mSaturation [0 , 100] + + HSB2rgb(mHue, mSaturation, brightness, red, green, blue); + + if (mRgbw) + { + simpleRGB2RGBW(red, green, blue, coolwhite, warmwhite); + duty_cwhite = static_cast (coolwhite) / 254.0; + duty_wwhite = static_cast (warmwhite) / 254.0; + } + + duty_red = static_cast(red) / 254.0; + duty_green = static_cast(green) / 254.0; + duty_blue = static_cast(blue) / 254.0; + + ChipLogProgress(DeviceLayer, "brightness: %d", brightness); + ChipLogProgress(DeviceLayer, "red: %d, red_duty: %f", red, duty_red); + ChipLogProgress(DeviceLayer, "green: %d, green_duty: %f", green, duty_green); + ChipLogProgress(DeviceLayer, "blue: %d, blue_duty: %f", blue, duty_blue); + + if (mRgbw) + { + ChipLogProgress(DeviceLayer, "cwhite: %d, cwhite_duty: %f", coolwhite, duty_cwhite); + ChipLogProgress(DeviceLayer, "wwhite: %d, wwhite_duty: %f\r\n", warmwhite, duty_wwhite); + pwmout_write(mPwm_cwhite, duty_cwhite); + pwmout_write(mPwm_wwhite, duty_wwhite); + } + + pwmout_write(mPwm_red, duty_red); + pwmout_write(mPwm_blue, duty_blue); + pwmout_write(mPwm_green, duty_green); + } +} + +void MatterLED::SetColorTemp(uint16_t colortemp) +{ +#if 0 + if (colortemp!=0) + mColorTemp = static_cast(1000000 / colortemp); + else + mColorTemp = 0; +#endif + mColorTemp = colortemp; + ChipLogProgress(DeviceLayer, "Color Temperature changed to %d", mColorTemp); + // SetBrightness(mBrightness); + DoSet(); +} + +void MatterLED::HSB2rgb(uint16_t Hue, uint8_t Saturation, uint8_t brightness, uint8_t & red, uint8_t & green, uint8_t & blue) +{ + uint16_t i = Hue / 60; + uint16_t rgb_max = brightness; + uint16_t rgb_min = rgb_max * (100 - Saturation) / 100; + uint16_t diff = Hue % 60; + uint16_t rgb_adj = (rgb_max - rgb_min) * diff / 60; + + switch (i) + { + case 0: + red = rgb_max; + green = rgb_min + rgb_adj; + blue = rgb_min; + break; + case 1: + red = rgb_max - rgb_adj; + green = rgb_max; + blue = rgb_min; + break; + case 2: + red = rgb_min; + green = rgb_max; + blue = rgb_min + rgb_adj; + break; + case 3: + red = rgb_min; + green = rgb_max - rgb_adj; + blue = rgb_max; + break; + case 4: + red = rgb_min + rgb_adj; + green = rgb_min; + blue = rgb_max; + break; + default: + red = rgb_max; + green = rgb_min; + blue = rgb_max - rgb_adj; + break; + } +} + +void MatterLED:: simpleRGB2RGBW(uint8_t & red, uint8_t & green, uint8_t & blue, uint8_t & cwhite, uint8_t & wwhite) +{ + uint8_t white = std::min({red, green, blue}); + + // Original color channel minus the contribution of white channel + red -= white; + green -= white; + blue -= white; + + uint16_t colortemp; + uint8_t i = 0; + + while(i < 11) + { + colortemp = WhitePercentage[i][0]; + if (mColorTemp < colortemp) + break; + i++; + } + + if (i != 0) + i -= 1; + + cwhite = white * WhitePercentage[i][1] / 100; + wwhite = white * WhitePercentage[i][2] / 100; +} diff --git a/component/common/application/matter/driver/led_driver.h b/component/common/application/matter/driver/led_driver.h new file mode 100644 index 00000000..43d8b353 --- /dev/null +++ b/component/common/application/matter/driver/led_driver.h @@ -0,0 +1,60 @@ +#pragma once + +#include +#include "pwmout_api.h" + +class MatterLED +{ +public: + void Init(PinName pin); + void Init(PinName redpin, PinName greenpin, PinName bluepin); + void Init(PinName redpin, PinName greenpin, PinName bluepin, PinName cwhitepin, PinName wwhitepin); + void deInit(void); + uint8_t GetLevel(void); + bool IsTurnedOn(void); + void Set(bool state); + void Toggle(void); + void SetBrightness(uint8_t brightness); + void SetColor(uint8_t Hue, uint8_t Saturation); + void SetColorTemp(uint16_t colortemp); + void HSB2rgb(uint16_t Hue, uint8_t Saturation, uint8_t brightness, uint8_t & red, uint8_t & green, uint8_t & blue); + void simpleRGB2RGBW(uint8_t & red, uint8_t & green, uint8_t & blue, uint8_t & cwhite, uint8_t & wwhite); + uint8_t mBrightness; + uint16_t mHue; // mHue [0, 360] + uint8_t mSaturation; // mSaturation [0, 100] + uint16_t mColorTemp; + +private: + pwmout_t *mPwm_obj = NULL; + pwmout_t *mPwm_red = NULL; + pwmout_t *mPwm_green = NULL; + pwmout_t *mPwm_blue = NULL; + pwmout_t *mPwm_cwhite = NULL; + pwmout_t *mPwm_wwhite = NULL; + bool mRgb = false; + bool mRgbw = false; + bool mState; + void DoSet(); + uint16_t WhitePercentage[11][3] = + { + /*CT--coolwhite%--warmwhite%*/ + {2708, 0, 100}, + {2891, 10, 90}, + {3110, 20, 80}, + {3364, 30, 70}, + {3656, 40, 60}, + {3992, 50, 50}, + {4376, 60, 40}, + {4809, 70, 30}, + {5304, 80, 20}, + {5853, 90, 10}, + {6471, 100, 0} + }; + +}; +// #define PWM_LED PA_23 +// #define GREEN_LED_GPIO_NUM PA_19 +// #define RED_LED_GPIO_NUM PA_18 +// #define BLUE_LED_GPIO_NUM PA_20 +// #define COOL_WHITE_LED_GPIO_NUM PA_4 +// #define WARM_WHITE_LED_GPIO_NUM PA_17 diff --git a/component/common/application/matter/application/example_matter.c b/component/common/application/matter/example/chiptest/example_matter.c similarity index 100% rename from component/common/application/matter/application/example_matter.c rename to component/common/application/matter/example/chiptest/example_matter.c diff --git a/component/common/application/matter/application/example_matter.h b/component/common/application/matter/example/chiptest/example_matter.h similarity index 100% rename from component/common/application/matter/application/example_matter.h rename to component/common/application/matter/example/chiptest/example_matter.h diff --git a/component/common/application/matter/example/light/Makefile b/component/common/application/matter/example/light/Makefile new file mode 100644 index 00000000..74e6cd71 --- /dev/null +++ b/component/common/application/matter/example/light/Makefile @@ -0,0 +1,49 @@ +BASEDIR := $(shell pwd) +SDKROOTDIR := $(BASEDIR)/../../../../../.. +AMEBAZ2_TOOLDIR = $(SDKROOTDIR)/component/soc/realtek/8710c/misc/iar_utility +CHIPDIR = $(SDKROOTDIR)/third_party/connectedhomeip +OUTPUT_DIR = $(CHIPDIR)/examples/lighting-app/ameba/build/chip + +OS := $(shell uname) +LBITS := $(shell getconf LONG_BIT) + +.PHONY: toolchain +toolchain: + @echo Toolchain unzipping... +ifeq ($(findstring CYGWIN, $(OS)), CYGWIN) +ifneq ("$(LBITS)", "32") + @echo ONLY 32-BIT CYGWIN IS SUPPORTED! + @exit -1 +endif + if [ ! -f $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk-6.4.1-cygwin-newlib-build-2778-i686.tar.bz2 ] ; then cat $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk-6.4.1-cygwin-newlib-build-2778-i686.tar.bz2* > $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk-6.4.1-cygwin-newlib-build-2778-i686.tar.bz2; fi;\ + if [ ! -d $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk ] ; then mkdir $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk; fi;\ + if [ ! -d $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk/cygwin ] ; then tar -jxf $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk-6.4.1-cygwin-newlib-build-2778-i686.tar.bz2 -C $(SDKROOTDIR)/tools/arm-none-eabi-gcc/ ; mv $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk-6.4.1/cygwin $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk/cygwin ;fi +endif + +ifeq ($(findstring MINGW32, $(OS)), MINGW32) + if [ ! -f /bin/unzip.exe ] ; then mingw-get.exe install msys-unzip; fi;\ + if [ ! -d $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk ] ; then mkdir $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk; fi;\ + if [ ! -d $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk/mingw32 ] ; then unzip -q -u $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk64-6.4.1-mingw32-newlib-build-3026.zip ; mv asdk-6.4.1/mingw32 $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk/mingw32 ; rm -rf asdk-6.4.1 ;fi +endif + +ifeq ($(findstring Linux, $(OS)), Linux) +ifneq ("$(LBITS)", "64") + @echo ONLY 64-BIT LINUX IS SUPPORTED! + @exit -1 +endif + if [ ! -f $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk-10.3.0-linux-newlib-build-3638-x86_64.tar.bz2 ] ; then cat $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk-10.3.0-linux-newlib-build-3638-x86_64.tar.bz2* > $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk-10.3.0-linux-newlib-build-3638-x86_64.tar.bz2; fi;\ + if [ ! -d $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk ] ; then mkdir $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk; fi;\ + if [ ! -d $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk/linux ] ; then tar -jxf $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk-10.3.0-linux-newlib-build-3638-x86_64.tar.bz2 -C $(SDKROOTDIR)/tools/arm-none-eabi-gcc/ ; mv $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk-10.3.0/linux $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk/linux ; rmdir $(SDKROOTDIR)/tools/arm-none-eabi-gcc/asdk-10.3.0; fi +endif + @echo Toolchain unzip done! + +.PHONY: light +light: toolchain + python3 ameba_zap_cluster_list.py --zap_file $(CHIPDIR)/examples/lighting-app/lighting-common/lighting-app.zap + @$(MAKE) -f lib_chip_light_core.mk all + @$(MAKE) -f lib_chip_light_main.mk all + +.PHONY: clean +clean: + @$(MAKE) -f lib_chip_light_core.mk clean + @$(MAKE) -f lib_chip_light_main.mk clean diff --git a/component/common/application/matter/example/light/README.md b/component/common/application/matter/example/light/README.md new file mode 100644 index 00000000..4e25eadb --- /dev/null +++ b/component/common/application/matter/example/light/README.md @@ -0,0 +1,55 @@ +# Lighting-app Example +This example is an implementation of the *Dimmable Light* device type. You will need an LED and a button. + +| Peripheral | Pin | +| ----------- | ----------- | +| LED | PA_23 | +| Button | PA_17 | + +## How it works +The LED can be controlled in two ways, by the Matter controller, or by a button. +Thus, 2 streams of communication (FreeRTOS Queues) are needed to control and update the status of the LED effectively: + 1. Uplink - Matter controller changes the On/Off attribute of the LED -> callback triggers and invokes the LED driver to toggle the LED + 2. Downlink - Button press toggles the LED -> update the new Matter On/Off attribute of the LED + +### Peripheral Initialization +Both the initializations of the LED and the button are handled in `matter_drivers.cpp`. +The initialization of the button sets up an IRQ that is triggered whenever the button is pressed. + +### Button Press +Whenever the button is pressed, the interrupt handler will be invoked. +The interrupt handler will post an event to the downlink queue, which will be received by the interaction handler. +The interaction handler will be responsible for updating the On/Off attribute of the LED. + +### Matter Attribute Change Callback +Whenever the Matter controller changes the On/Off attribute of the LED, 2 types of callbacks will be invoked: + 1. MatterPreAttributeChangeCallback - Toggle the LED before updating the On/Off attribute (TBD) + 2. MatterPostAttributeChangeCallback - Toggle the LED after updating the On/Off attribute + +These callbacks are defined in `core/matter_interaction.cpp`. +These callbacks will post an event to the uplink queue, which will be received by the interaction handler. +The interaction handler will be responsible for toggling the LED. + +## How to build + +## Configurations +Enable `CONFIG_EXAMPLE_MATTER` and `CONFIG_EXAMPLE_MATTER_LIGHT` in `platform_opts.h`. +Ensure that `CONFIG_EXAMPLE_MATTER_CHIPTEST` is disabled. + +### Setup the Build Environment + + cd connectedhomeip + source scripts/activate.sh + +### Build Matter Libraries + + cd ambz2_matter/component/common/application/matter/example/light + make light + +### Build the Final Firmware + + cd ambz2_matter/project/realtek_amebaz2_v0_example/GCC-RELEASE/ + make is_matter + +### Flash the Image +Refer to this [guide](https://github.com/ambiot/ambz2_matter/blob/main/tools/AmebaZ2/Image_Tool_Linux/README.md) to flash the image with the Linux Image Tool diff --git a/component/common/application/matter/example/light/example_matter_light.cpp b/component/common/application/matter/example/light/example_matter_light.cpp new file mode 100644 index 00000000..cd39eba2 --- /dev/null +++ b/component/common/application/matter/example/light/example_matter_light.cpp @@ -0,0 +1,57 @@ +#include "FreeRTOS.h" +#include "task.h" +#include "platform/platform_stdlib.h" +#include "basic_types.h" +#include "platform_opts.h" +#include "section_config.h" +#include "wifi_constants.h" +#include "wifi/wifi_conf.h" +#include "chip_porting.h" +#include "matter_core.h" +#include "matter_drivers.h" +#include "matter_interaction.h" + +static void example_matter_light_task(void *pvParameters) +{ + // TODO: error checking + // TODO: set default led values + while(!(wifi_is_up(RTW_STA_INTERFACE) || wifi_is_up(RTW_AP_INTERFACE))) { + //waiting for Wifi to be initialized + } + + CHIP_ERROR err = CHIP_NO_ERROR; + + initPref(); // init NVS + // + err = matter_core_start(); + if (err != CHIP_NO_ERROR) + printf("matter_core_start failed!\n"); + + err = matter_driver_led_init(); + if (err != CHIP_NO_ERROR) + printf("matter_driver_led_init failed!\n"); + + err = matter_driver_led_set_startup_value(); + if (err != CHIP_NO_ERROR) + printf("matter_driver_led_set_startup_value failed!\n"); + + err = matter_driver_button_init(); + if (err != CHIP_NO_ERROR) + printf("matter_driver_button_init failed!\n"); + + err = matter_interaction_start_downlink(); + if (err != CHIP_NO_ERROR) + printf("matter_interaction_start_downlink failed!\n"); + + err = matter_interaction_start_uplink(); + if (err != CHIP_NO_ERROR) + printf("matter_interaction_start_uplink failed!\n"); + + while(1); +} + +extern "C" void example_matter_light(void) +{ + if(xTaskCreate(example_matter_light_task, ((const char*)"example_matter_task_thread"), 2048, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS) + printf("\n\r%s xTaskCreate(example_matter_light) failed", __FUNCTION__); +} diff --git a/component/common/application/matter/example/light/example_matter_light.h b/component/common/application/matter/example/light/example_matter_light.h new file mode 100644 index 00000000..e1291cf5 --- /dev/null +++ b/component/common/application/matter/example/light/example_matter_light.h @@ -0,0 +1,6 @@ +#ifndef EXAMPLE_MATTER_LIGHT_H +#define EXAMPLE_MATTER_LIGHT_H + +void example_matter_task(void); + +#endif /* EXAMPLE_MATTER_LIGHT_H */ diff --git a/component/common/application/matter/example/light/lib_chip_light_core.mk b/component/common/application/matter/example/light/lib_chip_light_core.mk new file mode 100644 index 00000000..99cfc58d --- /dev/null +++ b/component/common/application/matter/example/light/lib_chip_light_core.mk @@ -0,0 +1,259 @@ +SHELL = /bin/bash + +# Initialize tool chain +# ------------------------------------------------------------------- +BASEDIR := $(shell pwd) +SDKROOTDIR := $(BASEDIR)/../../../../../.. +AMEBAZ2_TOOLDIR = $(SDKROOTDIR)/component/soc/realtek/8710c/misc/iar_utility +CHIPDIR = $(SDKROOTDIR)/third_party/connectedhomeip +OUTPUT_DIR = $(CHIPDIR)/examples/lighting-app/ameba/build/chip + +OS := $(shell uname) + +CROSS_COMPILE = $(ARM_GCC_TOOLCHAIN)/arm-none-eabi- + +# Compilation tools +AR = $(CROSS_COMPILE)ar +CC = $(CROSS_COMPILE)gcc +AS = $(CROSS_COMPILE)as +NM = $(CROSS_COMPILE)nm +LD = $(CROSS_COMPILE)gcc +GDB = $(CROSS_COMPILE)gdb +OBJCOPY = $(CROSS_COMPILE)objcopy +OBJDUMP = $(CROSS_COMPILE)objdump + +OS := $(shell uname) + +# Initialize target name and target object files +# ------------------------------------------------------------------- + +OBJ_DIR=$(TARGET)/Debug/obj +BIN_DIR=$(TARGET)/Debug/bin +INFO_DIR=$(TARGET)/Debug/info + +# Include folder list +# ------------------------------------------------------------------- + +INCLUDES = +INCLUDES += -I$(SDKROOTDIR)/project/realtek_amebaz2_v0_example/inc + +INCLUDES += -I$(SDKROOTDIR)/component/common/api +INCLUDES += -I$(SDKROOTDIR)/component/common/api/at_cmd +INCLUDES += -I$(SDKROOTDIR)/component/common/api/platform +INCLUDES += -I$(SDKROOTDIR)/component/common/api/wifi +INCLUDES += -I$(SDKROOTDIR)/component/common/api/wifi/rtw_wpa_supplicant/src +INCLUDES += -I$(SDKROOTDIR)/component/common/api/wifi/rtw_wpa_supplicant/src/crypto +INCLUDES += -I$(SDKROOTDIR)/component/common/api/network/include +INCLUDES += -I$(SDKROOTDIR)/component/common/application +INCLUDES += -I$(SDKROOTDIR)/component/common/application/mqtt/MQTTClient +INCLUDES += -I$(SDKROOTDIR)/component/common/example +INCLUDES += -I$(SDKROOTDIR)/component/common/file_system +INCLUDES += -I$(SDKROOTDIR)/component/common/file_system/dct +INCLUDES += -I$(SDKROOTDIR)/component/common/file_system/fatfs +INCLUDES += -I$(SDKROOTDIR)/component/common/file_system/fatfs/r0.10c/include +INCLUDES += -I$(SDKROOTDIR)/component/common/file_system/ftl +INCLUDES += -I$(SDKROOTDIR)/component/common/utilities +INCLUDES += -I$(SDKROOTDIR)/component/common/mbed/hal +INCLUDES += -I$(SDKROOTDIR)/component/common/mbed/hal_ext +INCLUDES += -I$(SDKROOTDIR)/component/common/mbed/targets/hal/rtl8710c +INCLUDES += -I$(SDKROOTDIR)/component/common/network +INCLUDES += -I$(SDKROOTDIR)/component/common/network/coap/include +INCLUDES += -I$(SDKROOTDIR)/component/common/network/libcoap/include +INCLUDES += -I$(SDKROOTDIR)/component/common/network/http2/nghttp2-1.31.0/includes +INCLUDES += -I$(SDKROOTDIR)/component/common/network/lwip/lwip_v2.1.2/src/include +INCLUDES += -I$(SDKROOTDIR)/component/common/network/lwip/lwip_v2.1.2/src/include/lwip +INCLUDES += -I$(SDKROOTDIR)/component/common/network/lwip/lwip_v2.1.2/port/realtek +INCLUDES += -I$(SDKROOTDIR)/component/common/network/lwip/lwip_v2.1.2/port/realtek/freertos +INCLUDES += -I$(SDKROOTDIR)/component/common/network/ssl/mbedtls-matter/include +INCLUDES += -I$(SDKROOTDIR)/component/common/network/ssl/mbedtls-matter/include/mbedtls +#INCLUDES += -I$(SDKROOTDIR)/component/common/network/ssl/ssl_ram_map/rom +INCLUDES += -I$(SDKROOTDIR)/component/common/drivers/wlan/realtek/include +INCLUDES += -I$(SDKROOTDIR)/component/common/drivers/wlan/realtek/src/osdep +INCLUDES += -I$(SDKROOTDIR)/component/common/drivers/wlan/realtek/src/core/option +INCLUDES += -I$(SDKROOTDIR)/component/common/test +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/app +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile/client +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile/server +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/os +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/platform +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/stack +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/lib +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/src +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/src/data_uart +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/src/hci +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/src/os +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/src/vendor_cmd +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/ble_central +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/ble_peripheral +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/ble_scatternet +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_fuzz_test +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_ota_central_client +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_datatrans +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/cmd +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/common +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/gap +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/inc +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/inc/amebaz2 +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/model +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/model/realtek +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/platform +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/profile +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/utility +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/provisioner +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/device +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/api/common +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/api/provisioner +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/api/device +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/api +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_provisioner_rtk_demo +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_provisioner_rtk_demo/inc +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_device_rtk_demo +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_multiple_profile/device_multiple_profile +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_multiple_profile/provisioner_multiple_profile +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_test +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/src/mcu/module/data_uart_cmd +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/src/app/hrp/gap +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/common/inc +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_airsync_config +INCLUDES += -I$(SDKROOTDIR)/component/common/media/rtp_codec +INCLUDES += -I$(SDKROOTDIR)/component/common/media/mmfv2 +INCLUDES += -I$(SDKROOTDIR)/component/common/application/airsync/1.0.4 + +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/cmsis/rtl8710c/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/cmsis/rtl8710c/lib/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/fwlib/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/fwlib/lib/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/cmsis/cmsis-core/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/app/rtl_printf/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/app/shell +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/app/stdio_port +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/misc/utilities/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/mbed-drivers/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/misc/platform +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/misc/driver +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/misc/os + +INCLUDES += -I$(SDKROOTDIR)/component/os/freertos +INCLUDES += -I$(SDKROOTDIR)/component/os/freertos/freertos_v10.0.1/Source/include +INCLUDES += -I$(SDKROOTDIR)/component/os/freertos/freertos_v10.0.1/Source/portable/GCC/ARM_RTL8710C +INCLUDES += -I$(SDKROOTDIR)/component/os/os_dep/include + +INCLUDES += -I$(SDKROOTDIR)/component/common/application/matter/common/bluetooth/bt_matter_adapter +INCLUDES += -I$(SDKROOTDIR)/component/common/application/matter/common/mbedtls +INCLUDES += -I$(SDKROOTDIR)/component/common/application/matter/common/port + +# CHIP Include folder list +# ------------------------------------------------------------------- +INCLUDES += -I$(CHIPDIR)/config/ameba +INCLUDES += -I$(CHIPDIR)/src/include/platform/Ameba +INCLUDES += -I$(CHIPDIR)/src/include +INCLUDES += -I$(CHIPDIR)/src/lib +INCLUDES += -I$(CHIPDIR)/src +INCLUDES += -I$(CHIPDIR)/src/system +INCLUDES += -I$(CHIPDIR)/src/app +INCLUDES += -I$(CHIPDIR)/third_party/nlassert/repo/include +INCLUDES += -I$(CHIPDIR)/third_party/nlio/repo/include +INCLUDES += -I$(CHIPDIR)/third_party/nlunit-test/repo/src + +# Compile options +# ------------------------------------------------------------------- + +CFLAGS = +CFLAGS += -march=armv8-m.main+dsp -mthumb -mcmse -mfloat-abi=soft -D__thumb2__ -g -gdwarf-3 -Os +CFLAGS += -D__ARM_ARCH_8M_MAIN__=1 -gdwarf-3 -fstack-usage -fdata-sections -ffunction-sections +CFLAGS += -fdiagnostics-color=always -Wall -Wpointer-arith -Wno-write-strings +CFLAGS += -Wno-maybe-uninitialized -c -MMD +CFLAGS += -DCONFIG_PLATFORM_8710C -DCONFIG_BUILD_RAM=1 +CFLAGS += -DV8M_STKOVF +#for time64 +ifdef SYSTEM_TIME64_MAKE_OPTION +CFLAGS += -DCONFIG_SYSTEM_TIME64=1 +CFLAGS += -include time64.h +else +CFLAGS += -DCONFIG_SYSTEM_TIME64=0 +endif + +# CHIP options +# ------------------------------------------------------------------- +CFLAGS += -DCHIP_PROJECT=1 +CFLAGS += -DCONFIG_ENABLE_AMEBA_FACTORY_DATA=0 +CFLAGS += -DCHIP_DEVICE_LAYER_TARGET=Ameba +CFLAGS += -DMBEDTLS_CONFIG_FILE=\"mbedtls_config.h\" + +CFLAGS += -DLWIP_IPV6_ND=1 +CFLAGS += -DLWIP_IPV6_SCOPES=0 +CFLAGS += -DLWIP_PBUF_FROM_CUSTOM_POOLS=0 +CFLAGS += -DLWIP_IPV6_ROUTE_TABLE_SUPPORT=1 + +CFLAGS += -DCHIP_DEVICE_LAYER_NONE=0 +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_ZEPHYR_NET_IF=0 +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS=0 +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKET_EXTENSIONS=0 + +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_LWIP=1 +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_SOCKETS=0 +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK=0 + +CXXFLAGS += -DFD_SETSIZE=10 + +CXXFLAGS += -Wno-sign-compare +CXXFLAGS += -Wno-unused-function +CXXFLAGS += -Wno-unused-but-set-variable +CXXFLAGS += -Wno-unused-label +CXXFLAGS += -Wno-unused-variable +CXXFLAGS += -Wno-deprecated-declarations +CXXFLAGS += -Wno-unused-parameter +CXXFLAGS += -Wno-format +CXXFLAGS += -Wno-format-nonliteral +CXXFLAGS += -Wno-format-security + +CXXFLAGS += -std=gnu++14 +#CXXFLAGS += -std=c++14 +CXXFLAGS += -fno-rtti + +CHIP_CFLAGS = $(CFLAGS) +CHIP_CFLAGS += $(INCLUDES) + +CHIP_CXXFLAGS += $(CFLAGS) +CHIP_CXXFLAGS += $(CXXFLAGS) +CHIP_CXXFLAGS += $(INCLUDES) + +#*****************************************************************************# +# RULES TO GENERATE TARGETS # +#*****************************************************************************# + +# Define the Rules to build the core targets +all: GENERATE_NINJA + +GENERATE_NINJA: + echo "INSTALL CHIP..." + mkdir -p $(OUTPUT_DIR) + echo > $(OUTPUT_DIR)/args.gn + echo "import(\"//args.gni\")" >> $(OUTPUT_DIR)/args.gn + echo target_cflags_c = [$(foreach word,$(CHIP_CFLAGS),\"$(word)\",)] | sed -e 's/=\"/=\\"/g;s/\"\"/\\"\"/g;' >> $(OUTPUT_DIR)/args.gn + echo target_cflags_cc = [$(foreach word,$(CHIP_CXXFLAGS),\"$(word)\",)] | sed -e 's/=\"/=\\"/g;s/\"\"/\\"\"/g;' >> $(OUTPUT_DIR)/args.gn + echo ameba_ar = \"arm-none-eabi-ar\" >> $(OUTPUT_DIR)/args.gn + echo ameba_cc = \"arm-none-eabi-gcc\" >> $(OUTPUT_DIR)/args.gn + echo ameba_cxx = \"arm-none-eabi-c++\" >> $(OUTPUT_DIR)/args.gn + echo ameba_cpu = \"ameba\" >> $(OUTPUT_DIR)/args.gn + echo chip_enable_ota_requestor = "true" >> $(OUTPUT_DIR)/args.gn + echo chip_inet_config_enable_ipv4 = "false" >> $(OUTPUT_DIR)/args.gn + echo chip_support_enable_storage_api_audit = "false" >> $(OUTPUT_DIR)/args.gn + echo chip_use_transitional_commissionable_data_provider = "false" >> $(OUTPUT_DIR)/args.gn + sed -i 's/chip_build_tests\ =\ true/chip_build_tests\ =\ false/g' $(CHIPDIR)/config/ameba/args.gni + mkdir -p $(CHIPDIR)/config/ameba/components/chip + cd $(CHIPDIR)/config/ameba/components/chip && gn gen --check --fail-on-unused-args $(CHIPDIR)/examples/lighting-app/ameba/build/chip + cd $(CHIPDIR)/config/ameba/components/chip ; ninja -C $(CHIPDIR)/examples/lighting-app/ameba/build/chip :ameba + cp -f $(OUTPUT_DIR)/lib/* $(SDKROOTDIR)/component/soc/realtek/8710c/misc/bsp/lib/common/GCC +#*****************************************************************************# +# CLEAN GENERATED FILES # +#*****************************************************************************# +.PHONY: clean +clean: + echo "RM $(OUTPUT_DIR)" + rm -rf $(OUTPUT_DIR) + diff --git a/component/common/application/matter/example/light/lib_chip_light_main.mk b/component/common/application/matter/example/light/lib_chip_light_main.mk new file mode 100644 index 00000000..f87e8f67 --- /dev/null +++ b/component/common/application/matter/example/light/lib_chip_light_main.mk @@ -0,0 +1,363 @@ +SHELL = /bin/bash + +# Initialize tool chain +# ------------------------------------------------------------------- +BASEDIR := $(shell pwd) +SDKROOTDIR := $(BASEDIR)/../../../../../.. +AMEBAZ2_TOOLDIR = $(SDKROOTDIR)/component/soc/realtek/8710c/misc/iar_utility +CHIPDIR = $(SDKROOTDIR)/third_party/connectedhomeip +OUTPUT_DIR = $(CHIPDIR)/examples/lighting-app/ameba/build/chip + +OS := $(shell uname) + +#CROSS_COMPILE = $(ARM_GCC_TOOLCHAIN)/arm-none-eabi- +CROSS_COMPILE = arm-none-eabi- + +# Compilation tools +AR = $(CROSS_COMPILE)ar +CC = $(CROSS_COMPILE)gcc +AS = $(CROSS_COMPILE)as +NM = $(CROSS_COMPILE)nm +LD = $(CROSS_COMPILE)gcc +GDB = $(CROSS_COMPILE)gdb +OBJCOPY = $(CROSS_COMPILE)objcopy +OBJDUMP = $(CROSS_COMPILE)objdump + +OS := $(shell uname) + +# Initialize target name and target object files +# ------------------------------------------------------------------- + +all: lib_main + +TARGET=lib_main + +OBJ_DIR=$(TARGET)/Debug/obj +BIN_DIR=$(TARGET)/Debug/bin +INFO_DIR=$(TARGET)/Debug/info + +# Include folder list +# ------------------------------------------------------------------- + +INCLUDES = +INCLUDES += -I$(SDKROOTDIR)/project/realtek_amebaz2_v0_example/inc + +INCLUDES += -I$(SDKROOTDIR)/component/common/api +INCLUDES += -I$(SDKROOTDIR)/component/common/api/at_cmd +INCLUDES += -I$(SDKROOTDIR)/component/common/api/platform +INCLUDES += -I$(SDKROOTDIR)/component/common/api/wifi +INCLUDES += -I$(SDKROOTDIR)/component/common/api/wifi/rtw_wpa_supplicant/src +INCLUDES += -I$(SDKROOTDIR)/component/common/api/wifi/rtw_wpa_supplicant/src/crypto +INCLUDES += -I$(SDKROOTDIR)/component/common/api/network/include +INCLUDES += -I$(SDKROOTDIR)/component/common/application +INCLUDES += -I$(SDKROOTDIR)/component/common/application/matter +INCLUDES += -I$(SDKROOTDIR)/component/common/application/mqtt/MQTTClient +INCLUDES += -I$(SDKROOTDIR)/component/common/example +INCLUDES += -I$(SDKROOTDIR)/component/common/file_system +INCLUDES += -I$(SDKROOTDIR)/component/common/file_system/dct +INCLUDES += -I$(SDKROOTDIR)/component/common/file_system/fatfs +INCLUDES += -I$(SDKROOTDIR)/component/common/file_system/fatfs/r0.10c/include +INCLUDES += -I$(SDKROOTDIR)/component/common/file_system/ftl +INCLUDES += -I$(SDKROOTDIR)/component/common/utilities +INCLUDES += -I$(SDKROOTDIR)/component/common/mbed/hal +INCLUDES += -I$(SDKROOTDIR)/component/common/mbed/hal_ext +INCLUDES += -I$(SDKROOTDIR)/component/common/mbed/targets/hal/rtl8710c +INCLUDES += -I$(SDKROOTDIR)/component/common/network +INCLUDES += -I$(SDKROOTDIR)/component/common/network/coap/include +INCLUDES += -I$(SDKROOTDIR)/component/common/network/libcoap/include +INCLUDES += -I$(SDKROOTDIR)/component/common/network/http2/nghttp2-1.31.0/includes +INCLUDES += -I$(SDKROOTDIR)/component/common/network/lwip/lwip_v2.1.2/src/include +INCLUDES += -I$(SDKROOTDIR)/component/common/network/lwip/lwip_v2.1.2/src/include/lwip +INCLUDES += -I$(SDKROOTDIR)/component/common/network/lwip/lwip_v2.1.2/port/realtek +INCLUDES += -I$(SDKROOTDIR)/component/common/network/lwip/lwip_v2.1.2/port/realtek/freertos +INCLUDES += -I$(SDKROOTDIR)/component/common/network/ssl/mbedtls-matter/include +INCLUDES += -I$(SDKROOTDIR)/component/common/network/ssl/mbedtls-matter/include/mbedtls +#INCLUDES += -I$(SDKROOTDIR)/component/common/network/ssl/ssl_ram_map/rom +INCLUDES += -I$(SDKROOTDIR)/component/common/drivers/wlan/realtek/include +INCLUDES += -I$(SDKROOTDIR)/component/common/drivers/wlan/realtek/src/osdep +INCLUDES += -I$(SDKROOTDIR)/component/common/drivers/wlan/realtek/src/core/option +INCLUDES += -I$(SDKROOTDIR)/component/common/test +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/app +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile/client +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/bluetooth/profile/server +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/os +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/platform +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/inc/stack +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/lib +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/src +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/src/data_uart +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/src/hci +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/src/os +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/amebaz2/src/vendor_cmd +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/ble_central +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/ble_peripheral +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/ble_scatternet +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_fuzz_test +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_ota_central_client +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_datatrans +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/cmd +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/common +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/gap +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/inc +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/inc/amebaz2 +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/model +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/model/realtek +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/platform +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/profile +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/lib/utility +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/provisioner +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/device +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/api/common +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/api/provisioner +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/api/device +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh/api +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_provisioner_rtk_demo +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_provisioner_rtk_demo/inc +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_device_rtk_demo +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_multiple_profile/device_multiple_profile +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_multiple_profile/provisioner_multiple_profile +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_mesh_test +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/src/mcu/module/data_uart_cmd +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/src/app/hrp/gap +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/board/common/inc +INCLUDES += -I$(SDKROOTDIR)/component/common/bluetooth/realtek/sdk/example/bt_airsync_config +INCLUDES += -I$(SDKROOTDIR)/component/common/media/rtp_codec +INCLUDES += -I$(SDKROOTDIR)/component/common/media/mmfv2 +INCLUDES += -I$(SDKROOTDIR)/component/common/application/airsync/1.0.4 + +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/cmsis/rtl8710c/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/cmsis/rtl8710c/lib/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/fwlib/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/fwlib/lib/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/cmsis/cmsis-core/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/app/rtl_printf/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/app/shell +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/app/stdio_port +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/misc/utilities/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/mbed-drivers/include +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/misc/platform +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/misc/driver +INCLUDES += -I$(SDKROOTDIR)/component/soc/realtek/8710c/misc/os + +INCLUDES += -I$(SDKROOTDIR)/component/os/freertos +INCLUDES += -I$(SDKROOTDIR)/component/os/freertos/freertos_v10.0.1/Source/include +INCLUDES += -I$(SDKROOTDIR)/component/os/freertos/freertos_v10.0.1/Source/portable/GCC/ARM_RTL8710C +INCLUDES += -I$(SDKROOTDIR)/component/os/os_dep/include + +INCLUDES += -I$(SDKROOTDIR)/component/common/application/matter/common/bluetooth/bt_matter_adapter +INCLUDES += -I$(SDKROOTDIR)/component/common/application/matter/common/mbedtls +INCLUDES += -I$(SDKROOTDIR)/component/common/application/matter/common/port +INCLUDES += -I$(SDKROOTDIR)/component/common/application/matter/core +INCLUDES += -I$(SDKROOTDIR)/component/common/application/matter/driver +INCLUDES += -I$(SDKROOTDIR)/component/common/application/matter/example/light + +# CHIP Include folder list +# ------------------------------------------------------------------- +INCLUDES += -I$(CHIPDIR)/zzz_generated/app-common +INCLUDES += -I$(CHIPDIR)/zzz_generated/lighting-app +INCLUDES += -I$(CHIPDIR)/zzz_generated/lighting-app/zap-generated +INCLUDES += -I$(CHIPDIR)/examples/lighting-app/lighting-common +INCLUDES += -I$(CHIPDIR)/examples/lighting-app/ameba/main/include +INCLUDES += -I$(CHIPDIR)/examples/lighting-app/ameba/build/chip/gen/include +INCLUDES += -I$(CHIPDIR)/examples/platform/ameba +INCLUDES += -I$(CHIPDIR)/examples/providers +INCLUDES += -I$(CHIPDIR)/src/include +INCLUDES += -I$(CHIPDIR)/src/lib +INCLUDES += -I$(CHIPDIR)/src +INCLUDES += -I$(CHIPDIR)/third_party/nlassert/repo/include +INCLUDES += -I$(CHIPDIR)/src/app +INCLUDES += -I$(CHIPDIR)/src/app/util +INCLUDES += -I$(CHIPDIR)/src/app/server +INCLUDES += -I$(CHIPDIR)/src/app/clusters/bindings +INCLUDES += -I$(CHIPDIR)/third_party/nlio/repo/include +INCLUDES += -I$(CHIPDIR)/third_party/nlunit-test/repo/src + +# Source file list +# ------------------------------------------------------------------- + +SRC_C = +SRC_C += $(CHIPDIR)/examples/platform/ameba/route_hook/ameba_route_hook.c +SRC_C += $(CHIPDIR)/examples/platform/ameba/route_hook/ameba_route_table.c + +SRC_CPP = + +SRC_CPP += $(CHIPDIR)/src/app/server/EchoHandler.cpp +SRC_CPP += $(CHIPDIR)/src/app/server/Dnssd.cpp +SRC_CPP += $(CHIPDIR)/src/app/server/OnboardingCodesUtil.cpp +SRC_CPP += $(CHIPDIR)/src/app/server/Server.cpp +SRC_CPP += $(CHIPDIR)/src/app/server/CommissioningWindowManager.cpp + +SRC_CPP += $(CHIPDIR)/src/app/util/af-event.cpp +SRC_CPP += $(CHIPDIR)/src/app/util/attribute-size-util.cpp +SRC_CPP += $(CHIPDIR)/src/app/util/attribute-storage.cpp +SRC_CPP += $(CHIPDIR)/src/app/util/attribute-table.cpp +SRC_CPP += $(CHIPDIR)/src/app/util/binding-table.cpp +SRC_CPP += $(CHIPDIR)/src/app/util/DataModelHandler.cpp +SRC_CPP += $(CHIPDIR)/src/app/util/ember-compatibility-functions.cpp +SRC_CPP += $(CHIPDIR)/src/app/util/ember-print.cpp +SRC_CPP += $(CHIPDIR)/src/app/util/message.cpp +SRC_CPP += $(CHIPDIR)/src/app/util/util.cpp +SRC_CPP += $(CHIPDIR)/src/app/util/error-mapping.cpp +SRC_CPP += $(CHIPDIR)/src/app/util/privilege-storage.cpp + +SRC_CPP += $(CHIPDIR)/src/app/reporting/Engine.cpp + +SRC_CPP += $(shell cat $(BASEDIR)/cluster-file.txt) + +SRC_CPP += $(CHIPDIR)/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp +SRC_CPP += $(CHIPDIR)/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp + +SRC_CPP += $(CHIPDIR)/zzz_generated/lighting-app/zap-generated/callback-stub.cpp +SRC_CPP += $(CHIPDIR)/zzz_generated/lighting-app/zap-generated/IMClusterCommandHandler.cpp + +SRC_CPP += $(CHIPDIR)/examples/providers/DeviceInfoProviderImpl.cpp + +# Custom light-app src files with porting layer +SRC_CPP += $(SDKROOTDIR)/component/common/application/matter/core/matter_core.cpp +SRC_CPP += $(SDKROOTDIR)/component/common/application/matter/core/matter_interaction.cpp +SRC_CPP += $(SDKROOTDIR)/component/common/application/matter/core/matter_ota.cpp +SRC_CPP += $(SDKROOTDIR)/component/common/application/matter/driver/led_driver.cpp +SRC_CPP += $(SDKROOTDIR)/component/common/application/matter/example/light/example_matter_light.cpp +SRC_CPP += $(SDKROOTDIR)/component/common/application/matter/example/light/matter_drivers.cpp + +#lib_version +VER_C += $(TARGET)_version.c + +# Generate obj list +# ------------------------------------------------------------------- + +SRC_O = $(patsubst %.c,%_$(TARGET).o,$(SRC_C)) +VER_O = $(patsubst %.c,%_$(TARGET).o,$(VER_C)) + +SRC_C_LIST = $(notdir $(SRC_C)) $(notdir $(DRAM_C)) +OBJ_LIST = $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%_$(TARGET).o,$(SRC_C_LIST))) +DEPENDENCY_LIST = $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%_$(TARGET).d,$(SRC_C_LIST))) + +SRC_OO += $(patsubst %.cpp,%_$(TARGET).oo,$(SRC_CPP)) +SRC_CPP_LIST = $(notdir $(SRC_CPP)) +OBJ_CPP_LIST = $(addprefix $(OBJ_DIR)/,$(patsubst %.cpp,%_$(TARGET).oo,$(SRC_CPP_LIST))) +DEPENDENCY_LIST += $(addprefix $(OBJ_DIR)/,$(patsubst %.cpp,%_$(TARGET).d,$(SRC_CPP_LIST))) + +# Compile options +# ------------------------------------------------------------------- + +CFLAGS = +CFLAGS += -march=armv8-m.main+dsp -mthumb -mcmse -mfloat-abi=soft -D__thumb2__ -g -gdwarf-3 -Os +CFLAGS += -D__ARM_ARCH_8M_MAIN__=1 -gdwarf-3 -fstack-usage -fdata-sections -ffunction-sections +CFLAGS += -fdiagnostics-color=always -Wall -Wpointer-arith -Wno-write-strings +CFLAGS += -Wno-maybe-uninitialized --save-temps -c -MMD +CFLAGS += -DCONFIG_PLATFORM_8710C -DCONFIG_BUILD_RAM=1 +CFLAGS += -DV8M_STKOVF + +# CHIP options +# ------------------------------------------------------------------- +CFLAGS += -DCHIP_PROJECT=1 +CFLAGS += -DCONFIG_ENABLE_OTA_REQUESTOR=1 +CFLAGS += -DCONFIG_ENABLE_AMEBA_FACTORY_DATA=0 +CFLAGS += -DCHIP_DEVICE_LAYER_TARGET=Ameba +CFLAGS += -DMBEDTLS_CONFIG_FILE=\"mbedtls_config.h\" +CFLAGS += -DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=\"lib/address_resolve/AddressResolve_DefaultImpl.h\" + +CFLAGS += -DLWIP_IPV6_ND=1 +CFLAGS += -DLWIP_IPV6_SCOPES=0 +CFLAGS += -DLWIP_PBUF_FROM_CUSTOM_POOLS=0 +CFLAGS += -DLWIP_IPV6_ROUTE_TABLE_SUPPORT=1 + +CFLAGS += -DCHIP_DEVICE_LAYER_NONE=0 +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_ZEPHYR_NET_IF=0 +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS=0 +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKET_EXTENSIONS=0 + +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_LWIP=1 +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_SOCKETS=0 +CFLAGS += -DCHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK=0 +CFLAGS += -DCHIP_SYSTEM_CONFIG_POSIX_LOCKING=0 +CFLAGS += -DINET_CONFIG_ENABLE_IPV4=0 + +CFLAGS += -DUSE_ZAP_CONFIG +CFLAGS += -DCHIP_HAVE_CONFIG_H + +CPPFLAGS := $(CFLAGS) + +CPPFLAGS += -DFD_SETSIZE=10 +CPPFLAGS += -Wno-sign-compare +CPPFLAGS += -Wno-unused-function +CPPFLAGS += -Wno-unused-but-set-variable +CPPFLAGS += -Wno-unused-variable +CPPFLAGS += -Wno-deprecated-declarations +CPPFLAGS += -Wno-unused-parameter +CPPFLAGS += -Wno-format + +CPPFLAGS += -std=gnu++14 +#CPPFLAGS += -std=c++14 +CPPFLAGS += -fno-rtti + +# Compile +# ------------------------------------------------------------------- + +.PHONY: lib_main +lib_main: prerequirement $(SRC_O) $(DRAM_O) $(SRC_OO) + $(AR) crv $(BIN_DIR)/$(TARGET).a $(OBJ_CPP_LIST) $(OBJ_LIST) $(VER_O) + cp $(BIN_DIR)/$(TARGET).a $(SDKROOTDIR)/component/soc/realtek/8710c/misc/bsp/lib/common/GCC/$(TARGET).a + +# Manipulate Image +# ------------------------------------------------------------------- + +.PHONY: manipulate_images +manipulate_images: + @echo =========================================================== + @echo Image manipulating + @echo =========================================================== + +# Generate build info +# ------------------------------------------------------------------- + +.PHONY: prerequirement +prerequirement: + @rm -f $(TARGET)_version*.o + @echo const char $(TARGET)_rev[] = \"$(TARGET)_ver_`git rev-parse HEAD`_`date +%Y/%m/%d-%T`\"\; > $(TARGET)_version.c + @$(CC) $(CFLAGS) $(INCLUDES) -c $(VER_C) -o $(VER_O) + @if [ ! -d $(ARM_GCC_TOOLCHAIN) ]; then \ + echo ===========================================================; \ + echo Toolchain not found, \"make toolchain\" first!; \ + echo ===========================================================; \ + exit -1; \ + fi + @echo =========================================================== + @echo Build $(TARGET) + @echo =========================================================== + mkdir -p $(OBJ_DIR) + mkdir -p $(BIN_DIR) + mkdir -p $(INFO_DIR) + +$(SRC_OO): %_$(TARGET).oo : %.cpp | prerequirement + $(CC) $(CPPFLAGS) $(INCLUDES) -c $< -o $@ + $(CC) $(CPPFLAGS) $(INCLUDES) -c $< -MM -MT $@ -MF $(OBJ_DIR)/$(notdir $(patsubst %.oo,%.d,$@)) + cp $@ $(OBJ_DIR)/$(notdir $@) + mv $(notdir $*.ii) $(INFO_DIR) + mv $(notdir $*.s) $(INFO_DIR) + chmod 777 $(OBJ_DIR)/$(notdir $@) + +$(SRC_O): %_$(TARGET).o : %.c | prerequirement + $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ + $(CC) $(CFLAGS) $(INCLUDES) -c $< -MM -MT $@ -MF $(OBJ_DIR)/$(notdir $(patsubst %.o,%.d,$@)) + cp $@ $(OBJ_DIR)/$(notdir $@) + mv $(notdir $*.i) $(INFO_DIR) + mv $(notdir $*.s) $(INFO_DIR) + chmod 777 $(OBJ_DIR)/$(notdir $@) + +-include $(DEPENDENCY_LIST) + +.PHONY: clean +clean: + rm -rf $(TARGET) + rm -f $(SRC_O) $(DRAM_O) $(VER_O) $(SRC_OO) + rm -f $(patsubst %.o,%.d,$(SRC_O)) $(patsubst %.o,%.d,$(DRAM_O)) $(patsubst %.o,%.d,$(VER_O)) $(patsubst %.oo,%.d,$(SRC_OO)) + rm -f $(patsubst %.o,%.su,$(SRC_O)) $(patsubst %.o,%.su,$(DRAM_O)) $(patsubst %.o,%.su,$(VER_O)) $(patsubst %.oo,%.su,$(SRC_OO)) + rm -f *.i + rm -f *.s + rm -f $(VER_C) diff --git a/component/common/application/matter/example/light/matter_drivers.cpp b/component/common/application/matter/example/light/matter_drivers.cpp new file mode 100644 index 00000000..d9f53519 --- /dev/null +++ b/component/common/application/matter/example/light/matter_drivers.cpp @@ -0,0 +1,148 @@ +#include "matter_drivers.h" +#include "matter_interaction.h" +#include "led_driver.h" +#include "gpio_irq_api.h" + +#include +#include +#include +#include + +using namespace ::chip::app; + +#define PWM_LED PA_23 +#define GPIO_IRQ_PIN PA_17 + +MatterLED led; +gpio_irq_t gpio_btn; + +void matter_driver_button_callback(uint32_t id, gpio_irq_event event) +{ + AppEvent downlink_event; + downlink_event.Type = AppEvent::kEventType_Downlink_OnOff; + downlink_event.mHandler = matter_interaction_onoff_handler; + PostDownlinkEvent(&downlink_event); +} + +CHIP_ERROR matter_driver_button_init() +{ + // TODO: error checking + // Initialize downlink interrupt source here + // Initial Push Button pin as interrupt source + gpio_irq_init(&gpio_btn, GPIO_IRQ_PIN, matter_driver_button_callback, 1); + gpio_irq_set(&gpio_btn, IRQ_FALL, 1); // Falling Edge Trigger + gpio_irq_enable(&gpio_btn) ; + return CHIP_NO_ERROR; +} + +CHIP_ERROR matter_driver_led_init() +{ + led.Init(PWM_LED); + return CHIP_NO_ERROR; +} + +CHIP_ERROR matter_driver_led_set_onoff(uint8_t value) +{ + led.Set(value); + return CHIP_NO_ERROR; +} + +CHIP_ERROR matter_driver_led_set_brightness(uint8_t value) +{ + led.SetBrightness(value); + return CHIP_NO_ERROR; +} + +CHIP_ERROR matter_driver_led_toggle() +{ + led.Toggle(); + return CHIP_NO_ERROR; +} + +bool matter_driver_led_get_onoff() +{ + return led.IsTurnedOn(); +} + +uint8_t matter_driver_led_get_level() +{ + return led.GetLevel(); +} + +CHIP_ERROR matter_driver_led_set_startup_value() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + bool LEDOnOffValue = 0; + DataModel::Nullable LEDCurrentLevelValue; + + chip::DeviceLayer::PlatformMgr().LockChipStack(); + // TODO: this example only considers endpoint1 + EmberAfStatus onoffstatus = Clusters::OnOff::Attributes::OnOff::Get(1, &LEDOnOffValue); + if (onoffstatus != EMBER_ZCL_STATUS_SUCCESS) + { + ChipLogError(DeviceLayer, "Failed to read onoff value: %x", onoffstatus); + return CHIP_ERROR_INTERNAL; + } + + // TODO: this example only considers endpoint1 + EmberAfStatus currentlevelstatus = Clusters::LevelControl::Attributes::CurrentLevel::Get(1, LEDCurrentLevelValue); + if (currentlevelstatus != EMBER_ZCL_STATUS_SUCCESS) + { + ChipLogError(DeviceLayer, "Failed to read currentlevel value: %x", currentlevelstatus); + return CHIP_ERROR_INTERNAL; + } + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); + + // Set LED to onoff value + // AppLED.Set(LEDOnOffValue); + err = matter_driver_led_set_onoff(LEDOnOffValue); + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to set startup onoff value"); + return CHIP_ERROR_INTERNAL; + } + // Set LED to currentlevel value + // AppLED.SetBrightness(LEDCurrentLevelValue.Value()); + err = matter_driver_led_set_brightness(LEDCurrentLevelValue.Value()); + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to set startup level value"); + return CHIP_ERROR_INTERNAL; + } + + return err; +} + +void matter_driver_attribute_update(AppEvent *aEvent) +{ + // get endpoint, cluster, attribute, val + // according to above, call the LED api + chip::app::ConcreteAttributePath path = aEvent->path; + + // TODO: this example only considers endpoint1 + VerifyOrExit(aEvent->path.mEndpointId == 1, + ChipLogError(DeviceLayer, "Unexpected EndPoint ID: `0x%02x'", path.mEndpointId)); + + switch(path.mClusterId) + { + case ZCL_ON_OFF_CLUSTER_ID: + if(path.mAttributeId == ZCL_ON_OFF_ATTRIBUTE_ID) + { + // led.Set(aEvent->value); + matter_driver_led_set_onoff(aEvent->value); + } + break; + case ZCL_LEVEL_CONTROL_CLUSTER_ID: + if(path.mAttributeId == ZCL_CURRENT_LEVEL_ATTRIBUTE_ID) + { + // led.SetBrightness(aEvent->value); + matter_driver_led_set_brightness(aEvent->value); + } + break; + case ZCL_IDENTIFY_CLUSTER_ID: + break; + } + +exit: + return; +} diff --git a/component/common/application/matter/example/light/matter_drivers.h b/component/common/application/matter/example/light/matter_drivers.h new file mode 100644 index 00000000..955dfec2 --- /dev/null +++ b/component/common/application/matter/example/light/matter_drivers.h @@ -0,0 +1,12 @@ +#pragma once + +#include "matter_events.h" + +#include +CHIP_ERROR matter_driver_button_init(void); +CHIP_ERROR matter_driver_led_init(void); +CHIP_ERROR matter_driver_led_toggle(void); +bool matter_driver_led_get_onoff(void); +uint8_t matter_driver_led_get_level(void); +CHIP_ERROR matter_driver_led_set_startup_value(void); +void matter_driver_attribute_update(AppEvent *aEvent); diff --git a/component/common/example/example_entry.c b/component/common/example/example_entry.c index 19189fac..c2edcea1 100644 --- a/component/common/example/example_entry.c +++ b/component/common/example/example_entry.c @@ -359,7 +359,11 @@ #endif #if defined(CONFIG_EXAMPLE_MATTER) && (CONFIG_EXAMPLE_MATTER == 1) +#if defined(CONFIG_EXAMPLE_MATTER_CHIPTEST) && (CONFIG_EXAMPLE_MATTER_CHIPTEST == 1) #include +#elif defined(CONFIG_EXAMPLE_MATTER_LIGHT) && (CONFIG_EXAMPLE_MATTER_LIGHT == 1) +#include +#endif #endif /* @@ -838,7 +842,12 @@ example_hilink(); #endif #if defined(CONFIG_EXAMPLE_MATTER) && (CONFIG_EXAMPLE_MATTER == 1) +#if defined(CONFIG_EXAMPLE_MATTER_CHIPTEST) && (CONFIG_EXAMPLE_MATTER_CHIPTEST == 1) example_matter_task(); +#elif defined(CONFIG_EXAMPLE_MATTER_LIGHT) && (CONFIG_EXAMPLE_MATTER_LIGHT == 1) + extern void example_matter_light(); + example_matter_light(); +#endif #endif #if defined(API_TEST_MODE) diff --git a/project/realtek_amebaz2_v0_example/GCC-RELEASE/application.is.matter.mk b/project/realtek_amebaz2_v0_example/GCC-RELEASE/application.is.matter.mk index d5823062..227e29a6 100644 --- a/project/realtek_amebaz2_v0_example/GCC-RELEASE/application.is.matter.mk +++ b/project/realtek_amebaz2_v0_example/GCC-RELEASE/application.is.matter.mk @@ -183,17 +183,19 @@ INCLUDES += -I../../../component/os/os_dep/include INCLUDES += -I../../../component/common/application/amazon/amazon-ffs/ffs_demo/common/include INCLUDES += -I../../../component/common/application/amazon/amazon-ffs/ffs_demo/realtek/configs -#matter +# Matter ifdef BT_MATTER_MESH_ADAPTER INCLUDES += -I../../../component/common/bluetooth/realtek/sdk/example/bt_mesh_multiple_profile/bt_mesh_device_matter else INCLUDES += -I../../../component/common/application/matter/common/bluetooth/bt_matter_adapter endif INCLUDES += -I../../../component/common/application/matter/common/bluetooth -INCLUDES += -I../../../component/common/application/matter/application -INCLUDES += -I../../../component/common/application/matter/mbedtls -INCLUDES += -I../../../component/common/application/matter/protobuf -INCLUDES += -I../../../component/common/application/matter/protobuf/nanopb +INCLUDES += -I../../../component/common/application/matter/common/port +INCLUDES += -I../../../component/common/application/matter/common/mbedtls +INCLUDES += -I../../../component/common/application/matter/common/protobuf +INCLUDES += -I../../../component/common/application/matter/common/protobuf/nanopb +INCLUDES += -I../../../component/common/application/matter/example/chiptest +INCLUDES += -I../../../component/common/application/matter/example/light INCLUDES += -I../../../component/common/bluetooth/realtek/sdk/src/app/hrp/gap # Source file list @@ -370,13 +372,13 @@ SRC_C += ../../../component/common/utilities/http_client.c SRC_C += ../../../component/common/utilities/xml.c #matter - app -SRC_C += ../../../component/common/application/matter/application/matter_dcts.c -SRC_C += ../../../component/common/application/matter/application/matter_timers.c -SRC_C += ../../../component/common/application/matter/application/matter_utils.c -SRC_C += ../../../component/common/application/matter/application/matter_wifis.c -SRC_C += ../../../component/common/application/matter/application/example_matter.c -SRC_C += ../../../component/common/application/matter/common/atcmd_matter.c -SRC_C += ../../../component/common/application/matter/mbedtls/net_sockets.c +SRC_C += ../../../component/common/application/matter/common/port/matter_dcts.c +SRC_C += ../../../component/common/application/matter/common/port/matter_timers.c +SRC_C += ../../../component/common/application/matter/common/port/matter_utils.c +SRC_C += ../../../component/common/application/matter/common/port/matter_wifis.c +SRC_C += ../../../component/common/application/matter/example/chiptest/example_matter.c +SRC_C += ../../../component/common/application/matter/common/atcmd/atcmd_matter.c +SRC_C += ../../../component/common/application/matter/common/mbedtls/net_sockets.c #network - app - mqtt SRC_C += ../../../component/common/application/mqtt/MQTTClient/MQTTClient.c @@ -669,10 +671,10 @@ SRC_C += ../../../component/common/example/fatfs/example_fatfs.c SRC_C += ../../../component/common/example/tickless_wifi_roaming/example_tickless_wifi_roaming.c # nanopb for Matter FactoryData -SRC_C += ../../../component/common/application/matter/protobuf/ameba_factory.pb.c -SRC_C += ../../../component/common/application/matter/protobuf/nanopb/pb_encode.c # The nanopb encoder -SRC_C += ../../../component/common/application/matter/protobuf/nanopb/pb_decode.c # The nanopb decoder -SRC_C += ../../../component/common/application/matter/protobuf/nanopb/pb_common.c # The nanopb common parts +SRC_C += ../../../component/common/application/matter/common/protobuf/ameba_factory.pb.c +SRC_C += ../../../component/common/application/matter/common/protobuf/nanopb/pb_encode.c # The nanopb encoder +SRC_C += ../../../component/common/application/matter/common/protobuf/nanopb/pb_decode.c # The nanopb decoder +SRC_C += ../../../component/common/application/matter/common/protobuf/nanopb/pb_common.c # The nanopb common parts #user SRC_C += ../src/main.c diff --git a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip.mk b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip.mk index bd1bb9a7..5212c0ce 100644 --- a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip.mk +++ b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip.mk @@ -66,7 +66,6 @@ INCLUDES += -I$(BASEDIR)/../../../component/common/network/lwip/lwip_v2.1.2/port INCLUDES += -I$(BASEDIR)/../../../component/common/network/lwip/lwip_v2.1.2/port/realtek/freertos INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter/include INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter/include/mbedtls -INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter #INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/ssl_ram_map/rom INCLUDES += -I$(BASEDIR)/../../../component/common/drivers/wlan/realtek/include INCLUDES += -I$(BASEDIR)/../../../component/common/drivers/wlan/realtek/src/osdep @@ -146,8 +145,8 @@ INCLUDES += -I$(BASEDIR)/../../../component/os/os_dep/include INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth/bt_matter_adapter -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/application -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/port # CHIP Include folder list # ------------------------------------------------------------------- diff --git a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_chef_core.mk b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_chef_core.mk index 025649ea..b2412c32 100644 --- a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_chef_core.mk +++ b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_chef_core.mk @@ -65,7 +65,7 @@ INCLUDES += -I$(BASEDIR)/../../../component/common/network/lwip/lwip_v2.1.2/src/ INCLUDES += -I$(BASEDIR)/../../../component/common/network/lwip/lwip_v2.1.2/port/realtek INCLUDES += -I$(BASEDIR)/../../../component/common/network/lwip/lwip_v2.1.2/port/realtek/freertos INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter/include -INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter/include/mbedtls #INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/ssl_ram_map/rom INCLUDES += -I$(BASEDIR)/../../../component/common/drivers/wlan/realtek/include INCLUDES += -I$(BASEDIR)/../../../component/common/drivers/wlan/realtek/src/osdep @@ -143,8 +143,8 @@ INCLUDES += -I$(BASEDIR)/../../../component/os/freertos/freertos_v10.0.1/Source/ INCLUDES += -I$(BASEDIR)/../../../component/os/os_dep/include INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth/bt_matter_adapter -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/application -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/port # CHIP Include folder list # ------------------------------------------------------------------- diff --git a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_chef_main.mk b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_chef_main.mk index 978a0bb1..0dacc6b1 100644 --- a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_chef_main.mk +++ b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_chef_main.mk @@ -148,8 +148,8 @@ INCLUDES += -I$(BASEDIR)/../../../component/os/freertos/freertos_v10.0.1/Source/ INCLUDES += -I$(BASEDIR)/../../../component/os/os_dep/include INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth/bt_matter_adapter -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/application -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/port # CHIP Include folder list # ------------------------------------------------------------------- diff --git a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_light_core.mk b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_light_core.mk index ba40ec4f..751c88d7 100644 --- a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_light_core.mk +++ b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_light_core.mk @@ -65,7 +65,7 @@ INCLUDES += -I$(BASEDIR)/../../../component/common/network/lwip/lwip_v2.1.2/src/ INCLUDES += -I$(BASEDIR)/../../../component/common/network/lwip/lwip_v2.1.2/port/realtek INCLUDES += -I$(BASEDIR)/../../../component/common/network/lwip/lwip_v2.1.2/port/realtek/freertos INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter/include -INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter/include/mbedtls #INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/ssl_ram_map/rom INCLUDES += -I$(BASEDIR)/../../../component/common/drivers/wlan/realtek/include INCLUDES += -I$(BASEDIR)/../../../component/common/drivers/wlan/realtek/src/osdep @@ -143,8 +143,8 @@ INCLUDES += -I$(BASEDIR)/../../../component/os/freertos/freertos_v10.0.1/Source/ INCLUDES += -I$(BASEDIR)/../../../component/os/os_dep/include INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth/bt_matter_adapter -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/application -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/port # CHIP Include folder list # ------------------------------------------------------------------- diff --git a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_light_main.mk b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_light_main.mk index c99aa2af..c396dd6f 100644 --- a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_light_main.mk +++ b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_light_main.mk @@ -148,8 +148,8 @@ INCLUDES += -I$(BASEDIR)/../../../component/os/freertos/freertos_v10.0.1/Source/ INCLUDES += -I$(BASEDIR)/../../../component/os/os_dep/include INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth/bt_matter_adapter -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/application -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/port # CHIP Include folder list # ------------------------------------------------------------------- diff --git a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_main.mk b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_main.mk index 768dfd3b..808cb885 100644 --- a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_main.mk +++ b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_main.mk @@ -49,6 +49,7 @@ INCLUDES += -I$(BASEDIR)/../../../component/common/api/wifi/rtw_wpa_supplicant/s INCLUDES += -I$(BASEDIR)/../../../component/common/api/wifi/rtw_wpa_supplicant/src/crypto INCLUDES += -I$(BASEDIR)/../../../component/common/api/network/include INCLUDES += -I$(BASEDIR)/../../../component/common/application +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter INCLUDES += -I$(BASEDIR)/../../../component/common/application/mqtt/MQTTClient INCLUDES += -I$(BASEDIR)/../../../component/common/example INCLUDES += -I$(BASEDIR)/../../../component/common/file_system @@ -149,8 +150,8 @@ INCLUDES += -I$(BASEDIR)/../../../component/os/os_dep/include INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth/bt_matter_adapter -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/application -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/port # CHIP Include folder list # ------------------------------------------------------------------- diff --git a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_otar_core.mk b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_otar_core.mk index 487309f9..f60037fb 100644 --- a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_otar_core.mk +++ b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_otar_core.mk @@ -65,7 +65,7 @@ INCLUDES += -I$(BASEDIR)/../../../component/common/network/lwip/lwip_v2.1.2/src/ INCLUDES += -I$(BASEDIR)/../../../component/common/network/lwip/lwip_v2.1.2/port/realtek INCLUDES += -I$(BASEDIR)/../../../component/common/network/lwip/lwip_v2.1.2/port/realtek/freertos INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter/include -INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/mbedtls-matter/include/mbedtls #INCLUDES += -I$(BASEDIR)/../../../component/common/network/ssl/ssl_ram_map/rom INCLUDES += -I$(BASEDIR)/../../../component/common/drivers/wlan/realtek/include INCLUDES += -I$(BASEDIR)/../../../component/common/drivers/wlan/realtek/src/osdep @@ -143,8 +143,8 @@ INCLUDES += -I$(BASEDIR)/../../../component/os/freertos/freertos_v10.0.1/Source/ INCLUDES += -I$(BASEDIR)/../../../component/os/os_dep/include INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth/bt_matter_adapter -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/application -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/port # CHIP Include folder list # ------------------------------------------------------------------- diff --git a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_otar_main.mk b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_otar_main.mk index 5d448767..3dc2be01 100644 --- a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_otar_main.mk +++ b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_otar_main.mk @@ -148,8 +148,8 @@ INCLUDES += -I$(BASEDIR)/../../../component/os/freertos/freertos_v10.0.1/Source/ INCLUDES += -I$(BASEDIR)/../../../component/os/os_dep/include INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth/bt_matter_adapter -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/application -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/port # CHIP Include folder list # ------------------------------------------------------------------- diff --git a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_switch_core.mk b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_switch_core.mk index bfa4088f..f5558230 100644 --- a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_switch_core.mk +++ b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_switch_core.mk @@ -143,8 +143,8 @@ INCLUDES += -I$(BASEDIR)/../../../component/os/freertos/freertos_v10.0.1/Source/ INCLUDES += -I$(BASEDIR)/../../../component/os/os_dep/include INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth/bt_matter_adapter -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/application -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/port # CHIP Include folder list # ------------------------------------------------------------------- diff --git a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_switch_main.mk b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_switch_main.mk index e32e0716..55247ed7 100644 --- a/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_switch_main.mk +++ b/project/realtek_amebaz2_v0_example/GCC-RELEASE/lib_chip_switch_main.mk @@ -149,8 +149,8 @@ INCLUDES += -I$(BASEDIR)/../../../component/os/freertos/freertos_v10.0.1/Source/ INCLUDES += -I$(BASEDIR)/../../../component/os/os_dep/include INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/bluetooth/bt_matter_adapter -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/application -INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/mbedtls +INCLUDES += -I$(BASEDIR)/../../../component/common/application/matter/common/port # CHIP Include folder list # ------------------------------------------------------------------- diff --git a/project/realtek_amebaz2_v0_example/inc/platform_opts.h b/project/realtek_amebaz2_v0_example/inc/platform_opts.h index 3056fd74..bdf737f0 100644 --- a/project/realtek_amebaz2_v0_example/inc/platform_opts.h +++ b/project/realtek_amebaz2_v0_example/inc/platform_opts.h @@ -90,6 +90,8 @@ /* For Matter */ #define CONFIG_EXAMPLE_MATTER 1 +#define CONFIG_EXAMPLE_MATTER_CHIPTEST 1 +#define CONFIG_EXAMPLE_MATTER_LIGHT 0 /* For WPS and P2P */ #define CONFIG_ENABLE_WPS 0