From b8197231884793e91ec2eb21b038e657f35edac3 Mon Sep 17 00:00:00 2001 From: KilDoom <117968565+KilDoomWise@users.noreply.github.com> Date: Mon, 2 Jun 2025 18:37:46 +0300 Subject: [PATCH 1/4] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4ab852b..4dd322c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +# MODIFIED VERSION OF ONEWIREHUB WITH ESP32 SUPPORT FROM KILDOOM +# МОДИФИЦИРОВАННАЯ ВЕРСИЯ ONEWIREHUB С ПОДДЕРЖКОЙ ESP32 ОТ КИЛДУОМА + # OneWireHub The OneWireHub is a sleek Arduino compatible (and many more platforms) library to emulate OneWire-Periphery with support for various devices & sensors. The motivation is to offer a shared code base for all OneWire-Periphery-Devices. With a small overhead one µC can emulate up to 32 ICs simultaneously. From 42082d38d4e3739bcd60e0eced7e3f7245d72c79 Mon Sep 17 00:00:00 2001 From: KilDoom <117968565+KilDoomWise@users.noreply.github.com> Date: Mon, 2 Jun 2025 18:39:20 +0300 Subject: [PATCH 2/4] Fixed mem size error in compilation --- src/DS2408.cpp | 4 ++-- src/DS2408.h | 4 ++-- src/DS2423.cpp | 10 +++++----- src/DS2423.h | 6 +++--- src/DS2430.cpp | 6 +++--- src/DS2430.h | 4 ++-- src/DS2431.cpp | 8 ++++---- src/DS2431.h | 6 +++--- src/DS2433.cpp | 12 ++++++------ src/DS2433.h | 6 +++--- src/DS2434.cpp | 10 +++++----- src/DS2434.h | 4 ++-- src/DS2438.cpp | 8 ++++---- src/DS2438.h | 4 ++-- src/DS2450.cpp | 6 +++--- src/DS2450.h | 4 ++-- src/DS2502.cpp | 12 ++++++------ src/DS2502.h | 6 +++--- src/DS2506.cpp | 14 +++++++------- src/DS2506.h | 14 +++++++------- 20 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/DS2408.cpp b/src/DS2408.cpp index 642b407..4dc0708 100644 --- a/src/DS2408.cpp +++ b/src/DS2408.cpp @@ -20,13 +20,13 @@ void DS2408::duty(OneWireHub *const hub) case 0xF0: // Read PIO Registers if (hub->recv(®_TA, 1, crc)) return; - if ((reg_TA < REG_OFFSET) || (reg_TA >= REG_OFFSET + MEM_SIZE)) return; + if ((reg_TA < REG_OFFSET) || (reg_TA >= REG_OFFSET + MEMORY_SIZE)) return; if (hub->recv(&data, 1, crc)) return; // seconds part of reg_TA, should be zero if (data != 0) return; { const uint8_t start = (reg_TA - REG_OFFSET); - const uint8_t length = MEM_SIZE - start; + const uint8_t length = MEMORY_SIZE - start; if (hub->send(&memory[start], length, crc)) return; } diff --git a/src/DS2408.h b/src/DS2408.h index 9167233..84f5ae1 100644 --- a/src/DS2408.h +++ b/src/DS2408.h @@ -10,7 +10,7 @@ class DS2408 : public OneWireItem { private: - static constexpr uint8_t MEM_SIZE{8}; + static constexpr uint8_t MEMORY_SIZE{8}; // Register Indexes static constexpr uint8_t REG_OFFSET{0x88}; @@ -25,7 +25,7 @@ class DS2408 : public OneWireItem static constexpr uint8_t REG_RD_ABOVE_ALWAYS_FF_8E{6}; // 0x8E - these bytes give always 0xFF static constexpr uint8_t REG_RD_ABOVE_ALWAYS_FF_8F{7}; // 0x8F - these bytes give always 0xFF - uint8_t memory[MEM_SIZE]; + uint8_t memory[MEMORY_SIZE]; public: static constexpr uint8_t family_code{0x29}; diff --git a/src/DS2423.cpp b/src/DS2423.cpp index 1537a6e..d11b0e9 100644 --- a/src/DS2423.cpp +++ b/src/DS2423.cpp @@ -146,15 +146,15 @@ void DS2423::duty(OneWireHub *const hub) } -void DS2423::clearMemory(void) { memset(memory, static_cast(0x00), MEM_SIZE); } +void DS2423::clearMemory(void) { memset(memory, static_cast(0x00), MEMORY_SIZE); } void DS2423::clearScratchpad(void) { memset(scratchpad, static_cast(0x00), PAGE_SIZE); } bool DS2423::writeMemory(const uint8_t *const source, const uint16_t length, const uint16_t position) { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(&memory[position], source, _length); const uint8_t page_start = uint8_t(position >> 5); @@ -173,8 +173,8 @@ bool DS2423::writeMemory(const uint8_t *const source, const uint16_t length, bool DS2423::readMemory(uint8_t *const destination, const uint16_t length, const uint16_t position) const { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(destination, &memory[position], _length); return (_length == length); } diff --git a/src/DS2423.h b/src/DS2423.h index 9f7d0cd..9f71955 100644 --- a/src/DS2423.h +++ b/src/DS2423.h @@ -10,10 +10,10 @@ class DS2423 : public OneWireItem { private: - static constexpr uint16_t MEM_SIZE{512}; + static constexpr uint16_t MEMORY_SIZE{512}; static constexpr uint8_t PAGE_SIZE{32}; - static constexpr uint16_t PAGE_COUNT{MEM_SIZE / PAGE_SIZE}; + static constexpr uint16_t PAGE_COUNT{MEMORY_SIZE / PAGE_SIZE}; static constexpr uint8_t PAGE_MASK{0b00011111}; static constexpr uint8_t COUNTER_COUNT{4}; @@ -28,7 +28,7 @@ class DS2423 : public OneWireItem static constexpr uint16_t REG_TA_MASK{ 0x01FF}; // Addresses will be stripped of the highest 7 bytes - uint8_t memory[MEM_SIZE]; // 4kbit max storage + uint8_t memory[MEMORY_SIZE]; // 4kbit max storage uint8_t scratchpad[PAGE_SIZE]; uint32_t memcounter[COUNTER_COUNT]; diff --git a/src/DS2430.cpp b/src/DS2430.cpp index f274e62..61ba9e5 100644 --- a/src/DS2430.cpp +++ b/src/DS2430.cpp @@ -117,15 +117,15 @@ bool DS2430::writeMemory(const uint8_t *const source, const uint8_t length, cons bool DS2430::readMemory(uint8_t *const destination, const uint16_t length, const uint16_t position) const { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(destination, &memory[position], _length); return (_length == length); } bool DS2430::syncScratchpad() { - uint8_t length = (MEM_SIZE > SCRATCHPAD_SIZE) ? SCRATCHPAD_SIZE : MEM_SIZE; + uint8_t length = (MEMORY_SIZE > SCRATCHPAD_SIZE) ? SCRATCHPAD_SIZE : MEMORY_SIZE; memcpy(scratchpad, memory, length); return true; } diff --git a/src/DS2430.h b/src/DS2430.h index 2d43820..9c7af37 100644 --- a/src/DS2430.h +++ b/src/DS2430.h @@ -9,7 +9,7 @@ class DS2430 : public OneWireItem { private: - static constexpr uint8_t MEM_SIZE{32 + 8}; + static constexpr uint8_t MEMORY_SIZE{32 + 8}; static constexpr uint8_t SCRATCHPAD_SIZE{32 + 8}; @@ -20,7 +20,7 @@ class DS2430 : public OneWireItem static constexpr uint8_t SCRATCHPAD2_SIZE{8}; static constexpr uint8_t SCRATCHPAD2_MASK{0b00000111}; - uint8_t memory[MEM_SIZE]; + uint8_t memory[MEMORY_SIZE]; uint8_t scratchpad[SCRATCHPAD_SIZE]; diff --git a/src/DS2431.cpp b/src/DS2431.cpp index bf7a7b8..036a434 100644 --- a/src/DS2431.cpp +++ b/src/DS2431.cpp @@ -128,8 +128,8 @@ void DS2431::duty(OneWireHub *const hub) case 0xF0: // READ MEMORY COMMAND if (hub->recv(reinterpret_cast(®_TA), 2)) return; - if (reg_TA >= MEM_SIZE) return; - if (hub->send(&memory[reg_TA], MEM_SIZE - uint8_t(reg_TA), crc)) return; + if (reg_TA >= MEMORY_SIZE) return; + if (hub->send(&memory[reg_TA], MEMORY_SIZE - uint8_t(reg_TA), crc)) return; break; // send 1s when read is complete, is passive, so do nothing here default: hub->raiseDeviceError(cmd); @@ -160,8 +160,8 @@ bool DS2431::writeMemory(const uint8_t *const source, const uint8_t length, cons bool DS2431::readMemory(uint8_t *const destination, const uint16_t length, const uint16_t position) const { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(destination, &memory[position], _length); return (_length == length); } diff --git a/src/DS2431.h b/src/DS2431.h index 41e71eb..b67ad4a 100644 --- a/src/DS2431.h +++ b/src/DS2431.h @@ -11,10 +11,10 @@ class DS2431 : public OneWireItem { private: - static constexpr uint8_t MEM_SIZE{144}; + static constexpr uint8_t MEMORY_SIZE{144}; static constexpr uint8_t PAGE_SIZE{32}; - static constexpr uint8_t PAGE_COUNT{MEM_SIZE / PAGE_SIZE}; + static constexpr uint8_t PAGE_COUNT{MEMORY_SIZE / PAGE_SIZE}; static constexpr uint8_t PAGE_MASK{0b00011111}; static constexpr uint8_t SCRATCHPAD_SIZE{8}; @@ -28,7 +28,7 @@ class DS2431 : public OneWireItem static constexpr uint8_t WP_MODE{0x55}; // write protect mode static constexpr uint8_t EP_MODE{0xAA}; // eprom mode - uint8_t memory[MEM_SIZE]; + uint8_t memory[MEMORY_SIZE]; uint8_t scratchpad[SCRATCHPAD_SIZE]; uint8_t page_protection; diff --git a/src/DS2433.cpp b/src/DS2433.cpp index 21dae9c..c0f3a31 100644 --- a/src/DS2433.cpp +++ b/src/DS2433.cpp @@ -98,7 +98,7 @@ void DS2433::duty(OneWireHub *const hub) if (hub->recv(reinterpret_cast(®_TA), 2)) return; - for (uint16_t i = reg_TA; i < MEM_SIZE; + for (uint16_t i = reg_TA; i < MEMORY_SIZE; i += PAGE_SIZE) // model of the 32byte scratchpad { if (hub->send(&memory[i], PAGE_SIZE)) return; @@ -109,15 +109,15 @@ void DS2433::duty(OneWireHub *const hub) } } -void DS2433::clearMemory(void) { memset(memory, static_cast(0x00), MEM_SIZE); } +void DS2433::clearMemory(void) { memset(memory, static_cast(0x00), MEMORY_SIZE); } void DS2433::clearScratchpad(void) { memset(scratchpad, static_cast(0x00), PAGE_SIZE); } bool DS2433::writeMemory(const uint8_t *const source, const uint16_t length, const uint16_t position) { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(&memory[position], source, _length); return true; } @@ -125,8 +125,8 @@ bool DS2433::writeMemory(const uint8_t *const source, const uint16_t length, bool DS2433::readMemory(uint8_t *const destination, const uint16_t length, const uint16_t position) const { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(destination, &memory[position], _length); return (_length == length); } diff --git a/src/DS2433.h b/src/DS2433.h index 8086114..ad646f5 100644 --- a/src/DS2433.h +++ b/src/DS2433.h @@ -10,11 +10,11 @@ class DS2433 : public OneWireItem { private: - static constexpr uint16_t MEM_SIZE{512}; + static constexpr uint16_t MEMORY_SIZE{512}; static constexpr uint16_t MEM_MASK{0x01FF}; static constexpr uint8_t PAGE_SIZE{32}; - static constexpr uint16_t PAGE_COUNT{MEM_SIZE / PAGE_SIZE}; + static constexpr uint16_t PAGE_COUNT{MEMORY_SIZE / PAGE_SIZE}; static constexpr uint8_t PAGE_MASK{0b00011111}; static constexpr uint8_t REG_ES_PF_MASK{0b00100000}; // partial byte flag @@ -22,7 +22,7 @@ class DS2433 : public OneWireItem static constexpr uint8_t REG_ES_AA_MASK{ 0b10000000}; // authorization accepted (data copied to target memory) - uint8_t memory[MEM_SIZE]; // 4kbit max storage + uint8_t memory[MEMORY_SIZE]; // 4kbit max storage uint8_t scratchpad[PAGE_SIZE]; void clearScratchpad(void); diff --git a/src/DS2434.cpp b/src/DS2434.cpp index ae9731e..5c6e51c 100644 --- a/src/DS2434.cpp +++ b/src/DS2434.cpp @@ -137,7 +137,7 @@ void DS2434::duty(OneWireHub *const hub) } } -void DS2434::clearMemory(void) { memset(memory, static_cast(0xFF), MEM_SIZE); } +void DS2434::clearMemory(void) { memset(memory, static_cast(0xFF), MEMORY_SIZE); } void DS2434::clearScratchpad(void) { @@ -147,8 +147,8 @@ void DS2434::clearScratchpad(void) bool DS2434::writeMemory(const uint8_t *const source, const uint16_t length, const uint16_t position) { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(&memory[position], source, _length); return true; } @@ -156,8 +156,8 @@ bool DS2434::writeMemory(const uint8_t *const source, const uint16_t length, bool DS2434::readMemory(uint8_t *const destination, const uint16_t length, const uint16_t position) const { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(destination, &memory[position], _length); return (_length == length); } diff --git a/src/DS2434.h b/src/DS2434.h index 216e7ef..7ce799a 100644 --- a/src/DS2434.h +++ b/src/DS2434.h @@ -48,7 +48,7 @@ class DS2434 : public OneWireItem static constexpr uint8_t PAGE_SIZE{32}; static constexpr uint8_t PAGE_COUNT{5}; - static constexpr uint8_t MEM_SIZE{4 * PAGE_SIZE + + static constexpr uint8_t MEMORY_SIZE{4 * PAGE_SIZE + 4}; // Limit the memory size to the working space static constexpr uint8_t SCRATCHPAD_SIZE{3 * PAGE_SIZE}; // Scratchpad is used for first 3 pages @@ -58,7 +58,7 @@ class DS2434 : public OneWireItem uint32_t timer_nvwr = 0u; bool request_temp = false; - uint8_t memory[MEM_SIZE]; + uint8_t memory[MEMORY_SIZE]; uint8_t scratchpad[SCRATCHPAD_SIZE]; void clearScratchpad(void); diff --git a/src/DS2438.cpp b/src/DS2438.cpp index 053c08c..90a4650 100644 --- a/src/DS2438.cpp +++ b/src/DS2438.cpp @@ -94,8 +94,8 @@ void DS2438::clearMemory(void) bool DS2438::writeMemory(const uint8_t *const source, const uint8_t length, const uint8_t position) { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(&memory[position], source, _length); const uint8_t page_start = uint8_t(position >> 3); @@ -113,8 +113,8 @@ bool DS2438::writeMemory(const uint8_t *const source, const uint8_t length, cons bool DS2438::readMemory(uint8_t *const destination, const uint8_t length, const uint8_t position) const { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(destination, &memory[position], _length); return (_length == length); } diff --git a/src/DS2438.h b/src/DS2438.h index 28e567e..e2367aa 100644 --- a/src/DS2438.h +++ b/src/DS2438.h @@ -48,7 +48,7 @@ class DS2438 : public OneWireItem 8}; // how much of the real 8 pages should be emulated, use at least 1, max 8 static constexpr uint8_t PAGE_SIZE{8}; // - static constexpr uint8_t MEM_SIZE{PAGE_COUNT * PAGE_SIZE}; + static constexpr uint8_t MEMORY_SIZE{PAGE_COUNT * PAGE_SIZE}; // Register Addresses static constexpr uint8_t REG0_MASK_IAD{0x01}; // enable automatic current measurements @@ -60,7 +60,7 @@ class DS2438 : public OneWireItem static constexpr uint8_t REG0_MASK_ADB{0x40}; // adc busy flag uint8_t memory - [MEM_SIZE]; // this mem is the "scratchpad" in the datasheet., no EEPROM implemented + [MEMORY_SIZE]; // this mem is the "scratchpad" in the datasheet., no EEPROM implemented uint8_t crc [PAGE_COUNT + 1]; // keep the matching crc for each memory-page, reading can be very time-sensitive diff --git a/src/DS2450.cpp b/src/DS2450.cpp index be7ff9e..b39bcb4 100644 --- a/src/DS2450.cpp +++ b/src/DS2450.cpp @@ -20,7 +20,7 @@ void DS2450::duty(OneWireHub *const hub) { case 0xAA: // READ MEMORY - while (reg_TA < MEM_SIZE) + while (reg_TA < MEMORY_SIZE) { const uint8_t length = PAGE_SIZE - (uint8_t(reg_TA) & PAGE_MASK); if (hub->send(&memory[reg_TA], length, crc)) return; @@ -36,7 +36,7 @@ void DS2450::duty(OneWireHub *const hub) case 0x55: // write memory (only page 1&2 allowed) - while (reg_TA < MEM_SIZE) + while (reg_TA < MEMORY_SIZE) { uint8_t data; if (hub->recv(&data, 1, crc)) break; @@ -71,7 +71,7 @@ void DS2450::duty(OneWireHub *const hub) void DS2450::clearMemory(void) { constexpr uint8_t value_x00 = 0; - memset(memory, value_x00, MEM_SIZE); + memset(memory, value_x00, MEMORY_SIZE); // set power on defaults for (uint8_t adc = 0; adc < POTI_COUNT; ++adc) diff --git a/src/DS2450.h b/src/DS2450.h index feb09b7..c1a8c86 100644 --- a/src/DS2450.h +++ b/src/DS2450.h @@ -15,9 +15,9 @@ class DS2450 : public OneWireItem static constexpr uint8_t PAGE_SIZE{2 * POTI_COUNT}; static constexpr uint8_t PAGE_MASK{0b00000111}; - static constexpr uint8_t MEM_SIZE{PAGE_COUNT * PAGE_SIZE}; + static constexpr uint8_t MEMORY_SIZE{PAGE_COUNT * PAGE_SIZE}; - uint8_t memory[MEM_SIZE]; + uint8_t memory[MEMORY_SIZE]; // Page1 : conversion results: 16 bit for Channel A, B, C & D, power on default: 0x00 // Page2 : control / status: 16 bit per channel // Page3 : alarm settings: 16 bit per channel diff --git a/src/DS2502.cpp b/src/DS2502.cpp index d19b3c8..e3d2231 100644 --- a/src/DS2502.cpp +++ b/src/DS2502.cpp @@ -4,7 +4,7 @@ DS2502::DS2502(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID7) : OneWireItem(ID1, ID2, ID3, ID4, ID5, ID6, ID7) { - static_assert(MEM_SIZE < 256, "Implementation does not cover the whole address-space"); + static_assert(MEMORY_SIZE < 256, "Implementation does not cover the whole address-space"); clearMemory(); clearStatus(); @@ -142,7 +142,7 @@ uint8_t DS2502::translateRedirection(const uint8_t source_address) const return destin_address; } -void DS2502::clearMemory(void) { memset(memory, static_cast(0xFF), MEM_SIZE); } +void DS2502::clearMemory(void) { memset(memory, static_cast(0xFF), MEMORY_SIZE); } void DS2502::clearStatus(void) { @@ -152,8 +152,8 @@ void DS2502::clearStatus(void) bool DS2502::writeMemory(const uint8_t *const source, const uint8_t length, const uint8_t position) { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(&memory[position], source, _length); const uint8_t page_start = static_cast(position >> 5); @@ -166,8 +166,8 @@ bool DS2502::writeMemory(const uint8_t *const source, const uint8_t length, cons bool DS2502::readMemory(uint8_t *const destination, const uint8_t length, const uint8_t position) const { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(destination, &memory[position], _length); return (_length == length); } diff --git a/src/DS2502.h b/src/DS2502.h index 145bb15..bfc337b 100644 --- a/src/DS2502.h +++ b/src/DS2502.h @@ -14,8 +14,8 @@ class DS2502 : public OneWireItem static constexpr uint8_t PAGE_SIZE{32}; // bytes static constexpr uint8_t PAGE_MASK{PAGE_SIZE - 1}; - static constexpr uint8_t MEM_SIZE{PAGE_COUNT * PAGE_SIZE}; // bytes - static constexpr uint16_t MEM_MASK{MEM_SIZE - 1}; + static constexpr uint8_t MEMORY_SIZE{PAGE_COUNT * PAGE_SIZE}; // bytes + static constexpr uint16_t MEM_MASK{MEMORY_SIZE - 1}; static constexpr uint8_t STATUS_SIZE{8}; @@ -25,7 +25,7 @@ class DS2502 : public OneWireItem static constexpr uint8_t STATUS_UNDEF_B1{0x05}; // 2 byte -> reserved / undefined static constexpr uint8_t STATUS_FACTORYP{0x07}; // 2 byte -> factoryprogrammed 0x00 - uint8_t memory[MEM_SIZE]; // 4 pages of 32 bytes + uint8_t memory[MEMORY_SIZE]; // 4 pages of 32 bytes uint8_t status[STATUS_SIZE]; // eprom status bytes: uint8_t sizeof_memory; // device specific "real" size diff --git a/src/DS2506.cpp b/src/DS2506.cpp index 4e25e17..2dc0334 100644 --- a/src/DS2506.cpp +++ b/src/DS2506.cpp @@ -50,7 +50,7 @@ void DS2506::duty(OneWireHub *const hub) const uint16_t destin_TA = translateRedirection(reg_TA); const uint8_t length = PAGE_SIZE - uint8_t(reg_TA & PAGE_MASK); - if (destin_TA < MEM_SIZE) + if (destin_TA < MEMORY_SIZE) { if (hub->send(&memory[destin_TA], length, crc)) return; } @@ -85,7 +85,7 @@ void DS2506::duty(OneWireHub *const hub) const uint16_t destin_TA = translateRedirection(reg_TA); const uint8_t length = PAGE_SIZE - uint8_t(reg_TA & PAGE_MASK); - if (destin_TA < MEM_SIZE) + if (destin_TA < MEMORY_SIZE) { if (hub->send(&memory[destin_TA], length, crc)) return; } @@ -208,15 +208,15 @@ void DS2506::duty(OneWireHub *const hub) } } -void DS2506::clearMemory(void) { memset(memory, value_xFF, MEM_SIZE); } +void DS2506::clearMemory(void) { memset(memory, value_xFF, MEMORY_SIZE); } void DS2506::clearStatus(void) { memset(status, value_xFF, STATUS_SIZE); } bool DS2506::writeMemory(const uint8_t *const source, const uint16_t length, const uint16_t position) { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(&memory[position], source, _length); const uint8_t page_start = static_cast(position >> 5); @@ -229,8 +229,8 @@ bool DS2506::writeMemory(const uint8_t *const source, const uint16_t length, bool DS2506::readMemory(uint8_t *const destination, const uint16_t length, const uint16_t position) const { - if (position >= MEM_SIZE) return false; - const uint16_t _length = (position + length >= MEM_SIZE) ? (MEM_SIZE - position) : length; + if (position >= MEMORY_SIZE) return false; + const uint16_t _length = (position + length >= MEMORY_SIZE) ? (MEMORY_SIZE - position) : length; memcpy(destination, &memory[position], _length); return (_length == length); } diff --git a/src/DS2506.h b/src/DS2506.h index 5b51f45..17faf18 100644 --- a/src/DS2506.h +++ b/src/DS2506.h @@ -15,15 +15,15 @@ class DS2506 : public OneWireItem private: // Problem: atmega has 2kb RAM, this IC offers 8kb // Solution: out-of-bound-memory will be constant 0xFF, same for the depending status-registers - static constexpr uint16_t MEM_SIZE_PROPOSE{ + static constexpr uint16_t MEMORY_SIZE_PROPOSE{ 256}; // TUNE HERE! Give this device as much RAM as your CPU can spare static constexpr uint8_t PAGE_SIZE{32}; - static constexpr uint16_t PAGE_COUNT{MEM_SIZE_PROPOSE / PAGE_SIZE}; // ATM: 8 + static constexpr uint16_t PAGE_COUNT{MEMORY_SIZE_PROPOSE / PAGE_SIZE}; // ATM: 8 static constexpr uint8_t PAGE_MASK{0b00011111}; - static constexpr uint16_t MEM_SIZE{PAGE_COUNT * PAGE_SIZE}; - static constexpr uint16_t MEM_MASK{MEM_SIZE - 1}; + static constexpr uint16_t MEMORY_SIZE{PAGE_COUNT * PAGE_SIZE}; + static constexpr uint16_t MEM_MASK{MEMORY_SIZE - 1}; static constexpr uint8_t STATUS_SEGMENT{PAGE_COUNT / 8}; // ATM: 1 static constexpr uint16_t STATUS_SIZE{PAGE_COUNT + (3 * STATUS_SEGMENT)}; @@ -38,11 +38,11 @@ class DS2506 : public OneWireItem 0x100}; // 256 bytes -> Redirection to page, 0xFF if valid, ones complement (xFD is page 2) static constexpr uint16_t STATUS_UNDEF_B2_BEG{0x200}; - static_assert(MEM_SIZE > 255, "REAL MEM SIZE IS TOO SMALL"); + static_assert(MEMORY_SIZE > 255, "REAL MEM SIZE IS TOO SMALL"); static_assert(STATUS_SEGMENT > 0, "REAL MEM SIZE IS TOO SMALL"); - static_assert(MEM_SIZE <= 8192, "REAL MEM SIZE IS TOO BIG, MAX IS 8291 bytes"); + static_assert(MEMORY_SIZE <= 8192, "REAL MEM SIZE IS TOO BIG, MAX IS 8291 bytes"); - uint8_t memory[MEM_SIZE]; // at least 4 pages of 32 bytes + uint8_t memory[MEMORY_SIZE]; // at least 4 pages of 32 bytes uint8_t status[STATUS_SIZE]; // eprom status bytes uint16_t sizeof_memory; // device specific "real" size From 4b6c1349b1b20d88e93f4f0554a46363012cf320 Mon Sep 17 00:00:00 2001 From: KilDoom <117968565+KilDoomWise@users.noreply.github.com> Date: Sat, 7 Jun 2025 19:41:42 +0300 Subject: [PATCH 3/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4dd322c..9547ce7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # MODIFIED VERSION OF ONEWIREHUB WITH ESP32 SUPPORT FROM KILDOOM -# МОДИФИЦИРОВАННАЯ ВЕРСИЯ ONEWIREHUB С ПОДДЕРЖКОЙ ESP32 ОТ КИЛДУОМА +# МОДИФИЦИРОВАННАЯ ВЕРСИЯ ONEWIREHUB С ПОДДЕРЖКОЙ ESP32 ОТ КИЛДУМА # OneWireHub From 6fc5c6327cf807d52e0fa86652491f3a13bb4cfd Mon Sep 17 00:00:00 2001 From: KilDoom <117968565+KilDoomWise@users.noreply.github.com> Date: Sun, 14 Dec 2025 22:34:04 +0300 Subject: [PATCH 4/4] Update README.md --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 9547ce7..4ab852b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,3 @@ -# MODIFIED VERSION OF ONEWIREHUB WITH ESP32 SUPPORT FROM KILDOOM -# МОДИФИЦИРОВАННАЯ ВЕРСИЯ ONEWIREHUB С ПОДДЕРЖКОЙ ESP32 ОТ КИЛДУМА - # OneWireHub The OneWireHub is a sleek Arduino compatible (and many more platforms) library to emulate OneWire-Periphery with support for various devices & sensors. The motivation is to offer a shared code base for all OneWire-Periphery-Devices. With a small overhead one µC can emulate up to 32 ICs simultaneously.