diff --git a/examples/flash/console/spi/main.go b/examples/flash/console/spi/main.go index 21e088d64..5d28fa77b 100644 --- a/examples/flash/console/spi/main.go +++ b/examples/flash/console/spi/main.go @@ -10,7 +10,7 @@ import ( func main() { console_example.RunFor( flash.NewSPI( - &machine.SPI1, + machine.SPI1, machine.SPI1_SDO_PIN, machine.SPI1_SDI_PIN, machine.SPI1_SCK_PIN, diff --git a/examples/sdcard/console/feather-m4.go b/examples/sdcard/console/feather-m4.go index 258aac5de..dae1fb04c 100644 --- a/examples/sdcard/console/feather-m4.go +++ b/examples/sdcard/console/feather-m4.go @@ -7,7 +7,7 @@ import ( ) func init() { - spi = &machine.SPI0 + spi = machine.SPI0 sckPin = machine.SPI0_SCK_PIN sdoPin = machine.SPI0_SDO_PIN sdiPin = machine.SPI0_SDI_PIN diff --git a/examples/sdcard/console/grandcentral-m4.go b/examples/sdcard/console/grandcentral-m4.go index 51eb5c2aa..ed13803e7 100644 --- a/examples/sdcard/console/grandcentral-m4.go +++ b/examples/sdcard/console/grandcentral-m4.go @@ -7,7 +7,7 @@ import ( ) func init() { - spi = &machine.SPI1 + spi = machine.SPI1 sckPin = machine.SDCARD_SCK_PIN sdoPin = machine.SDCARD_SDO_PIN sdiPin = machine.SDCARD_SDI_PIN diff --git a/examples/sdcard/console/m0.go b/examples/sdcard/console/m0.go index 5ba53915d..fcb0b0376 100644 --- a/examples/sdcard/console/m0.go +++ b/examples/sdcard/console/m0.go @@ -7,7 +7,7 @@ import ( ) func init() { - spi = &machine.SPI0 + spi = machine.SPI0 sckPin = machine.SPI0_SCK_PIN sdoPin = machine.SPI0_SDO_PIN sdiPin = machine.SPI0_SDI_PIN diff --git a/examples/sdcard/console/p1am-100.go b/examples/sdcard/console/p1am-100.go index b1acb6251..b003042ac 100644 --- a/examples/sdcard/console/p1am-100.go +++ b/examples/sdcard/console/p1am-100.go @@ -7,7 +7,7 @@ import ( ) func init() { - spi = &machine.SDCARD_SPI + spi = machine.SDCARD_SPI sckPin = machine.SDCARD_SCK_PIN sdoPin = machine.SDCARD_SDO_PIN sdiPin = machine.SDCARD_SDI_PIN diff --git a/examples/sdcard/console/pygamer.go b/examples/sdcard/console/pygamer.go index 35182445f..cc1187c52 100644 --- a/examples/sdcard/console/pygamer.go +++ b/examples/sdcard/console/pygamer.go @@ -7,7 +7,7 @@ import ( ) func init() { - spi = &machine.SPI0 + spi = machine.SPI0 sckPin = machine.SPI0_SCK_PIN sdoPin = machine.SPI0_SDO_PIN sdiPin = machine.SPI0_SDI_PIN diff --git a/examples/sdcard/console/pyportal.go b/examples/sdcard/console/pyportal.go index 9a8accb46..3599cdfc1 100644 --- a/examples/sdcard/console/pyportal.go +++ b/examples/sdcard/console/pyportal.go @@ -7,7 +7,7 @@ import ( ) func init() { - spi = &machine.SPI0 + spi = machine.SPI0 sckPin = machine.SPI0_SCK_PIN sdoPin = machine.SPI0_SDO_PIN sdiPin = machine.SPI0_SDI_PIN diff --git a/examples/sdcard/console/wioterminal.go b/examples/sdcard/console/wioterminal.go index 96019e3a1..934b87a0f 100644 --- a/examples/sdcard/console/wioterminal.go +++ b/examples/sdcard/console/wioterminal.go @@ -7,7 +7,7 @@ import ( ) func init() { - spi = &machine.SPI2 + spi = machine.SPI2 sckPin = machine.SCK2 sdoPin = machine.SDO2 sdiPin = machine.SDI2 diff --git a/examples/tmc5160/main.go b/examples/tmc5160/main.go index 309ea14b3..3b60ccf1b 100644 --- a/examples/tmc5160/main.go +++ b/examples/tmc5160/main.go @@ -27,7 +27,7 @@ func main() { //bind csPin to driverAdddress driverAddress := uint8(0) // Let's assume we are working with driver at address 0x01 // Step 3. Bind the communication interface to the protocol - comm := tmc5160.NewSPIComm(*spi, csPins) + comm := tmc5160.NewSPIComm(spi, csPins) // Step 4. Define your stepper like this below //stepper := tmc5160.NewStepper(angle , gearRatio vSupply rCoil , lCoil , iPeak , rSense , mSteps, fclk ) stepper := tmc5160.NewDefaultStepper() // Default Stepper should be used only for testing. diff --git a/ili9341/spi_atsamd21.go b/ili9341/spi_atsamd21.go index 5aff3a9fd..c9582e48d 100644 --- a/ili9341/spi_atsamd21.go +++ b/ili9341/spi_atsamd21.go @@ -8,10 +8,10 @@ import ( ) type spiDriver struct { - bus machine.SPI + bus *machine.SPI } -func NewSPI(bus machine.SPI, dc, cs, rst machine.Pin) *Device { +func NewSPI(bus *machine.SPI, dc, cs, rst machine.Pin) *Device { return &Device{ dc: dc, cs: cs, diff --git a/ili9341/spi_atsamd51.go b/ili9341/spi_atsamd51.go index 40b99954e..a5cee859a 100644 --- a/ili9341/spi_atsamd51.go +++ b/ili9341/spi_atsamd51.go @@ -8,10 +8,10 @@ import ( ) type spiDriver struct { - bus machine.SPI + bus *machine.SPI } -func NewSPI(bus machine.SPI, dc, cs, rst machine.Pin) *Device { +func NewSPI(bus *machine.SPI, dc, cs, rst machine.Pin) *Device { return &Device{ dc: dc, cs: cs, diff --git a/max6675/max6675.go b/max6675/max6675.go index 9d2433e6d..eb67596b6 100644 --- a/max6675/max6675.go +++ b/max6675/max6675.go @@ -4,6 +4,8 @@ package max6675 import ( "errors" "machine" + + "tinygo.org/x/drivers" ) // ErrThermocoupleOpen is returned when the thermocouple input is open. @@ -11,14 +13,14 @@ import ( var ErrThermocoupleOpen = errors.New("thermocouple input open") type Device struct { - bus machine.SPI + bus drivers.SPI cs machine.Pin } // 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 machine.SPI, cs machine.Pin) *Device { +func NewDevice(bus drivers.SPI, cs machine.Pin) *Device { return &Device{ bus: bus, cs: cs, diff --git a/max72xx/max72xx.go b/max72xx/max72xx.go index 27de1b539..ca6c81929 100644 --- a/max72xx/max72xx.go +++ b/max72xx/max72xx.go @@ -4,17 +4,19 @@ package max72xx import ( "machine" + + "tinygo.org/x/drivers" ) type Device struct { - bus machine.SPI + bus drivers.SPI cs machine.Pin } // 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 machine.SPI, cs machine.Pin) *Device { +func NewDevice(bus drivers.SPI, cs machine.Pin) *Device { return &Device{ bus: bus, cs: cs, diff --git a/p1am/p1am.go b/p1am/p1am.go index d61817d2f..a46cd71b8 100644 --- a/p1am/p1am.go +++ b/p1am/p1am.go @@ -14,7 +14,8 @@ import ( ) type P1AM struct { - bus machine.SPI + bus *machine.SPI + slaveSelectPin, slaveAckPin, baseEnablePin machine.Pin // SkipAutoConfig will skip loading a default configuration into each module. diff --git a/sx127x/sx127x.go b/sx127x/sx127x.go index bced11ae8..f2c2a8737 100644 --- a/sx127x/sx127x.go +++ b/sx127x/sx127x.go @@ -43,7 +43,7 @@ func (d *Device) GetRadioEventChan() chan lora.RadioEvent { } // New creates a new SX127x connection. The SPI bus must already be configured. -func New(spi machine.SPI, rstPin machine.Pin) *Device { +func New(spi drivers.SPI, rstPin machine.Pin) *Device { k := Device{ spi: spi, rstPin: rstPin, diff --git a/tmc5160/README.MD b/tmc5160/README.MD index b0b4916a0..4c4e11c64 100644 --- a/tmc5160/README.MD +++ b/tmc5160/README.MD @@ -183,7 +183,7 @@ if err != nil { ## API Reference - NewSPIComm(spi machine.SPI, csPins map[uint8]machine.Pin) *SPIComm + NewSPIComm(spi *machine.SPI, csPins map[uint8]machine.Pin) *SPIComm Creates a new SPI communication interface for the TMC5160. diff --git a/tmc5160/spicomm.go b/tmc5160/spicomm.go index 4127f0fef..fb3a46f37 100644 --- a/tmc5160/spicomm.go +++ b/tmc5160/spicomm.go @@ -16,12 +16,12 @@ func (e CustomError) Error() string { // SPIComm implements RegisterComm for SPI-based communication type SPIComm struct { - spi machine.SPI + spi *machine.SPI CsPins map[uint8]machine.Pin // Map to store CS pin for each Driver by its address } // NewSPIComm creates a new SPIComm instance. -func NewSPIComm(spi machine.SPI, csPins map[uint8]machine.Pin) *SPIComm { +func NewSPIComm(spi *machine.SPI, csPins map[uint8]machine.Pin) *SPIComm { return &SPIComm{ spi: spi, CsPins: csPins, @@ -31,7 +31,7 @@ func NewSPIComm(spi machine.SPI, csPins map[uint8]machine.Pin) *SPIComm { // Setup initializes the SPI communication with the Driver and configures all CS pins. func (comm *SPIComm) Setup() error { // Check if SPI is initialized - if comm.spi == (machine.SPI{}) { + if comm.spi == nil { return CustomError("SPI not initialized") } @@ -66,7 +66,7 @@ func (comm *SPIComm) WriteRegister(register uint8, value uint32, driverAddress u addressWithWriteAccess := register | 0x80 // Send the address and the data to write (split into 4 bytes) - _, err := spiTransfer40(&comm.spi, addressWithWriteAccess, value) + _, err := spiTransfer40(comm.spi, addressWithWriteAccess, value) if err != nil { csPin.High() return CustomError("Failed to write register") @@ -88,7 +88,7 @@ func (comm *SPIComm) ReadRegister(register uint8, driverAddress uint8) (uint32, csPin.Low() // Step 1: Send a dummy write operation to begin the read sequence - _, err := spiTransfer40(&comm.spi, register, 0x00) // Send dummy data + _, err := spiTransfer40(comm.spi, register, 0x00) // Send dummy data if err != nil { csPin.High() return 0, CustomError("Failed to send dummy write") @@ -97,7 +97,7 @@ func (comm *SPIComm) ReadRegister(register uint8, driverAddress uint8) (uint32, time.Sleep(176 * time.Nanosecond) csPin.Low() // Step 2: Send the register read request again to get the actual value - response, err := spiTransfer40(&comm.spi, register, 0x00) // Send again to get actual register data + response, err := spiTransfer40(comm.spi, register, 0x00) // Send again to get actual register data if err != nil { csPin.High() return 0, CustomError("Failed to read register") diff --git a/waveshare-epd/epd1in54/epd1in54.go b/waveshare-epd/epd1in54/epd1in54.go index 4cbda2a80..120b356ef 100644 --- a/waveshare-epd/epd1in54/epd1in54.go +++ b/waveshare-epd/epd1in54/epd1in54.go @@ -22,7 +22,7 @@ type Config struct { } type Device struct { - bus machine.SPI + bus *machine.SPI cs machine.Pin dc machine.Pin rst machine.Pin @@ -79,7 +79,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, busyPin machine.Pin) Device { +func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device { return Device{ buffer: make([]uint8, (uint32(Width)*uint32(Height))/8), bus: bus,