periph / host

Go·Hardware·Lean - Host drivers
https://periph.io
Apache License 2.0
57 stars 32 forks source link

Serial Interface Update Question #18

Open schmidtw opened 2 years ago

schmidtw commented 2 years ago

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.

maruel commented 2 years ago

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.

schmidtw commented 2 years ago

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:

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

maruel commented 2 years ago

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

schmidtw commented 1 year ago

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