Skip to content
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

emulation on host: Add full UART driver emulation. #5785

Merged
merged 12 commits into from Feb 22, 2019
Merged

emulation on host: Add full UART driver emulation. #5785

merged 12 commits into from Feb 22, 2019

Conversation

everslick
Copy link
Contributor

This PR replaces the high level Serial mock with a more complete UART driver. This way the HardwareSerial works without any modifications. Additionally the driver supports UART0 and UART1 at the same time (UART0 is directed to stdout and UART1 writes to stderr). RX is implemented by switching the terminal into raw non-blocking mode and injecting each key-press directly into the FIFO of UART0. A new command line switch -c was added to ignore CTRL-C and send it via serial as well. The decumentation was updated accordingly.

Reading and setting of GPIOs does only write to stderr, when compiled with D=1. But this is subject to be replaced with a proper GPIO emulation anyway. Reading from GPIO0 now returns 1 instead of 0 because this is most likely a low active input.

  This PR replaces the high level Serial mock with a more complete
  UART driver. This way the HardwareSerial works without any
  modifications. Additionally the driver supports UART0 and UART1
  at the same time (UART0 is directed to stdout and UART1 writes
  to stderr). RX is implemented by switching the terminal into raw
  non-blocking mode and injecting each key-press directly into the
  FIFO of UART0. A new command line switch -c was added to ignore
  CTRL-C and send it via serial as well. The decumentation was
  updated accordingly.

  Reading and setting of GPIOs does only write to stderr, when compiled
  with D=1. But this is subject to be replaced with a proper GPIO emu
  anyway. Reading from GPIO0 now returns 1 instead of 0 because this is
  most likely a low active input.
@d-a-v
Copy link
Collaborator

d-a-v commented Feb 21, 2019

@everslick Can you properly restore the terminal state after the double ^C,
I need to make a stty sane to restore echo.

Also is there a way to tell term to print \r\n when only \n is sent ?
Or, maybe with an option, tell mock serial to print another \r when \n is to be printed ?

@everslick
Copy link
Contributor Author

The restore is actually in, but I see it not working here as well. I'll have a look... The \r -> \r\n translation should be easy to add. I will commit something... thanks for the feedback! :-)

Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is running well, tested with WiFiTelnetToSerial, thanks !
I however have an issue. My terminal gets broken somewhere and can't be restored:

if (!isatty(STDIN))
{
    perror("isatty(STDIN)");
    //system("stty sane"); <- same error message "Inappropriate ioctl for device"
    return 0;
}

My terminal gets broken after I initialize ESP8266WebServer so I will track this bug myself, not the fault of this PR.

Can you check and perror-report on all tcget/setattr / isatty's like above ?

(funny system programming on an arduino core :)

@d-a-v d-a-v self-requested a review February 22, 2019 14:41
@d-a-v d-a-v merged commit ef44211 into esp8266:master Feb 22, 2019
@everslick everslick deleted the host-emu-uart branch February 22, 2019 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants