From c88b00dfe149368c9066a47ae2bab1e9736dd958 Mon Sep 17 00:00:00 2001 From: Kilian Bracher Date: Thu, 27 Jun 2024 02:22:01 +0200 Subject: [PATCH] allow access to device verification function --- DS2482_HAL.c | 35 +++++++++++------------------------ DS2482_HAL.h | 1 + 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/DS2482_HAL.c b/DS2482_HAL.c index 8089c8c..fd2849e 100644 --- a/DS2482_HAL.c +++ b/DS2482_HAL.c @@ -1,5 +1,4 @@ #include "DS2482_HAL.h" -#include "errors.h" #include static I2C_HandleTypeDef* hi2c; @@ -188,7 +187,7 @@ static uint8_t crc8; // Setup the search to find the device type 'family_code' on the next call // to OWNext() if it is present. // -static void OWTargetSetup(uint8_t family_code) { +[[maybe_unused]] static void OWTargetSetup(uint8_t family_code) { int i; // set the search state to find SearchFamily type devices @@ -204,7 +203,7 @@ static void OWTargetSetup(uint8_t family_code) { // Setup the search to skip the current device type on the next call // to OWNext(). // -static void OWFamilySkipSetup() { +[[maybe_unused]] static void OWFamilySkipSetup() { // set the Last discrepancy to last family discrepancy LastDiscrepancy = LastFamilyDiscrepancy; LastFamilyDiscrepancy = 0; @@ -413,21 +412,16 @@ static inline bool OWNext() { return OWSearch(); } -//-------------------------------------------------------------------------- -// Verify the device with the ROM number in ROM_NO buffer is present. -// Return true : device verified present -// false : device not present -// -static bool OWVerify() { - uint8_t rom_backup[8]; - int i, rslt, ld_backup, ldf_backup, lfd_backup; - // keep a backup copy of the current state - for (i = 0; i < 8; i++) +// Verify the device with the ROM number in ROM_NO buffer is present. +HAL_StatusTypeDef ds2482_1w_verify_device(uint64_t device, bool* present) { + uint8_t rom_backup[8]; + int i, rslt; + + for (int i = 0; i < 8; i++) { + ROM_NO[i] = (device >> (i * 8)) & 0xFF; rom_backup[i] = ROM_NO[i]; - ld_backup = LastDiscrepancy; - ldf_backup = LastDeviceFlag; - lfd_backup = LastFamilyDiscrepancy; + } // set search to find the same device LastDiscrepancy = 64; @@ -444,14 +438,7 @@ static bool OWVerify() { } } else rslt = false; - - // restore the search state - for (i = 0; i < 8; i++) - ROM_NO[i] = rom_backup[i]; - LastDiscrepancy = ld_backup; - LastDeviceFlag = ldf_backup; - LastFamilyDiscrepancy = lfd_backup; - + // return the result of the verify return rslt; } diff --git a/DS2482_HAL.h b/DS2482_HAL.h index 735ec26..9f07d89 100644 --- a/DS2482_HAL.h +++ b/DS2482_HAL.h @@ -47,5 +47,6 @@ HAL_StatusTypeDef ds2482_1w_read_byte(uint8_t* byte); HAL_StatusTypeDef ds2482_1w_triplet(uint8_t dir); HAL_StatusTypeDef ds2482_1w_search(uint16_t max_devices, uint64_t devices[static max_devices]); +HAL_StatusTypeDef ds2482_1w_verify_device(uint64_t device, bool* present); #endif // DS2482_HAL_H \ No newline at end of file