Skip to content

Commit

Permalink
telink: b92: optimize code format
Browse files Browse the repository at this point in the history
- Optimize code format to access CI .

Signed-off-by: Fengtai Xie <fengtai.xie@telink-semi.com>
  • Loading branch information
fengtai-telink committed Dec 24, 2024
1 parent ee0bc9d commit 3e37ea6
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 72 deletions.
1 change: 1 addition & 0 deletions examples/lighting-app/telink/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class AppTask : public AppTaskCommon
void UpdateClusterState(void);
void Init_cluster_info(void);
void Set_cluster_info(void);

private:
friend AppTask & GetAppTask(void);
friend class AppTaskCommon;
Expand Down
50 changes: 26 additions & 24 deletions examples/lighting-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#include "ColorFormat.h"
#include "LEDManager.h"
#include "PWMManager.h"
#include <zephyr/device.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/kernel.h>
#include <zephyr/device.h>

#include <app-common/zap-generated/attributes/Accessors.h>

Expand Down Expand Up @@ -61,37 +61,38 @@ void AppTask::PowerOnFactoryReset(void)
#if CONFIG_CUSTOMER_MODE
void i2c_demo_proc()
{
const uint8_t tx_buf[23]= { 0xc0,0x63,0x3f,0x63, 0x63,0x63,0x22,0x22,
0x00,0x00,0x00,0x00, 0x3f,0x3f,0x00,0x00,
0x00,0x00,0xff,0xff, 0x2b,0x06,0xbe};
const uint8_t tx_buf[23] = { 0xc0, 0x63, 0x3f, 0x63, 0x63, 0x63, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
0x3f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2b, 0x06, 0xbe };
/* add the i2c module here */
printk("i2c demo start \n.");
uint32_t i2c_cfg = I2C_SPEED_SET(I2C_SPEED_FAST) | I2C_MODE_CONTROLLER;
/* get i2c device */
int rc;
const struct i2c_dt_spec i2c = I2C_DT_SPEC_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(ledcontrol_i2c));
if (!device_is_ready(i2c.bus)) {
printf("Device %s is not ready\n", i2c.bus->name);
return ;
}
const struct i2c_dt_spec i2c = I2C_DT_SPEC_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(ledcontrol_i2c));
if (!device_is_ready(i2c.bus))
{
printf("Device %s is not ready\n", i2c.bus->name);
return;
}
rc = i2c_configure(i2c.bus, i2c_cfg);
if(rc != 0){
printf("Failed to configure i2c device\n");
return ;
}
i2c_write(i2c.bus, tx_buf+1, sizeof(tx_buf)-1,tx_buf[0]);
if (rc != 0)
{
printf("Failed to configure i2c device\n");
return;
}
i2c_write(i2c.bus, tx_buf + 1, sizeof(tx_buf) - 1, tx_buf[0]);
printk("i2c demo stop ,finish transfer\n");
}

void AppTask::Init_cluster_info(void)
{
printk("%%%%%%Set_cluster_info!!!!%%%%%%\n");
light_para_t *p_para = &light_para;
light_para_t * p_para = &light_para;
Protocols::InteractionModel::Status status;
printk("%%%%%%Set_cluster_info:p_para->onoff:%d!!!!%%%%%%\n",p_para->onoff);
printk("%%%%%%Set_cluster_info:p_para->onoff:%d!!!!%%%%%%\n", p_para->onoff);
status = Clusters::OnOff::Attributes::OnOff::Set(1, p_para->onoff);
// Set brightness value
printk("%%%%%%Set_cluster_info:p_para->level:%d!!!!%%%%%%\n",p_para->level);
printk("%%%%%%Set_cluster_info:p_para->level:%d!!!!%%%%%%\n", p_para->level);
status = Clusters::LevelControl::Attributes::CurrentLevel::Set(kExampleEndpointId, p_para->level);
// Set ColorMode value
/*
Expand All @@ -109,7 +110,7 @@ void AppTask::Init_cluster_info(void)

// Set EnhancedCurrentHue value
status = Clusters::ColorControl::Attributes::EnhancedCurrentHue::Set(1, p_para->enhanced_current_hue);

// Set CurrentHue value
status = Clusters::ColorControl::Attributes::CurrentHue::Set(1, p_para->cur_hue);

Expand All @@ -130,17 +131,18 @@ CHIP_ERROR AppTask::Init(void)
if (user_para.val == USER_ZB_SW_VAL)
{
/* switch from zigbee , which means uncommission state .*/

}else if (user_para.val == USER_MATTER_PAIR_VAL)
}
else if (user_para.val == USER_MATTER_PAIR_VAL)
{
/* start from matter , add cluster info demo here*/
/* start from matter , add cluster info demo here*/
Init_cluster_info();
}else
}
else
{
/* start from matter , but without zigbee fw*/
/* start from matter , but without zigbee fw*/
}
/* if need , can call i2c_demo_proc here to see light works or not*/

