From 36937f3595911105d191fc46303c21d6dfa3f07d Mon Sep 17 00:00:00 2001 From: DrZlo13 Date: Fri, 27 Nov 2020 18:48:59 +1000 Subject: [PATCH] [FL-367] iButton app fixes by hw tests (#254) * do not exit after command parse * fix reset length time --- lib/onewire/one_wire_slave_gpio.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/onewire/one_wire_slave_gpio.cpp b/lib/onewire/one_wire_slave_gpio.cpp index 9e9cab7f6..9dbc4d7d5 100644 --- a/lib/onewire/one_wire_slave_gpio.cpp +++ b/lib/onewire/one_wire_slave_gpio.cpp @@ -33,13 +33,14 @@ void OneWireGpioSlave::stop(void) { } bool OneWireGpioSlave::emulate() { + bool anything_emulated = false; error = OneWireGpioSlaveError::NO_ERROR; while(1) { if(devices_count == 0) return false; if(!check_reset()) { - return false; + return anything_emulated; } else { } @@ -47,21 +48,21 @@ bool OneWireGpioSlave::emulate() { osKernelLock(); if(!show_presence()) { - return false; + return anything_emulated; } else { + anything_emulated = true; } // and we succefully show our presence on bus __disable_irq(); + // TODO think about return condition if(!receive_and_process_cmd()) { __enable_irq(); osKernelUnlock(); - return false; } else { __enable_irq(); osKernelUnlock(); - return (error == OneWireGpioSlaveError::NO_ERROR); } } } @@ -324,7 +325,9 @@ bool OneWireGpioSlave::check_reset(void) { } // if line is low, then just leave - if(gpio_read(gpio) == 0) return false; + if(gpio_read(gpio) == 0) { + return false; + } // wait while gpio is high if(wait_while_gpio_is(OWET::RESET_TIMEOUT, true) == 0) { @@ -332,7 +335,7 @@ bool OneWireGpioSlave::check_reset(void) { } // store low time - const OneWiteTimeType time_remaining = wait_while_gpio_is(OWET::RESET_MAX[0], false); + OneWiteTimeType time_remaining = wait_while_gpio_is(OWET::RESET_MAX[0], false); // low time more than RESET_MAX time if(time_remaining == 0) { @@ -340,6 +343,9 @@ bool OneWireGpioSlave::check_reset(void) { return false; } + // get real reset time + time_remaining = OWET::RESET_MAX[0] - time_remaining; + // if time, while bus was low, fit in standart reset timings if(overdrive_mode && ((OWET::RESET_MAX[0] - OWET::RESET_MIN[0]) <= time_remaining)) { // normal reset detected @@ -389,7 +395,7 @@ bool OneWireGpioSlave::receive_and_process_cmd(void) { // trigger reinit return true; - case 0x33: + case 0x33: // READ ROM // work only when one slave on the bus