spi: Rename Port.DevParams to Connect (#149)

It better conveys the purpose of the function, which is to create a Conn over a
Port.
pull/1/head
M-A 9 years ago committed by GitHub
parent 1c4e51fe0c
commit 24ef228ca1

@ -294,7 +294,7 @@ func (d *Dev) Halt() error {
// https://en.wikipedia.org/wiki/Flicker_fusion_threshold is a recommended // https://en.wikipedia.org/wiki/Flicker_fusion_threshold is a recommended
// reading. // reading.
func New(p spi.Port, numLights int, intensity uint8, temperature uint16) (*Dev, error) { func New(p spi.Port, numLights int, intensity uint8, temperature uint16) (*Dev, error) {
c, err := p.DevParams(20000000, spi.Mode3, 8) c, err := p.Connect(20000000, spi.Mode3, 8)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -340,9 +340,9 @@ func TestDevEmpty(t *testing.T) {
} }
} }
func TestDevParamsFail(t *testing.T) { func TestConnectFail(t *testing.T) {
if d, err := New(&configFail{}, 150, 255, 6500); d != nil || err == nil { if d, err := New(&configFail{}, 150, 255, 6500); d != nil || err == nil {
t.Fatal("DevParams() call have failed") t.Fatal("Connect() call have failed")
} }
} }
@ -703,7 +703,7 @@ type configFail struct {
spitest.Record spitest.Record
} }
func (c *configFail) DevParams(maxHz int64, mode spi.Mode, bits int) (spi.Conn, error) { func (c *configFail) Connect(maxHz int64, mode spi.Mode, bits int) (spi.Conn, error) {
return nil, errors.New("injected error") return nil, errors.New("injected error")
} }

@ -175,7 +175,7 @@ func NewI2C(b i2c.Bus, opts *Opts) (*Dev, error) {
// When using SPI, the CS line must be used. // When using SPI, the CS line must be used.
func NewSPI(p spi.Port, opts *Opts) (*Dev, error) { func NewSPI(p spi.Port, opts *Opts) (*Dev, error) {
// It works both in Mode0 and Mode3. // It works both in Mode0 and Mode3.
c, err := p.DevParams(10000000, spi.Mode3, 8) c, err := p.Connect(10000000, spi.Mode3, 8)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -105,7 +105,7 @@ func TestSPISense_success(t *testing.T) {
func TestNewSPI_fail(t *testing.T) { func TestNewSPI_fail(t *testing.T) {
if d, err := NewSPI(&spiFail{}, nil); d != nil || err == nil { if d, err := NewSPI(&spiFail{}, nil); d != nil || err == nil {
t.Fatal("DevParams() have failed") t.Fatal("Connect() have failed")
} }
} }
@ -545,6 +545,6 @@ type spiFail struct {
spitest.Playback spitest.Playback
} }
func (s *spiFail) DevParams(maxHz int64, mode spi.Mode, bits int) (spi.Conn, error) { func (s *spiFail) Connect(maxHz int64, mode spi.Mode, bits int) (spi.Conn, error) {
return nil, errors.New("failing") return nil, errors.New("failing")
} }

@ -84,7 +84,7 @@ type Dev struct {
// New returns an initialized connection to the FLIR Lepton. // New returns an initialized connection to the FLIR Lepton.
// //
// The CS line is manually managed by using mode spi.NoCS when calling // The CS line is manually managed by using mode spi.NoCS when calling
// DevParams(). In this case pass nil for the cs parameter. Some spidev drivers // Connect(). In this case pass nil for the cs parameter. Some spidev drivers
// refuse spi.NoCS, they do not implement proper support to not trigger the CS // refuse spi.NoCS, they do not implement proper support to not trigger the CS
// line so a manual CS (really, any GPIO pin) must be used instead. // line so a manual CS (really, any GPIO pin) must be used instead.
// //
@ -112,7 +112,7 @@ func New(p spi.Port, i i2c.Bus, cs gpio.PinOut) (*Dev, error) {
} }
// TODO(maruel): Switch to 16 bits per word, so that big endian 16 bits word // TODO(maruel): Switch to 16 bits per word, so that big endian 16 bits word
// decoding is done by the SPI driver. // decoding is done by the SPI driver.
s, err := p.DevParams(20000000, mode, 8) s, err := p.Connect(20000000, mode, 8)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -144,11 +144,11 @@ func TestNew_fail_no_Pins(t *testing.T) {
} }
} }
func TestNew_DevParams(t *testing.T) { func TestNew_Connect(t *testing.T) {
i := i2ctest.Record{} i := i2ctest.Record{}
s := spiStream{err: errors.New("injected")} s := spiStream{err: errors.New("injected")}
if _, err := New(&s, &i, &gpiotest.Pin{N: "CS"}); err == nil { if _, err := New(&s, &i, &gpiotest.Pin{N: "CS"}); err == nil {
t.Fatal("DevParams failed") t.Fatal("Connect failed")
} }
} }
@ -370,7 +370,7 @@ type spiStream struct {
err error err error
} }
func (s *spiStream) DevParams(maxHz int64, mode spi.Mode, bits int) (spi.Conn, error) { func (s *spiStream) Connect(maxHz int64, mode spi.Mode, bits int) (spi.Conn, error) {
if maxHz != 20000000 { if maxHz != 20000000 {
s.t.Fatal(maxHz) s.t.Fatal(maxHz)
} }

@ -133,7 +133,7 @@ func NewSPI(p spi.Port, dc gpio.PinOut, w, h int, rotated bool) (*Dev, error) {
} else if err := dc.Out(gpio.Low); err != nil { } else if err := dc.Out(gpio.Low); err != nil {
return nil, err return nil, err
} }
c, err := p.DevParams(3300000, spi.Mode0, bits) c, err := p.Connect(3300000, spi.Mode0, bits)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -576,7 +576,7 @@ type configFail struct {
spitest.Record spitest.Record
} }
func (c *configFail) DevParams(maxHz int64, mode spi.Mode, bits int) (spi.Conn, error) { func (c *configFail) Connect(maxHz int64, mode spi.Mode, bits int) (spi.Conn, error) {
return nil, errors.New("injected error") return nil, errors.New("injected error")
} }

@ -67,8 +67,8 @@ func (s *SPI) LimitSpeed(maxHz int64) error {
return nil return nil
} }
// DevParams implements spi.Conn. // Connect implements spi.Conn.
func (s *SPI) DevParams(maxHz int64, mode spi.Mode, bits int) error { func (s *SPI) Connect(maxHz int64, mode spi.Mode, bits int) error {
if maxHz < 0 { if maxHz < 0 {
return errors.New("bitbang-spi: invalid maxHz") return errors.New("bitbang-spi: invalid maxHz")
} }

Loading…
Cancel
Save