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

Develop dual fix customer #358

Merged
merged 1 commit into from
Jan 3, 2025
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
5 changes: 5 additions & 0 deletions config/telink/chip-module/Kconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ config COMPRESS_LZMA
default y if SOC_RISCV_TELINK_TL321X
default n

config CUSTOMER_MODE
bool "control the demo code"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to replace it with "Enable/Disable Customer Mode"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@damien0x0023 should not use enable , so change to control , or CI wil fail which will check enable words in descriptor.

default n if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_B92
default n

config DUAL_MODE_SWTICH
bool "Control Dual-Mode Switching"
default y if SOC_RISCV_TELINK_TL321X || SOC_RISCV_TELINK_B92
Expand Down
2 changes: 2 additions & 0 deletions examples/lighting-app/telink/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class AppTask : public AppTaskCommon
bool IsTurnedOn() const;
void SetInitiateAction(Fixture_Action aAction, int32_t aActor, uint8_t * value);
void UpdateClusterState(void);
void Init_cluster_info(void);
void Set_cluster_info(void);

private:
friend AppTask & GetAppTask(void);
Expand Down
131 changes: 123 additions & 8 deletions examples/lighting-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +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 <app-common/zap-generated/attributes/Accessors.h>

Expand Down Expand Up @@ -55,22 +58,134 @@ void AppTask::PowerOnFactoryReset(void)
}
#endif /* CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET */

#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 };
/* 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;
}
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]);
printk("i2c demo stop ,finish transfer\n");
}

#define MATTER_COLORMODE_ENABLE 0

void AppTask::Set_cluster_info(void)
{
printk("%%%%%%Set_cluster_info!!!!%%%%%%\n");
light_para_t * p_para = &light_para;
Protocols::InteractionModel::Status status;
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);
status = Clusters::LevelControl::Attributes::CurrentLevel::Set(kExampleEndpointId, p_para->level);

#if MATTER_COLORMODE_ENABLE
// Set ColorMode value
printk("%%%%%%Set_cluster_info:p_para->color_mode:%d!!!!%%%%%%\n", p_para->color_mode);
status = Clusters::ColorControl::Attributes::ColorMode::Set(1, p_para->color_mode);
#endif

// Set ColorTemperatureMireds value
status = Clusters::ColorControl::Attributes::ColorTemperatureMireds::Set(1, p_para->color_temp_mireds);
// Set CurrentX value
status = Clusters::ColorControl::Attributes::CurrentX::Set(1, p_para->currentx);
// Set CurrentY value
status = Clusters::ColorControl::Attributes::CurrentY::Set(1, p_para->currenty);
// 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);
// Set CurrentSaturation value
status = Clusters::ColorControl::Attributes::CurrentSaturation::Set(1, p_para->cur_saturation);
// Set OnOffTransitionTime value
status = Clusters::LevelControl::Attributes::OnOffTransitionTime::Set(1, p_para->onoff_transition);
}

void AppTask::Init_cluster_info(void)
{
light_para_t * p_para = &light_para;
Protocols::InteractionModel::Status status;
bool onoff_sts;
status = Clusters::OnOff::Attributes::OnOff::Get(1, &(onoff_sts));
p_para->onoff = (uint8_t) onoff_sts;
app::DataModel::Nullable<uint8_t> brightness;
// Read brightness value
status = Clusters::LevelControl::Attributes::CurrentLevel::Get(kExampleEndpointId, brightness);
if (status == Protocols::InteractionModel::Status::Success && !brightness.IsNull())
{
p_para->level = brightness.Value();
}

#if MATTER_COLORMODE_ENABLE
// Read ColorMode value
status = Clusters::ColorControl::Attributes::ColorMode::Get(1, &(p_para->color_mode));
#endif

// Read ColorTemperatureMireds value
status = Clusters::ColorControl::Attributes::ColorTemperatureMireds::Get(1, &(p_para->color_temp_mireds));

// Read CurrentX value
status = Clusters::ColorControl::Attributes::CurrentX::Get(1, &(p_para->currentx));

// Read CurrentY value
status = Clusters::ColorControl::Attributes::CurrentY::Get(1, &(p_para->currenty));

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

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

// Read CurrentSaturation value
status = Clusters::ColorControl::Attributes::CurrentSaturation::Get(1, &(p_para->cur_saturation));

// Read OnOffTransitionTime value
status = Clusters::LevelControl::Attributes::OnOffTransitionTime::Get(1, &(p_para->onoff_transition));
}

#endif

CHIP_ERROR AppTask::Init(void)
{
SetExampleButtonCallbacks(LightingActionEventHandler);
InitCommonParts();

#if CONFIG_DUAL_MODE_SWTICH
if (sBoot_zb)
#if CONFIG_CUSTOMER_MODE
if (user_para.val == USER_ZB_SW_VAL)
{
/* Switching from TouchLink (Zigbee) to Matter. Restore previous states. */
sfixture_on = user_para.onoff;
sBrightness = user_para.lightness;
sAppTask.UpdateClusterState();
printk("Matter: Restored Zigbee On/Off and brightness states.\n");
Set_cluster_info();
}
#endif
else if (user_para.val == USER_MATTER_PAIR_VAL)
{
/* start from matter , add cluster info demo here*/
Init_cluster_info();
}
else
{
/* 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;

app::DataModel::Nullable<uint8_t> brightness;
Expand All @@ -91,7 +206,7 @@ CHIP_ERROR AppTask::Init(void)
// Set actual state to stored before reboot
SetInitiateAction(storedValue ? ON_ACTION : OFF_ACTION, static_cast<int32_t>(AppEvent::kEventType_DeviceAction), nullptr);
}

#endif
return CHIP_NO_ERROR;
}

Expand Down
9 changes: 9 additions & 0 deletions examples/lighting-app/telink/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ using namespace chip::app::Clusters;
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size,
uint8_t * value)
{
#if CONFIG_CUSTOMER_MODE
/* customer mode , add the customer code here for cb*/
ClusterId clusterId = attributePath.mClusterId;
AttributeId attributeId = attributePath.mAttributeId;
ChipLogProgress(Zcl, "========MatterPostAttributeChangeCallback:clusterId=0x%x,AttributeId=0x%x,value=0x%x", clusterId,
attributeId, *value);

#else
static HsvColor_t hsv;
static XyColor_t xy;
ClusterId clusterId = attributePath.mClusterId;
Expand Down Expand Up @@ -116,4 +124,5 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
ChipLogDetail(Zcl, "Ignore ColorControl attribute (%u) that is not currently processed!", attributeId);
}
}
#endif
}
32 changes: 29 additions & 3 deletions examples/platform/telink/common/include/AppTaskCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,22 @@
#include <zephyr/storage/flash_map.h>
#include <zephyr/sys/reboot.h>

#if CONFIG_SOC_RISCV_TELINK_B92
#define ZB_NVS_PARTITION zigbee_partition
#define ZB_NVS_SEC_SIZE FIXED_PARTITION_SIZE(ZB_NVS_PARTITION)
#elif CONFIG_SOC_RISCV_TELINK_TL321X
#define ZB_NVS_PARTITION slot1_partition
/* zb para locate in the slot1 , and it will cost 104k size in slot1 */
#define ZB_NVS_SEC_SIZE (104 * 1024)
#endif

#define ZB_NVS_PARTITION_DEVICE FIXED_PARTITION_DEVICE(ZB_NVS_PARTITION)
#define ZB_NVS_START_ADR FIXED_PARTITION_OFFSET(ZB_NVS_PARTITION)

#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_PARA_MAC_OFFSET 0x100
#define USER_PARTITION user_para_partition
#define USER_PARTITION_DEVICE FIXED_PARTITION_DEVICE(USER_PARTITION)
Expand All @@ -55,11 +68,24 @@
typedef struct
{
uint8_t val;
uint8_t rfu;
uint8_t onoff;
uint8_t lightness;
uint8_t on_net;
} user_para_t;

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;
extern user_para_t user_para;
extern uint8_t para_lightness;
extern uint8_t sBoot_zb;
Expand Down
Loading
Loading