Skip to content

Commit

Permalink
[Telink] Update apps and configs & Update Telink image to 0.6.27 (#24200
Browse files Browse the repository at this point in the history
)

* [Telink] Rework flash partitions & use swap move algorithm

* [Telink] Removed timer to BLE disconnect

* [Telink] Rework flash partitions & use swap move algorithm

* [Telink] Use latest Telink mcuboot changes

* [Telink] Enable reboot system when fault happened

* [Telink] Rework system status LED loop and made the Factory-Reset Button more user friendly

* [Telink] Revert submodule change

* [Telink] Added last changes also to the Thermostat example

* [Telink] Restyled

* [Telink] Add contact sensor app example

* [Telink] Add new target for CI

* [Telink] Fix device re-pairing

* [Telink] Enable NVS lookup cache

* [Telink] Update every image to 0.6.27

* [Telink] Ordered by alphabet targets

* [Telink] Fix example name

* Revert "[Telink] Update every image to 0.6.27"

This reverts commit 6df90e7.

* [Telink] Update Telink image to 0.6.27

Co-authored-by: Serhii Salamakha <serhii.salamakha@gmail.com>
Co-authored-by: Andrii Bilynskyi <andrii.bilynskyi@telink-semi.com>
  • Loading branch information
3 people authored and pull[bot] committed Dec 15, 2023
1 parent 2e1ffbe commit 2436705
Show file tree
Hide file tree
Showing 47 changed files with 2,055 additions and 167 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/examples-telink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ jobs:
if: github.actor != 'restyled-io[bot]'

container:
# TODO: update this to connectedhomeip/chip-build-vscode:0.6.27 once we can compile
image: connectedhomeip/chip-build-telink:0.6.18
image: connectedhomeip/chip-build-telink:0.6.27
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"

Expand Down Expand Up @@ -76,6 +75,15 @@ jobs:
out/telink-tlsr9518adk80d-all-clusters-minimal/zephyr/zephyr.elf \
/tmp/bloat_reports/
- name: Build example Telink Contact Sensor App
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py --target 'telink-tlsr9518adk80d-contact-sensor' build"
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
telink tlsr9518adk80d contact-sensor-app \
out/telink-tlsr9518adk80d-contact-sensor/zephyr/zephyr.elf \
/tmp/bloat_reports/
- name: Build example Telink Lighting App
run: |
./scripts/run_in_build_env.sh \
Expand Down
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@
"qpg-qpg6100-lock",
"telink-tlsr9518adk80d-all-clusters",
"telink-tlsr9518adk80d-all-clusters-minimal",
"telink-tlsr9518adk80d-contact-sensor",
"telink-tlsr9518adk80d-light",
"telink-tlsr9518adk80d-light-switch",
"telink-tlsr9518adk80d-ota-requestor",
Expand Down
6 changes: 6 additions & 0 deletions config/telink/app/zephyr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ CONFIG_DYNAMIC_INTERRUPTS=y
# nvs_sector_size = flash_page_size * mult = 256 * 8 = 2048
CONFIG_SETTINGS_NVS_SECTOR_SIZE_MULT=8

# Enable NVS lookup cache
CONFIG_NVS_LOOKUP_CACHE=y

# Reboot system when fault happened
CONFIG_TELINK_B91_REBOOT_ON_FAULT=y

# Shell settings
CONFIG_SHELL=n
CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE=255
Expand Down
18 changes: 5 additions & 13 deletions config/telink/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,37 +297,29 @@ add_dependencies(chip chip-gn)
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
add_custom_target(build_mcuboot ALL
COMMAND
west build -b tlsr9518adk80d -d build_mcuboot ${ZEPHYR_BASE}/../bootloader/mcuboot/boot/zephyr
)

