Skip to content

Commit e3e1e63

Browse files
committed
Add atecc_handle_write_default_configuration to simplify provisioning of atec608
Signed-off-by: cybnon <stefan.weber93@googlemail.com>
1 parent 513a463 commit e3e1e63

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

include/atecc608_handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const uint8_t ECCX08_DEFAULT_CONFIGURATION_VALS[112] = {
7777
};
7878

7979
extern "C" int atecc_handler_write_configuration(const uint8_t *config, size_t len);
80+
extern "C" int atecc_handle_write_default_configuration();
8081
extern "C" int atecc_handler_lock_zone(uint8_t zone);
8182
extern "C" int atecc_handler_init(int i2cAddr, int bus);
8283
extern "C" int atecc_handler_read_configuration(uint8_t *config_data);

src/atecc608_handler.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ int atecc_handler_write_configuration(const uint8_t *config, size_t len)
3030
return status;
3131
}
3232

33+
/** \brief Write default configuration to the chip.
34+
* \return ATCA_SUCCESS on success, otherwise an error code.
35+
*/
36+
int atecc_handle_write_default_configuration(){
37+
ATCA_STATUS status;
38+
status = atcab_init(&cfg);
39+
if (status == ATCA_SUCCESS)
40+
{
41+
status = atecc_handler_write_configuration(ECCX08_DEFAULT_CONFIGURATION_VALS, sizeof(ECCX08_DEFAULT_CONFIGURATION_VALS));
42+
return status;
43+
}
44+
return status;
45+
}
46+
3347

3448
/** \brief Check if a the DATA_ZONE or CONFIG_ZONE is locked
3549
* \param[in] zone LOCK_ZONE_DATA or LOCK_ZONE_CONFIG

test/test_atecc608.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ void printHexBuffer(std::vector<uint8_t> input){
1717

1818
void write_atecc_config()
1919
{
20-
auto status = atecc_handler_init(0xC0);
20+
auto status = atecc_handler_init(0xC0, 1);
2121
if(status){
2222
std::cout << "atecc_handler_init Fail! ";
2323
std::cout << status << "\n";
2424
return;
2525
}
2626

27-
status = atecc_handler_write_configuration(ECCX08_DEFAULT_CONFIGURATION_VALS, sizeof(ECCX08_DEFAULT_CONFIGURATION_VALS));
27+
status = atecc_handle_write_default_configuration();
2828
if(status){
2929
std::cout << "atecc_handler_write_configuration Fail! ";
3030
std::cout << status << "\n";
@@ -41,7 +41,7 @@ void write_atecc_config()
4141

4242

4343
int general_test(){
44-
auto status = atecc_handler_init(0xC0);
44+
auto status = atecc_handler_init(0xC0, 1);
4545
if(status){
4646
std::cout << "atecc_handler_init Fail! ";
4747
std::cout << status << "\n";
@@ -120,7 +120,7 @@ int general_test(){
120120

121121

122122
int main(){
123-
// write_atecc_config();
123+
write_atecc_config();
124124
general_test();
125125

126126
return 0;

0 commit comments

Comments
 (0)