Skip to content

Commit

Permalink
modified softuart fix
Browse files Browse the repository at this point in the history
- reverted softuart change to rx pin listening (tighter loop)
- added UART onewire solution to be tested with TMC
  • Loading branch information
Paciente8159 committed Jan 25, 2024
1 parent 4953d86 commit ef7c469
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
5 changes: 2 additions & 3 deletions uCNC/src/modules/softuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
28 changes: 25 additions & 3 deletions uCNC/src/modules/softuart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); } \
Expand Down

0 comments on commit ef7c469

Please sign in to comment.