add_custom_target(west_sign ALL
COMMAND
west sign -t imgtool -p ${ZEPHYR_BASE}/../bootloader/mcuboot/scripts/imgtool.py -d ${PROJECT_BINARY_DIR}/.. -- --key ${ZEPHYR_BASE}/../bootloader/mcuboot/root-rsa-2048.pem
BYPRODUCTS
${PROJECT_BINARY_DIR}/zephyr.signed.bin
west build -b tlsr9518adk80d -d build_mcuboot ${ZEPHYR_BASE}/../bootloader/mcuboot/boot/zephyr -- -DCONFIG_BOOT_SWAP_USING_MOVE=y
)

add_custom_target(merge_mcuboot ALL
COMMAND
dd if=${PROJECT_BINARY_DIR}/../modules/chip-module/build_mcuboot/zephyr/zephyr.bin of=${PROJECT_BINARY_DIR}/zephyr.bin
COMMAND
dd if=${PROJECT_BINARY_DIR}/zephyr.signed.bin of=${PROJECT_BINARY_DIR}/zephyr.bin bs=1024 seek=96
dd if=${PROJECT_BINARY_DIR}/zephyr.signed.bin of=${PROJECT_BINARY_DIR}/zephyr.bin bs=1024 seek=76
)

chip_ota_image(chip-ota-image
INPUT_FILES ${PROJECT_BINARY_DIR}/zephyr.signed.bin
OUTPUT_FILE ${PROJECT_BINARY_DIR}/zephyr-ota.bin
)

add_dependencies(west_sign ${ZEPHYR_FINAL_EXECUTABLE})
add_dependencies(merge_mcuboot west_sign)
add_dependencies(chip-ota-image west_sign)
add_dependencies(merge_mcuboot ${ZEPHYR_FINAL_EXECUTABLE})
add_dependencies(chip-ota-image ${ZEPHYR_FINAL_EXECUTABLE})
endif()

if (CONFIG_CHIP_FACTORY_DATA_MERGE_WITH_FIRMWARE)
add_custom_target(merge_factory_data ALL
COMMAND
dd if=${PROJECT_BINARY_DIR}/factory/factory_data.bin of=${PROJECT_BINARY_DIR}/zephyr.bin bs=1024 seek=2000
dd if=${PROJECT_BINARY_DIR}/factory/factory_data.bin of=${PROJECT_BINARY_DIR}/zephyr.bin bs=1024 seek=1040
)
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
add_dependencies(merge_factory_data merge_mcuboot)
Expand Down
12 changes: 12 additions & 0 deletions examples/all-clusters-app/telink/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
struct AppEvent;
typedef void (*EventHandler)(AppEvent *);

class LEDWidget;

struct AppEvent
{
enum AppEventTypes
{
kEventType_Button = 0,
kEventType_Timer,
kEventType_UpdateLedState,
};

uint16_t Type;
Expand All @@ -38,6 +42,14 @@ struct AppEvent
{
uint8_t Action;
} ButtonEvent;
struct
{
void * Context;
} TimerEvent;
struct
{
LEDWidget * LedWidget;
} UpdateLedStateEvent;
};

EventHandler Handler;
Expand Down
6 changes: 6 additions & 0 deletions examples/all-clusters-app/telink/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include "AppEvent.h"
#include "LEDWidget.h"

#include <zephyr/drivers/gpio.h>

Expand All @@ -43,15 +44,20 @@ class AppTask
void DispatchEvent(AppEvent * event);

static void UpdateStatusLED();
static void LEDStateUpdateHandler(LEDWidget * ledWidget);
static void FactoryResetButtonEventHandler(void);
static void StartThreadButtonEventHandler(void);
static void StartBleAdvButtonEventHandler(void);

static void ChipEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);

static void FactoryResetTimerTimeoutCallback(k_timer * timer);

static void FactoryResetTimerEventHandler(AppEvent * aEvent);
static void FactoryResetHandler(AppEvent * aEvent);
static void StartThreadHandler(AppEvent * aEvent);
static void StartBleAdvHandler(AppEvent * aEvent);
static void UpdateLedStateEventHandler(AppEvent * aEvent);

static void InitButtons(void);

