From 1662476bcfa80a7419e32c2f64080ca40a1aa657 Mon Sep 17 00:00:00 2001 From: stoneM2017 Date: Sun, 3 Jul 2022 00:22:40 +0800 Subject: [PATCH] [BL602]1. add the support of pw_rpc; 2. enable buttons on dev board to do factory reset and control light (#20212) * [BL602]add the support of pw_rpc * enable Button to do factory reset and toggle LED * [BL602]fix restyled issue * add new line at end of file * fix restyle issues * continue fix restlye issues * continue fix restlye issues * continue fix restlye issues * trigger restyled check --- config/bouffalolab/bl602/lib/pw_rpc/BUILD.gn | 2 +- .../bouffalolab/bl602/lib/pw_rpc/pw_rpc.gni | 4 +- .../bouffalolab/bl602/PigweedLoggerMutex.cpp | 27 ++ .../bouffalolab/bl602/PigweedLoggerMutex.h | 54 ++++ .../lighting-app/bouffalolab/bl602/BUILD.gn | 62 ++++ .../lighting-app/bouffalolab/bl602/README.md | 23 ++ .../lighting-app/bouffalolab/bl602/args.gni | 4 +- .../bouffalolab/bl602/include/AppConfig.h | 5 +- .../bouffalolab/bl602/include/AppTask.h | 5 +- .../bouffalolab/bl602/include/LEDWidget.h | 6 +- .../bouffalolab/bl602/src/AppTask.cpp | 138 ++++++--- .../bouffalolab/bl602/src/DeviceCallbacks.cpp | 4 +- .../bouffalolab/bl602/src/LEDWidget.cpp | 112 ++----- .../bouffalolab/bl602/src/main.cpp | 6 +- .../bouffalolab/bl602/with_pw_rpc.gni | 28 ++ .../bouffalolab/bl602/InitPlatform.cpp | 90 +++++- .../platform/bouffalolab/bl602/InitPlatform.h | 3 + .../bouffalolab/bl602/PigweedLogger.cpp | 2 +- examples/platform/bouffalolab/bl602/Rpc.cpp | 229 ++++++++++++++ examples/platform/bouffalolab/bl602/Rpc.h | 30 ++ .../bouffalolab/bl602/pw_sys_io/BUILD.gn | 2 +- .../init.h | 0 .../{sys_io_efr32.cc => sys_io_bl602.cc} | 0 examples/platform/bouffalolab/bl602/uart.c | 290 ++++-------------- scripts/examples/gn_bl602_example.sh | 40 ++- .../BL602/ConfigurationManagerImpl.cpp | 23 +- src/platform/bouffalolab/BL602/Logging.cpp | 32 ++ .../bouffalolab/bl602_sdk/bl602_sdk.gni | 2 +- 28 files changed, 807 insertions(+), 416 deletions(-) create mode 100644 examples/common/pigweed/bouffalolab/bl602/PigweedLoggerMutex.cpp create mode 100644 examples/common/pigweed/bouffalolab/bl602/PigweedLoggerMutex.h create mode 100644 examples/lighting-app/bouffalolab/bl602/with_pw_rpc.gni create mode 100644 examples/platform/bouffalolab/bl602/Rpc.cpp create mode 100644 examples/platform/bouffalolab/bl602/Rpc.h rename examples/platform/bouffalolab/bl602/pw_sys_io/public/{pw_sys_io_efr32 => pw_sys_io_bl602}/init.h (100%) rename examples/platform/bouffalolab/bl602/pw_sys_io/{sys_io_efr32.cc => sys_io_bl602.cc} (100%) diff --git a/config/bouffalolab/bl602/lib/pw_rpc/BUILD.gn b/config/bouffalolab/bl602/lib/pw_rpc/BUILD.gn index 66ab51fc23adf0..8f11811b370736 100644 --- a/config/bouffalolab/bl602/lib/pw_rpc/BUILD.gn +++ b/config/bouffalolab/bl602/lib/pw_rpc/BUILD.gn @@ -24,7 +24,7 @@ static_library("pw_rpc") { public_deps = [ "$dir_pw_rpc:server", "$dir_pw_rpc/nanopb:echo_service", - "${chip_root}/examples/platform/bl602/pw_sys_io:pw_sys_io_bl602", + "${chip_root}/examples/platform/bouffalolab/bl602/pw_sys_io:pw_sys_io_bl602", "${dir_pigweed}/pw_hdlc:pw_rpc", dir_pw_assert, dir_pw_checksum, diff --git a/config/bouffalolab/bl602/lib/pw_rpc/pw_rpc.gni b/config/bouffalolab/bl602/lib/pw_rpc/pw_rpc.gni index 172d2f366d3212..87e772e7c7ba96 100644 --- a/config/bouffalolab/bl602/lib/pw_rpc/pw_rpc.gni +++ b/config/bouffalolab/bl602/lib/pw_rpc/pw_rpc.gni @@ -16,9 +16,9 @@ import("//build_overrides/chip.gni") import("//build_overrides/pigweed.gni") pw_log_BACKEND = "$dir_pw_log_basic" -pw_assert_BACKEND = "$dir_pw_assert_log:check_backend" +pw_assert_BACKEND = "$dir_pw_assert_log" pw_sys_io_BACKEND = - "${chip_root}/examples/platform/bl602/pw_sys_io:pw_sys_io_bl602" + "${chip_root}/examples/platform/bouffalolab/bl602/pw_sys_io:pw_sys_io_bl602" pw_span_ENABLE_STD_SPAN_POLYFILL = false pw_build_LINK_DEPS = [ diff --git a/examples/common/pigweed/bouffalolab/bl602/PigweedLoggerMutex.cpp b/examples/common/pigweed/bouffalolab/bl602/PigweedLoggerMutex.cpp new file mode 100644 index 00000000000000..5061d53e768a6d --- /dev/null +++ b/examples/common/pigweed/bouffalolab/bl602/PigweedLoggerMutex.cpp @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2021 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 "PigweedLoggerMutex.h" + +namespace chip { +namespace rpc { + +PigweedLoggerMutex logger_mutex; + +} // namespace rpc +} // namespace chip diff --git a/examples/common/pigweed/bouffalolab/bl602/PigweedLoggerMutex.h b/examples/common/pigweed/bouffalolab/bl602/PigweedLoggerMutex.h new file mode 100644 index 00000000000000..4df8b616895e39 --- /dev/null +++ b/examples/common/pigweed/bouffalolab/bl602/PigweedLoggerMutex.h @@ -0,0 +1,54 @@ +/* + * + * Copyright (c) 2021 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 "PigweedLogger.h" +#include "pigweed/RpcService.h" +#include "semphr.h" +#include + +namespace chip { +namespace rpc { +class PigweedLoggerMutex : public ::chip::rpc::Mutex +{ + +public: + PigweedLoggerMutex() {} + void Lock() override + { + SemaphoreHandle_t * sem = PigweedLogger::GetSemaphore(); + if (sem) + { + xSemaphoreTake(*sem, portMAX_DELAY); + } + } + void Unlock() override + { + SemaphoreHandle_t * sem = PigweedLogger::GetSemaphore(); + if (sem) + { + xSemaphoreGive(*sem); + } + } +}; + +extern PigweedLoggerMutex logger_mutex; + +} // namespace rpc +} // namespace chip diff --git a/examples/lighting-app/bouffalolab/bl602/BUILD.gn b/examples/lighting-app/bouffalolab/bl602/BUILD.gn index ec6b1198c2d3c4..08cd7fda67ebe6 100644 --- a/examples/lighting-app/bouffalolab/bl602/BUILD.gn +++ b/examples/lighting-app/bouffalolab/bl602/BUILD.gn @@ -19,6 +19,12 @@ import("//build_overrides/chip.gni") import("${bl602_sdk_build_root}/bl602_executable.gni") import("${bl602_sdk_build_root}/bl602_sdk.gni") import("${build_root}/config/defaults.gni") +import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") + +if (chip_enable_pw_rpc) { + import("//build_overrides/pigweed.gni") + import("$dir_pw_build/target_types.gni") +} assert(current_os == "freertos") @@ -59,6 +65,10 @@ bl602_sdk("sdk") { "CONFIG_PSM_EASYFLASH_SIZE=16384", "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}", ] + + if (chip_enable_pw_rpc) { + defines += [ "PW_RPC_ENABLED" ] + } } bl602_executable("lighting_app") { @@ -76,6 +86,10 @@ bl602_executable("lighting_app") { "src/main.cpp", ] + if (chip_enable_pw_rpc) { + sources += [ "${examples_plat_dir}/uart.c" ] + } + deps = [ ":sdk", "${chip_root}/examples/common/QRCode", @@ -99,6 +113,54 @@ bl602_executable("lighting_app") { defines += [ "DISPLAY_ENABLED" ] } + if (chip_enable_pw_rpc) { + defines += [ + "PW_RPC_ENABLED", + "PW_RPC_ATTRIBUTE_SERVICE=1", + "PW_RPC_BUTTON_SERVICE=1", + "PW_RPC_DESCRIPTOR_SERVICE=1", + "PW_RPC_DEVICE_SERVICE=1", + "PW_RPC_LIGHTING_SERVICE=1", + + #"PW_RPC_OTCLI_SERVICE=1", + #"PW_RPC_THREAD_SERVICE=1", + #"PW_RPC_TRACING_SERVICE=1", + ] + + sources += [ + "${chip_root}/examples/common/pigweed/RpcService.cpp", + "${chip_root}/examples/common/pigweed/bouffalolab/bl602/PigweedLoggerMutex.cpp", + "${examples_plat_dir}/PigweedLogger.cpp", + "${examples_plat_dir}/Rpc.cpp", + ] + + deps += [ + "$dir_pw_hdlc:rpc_channel_output", + "$dir_pw_stream:sys_io_stream", + + #"$dir_pw_trace", + #"$dir_pw_trace_tokenized", + #"$dir_pw_trace_tokenized:trace_rpc_service", + "${chip_root}/config/bouffalolab/bl602/lib/pw_rpc:pw_rpc", + "${chip_root}/examples/common/pigweed:attributes_service.nanopb_rpc", + "${chip_root}/examples/common/pigweed:button_service.nanopb_rpc", + "${chip_root}/examples/common/pigweed:descriptor_service.nanopb_rpc", + "${chip_root}/examples/common/pigweed:device_service.nanopb_rpc", + "${chip_root}/examples/common/pigweed:lighting_service.nanopb_rpc", + + #"${chip_root}/examples/common/pigweed:ot_cli_service.nanopb_rpc", + #"${chip_root}/examples/common/pigweed:thread_service.nanopb_rpc", + "${examples_plat_dir}/pw_sys_io:pw_sys_io_bl602", + ] + + deps += pw_build_LINK_DEPS + + include_dirs += [ + "${chip_root}/examples/common", + "${chip_root}/examples/common/pigweed/bouffalolab/bl602", + ] + } + if (enable_heap_monitoring) { defines += [ "HEAP_MONITORING" ] sources += [ "${examples_plat_dir}/MemMonitoring.cpp" ] diff --git a/examples/lighting-app/bouffalolab/bl602/README.md b/examples/lighting-app/bouffalolab/bl602/README.md index 22873801a823c9..398562aaa17b63 100644 --- a/examples/lighting-app/bouffalolab/bl602/README.md +++ b/examples/lighting-app/bouffalolab/bl602/README.md @@ -39,6 +39,12 @@ The steps in this document were validated on Ubuntu 18.04 and 20.04. ./scripts/build/build_examples.py --target bl602-light build ``` +- Build the lighting-app with Pigweed RPC: + + ``` + ./scripts/examples/gn_bl602_example.sh lighting-app ./out/bl602-light 'import("//with_pw_rpc.gni")' + ``` + - Connect the board to your flashing station (MacOS, Ubuntu, Windows). - Set the board to the download mode: @@ -118,3 +124,20 @@ the BL602 lighting-app to commission it onto a Wi-Fi network: ``` $ sudo ./chip-tool colorcontrol move-to-hue-and-saturation 240 100 0 0 0 1 1 ``` + +### Running RPC Console + +- Build chip-console following this + [guide](../../../common/pigweed/rpc_console/README.md) + +- Start the console + + ``` + $ chip-console --device /dev/ttyUSB0 -b 2000000 + ``` + +- Get or Set the light state + + `rpcs.chip.rpc.Lighting.Get()` + + `rpcs.chip.rpc.Lighting.Set(on=True, level=128)` diff --git a/examples/lighting-app/bouffalolab/bl602/args.gni b/examples/lighting-app/bouffalolab/bl602/args.gni index 3425fc8d0035ba..7f4894d278fd7d 100644 --- a/examples/lighting-app/bouffalolab/bl602/args.gni +++ b/examples/lighting-app/bouffalolab/bl602/args.gni @@ -18,10 +18,12 @@ import("${chip_root}/src/platform/bouffalolab/BL602/args.gni") bl602_sdk_target = get_label_info(":sdk", "label_no_toolchain") pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" -pw_assert_BACKEND = "$dir_pw_assert_log:check_backend" +pw_assert_BACKEND = "$dir_pw_assert_log" chip_enable_openthread = false +pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex" + # Disable lock tracking, since our FreeRTOS configuration does not set # INCLUDE_xSemaphoreGetMutexHolder chip_stack_lock_tracking = "none" diff --git a/examples/lighting-app/bouffalolab/bl602/include/AppConfig.h b/examples/lighting-app/bouffalolab/bl602/include/AppConfig.h index 4bc195187b2c69..584a61aa4f5aad 100644 --- a/examples/lighting-app/bouffalolab/bl602/include/AppConfig.h +++ b/examples/lighting-app/bouffalolab/bl602/include/AppConfig.h @@ -32,12 +32,11 @@ extern "C" { //#define APP_LIGHT_BUTTON (34) #define APP_FUNCTION_BUTTON (35) - +#define APP_LOCK_BUTTON (8) #define APP_BUTTON_DEBOUNCE_PERIOD_MS 50 #define APP_BUTTON_PRESSED 0 -#define APP_BUTTON_RELEASED 1 - +#define APP_BUTTON_LONGPRESSED 1 // Time it takes in ms for the simulated actuator to move from one // state to another. #define ACTUATOR_MOVEMENT_PERIOS_MS 2000 diff --git a/examples/lighting-app/bouffalolab/bl602/include/AppTask.h b/examples/lighting-app/bouffalolab/bl602/include/AppTask.h index d27d9332c21c25..f8e56c4cb43464 100644 --- a/examples/lighting-app/bouffalolab/bl602/include/AppTask.h +++ b/examples/lighting-app/bouffalolab/bl602/include/AppTask.h @@ -49,6 +49,7 @@ class AppTask void PostEvent(const AppEvent * event); void ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction); void AppTask::OtaTask(void); + void LightStateUpdateEventHandler(void); private: friend AppTask & GetAppTask(void); @@ -68,7 +69,9 @@ class AppTask static void TimerEventHandler(TimerHandle_t xTimer); static void UpdateClusterState(void); - + static void FactoryResetButtonEventHandler(void); + static void LightingActionButtonEventHandler(void); + static void InitButtons(void); void StartTimer(uint32_t aTimeoutMs); enum Function_t diff --git a/examples/lighting-app/bouffalolab/bl602/include/LEDWidget.h b/examples/lighting-app/bouffalolab/bl602/include/LEDWidget.h index a32bdd9151795d..2b218d02fd899b 100644 --- a/examples/lighting-app/bouffalolab/bl602/include/LEDWidget.h +++ b/examples/lighting-app/bouffalolab/bl602/include/LEDWidget.h @@ -45,7 +45,9 @@ class LEDWidget void Animate(); void SetColor(uint8_t Hue, uint8_t Saturation); - + void Toggle(); + uint8_t GetLevel(); + bool IsTurnedOn(); void HSB2rgb(uint16_t Hue, uint8_t Saturation, uint8_t brightness, uint8_t & red, uint8_t & green, uint8_t & blue); private: @@ -62,7 +64,7 @@ class LEDWidget bool mError; TimerHandle_t errorTimer; - void DoSet(bool state); + void DoSet(); friend void ClearErrorState(TimerHandle_t); }; diff --git a/examples/lighting-app/bouffalolab/bl602/src/AppTask.cpp b/examples/lighting-app/bouffalolab/bl602/src/AppTask.cpp index db3e23741d7ced..b2cab4c7bbea3d 100644 --- a/examples/lighting-app/bouffalolab/bl602/src/AppTask.cpp +++ b/examples/lighting-app/bouffalolab/bl602/src/AppTask.cpp @@ -41,10 +41,17 @@ #include #include +#include #include #include +#include +#include #include +#if PW_RPC_ENABLED +#include "Rpc.h" +#endif + #define FACTORY_RESET_TRIGGER_TIMEOUT 3000 #define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000 #define APP_EVENT_QUEUE_SIZE 10 @@ -54,7 +61,7 @@ static const char * const TAG = "lighting-app"; static xTaskHandle OTA_TASK_HANDLE; - +static LEDWidget statusLED; namespace { TimerHandle_t sFunctionTimer; // FreeRTOS app sw timer. @@ -143,6 +150,13 @@ CHIP_ERROR AppTask::Init() ConfigurationMgr().LogDeviceConfig(); PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE)); + + InitButtons(); + +#if PW_RPC_ENABLED + chip::rpc::Init(); +#endif + return err; } @@ -351,55 +365,24 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) void AppTask::FunctionHandler(AppEvent * aEvent) { - // To trigger software update: press the APP_FUNCTION_BUTTON button briefly (< - // FACTORY_RESET_TRIGGER_TIMEOUT) To initiate factory reset: press the - // APP_FUNCTION_BUTTON for FACTORY_RESET_TRIGGER_TIMEOUT + - // FACTORY_RESET_CANCEL_WINDOW_TIMEOUT All LEDs start blinking after - // FACTORY_RESET_TRIGGER_TIMEOUT to signal factory reset has been initiated. - // To cancel factory reset: release the APP_FUNCTION_BUTTON once all LEDs - // start blinking within the FACTORY_RESET_CANCEL_WINDOW_TIMEOUT - if (aEvent->ButtonEvent.Action == APP_BUTTON_PRESSED) - { - if (!sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_NoneSelected) - { - sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT); - sAppTask.mFunction = kFunction_StartBleAdv; - } + + if (aEvent->ButtonEvent.Action == APP_BUTTON_LONGPRESSED) + { + log_info("FactoryReset! please release boutton!!!\r\n"); + statusLED.Toggle(); + vTaskDelay(1000); + statusLED.Toggle(); + vTaskDelay(1000); + statusLED.Toggle(); + vTaskDelay(3000); + chip::Server::GetInstance().ScheduleFactoryReset(); } - else + else if (aEvent->ButtonEvent.Action == APP_BUTTON_PRESSED) { - // If the button was released before factory reset got initiated, start BLE advertissement in fast mode - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv) - { - sAppTask.CancelTimer(); - sAppTask.mFunction = kFunction_NoneSelected; - - if (!ConnectivityMgr().IsThreadProvisioned()) - { - // Enable BLE advertisements - ConnectivityMgr().SetBLEAdvertisingEnabled(true); - ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising); - } - else - { - log_warn("Network is already provisioned, Ble advertissement not enabled\r\n"); - } - } - else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset) - { -#if 0 // TODO: 3R - // Set lock status LED back to show state of lock. - sLockLED.Set(!BoltLockMgr().IsUnlocked()); -#endif - - sAppTask.CancelTimer(); - - // Change the function to none selected since factory reset has been - // canceled. - sAppTask.mFunction = kFunction_NoneSelected; - - log_info("Factory Reset has been Canceled\r\n"); - } + AppEvent Lightevent = {}; + Lightevent.Type = AppEvent::kEventType_Button; + Lightevent.Handler = LightActionEventHandler; + sAppTask.PostEvent(&Lightevent); } } @@ -535,8 +518,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent) void AppTask::UpdateClusterState(void) { uint8_t newValue = LightMgr().IsLightOn(); - - // write the new on/off value + log_info("updating on/off = %x\r\n", newValue); EmberAfStatus status = emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, (uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE); if (status != EMBER_ZCL_STATUS_SUCCESS) @@ -557,3 +539,59 @@ void AppTask::OtaTask(void) return; } } + +void AppTask::FactoryResetButtonEventHandler(void) +{ + AppEvent button_event = {}; + button_event.Type = AppEvent::kEventType_Button; + button_event.ButtonEvent.Action = APP_BUTTON_LONGPRESSED; + + button_event.Handler = FunctionHandler; + log_info("FactoryResetButtonEventHandler\r\n"); + sAppTask.PostEvent(&button_event); +} + +void AppTask::LightingActionButtonEventHandler(void) +{ + AppEvent button_event = {}; + button_event.Type = AppEvent::kEventType_Button; + button_event.ButtonEvent.Action = APP_BUTTON_PRESSED; + + button_event.Handler = FunctionHandler; + log_info("LightingActionButtonEventHandler\r\n"); + sAppTask.PostEvent(&button_event); +} + +void AppTask::InitButtons(void) +{ + Button_Configure_FactoryResetEventHandler(&FactoryResetButtonEventHandler); + Button_Configure_LightingActionEventHandler(&LightingActionButtonEventHandler); +} + +void AppTask::LightStateUpdateEventHandler(void) +{ + uint8_t onoff, level; + do + { + if (EMBER_ZCL_STATUS_SUCCESS != + emberAfReadAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, (uint8_t *) &onoff, sizeof(uint8_t))) + { + break; + } + if (EMBER_ZCL_STATUS_SUCCESS != + emberAfReadAttribute(1, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID, (uint8_t *) &level, + sizeof(uint8_t))) + { + break; + } + if (0 == onoff) + { + statusLED.SetBrightness(0); + statusLED.Set(0); + } + else + { + statusLED.SetBrightness(level); + } + } while (0); +} diff --git a/examples/lighting-app/bouffalolab/bl602/src/DeviceCallbacks.cpp b/examples/lighting-app/bouffalolab/bl602/src/DeviceCallbacks.cpp index 146559b3552d6b..b97ba7ee908df0 100644 --- a/examples/lighting-app/bouffalolab/bl602/src/DeviceCallbacks.cpp +++ b/examples/lighting-app/bouffalolab/bl602/src/DeviceCallbacks.cpp @@ -167,7 +167,7 @@ void DeviceCallbacks::OnOnOffPostAttributeChangeCallback(EndpointId endpointId, // At this point we can assume that value points to a bool value. mEndpointOnOffState[endpointId - 1] = *value; - statusLED1.Set(*value); + GetAppTask().LightStateUpdateEventHandler(); exit: return; @@ -182,7 +182,7 @@ void DeviceCallbacks::OnLevelControlAttributeChangeCallback(EndpointId endpointI VerifyOrExit(endpointId == 1 || endpointId == 2, log_error("Unexpected EndPoint ID: `0x%02x'\r\n", endpointId)); // At this point we can assume that value points to a bool value. - statusLED1.SetBrightness(brightness); + GetAppTask().LightStateUpdateEventHandler(); exit: return; diff --git a/examples/lighting-app/bouffalolab/bl602/src/LEDWidget.cpp b/examples/lighting-app/bouffalolab/bl602/src/LEDWidget.cpp index 0dab8b76bf7283..79f9076881160c 100644 --- a/examples/lighting-app/bouffalolab/bl602/src/LEDWidget.cpp +++ b/examples/lighting-app/bouffalolab/bl602/src/LEDWidget.cpp @@ -27,74 +27,11 @@ #include "AppTask.h" #include -#include - -#define IOT_DVK_3S 0 - -#if BOARD_ID == IOT_DVK_3S -hosal_pwm_dev_t pwmR = { .port = 0xff }; -#endif +#include static void showRGB(uint8_t red, uint8_t green, uint8_t blue) { - -#if BOARD_ID == IOT_DVK_3S - - uint32_t level = (red * 10000) / UINT8_MAX; - log_info("red level: %d\r\n", level); - - if (pwmR.port == 0xff) - { - pwmR.port = 0; - pwmR.config.pin = 0; - pwmR.config.duty_cycle = level; // duty_cycle range is 0~10000 correspond to 0~100% - pwmR.config.freq = 1000; - hosal_pwm_init(&pwmR); - vTaskDelay(50); - hosal_pwm_start(&pwmR); - } - else - { - pwmR.config.duty_cycle = level; // duty_cycle range is 0~10000 correspond to 0~100% - pwmR.config.freq = 1000; - hosal_pwm_para_chg(&pwmR, pwmR.config); - } -#else - - hosal_pwm_dev_t pwmR, pwmG, pwmB; - - uint32_t level = (red * 10000) / UINT8_MAX; - log_info("red level: %d\r\n", level); - pwmR.port = 0; - pwmR.config.pin = 20; - pwmR.config.duty_cycle = level; // duty_cycle range is 0~10000 correspond to 0~100% - pwmR.config.freq = 1000; - hosal_pwm_init(&pwmR); - // vTaskDelay(100); - - level = (green * 10000) / UINT8_MAX; - log_info("green level: %d\r\n", level); - pwmG.port = 1; - pwmG.config.pin = 21; - pwmG.config.duty_cycle = level; // duty_cycle range is 0~10000 correspond to 0~100% - pwmG.config.freq = 1000; - hosal_pwm_init(&pwmG); - // vTaskDelay(100); - - level = (blue * 10000) / UINT8_MAX; - log_info("blue level: %d\r\n", level); - pwmB.port = 2; - // not use debug port - // pwmB.config.pin = 17; - pwmB.config.duty_cycle = level; // duty_cycle range is 0~10000 correspond to 0~100% - pwmB.config.freq = 1000; - hosal_pwm_init(&pwmB); - vTaskDelay(50); - - hosal_pwm_start(&pwmG); - hosal_pwm_start(&pwmR); - hosal_pwm_start(&pwmB); -#endif + BL602_LightState_Update(red, green, blue); } void LEDWidget::Init(uint8_t gpioNum) @@ -116,9 +53,13 @@ void LEDWidget::Init(uint8_t gpioNum) void LEDWidget::Set(bool state) { - log_info("state: %d\r\n", state); + log_info("Setting state to %d", state ? 1 : 0); + if (state == mState) + return; + + mState = state; mBlinkOnTimeMS = mBlinkOffTimeMS = 0; - DoSet(state); + DoSet(); } void LEDWidget::SetBrightness(uint8_t brightness) @@ -129,11 +70,7 @@ void LEDWidget::SetBrightness(uint8_t brightness) log_info("brightness: %d, mHue: %d, mSaturation: %d, red: %d, green: %d, blue: %d\r\n", brightness, mHue, mSaturation, red, green, blue); showRGB(red, green, blue); - - if (brightness > 0) - { - mDefaultOnBrightness = brightness; - } + mDefaultOnBrightness = brightness; } void LEDWidget::Blink(uint32_t changeRateMS) @@ -168,20 +105,39 @@ void LEDWidget::Animate() } } -void LEDWidget::DoSet(bool state) +void LEDWidget::DoSet() { - bool stateChange = (mState != state); - mState = state; - uint8_t red, green, blue; - uint8_t brightness = state ? mDefaultOnBrightness : 0; - log_info("state: %d, mDefaultOnBrightness: %d, brightness: %d\r\n", state, mDefaultOnBrightness, brightness); + uint8_t brightness = mState ? mDefaultOnBrightness : 0; + log_info("state: %d, mDefaultOnBrightness: %d, brightness: %d\r\n", mState, mDefaultOnBrightness, brightness); HSB2rgb(mHue, mSaturation, brightness, red, green, blue); log_info("brightness: %d, mHue: %d, mSaturation: %d, red: %d, green: %d, blue: %d\r\n", brightness, mHue, mSaturation, red, green, blue); showRGB(red, green, blue); } +void LEDWidget::Toggle() +{ + log_info("Toggling state to %d", !mState); + mState = !mState; + if (mState == 1) + { + SetBrightness(UINT8_MAX); + } + else + { + SetBrightness(0); + } +} +uint8_t LEDWidget::GetLevel() +{ + return this->mDefaultOnBrightness; +} + +bool LEDWidget::IsTurnedOn() +{ + return this->mState; +} void LEDWidget::SetColor(uint8_t Hue, uint8_t Saturation) { uint8_t red, green, blue; diff --git a/examples/lighting-app/bouffalolab/bl602/src/main.cpp b/examples/lighting-app/bouffalolab/bl602/src/main.cpp index 679812bb274fc5..de96a44d69608c 100644 --- a/examples/lighting-app/bouffalolab/bl602/src/main.cpp +++ b/examples/lighting-app/bouffalolab/bl602/src/main.cpp @@ -35,7 +35,7 @@ #include -#if CONFIG_ENABLE_PW_RPC +#if PW_RPC_ENABLED #include "PigweedLogger.h" #include "Rpc.h" #endif @@ -73,8 +73,8 @@ extern "C" int main() { InitPlatform(); -#if CONFIG_ENABLE_PW_RPC - chip::rpc::Init(); +#if PW_RPC_ENABLED + PigweedLogger::init(); #endif log_info("==================================================\r\n"); diff --git a/examples/lighting-app/bouffalolab/bl602/with_pw_rpc.gni b/examples/lighting-app/bouffalolab/bl602/with_pw_rpc.gni new file mode 100644 index 00000000000000..77eac0ca9deff3 --- /dev/null +++ b/examples/lighting-app/bouffalolab/bl602/with_pw_rpc.gni @@ -0,0 +1,28 @@ +# 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. + +# add this gni as import in your build args to use pigweed in the example +# 'import("//with_pw_rpc.gni")' + +import("//build_overrides/chip.gni") +import("//build_overrides/pigweed.gni") +import("${chip_root}/config/bouffalolab/bl602/lib/pw_rpc/pw_rpc.gni") +import("${chip_root}/examples/platform/bouffalolab/bl602/args.gni") + +chip_enable_pw_rpc = true +chip_enable_openthread = false +chip_build_pw_trace_lib = false + +cpp_standard = "gnu++17" +#pw_trace_BACKEND = "$dir_pw_trace_tokenized" diff --git a/examples/platform/bouffalolab/bl602/InitPlatform.cpp b/examples/platform/bouffalolab/bl602/InitPlatform.cpp index 1df65555ed1dfe..674c200b3be176 100644 --- a/examples/platform/bouffalolab/bl602/InitPlatform.cpp +++ b/examples/platform/bouffalolab/bl602/InitPlatform.cpp @@ -44,8 +44,83 @@ extern "C" { #include #include #include +#include #include +#define IOT_DVK_3S 1 + +#if BOARD_ID == IOT_DVK_3S +hosal_pwm_dev_t pwmR = { .port = 0xff }; +#else +hosal_pwm_dev_t pwmR, pwmG, pwmB; +#endif + +static void (*Button_FactoryResetEventHandler)(void) = nullptr; +static void (*Button_LightingActionEventHandler)(void) = nullptr; +void Button_Configure_FactoryResetEventHandler(void (*callback)(void)) +{ + Button_FactoryResetEventHandler = callback; +} + +void Button_Configure_LightingActionEventHandler(void (*callback)(void)) +{ + Button_LightingActionEventHandler = callback; +} + +static void Platform_Light_Init(void) +{ +#if BOARD_ID == IOT_DVK_3S + if (pwmR.port == 0xff) + { + pwmR.port = 0; + pwmR.config.pin = 0; + pwmR.config.duty_cycle = 0; // duty_cycle range is 0~10000 correspond to 0~100% + pwmR.config.freq = 1000; + hosal_pwm_init(&pwmR); + vTaskDelay(50); + hosal_pwm_start(&pwmR); + } +#else + pwmR.port = 0; + pwmR.config.pin = 20; + pwmR.config.duty_cycle = 0; // duty_cycle range is 0~10000 correspond to 0~100% + pwmR.config.freq = 1000; + hosal_pwm_init(&pwmR); + + pwmG.port = 1; + pwmG.config.pin = 21; + pwmG.config.duty_cycle = 0; // duty_cycle range is 0~10000 correspond to 0~100% + pwmG.config.freq = 1000; + hosal_pwm_init(&pwmG); + + pwmB.port = 2; + pwmB.config.pin = 17; + pwmB.config.duty_cycle = 0; // duty_cycle range is 0~10000 correspond to 0~100% + pwmB.config.freq = 1000; + hosal_pwm_init(&pwmB); + + vTaskDelay(50); + hosal_pwm_start(&pwmR); + hosal_pwm_start(&pwmG); + hosal_pwm_start(&pwmB); +#endif +} + +void BL602_LightState_Update(uint8_t red, uint8_t green, uint8_t blue) +{ +#if BOARD_ID == IOT_DVK_3S + uint32_t level = (red * 10000) / UINT8_MAX; + log_info("red level: %d\r\n", level); + hosal_pwm_duty_set(&pwmR, level); +#else + uint32_t r_level = (red * 10000) / UINT8_MAX; + uint32_t g_level = (green * 10000) / UINT8_MAX; + uint32_t b_level = (blue * 10000) / UINT8_MAX; + hosal_pwm_duty_set(&pwmR, r_level); + hosal_pwm_duty_set(&pwmG, g_level); + hosal_pwm_duty_set(&pwmB, b_level); +#endif +} void user_vAssertCalled(void) __attribute__((weak, alias("vAssertCalled"))); void vAssertCalled(void) { @@ -174,10 +249,10 @@ static void event_cb_key_event(input_event_t * event, void * private_data) log_info("[KEY_1] [EVT] INIT DONE %lld\r\n", aos_now_ms()); log_info("short press \r\n"); - log_info("factory reset. erasing easyflash...\r\n"); - ef_port_erase_all(); - log_info("factory reset. rebooting...\r\n"); - hal_reboot(); + if (Button_LightingActionEventHandler != nullptr) + { + (*Button_LightingActionEventHandler)(); + } } break; case KEY_2: { @@ -188,7 +263,10 @@ static void event_cb_key_event(input_event_t * event, void * private_data) case KEY_3: { log_info("[KEY_3] [EVT] INIT DONE %lld\r\n", aos_now_ms()); log_info("longlong press \r\n"); - // xTaskCreate(task_factory_reset, "factory-reset", 256, NULL, 10, NULL); + if (Button_FactoryResetEventHandler != nullptr) + { + (*Button_FactoryResetEventHandler)(); + } } break; default: { @@ -210,7 +288,7 @@ void InitPlatform(void) hal_gpio_init_from_dts(fdt, offset); fdt_button_module_init((const void *) fdt, (int) offset); } - + Platform_Light_Init(); aos_register_event_filter(EV_KEY, event_cb_key_event, NULL); } diff --git a/examples/platform/bouffalolab/bl602/InitPlatform.h b/examples/platform/bouffalolab/bl602/InitPlatform.h index c8300268216c5c..85d7d09f719dc5 100644 --- a/examples/platform/bouffalolab/bl602/InitPlatform.h +++ b/examples/platform/bouffalolab/bl602/InitPlatform.h @@ -27,6 +27,9 @@ extern "C" { #include void InitPlatform(void); +void Button_Configure_FactoryResetEventHandler(void (*callback)(void)); +void Button_Configure_LightingActionEventHandler(void (*callback)(void)); +void BL602_LightState_Update(uint8_t red, uint8_t green, uint8_t blue); #ifdef __cplusplus } diff --git a/examples/platform/bouffalolab/bl602/PigweedLogger.cpp b/examples/platform/bouffalolab/bl602/PigweedLogger.cpp index 5ab24767a47ab2..608e2ece55a27e 100644 --- a/examples/platform/bouffalolab/bl602/PigweedLogger.cpp +++ b/examples/platform/bouffalolab/bl602/PigweedLogger.cpp @@ -29,7 +29,7 @@ #include "semphr.h" #include #include -#include +#include #include "pw_span/span.h" #include diff --git a/examples/platform/bouffalolab/bl602/Rpc.cpp b/examples/platform/bouffalolab/bl602/Rpc.cpp new file mode 100644 index 00000000000000..0ff69e920b5ac1 --- /dev/null +++ b/examples/platform/bouffalolab/bl602/Rpc.cpp @@ -0,0 +1,229 @@ +/* + * + * Copyright (c) 2021 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 "AppTask.h" +#include "FreeRTOS.h" +#include "PigweedLoggerMutex.h" +#include "pigweed/RpcService.h" +#include "pw_sys_io_bl602/init.h" +#include "task.h" +extern "C" { +#include "bl_sys.h" +} +#if defined(PW_RPC_ATTRIBUTE_SERVICE) && PW_RPC_ATTRIBUTE_SERVICE +#include "pigweed/rpc_services/Attributes.h" +#endif // defined(PW_RPC_ATTRIBUTE_SERVICE) && PW_RPC_ATTRIBUTE_SERVICE + +#if defined(PW_RPC_BUTTON_SERVICE) && PW_RPC_BUTTON_SERVICE +#include "pigweed/rpc_services/Button.h" +#endif // defined(PW_RPC_BUTTON_SERVICE) && PW_RPC_BUTTON_SERVICE + +#if defined(PW_RPC_DESCRIPTOR_SERVICE) && PW_RPC_DESCRIPTOR_SERVICE +#include "pigweed/rpc_services/Descriptor.h" +#endif // defined(PW_RPC_DESCRIPTOR_SERVICE) && PW_RPC_DESCRIPTOR_SERVICE + +#if defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE +#include "pigweed/rpc_services/Device.h" +#endif // defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE + +#if defined(PW_RPC_LIGHTING_SERVICE) && PW_RPC_LIGHTING_SERVICE +#include "pigweed/rpc_services/Lighting.h" +#endif // defined(PW_RPC_LIGHTING_SERVICE) && PW_RPC_LIGHTING_SERVICE + +#if defined(PW_RPC_LOCKING_SERVICE) && PW_RPC_LOCKING_SERVICE +#include "pigweed/rpc_services/Locking.h" +#endif // defined(PW_RPC_LOCKING_SERVICE) && PW_RPC_LOCKING_SERVICE + +#if defined(PW_RPC_OTCLI_SERVICE) && PW_RPC_OTCLI_SERVICE +#include "pigweed/rpc_services/OtCli.h" +#endif // defined(PW_RPC_OTCLI_SERVICE) && PW_RPC_OTCLI_SERVICE + +#if defined(PW_RPC_THREAD_SERVICE) && PW_RPC_THREAD_SERVICE +#include "pigweed/rpc_services/Thread.h" +#endif // defined(PW_RPC_THREAD_SERVICE) && PW_RPC_THREAD_SERVICE + +#if defined(PW_RPC_TRACING_SERVICE) && PW_RPC_TRACING_SERVICE +#define PW_TRACE_BUFFER_SIZE_BYTES 1024 +#include "pw_trace/trace.h" +#include "pw_trace_tokenized/trace_rpc_service_nanopb.h" + +// Define trace time for pw_trace +PW_TRACE_TIME_TYPE pw_trace_GetTraceTime() +{ + return (PW_TRACE_TIME_TYPE) chip::System::SystemClock().GetMonotonicMicroseconds64().count(); +} +// Microsecond time source +size_t pw_trace_GetTraceTimeTicksPerSecond() +{ + return 1000000; +} + +#endif // defined(PW_RPC_TRACING_SERVICE) && PW_RPC_TRACING_SERVICE + +namespace chip { +namespace rpc { + +#if defined(PW_RPC_BUTTON_SERVICE) && PW_RPC_BUTTON_SERVICE +class BL602Button final : public Button +{ +public: + pw::Status Event(const chip_rpc_ButtonEvent & request, pw_protobuf_Empty & response) override + { + GetAppTask().ButtonEventHandler(request.idx, request.pushed); + return pw::OkStatus(); + } +}; +#endif // defined(PW_RPC_BUTTON_SERVICE) && PW_RPC_BUTTON_SERVICE + +#if defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE +class BL602Device final : public Device +{ +public: + pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override + { + if (!mRebootTimer) + { + mRebootTimer = + xTimerCreateStatic("Reboot", kRebootTimerPeriodTicks, false, nullptr, RebootHandler, &mRebootTimerBuffer); + xTimerStart(mRebootTimer, 0); + } + return pw::OkStatus(); + } + + pw::Status FactoryReset(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override + { + if (!mRebootTimer) + { + mRebootTimer = xTimerCreateStatic("FactoryReset", kRebootTimerPeriodTicks, false, nullptr, FactoryResetHandler, + &mRebootTimerBuffer); + xTimerStart(mRebootTimer, 0); + } + return pw::OkStatus(); + } + +private: + static constexpr TickType_t kRebootTimerPeriodTicks = 1000; + TimerHandle_t mRebootTimer; + StaticTimer_t mRebootTimerBuffer; + + static void RebootHandler(TimerHandle_t) { bl_sys_reset_system(); } + + static void FactoryResetHandler(TimerHandle_t) { DeviceLayer::ConfigurationMgr().InitiateFactoryReset(); } +}; +#endif // defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE + +namespace { + +#define RPC_TASK_STACK_SIZE 1536 +#define RPC_TASK_PRIORITY 1 +static TaskHandle_t sRpcTaskHandle; +StaticTask_t sRpcTaskBuffer; +StackType_t sRpcTaskStack[RPC_TASK_STACK_SIZE]; + +#if defined(PW_RPC_ATTRIBUTE_SERVICE) && PW_RPC_ATTRIBUTE_SERVICE +Attributes attributes_service; +#endif // defined(PW_RPC_ATTRIBUTE_SERVICE) && PW_RPC_ATTRIBUTE_SERVICE + +#if defined(PW_RPC_BUTTON_SERVICE) && PW_RPC_BUTTON_SERVICE +BL602Button button_service; +#endif // defined(PW_RPC_BUTTON_SERVICE) && PW_RPC_BUTTON_SERVICE + +#if defined(PW_RPC_DESCRIPTOR_SERVICE) && PW_RPC_DESCRIPTOR_SERVICE +Descriptor descriptor_service; +#endif // defined(PW_RPC_DESCRIPTOR_SERVICE) && PW_RPC_DESCRIPTOR_SERVICE + +#if defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE +BL602Device device_service; +#endif // defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE + +#if defined(PW_RPC_LIGHTING_SERVICE) && PW_RPC_LIGHTING_SERVICE +Lighting lighting_service; +#endif // defined(PW_RPC_LIGHTING_SERVICE) && PW_RPC_LIGHTING_SERVICE + +#if defined(PW_RPC_LOCKING_SERVICE) && PW_RPC_LOCKING_SERVICE +Locking locking; +#endif // defined(PW_RPC_LOCKING_SERVICE) && PW_RPC_LOCKING_SERVICE + +#if defined(PW_RPC_OTCLI_SERVICE) && PW_RPC_OTCLI_SERVICE +OtCli ot_cli_service; +#endif // defined(PW_RPC_OTCLI_SERVICE) && PW_RPC_OTCLI_SERVICE + +#if defined(PW_RPC_THREAD_SERVICE) && PW_RPC_THREAD_SERVICE +Thread thread; +#endif // defined(PW_RPC_THREAD_SERVICE) && PW_RPC_THREAD_SERVICE + +#if defined(PW_RPC_TRACING_SERVICE) && PW_RPC_TRACING_SERVICE +pw::trace::TraceService trace_service; +#endif // defined(PW_RPC_TRACING_SERVICE) && PW_RPC_TRACING_SERVICE + +void RegisterServices(pw::rpc::Server & server) +{ +#if defined(PW_RPC_ATTRIBUTE_SERVICE) && PW_RPC_ATTRIBUTE_SERVICE + server.RegisterService(attributes_service); +#endif // defined(PW_RPC_ATTRIBUTE_SERVICE) && PW_RPC_ATTRIBUTE_SERVICE + +#if defined(PW_RPC_BUTTON_SERVICE) && PW_RPC_BUTTON_SERVICE + server.RegisterService(button_service); +#endif // defined(PW_RPC_BUTTON_SERVICE) && PW_RPC_BUTTON_SERVICE + +#if defined(PW_RPC_DESCRIPTOR_SERVICE) && PW_RPC_DESCRIPTOR_SERVICE + server.RegisterService(descriptor_service); +#endif // defined(PW_RPC_DESCRIPTOR_SERVICE) && PW_RPC_DESCRIPTOR_SERVICE + +#if defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE + server.RegisterService(device_service); +#endif // defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE + +#if defined(PW_RPC_LIGHTING_SERVICE) && PW_RPC_LIGHTING_SERVICE + server.RegisterService(lighting_service); +#endif // defined(PW_RPC_LIGHTING_SERVICE) && PW_RPC_LIGHTING_SERVICE + +#if defined(PW_RPC_LOCKING_SERVICE) && PW_RPC_LOCKING_SERVICE + server.RegisterService(locking); +#endif // defined(PW_RPC_LOCKING_SERVICE) && PW_RPC_LOCKING_SERVICE + +#if defined(PW_RPC_OTCLI_SERVICE) && PW_RPC_OTCLI_SERVICE + server.RegisterService(ot_cli_service); +#endif // defined(PW_RPC_OTCLI_SERVICE) && PW_RPC_OTCLI_SERVICE + +#if defined(PW_RPC_THREAD_SERVICE) && PW_RPC_THREAD_SERVICE + server.RegisterService(thread); +#endif // defined(PW_RPC_THREAD_SERVICE) && PW_RPC_THREAD_SERVICE + +#if defined(PW_RPC_TRACING_SERVICE) && PW_RPC_TRACING_SERVICE + server.RegisterService(trace_service); + PW_TRACE_SET_ENABLED(true); +#endif // defined(PW_RPC_TRACING_SERVICE) && PW_RPC_TRACING_SERVICE +} + +} // namespace + +void RunRpcService(void *) +{ + Start(RegisterServices, &logger_mutex); +} + +void Init() +{ + // Start App task. + sRpcTaskHandle = xTaskCreateStatic(RunRpcService, "RPC_TASK", ArraySize(sRpcTaskStack), nullptr, RPC_TASK_PRIORITY, + sRpcTaskStack, &sRpcTaskBuffer); +} + +} // namespace rpc +} // namespace chip diff --git a/examples/platform/bouffalolab/bl602/Rpc.h b/examples/platform/bouffalolab/bl602/Rpc.h new file mode 100644 index 00000000000000..dcb25862a9cd1e --- /dev/null +++ b/examples/platform/bouffalolab/bl602/Rpc.h @@ -0,0 +1,30 @@ +/* + * + * Copyright (c) 2021 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 + +namespace chip { +namespace rpc { + +class LightingService; + +void Init(); +void RunRpcService(void *); + +} // namespace rpc +} // namespace chip diff --git a/examples/platform/bouffalolab/bl602/pw_sys_io/BUILD.gn b/examples/platform/bouffalolab/bl602/pw_sys_io/BUILD.gn index c7001f3271284c..6cea51cc6c4ef4 100644 --- a/examples/platform/bouffalolab/bl602/pw_sys_io/BUILD.gn +++ b/examples/platform/bouffalolab/bl602/pw_sys_io/BUILD.gn @@ -17,7 +17,7 @@ import("//build_overrides/pigweed.gni") import("$dir_pw_build/target_types.gni") -examples_plat_dir = "${chip_root}/examples/platform/bl602" +examples_plat_dir = "${chip_root}/examples/platform/bouffalolab/bl602" config("default_config") { include_dirs = [ "public" ] diff --git a/examples/platform/bouffalolab/bl602/pw_sys_io/public/pw_sys_io_efr32/init.h b/examples/platform/bouffalolab/bl602/pw_sys_io/public/pw_sys_io_bl602/init.h similarity index 100% rename from examples/platform/bouffalolab/bl602/pw_sys_io/public/pw_sys_io_efr32/init.h rename to examples/platform/bouffalolab/bl602/pw_sys_io/public/pw_sys_io_bl602/init.h diff --git a/examples/platform/bouffalolab/bl602/pw_sys_io/sys_io_efr32.cc b/examples/platform/bouffalolab/bl602/pw_sys_io/sys_io_bl602.cc similarity index 100% rename from examples/platform/bouffalolab/bl602/pw_sys_io/sys_io_efr32.cc rename to examples/platform/bouffalolab/bl602/pw_sys_io/sys_io_bl602.cc diff --git a/examples/platform/bouffalolab/bl602/uart.c b/examples/platform/bouffalolab/bl602/uart.c index d47ac3938ed177..25f483993d5845 100644 --- a/examples/platform/bouffalolab/bl602/uart.c +++ b/examples/platform/bouffalolab/bl602/uart.c @@ -16,292 +16,126 @@ * limitations under the License. */ #include "uart.h" -#include "AppConfig.h" -#include "assert.h" -#include "em_core.h" -#include "em_usart.h" -#include "hal-config.h" -#include "sl_uartdrv_usart_vcom_config.h" -#include "uartdrv.h" -#include +#include "hosal_uart.h" #include -#if !defined(MIN) -#define MIN(A, B) ((A) < (B) ? (A) : (B)) -#endif - -#define HELPER1(x) USART##x##_RX_IRQn -#define HELPER2(x) HELPER1(x) -#define USART_IRQ HELPER2(SL_UARTDRV_USART_VCOM_PERIPHERAL_NO) - -#define HELPER3(x) USART##x##_RX_IRQHandler -#define HELPER4(x) HELPER3(x) -#define USART_IRQHandler HELPER4(SL_UARTDRV_USART_VCOM_PERIPHERAL_NO) - -DEFINE_BUF_QUEUE(EMDRV_UARTDRV_MAX_CONCURRENT_RX_BUFS, sUartRxQueue); -DEFINE_BUF_QUEUE(EMDRV_UARTDRV_MAX_CONCURRENT_TX_BUFS, sUartTxQueue); - -typedef struct -{ - // The data buffer - uint8_t * pBuffer; - // The offset of the first item written to the list. - volatile uint16_t Head; - // The offset of the next item to be written to the list. - volatile uint16_t Tail; - // Maxium size of data that can be hold in buffer before overwriting - uint16_t MaxSize; -} Fifo_t; - -#define UART_CONSOLE_ERR -1 // Negative value in case of UART Console action failed. Triggers a failure for PW_RPC #define MAX_BUFFER_SIZE 256 -#define MAX_DMA_BUFFER_SIZE (MAX_BUFFER_SIZE / 2) -// In order to reduce the probability of data loss during the dmaFull callback handler we use -// two duplicate receive buffers so we can always have one "active" receive queue. -static uint8_t sRxDmaBuffer[MAX_DMA_BUFFER_SIZE]; -static uint8_t sRxDmaBuffer2[MAX_DMA_BUFFER_SIZE]; -static uint16_t lastCount; // Nb of bytes already processed from the active dmaBuffer -// Rx buffer for the receive Fifo -static uint8_t sRxFifoBuffer[MAX_BUFFER_SIZE]; -static Fifo_t sReceiveFifo; +extern hosal_uart_dev_t uart_stdio; -static UARTDRV_HandleData_t sUartHandleData; -static UARTDRV_Handle_t sUartHandle = &sUartHandleData; +typedef struct _uartFifo +{ + uint16_t head; + uint16_t tail; + uint8_t rxbuf[MAX_BUFFER_SIZE]; +} UartFifo_t; -static void UART_rx_callback(UARTDRV_Handle_t handle, Ecode_t transferStatus, uint8_t * data, UARTDRV_Count_t transferCount); +static UartFifo_t UartFifo_v; -static bool InitFifo(Fifo_t * fifo, uint8_t * pDataBuffer, uint16_t bufferSize) +static uint16_t availableDataSize() { - if (fifo == NULL || pDataBuffer == NULL) + if (UartFifo_v.tail >= UartFifo_v.head) { - return false; + return UartFifo_v.tail - UartFifo_v.head; + } + else + { + return MAX_BUFFER_SIZE - UartFifo_v.head + UartFifo_v.tail; } - - fifo->pBuffer = pDataBuffer; - fifo->MaxSize = bufferSize; - fifo->Tail = fifo->Head = 0; - - return true; } -/* - * @brief Get the amount of unprocessed bytes in the fifo buffer - * @param Ptr to the fifo - * @return Nb of "unread" bytes available in the fifo - */ -static uint16_t AvailableDataCount(Fifo_t * fifo) +static uint16_t readFromFifo(uint8_t * dstBuf, uint16_t NbBytesToRead) { - uint16_t size = 0; + uint16_t currentDataSize = availableDataSize(); + uint16_t sizeToRead = (NbBytesToRead >= currentDataSize) ? currentDataSize : NbBytesToRead; + uint16_t bytesBeforeWrap = MAX_BUFFER_SIZE - UartFifo_v.head; - // if equal there is no data return 0 directly - if (fifo->Tail != fifo->Head) + if (sizeToRead) { - // determine if a wrap around occurred to get the right data size available. - size = (fifo->Tail < fifo->Head) ? (fifo->MaxSize - fifo->Head + fifo->Tail) : (fifo->Tail - fifo->Head); - } + if (bytesBeforeWrap >= sizeToRead) + { + memcpy(dstBuf, UartFifo_v.rxbuf + UartFifo_v.head, sizeToRead); + } + else + { + memcpy(dstBuf, UartFifo_v.rxbuf + UartFifo_v.head, bytesBeforeWrap); + memcpy(dstBuf + bytesBeforeWrap, UartFifo_v.rxbuf, sizeToRead - bytesBeforeWrap); + } - return size; -} + UartFifo_v.head = (UartFifo_v.head + sizeToRead) % MAX_BUFFER_SIZE; + } -/* - * @brief Get the available space in the fifo buffer to insert new data - * @param Ptr to the fifo - * @return Nb of free bytes left in te buffer - */ -static uint16_t RemainingSpace(Fifo_t * fifo) -{ - return fifo->MaxSize - AvailableDataCount(fifo); + return sizeToRead; } -/* - * @brief Write data in the fifo as a circular buffer - * @param Ptr to the fifo, ptr of the data to write, nb of bytes to write - */ -static void WriteToFifo(Fifo_t * fifo, uint8_t * pDataToWrite, uint16_t SizeToWrite) +static void writeToFifo(uint8_t * buf, uint16_t NbBytesToWrite) { - assert(fifo); - assert(pDataToWrite); - assert(SizeToWrite <= fifo->MaxSize); + uint16_t currentCapacity = MAX_BUFFER_SIZE - availableDataSize(); - // Overwrite is not allowed - if (RemainingSpace(fifo) >= SizeToWrite) + if (currentCapacity >= NbBytesToWrite) { - uint16_t nBytesBeforWrap = (fifo->MaxSize - fifo->Tail); - if (SizeToWrite > nBytesBeforWrap) + uint16_t bytesBeforeWrap = MAX_BUFFER_SIZE - UartFifo_v.tail; + if (bytesBeforeWrap >= NbBytesToWrite) { - // The number of bytes to write is bigger than the remaining bytes - // in the buffer, we have to wrap around - memcpy(fifo->pBuffer + fifo->Tail, pDataToWrite, nBytesBeforWrap); - memcpy(fifo->pBuffer, pDataToWrite + nBytesBeforWrap, SizeToWrite - nBytesBeforWrap); + memcpy(UartFifo_v.rxbuf + UartFifo_v.tail, buf, NbBytesToWrite); } else { - memcpy(fifo->pBuffer + fifo->Tail, pDataToWrite, SizeToWrite); + memcpy(UartFifo_v.rxbuf + UartFifo_v.tail, buf, bytesBeforeWrap); + memcpy(UartFifo_v.rxbuf, buf + bytesBeforeWrap, NbBytesToWrite - bytesBeforeWrap); } - fifo->Tail = (fifo->Tail + SizeToWrite) % fifo->MaxSize; // increment tail with wraparound + UartFifo_v.tail = (UartFifo_v.tail + NbBytesToWrite) % MAX_BUFFER_SIZE; } } -/* - * @brief Write data in the fifo as a circular buffer - * @param Ptr to the fifo, ptr to contain the data to process, nb of bytes to pull from the fifo - * @return Nb of bytes that were retrieved. - */ -static uint8_t RetrieveFromFifo(Fifo_t * fifo, uint8_t * pData, uint16_t SizeToRead) +static int uartRxCallback(void * p_arg) { - assert(fifo); - assert(pData); - assert(SizeToRead <= fifo->MaxSize); - - uint16_t ReadSize = MIN(SizeToRead, AvailableDataCount(fifo)); - uint16_t nBytesBeforWrap = (fifo->MaxSize - fifo->Head); + uint8_t data_buf[32]; - if (ReadSize > nBytesBeforWrap) + int ret = hosal_uart_receive(&uart_stdio, data_buf, sizeof(data_buf)); + if (ret) { - memcpy(pData, fifo->pBuffer + fifo->Head, nBytesBeforWrap); - memcpy(pData + nBytesBeforWrap, fifo->pBuffer, ReadSize - nBytesBeforWrap); + writeToFifo(data_buf, ret); } - else - { - memcpy(pData, (fifo->pBuffer + fifo->Head), ReadSize); - } - - fifo->Head = (fifo->Head + ReadSize) % fifo->MaxSize; // increment tail with wraparound - return ReadSize; + return 0; } -/* - * @brief Init the the UART for serial communication, Start DMA reception - * and init Fifo to handle the received data from this uart - * - * @Note This UART is used for pigweed rpc - */ -void uartConsoleInit(void) +static int uartTxCallback(void * p_arg) { - UARTDRV_Init_t uartInit = { - .port = USART0, - .baudRate = HAL_SERIAL_APP_BAUD_RATE, -#if defined(_USART_ROUTELOC0_MASK) - .portLocationTx = BSP_SERIAL_APP_TX_LOC, - .portLocationRx = BSP_SERIAL_APP_RX_LOC, -#elif defined(_USART_ROUTE_MASK) -#error This configuration is not supported -#elif defined(_GPIO_USART_ROUTEEN_MASK) - .txPort = BSP_SERIAL_APP_TX_PORT, /* USART Tx port number */ - .rxPort = BSP_SERIAL_APP_RX_PORT, /* USART Rx port number */ - .txPin = BSP_SERIAL_APP_TX_PIN, /* USART Tx pin number */ - .rxPin = BSP_SERIAL_APP_RX_PIN, /* USART Rx pin number */ - .uartNum = 0, /* UART instance number */ -#endif -#if defined(USART_CTRL_MVDIS) - .mvdis = false, -#endif - .stopBits = (USART_Stopbits_TypeDef) USART_FRAME_STOPBITS_ONE, - .parity = (USART_Parity_TypeDef) USART_FRAME_PARITY_NONE, - .oversampling = (USART_OVS_TypeDef) USART_CTRL_OVS_X16, - .fcType = HAL_SERIAL_APP_FLOW_CONTROL, - .ctsPort = BSP_SERIAL_APP_CTS_PORT, - .ctsPin = BSP_SERIAL_APP_CTS_PIN, - .rtsPort = BSP_SERIAL_APP_RTS_PORT, - .rtsPin = BSP_SERIAL_APP_RTS_PIN, - .rxQueue = (UARTDRV_Buffer_FifoQueue_t *) &sUartRxQueue, - .txQueue = (UARTDRV_Buffer_FifoQueue_t *) &sUartTxQueue, -#if defined(_USART_ROUTELOC1_MASK) - .portLocationCts = BSP_SERIAL_APP_CTS_LOC, - .portLocationRts = BSP_SERIAL_APP_RTS_LOC, -#endif - }; + hosal_uart_ioctl(&uart_stdio, HOSAL_UART_TX_TRIGGER_OFF, NULL); - // Init a fifo for the data received on the uart - InitFifo(&sReceiveFifo, sRxFifoBuffer, MAX_BUFFER_SIZE); - - UARTDRV_InitUart(sUartHandle, &uartInit); - // Activate 2 dma queues to always have one active - UARTDRV_Receive(sUartHandle, sRxDmaBuffer, MAX_DMA_BUFFER_SIZE, UART_rx_callback); - UARTDRV_Receive(sUartHandle, sRxDmaBuffer2, MAX_DMA_BUFFER_SIZE, UART_rx_callback); - - // Enable USART0 interrupt to wake OT task when data arrives - NVIC_ClearPendingIRQ(USART_IRQ); - NVIC_EnableIRQ(USART_IRQ); - USART_IntEnable(SL_UARTDRV_USART_VCOM_PERIPHERAL, USART_IF_RXDATAV); + return 0; } -void USART_IRQHandler(void) -{ -#ifndef PW_RPC_ENABLED - otSysEventSignalPending(); -#endif -} - -/* - * @brief Callback triggered when a UARTDRV DMA buffer is full - */ -static void UART_rx_callback(UARTDRV_Handle_t handle, Ecode_t transferStatus, uint8_t * data, UARTDRV_Count_t transferCount) +void uartConsoleInit(void) { - (void) transferStatus; - - uint8_t writeSize = (transferCount - lastCount); - if (RemainingSpace(&sReceiveFifo) >= writeSize) - { - WriteToFifo(&sReceiveFifo, data + lastCount, writeSize); - lastCount = 0; - } + memset(&UartFifo_v, 0, offsetof(UartFifo_t, rxbuf)); - UARTDRV_Receive(sUartHandle, data, transferCount, UART_rx_callback); -#ifndef PW_RPC_ENABLED - otSysEventSignalPending(); -#endif + hosal_uart_finalize(&uart_stdio); + hosal_uart_init(&uart_stdio); + hosal_uart_callback_set(&uart_stdio, HOSAL_UART_RX_CALLBACK, uartRxCallback, NULL); + hosal_uart_callback_set(&uart_stdio, HOSAL_UART_TX_CALLBACK, uartTxCallback, NULL); + hosal_uart_ioctl(&uart_stdio, HOSAL_UART_MODE_SET, (void *) HOSAL_UART_MODE_INT); } -/* - * @brief Read the data available from the console Uart - * @param Buffer that contains the data to write, number bytes to write. - * @return Amount of bytes written or ERROR (-1) - */ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength) { if (Buf == NULL || BufLength < 1) { - return UART_CONSOLE_ERR; + return -1; } - // Use of ForceTransmit here. Transmit with DMA was causing errors with PW_RPC - // TODO Use DMA and find/fix what causes the issue with PW - if (UARTDRV_ForceTransmit(sUartHandle, (uint8_t *) Buf, BufLength) == ECODE_EMDRV_UARTDRV_OK) - { - return BufLength; - } - - return UART_CONSOLE_ERR; + return hosal_uart_send(&uart_stdio, Buf, BufLength); } -/* - * @brief Read the data available from the console Uart - * @param Buffer for the data to be read, number bytes to read. - * @return Amount of bytes that was read from the rx fifo or ERROR (-1) - */ int16_t uartConsoleRead(char * Buf, uint16_t NbBytesToRead) { - uint8_t * data; - UARTDRV_Count_t count, remaining; - if (Buf == NULL || NbBytesToRead < 1) { - return UART_CONSOLE_ERR; - } - - if (NbBytesToRead > AvailableDataCount(&sReceiveFifo)) - { - // Not enough data available in the fifo for the read size request - // If there is data available in dma buffer, get it now. - CORE_ATOMIC_SECTION(UARTDRV_GetReceiveStatus(sUartHandle, &data, &count, &remaining); if (count > lastCount) { - WriteToFifo(&sReceiveFifo, data + lastCount, count - lastCount); - lastCount = count; - }) + return -1; } - return (int16_t) RetrieveFromFifo(&sReceiveFifo, (uint8_t *) Buf, NbBytesToRead); + return readFromFifo(Buf, NbBytesToRead); } diff --git a/scripts/examples/gn_bl602_example.sh b/scripts/examples/gn_bl602_example.sh index 9b6d02b3927b3f..3bd72ca563fbcc 100755 --- a/scripts/examples/gn_bl602_example.sh +++ b/scripts/examples/gn_bl602_example.sh @@ -17,27 +17,37 @@ # set -e -# Build script for GN BL602 examples GitHub workflow. + +BL602_BOARD=BL-HWC-G1 + +# Build script for GN examples GitHub workflow. + +MATTER_ROOT=$(dirname "$0")/../../ + source "$(dirname "$0")/../../scripts/activate.sh" -set -x -env +USAGE="./scripts/examples/gn_bl602_example.sh example_dir output_dir" + +if [ $# -lt 2 ]; then + echo "Usage: $USAGE" + exit 1 +fi -# Build steps -EXAMPLE_DIR=$1 +EXAMPLE_DIR=examples/$1/bouffalolab/bl602/ +shift +OUTPUT_DIR=$1 shift -OUTPUT_DIR=out/example_app -BL602_BOARD=BL-HWC-G1 -MATTER_BL_ROOT=$PWD -export BL602_SDK_ROOT="$MATTER_BL_ROOT"/third_party/bouffalolab/bl602_sdk/repo -export PATH="$BL602_SDK_ROOT/toolchain/riscv/Linux/bin:$PATH" -if [[ ! -z "$1" ]]; then - OUTPUT_DIR=$1 - shift +export BL_IOT_SDK_PATH="$MATTER_ROOT"/third_party/bouffalolab/bl602_sdk/repo + +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + export PATH="$BL_IOT_SDK_PATH/toolchain/riscv/Linux/bin:$PATH" +elif [[ "$OSTYPE" == "darwin"* ]]; then + export PATH="$BL_IOT_SDK_PATH/toolchain/riscv/Darwin/bin:$PATH" fi GN_ARGS=() + NINJA_ARGS=() for arg; do @@ -58,6 +68,6 @@ for arg; do esac done -#gn clean out/lighting_app_bl602 -gn gen "$OUTPUT_DIR" --root="$EXAMPLE_DIR" --args="${GN_ARGS[*]}" +gn gen --fail-on-unused-args --root="$EXAMPLE_DIR" "$OUTPUT_DIR" --args="${GN_ARGS[*]}" + ninja -C "$OUTPUT_DIR" "${NINJA_ARGS[@]}" diff --git a/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp b/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp index 158dc51c057a7e..23c860a1a32d82 100644 --- a/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp +++ b/src/platform/bouffalolab/BL602/ConfigurationManagerImpl.cpp @@ -31,11 +31,9 @@ #include #include -//#include "esp_wifi.h" -//#include "nvs.h" -//#include "nvs_flash.h" extern "C" { #include +#include } namespace chip { @@ -177,24 +175,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) CHIP_ERROR err; ChipLogProgress(DeviceLayer, "Performing factory reset"); - - // 3R: TODO - - // // Erase all values in the chip-config NVS namespace. - // err = ClearNamespace(kConfigNamespace_ChipConfig); - // if (err != CHIP_NO_ERROR) - // { - // ChipLogError(DeviceLayer, "ClearNamespace(ChipConfig) failed: %s", chip::ErrorStr(err)); - // } - - // // Restore WiFi persistent settings to default values. - // err = esp_wifi_restore(); - // if (err != ESP_OK) - // { - // ChipLogError(DeviceLayer, "esp_wifi_restore() failed: %s", chip::ErrorStr(err)); - // } - - // Restart the system. + ef_port_erase_all(); ChipLogProgress(DeviceLayer, "System restarting"); hal_reboot(); } diff --git a/src/platform/bouffalolab/BL602/Logging.cpp b/src/platform/bouffalolab/BL602/Logging.cpp index 6ed1005826d9d2..872fd3c65ce1cf 100644 --- a/src/platform/bouffalolab/BL602/Logging.cpp +++ b/src/platform/bouffalolab/BL602/Logging.cpp @@ -16,6 +16,10 @@ extern "C" { #include } +#ifdef PW_RPC_ENABLED +#include "PigweedLogger.h" +#endif + namespace chip { namespace Logging { namespace Platform { @@ -23,6 +27,8 @@ namespace Platform { void LogV(const char * module, uint8_t category, const char * msg, va_list v) { char formattedMsg[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE]; + +#ifndef PW_RPC_ENABLED vsnprintf(formattedMsg, sizeof(formattedMsg), msg, v); switch (category) @@ -38,6 +44,32 @@ void LogV(const char * module, uint8_t category, const char * msg, va_list v) log_trace("[%s] %s\r\n", module, formattedMsg); break; } +#else + size_t prefixLen = 0; + + switch (category) + { + case kLogCategory_Error: + strcpy(formattedMsg, "[ERROR] "); + break; + case kLogCategory_Progress: + default: + strcpy(formattedMsg, "[INFO] "); + break; + case kLogCategory_Detail: + strcpy(formattedMsg, "[TRACE] "); + break; + } + + prefixLen = strlen(formattedMsg); + snprintf(formattedMsg + prefixLen, sizeof(formattedMsg) - prefixLen, "[%s] ", module); + prefixLen = strlen(formattedMsg); + vsnprintf(formattedMsg + prefixLen, sizeof(formattedMsg) - prefixLen, msg, v); + + PigweedLogger::putString(formattedMsg, strlen(formattedMsg)); + const char * newline = "\r\n"; + PigweedLogger::putString(newline, strlen(newline)); +#endif } } // namespace Platform diff --git a/third_party/bouffalolab/bl602_sdk/bl602_sdk.gni b/third_party/bouffalolab/bl602_sdk/bl602_sdk.gni index 510d4d21e18684..d240812d8106f4 100644 --- a/third_party/bouffalolab/bl602_sdk/bl602_sdk.gni +++ b/third_party/bouffalolab/bl602_sdk/bl602_sdk.gni @@ -157,6 +157,7 @@ template("bl602_sdk") { "SYS_BLOG_ENABLE=1", "SYS_VFS_ENABLE=1", "SYS_AOS_LOOP_ENABLE=1", + "BL602_USE_HAL_DRIVER=1", "BL602=BL602", "SYS_LOOPRT_ENABLE=1", "CFG_TXDESC=2", @@ -201,7 +202,6 @@ template("bl602_sdk") { "CONFIG_BT_SETTINGS_USE_PRINTK", "CFG_BLE_STACK_DBG_PRINT", - "CONFIG_ENABLE_PW_RPC=0", "__FILENAME__=__FILE__", "BL602_LOG_ENABLED=1",