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 Lock App and flash overlay #30745

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions config/telink/chip-module/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ config NVS_LOOKUP_CACHE_SIZE
config SETTINGS_NVS_SECTOR_SIZE_MULT
default 1

# Set sector counter of NVS
config SETTINGS_NVS_SECTOR_COUNT
default 10

# Enable OpenThread

config NET_L2_OPENTHREAD
Expand Down
5 changes: 3 additions & 2 deletions examples/lock-app/telink/include/LockSettingsStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <../Zephyr/ZephyrConfig.h>
#include <AppConfig.h>
#include <LockManager.h>

#if LOCK_MANAGER_CONFIG_USE_NVM_CREDENTIAL_STORAGE
namespace chip {
Expand All @@ -28,13 +29,13 @@ class LockSettingsStorage : ZephyrConfig
{
public:
static const ZephyrConfig::Key kConfigKey_LockUser;
static const ZephyrConfig::Key kConfigKey_Credential;
static const ZephyrConfig::Key kConfigKey_LockUserName;
static const ZephyrConfig::Key kConfigKey_CredentialData;
static const ZephyrConfig::Key kConfigKey_UserCredentials;
static const ZephyrConfig::Key kConfigKey_WeekDaySchedules;
static const ZephyrConfig::Key kConfigKey_YearDaySchedules;
static const ZephyrConfig::Key kConfigKey_HolidaySchedules;
static const char * kConfigKey_Credential[kNumCredentialTypes];
static const char * kConfigKey_CredentialData[kNumCredentialTypes];
};
} // namespace Internal
} // namespace DeviceLayer
Expand Down
36 changes: 25 additions & 11 deletions examples/lock-app/telink/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ bool LockManager::LockAction(int32_t appSource, Action_t aAction, OperationSourc
}
else
{
status = true;
LOG_INF("Lock Action: Lock is already locked. No action performed");
}
break;
Expand Down Expand Up @@ -181,6 +182,7 @@ bool LockManager::LockAction(int32_t appSource, Action_t aAction, OperationSourc
}
else
{
status = true;
LOG_INF("Unlock Action: Lock is already unlocked. no action performed");
}
break;
Expand All @@ -205,6 +207,7 @@ bool LockManager::LockAction(int32_t appSource, Action_t aAction, OperationSourc
}
else
{
status = true;
LOG_INF("Unbolt Action: Lock is already in unbolt state. no action performed");
}
break;
Expand Down Expand Up @@ -244,6 +247,7 @@ bool LockManager::LockAction(int32_t appSource, Action_t aAction, OperationSourc
}
else
{
status = true;
LOG_INF("Lock Action: Lock is already locked. No action performed");
}
break;
Expand Down Expand Up @@ -302,6 +306,7 @@ bool LockManager::LockAction(int32_t appSource, Action_t aAction, OperationSourc
}
else
{
status = true;
LOG_INF("Unlock Action: Lock is already unlocked. no action performed");
}
break;
Expand All @@ -325,6 +330,7 @@ bool LockManager::LockAction(int32_t appSource, Action_t aAction, OperationSourc
}
else
{
status = true;
LOG_INF("Unbolt Action: Lock is already in unbolt state. no action performed");
}
break;
Expand Down Expand Up @@ -426,15 +432,9 @@ bool LockManager::ReadConfigValues()
ZephyrConfig::ReadConfigValueBin(LockSettingsStorage::kConfigKey_LockUser, reinterpret_cast<uint8_t *>(&mLockUsers),
sizeof(EmberAfPluginDoorLockUserInfo) * ArraySize(mLockUsers), outLen);

ZephyrConfig::ReadConfigValueBin(LockSettingsStorage::kConfigKey_Credential, reinterpret_cast<uint8_t *>(&mLockCredentials),
sizeof(EmberAfPluginDoorLockCredentialInfo) * kMaxCredentials * kNumCredentialTypes, outLen);

ZephyrConfig::ReadConfigValueBin(LockSettingsStorage::kConfigKey_LockUserName, reinterpret_cast<uint8_t *>(mUserNames),
sizeof(mUserNames), outLen);

ZephyrConfig::ReadConfigValueBin(LockSettingsStorage::kConfigKey_CredentialData, reinterpret_cast<uint8_t *>(mCredentialData),
sizeof(mCredentialData), outLen);

