host icon indicating copy to clipboard operation
host copied to clipboard

Serial Interface Update Question

Open schmidtw opened this issue 2 years ago • 4 comments

The serial port sub-system was mentioned as one that you're ok bringing in other implementations.

I'm presently using this one as the basis for a ds2480 1-wire chip: https://github.com/bugst/go-serial. Based on my searching this seems to be the best cross-platform, no cgo version around.

I'm curious how you envision supporting other impls. I think the conn.Conn interface works for most simple serial devices, but the Connect() function may not be enough to support devices like a ds2480, where uart focused changes need to happen on the fly.

If there is a set of interfaces that are the right ones for implementing as external serial port adapters, then it will be pretty easy to write a small adapter library. The adapter can be external to the host project (like periph/bugst-serial-adapter) that can adapt the two & allow for the drivers & that logic to live in periph/drivers.

I'm happy to do the coding for these two things (ds2480 and the bugst/go-serial bridge) as long as I know what you want it to look like & you're cool with the approach.

schmidtw avatar Oct 02 '22 01:10 schmidtw

You mention Connect, you mean https://pkg.go.dev/periph.io/x/conn/v3/uart#Port ? I'm confused because you refer to 1-wire but the 1-wire API doesn't have a Connect() function; https://pkg.go.dev/periph.io/x/conn/v3/onewire

This is because UART is a Port, and 1-wire is a Bus.

maruel avatar Oct 03 '22 12:10 maruel

Sorry for the confusion. I'll try to clarify.

I am interested in doing is bringing support in for the ds2480 chip (serial <-> 1-wire adapter chip). For our purposes, only the serial side of the chip is of concern.

I looked at the Port interface but it doesn't seem flexible enough to support the ds2480 chip for a few reasons:

  1. The baud rate needs to change after the connection is made.
  2. Input and output buffers need be able to be flushed.
  3. All the control pins aren't available.
  4. Hardware level timeouts aren't available.

This interface: https://pkg.go.dev/go.bug.st/serial#pkg-types does a pretty good job of showing the different features a serial interface needs. Specifically, the methods I am using from that interface that don't appear to have equivalents are:

  • SetMode() - unless the uart Port.Connect() will allow for changes without connection interruption.
  • ResetInputBuffer()
  • ResetOutputBuffer()
  • SetReadTimeout()

The ds2480 driver code needs to change the serial port to operate & needs an interface to be portable to all the supported serial implementations.

schmidtw avatar Oct 03 '22 16:10 schmidtw

Oh ok so it would work over UART instead of I2C like https://pkg.go.dev/periph.io/x/devices/v3/ds248x does?

maruel avatar Oct 04 '22 19:10 maruel

Yes, that's right. Sorry for the delay - I missed the update email & just saw your post.

schmidtw avatar Dec 17 '22 19:12 schmidtw