From d710ca5530efb456983008c19d8496e8c09e7a75 Mon Sep 17 00:00:00 2001 From: mikaelpatel Date: Tue, 10 Oct 2017 17:56:58 +0200 Subject: [PATCH] Refactoring hardware bus manager support --- README.md | 8 +- examples/Alarm/Alarm.ino | 21 ++- examples/DS18B20/DS18B20.ino | 19 +- examples/DS2482/DS2482.ino | 122 ------------ examples/Scanner/Scanner.ino | 7 +- examples/Search/Search.ino | 7 +- library.properties | 2 +- mainpage.dox | 2 +- src/Hardware/OWI.h | 346 +++-------------------------------- src/OWI.h | 30 ++- src/Software/OWI.h | 11 +- 11 files changed, 100 insertions(+), 475 deletions(-) delete mode 100644 examples/DS2482/DS2482.ino diff --git a/README.md b/README.md index 16304d3..976da52 100644 --- a/README.md +++ b/README.md @@ -5,23 +5,21 @@ based software and DS2482 based hardware bus manager, and device driver for DS18B20. The examples directory contains device search, bus scanner, -thermometer alarm search, and example sketches for DS18B20, DS1990A -and DS2482. +thermometer alarm search, and example sketches for DS18B20 and +DS1990A. -Version: 1.6 +Version: 1.7 ## Classes * [Abstract One-Wire Bus Manager and Device Interface, OWI](./src/OWI.h) * [Software One-Wire Bus Manager, GPIO, Software::OWI](./src/Software/OWI.h) -* [Hardware One-Wire Bus Manager, DS2482, Hardware::OWI](./src/Hardware/OWI.h) * [Programmable Resolution 1-Wire Digital Thermometer, DS18B20](./src/Driver/DS18B20.h) ## Example Sketches * [DS18B20](./examples/DS18B20) * [DS1990A](./examples/DS1990A) -* [DS2482](./examples/DS2482) * [Alarm](./examples/Alarm) * [Scanner](./examples/Scanner) * [Search](./examples/Search) diff --git a/examples/Alarm/Alarm.ino b/examples/Alarm/Alarm.ino index cf468be..19e2555 100644 --- a/examples/Alarm/Alarm.ino +++ b/examples/Alarm/Alarm.ino @@ -9,12 +9,17 @@ Software::OWI owi; #else +#include "TWI.h" #include "Hardware/OWI.h" // Configure: Software/Hardware TWI Bus Manager // #define USE_SOFTWARE_TWI #if defined(USE_SOFTWARE_TWI) #include "Software/TWI.h" +#if defined(SAM) +Software::TWI twi; +#else Software::TWI twi; +#endif #else #include "Hardware/TWI.h" Hardware::TWI twi; @@ -24,6 +29,16 @@ Hardware::OWI owi(twi); DS18B20 sensor(owi); +#define ASSERT(expr) \ + do { \ + if (!(expr)) { \ + Serial.print(__LINE__); \ + Serial.println(F(":assert:" #expr)); \ + Serial.flush(); \ + exit(0); \ + } \ + } while (0) + void setup() { Serial.begin(57600); @@ -38,7 +53,7 @@ void setup() if (last == owi.ERROR) break; sensor.resolution(10); sensor.set_trigger(20, 25); - sensor.write_scratchpad(); + ASSERT(sensor.write_scratchpad()); } while (last != owi.LAST); } @@ -50,7 +65,6 @@ void loop() int8_t last = owi.FIRST; uint8_t* rom = sensor.rom(); - bool triggered = false; static uint16_t timestamp = 0; uint8_t id = 0; if (!sensor.convert_request(true)) return; @@ -58,8 +72,7 @@ void loop() do { last = owi.alarm_search(rom, last); if (last == owi.ERROR) break; - triggered = true; - sensor.read_scratchpad(false); + ASSERT(sensor.read_scratchpad(false)); Serial.print(timestamp); Serial.print('.'); Serial.print(id++); diff --git a/examples/DS18B20/DS18B20.ino b/examples/DS18B20/DS18B20.ino index d9ea9c2..04008e9 100644 --- a/examples/DS18B20/DS18B20.ino +++ b/examples/DS18B20/DS18B20.ino @@ -9,12 +9,17 @@ Software::OWI owi; #else -#include "Hardware/OWI.h" // Configure: Software/Hardware TWI Bus Manager // #define USE_SOFTWARE_TWI +#include "TWI.h" +#include "Hardware/OWI.h" #if defined(USE_SOFTWARE_TWI) #include "Software/TWI.h" +#if defined(SAM) +Software::TWI twi; +#else Software::TWI twi; +#endif #else #include "Hardware/TWI.h" Hardware::TWI twi; @@ -24,6 +29,16 @@ Hardware::OWI owi(twi); DS18B20 sensor(owi); +#define ASSERT(expr) \ + do { \ + if (!(expr)) { \ + Serial.print(__LINE__); \ + Serial.println(F(":assert:" #expr)); \ + Serial.flush(); \ + exit(0); \ + } \ + } while (0) + void setup() { Serial.begin(57600); @@ -47,7 +62,7 @@ void loop() if (last == owi.ERROR) break; // Read the scratchpad with current temperature, tiggers, etc - sensor.read_scratchpad(false); + ASSERT(sensor.read_scratchpad(false)); int8_t low, high; sensor.get_trigger(low, high); diff --git a/examples/DS2482/DS2482.ino b/examples/DS2482/DS2482.ino deleted file mode 100644 index 83271a0..0000000 --- a/examples/DS2482/DS2482.ino +++ /dev/null @@ -1,122 +0,0 @@ -#include "GPIO.h" -#include "OWI.h" -#include "TWI.h" -#include "Hardware/OWI.h" -#include - -#define USE_SOFTWARE_TWI -#if defined(USE_SOFTWARE_TWI) -#include "Software/TWI.h" -Software::TWI twi; -#else -#include "Hardware/TWI.h" -Hardware::TWI twi; -#endif - -Hardware::OWI owi(twi); - -// DS18B20 Commands -enum { - CONVERT_T = 0x44, - READ_SCRATCHPAD = 0xbe -}; - -// DS18B20 Scratchpad Memory -struct scratchpad_t { - int16_t temperature; - int8_t high_trigger; - int8_t low_trigger; - uint8_t configuration; - uint8_t reserved[3]; - uint8_t crc; -}; - -#define TRACE(expr) \ - do { \ - Serial.print(#expr "="); \ - Serial.println(expr); \ - } while (0) - -void setup() -{ - Serial.begin(57600); - while (!Serial); - - TRACE(owi.device_reset()); - TRACE(owi.device_config()); - TRACE(owi.set_read_pointer(owi.READ_DATA_REGISTER)); - TRACE(owi.set_read_pointer(owi.CONFIGURATION_REGISTER)); - TRACE(owi.set_read_pointer(owi.CHANNEL_SELECTION_REGISTER)); - TRACE(owi.set_read_pointer(owi.STATUS_REGISTER)); - - uint8_t rom[owi.ROM_MAX] = { 0 }; - uint8_t crc = 0; - TRACE(owi.reset()); - Serial.print(F("rom=")); - owi.write(owi.READ_ROM); - for (size_t i = 0; i < sizeof(rom); i++) { - rom[i] = owi.read(8); - if (rom[i] < 0x10) Serial.print(0); - Serial.print(rom[i], HEX); - crc = _crc_ibutton_update(crc, rom[i]); - } - Serial.print(F(", crc=")); - Serial.println(crc); - - uint8_t value = 0; - uint8_t bits = 0; - uint8_t ix = 0; - uint8_t res = 0; - uint8_t dir = 0; - bool id; - bool nid; - crc = 0; - TRACE(owi.reset()); - Serial.print(F("rom=")); - owi.write(owi.SEARCH_ROM); - do { - res = owi.triplet(dir); - id = (res & 1) != 0; - nid = (res & 2) != 0; - value = (value >> 1); - if (dir) value |= 0x80; - bits += 1; - if (bits == CHARBITS) { - rom[ix] = value; - if (rom[ix] < 0x10) Serial.print(0); - Serial.print(rom[ix], HEX); - crc = _crc_ibutton_update(crc, rom[ix]); - ix += 1; - bits = 0; - value = 0; - } - } while (id != nid); - Serial.print(F(", crc=")); - Serial.println(crc); -} - -void loop() -{ - owi.reset(); - owi.write(owi.SKIP_ROM); - owi.write(CONVERT_T); - delay(750); - - owi.reset(); - owi.write(owi.SKIP_ROM); - owi.write(READ_SCRATCHPAD); - - scratchpad_t scratchpad; - uint8_t* p = (uint8_t*) &scratchpad; - uint8_t crc = 0; - for (size_t i = 0; i < sizeof(scratchpad); i++) { - p[i] = owi.read(); - crc = _crc_ibutton_update(crc, p[i]); - } - if (crc == 0) { - float temperature = scratchpad.temperature * 0.0625; - TRACE(temperature); - } else - TRACE(crc); - delay(2000); -} diff --git a/examples/Scanner/Scanner.ino b/examples/Scanner/Scanner.ino index 00070f5..e21bfcc 100644 --- a/examples/Scanner/Scanner.ino +++ b/examples/Scanner/Scanner.ino @@ -8,12 +8,17 @@ Software::OWI owi; #else -#include "Hardware/OWI.h" // Configure: Software/Hardware TWI Bus Manager // #define USE_SOFTWARE_TWI +#include "TWI.h" +#include "Hardware/OWI.h" #if defined(USE_SOFTWARE_TWI) #include "Software/TWI.h" +#if defined(SAM) +Software::TWI twi; +#else Software::TWI twi; +#endif #else #include "Hardware/TWI.h" Hardware::TWI twi; diff --git a/examples/Search/Search.ino b/examples/Search/Search.ino index 33ea1cc..b4781a1 100644 --- a/examples/Search/Search.ino +++ b/examples/Search/Search.ino @@ -8,12 +8,17 @@ Software::OWI owi; #else -#include "Hardware/OWI.h" // Configure: Software/Hardware TWI Bus Manager // #define USE_SOFTWARE_TWI +#include "TWI.h" +#include "Hardware/OWI.h" #if defined(USE_SOFTWARE_TWI) #include "Software/TWI.h" +#if defined(SAM) +Software::TWI twi; +#else Software::TWI twi; +#endif #else #include "Hardware/TWI.h" Hardware::TWI twi; diff --git a/library.properties b/library.properties index 4515910..31239f8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino-OWI -version=1.6 +version=1.7 author=Mikael Patel maintainer=Mikael Patel sentence=One-Wire Interface (OWI) library for Arduino. diff --git a/mainpage.dox b/mainpage.dox index 45f3cfc..6aa5a7a 100644 --- a/mainpage.dox +++ b/mainpage.dox @@ -5,7 +5,7 @@ The OWI library has been developed to support the implementation of based Software::OWI bus manager, DS2482 based Hardware::OWI bus manager, and device driver for DS18B20. -Version: 1.6 +Version: 1.7 */ /** @page License diff --git a/src/Hardware/OWI.h b/src/Hardware/OWI.h index 5cd589b..002a37d 100644 --- a/src/Hardware/OWI.h +++ b/src/Hardware/OWI.h @@ -20,14 +20,14 @@ #define HARDWARE_OWI_H #include "OWI.h" -#include "TWI.h" +#include "Driver/DS2482.h" /** * One Wire Interface (OWI) Bus Manager class using DS2482, * Single-Channel 1-Wire Master, TWI to OWI Bridge Device. */ namespace Hardware { -class OWI : public ::OWI, protected TWI::Device { +class OWI : public ::OWI { public: /** * Construct one wire bus manager for DS2482. @@ -35,7 +35,7 @@ class OWI : public ::OWI, protected TWI::Device { * @param[in] subaddr sub-address for device. */ OWI(TWI& twi, uint8_t subaddr = 0) : - TWI::Device(twi, 0x18 | (subaddr & 0x03)) + m_bridge(twi, 0x18 | (subaddr & 0x03)) { } @@ -47,27 +47,7 @@ class OWI : public ::OWI, protected TWI::Device { */ virtual bool reset() { - status_t status; - uint8_t cmd; - int count; - - // Issue one wire reset command - cmd = ONE_WIRE_RESET; - if (!TWI::Device::acquire()) return (false); - count = TWI::Device::write(&cmd, sizeof(cmd)); - if (count != sizeof(cmd)) goto error; - - // Wait for one wire operation to complete - for (int i = 0; i < POLL_MAX; i++) { - count = TWI::Device::read(&status, sizeof(status)); - if (count == sizeof(status) && !status.IWB) break; - } - if (!TWI::Device::release()) return (false); - return ((count == sizeof(status)) && status.PPD); - - error: - TWI::Device::release(); - return (false); + return (m_bridge.one_wire_reset()); } /** @@ -79,42 +59,21 @@ class OWI : public ::OWI, protected TWI::Device { */ virtual uint8_t read(uint8_t bits = CHARBITS) { - status_t status; - uint8_t cmd; - int count; - - // Check for bit read - if (bits != CHARBITS) { + uint8_t res = 0; + if (bits == CHARBITS) { + m_bridge.one_wire_read_byte(res); + } + else { uint8_t adjust = CHARBITS - bits; - uint8_t res = 0; + bool value = 0; while (bits--) { res >>= 1; - if (read_bit()) res |= 0x80; + m_bridge.one_wire_read_bit(value); + if (value) res |= 0x80; } res >>= adjust; - return (res); } - - // Issue one wire read byte command - cmd = ONE_WIRE_READ_BYTE; - if (!TWI::Device::acquire()) return (false); - count = TWI::Device::write(&cmd, sizeof(cmd)); - if (count != sizeof(cmd)) goto error; - - // Wait for one wire operation to complete - for (int i = 0; i < POLL_MAX; i++) { - count = TWI::Device::read(&status, sizeof(status)); - if (count == sizeof(status) && !status.IWB) break; - } - if (!TWI::Device::release()) return (false); - if ((count != sizeof(status)) || status.IWB) return (0); - - // Read data register value - return (set_read_pointer(READ_DATA_REGISTER)); - - error: - TWI::Device::release(); - return (0); + return (res); } /** @@ -126,33 +85,15 @@ class OWI : public ::OWI, protected TWI::Device { */ virtual void write(uint8_t value, uint8_t bits = CHARBITS) { - status_t status; - uint8_t cmd[2]; - int count; - - // Issue one wire write byte command with given data - if (bits != CHARBITS) { + if (bits == CHARBITS) { + m_bridge.one_wire_write_byte(value); + } + else { while (bits--) { - write_bit(value & 0x01); + m_bridge.one_wire_write_bit(value & 0x01); value >>= 1; } - return; } - - cmd[0] = ONE_WIRE_WRITE_BYTE; - cmd[1] = value; - if (!TWI::Device::acquire()) return; - count = TWI::Device::write(cmd, sizeof(cmd)); - if (count != sizeof(cmd)) goto error; - - // Wait for one wire operation to complete - for (int i = 0; i < POLL_MAX; i++) { - count = TWI::Device::read(&status, sizeof(status)); - if (count == sizeof(status) && !status.IWB) break; - } - - error: - TWI::Device::release(); } /** @@ -166,30 +107,7 @@ class OWI : public ::OWI, protected TWI::Device { */ virtual int8_t triplet(uint8_t& dir) { - status_t status; - uint8_t cmd[2]; - int count; - - // Issue one wire single bit command with given data - cmd[0] = ONE_WIRE_TRIPLET; - cmd[1] = (dir ? 0x80 : 0x00); - if (!TWI::Device::acquire()) return (ERROR); - count = TWI::Device::write(cmd, sizeof(cmd)); - if (count != sizeof(cmd)) goto error; - - // Wait for one wire operation to complete - for (int i = 0; i < POLL_MAX; i++) { - count = TWI::Device::read(&status, sizeof(status)); - if (count == sizeof(status) && !status.IWB) break; - } - if (!TWI::Device::release()) return (ERROR); - if (count != sizeof(status) && status.IWB) return (ERROR); - dir = status.DIR; - return ((status >> 5) & 0x3); - - error: - TWI::Device::release(); - return (ERROR); + return (m_bridge.one_wire_triplet(dir)); } /** @@ -199,24 +117,7 @@ class OWI : public ::OWI, protected TWI::Device { */ bool device_reset() { - status_t status; - uint8_t cmd; - int count; - - // Issue device reset command - cmd = DEVICE_RESET; - if (!TWI::Device::acquire()) return (false); - count = TWI::Device::write(&cmd, sizeof(cmd)); - if (count != sizeof(cmd)) goto error; - - // Check status register for device reset - count = TWI::Device::read(&status, sizeof(status)); - if (!TWI::Device::release()) return (false); - return ((count == sizeof(status)) && status.RST); - - error: - TWI::Device::release(); - return (false); + return (m_bridge.device_reset()); } /** @@ -227,73 +128,9 @@ class OWI : public ::OWI, protected TWI::Device { * @param[in] iws one wire speed (default false). * @return bool. */ - bool device_config(bool apu = true, bool spu = false, bool iws = false) + bool device_configuration(bool apu = true, bool spu = false, bool iws = false) { - config_t config; - status_t status; - uint8_t cmd[2]; - int count; - - // Set configuration bit-fields - config.APU = apu; - config.SPU = spu; - config.IWS = iws; - config.COMP = ~config; - - // Issue write configuration command with given setting - cmd[0] = WRITE_CONGIFURATION; - cmd[1] = config; - if (!TWI::Device::acquire()) return (false); - count = TWI::Device::write(cmd, sizeof(cmd)); - if (count != sizeof(cmd)) goto error; - - // Read status and check configuration - count = TWI::Device::read(&status, sizeof(status)); - if (!TWI::Device::release()) return (false); - return ((count == sizeof(status)) && !status.RST); - - error: - TWI::Device::release(); - return (false); - } - - /** - * Device Registers, pp. 5. Valid Pointer Codes, pp. 10. - */ - enum Register { - STATUS_REGISTER = 0xf0, - READ_DATA_REGISTER = 0xe1, - CHANNEL_SELECTION_REGISTER = 0xd2, - CONFIGURATION_REGISTER = 0xc3 - } __attribute__((packed)); - - /** - * Set the read pointer to the specified register. Return register - * value or negative error code. - * @param[in] addr register address. - * @return register value or negative error code. - */ - int set_read_pointer(Register addr) - { - uint8_t cmd[2]; - uint8_t reg; - int count; - - // Issue set read pointer command with given pointer - cmd[0] = SET_READ_POINTER; - cmd[1] = (uint8_t) addr; - if (!TWI::Device::acquire()) return (-1); - count = TWI::Device::write(cmd, sizeof(cmd)); - if (count != sizeof(cmd)) goto error; - - // Read register value - count = TWI::Device::read(®, sizeof(reg)); - if (!TWI::Device::release()) return (false); - return ((count == sizeof(reg)) ? reg : -1); - - error: - TWI::Device::release(); - return (-1); + return (m_bridge.write_configuration(apu, spu, iws)); } /** @@ -304,146 +141,11 @@ class OWI : public ::OWI, protected TWI::Device { */ bool channel_select(uint8_t chan) { - uint8_t cmd[2]; - int count; - - // Check channel number - if (chan > 7) return (false); - - // Issue channel select command with channel code - cmd[0] = CHANNEL_SELECT; - cmd[1] = (~chan << 4) | chan; - if (!TWI::Device::acquire()) return (false); - count = TWI::Device::write(cmd, sizeof(cmd)); - if (!TWI::Device::release()) return (false); - return (count == sizeof(cmd)); + return (m_bridge.channel_select(chan)); } protected: - /** - * Function Commands, pp. 9-15. - */ - enum { - DEVICE_RESET = 0xf0, //!< Device Reset. - SET_READ_POINTER = 0xe1, //!< Set Read Pointer. - WRITE_CONGIFURATION = 0xd2, //!< Write Configuration. - CHANNEL_SELECT = 0xc3, //!< Channel Select. - ONE_WIRE_RESET = 0xb4, //!< 1-Wire Reset. - ONE_WIRE_SINGLE_BIT = 0x87, //!< 1-Wire Single Bit. - ONE_WIRE_WRITE_BYTE = 0xa5, //!< 1-Wire Write Byte. - ONE_WIRE_READ_BYTE = 0x96, //!< 1-Wire Read Byte. - ONE_WIRE_TRIPLET = 0x78 //!< 1-Wire Triplet. - } __attribute__((packed)); - - /** - * Status Register, bit-fields, pp. 8-9. - */ - union status_t { - uint8_t as_uint8; //!< Unsigned byte access. - struct { //!< Bitfield access (little endian). - uint8_t IWB:1; //!< 1-Wire Busy. - uint8_t PPD:1; //!< Presence-Pulse Detect. - uint8_t SD:1; //!< Short Detected. - uint8_t LL:1; //!< Logic Level. - uint8_t RST:1; //!< Device Reset. - uint8_t SBR:1; //!< Single Bit Result. - uint8_t TSB:1; //!< Triplet Second Bit. - uint8_t DIR:1; //!< Branch Direction Taken. - }; - operator uint8_t() - { - return (as_uint8); - } - }; - - /** - * Configuration Register, bit-fields, pp. 5-6. - */ - union config_t { - uint8_t as_uint8; //!< Unsigned byte access. - struct { //!< Bitfield access (little endian). - uint8_t APU:1; //!< Active Pullup. - uint8_t ZERO:1; //!< Always Zero(0). - uint8_t SPU:1; //!< Strong Pullup. - uint8_t IWS:1; //!< 1-Wire Speed. - uint8_t COMP:4; //!< Complement of lower 4-bits. - }; - operator uint8_t() - { - return (as_uint8); - } - config_t() - { - as_uint8 = 0; - } - }; - - /** Number of one-wire polls */ - static const int POLL_MAX = 20; - - /** - * Read a single bit from one wire bus. Returns bit value (0 or 1) - * or a negative error code. - * @return bit read. - */ - bool read_bit() - { - status_t status; - uint8_t cmd[2]; - int count; - - // Issue one wire single bit command with read data time slot - cmd[0] = ONE_WIRE_SINGLE_BIT; - cmd[1] = 0x80; - if (!TWI::Device::acquire()) return (false); - count = TWI::Device::write(cmd, sizeof(cmd)); - if (count != sizeof(cmd)) goto error; - - // Wait for one wire operation to complete - for (int i = 0; i < POLL_MAX; i++) { - count = TWI::Device::read(&status, sizeof(status)); - if (count == sizeof(status) && !status.IWB) break; - } - if (!TWI::Device::release()) return (false); - if (count != sizeof(status) || status.IWB) return (false); - return (status.SBR); - - error: - TWI::Device::release(); - return (false); - } - - /** - * Write a single bit to one wire bus. Returns true if successful - * otherwise false. - * @param[in] value bit to write. - * @return bool. - */ - bool write_bit(bool value) - { - status_t status; - uint8_t cmd[2]; - int count; - - // Issue one wire single bit command with given data - cmd[0] = ONE_WIRE_SINGLE_BIT; - cmd[1] = (value ? 0x80 : 0x00); - if (!TWI::Device::acquire()) return (false); - count = TWI::Device::write(cmd, sizeof(cmd)); - if (count != sizeof(cmd)) goto error; - - // Wait for one wire operation to complete - for (int i = 0; i < POLL_MAX; i++) { - count = TWI::Device::read(&status, sizeof(status)); - if (count == sizeof(status) && !status.IWB) break; - } - if (!TWI::Device::release()) return (false); - return ((count == sizeof(status)) && !status.IWB); - - error: - TWI::Device::release(); - return (false); - } + DS2482 m_bridge; }; }; #endif diff --git a/src/OWI.h b/src/OWI.h index 615ec4e..6f46907 100644 --- a/src/OWI.h +++ b/src/OWI.h @@ -61,9 +61,13 @@ class OWI { bool read(void* buf, size_t count) { uint8_t* bp = (uint8_t*) buf; - m_crc = 0; - while (count--) *bp++ = read(); - return (m_crc == 0); + uint8_t crc = 0; + while (count--) { + uint8_t value = read(); + *bp++ = value; + crc = crc_update(crc, value); + } + return (crc == 0); } /** @@ -257,13 +261,27 @@ class OWI { ALARM_SEARCH = 0xEC //!< Initiate device alarm search. } __attribute__((packed)); + /** + * Optimized Dallas (now Maxim) iButton 8-bit CRC calculation. + * Polynomial: x^8 + x^5 + x^4 + 1 (0x8C) Initial value: 0x0 + * See http://www.maxim-ic.com/appnotes.cfm/appnote_number/27 + */ + static uint8_t crc_update(uint8_t crc, uint8_t data) + { + crc = crc ^ data; + for (uint8_t i = 0; i < 8; i++) { + if (crc & 0x01) + crc = (crc >> 1) ^ 0x8C; + else + crc >>= 1; + } + return (crc); + } + protected: /** Maximum number of reset retries. */ static const uint8_t RESET_RETRY_MAX = 4; - /** Intermediate CRC sum. */ - uint8_t m_crc; - /** * Search device rom given the last position of discrepancy and * partial or full rom code. diff --git a/src/Software/OWI.h b/src/Software/OWI.h index b4ffe94..9c4ff7d 100644 --- a/src/Software/OWI.h +++ b/src/Software/OWI.h @@ -73,7 +73,6 @@ class OWI : public ::OWI { { uint8_t adjust = CHARBITS - bits; uint8_t res = 0; - uint8_t mix = 0; while (bits--) { noInterrupts(); m_pin.output(); @@ -81,15 +80,7 @@ class OWI : public ::OWI { m_pin.input(); delayMicroseconds(9); res >>= 1; - if (m_pin) { - res |= 0x80; - mix = (m_crc ^ 1); - } - else { - mix = (m_crc ^ 0); - } - m_crc >>= 1; - if (mix & 1) m_crc ^= 0x8C; + res |= (m_pin ? 0x80 : 0x00); interrupts(); delayMicroseconds(55); }