#else
Protocols::InteractionModel::Status status;

Expand Down
30 changes: 15 additions & 15 deletions examples/platform/telink/common/include/AppTaskCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
#define ZB_NVS_PARTITION_DEVICE FIXED_PARTITION_DEVICE(ZB_NVS_PARTITION)
#define ZB_NVS_START_ADR FIXED_PARTITION_OFFSET(ZB_NVS_PARTITION)
/* zb para locate in the slot1 , and it will cost 104k size in slot1 */
#define ZB_NVS_SEC_SIZE (104*1024)
#define ZB_NVS_SEC_SIZE (104 * 1024)
#endif

#define USER_INIT_VAL 0xff
#define USER_ZB_SW_VAL 0xaa
#define USER_MATTER_PAIR_VAL 0x55
#define USER_MATTER_BACK_ZB 0xa0 // only commisiion fail will back to zb
#define USER_MATTER_BACK_ZB 0xa0 // only commisiion fail will back to zb
#define USER_PARA_MAC_OFFSET 0x100
#define USER_PARTITION user_para_partition
#define USER_PARTITION_DEVICE FIXED_PARTITION_DEVICE(USER_PARTITION)
Expand All @@ -76,19 +76,19 @@ typedef struct

typedef struct
{
uint8_t onoff;
uint8_t level;
uint16_t color_temp_mireds;
uint16_t currentx;
uint16_t currenty;
uint16_t enhanced_current_hue;
uint16_t onoff_transition;
uint8_t cur_hue;
uint8_t cur_saturation;
uint8_t color_mode;
}light_para_t;

extern light_para_t light_para;
uint8_t onoff;
uint8_t level;
uint16_t color_temp_mireds;
uint16_t currentx;
uint16_t currenty;
uint16_t enhanced_current_hue;
uint16_t onoff_transition;
uint8_t cur_hue;
uint8_t cur_saturation;
uint8_t color_mode;
} light_para_t;

extern light_para_t light_para;
extern user_para_t user_para;
extern uint8_t para_lightness;
extern uint8_t sBoot_zb;
Expand Down
33 changes: 17 additions & 16 deletions examples/platform/telink/common/src/AppTaskCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
#include <app/clusters/ota-requestor/OTARequestorInterface.h>
#endif

#include <app-common/zap-generated/attributes/Accessors.h>
#include <zephyr/fs/nvs.h>
#include <zephyr/settings/settings.h>
#include <app-common/zap-generated/attributes/Accessors.h>

#if CONFIG_DUAL_MODE_SWTICH
uint8_t sBoot_zb = 0;
uint8_t sBoot_zb = 0;
uint8_t para_lightness = 0;
user_para_t user_para;
light_para_t light_para;
light_para_t light_para;
#endif

using namespace chip::app;
Expand Down Expand Up @@ -239,9 +239,9 @@ void AppTaskCommon::PowerOnFactoryReset(void)

void SwitchBackToZigbee()
{
uint8_t switch_flag = USER_MATTER_BACK_ZB;
//flash_erase(flash_para_dev, USER_PARTITION_OFFSET, USER_PARTITION_SIZE);
flash_write(flash_para_dev,USER_PARTITION_OFFSET,&switch_flag,1);
uint8_t switch_flag = USER_MATTER_BACK_ZB;
// flash_erase(flash_para_dev, USER_PARTITION_OFFSET, USER_PARTITION_SIZE);
flash_write(flash_para_dev, USER_PARTITION_OFFSET, &switch_flag, 1);
sys_reboot(0);
}

