diff --git a/uCNC/src/modules/softuart.c b/uCNC/src/modules/softuart.c index f31cc95c9..90646fe32 100644 --- a/uCNC/src/modules/softuart.c +++ b/uCNC/src/modules/softuart.c @@ -59,14 +59,13 @@ int16_t softuart_getc(softuart_port_t *port, uint32_t ms_timeout) } else { - ms_timeout *= 1000; + ms_timeout += mcu_millis(); while (port->rx()) { - if (!ms_timeout--) + if (ms_timeout > mcu_millis()) { return -1; } - cnc_dotasks(); } port->waithalf(); diff --git a/uCNC/src/modules/softuart.h b/uCNC/src/modules/softuart.h index 9ff8b7c2e..2a4dc9a37 100644 --- a/uCNC/src/modules/softuart.h +++ b/uCNC/src/modules/softuart.h @@ -41,16 +41,38 @@ extern "C" { \ if (state) \ { \ - io_set_output(TXPIN); \ + io_set_output(TXPIN); \ } \ else \ { \ - io_clear_output(TXPIN); \ + io_clear_output(TXPIN); \ } \ } \ bool NAME##_rx(void) \ { \ - return io_get_input(RXPIN); \ + return io_get_input(RXPIN); \ + } \ + void NAME##_wait(void) { mcu_delay_cycles(F_CPU / BAUD); } \ + void NAME##_waithalf(void) { mcu_delay_cycles(F_CPU / 2 / BAUD); } \ + __attribute__((used)) softuart_port_t NAME = {.wait = &NAME##_wait, .waithalf = &NAME##_waithalf, .tx = &NAME##_tx, .rx = &NAME##_rx}; + +#define ONEWIRE(NAME, BAUD, TRXPIN) \ + void NAME##_tx(bool state) \ + { \ + if (state) \ + { \ + io_config_input(TRXPIN); \ + io_config_pullup(TRXPIN); \ + } \ + else \ + { \ + io_clear_output(TRXPIN); \ + io_config_output(TRXPIN); \ + } \ + } \ + bool NAME##_rx(void) \ + { \ + return io_get_input(RXPIN); \ } \ void NAME##_wait(void) { mcu_delay_cycles(F_CPU / BAUD); } \ void NAME##_waithalf(void) { mcu_delay_cycles(F_CPU / 2 / BAUD); } \