Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telink] Update apps and configs & Update Telink image to 0.6.27 #24200

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
97e607d
[Telink] Rework flash partitions & use swap move algorithm
s07641069 Dec 14, 2022
a7640de
[Telink] Removed timer to BLE disconnect
serhiiSalamakha Dec 13, 2022
427039c
[Telink] Rework flash partitions & use swap move algorithm
s07641069 Dec 19, 2022
6d67236
[Telink] Use latest Telink mcuboot changes
s07641069 Dec 19, 2022
66e5a36
[Telink] Enable reboot system when fault happened
s07641069 Dec 19, 2022
99b433f
[Telink] Rework system status LED loop and made the Factory-Reset But…
serhiiSalamakha Dec 20, 2022
3dd66a5
[Telink] Reworked system status LED loop and made the Factory-Reset B…
serhiiSalamakha Dec 20, 2022
9b8ccd7
Merge branch 'telink_improve_ble_thread_switching' into telink_flash_…
s07641069 Dec 20, 2022
a42f52e
[Telink] Revert submodule change
s07641069 Dec 20, 2022
fde3529
[Telink] Added last changes also to the Thermostat example
serhiiSalamakha Dec 20, 2022
76a7282
[Telink] Restyled
s07641069 Dec 20, 2022
bacc0da
[Telink] Add contact sensor app example
s07641069 Dec 20, 2022
b74fc0d
[Telink] Add new target for CI
s07641069 Dec 20, 2022
c2b5131
Merge branch 'telink_contact_sensor_app' into telink_flash_optimizati…
s07641069 Dec 21, 2022
274ba8a
[Telink] Fix device re-pairing
andriy-bilynskyy Dec 21, 2022
17361b0
Merge branch 'master' into telink_flash_optimization_and_use_swap_move
s07641069 Dec 22, 2022
829efd3
[Telink] Enable NVS lookup cache
s07641069 Dec 23, 2022
6df90e7
[Telink] Update every image to 0.6.27
s07641069 Dec 23, 2022
95ed283
Merge branch 'master' into telink_flash_optimization_and_use_swap_move
s07641069 Dec 23, 2022
03ba586
[Telink] Ordered by alphabet targets
s07641069 Dec 23, 2022
78cd399
Merge branch 'master' into telink_flash_optimization_and_use_swap_move
s07641069 Jan 4, 2023
1a7e4c2
Merge branch 'master' into telink_flash_optimization_and_use_swap_move
s07641069 Jan 4, 2023
52535b0
[Telink] Fix example name
s07641069 Jan 4, 2023
b0d8fff
Revert "[Telink] Update every image to 0.6.27"
s07641069 Jan 5, 2023
5376082
[Telink] Update Telink image to 0.6.27
s07641069 Jan 5, 2023
3504b43
Merge branch 'master' into telink_flash_optimization_and_use_swap_move
s07641069 Jan 5, 2023
fffc597
Merge branch 'master' into telink_flash_optimization_and_use_swap_move
s07641069 Jan 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
s07641069 marked this conversation as resolved.
Show resolved Hide resolved
}
}
};

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