Expand All @@ -253,7 +253,8 @@ void AppTaskCommon::DnssTimerTimeoutCallback(k_timer * timer)
}
printk("Matter: DnssTimer expired.\r\n");
/*If initialization of Dnss takes longer than 90 seconds, the device will reboot and revert to Zigbee mode*/
if (sBoot_zb){
if (sBoot_zb)
{
SwitchBackToZigbee();
}
}
Expand All @@ -270,14 +271,14 @@ CHIP_ERROR AppTaskCommon::StartApp(void)
{
sBoot_zb = 1;
/* if switch from zb , need to get all the cluster info from zb */
flash_read(flash_para_dev, USER_PARTITION_OFFSET+sizeof(user_para), &light_para, sizeof(light_para));
flash_read(flash_para_dev, USER_PARTITION_OFFSET + sizeof(user_para), &light_para, sizeof(light_para));
/* Ensure lightness is at least 2 to avoid display error on HomePod Mini */
if(light_para.level < 2)
if (light_para.level < 2)
{
light_para.level = 2;
}
/* Pass the value to the init part to avoid gaps in pwm_pool init */
if(light_para.onoff)
if (light_para.onoff)
{
para_lightness = light_para.level;
}
Expand Down Expand Up @@ -832,14 +833,14 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /*
#endif
break;
#if CONFIG_DUAL_MODE_SWTICH
case DeviceEventType::kCommissioningComplete:
{
case DeviceEventType::kCommissioningComplete: {
uint8_t val = USER_MATTER_PAIR_VAL;
#if CONFIG_CUSTOMER_MODE
#if CONFIG_CUSTOMER_MODE
/* need to add here to update the cluster information , only in the zb switch and touchlink is paired*/
if(user_para.val == USER_ZB_SW_VAL && user_para.on_net ){
if (user_para.val == USER_ZB_SW_VAL && user_para.on_net)
{
Protocols::InteractionModel::Status status;
/* Switch from the touch link, need to restore previous values */
/* Switch from the touch link, need to restore previous values */
status = Clusters::OnOff::Attributes::OnOff::Set(kExampleEndpointId, light_para.onoff);
if (status != Protocols::InteractionModel::Status::Success)
{
Expand All @@ -850,7 +851,7 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /*
LOG_ERR("Update brightness fail: %x", to_underlying(status));
}
}
#endif
#endif
flash_erase(flash_para_dev, USER_PARTITION_OFFSET, USER_PARTITION_SIZE);
flash_write(flash_para_dev, USER_PARTITION_OFFSET, &val, 1);
printk("Commissioning complete, set Matter commissionined flag");
Expand Down
36 changes: 19 additions & 17 deletions examples/platform/telink/common/src/mainCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,32 +107,34 @@ static void FactoryResetOnBoot(void)

#if CONFIG_CUSTOMER_MODE

#define MATTER_NVS_DEMO_EN 0
#define MATTER_NVS_DEMO_EN 0

#if MATTER_NVS_DEMO_EN
#if MATTER_NVS_DEMO_EN
void matter_nvs_raw_demo(void)
{
static constexpr char kFactoryResetOnBootStoreKey[] = "TelinkFactoryResetOnBootCnt";
uint32_t test_flag =0x55;
if (chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr().Put(kFactoryResetOnBootStoreKey, &test_flag,
sizeof(test_flag)) != CHIP_NO_ERROR)
static constexpr char kFactoryResetOnBootStoreKey[] = "TelinkFactoryResetOnBootCnt";
uint32_t test_flag = 0x55;

if (chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr().Put(kFactoryResetOnBootStoreKey, &test_flag, sizeof(test_flag)) !=
CHIP_NO_ERROR)
{
printk("FactoryResetOnBootCnt write fail\n");
}

test_flag =0xaa;
CHIP_ERROR FactoryResetOnBootErr = chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr().Get(
kFactoryResetOnBootStoreKey, &test_flag, sizeof(test_flag));
if(FactoryResetOnBootErr != CHIP_NO_ERROR ){

test_flag = 0xaa;
CHIP_ERROR FactoryResetOnBootErr =
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr().Get(kFactoryResetOnBootStoreKey, &test_flag, sizeof(test_flag));
if (FactoryResetOnBootErr != CHIP_NO_ERROR)
{
printk("FactoryResetOnBootCnt get fail\n");
}
printk("nvs read value is %x \n",test_flag);
printk("nvs read value is %x \n", test_flag);
(void) chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr().Delete(kFactoryResetOnBootStoreKey);
test_flag =0xbb;
FactoryResetOnBootErr = chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr().Get(
kFactoryResetOnBootStoreKey, &test_flag, sizeof(test_flag));
if(FactoryResetOnBootErr != CHIP_NO_ERROR ){
test_flag = 0xbb;
FactoryResetOnBootErr =
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgr().Get(kFactoryResetOnBootStoreKey, &test_flag, sizeof(test_flag));
if (FactoryResetOnBootErr != CHIP_NO_ERROR)
{
printk("FactoryResetOnBootCnt delete after read fail \n");
}
}
Expand Down

0 comments on commit 3e37ea6

Please sign in to comment.