ZephyrConfig::ReadConfigValueBin(LockSettingsStorage::kConfigKey_UserCredentials, reinterpret_cast<uint8_t *>(mCredentials),
sizeof(CredentialStruct) * LockParams.numberOfUsers * LockParams.numberOfCredentialsPerUser,
outLen);
Expand All @@ -453,6 +453,17 @@ bool LockManager::ReadConfigValues()
reinterpret_cast<uint8_t *>(&(mHolidaySchedule)),
sizeof(EmberAfPluginDoorLockHolidaySchedule) * LockParams.numberOfHolidaySchedules, outLen);

for (uint8_t i = 0; i < kNumCredentialTypes; i++)
{
ZephyrConfig::ReadConfigValueBin(LockSettingsStorage::kConfigKey_Credential[i],
reinterpret_cast<uint8_t *>(&mLockCredentials[i]),
sizeof(EmberAfPluginDoorLockCredentialInfo) * kMaxCredentials, outLen);

ZephyrConfig::ReadConfigValueBin(LockSettingsStorage::kConfigKey_CredentialData[i],
reinterpret_cast<uint8_t *>(mCredentialData[i]), kMaxCredentials * kMaxCredentialSize,
outLen);
}

return true;
}
#endif
Expand Down Expand Up @@ -654,16 +665,19 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential
chip::ByteSpan{ mCredentialData[to_underlying(credentialType)][credentialIndex], credentialData.size() };

#if LOCK_MANAGER_CONFIG_USE_NVM_CREDENTIAL_STORAGE
CHIP_ERROR err;

// Save credential information in NVM flash
CHIP_ERROR err = ZephyrConfig::WriteConfigValueBin(
LockSettingsStorage::kConfigKey_Credential, reinterpret_cast<const uint8_t *>(&mLockCredentials),
sizeof(EmberAfPluginDoorLockCredentialInfo) * kMaxCredentials * kNumCredentialTypes);
err = ZephyrConfig::WriteConfigValueBin(LockSettingsStorage::kConfigKey_Credential[to_underlying(credentialType)],
reinterpret_cast<const uint8_t *>(&mLockCredentials[to_underlying(credentialType)]),
sizeof(EmberAfPluginDoorLockCredentialInfo) * kMaxCredentials);
if (err != CHIP_NO_ERROR)
ChipLogError(
Zcl, "Failed to write kConfigKey_Credential. User data will be resetted during reboot. Not enough storage space \n");

