diff --git a/apa102/apa102.go b/apa102/apa102.go index 0cc22e0..31f0b5e 100644 --- a/apa102/apa102.go +++ b/apa102/apa102.go @@ -8,7 +8,6 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) const ( @@ -38,7 +37,7 @@ func New(b drivers.SPI) *Device { // NewSoftwareSPI returns a new APA102 driver that will use a software based // implementation of the SPI protocol. -func NewSoftwareSPI(sckPin, sdoPin pin.Output, delay uint32) *Device { +func NewSoftwareSPI(sckPin, sdoPin drivers.PinOutput, delay uint32) *Device { return New(&bbSPI{SCK: sckPin.Set, SDO: sdoPin.Set, Delay: delay, configurePins: func() { legacy.ConfigurePinOut(sckPin) legacy.ConfigurePinOut(sdoPin) diff --git a/apa102/softspi.go b/apa102/softspi.go index f221d47..07110d8 100644 --- a/apa102/softspi.go +++ b/apa102/softspi.go @@ -11,8 +11,8 @@ import ( // most purposes other than the APA102 package. It might be desirable to make // this more generic and include it in the TinyGo "machine" package instead. type bbSPI struct { - SCK drivers.PinOutput - SDO drivers.PinOutput + SCK drivers.PinOutputFunc + SDO drivers.PinOutputFunc Delay uint32 configurePins func() } diff --git a/bmi160/bmi160.go b/bmi160/bmi160.go index 2ea0b01..6d1b498 100644 --- a/bmi160/bmi160.go +++ b/bmi160/bmi160.go @@ -5,14 +5,13 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) // DeviceSPI is the SPI interface to a BMI160 accelerometer/gyroscope. There is // also an I2C interface, but it is not yet supported. type DeviceSPI struct { // Chip select pin - csb drivers.PinOutput + csb drivers.PinOutputFunc buf [7]byte @@ -24,7 +23,7 @@ type DeviceSPI struct { // NewSPI returns a new device driver. The pin and SPI interface are not // touched, provide a fully configured SPI object and call Configure to start // using this device. -func NewSPI(csb pin.Output, spi drivers.SPI) *DeviceSPI { +func NewSPI(csb drivers.PinOutput, spi drivers.SPI) *DeviceSPI { return &DeviceSPI{ csb: csb.Set, // chip select bus: spi, diff --git a/buzzer/buzzer.go b/buzzer/buzzer.go index daa8ddf..c0c3b43 100644 --- a/buzzer/buzzer.go +++ b/buzzer/buzzer.go @@ -5,18 +5,17 @@ import ( "time" "tinygo.org/x/drivers" - "tinygo.org/x/drivers/internal/pin" ) // Device wraps a GPIO connection to a buzzer. type Device struct { - pin drivers.PinOutput + pin drivers.PinOutputFunc High bool BPM float64 } // New returns a new buzzer driver given which pin to use -func New(pin pin.Output) Device { +func New(pin drivers.PinOutput) Device { return Device{ pin: pin.Set, High: false, diff --git a/easystepper/easystepper.go b/easystepper/easystepper.go index 8862d33..5dc78e3 100644 --- a/easystepper/easystepper.go +++ b/easystepper/easystepper.go @@ -32,7 +32,7 @@ func (sm StepMode) stepCount() uint { // Device holds the pins and the delay between steps type Device struct { - pins [4]drivers.PinOutput + pins [4]drivers.PinOutputFunc config func() stepDelay time.Duration stepNumber uint8 diff --git a/easystepper/easystepper_go.go b/easystepper/easystepper_go.go index c189a6d..f77bc80 100644 --- a/easystepper/easystepper_go.go +++ b/easystepper/easystepper_go.go @@ -7,7 +7,7 @@ import ( "tinygo.org/x/drivers" ) -func NewCrossPlatform(stepcount, rpm uint, mode StepMode, pins [4]drivers.PinOutput) (*Device, error) { +func NewCrossPlatform(stepcount, rpm uint, mode StepMode, pins [4]drivers.PinOutputFunc) (*Device, error) { if stepcount == 0 || rpm == 0 { return nil, errors.New("zero rpm and/or stepcount") } diff --git a/easystepper/easystepper_tinygo.go b/easystepper/easystepper_tinygo.go index ae1a7cf..11159e1 100644 --- a/easystepper/easystepper_tinygo.go +++ b/easystepper/easystepper_tinygo.go @@ -17,7 +17,7 @@ func New(config DeviceConfig) (*Device, error) { return nil, errors.New("config.StepCount and config.RPM must be > 0") } return &Device{ - pins: [4]drivers.PinOutput{config.Pin1.Set, config.Pin2.Set, config.Pin3.Set, config.Pin4.Set}, + pins: [4]drivers.PinOutputFunc{config.Pin1.Set, config.Pin2.Set, config.Pin3.Set, config.Pin4.Set}, stepDelay: time.Second * 60 / time.Duration((config.StepCount * config.RPM)), stepMode: config.Mode, config: func() { diff --git a/ft6336/ft6336.go b/ft6336/ft6336.go index 9252f3c..53f188d 100644 --- a/ft6336/ft6336.go +++ b/ft6336/ft6336.go @@ -7,7 +7,6 @@ package ft6336 import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" "tinygo.org/x/drivers/touch" ) @@ -20,7 +19,7 @@ type Device struct { } // New returns FT6336 device for the provided I2C bus using default address. -func New(i2c drivers.I2C, intPin pin.Input) *Device { +func New(i2c drivers.I2C, intPin drivers.PinInput) *Device { return &Device{ bus: i2c, buf: make([]byte, 11), diff --git a/gc9a01/gc9a01.go b/gc9a01/gc9a01.go index fd9d2b9..b8c4373 100644 --- a/gc9a01/gc9a01.go +++ b/gc9a01/gc9a01.go @@ -11,7 +11,6 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) // Rotation controls the rotation used by the display. @@ -23,10 +22,10 @@ type FrameRate uint8 // Device wraps an SPI connection. type Device struct { bus drivers.SPI - dcPin drivers.PinOutput - resetPin drivers.PinOutput - csPin drivers.PinOutput - blPin drivers.PinOutput + dcPin drivers.PinOutputFunc + resetPin drivers.PinOutputFunc + csPin drivers.PinOutputFunc + blPin drivers.PinOutputFunc width int16 height int16 columnOffsetCfg int16 @@ -53,7 +52,7 @@ type Config struct { } // New creates a new ST7789 connection. The SPI wire must already be configured. -func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin pin.Output) Device { +func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.PinOutput) Device { legacy.ConfigurePinOut(resetPin) legacy.ConfigurePinOut(dcPin) legacy.ConfigurePinOut(csPin) diff --git a/hcsr04/hcsr04.go b/hcsr04/hcsr04.go index c2f6e1f..fe11f92 100644 --- a/hcsr04/hcsr04.go +++ b/hcsr04/hcsr04.go @@ -9,20 +9,19 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) const TIMEOUT = 23324 // max sensing distance (4m) // Device holds the pins type Device struct { - trigger drivers.PinOutput - echo drivers.PinInput + trigger drivers.PinOutputFunc + echo drivers.PinInputFunc configurePins func() } // New returns a new ultrasonic driver given 2 pins -func New(trigger pin.Output, echo pin.Input) Device { +func New(trigger drivers.PinOutput, echo drivers.PinInput) Device { return Device{ trigger: trigger.Set, echo: echo.Get, diff --git a/internal/legacy/pinhal.go b/internal/legacy/pinhal.go index 1a9da9a..41b3d32 100644 --- a/internal/legacy/pinhal.go +++ b/internal/legacy/pinhal.go @@ -3,7 +3,7 @@ package legacy import ( "errors" - "tinygo.org/x/drivers/internal/pin" + "tinygo.org/x/drivers" ) // ConfigurePinOut is a legacy function used to configure pins as outputs. @@ -11,7 +11,7 @@ import ( // Deprecated: Do not configure pins in drivers. // This is a legacy feature and should only be used by drivers that // previously configured pins in initialization to avoid breaking users. -func ConfigurePinOut(po pin.Output) { +func ConfigurePinOut(po drivers.PinOutput) { configurePinOut(po) } @@ -20,7 +20,7 @@ func ConfigurePinOut(po pin.Output) { // Deprecated: Do not configure pins in drivers. // This is a legacy feature and should only be used by drivers that // previously configured pins in initialization to avoid breaking users. -func ConfigurePinInputPulldown(pi pin.Input) { +func ConfigurePinInputPulldown(pi drivers.PinInput) { configurePinInputPulldown(pi) } @@ -29,7 +29,7 @@ func ConfigurePinInputPulldown(pi pin.Input) { // Deprecated: Do not configure pins in drivers. // This is a legacy feature and should only be used by drivers that // previously configured pins in initialization to avoid breaking users. -func ConfigurePinInput(pi pin.Input) { +func ConfigurePinInput(pi drivers.PinInput) { configurePinInput(pi) } @@ -38,7 +38,7 @@ func ConfigurePinInput(pi pin.Input) { // Deprecated: Do not configure pins in drivers. // This is a legacy feature and should only be used by drivers that // previously configured pins in initialization to avoid breaking users. -func ConfigurePinInputPullup(pi pin.Input) { +func ConfigurePinInputPullup(pi drivers.PinInput) { configurePinInputPullup(pi) } diff --git a/internal/legacy/pinhal_go.go b/internal/legacy/pinhal_go.go index f76cc8b..2825f05 100644 --- a/internal/legacy/pinhal_go.go +++ b/internal/legacy/pinhal_go.go @@ -2,10 +2,12 @@ package legacy -import "tinygo.org/x/drivers/internal/pin" +import ( + "tinygo.org/x/drivers" +) -func configurePinOut(p pin.Output) {} -func configurePinInput(p pin.Input) {} -func configurePinInputPulldown(p pin.Input) {} -func configurePinInputPullup(p pin.Input) {} -func pinIsNoPin(a any) bool { return false } +func configurePinOut(p drivers.PinOutput) {} +func configurePinInput(p drivers.PinInput) {} +func configurePinInputPulldown(p drivers.PinInput) {} +func configurePinInputPullup(p drivers.PinInput) {} +func pinIsNoPin(a any) bool { return false } diff --git a/internal/legacy/pinhal_tinygo.go b/internal/legacy/pinhal_tinygo.go index d0068b2..cd33f52 100644 --- a/internal/legacy/pinhal_tinygo.go +++ b/internal/legacy/pinhal_tinygo.go @@ -5,22 +5,22 @@ package legacy import ( "machine" - "tinygo.org/x/drivers/internal/pin" + "tinygo.org/x/drivers" ) -func configurePinOut(po pin.Output) { +func configurePinOut(po drivers.PinOutput) { configurePin(po, machine.PinOutput) } -func configurePinInputPulldown(pi pin.Input) { +func configurePinInputPulldown(pi drivers.PinInput) { configurePin(pi, pulldown) // some chips do not have pull down, in which case pulldown==machine.PinInput. } -func configurePinInput(pi pin.Input) { +func configurePinInput(pi drivers.PinInput) { configurePin(pi, machine.PinInput) } -func configurePinInputPullup(pi pin.Input) { +func configurePinInputPullup(pi drivers.PinInput) { configurePin(pi, pullup) // some chips do not have pull up, in which case pullup==machine.PinInput. } diff --git a/internal/pin/pin.go b/internal/pin/pin.go deleted file mode 100644 index 3eb0e7e..0000000 --- a/internal/pin/pin.go +++ /dev/null @@ -1,23 +0,0 @@ -package pin - -import "tinygo.org/x/drivers" - -// Here to aid relevant documentation links of [drivers.PinOutput] and [drivers.PinInput]. -var _ drivers.PinOutput - -// Output represents a pin hardware abstraction layer for a pin that can output a digital signal. -// -// This is an alternative to [drivers.PinOutput] abstraction which is a function type and has -// not been standardized as of yet as a standard HAL in the drivers package, -// [discussion ongoing here]. -// -// [discussion ongoing here]: https://github.com/orgs/tinygo-org/discussions/5043 -type Output interface { - Set(level bool) -} - -// Input represents a pin hardware abstraction layer. -// See [Output] for more information on why this type exists separate to drivers. -type Input interface { - Get() (level bool) -} diff --git a/max6675/max6675.go b/max6675/max6675.go index a712df0..49d7864 100644 --- a/max6675/max6675.go +++ b/max6675/max6675.go @@ -5,7 +5,6 @@ import ( "errors" "tinygo.org/x/drivers" - "tinygo.org/x/drivers/internal/pin" ) // ErrThermocoupleOpen is returned when the thermocouple input is open. @@ -14,13 +13,13 @@ var ErrThermocoupleOpen = errors.New("thermocouple input open") type Device struct { bus drivers.SPI - cs drivers.PinOutput + cs drivers.PinOutputFunc } // Create a new Device to read from a MAX6675 thermocouple. // Pins must be configured before use. Frequency for SPI // should be 4.3MHz maximum. -func NewDevice(bus drivers.SPI, cs pin.Output) *Device { +func NewDevice(bus drivers.SPI, cs drivers.PinOutput) *Device { return &Device{ bus: bus, cs: cs.Set, diff --git a/max72xx/max72xx.go b/max72xx/max72xx.go index 815ff7b..53a60e9 100644 --- a/max72xx/max72xx.go +++ b/max72xx/max72xx.go @@ -5,19 +5,18 @@ package max72xx import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) type Device struct { bus drivers.SPI - cs drivers.PinOutput + cs drivers.PinOutputFunc configurePins func() } // NewDriver creates a new max7219 connection. The SPI wire must already be configured // The SPI frequency must not be higher than 10MHz. // parameter cs: the datasheet also refers to this pin as "load" pin. -func NewDevice(bus drivers.SPI, cs pin.Output) *Device { +func NewDevice(bus drivers.SPI, cs drivers.PinOutput) *Device { return &Device{ bus: bus, cs: cs.Set, diff --git a/mcp2515/mcp2515.go b/mcp2515/mcp2515.go index 48ebaf1..a7de014 100644 --- a/mcp2515/mcp2515.go +++ b/mcp2515/mcp2515.go @@ -12,13 +12,12 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) // Device wraps MCP2515 SPI CAN Module. type Device struct { spi SPI - cs drivers.PinOutput + cs drivers.PinOutputFunc msg *CANMsg mcpMode byte configurePins func() @@ -38,7 +37,7 @@ const ( ) // New returns a new MCP2515 driver. Pass in a fully configured SPI bus. -func New(b drivers.SPI, csPin pin.Output) *Device { +func New(b drivers.SPI, csPin drivers.PinOutput) *Device { d := &Device{ spi: SPI{ bus: b, diff --git a/pcd8544/pcd8544.go b/pcd8544/pcd8544.go index 73a17f0..7b5a889 100644 --- a/pcd8544/pcd8544.go +++ b/pcd8544/pcd8544.go @@ -9,15 +9,14 @@ import ( "time" "tinygo.org/x/drivers" - "tinygo.org/x/drivers/internal/pin" ) // Device wraps an SPI connection. type Device struct { bus drivers.SPI - dcPin drivers.PinOutput - rstPin drivers.PinOutput - scePin drivers.PinOutput + dcPin drivers.PinOutputFunc + rstPin drivers.PinOutputFunc + scePin drivers.PinOutputFunc buffer []byte width int16 height int16 @@ -30,7 +29,7 @@ type Config struct { } // New creates a new PCD8544 connection. The SPI bus must already be configured. -func New(bus drivers.SPI, dcPin, rstPin, scePin pin.Output) *Device { +func New(bus drivers.SPI, dcPin, rstPin, scePin drivers.PinOutput) *Device { return &Device{ bus: bus, dcPin: dcPin.Set, diff --git a/pin.go b/pin.go index 33ea5ac..fa27f7c 100644 --- a/pin.go +++ b/pin.go @@ -1,29 +1,39 @@ package drivers -// PinOutput is hardware abstraction for a pin which outputs a +// PinOutput represents a pin hardware abstraction layer for a pin that can output a digital signal. +type PinOutput interface { + Set(level bool) +} + +// PinInput represents a pin hardware abstraction layer. +type PinInput interface { + Get() (level bool) +} + +// PinOutputFunc is hardware abstraction for a function that causes pin to output a // digital signal (high or low level). // -// // Code conversion demo: from machine.Pin to drivers.PinOutput +// // Code conversion demo: from machine.Pin to drivers.PinOutputFunc // led := machine.LED // led.Configure(machine.PinConfig{Mode: machine.PinOutput}) -// var pin drivers.PinOutput = led.Set // Going from a machine.Pin to a drivers.PinOutput -type PinOutput func(level bool) +// var pin drivers.PinOutputFunc = led.Set // Going from a machine.Pin to a drivers.PinOutputFunc +type PinOutputFunc func(level bool) // High sets the underlying pin's level to high. This is equivalent to calling PinOutput(true). -func (po PinOutput) High() { +func (po PinOutputFunc) High() { po(true) } // Low sets the underlying pin's level to low. This is equivalent to calling PinOutput(false). -func (po PinOutput) Low() { +func (po PinOutputFunc) Low() { po(false) } -// PinInput is hardware abstraction for a pin which receives a +// PinInputFunc is hardware abstraction for a pin which receives a // digital signal and reads it (high or low level). // -// // Code conversion demo: from machine.Pin to drivers.PinInput +// // Code conversion demo: from machine.Pin to drivers.PinInputFunc // input := machine.LED // input.Configure(machine.PinConfig{Mode: machine.PinInputPulldown}) // or use machine.PinInputPullup or machine.PinInput -// var pin drivers.PinInput = input.Get // Going from a machine.Pin to a drivers.PinInput -type PinInput func() (level bool) +// var pin drivers.PinInputFunc = input.Get // Going from a machine.Pin to a drivers.PinInputFunc +type PinInputFunc func() (level bool) diff --git a/shiftregister/shiftregister.go b/shiftregister/shiftregister.go index c315387..3949b21 100644 --- a/shiftregister/shiftregister.go +++ b/shiftregister/shiftregister.go @@ -4,7 +4,6 @@ package shiftregister import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) type NumberBit int8 @@ -18,7 +17,7 @@ const ( // Device holds pin number type Device struct { - latch, clock, out drivers.PinOutput // IC wiring + latch, clock, out drivers.PinOutputFunc // IC wiring config func() bits NumberBit // Pin number mask uint32 // keep all pins state @@ -32,7 +31,7 @@ type ShiftPin struct { } // New returns a new shift output register device -func New(Bits NumberBit, Latch, Clock, Out pin.Output) *Device { +func New(Bits NumberBit, Latch, Clock, Out drivers.PinOutput) *Device { return &Device{ latch: Latch.Set, clock: Clock.Set, diff --git a/ssd1289/ssd1289.go b/ssd1289/ssd1289.go index c649d84..786308b 100644 --- a/ssd1289/ssd1289.go +++ b/ssd1289/ssd1289.go @@ -17,10 +17,10 @@ type Bus interface { } type Device struct { - rs drivers.PinOutput - wr drivers.PinOutput - cs drivers.PinOutput - rst drivers.PinOutput + rs drivers.PinOutputFunc + wr drivers.PinOutputFunc + cs drivers.PinOutputFunc + rst drivers.PinOutputFunc bus Bus } diff --git a/ssd1331/ssd1331.go b/ssd1331/ssd1331.go index 9775819..2e7bfd0 100644 --- a/ssd1331/ssd1331.go +++ b/ssd1331/ssd1331.go @@ -20,9 +20,9 @@ type Rotation uint8 // Device wraps an SPI connection. type Device struct { bus drivers.SPI - dcPin drivers.PinOutput - resetPin drivers.PinOutput - csPin drivers.PinOutput + dcPin drivers.PinOutputFunc + resetPin drivers.PinOutputFunc + csPin drivers.PinOutputFunc width int16 height int16 batchLength int16 diff --git a/ssd1351/ssd1351.go b/ssd1351/ssd1351.go index 96a6f0c..6bce8bd 100644 --- a/ssd1351/ssd1351.go +++ b/ssd1351/ssd1351.go @@ -10,7 +10,6 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) var ( @@ -21,11 +20,11 @@ var ( // Device wraps an SPI connection. type Device struct { bus drivers.SPI - dcPin drivers.PinOutput - resetPin drivers.PinOutput - csPin drivers.PinOutput - enPin drivers.PinOutput - rwPin drivers.PinOutput + dcPin drivers.PinOutputFunc + resetPin drivers.PinOutputFunc + csPin drivers.PinOutputFunc + enPin drivers.PinOutputFunc + rwPin drivers.PinOutputFunc configurePins func() width int16 height int16 @@ -43,7 +42,7 @@ type Config struct { } // New creates a new SSD1351 connection. The SPI wire must already be configured. -func New(bus drivers.SPI, resetPin, dcPin, csPin, enPin, rwPin pin.Output) Device { +func New(bus drivers.SPI, resetPin, dcPin, csPin, enPin, rwPin drivers.PinOutput) Device { return Device{ bus: bus, dcPin: dcPin.Set, diff --git a/st7735/st7735.go b/st7735/st7735.go index 235bcd6..3593214 100644 --- a/st7735/st7735.go +++ b/st7735/st7735.go @@ -11,7 +11,6 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" "tinygo.org/x/drivers/pixel" ) @@ -40,10 +39,10 @@ type Device = DeviceOf[pixel.RGB565BE] // formats. type DeviceOf[T Color] struct { bus drivers.SPI - dcPin drivers.PinOutput - resetPin drivers.PinOutput - csPin drivers.PinOutput - blPin drivers.PinOutput + dcPin drivers.PinOutputFunc + resetPin drivers.PinOutputFunc + csPin drivers.PinOutputFunc + blPin drivers.PinOutputFunc width int16 height int16 columnOffset int16 @@ -66,13 +65,13 @@ type Config struct { } // New creates a new ST7735 connection. The SPI wire must already be configured. -func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin pin.Output) Device { +func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.PinOutput) Device { return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin) } // NewOf creates a new ST7735 connection with a particular pixel format. The SPI // wire must already be configured. -func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin pin.Output) DeviceOf[T] { +func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.PinOutput) DeviceOf[T] { legacy.ConfigurePinOut(dcPin) legacy.ConfigurePinOut(resetPin) legacy.ConfigurePinOut(csPin) diff --git a/st7789/st7789.go b/st7789/st7789.go index 7602b52..10208e0 100644 --- a/st7789/st7789.go +++ b/st7789/st7789.go @@ -14,7 +14,6 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" "tinygo.org/x/drivers/pixel" ) @@ -47,10 +46,10 @@ type Device = DeviceOf[pixel.RGB565BE] // formats. type DeviceOf[T Color] struct { bus drivers.SPI - dcPin drivers.PinOutput - resetPin drivers.PinOutput - csPin drivers.PinOutput - blPin drivers.PinOutput + dcPin drivers.PinOutputFunc + resetPin drivers.PinOutputFunc + csPin drivers.PinOutputFunc + blPin drivers.PinOutputFunc width int16 height int16 columnOffsetCfg int16 @@ -84,18 +83,18 @@ type Config struct { } // New creates a new ST7789 connection. The SPI wire must already be configured. -func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin pin.Output) Device { +func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.PinOutput) Device { return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin) } // NewOf creates a new ST7789 connection with a particular pixel format. The SPI // wire must already be configured. -func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin pin.Output) DeviceOf[T] { +func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.PinOutput) DeviceOf[T] { legacy.ConfigurePinOut(dcPin) legacy.ConfigurePinOut(resetPin) legacy.ConfigurePinOut(csPin) legacy.ConfigurePinOut(blPin) - var cs drivers.PinOutput + var cs drivers.PinOutputFunc if !legacy.PinIsNoPin(csPin) { cs = csPin.Set } diff --git a/sx127x/sx127x.go b/sx127x/sx127x.go index e820f3a..14489ec 100644 --- a/sx127x/sx127x.go +++ b/sx127x/sx127x.go @@ -9,7 +9,6 @@ import ( "time" "tinygo.org/x/drivers" - "tinygo.org/x/drivers/internal/pin" "tinygo.org/x/drivers/lora" ) @@ -21,15 +20,15 @@ const ( // Device wraps an SPI connection to a SX127x device. type Device struct { - spi drivers.SPI // SPI bus for module communication - rstPin drivers.PinOutput // GPIO for reset - radioEventChan chan lora.RadioEvent // Channel for Receiving events - loraConf lora.Config // Current Lora configuration - controller RadioController // to manage interactions with the radio - deepSleep bool // Internal Sleep state - deviceType int // sx1261,sx1262,sx1268 (defaults sx1261) - spiTxBuf []byte // global Tx buffer to avoid heap allocations in interrupt - spiRxBuf []byte // global Rx buffer to avoid heap allocations in interrupt + spi drivers.SPI // SPI bus for module communication + rstPin drivers.PinOutputFunc // GPIO for reset + radioEventChan chan lora.RadioEvent // Channel for Receiving events + loraConf lora.Config // Current Lora configuration + controller RadioController // to manage interactions with the radio + deepSleep bool // Internal Sleep state + deviceType int // sx1261,sx1262,sx1268 (defaults sx1261) + spiTxBuf []byte // global Tx buffer to avoid heap allocations in interrupt + spiRxBuf []byte // global Rx buffer to avoid heap allocations in interrupt } // -------------------------------------------------- @@ -43,7 +42,7 @@ func (d *Device) GetRadioEventChan() chan lora.RadioEvent { } // New creates a new SX127x connection. The SPI bus must already be configured. -func New(spi drivers.SPI, rstPin pin.Output) *Device { +func New(spi drivers.SPI, rstPin drivers.PinOutput) *Device { k := Device{ spi: spi, rstPin: rstPin.Set, diff --git a/uc8151/uc8151.go b/uc8151/uc8151.go index 6da8866..a01b217 100644 --- a/uc8151/uc8151.go +++ b/uc8151/uc8151.go @@ -12,7 +12,6 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" "tinygo.org/x/drivers/pixel" ) @@ -32,10 +31,10 @@ type Config struct { type Device struct { bus drivers.SPI - cs drivers.PinOutput - dc drivers.PinOutput - rst drivers.PinOutput - isBusy drivers.PinInput + cs drivers.PinOutputFunc + dc drivers.PinOutputFunc + rst drivers.PinOutputFunc + isBusy drivers.PinInputFunc width int16 height int16 buffer []uint8 @@ -50,7 +49,7 @@ type Device struct { type Speed uint8 // New returns a new uc8151 driver. Pass in a fully configured SPI bus. -func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device { +func New(bus drivers.SPI, csPin, dcPin, rstPin drivers.PinOutput, busyPin drivers.PinInput) Device { legacy.ConfigurePinOut(csPin) legacy.ConfigurePinOut(dcPin) legacy.ConfigurePinOut(rstPin) diff --git a/waveshare-epd/epd1in54/epd1in54.go b/waveshare-epd/epd1in54/epd1in54.go index 4db9d76..df4072e 100644 --- a/waveshare-epd/epd1in54/epd1in54.go +++ b/waveshare-epd/epd1in54/epd1in54.go @@ -15,7 +15,6 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) type Config struct { @@ -27,10 +26,10 @@ type Config struct { type Device struct { bus *machine.SPI - cs drivers.PinOutput - dc drivers.PinOutput - rst drivers.PinOutput - isBusy drivers.PinInput + cs drivers.PinOutputFunc + dc drivers.PinOutputFunc + rst drivers.PinOutputFunc + isBusy drivers.PinInputFunc configurePins func() buffer []uint8 rotation Rotation @@ -83,7 +82,7 @@ var partialRefresh = [159]uint8{ } // New returns a new epd1in54 driver. Pass in a fully configured SPI bus. -func New(bus *machine.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device { +func New(bus *machine.SPI, csPin, dcPin, rstPin drivers.PinOutput, busyPin drivers.PinInput) Device { return Device{ buffer: make([]uint8, (uint32(Width)*uint32(Height))/8), bus: bus, diff --git a/waveshare-epd/epd2in13/epd2in13.go b/waveshare-epd/epd2in13/epd2in13.go index 408af5e..1ed4446 100644 --- a/waveshare-epd/epd2in13/epd2in13.go +++ b/waveshare-epd/epd2in13/epd2in13.go @@ -10,7 +10,6 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) type Config struct { @@ -22,10 +21,10 @@ type Config struct { type Device struct { bus drivers.SPI - cs drivers.PinOutput - dc drivers.PinOutput - rst drivers.PinOutput - isBusy drivers.PinInput + cs drivers.PinOutputFunc + dc drivers.PinOutputFunc + rst drivers.PinOutputFunc + isBusy drivers.PinInputFunc logicalWidth int16 width int16 height int16 @@ -54,7 +53,7 @@ var lutPartialUpdate = [30]uint8{ } // New returns a new epd2in13x driver. Pass in a fully configured SPI bus. -func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device { +func New(bus drivers.SPI, csPin, dcPin, rstPin drivers.PinOutput, busyPin drivers.PinInput) Device { legacy.ConfigurePinOut(csPin) legacy.ConfigurePinOut(dcPin) legacy.ConfigurePinOut(rstPin) diff --git a/waveshare-epd/epd2in13x/epd2in13x.go b/waveshare-epd/epd2in13x/epd2in13x.go index 8469f0b..38bb5ad 100644 --- a/waveshare-epd/epd2in13x/epd2in13x.go +++ b/waveshare-epd/epd2in13x/epd2in13x.go @@ -10,7 +10,6 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) type Config struct { @@ -21,10 +20,10 @@ type Config struct { type Device struct { bus drivers.SPI - cs drivers.PinOutput - dc drivers.PinOutput - rst drivers.PinOutput - isBusy drivers.PinInput + cs drivers.PinOutputFunc + dc drivers.PinOutputFunc + rst drivers.PinOutputFunc + isBusy drivers.PinInputFunc width int16 height int16 buffer [][]uint8 @@ -34,7 +33,7 @@ type Device struct { type Color uint8 // New returns a new epd2in13x driver. Pass in a fully configured SPI bus. -func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device { +func New(bus drivers.SPI, csPin, dcPin, rstPin drivers.PinOutput, busyPin drivers.PinInput) Device { legacy.ConfigurePinOut(csPin) legacy.ConfigurePinOut(dcPin) legacy.ConfigurePinOut(rstPin) diff --git a/waveshare-epd/epd2in66b/dev.go b/waveshare-epd/epd2in66b/dev.go index 32cebd8..173ce70 100644 --- a/waveshare-epd/epd2in66b/dev.go +++ b/waveshare-epd/epd2in66b/dev.go @@ -19,10 +19,10 @@ const Baudrate = 4_000_000 // 4 MHz type Device struct { bus drivers.SPI - cs drivers.PinOutput - dc drivers.PinOutput - rst drivers.PinOutput - isBusy drivers.PinInput + cs drivers.PinOutputFunc + dc drivers.PinOutputFunc + rst drivers.PinOutputFunc + isBusy drivers.PinInputFunc blackBuffer []byte redBuffer []byte diff --git a/waveshare-epd/epd2in9/epd2in9.go b/waveshare-epd/epd2in9/epd2in9.go index b90f5f3..823bd68 100644 --- a/waveshare-epd/epd2in9/epd2in9.go +++ b/waveshare-epd/epd2in9/epd2in9.go @@ -17,7 +17,6 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) type Config struct { @@ -29,10 +28,10 @@ type Config struct { type Device struct { bus drivers.SPI - cs drivers.PinOutput - dc drivers.PinOutput - rst drivers.PinOutput - isBusy drivers.PinInput + cs drivers.PinOutputFunc + dc drivers.PinOutputFunc + rst drivers.PinOutputFunc + isBusy drivers.PinInputFunc logicalWidth int16 width int16 height int16 @@ -62,7 +61,7 @@ var lutPartialUpdate = [30]uint8{ } // New returns a new epd2in9 driver. Pass in a fully configured SPI bus. -func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device { +func New(bus drivers.SPI, csPin, dcPin, rstPin drivers.PinOutput, busyPin drivers.PinInput) Device { legacy.ConfigurePinOut(csPin) legacy.ConfigurePinOut(dcPin) legacy.ConfigurePinOut(rstPin) diff --git a/waveshare-epd/epd4in2/epd4in2.go b/waveshare-epd/epd4in2/epd4in2.go index 772b834..16f1bd3 100644 --- a/waveshare-epd/epd4in2/epd4in2.go +++ b/waveshare-epd/epd4in2/epd4in2.go @@ -14,7 +14,6 @@ import ( "tinygo.org/x/drivers" "tinygo.org/x/drivers/internal/legacy" - "tinygo.org/x/drivers/internal/pin" ) type Config struct { @@ -26,10 +25,10 @@ type Config struct { type Device struct { bus drivers.SPI - cs drivers.PinOutput - dc drivers.PinOutput - rst drivers.PinOutput - isBusy drivers.PinInput + cs drivers.PinOutputFunc + dc drivers.PinOutputFunc + rst drivers.PinOutputFunc + isBusy drivers.PinInputFunc logicalWidth int16 width int16 height int16 @@ -41,7 +40,7 @@ type Device struct { type Rotation uint8 // New returns a new epd4in2 driver. Pass in a fully configured SPI bus. -func New(bus drivers.SPI, csPin, dcPin, rstPin pin.Output, busyPin pin.Input) Device { +func New(bus drivers.SPI, csPin, dcPin, rstPin drivers.PinOutput, busyPin drivers.PinInput) Device { legacy.ConfigurePinOut(csPin) legacy.ConfigurePinOut(dcPin) legacy.ConfigurePinOut(rstPin)