Skip to content

Commit

Permalink
[BL602]1. add the support of pw_rpc; 2. enable buttons on dev board t…
Browse files Browse the repository at this point in the history
…o 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
  • Loading branch information
stoneM2017 authored and pull[bot] committed Sep 29, 2023
1 parent 482469b commit 1662476
Show file tree
Hide file tree
Showing 28 changed files with 807 additions and 416 deletions.
2 changes: 1 addition & 1 deletion config/bouffalolab/bl602/lib/pw_rpc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions config/bouffalolab/bl602/lib/pw_rpc/pw_rpc.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
27 changes: 27 additions & 0 deletions examples/common/pigweed/bouffalolab/bl602/PigweedLoggerMutex.cpp
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions examples/common/pigweed/bouffalolab/bl602/PigweedLoggerMutex.h
Original file line number Diff line number Diff line change
@@ -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 <FreeRTOS.h>

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
62 changes: 62 additions & 0 deletions examples/lighting-app/bouffalolab/bl602/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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") {
Expand All @@ -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",
Expand All @@ -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" ]
Expand Down
23 changes: 23 additions & 0 deletions examples/lighting-app/bouffalolab/bl602/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)`
4 changes: 3 additions & 1 deletion examples/lighting-app/bouffalolab/bl602/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 2 additions & 3 deletions examples/lighting-app/bouffalolab/bl602/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion examples/lighting-app/bouffalolab/bl602/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions examples/lighting-app/bouffalolab/bl602/include/LEDWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -62,7 +64,7 @@ class LEDWidget
bool mError;
TimerHandle_t errorTimer;

void DoSet(bool state);
void DoSet();

friend void ClearErrorState(TimerHandle_t);
};
Loading

0 comments on commit 1662476

Please sign in to comment.