err = ZephyrConfig::WriteConfigValueBin(LockSettingsStorage::kConfigKey_CredentialData,
reinterpret_cast<const uint8_t *>(&mCredentialData), sizeof(mCredentialData));
err = ZephyrConfig::WriteConfigValueBin(LockSettingsStorage::kConfigKey_CredentialData[to_underlying(credentialType)],
reinterpret_cast<const uint8_t *>(&mCredentialData[to_underlying(credentialType)]),
kMaxCredentials * kMaxCredentialSize);
if (err != CHIP_NO_ERROR)
ChipLogError(
Zcl,
Expand Down
26 changes: 18 additions & 8 deletions examples/lock-app/telink/src/LockSettingsStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,26 @@ namespace Internal {
(key); \
static_assert(sizeof(key) <= SETTINGS_MAX_NAME_LEN, "Config key too long: " key)

#define CONFIG_KEY_CREDENTIAL(type) (NAMESPACE_CONFIG "credential-" type)
#define CONFIG_KEY_CREDENTIAL_DATA(type) (NAMESPACE_CONFIG "credential-" type "-data")

#define NAMESPACE_CONFIG CHIP_DEVICE_CONFIG_SETTINGS_KEY "/cfg/"

const ZephyrConfig::Key LockSettingsStorage::kConfigKey_LockUser = CONFIG_KEY(NAMESPACE_CONFIG "lock-user");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_Credential = CONFIG_KEY(NAMESPACE_CONFIG "credential");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_LockUserName = CONFIG_KEY(NAMESPACE_CONFIG "lock-user-name");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_CredentialData = CONFIG_KEY(NAMESPACE_CONFIG "credential-data");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_UserCredentials = CONFIG_KEY(NAMESPACE_CONFIG "user-credentials");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_WeekDaySchedules = CONFIG_KEY(NAMESPACE_CONFIG "week-day-schedules");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_YearDaySchedules = CONFIG_KEY(NAMESPACE_CONFIG "year-day-schedules");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_HolidaySchedules = CONFIG_KEY(NAMESPACE_CONFIG "holiday-schedules");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_LockUser = CONFIG_KEY(NAMESPACE_CONFIG "lock-user");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_LockUserName = CONFIG_KEY(NAMESPACE_CONFIG "lock-user-name");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_UserCredentials = CONFIG_KEY(NAMESPACE_CONFIG "user-credentials");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_WeekDaySchedules = CONFIG_KEY(NAMESPACE_CONFIG "week-day-schedules");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_YearDaySchedules = CONFIG_KEY(NAMESPACE_CONFIG "year-day-schedules");
const ZephyrConfig::Key LockSettingsStorage::kConfigKey_HolidaySchedules = CONFIG_KEY(NAMESPACE_CONFIG "holiday-schedules");
const char * LockSettingsStorage::kConfigKey_Credential[kNumCredentialTypes] = {
CONFIG_KEY_CREDENTIAL("programming-pin"), CONFIG_KEY_CREDENTIAL("pin"), CONFIG_KEY_CREDENTIAL("rfid"),
CONFIG_KEY_CREDENTIAL("finger-print"), CONFIG_KEY_CREDENTIAL("finger-vein"), CONFIG_KEY_CREDENTIAL("face")
};
const char * LockSettingsStorage::kConfigKey_CredentialData[kNumCredentialTypes] = {
CONFIG_KEY_CREDENTIAL_DATA("programming-pin"), CONFIG_KEY_CREDENTIAL_DATA("pin"), CONFIG_KEY_CREDENTIAL_DATA("rfid"),
CONFIG_KEY_CREDENTIAL_DATA("finger-print"), CONFIG_KEY_CREDENTIAL_DATA("finger-vein"), CONFIG_KEY_CREDENTIAL_DATA("face")
};

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
Expand Down
10 changes: 5 additions & 5 deletions src/platform/telink/1m_flash.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
};
slot0_partition: partition@19000 {
label = "image-0";
reg = <0x19000 0xDC000>;
reg = <0x19000 0xda000>;
};
factory_partition: partition@F5000 {
factory_partition: partition@f3000 {
label = "factory-data";
reg = <0xF5000 0x1000>;
reg = <0xf3000 0x1000>;
};
storage_partition: partition@F6000 {
storage_partition: partition@f4000 {
label = "storage";
reg = <0xF6000 0x8000>;
reg = <0xf4000 0xa000>;
};
vendor_partition: partition@fe000 {
label = "vendor-data";
Expand Down
14 changes: 7 additions & 7 deletions src/platform/telink/2m_flash.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
};
slot0_partition: partition@19000 {
label = "image-0";
reg = <0x19000 0xee000>;
reg = <0x19000 0xed000>;
};
factory_partition: partition@107000 {
factory_partition: partition@106000{
label = "factory-data";
reg = <0x107000 0x1000>;
reg = <0x106000 0x1000>;
};
storage_partition: partition@108000 {
storage_partition: partition@107000 {
label = "storage";
reg = <0x108000 0x8000>;
reg = <0x107000 0xa000>;
};
slot1_partition: partition@110000 {
slot1_partition: partition@111000 {
label = "image-1";
reg = <0x110000 0xee000>;
reg = <0x111000 0xed000>;
};
vendor_partition: partition@1fe000 {
label = "vendor-data";
Expand Down
14 changes: 7 additions & 7 deletions src/platform/telink/4m_flash.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
};
slot0_partition: partition@19000 {
label = "image-0";
reg = <0x19000 0x1ee000>;
reg = <0x19000 0x1ed000>;
};
factory_partition: partition@207000 {
factory_partition: partition@206000 {
label = "factory-data";
reg = <0x207000 0x1000>;
reg = <0x206000 0x1000>;
};
storage_partition: partition@208000 {
storage_partition: partition@207000 {
label = "storage";
reg = <0x208000 0x8000>;
reg = <0x207000 0xa000>;
};
slot1_partition: partition@210000 {
slot1_partition: partition@211000 {
label = "image-1";
reg = <0x210000 0x1ee000>;
reg = <0x211000 0x1ed000>;
};
vendor_partition: partition@3fe000 {
label = "vendor-data";
Expand Down
Loading