diff --git a/examples/chef/ameba/chip_main.cmake b/examples/chef/ameba/chip_main.cmake new file mode 100755 index 00000000000000..214d637ccc0c36 --- /dev/null +++ b/examples/chef/ameba/chip_main.cmake @@ -0,0 +1,133 @@ +cmake_minimum_required(VERSION 3.6) + +project(chip_main) + +set(chip_dir "${ameba_matter_root}") +set(chip_dir_output "${matter_output_path}/chip") +set(dir "${sdk_root}/component/common/api") +set(chip_main chip_main) +set(list_chip_main_sources chip_main_sources) + +include(${prj_root}/GCC-RELEASE/project_hp/asdk/includepath.cmake) +include(${chip_dir}/examples/chef/project_include.cmake) + +if (matter_enable_shell) +list( + APPEND ${list_chip_main_sources} + #shell + ${chip_dir}/examples/platform/ameba/shell/launch_shell.cpp +) +endif (matter_enable_shell) + +if (matter_enable_ota_requestor) +list( + APPEND ${list_chip_main_sources} + #OTARequestor + ${chip_dir}/src/app/clusters/ota-requestor/BDXDownloader.cpp + ${chip_dir}/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp + ${chip_dir}/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp + ${chip_dir}/src/app/clusters/ota-requestor/DefaultOTARequestorStorage.cpp + ${chip_dir}/src/app/clusters/ota-requestor/ota-requestor-server.cpp + ${chip_dir}/examples/platform/ameba/ota/OTAInitializer.cpp +) +endif (matter_enable_ota_requestor) + +list( + APPEND ${list_chip_main_sources} + + ${chip_dir}/examples/chef/out/${SAMPLE_NAME}/zap-generated/callback-stub.cpp + ${chip_dir}/examples/chef/out/${SAMPLE_NAME}/zap-generated/IMClusterCommandHandler.cpp + + ${matter_example_path}//main/chipinterface.cpp + ${matter_example_path}//main/DeviceCallbacks.cpp + ${matter_example_path}//main/CHIPDeviceManager.cpp + ${matter_example_path}//main/Globals.cpp + ${matter_example_path}//main/LEDWidget.cpp + ${matter_example_path}//main/DsoHack.cpp + + ${chip_dir}/examples/providers/DeviceInfoProviderImpl.cpp +) + +add_library( + ${chip_main} + STATIC + ${chip_main_sources} +) + +chip_configure_data_model(chip_main + INCLUDE_SERVER + ZAP_FILE ${matter_example_path}/../devices/${SAMPLE_NAME}.zap +) + +target_include_directories( + ${chip_main} + PUBLIC + ${inc_path} + ${matter_example_path}/main/include + ${chip_dir}/examples/chef/out/${SAMPLE_NAME} + ${chip_dir}/examples/chef/out/${SAMPLE_NAME}/zap-generated + ${chip_dir}/zzz_generated/app-common + ${chip_dir}/examples/all-clusters-app/all-clusters-common + ${chip_dir}/examples/all-clusters-app/all-clusters-common/include + ${chip_dir}/examples/all-clusters-app/ameba/main/include + ${chip_dir}/examples/platform/ameba + ${chip_dir}/examples/providers + ${chip_dir_output}/gen/include + ${chip_dir}/src/include/ + ${chip_dir}/src/lib/ + ${chip_dir}/src/ + ${chip_dir}/third_party/nlassert/repo/include/ + ${chip_dir}/src/app/ + ${chip_dir}/src/app/util/ + ${chip_dir}/src/app/server/ + ${chip_dir}/src/controller/data_model + ${chip_dir}/third_party/nlio/repo/include/ + ${chip_dir}/third_party/nlunit-test/repo/src +) + +list( + APPEND chip_main_flags + + -DINET_CONFIG_ENABLE_IPV4=0 + -DCHIP_PROJECT=1 + -DCHIP_DEVICE_LAYER_TARGET=Ameba + -DUSE_ZAP_CONFIG + -DCHIP_HAVE_CONFIG_H + -DMBEDTLS_CONFIG_FILE= + -DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID=${CONFIG_DEVICE_PRODUCT_ID} + -DCHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID=${CONFIG_DEVICE_VENDOR_ID} +) + +if (matter_enable_persistentstorage_audit) +list( + APPEND chip_main_flags + + -DCHIP_SUPPORT_ENABLE_STORAGE_API_AUDIT +) +endif (matter_enable_persistentstorage_audit) + +if (matter_enable_shell) +list( + APPEND chip_main_flags + + -DCONFIG_ENABLE_CHIP_SHELL=1 +) +endif (matter_enable_shell) + +list( + APPEND chip_main_cpp_flags + + -Wno-unused-parameter + -std=gnu++11 + -std=c++14 + -fno-rtti +) +target_compile_definitions(${chip_main} PRIVATE ${chip_main_flags} ) +target_compile_options(${chip_main} PRIVATE ${chip_main_cpp_flags}) + +# move static library post build command +add_custom_command( + TARGET ${chip_main} + POST_BUILD + COMMAND cp lib${chip_main}.a ${CMAKE_CURRENT_SOURCE_DIR}/lib/application +) diff --git a/examples/chef/ameba/main/CHIPDeviceManager.cpp b/examples/chef/ameba/main/CHIPDeviceManager.cpp new file mode 100644 index 00000000000000..4c1b55fbddb9fc --- /dev/null +++ b/examples/chef/ameba/main/CHIPDeviceManager.cpp @@ -0,0 +1,91 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file implements the CHIP Device Interface that is used by + * applications to interact with the CHIP stack + * + */ + +#include + +#include "CHIPDeviceManager.h" +#include +#include +#include +#include +#include + +using namespace ::chip; + +namespace chip { + +namespace DeviceManager { + +using namespace ::chip::DeviceLayer; + +void CHIPDeviceManager::CommonDeviceEventHandler(const ChipDeviceEvent * event, intptr_t arg) +{ + CHIPDeviceManagerCallbacks * cb = reinterpret_cast(arg); + if (cb != nullptr) + { + cb->DeviceEventCallback(event, reinterpret_cast(cb)); + } +} + +CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb) +{ + CHIP_ERROR err; + mCB = cb; + + err = Platform::MemoryInit(); + SuccessOrExit(err); + + // Initialize the CHIP stack. + err = PlatformMgr().InitChipStack(); + SuccessOrExit(err); + + if (CONFIG_NETWORK_LAYER_BLE) + { + ConnectivityMgr().SetBLEAdvertisingEnabled(true); + } + + // 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(CHIPDeviceManager::CommonDeviceEventHandler, reinterpret_cast(cb)); + + // Start a task to run the CHIP Device event loop. + err = PlatformMgr().StartEventLoopTask(); + SuccessOrExit(err); + +exit: + return err; +} +} // namespace DeviceManager +} // namespace chip + +void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & path, uint8_t type, uint16_t size, uint8_t * value) +{ + chip::DeviceManager::CHIPDeviceManagerCallbacks * cb = + chip::DeviceManager::CHIPDeviceManager::GetInstance().GetCHIPDeviceManagerCallbacks(); + if (cb != nullptr) + { + cb->PostAttributeChangeCallback(path.mEndpointId, path.mClusterId, path.mAttributeId, type, size, value); + } +} diff --git a/examples/chef/ameba/main/DeviceCallbacks.cpp b/examples/chef/ameba/main/DeviceCallbacks.cpp new file mode 100644 index 00000000000000..259ff3d726f529 --- /dev/null +++ b/examples/chef/ameba/main/DeviceCallbacks.cpp @@ -0,0 +1,180 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file DeviceCallbacks.cpp + * + * Implements all the callbacks to the application from the CHIP Stack + * + **/ +#include "DeviceCallbacks.h" + +#include "CHIPDeviceManager.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR +#include +#endif + +#include "Globals.h" +#include "LEDWidget.h" + +static const char * TAG = "app-devicecallbacks"; + +using namespace ::chip; +using namespace ::chip::Inet; +using namespace ::chip::System; +using namespace ::chip::DeviceLayer; +using namespace ::chip::DeviceManager; +using namespace ::chip::Logging; + +uint32_t identifyTimerCount; +constexpr uint32_t kIdentifyTimerDelayMS = 250; +constexpr uint32_t kInitOTARequestorDelaySec = 3; + +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR +void InitOTARequestorHandler(System::Layer * systemLayer, void * appState) +{ + OTAInitializer::Instance().InitOTARequestor(); +} +#endif + +void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg) +{ + switch (event->Type) + { + case DeviceEventType::kInternetConnectivityChange: + OnInternetConnectivityChange(event); + 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 DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId, uint8_t type, + uint16_t size, uint8_t * value) +{ + switch (clusterId) + { + case ZCL_ON_OFF_CLUSTER_ID: + OnOnOffPostAttributeChangeCallback(endpointId, attributeId, value); + break; + + case ZCL_IDENTIFY_CLUSTER_ID: + OnIdentifyPostAttributeChangeCallback(endpointId, attributeId, value); + break; + + default: + break; + } +} + +void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) +{ +#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(); +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + // Init OTA requestor only when we have gotten IPv6 address + if (!isOTAInitialized) + { + chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), + InitOTARequestorHandler, nullptr); + isOTAInitialized = true; + } +#endif + } + else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost) + { + ChipLogProgress(DeviceLayer, "Lost IPv6 connectivity..."); + } +} + +void DeviceCallbacks::OnOnOffPostAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value) +{ + VerifyOrExit(attributeId == ZCL_ON_OFF_ATTRIBUTE_ID, + ChipLogError(DeviceLayer, TAG, "Unhandled Attribute ID: '0x%04x", attributeId)); + VerifyOrExit(endpointId == 1 || endpointId == 2, + ChipLogError(DeviceLayer, TAG, "Unexpected EndPoint ID: `0x%02x'", endpointId)); + + // At this point we can assume that value points to a bool value. + statusLED1.Set(*value); + +exit: + return; +} + +void IdentifyTimerHandler(Layer * systemLayer, void * appState, CHIP_ERROR error) +{ + if (identifyTimerCount) + { + identifyTimerCount--; + } +} + +void DeviceCallbacks::OnIdentifyPostAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value) +{ + VerifyOrExit(attributeId == ZCL_IDENTIFY_TIME_ATTRIBUTE_ID, + ChipLogError(DeviceLayer, "[%s] Unhandled Attribute ID: '0x%04x", TAG, attributeId)); + VerifyOrExit(endpointId == 1, ChipLogError(DeviceLayer, "[%s] Unexpected EndPoint ID: `0x%02x'", TAG, endpointId)); + + // timerCount represents the number of callback executions before we stop the timer. + // value is expressed in seconds and the timer is fired every 250ms, so just multiply value by 4. + // Also, we want timerCount to be odd number, so the ligth state ends in the same state it starts. + identifyTimerCount = (*value) * 4; +exit: + return; +} + +bool emberAfBasicClusterMfgSpecificPingCallback(chip::app::CommandHandler * commandObj) +{ + emberAfSendDefaultResponse(emberAfCurrentCommand(), EMBER_ZCL_STATUS_SUCCESS); + return true; +} diff --git a/examples/chef/ameba/main/DsoHack.cpp b/examples/chef/ameba/main/DsoHack.cpp new file mode 100644 index 00000000000000..6fc5d7a63307c5 --- /dev/null +++ b/examples/chef/ameba/main/DsoHack.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// This hack is needed because Ameba SDK is not linking against libstdc++ correctly. +extern "C" { +void * __dso_handle = 0; +} diff --git a/examples/chef/ameba/main/Globals.cpp b/examples/chef/ameba/main/Globals.cpp new file mode 100755 index 00000000000000..71d9b6c9f0b940 --- /dev/null +++ b/examples/chef/ameba/main/Globals.cpp @@ -0,0 +1,21 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Globals.h" + +LEDWidget statusLED1; diff --git a/examples/chef/ameba/main/LEDWidget.cpp b/examples/chef/ameba/main/LEDWidget.cpp new file mode 100755 index 00000000000000..a050f4a4d4f0f0 --- /dev/null +++ b/examples/chef/ameba/main/LEDWidget.cpp @@ -0,0 +1,60 @@ +/* + * + * Copyright (c) 2018 Nest Labs, Inc. + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file LEDWidget.cpp + * + * Implements an LED Widget controller that is usually tied to a GPIO + * It also updates the display widget if it's enabled + */ + +#include "LEDWidget.h" + +gpio_t gpio_led; + +void LEDWidget::Init(PinName gpioNum) +{ + + mGPIONum = gpioNum; + mState = false; + + if (gpioNum != (PinName) NC) + { + // Init LED control pin + gpio_init(&gpio_led, gpioNum); + gpio_dir(&gpio_led, PIN_OUTPUT); // Direction: Output + gpio_mode(&gpio_led, PullNone); // No pull + gpio_write(&gpio_led, mState); + } +} + +void LEDWidget::Set(bool state) +{ + DoSet(state); +} + +void LEDWidget::DoSet(bool state) +{ + bool stateChange = (mState != state); + mState = state; + + if (stateChange) + { + gpio_write(&gpio_led, state); + } +} diff --git a/examples/chef/ameba/main/chipinterface.cpp b/examples/chef/ameba/main/chipinterface.cpp new file mode 100644 index 00000000000000..5a0b3f21d2417a --- /dev/null +++ b/examples/chef/ameba/main/chipinterface.cpp @@ -0,0 +1,159 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "CHIPDeviceManager.h" +#include "DeviceCallbacks.h" +#include "Globals.h" +#include "LEDWidget.h" +#include "chip_porting.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if CONFIG_ENABLE_PW_RPC +#include +#endif + +#if CONFIG_ENABLE_CHIP_SHELL +#include +#endif + +using namespace ::chip; +using namespace ::chip::Credentials; +using namespace ::chip::DeviceManager; +using namespace ::chip::DeviceLayer; +using namespace ::chip::System; + +namespace { // Network Commissioning +constexpr EndpointId kNetworkCommissioningEndpointMain = 0; +constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE; + +app::Clusters::NetworkCommissioning::Instance + sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */, + &(NetworkCommissioning::AmebaWiFiDriver::GetInstance())); +} // namespace + +void NetWorkCommissioningInstInit() +{ + sWiFiNetworkCommissioningInstance.Init(); + + // We only have network commissioning on endpoint 0. + emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false); +} + +Identify gIdentify0 = { + chip::EndpointId{ 0 }, + [](Identify *) { ChipLogProgress(Zcl, "onIdentifyStart"); }, + [](Identify *) { ChipLogProgress(Zcl, "onIdentifyStop"); }, + EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED, +}; + +Identify gIdentify1 = { + chip::EndpointId{ 1 }, + [](Identify *) { ChipLogProgress(Zcl, "onIdentifyStart"); }, + [](Identify *) { ChipLogProgress(Zcl, "onIdentifyStop"); }, + EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED, +}; + +#ifdef CONFIG_PLATFORM_8721D +#define STATUS_LED_GPIO_NUM PB_5 +#elif defined(CONFIG_PLATFORM_8710C) +#define STATUS_LED_GPIO_NUM PA_20 +#else +#define STATUS_LED_GPIO_NUM NC +#endif + +static DeviceCallbacks EchoCallbacks; +chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; +chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; + +static void InitServer(intptr_t 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); + + NetWorkCommissioningInstInit(); + + if (RTW_SUCCESS != wifi_is_connected_to_ap()) + { + // QR code will be used with CHIP Tool + PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); + } +} + +extern "C" void ChipTest(void) +{ + ChipLogProgress(DeviceLayer, "Chef App!"); + CHIP_ERROR err = CHIP_NO_ERROR; + +#if CONFIG_ENABLE_PW_RPC + chip::rpc::Init(); +#endif + + initPref(); + + // Initialize device attestation, commissionable data and device instance info + // TODO: Use our own DeviceInstanceInfoProvider + // SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); + CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance(); + + err = deviceMgr.Init(&EchoCallbacks); + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "DeviceManagerInit() - ERROR!\r\n"); + } + else + { + ChipLogProgress(DeviceLayer, "DeviceManagerInit() - OK\r\n"); + } + + chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, 0); + + statusLED1.Init(STATUS_LED_GPIO_NUM); + +#if CONFIG_ENABLE_CHIP_SHELL + chip::LaunchShell(); +#endif +} + +bool lowPowerClusterSleep() +{ + return true; +} diff --git a/examples/chef/ameba/main/include/BindingHandler.h b/examples/chef/ameba/main/include/BindingHandler.h new file mode 100644 index 00000000000000..280c94874f04dd --- /dev/null +++ b/examples/chef/ameba/main/include/BindingHandler.h @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "app-common/zap-generated/ids/Clusters.h" +#include "app-common/zap-generated/ids/Commands.h" +#include "lib/core/CHIPError.h" + +CHIP_ERROR InitBindingHandler(); +void SwitchWorkerFunction(intptr_t context); +void BindingWorkerFunction(intptr_t context); + +struct BindingCommandData +{ + chip::EndpointId localEndpointId = 1; + chip::CommandId commandId; + chip::ClusterId clusterId; + bool isGroup = false; +}; diff --git a/examples/chef/ameba/main/include/CHIPDeviceManager.h b/examples/chef/ameba/main/include/CHIPDeviceManager.h new file mode 100644 index 00000000000000..4a4efd1d4d39dd --- /dev/null +++ b/examples/chef/ameba/main/include/CHIPDeviceManager.h @@ -0,0 +1,124 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file contains definitions for the CHIP DeviceManager Interface + * + * This object will co-ordinate multiple activities such as + * initialisation, rendezvous, session mgmt and other such + * activities within the CHIP stack. This is a singleton object. + */ + +#pragma once + +#include +#include +#include + +#include + +#include +#include + +#include "af-types.h" + +namespace chip { +namespace DeviceManager { + +/** + * @brief + * This class provides a skeleton for all the callback functions. The functions will be + * called by other objects within the CHIP stack for specific events. + * Applications interested in receiving specific callbacks can specialize this class and handle + * these events in their implementation of this class. + */ +class CHIPDeviceManagerCallbacks +{ +public: + /** + * @brief + * Called when CHIP Device events (PublicEventTypes) are triggered. + * + * @param event ChipDeviceEvent that occurred + * @param arg arguments specific to the event, if any + */ + virtual void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) {} + + /** + * @brief + * Called after an attribute has been changed + * + * @param endpoint endpoint id + * @param clusterID cluster id + * @param attributeId attribute id that was changed + * @param manufacturerCode manufacturer code + * @param type attribute type + * @param size size of the attribute + * @param value pointer to the new value + */ + virtual void PostAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId, + uint8_t type, uint16_t size, uint8_t * value) + {} + virtual ~CHIPDeviceManagerCallbacks() {} +}; + +/** + * @brief + * A common class that drives other components of the CHIP stack + */ +class DLL_EXPORT CHIPDeviceManager +{ +public: + CHIPDeviceManager(const CHIPDeviceManager &) = delete; + CHIPDeviceManager(const CHIPDeviceManager &&) = delete; + CHIPDeviceManager & operator=(const CHIPDeviceManager &) = delete; + + static CHIPDeviceManager & GetInstance() + { + static CHIPDeviceManager instance; + return instance; + } + + /** + * @brief + * Initialise CHIPDeviceManager + * + * @param cb Application's instance of the CHIPDeviceManagerCallbacks for consuming events + */ + CHIP_ERROR Init(CHIPDeviceManagerCallbacks * cb); + + /** + * @brief + * Fetch a pointer to the registered CHIPDeviceManagerCallbacks object. + * + */ + CHIPDeviceManagerCallbacks * GetCHIPDeviceManagerCallbacks() { return mCB; } + + /** + * Use internally for registration of the ChipDeviceEvents + */ + static void CommonDeviceEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); + +private: + CHIPDeviceManagerCallbacks * mCB = nullptr; + CHIPDeviceManager() {} +}; + +} // namespace DeviceManager +} // namespace chip diff --git a/examples/chef/ameba/main/include/DeviceCallbacks.h b/examples/chef/ameba/main/include/DeviceCallbacks.h new file mode 100644 index 00000000000000..18ebb25ed75f36 --- /dev/null +++ b/examples/chef/ameba/main/include/DeviceCallbacks.h @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file DeviceCallbacks.h + * + * Implementations for the DeviceManager callbacks for this application + * + **/ + +#pragma once + +#include "CHIPDeviceManager.h" +#include +#include +#include + +class DeviceCallbacks : public chip::DeviceManager::CHIPDeviceManagerCallbacks +{ +public: + void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) override; + void PostAttributeChangeCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, chip::AttributeId attributeId, + uint8_t type, uint16_t size, uint8_t * value) override; + +private: + void OnInternetConnectivityChange(const chip::DeviceLayer::ChipDeviceEvent * event); + void OnOnOffPostAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value); + void OnIdentifyPostAttributeChangeCallback(chip::EndpointId endpointId, chip::AttributeId attributeId, uint8_t * value); +}; diff --git a/examples/chef/ameba/main/include/Globals.h b/examples/chef/ameba/main/include/Globals.h new file mode 100755 index 00000000000000..4033f2d0a996ee --- /dev/null +++ b/examples/chef/ameba/main/include/Globals.h @@ -0,0 +1,23 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "LEDWidget.h" + +extern LEDWidget statusLED1; diff --git a/examples/chef/ameba/main/include/LEDWidget.h b/examples/chef/ameba/main/include/LEDWidget.h new file mode 100755 index 00000000000000..9f1456daa7492d --- /dev/null +++ b/examples/chef/ameba/main/include/LEDWidget.h @@ -0,0 +1,158 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#ifdef CONFIG_PLATFORM_8710C +#include "gpio_api.h" +#include "rtl8710c_pin_name.h" + +#else + +typedef enum +{ + PORT_A = 0, + PORT_B = 1, +} GPIO_PORT; + +typedef enum +{ + PIN_INPUT = 0, + PIN_OUTPUT +} PinDirection; + +typedef enum +{ + PullNone = 0, // IN HIGHZ + PullUp = 1, + PullDown = 2, + PullDefault = PullNone +} PinMode; + +/* (((port)<<5)|(pin)) */ +typedef enum +{ + PA_0 = (PORT_A << 5 | 0), + PA_1 = (PORT_A << 5 | 1), + PA_2 = (PORT_A << 5 | 2), + PA_3 = (PORT_A << 5 | 3), + PA_4 = (PORT_A << 5 | 4), + PA_5 = (PORT_A << 5 | 5), + PA_6 = (PORT_A << 5 | 6), + PA_7 = (PORT_A << 5 | 7), + PA_8 = (PORT_A << 5 | 8), + PA_9 = (PORT_A << 5 | 9), + PA_10 = (PORT_A << 5 | 10), + PA_11 = (PORT_A << 5 | 11), + PA_12 = (PORT_A << 5 | 12), + PA_13 = (PORT_A << 5 | 13), + PA_14 = (PORT_A << 5 | 14), + PA_15 = (PORT_A << 5 | 15), + PA_16 = (PORT_A << 5 | 16), + PA_17 = (PORT_A << 5 | 17), + PA_18 = (PORT_A << 5 | 18), + PA_19 = (PORT_A << 5 | 19), + PA_20 = (PORT_A << 5 | 20), + PA_21 = (PORT_A << 5 | 21), + PA_22 = (PORT_A << 5 | 22), + PA_23 = (PORT_A << 5 | 23), + PA_24 = (PORT_A << 5 | 24), + PA_25 = (PORT_A << 5 | 25), + PA_26 = (PORT_A << 5 | 26), + PA_27 = (PORT_A << 5 | 27), + PA_28 = (PORT_A << 5 | 28), + PA_29 = (PORT_A << 5 | 29), + PA_30 = (PORT_A << 5 | 30), + PA_31 = (PORT_A << 5 | 31), + + PB_0 = (PORT_B << 5 | 0), + PB_1 = (PORT_B << 5 | 1), + PB_2 = (PORT_B << 5 | 2), + PB_3 = (PORT_B << 5 | 3), + PB_4 = (PORT_B << 5 | 4), + PB_5 = (PORT_B << 5 | 5), + PB_6 = (PORT_B << 5 | 6), + PB_7 = (PORT_B << 5 | 7), + PB_8 = (PORT_B << 5 | 8), + PB_9 = (PORT_B << 5 | 9), + PB_10 = (PORT_B << 5 | 10), + PB_11 = (PORT_B << 5 | 11), + PB_12 = (PORT_B << 5 | 12), + PB_13 = (PORT_B << 5 | 13), + PB_14 = (PORT_B << 5 | 14), + PB_15 = (PORT_B << 5 | 15), + PB_16 = (PORT_B << 5 | 16), + PB_17 = (PORT_B << 5 | 17), + PB_18 = (PORT_B << 5 | 18), + PB_19 = (PORT_B << 5 | 19), + PB_20 = (PORT_B << 5 | 20), + PB_21 = (PORT_B << 5 | 21), + PB_22 = (PORT_B << 5 | 22), + PB_23 = (PORT_B << 5 | 23), + PB_24 = (PORT_B << 5 | 24), + PB_25 = (PORT_B << 5 | 25), + PB_26 = (PORT_B << 5 | 26), + PB_27 = (PORT_B << 5 | 27), + PB_28 = (PORT_B << 5 | 28), + PB_29 = (PORT_B << 5 | 29), + PB_30 = (PORT_B << 5 | 30), + PB_31 = (PORT_B << 5 | 31), + + VBAT_MEAS = (0x7 << 5 | 2), + AD_0 = PB_4, // CH0 + AD_1 = PB_5, // CH1 + AD_2 = PB_6, // CH2 + AD_3 = PB_7, // CH3 + AD_4 = PB_1, // CH4 + AD_5 = PB_2, // CH5 + AD_6 = PB_3, // CH6 + AD_7 = VBAT_MEAS, // CH7 + + // Not connected + NC = (uint32_t) 0xFFFFFFFF +} PinName; + +typedef struct gpio_s +{ + PinName pin; +} gpio_t; + +#endif + +typedef struct gpio_s gpio_t; + +extern "C" void gpio_init(gpio_t * obj, PinName pin); +extern "C" uint32_t gpio_set(PinName pin); +extern "C" void gpio_mode(gpio_t * obj, PinMode mode); +extern "C" void gpio_dir(gpio_t * obj, PinDirection direction); +extern "C" void gpio_write(gpio_t * obj, int value); +extern "C" int gpio_read(gpio_t * obj); + +class LEDWidget +{ +public: + void Init(PinName gpioNum); + void Set(bool state); + +private: + PinName mGPIONum; + bool mState; + void DoSet(bool state); +}; diff --git a/examples/chef/ameba/third_party/connectedhomeip b/examples/chef/ameba/third_party/connectedhomeip new file mode 120000 index 00000000000000..11a54ed360106c --- /dev/null +++ b/examples/chef/ameba/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../../ \ No newline at end of file diff --git a/examples/chef/chef.py b/examples/chef/chef.py index 469ba9ac12463a..58d2b246d9f37d 100755 --- a/examples/chef/chef.py +++ b/examples/chef/chef.py @@ -38,7 +38,8 @@ _CHEF_SCRIPT_PATH = os.path.abspath(os.path.dirname(__file__)) _REPO_BASE_PATH = os.path.join(_CHEF_SCRIPT_PATH, "../../") _DEVICE_FOLDER = os.path.join(_CHEF_SCRIPT_PATH, "devices") -_DEVICE_LIST = [file[:-4] for file in os.listdir(_DEVICE_FOLDER) if file.endswith(".zap")] +_DEVICE_LIST = [file[:-4] + for file in os.listdir(_DEVICE_FOLDER) if file.endswith(".zap")] _CICD_CONFIG_FILE_NAME = os.path.join(_CHEF_SCRIPT_PATH, "cicd_config.json") _CD_STAGING_DIR = os.path.join(_CHEF_SCRIPT_PATH, "staging") @@ -64,6 +65,7 @@ def load_config() -> None: config["nrfconnect"] = dict() config["esp32"] = dict() config["silabs-thread"] = dict() + config["ameba"] = dict() configFile = f"{_CHEF_SCRIPT_PATH}/config.yaml" if (os.path.exists(configFile)): configStream = open(configFile, 'r') @@ -82,6 +84,10 @@ def load_config() -> None: config["silabs-thread"]["TTY"] = None config["silabs-thread"]["CU"] = None config["silabs-thread"]["EFR32_BOARD"] = None + config["ameba"]["AMEBA_SDK"] = None + config["ameba"]["MATTER_SDK"] = None + config["ameba"]["MODEL"] = 'D' + config["ameba"]["TTY"] = None flush_print(yaml.dump(config)) yaml.dump(config, configStream) @@ -250,7 +256,8 @@ def main() -> int: # if sys.platform == "win32": - flush_print('Windows is currently not supported. Use Linux or MacOS platforms') + flush_print( + 'Windows is currently not supported. Use Linux or MacOS platforms') exit(1) # @@ -267,6 +274,7 @@ def main() -> int: esp32 linux silabs-thread + ameba Device Types: {deviceTypes} @@ -304,7 +312,8 @@ def main() -> int: action='store', dest="build_target", help="specifies target platform. Default is esp32. See info below for currently supported target platforms", - choices=['nrfconnect', 'esp32', 'linux', 'silabs-thread'], + choices=['nrfconnect', 'esp32', + 'linux', 'silabs-thread', 'ameba'], metavar="TARGET", default="esp32") parser.add_option("-r", "--rpc", help="enables Pigweed RPC interface. Enabling RPC disables the shell interface. Your sdkconfig configurations will be reverted to default. Default is PW RPC off. When enabling or disabling this flag, on the first build force a clean build with -c", @@ -358,7 +367,8 @@ def main() -> int: libjpeg9-dev libgif-dev node-typescript""" shell.run_cmd(unwrap_cmd(install_deps_cmd)) if sys.platform == "darwin": - flush_print("Installation of ZAP OS packages not supported on MacOS") + flush_print( + "Installation of ZAP OS packages not supported on MacOS") if sys.platform == "win32": flush_print( "Installation of ZAP OS packages not supported on Windows") @@ -374,10 +384,12 @@ def main() -> int: if options.ci: for device_name in cicd_config["ci_allow_list"]: if device_name not in _DEVICE_LIST: - flush_print(f"{device_name} in CICD config but not {_DEVICE_FOLDER}!") + flush_print( + f"{device_name} in CICD config but not {_DEVICE_FOLDER}!") exit(1) if options.build_target == "nrfconnect": - shell.run_cmd("export GNUARMEMB_TOOLCHAIN_PATH=\"$PW_ARM_CIPD_INSTALL_DIR\"") + shell.run_cmd( + "export GNUARMEMB_TOOLCHAIN_PATH=\"$PW_ARM_CIPD_INSTALL_DIR\"") shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}") command = f"./chef.py -cbr --use_zzz -d {device_name} -t {options.build_target}" flush_print(f"Building {command}", with_border=True) @@ -413,7 +425,8 @@ def main() -> int: command += " ".join(args) flush_print(f"Building {command}", with_border=True) shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}") - shell.run_cmd("export GNUARMEMB_TOOLCHAIN_PATH=\"$PW_ARM_CIPD_INSTALL_DIR\"") + shell.run_cmd( + "export GNUARMEMB_TOOLCHAIN_PATH=\"$PW_ARM_CIPD_INSTALL_DIR\"") try: shell.run_cmd(command) except RuntimeError as build_fail_error: @@ -432,7 +445,8 @@ def main() -> int: continue os.makedirs(archive_prefix, exist_ok=True) archive_full_name = archive_prefix + archive_name + archive_suffix - flush_print(f"Adding build output to archive {archive_full_name}") + flush_print( + f"Adding build output to archive {archive_full_name}") if os.path.exists(archive_full_name): os.remove(archive_full_name) with tarfile.open(archive_full_name, "w:gz") as tar: @@ -461,25 +475,41 @@ def main() -> int: flush_print("Setting up environment...") if options.build_target == "esp32": if config['esp32']['IDF_PATH'] is None: - flush_print('Path for esp32 SDK was not found. Make sure esp32.IDF_PATH is set on your config.yaml file') + flush_print( + 'Path for esp32 SDK was not found. Make sure esp32.IDF_PATH is set on your config.yaml file') exit(1) plat_folder = os.path.normpath(f"{_CHEF_SCRIPT_PATH}/esp32") shell.run_cmd(f'source {config["esp32"]["IDF_PATH"]}/export.sh') elif options.build_target == "nrfconnect": if config['nrfconnect']['ZEPHYR_BASE'] is None: - flush_print('Path for nrfconnect SDK was not found. Make sure nrfconnect.ZEPHYR_BASE is set on your config.yaml file') + flush_print( + 'Path for nrfconnect SDK was not found. Make sure nrfconnect.ZEPHYR_BASE is set on your config.yaml file') exit(1) plat_folder = os.path.normpath(f"{_CHEF_SCRIPT_PATH}/nrfconnect") - shell.run_cmd(f'source {config["nrfconnect"]["ZEPHYR_BASE"]}/zephyr-env.sh') + shell.run_cmd( + f'source {config["nrfconnect"]["ZEPHYR_BASE"]}/zephyr-env.sh') shell.run_cmd("export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb") elif options.build_target == "linux": pass elif options.build_target == "silabs-thread": flush_print('Path to gecko sdk is configured within Matter.') if 'EFR32_BOARD' not in config['silabs-thread'] or config['silabs-thread']['EFR32_BOARD'] is None: - flush_print('EFR32_BOARD was not configured. Make sure silabs-thread.EFR32_BOARD is set on your config.yaml file') + flush_print( + 'EFR32_BOARD was not configured. Make sure silabs-thread.EFR32_BOARD is set on your config.yaml file') exit(1) efr32_board = config['silabs-thread']['EFR32_BOARD'] + elif options.build_target == "ameba": + if config['ameba']['AMEBA_SDK'] is None: + flush_print( + 'Path for Ameba SDK was not found. Make sure AMEBA_SDK is set on your config.yaml file') + exit(1) + if config['ameba']['MATTER_SDK'] is None: + flush_print( + 'Path for Matter SDK was not found. Make sure MATTER_SDK is set on your config.yaml file') + exit(1) + if (config['ameba']['MODEL'] != 'D' and config['ameba']['MODEL'] != 'Z2'): + flush_print("Ameba Model is not recognized, please input D or Z2") + exit(1) else: flush_print(f"Target {options.build_target} not supported") @@ -500,6 +530,8 @@ def main() -> int: flush_print("Silabs-thread toolchain not supported. Skipping") elif options.build_target == "linux": flush_print("Linux toolchain update not supported. Skipping") + elif options.build_target == "Ameba": + flush_print("Ameba toolchain update not supported. Skipping") # # Cluster customization @@ -532,9 +564,12 @@ def main() -> int: shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/nrfconnect") shell.run_cmd("west build -t menuconfig") elif (options.build_target == "silabs-thread") or (options.build_target == "silabs-wifi"): - flush_print("Menuconfig not available on Silabs-thread target. Skipping") + flush_print( + "Menuconfig not available on Silabs-thread target. Skipping") elif options.build_target == "linux": flush_print("Menuconfig not available on Linux target. Skipping") + elif options.build_target == "Ameba": + flush_print("Menuconfig not available on Ameba target. Skipping") # # Build @@ -550,7 +585,8 @@ def main() -> int: if match_texts: branch = match_texts[0] break - commit_id = shell.run_cmd("git rev-parse HEAD", return_cmd_output=True).replace("\n", "") + commit_id = shell.run_cmd( + "git rev-parse HEAD", return_cmd_output=True).replace("\n", "") sw_ver_string = f"""{branch}:{commit_id}""" # 64 bytes space could only contain 63 bytes string + 1 byte EOS. if len(sw_ver_string) >= 64: @@ -593,7 +629,7 @@ def main() -> int: f"Product ID 0x{options.pid:02X} / Vendor ID 0x{options.vid:02X}") shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}") - if (options.build_target == "esp32") or (options.build_target == "nrfconnect"): + if (options.build_target == "esp32") or (options.build_target == "nrfconnect") or (options.build_target == "ameba"): with open("project_include.cmake", "w") as f: f.write(textwrap.dedent(f"""\ set(CONFIG_DEVICE_VENDOR_ID {options.vid}) @@ -629,13 +665,16 @@ def main() -> int: if options.do_clean: shell.run_cmd(f"rm -rf out/{options.sample_device_type_name}") efr32_cmd_args = [] - efr32_cmd_args.append(f'{_REPO_BASE_PATH}/scripts/examples/gn_efr32_example.sh') + efr32_cmd_args.append( + f'{_REPO_BASE_PATH}/scripts/examples/gn_efr32_example.sh') efr32_cmd_args.append('./') efr32_cmd_args.append(f'out/{options.sample_device_type_name}') efr32_cmd_args.append(f'{efr32_board}') - efr32_cmd_args.append(f'\'sample_name=\"{options.sample_device_type_name}\"\'') + efr32_cmd_args.append( + f'\'sample_name=\"{options.sample_device_type_name}\"\'') if sw_ver_string: - efr32_cmd_args.append(f'\'chip_device_config_device_software_version_string=\"{sw_ver_string}\"\'') + efr32_cmd_args.append( + f'\'chip_device_config_device_software_version_string=\"{sw_ver_string}\"\'') efr32_cmd_args.append('enable_openthread_cli=true') if options.do_rpc: efr32_cmd_args.append('chip_build_libshell=false') @@ -645,6 +684,32 @@ def main() -> int: shell.run_cmd(" ".join(efr32_cmd_args)) shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}") + elif options.build_target == "ameba": + if config['ameba']['MODEL'] == 'D': + shell.run_cmd( + f"cd {config['ameba']['AMEBA_SDK']}/project/realtek_amebaD_va0_example/GCC-RELEASE") + if options.do_clean: + shell.run_cmd(f"rm -rf out") + shell.run_cmd( + f"./build.sh {config['ameba']['MATTER_SDK']} ninja {config['ameba']['AMEBA_SDK']}/project/realtek_amebaD_va0_example/GCC-RELEASE/out chef-app") + shell.run_cmd("ninja -C out") + elif config['ameba']['MODEL'] == 'Z2': + shell.run_cmd( + f"cd {config['ameba']['AMEBA_SDK']}/project/realtek_amebaz2_v0_example/GCC-RELEASE") + with open(f"{config['ameba']['AMEBA_SDK']}/project/realtek_amebaz2_v0_example/GCC-RELEASE/project_include.mk", "w") as f: + f.write(textwrap.dedent(f"""\ + SAMPLE_NAME = {options.sample_device_type_name} + CHEF_FLAGS = + CHEF_FLAGS += -DCONFIG_DEVICE_VENDOR_ID={options.vid} + CHEF_FLAGS += -DCONFIG_DEVICE_PRODUCT_ID={options.pid} + CHEF_FLAGS += -DCHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\"{options.pid}\" + """ + )) + if options.do_clean: + shell.run_cmd("make clean") + shell.run_cmd("make chef") + shell.run_cmd("make is") + elif options.build_target == "linux": shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/linux") @@ -673,7 +738,8 @@ def main() -> int: linux_args.append('target_cpu="arm64"') linux_args.append('is_clang=true') linux_args.append('chip_crypto="mbedtls"') - linux_args.append(f'sysroot="{shell.env["SYSROOT_AARCH64"]}"') + linux_args.append( + f'sysroot="{shell.env["SYSROOT_AARCH64"]}"') elif options.cpu_type == "arm": if "SYSROOT_ARMHF" not in shell.env: @@ -686,12 +752,14 @@ def main() -> int: linux_args.append('target_cpu="arm"') linux_args.append('is_clang=true') linux_args.append('chip_crypto="mbedtls"') - linux_args.append(f'sysroot="{shell.env["SYSROOT_ARMHF"]}"') + linux_args.append( + f'sysroot="{shell.env["SYSROOT_ARMHF"]}"') if options.cpu_type == "x64": uname_resp = shell.run_cmd("uname -m", return_cmd_output=True) if "x64" not in uname_resp and "x86_64" not in uname_resp: - flush_print(f"Unable to cross compile for x64 on {uname_resp}") + flush_print( + f"Unable to cross compile for x64 on {uname_resp}") exit(1) if options.ipv6only: linux_args.append("chip_inet_config_enable_ipv4=false") @@ -723,7 +791,8 @@ def main() -> int: flush_print("Flashing target") if options.build_target == "esp32": if config['esp32']['TTY'] is None: - flush_print('The path for the serial enumeration for esp32 is not set. Make sure esp32.TTY is set on your config.yaml file') + flush_print( + 'The path for the serial enumeration for esp32 is not set. Make sure esp32.TTY is set on your config.yaml file') exit(1) shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/esp32") if options.do_erase: @@ -738,9 +807,20 @@ def main() -> int: shell.run_cmd("west flash") elif (options.build_target == "silabs-thread") or (options.build_target == "silabs-wifi"): shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/efr32") - shell.run_cmd(f"python3 out/{options.sample_device_type_name}/{efr32_board}/chip-efr32-chef-example.flash.py") + shell.run_cmd( + f"python3 out/{options.sample_device_type_name}/{efr32_board}/chip-efr32-chef-example.flash.py") shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}") + elif (options.build_target == "ameba"): + if config['ameba']['MODEL'] == 'D': + shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/ameba") + shell.run_cmd( + f"cd {config['ameba']['AMEBA_SDK']}/tools/AmebaD/Image_Tool_Linux") + shell.run_cmd( + f"{config['ameba']['AMEBA_SDK']}/tools/AmebaD/Image_Tool_Linux/flash.sh {config['ameba']['TTY']} {config['ameba']['AMEBA_SDK']}/project/realtek_amebaD_va0_example/GCC-RELEASE/out", raise_on_returncode=False) + else: + flush_print( + "Ameba Z2 currently does not support flashing image through script, stil WIP") # # Terminal interaction @@ -750,13 +830,15 @@ def main() -> int: flush_print("Starting terminal...") if options.build_target == "esp32": if config['esp32']['TTY'] is None: - flush_print('The path for the serial enumeration for esp32 is not set. Make sure esp32.TTY is set on your config.yaml file') + flush_print( + 'The path for the serial enumeration for esp32 is not set. Make sure esp32.TTY is set on your config.yaml file') exit(1) shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/esp32") shell.run_cmd(f"idf.py -p {config['esp32']['TTY']} monitor") elif options.build_target == "nrfconnect": if config['nrfconnect']['TTY'] is None: - flush_print('The path for the serial enumeration for nordic is not set. Make sure nrfconnect.TTY is set on your config.yaml file') + flush_print( + 'The path for the serial enumeration for nordic is not set. Make sure nrfconnect.TTY is set on your config.yaml file') exit(1) shell.run_cmd("killall screen") shell.run_cmd(f"screen {config['nrfconnect']['TTY']} 115200") @@ -767,12 +849,23 @@ def main() -> int: exit(1) shell.run_cmd("killall screen") - shell.run_cmd(f"screen {config['silabs-thread']['TTY']} 115200 8-N-1") + shell.run_cmd( + f"screen {config['silabs-thread']['TTY']} 115200 8-N-1") elif options.build_target == "linux": flush_print( f"{_CHEF_SCRIPT_PATH}/linux/out/{options.sample_device_type_name}") shell.run_cmd( f"{_CHEF_SCRIPT_PATH}/linux/out/{options.sample_device_type_name}") + elif options.build_target == "ameba": + if config['ameba']['TTY'] is None: + flush_print( + 'The path for the serial enumeration for ameba is not set. Make sure ameba.TTY is set on your config.yaml file') + exit(1) + if config['ameba']['MODEL'] == 'D': + shell.run_cmd("killall screen") + shell.run_cmd(f"screen {config['ameba']['TTY']} 115200") + else: + flush_print("Ameba Z2 image has not been flashed yet") # # RPC Console @@ -787,13 +880,15 @@ def main() -> int: flush_print( 'The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.TTY is set on your config.yaml file') exit(1) - shell.run_cmd(f"python3 -m chip_rpc.console --device {config['silabs-thread']['TTY']} -b 115200") + shell.run_cmd( + f"python3 -m chip_rpc.console --device {config['silabs-thread']['TTY']} -b 115200") elif sys.platform == "darwin": if(config['silabs-thread']['CU'] is None): flush_print( 'The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.CU is set on your config.yaml file') exit(1) - shell.run_cmd(f"python3 -m chip_rpc.console --device {config['silabs-thread']['CU']} -b 115200") + shell.run_cmd( + f"python3 -m chip_rpc.console --device {config['silabs-thread']['CU']} -b 115200") flush_print("Done") return 0 diff --git a/src/platform/Ameba/KeyValueStoreManagerImpl.cpp b/src/platform/Ameba/KeyValueStoreManagerImpl.cpp index 93ec38b8611b58..520766f3746f31 100644 --- a/src/platform/Ameba/KeyValueStoreManagerImpl.cpp +++ b/src/platform/Ameba/KeyValueStoreManagerImpl.cpp @@ -21,6 +21,7 @@ * Platform-specific key value storage implementation for Ameba */ /* this file behaves like a config.h, comes first */ +#include "FreeRTOS.h" #include "chip_porting.h" #include #include