Skip to content

Update CDC.cpp - Remove delay in operator bool() #3437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions hardware/arduino/sam/cores/arduino/USB/CDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#define CDC_LINESTATE_READY (CDC_LINESTATE_RTS | CDC_LINESTATE_DTR)

uint32_t lineStateChangeTime = 0;

struct ring_buffer
{
uint8_t buffer[CDC_SERIAL_BUFFER_SIZE];
Expand Down Expand Up @@ -128,6 +130,7 @@ bool WEAK CDC_Setup(Setup& setup)
if (CDC_SET_CONTROL_LINE_STATE == r)
{
_usbLineInfo.lineState = setup.wValueL;
lineStateChangeTime = millis();
// auto-reset into the bootloader is triggered when the port, already
// open at 1200 bps, is closed.
if (1200 == _usbLineInfo.dwDTERate)
Expand Down Expand Up @@ -290,12 +293,11 @@ Serial_::operator bool()

bool result = false;

if (_usbLineInfo.lineState > 0)
if (_usbLineInfo.lineState > 0 && ((millis() - lineStateChangeTime) >= 10))
{
result = true;
}

delay(10);
return result;
}

Expand Down