From 50b1f5db034ea4790edad94f315ef4069b50888d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingmar=20In=CA=92o=20Splitt?= Date: Tue, 11 Oct 2022 01:03:36 +0200 Subject: [PATCH] allow to skip reboot after search-rom and read-rom default behavior for most IC --- README.md | 2 +- src/BAE910.cpp | 5 +++++ src/DS18B20.cpp | 3 +++ src/DS18B20.h | 2 +- src/DS2401.cpp | 3 +++ src/DS2405.h | 2 +- src/DS2434.cpp | 8 ++++---- src/DS2434.h | 2 +- src/OneWireHub.cpp | 22 +++++++++++++++++----- src/OneWireItem.h | 10 ++++++++-- 10 files changed, 44 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ce9c5b7..77f9142 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ The main goal is to use modern sensors (mainly [I2C](https://github.com/orgua/iL - **DS2431 (0x2D) 1kbit protected EEPROM** (also known as DS1972 or DS28E07, same FC) - DS2432 (0x33) 1kbit protected EEPROM (basically a ds2431 with extra sha-engine) - **DS2433 (0x23) 4Kbit EEPROM** (also known as DS1973) -- DS2434 (0x1B ???) BatteryManagement used in some IBM Notebook-Batteries (similar to DS2436 (x1B), with one less cmd) +- DS2434 (0x1B ???) BatteryManagement used in some IBM Notebook-Batteries (similar to DS2436 (x1B), but without multidrop and one less cmd) - **DS2438 (0x26) Smart Battery Monitor, measures temperature, 2x voltage and current, 10bit** - **DS2450 (0x20) 4 channel A/D** - **DS2501 (0x11, 0x91) 512bit EEPROM** -> use DS2502 with different family code diff --git a/src/BAE910.cpp b/src/BAE910.cpp index 5fd32b1..d296195 100644 --- a/src/BAE910.cpp +++ b/src/BAE910.cpp @@ -7,6 +7,11 @@ BAE910::BAE910(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, // clear memory memset(&memory.bytes[0], static_cast(0x00), BAE910_MEMORY_SIZE); + + // disable bus-features: + // TODO: test, as datasheet does not clear this up -> this settings keeps the previous behavior + fast_read_rom = false; + fast_search_rom = false; } diff --git a/src/DS18B20.cpp b/src/DS18B20.cpp index 675b1cb..2ce15d9 100644 --- a/src/DS18B20.cpp +++ b/src/DS18B20.cpp @@ -15,6 +15,9 @@ DS18B20::DS18B20(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5 updateCRC(); // update scratchpad[8] ds18s20_mode = (ID1 == 0x10); // different tempRegister + + // disable bus-features: + fast_search_rom = false; } void DS18B20::updateCRC() diff --git a/src/DS18B20.h b/src/DS18B20.h index e183a38..a089d6f 100644 --- a/src/DS18B20.h +++ b/src/DS18B20.h @@ -22,7 +22,7 @@ class DS18B20 : public OneWireItem public: - static constexpr uint8_t family_code { 0x28 }; // is compatible to ds1822 (0x22) and ds18S20 (0x10) + static constexpr uint8_t family_code { 0x28 }; // is compatible to ds1822 (0x22) and ds18S20 (0x10) DS18B20(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7); diff --git a/src/DS2401.cpp b/src/DS2401.cpp index 2fb0467..6820e04 100644 --- a/src/DS2401.cpp +++ b/src/DS2401.cpp @@ -2,6 +2,9 @@ DS2401::DS2401(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7) : OneWireItem(ID1, ID2, ID3, ID4, ID5, ID6, ID7) { + // disable bus-features: + fast_read_rom = false; + fast_search_rom = false; } void DS2401::duty(OneWireHub * const hub) diff --git a/src/DS2405.h b/src/DS2405.h index 5d636a5..fd91015 100644 --- a/src/DS2405.h +++ b/src/DS2405.h @@ -16,7 +16,7 @@ class DS2405 : public OneWireItem public: - static constexpr uint8_t family_code { 0x05 }; + static constexpr uint8_t family_code { 0x05 }; DS2405(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7); diff --git a/src/DS2434.cpp b/src/DS2434.cpp index d5a212b..7a25a5c 100644 --- a/src/DS2434.cpp +++ b/src/DS2434.cpp @@ -2,10 +2,10 @@ DS2434::DS2434(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7) : OneWireItem(ID1, ID2, ID3, ID4, ID5, ID6, ID7) { - // The DS2434 is NOT compatible with multidrop. - // It can be the only one of the bus - MULTIDROP = false; - + // disable bus-features: + // The DS2434 is NOT compatible with multidrop -> only one device on bus! + skip_multidrop = true; + clearMemory(); clearScratchpad(); } diff --git a/src/DS2434.h b/src/DS2434.h index 7fbfb28..9cbf2f5 100644 --- a/src/DS2434.h +++ b/src/DS2434.h @@ -58,7 +58,7 @@ class DS2434 : public OneWireItem public: - static constexpr uint8_t family_code { 0x53 }; // TODO: 1B seems to be right + static constexpr uint8_t family_code { 0x53 }; // TODO: 1B seems to be right (for ds2436) DS2434(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7); diff --git a/src/OneWireHub.cpp b/src/OneWireHub.cpp index 350a313..581edaa 100644 --- a/src/OneWireHub.cpp +++ b/src/OneWireHub.cpp @@ -404,12 +404,13 @@ bool OneWireHub::recvAndProcessCmd(void) { // If the only slave is not multidrop compatible, pass all data handling to the slave - if(slave_count == 1){ + if(slave_count == 1u){ slave_selected = slave_list[getIndexOfNextSensorInList()]; - // TODO: this might be expensive for weak uC and OW in Overdrive -> look into optimizations (i.e. preselect when only one device present?) + // TODO: this might be expensive for weak uC and OW in Overdrive and only one device emulated + // -> look into optimizations (i.e. preselect when only one device present?) - if( slave_selected->MULTIDROP == false ){ + if( slave_selected->skip_multidrop ){ slave_selected->duty(this); return (_error != Error::NO_ERROR); } @@ -431,8 +432,13 @@ bool OneWireHub::recvAndProcessCmd(void) noInterrupts(); searchIDTree(); interrupts(); - // slave_selected->duty(this); - // TODO: some ICs like DS2430 allow going for duty() right after search + + // most ICs allow going for duty() right after search + if ((_error == Error::NO_ERROR) && (slave_selected != nullptr) && slave_selected->fast_search_rom) + { + slave_selected->duty(this); + } + return false; // always trigger a re-init after searchIDTree case 0x69: // overdrive MATCH ROM @@ -520,6 +526,12 @@ bool OneWireHub::recvAndProcessCmd(void) if (slave_selected != nullptr) { slave_selected->sendID(this); + + // most ICs allow to go to duty() without reset + if ((_error == Error::NO_ERROR) && slave_selected->fast_read_rom) + { + slave_selected->duty(this); + } } return false; diff --git a/src/OneWireItem.h b/src/OneWireItem.h index 78acb8b..d1550d1 100644 --- a/src/OneWireItem.h +++ b/src/OneWireItem.h @@ -27,10 +27,16 @@ class OneWireItem OneWireItem& operator=(const OneWireItem& owItem) = delete; // disallow copy assignment OneWireItem& operator=(OneWireItem&& owItem) = delete; // disallow move assignment + // DEFAULT BUS-FEATURES: // Specify if the device can be used on a bus with other 1-wire devices // If FALSE all commands will be passed through directly to the duty() call of the device - bool MULTIDROP { true }; // TODO: should be lowercase, as it is no constant (yet) - + // NOTE: there can be only one device on the bus (beside the controller) + bool skip_multidrop { false }; + // skip reboot after a search-rom command -> feature normal, except ds2401 & ds18b20 + bool fast_search_rom { true }; + // skip reboot after a read-rom command -> feature normal, except ds2401 + bool fast_read_rom { true }; + uint8_t ID[8]; void sendID(OneWireHub * hub) const;