[FL-367] iButton app fixes by hw tests (#254)

* do not exit after command parse
* fix reset length time
This commit is contained in:
DrZlo13 2020-11-27 18:48:59 +10:00 committed by GitHub
parent 1f761d7fbb
commit 36937f3595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,13 +33,14 @@ void OneWireGpioSlave::stop(void) {
} }
bool OneWireGpioSlave::emulate() { bool OneWireGpioSlave::emulate() {
bool anything_emulated = false;
error = OneWireGpioSlaveError::NO_ERROR; error = OneWireGpioSlaveError::NO_ERROR;
while(1) { while(1) {
if(devices_count == 0) return false; if(devices_count == 0) return false;
if(!check_reset()) { if(!check_reset()) {
return false; return anything_emulated;
} else { } else {
} }
@ -47,21 +48,21 @@ bool OneWireGpioSlave::emulate() {
osKernelLock(); osKernelLock();
if(!show_presence()) { if(!show_presence()) {
return false; return anything_emulated;
} else { } else {
anything_emulated = true;
} }
// and we succefully show our presence on bus // and we succefully show our presence on bus
__disable_irq(); __disable_irq();
// TODO think about return condition
if(!receive_and_process_cmd()) { if(!receive_and_process_cmd()) {
__enable_irq(); __enable_irq();
osKernelUnlock(); osKernelUnlock();
return false;
} else { } else {
__enable_irq(); __enable_irq();
osKernelUnlock(); osKernelUnlock();
return (error == OneWireGpioSlaveError::NO_ERROR);
} }
} }
} }
@ -324,7 +325,9 @@ bool OneWireGpioSlave::check_reset(void) {
} }
// if line is low, then just leave // 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 // wait while gpio is high
if(wait_while_gpio_is(OWET::RESET_TIMEOUT, true) == 0) { if(wait_while_gpio_is(OWET::RESET_TIMEOUT, true) == 0) {
@ -332,7 +335,7 @@ bool OneWireGpioSlave::check_reset(void) {
} }
// store low time // 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 // low time more than RESET_MAX time
if(time_remaining == 0) { if(time_remaining == 0) {
@ -340,6 +343,9 @@ bool OneWireGpioSlave::check_reset(void) {
return false; 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 time, while bus was low, fit in standart reset timings
if(overdrive_mode && ((OWET::RESET_MAX[0] - OWET::RESET_MIN[0]) <= time_remaining)) { if(overdrive_mode && ((OWET::RESET_MAX[0] - OWET::RESET_MIN[0]) <= time_remaining)) {
// normal reset detected // normal reset detected