Skip to content

Commit

Permalink
Changes to support product-appearance attribute on ESP32.
Browse files Browse the repository at this point in the history
- Added the support for product-appearance attribute of BasicInformationCluster in factory script.
- Added DeviceInstanceInfoProvider implementation for the attribute.
  • Loading branch information
shripad621git committed Jul 18, 2024
1 parent 4be8f6d commit 1690183
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
26 changes: 25 additions & 1 deletion scripts/tools/generate_esp32_chip_factory_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@

INVALID_PASSCODES = [00000000, 11111111, 22222222, 33333333, 44444444, 55555555,
66666666, 77777777, 88888888, 99999999, 12345678, 87654321]
PRODUCT_FINISH_ENUM = {"other": 0, "matte": 1, "satin": 2, "polished": 3, "rugged": 4, "fabric": 5}
PRODUCT_COLOR_ENUM = {"black": 0, "navy": 1, "green": 2, "teal": 3, "maroon": 4, "purple": 5, "olive": 6, "gray": 7, "blue": 8, "lime": 9,
"aqua": 10, "red": 11, "fuchsia": 12, "yellow": 13, "white": 14, "nickel": 15, "chrome": 16, "brass": 18, "cooper": 19,
"silver": 19, "gold": 20}

TOOLS = {}

Expand Down Expand Up @@ -149,6 +153,16 @@
'encoding': 'hex2bin',
'value': None,
},
'product-finish': {
'type': 'data',
'encoding': 'u32',
'value': None,
},
'product-color': {
'type': 'data',
'encoding': 'u32',
'value': None,
},
}


Expand Down Expand Up @@ -301,6 +315,10 @@ def populate_factory_data(args, spake2p_params):
FACTORY_DATA['hardware-ver']['value'] = args.hw_ver
if args.hw_ver_str:
FACTORY_DATA['hw-ver-str']['value'] = args.hw_ver_str
if args.product_finish:
FACTORY_DATA['product-finish']['value'] = PRODUCT_FINISH_ENUM[args.product_finish]
if args.product_color:
FACTORY_DATA['product-color']['value'] = PRODUCT_COLOR_ENUM[args.product_color]

# SupportedModes are stored as multiple entries
# - sm-sz/<ep> : number of supported modes for the endpoint
Expand Down Expand Up @@ -471,6 +489,11 @@ def any_base_int(s): return int(s, 0)
parser.add_argument('--supported-modes', type=str, nargs='+', required=False,
help='List of supported modes, eg: mode1/label1/ep/"tagValue1\\mfgCode, tagValue2\\mfgCode" mode2/label2/ep/"tagValue1\\mfgCode, tagValue2\\mfgCode" mode3/label3/ep/"tagValue1\\mfgCode, tagValue2\\mfgCode"')

parser.add_argument("--product-finish", type=str, choices=PRODUCT_FINISH_ENUM.keys(),
help='Product finishes choices for product appearance')
parser.add_argument("--product-color", type=str, choices=PRODUCT_COLOR_ENUM.keys(),
help='Product colors choices for product appearance')

parser.add_argument('-s', '--size', type=any_base_int, default=0x6000,
help='The size of the partition.bin, default: 0x6000')
parser.add_argument('--target', default='esp32',
Expand Down Expand Up @@ -509,7 +532,8 @@ def set_up_factory_data(args):
def generate_factory_partiton_binary(args):
generate_nvs_csv(args.output_dir, FACTORY_PARTITION_CSV)
if args.generate_bin:
generate_nvs_bin(args.encrypt, args.size, FACTORY_PARTITION_CSV, FACTORY_PARTITION_BIN, args.output_dir)
csv_file = os.path.join(args.output_dir, FACTORY_PARTITION_CSV)
generate_nvs_bin(args.encrypt, args.size, csv_file, FACTORY_PARTITION_BIN, args.output_dir)
print_flashing_help(args.encrypt, args.output_dir, FACTORY_PARTITION_BIN)
clean_up()

Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/ESP32Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const ESP32Config::Key ESP32Config::kConfigKey_ProductURL = { kConfig
const ESP32Config::Key ESP32Config::kConfigKey_SupportedCalTypes = { kConfigNamespace_ChipFactory, "cal-types" };
const ESP32Config::Key ESP32Config::kConfigKey_SupportedLocaleSize = { kConfigNamespace_ChipFactory, "locale-sz" };
const ESP32Config::Key ESP32Config::kConfigKey_RotatingDevIdUniqueId = { kConfigNamespace_ChipFactory, "rd-id-uid" };
const ESP32Config::Key ESP32Config::kConfigKey_ProductFinish = { kConfigNamespace_ChipFactory, "product-finish" };
const ESP32Config::Key ESP32Config::kConfigKey_ProductColor = { kConfigNamespace_ChipFactory, "product-color" };
const ESP32Config::Key ESP32Config::kConfigKey_LocationCapability = { kConfigNamespace_ChipFactory, "loc-capability" };

// Keys stored in the chip-config namespace
Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/ESP32Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class ESP32Config
static const Key kConfigKey_SupportedCalTypes;
static const Key kConfigKey_SupportedLocaleSize;
static const Key kConfigKey_RotatingDevIdUniqueId;
static const Key kConfigKey_ProductFinish;
static const Key kConfigKey_ProductColor;
static const Key kConfigKey_LocationCapability;

// CHIP Config keys
Expand Down
25 changes: 25 additions & 0 deletions src/platform/ESP32/ESP32FactoryDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,31 @@ CHIP_ERROR ESP32FactoryDataProvider::GetManufacturingDate(uint16_t & year, uint8
return GenericDeviceInstanceInfoProvider<ESP32Config>::GetManufacturingDate(year, month, day);
}

CHIP_ERROR ESP32FactoryDataProvider::GetProductFinish(app::Clusters::BasicInformation::ProductFinishEnum * finish)
{
CHIP_ERROR err = CHIP_NO_ERROR;
uint32_t productFinish = 0;

err = ESP32Config::ReadConfigValue(ESP32Config::kConfigKey_ProductFinish, productFinish);
ReturnErrorOnFailure(err);
*finish = static_cast<app::Clusters::BasicInformation::ProductFinishEnum>(productFinish);

return err;
}

CHIP_ERROR ESP32FactoryDataProvider::GetProductPrimaryColor(app::Clusters::BasicInformation::ColorEnum * primaryColor)
{
CHIP_ERROR err = CHIP_NO_ERROR;
uint32_t color = 0;

err = ESP32Config::ReadConfigValue(ESP32Config::kConfigKey_ProductColor, color);
ReturnErrorOnFailure(err);

*primaryColor = static_cast<app::Clusters::BasicInformation::ColorEnum>(color);

return err;
}

CHIP_ERROR ESP32FactoryDataProvider::GetHardwareVersion(uint16_t & hardwareVersion)
{
return GenericDeviceInstanceInfoProvider<ESP32Config>::GetHardwareVersion(hardwareVersion);
Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/ESP32FactoryDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class ESP32FactoryDataProvider : public CommissionableDataProvider,
CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override;
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override;
CHIP_ERROR GetProductFinish(app::Clusters::BasicInformation::ProductFinishEnum * finish);
CHIP_ERROR GetProductPrimaryColor(app::Clusters::BasicInformation::ColorEnum * primaryColor);
#endif // CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER

private:
Expand Down

0 comments on commit 1690183

Please sign in to comment.