From e9529e4c72f8d28360ad9a3369c1e1f841bff08d Mon Sep 17 00:00:00 2001 From: Ron Evans Date: Mon, 16 Apr 2018 13:29:35 +0200 Subject: [PATCH] spi: remove unneeded type and cleanup GoDocs Signed-off-by: Ron Evans --- drivers/spi/spi.go | 28 ++++++++++------------------ drivers/spi/spi_test.go | 6 +++--- drivers/spi/ssd1306_driver.go | 3 +-- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/drivers/spi/spi.go b/drivers/spi/spi.go index 8a4291df..57d53f7f 100644 --- a/drivers/spi/spi.go +++ b/drivers/spi/spi.go @@ -10,24 +10,19 @@ const ( NotInitialized = -1 ) -// Operations are the wrappers around the actual functions used by the SPI Device interface +// Operations are the wrappers around the actual functions used by the SPI device interface type Operations interface { Close() error Tx(w, r []byte) error } -// Device is the interface to a specific spi bus/chip -type Device interface { - Operations -} - // Connector lets Adaptors provide the interface for Drivers // to get access to the SPI buses on platforms that support SPI. type Connector interface { // GetSpiConnection returns a connection to a SPI device at the specified bus and chip. // Bus numbering starts at index 0, the range of valid buses is // platform specific. Same with chip numbering. - GetSpiConnection(busNum, chip, mode, bits int, maxSpeed int64) (device Device, err error) + GetSpiConnection(busNum, chip, mode, bits int, maxSpeed int64) (device Connection, err error) // GetSpiDefaultBus returns the default SPI bus index GetSpiDefaultBus() int @@ -45,17 +40,14 @@ type Connector interface { GetSpiDefaultMaxSpeed() int64 } -// Connection is a connection to an SPI device with a specified bus -// on a specific chip. -// Implements SPIOperations to talk to the device, wrapping the -// calls in SetAddress to always target the specified device. -// Provided by an Adaptor by implementing the SPIConnector interface. +// Connection is a connection to a SPI device with a specific bus/chip. +// Provided by an Adaptor, usually just by calling the spi package's GetSpiConnection() function. type Connection Operations // SpiConnection is the implementation of the SPI interface using the periph.io -// implementataion for Linux. +// sysfs implementation for Linux. type SpiConnection struct { - Connection + Operations port xspi.PortCloser dev xspi.Conn bus int @@ -66,12 +58,12 @@ type SpiConnection struct { } // NewConnection creates and returns a new connection to a specific -// spi device on a bus/chip using the periph.io interface +// spi device on a bus/chip using the periph.io interface. func NewConnection(port xspi.PortCloser, conn xspi.Conn) (connection *SpiConnection) { return &SpiConnection{port: port, dev: conn} } -// Close the SPI connection +// Close the SPI connection. func (c *SpiConnection) Close() error { return c.port.Close() } @@ -81,8 +73,8 @@ func (c *SpiConnection) Tx(w, r []byte) error { return c.dev.Tx(w, r) } -// GetSpiConnection is a helper to return a SPI device -func GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (Device, error) { +// GetSpiConnection is a helper to return a SPI device. +func GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (Connection, error) { p, err := xsysfs.NewSPI(busNum, chipNum) if err != nil { return nil, err diff --git a/drivers/spi/spi_test.go b/drivers/spi/spi_test.go index ef1914a9..a24d7199 100644 --- a/drivers/spi/spi_test.go +++ b/drivers/spi/spi_test.go @@ -7,7 +7,7 @@ import ( type TestConnector struct{} -func (ctr *TestConnector) GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (device Device, err error) { +func (ctr *TestConnector) GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (device Connection, err error) { return NewConnection(&TestSpiConnection{}, &TestSpiDevice{}), nil } @@ -32,7 +32,7 @@ func (ctr *TestConnector) GetSpiDefaultMaxSpeed() int64 { } type TestSpiDevice struct { - dev Device + dev Connection } func (c *TestSpiDevice) Duplex() conn.Duplex { @@ -48,7 +48,7 @@ func (c *TestSpiDevice) Tx(w, r []byte) error { } type TestSpiConnection struct { - conn Connection + conn Operations } func (c *TestSpiConnection) Close() error { diff --git a/drivers/spi/ssd1306_driver.go b/drivers/spi/ssd1306_driver.go index 99adb109..35ac29f2 100644 --- a/drivers/spi/ssd1306_driver.go +++ b/drivers/spi/ssd1306_driver.go @@ -355,8 +355,7 @@ func (s *SSD1306Driver) Set(x, y, c int) { s.buffer.SetPixel(x, y, c) } -// Reset re-intializes the device to a clean state. - +// Reset re-initializes the device to a clean state. func (s *SSD1306Driver) Reset() (err error) { s.rstDriver.DigitalWrite(1) time.Sleep(10 * time.Millisecond)