Expand Down
104 changes: 88 additions & 16 deletions examples/all-clusters-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "AppConfig.h"
#include "AppEvent.h"
#include "ButtonManager.h"
#include "LEDWidget.h"
#include "binding-handler.h"
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
Expand All @@ -48,23 +47,25 @@
LOG_MODULE_DECLARE(app);

namespace {

constexpr int kAppEventQueueSize = 10;
constexpr uint8_t kButtonPushEvent = 1;
constexpr uint8_t kButtonReleaseEvent = 0;
constexpr int kFactoryResetTriggerTimeout = 2000;
constexpr int kAppEventQueueSize = 10;
constexpr uint8_t kButtonPushEvent = 1;
constexpr uint8_t kButtonReleaseEvent = 0;

K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), kAppEventQueueSize, alignof(AppEvent));
k_timer sFactoryResetTimer;

LEDWidget sStatusLED;

Button sFactoryResetButton;
Button sThreadStartButton;
Button sBleAdvStartButton;

bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sIsThreadAttached = false;
bool sHaveBLEConnections = false;
bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sIsThreadAttached = false;
bool sHaveBLEConnections = false;
bool sIsFactoryResetTimerActive = false;

chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;

Expand Down Expand Up @@ -108,6 +109,17 @@ using namespace ::chip::DeviceLayer::Internal;

AppTask AppTask::sAppTask;

class AppFabricTableDelegate : public FabricTable::Delegate
{
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex)
{
if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0)
{
chip::Server::GetInstance().ScheduleFactoryReset();
}
}
};

constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

CHIP_ERROR AppTask::Init()
Expand All @@ -118,12 +130,17 @@ CHIP_ERROR AppTask::Init()

// Initialize status LED
LEDWidget::InitGpio(SYSTEM_STATE_LED_PORT);
LEDWidget::SetStateUpdateCallback(LEDStateUpdateHandler);
sStatusLED.Init(SYSTEM_STATE_LED_PIN);

UpdateStatusLED();

InitButtons();

// Initialize function button timer
k_timer_init(&sFactoryResetTimer, &AppTask::FactoryResetTimerTimeoutCallback, nullptr);
k_timer_user_data_set(&sFactoryResetTimer, this);

// Init ZCL Data Model and start server
static chip::CommonCaseDeviceServerInitParams initParams;
(void) initParams.InitializeStaticResourcesBeforeServerInit();
Expand Down Expand Up @@ -168,6 +185,13 @@ CHIP_ERROR AppTask::Init()
return ret;
}

ret = chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(new AppFabricTableDelegate);
if (ret != CHIP_NO_ERROR)
{
LOG_ERR("AppFabricTableDelegate fail");
return ret;
}

return CHIP_NO_ERROR;
}

Expand All @@ -192,8 +216,6 @@ CHIP_ERROR AppTask::StartApp()
DispatchEvent(&event);
ret = k_msgq_get(&sAppEventQueue, &event, K_NO_WAIT);
}

sStatusLED.Animate();
}
}

Expand All @@ -209,8 +231,16 @@ void AppTask::FactoryResetButtonEventHandler(void)

void AppTask::FactoryResetHandler(AppEvent * aEvent)
{
LOG_INF("FactoryResetHandler");
chip::Server::GetInstance().ScheduleFactoryReset();
if (!sIsFactoryResetTimerActive)
{
k_timer_start(&sFactoryResetTimer, K_MSEC(kFactoryResetTriggerTimeout), K_NO_WAIT);
sIsFactoryResetTimerActive = true;
}
else
{
k_timer_stop(&sFactoryResetTimer);
sIsFactoryResetTimerActive = false;
}
}

void AppTask::StartThreadButtonEventHandler(void)
Expand Down Expand Up @@ -272,6 +302,23 @@ void AppTask::StartBleAdvHandler(AppEvent * aEvent)
}
}

void AppTask::UpdateLedStateEventHandler(AppEvent * aEvent)
{
if (aEvent->Type == AppEvent::kEventType_UpdateLedState)
{
aEvent->UpdateLedStateEvent.LedWidget->UpdateState();
}
}

void AppTask::LEDStateUpdateHandler(LEDWidget * ledWidget)
{
AppEvent event;
event.Type = AppEvent::kEventType_UpdateLedState;
event.Handler = UpdateLedStateEventHandler;
event.UpdateLedStateEvent.LedWidget = ledWidget;
sAppTask.PostEvent(&event);
}

void AppTask::UpdateStatusLED()
{
if (sIsThreadProvisioned && sIsThreadEnabled)
Expand Down Expand Up @@ -342,11 +389,36 @@ void AppTask::DispatchEvent(AppEvent * aEvent)
}
}

void AppTask::FactoryResetTimerTimeoutCallback(k_timer * timer)
{
if (!timer)
{
return;
}

AppEvent event;
event.Type = AppEvent::kEventType_Timer;
event.Handler = FactoryResetTimerEventHandler;
sAppTask.PostEvent(&event);
}

void AppTask::FactoryResetTimerEventHandler(AppEvent * aEvent)
{
if (aEvent->Type != AppEvent::kEventType_Timer)
{
return;
}

sIsFactoryResetTimerActive = false;
LOG_INF("FactoryResetHandler");
chip::Server::GetInstance().ScheduleFactoryReset();
}

void AppTask::InitButtons(void)
{
sFactoryResetButton.Configure(BUTTON_PORT, BUTTON_PIN_3, BUTTON_PIN_1, FactoryResetButtonEventHandler);
sThreadStartButton.Configure(BUTTON_PORT, BUTTON_PIN_3, BUTTON_PIN_2, StartThreadButtonEventHandler);
sBleAdvStartButton.Configure(BUTTON_PORT, BUTTON_PIN_4, BUTTON_PIN_2, StartBleAdvButtonEventHandler);
sFactoryResetButton.Configure(BUTTON_PORT, BUTTON_PIN_3, BUTTON_PIN_1, true, FactoryResetButtonEventHandler);
sThreadStartButton.Configure(BUTTON_PORT, BUTTON_PIN_3, BUTTON_PIN_2, false, StartThreadButtonEventHandler);
sBleAdvStartButton.Configure(BUTTON_PORT, BUTTON_PIN_4, BUTTON_PIN_2, false, StartBleAdvButtonEventHandler);

ButtonManagerInst().AddButton(sFactoryResetButton);
ButtonManagerInst().AddButton(sThreadStartButton);
Expand Down
12 changes: 12 additions & 0 deletions examples/all-clusters-minimal-app/telink/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
struct AppEvent;
typedef void (*EventHandler)(AppEvent *);

class LEDWidget;

struct AppEvent
{
enum AppEventTypes
{
kEventType_Button = 0,
kEventType_Timer,
kEventType_UpdateLedState,
};

uint16_t Type;
Expand All @@ -38,6 +42,14 @@ struct AppEvent
{
uint8_t Action;
} ButtonEvent;
struct
{
void * Context;
} TimerEvent;
struct
{
LEDWidget * LedWidget;
} UpdateLedStateEvent;
};

EventHandler Handler;
Expand Down
6 changes: 6 additions & 0 deletions examples/all-clusters-minimal-app/telink/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include "AppEvent.h"
#include "LEDWidget.h"

#include <zephyr/drivers/gpio.h>

Expand All @@ -43,13 +44,18 @@ class AppTask
void DispatchEvent(AppEvent * event);

static void UpdateStatusLED();
static void LEDStateUpdateHandler(LEDWidget * ledWidget);
static void FactoryResetButtonEventHandler(void);
static void StartBleAdvButtonEventHandler(void);

static void ChipEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);

static void FactoryResetTimerTimeoutCallback(k_timer * timer);

static void FactoryResetTimerEventHandler(AppEvent * aEvent);
static void FactoryResetHandler(AppEvent * aEvent);
static void StartBleAdvHandler(AppEvent * aEvent);
static void UpdateLedStateEventHandler(AppEvent * aEvent);

static void InitButtons(void);

Expand Down
Loading

0 comments on commit 2436705

Please sign in to comment.