Skip to content

Commit

Permalink
Implement Serial.availableForWrite() for serial emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulStoffregen committed Jan 27, 2024
1 parent 9a0eef6 commit dd6aa84
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion teensy4/usb_seremu.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,15 @@ int usb_seremu_write(const void *buffer, uint32_t size)

int usb_seremu_write_buffer_free(void)
{
return 1;
uint32_t sum = 0;
tx_noautoflush = 1;
for (uint32_t i=0; i < TX_NUM; i++) {
if (i == tx_head) continue; // never promise current buffer, might autoflush
if (!(usb_transfer_status(tx_transfer + i) & 0x80)) sum += SEREMU_TX_SIZE;
}
asm("dsb" ::: "memory");
tx_noautoflush = 0;
return sum;
}

void usb_seremu_flush_output(void)
Expand Down

0 comments on commit dd6aa84

Please sign in to comment.