Skip to content

Commit 102798a

Browse files
committed
fix: cr suggestions
1 parent d1e3188 commit 102798a

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

examples/w5500/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ func main() {
1616
})
1717
machine.GPIO17.Configure(machine.PinConfig{Mode: machine.PinOutput})
1818

19-
eth := w5500.New()
19+
eth := w5500.New(machine.SPI0, machine.GPIO17.Set)
2020
eth.Configure(w5500.Config{
21-
SPI: machine.SPI0,
22-
CS: machine.GPIO17.Set,
2321
MAC: net.HardwareAddr{0xee, 0xbe, 0xe9, 0xa9, 0xb6, 0x4f},
2422
IP: netip.AddrFrom4([4]byte{192, 168, 1, 2}),
2523
SubnetMask: netip.AddrFrom4([4]byte{255, 255, 255, 0}),

w5500/io.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ func (d *Device) sendReadHeader(addr uint16, bsb uint8) {
104104
buf[0] = byte(addr >> 8)
105105
buf[1] = byte(addr & 0xff)
106106
buf[2] = bsb<<3 | 0b000
107-
_ = d.bus.Tx(buf, nil)
107+
_ = d.bus.Tx(buf[:], nil)
108108
}
109109

110110
func (d *Device) sendWriteHeader(addr uint16, bsb uint8) {
111111
buf := d.cmdBuf
112112
buf[0] = byte(addr >> 8)
113113
buf[1] = byte(addr & 0xff)
114114
buf[2] = bsb<<3 | 0b100
115-
_ = d.bus.Tx(buf, nil)
115+
_ = d.bus.Tx(buf[:], nil)
116116
}

w5500/w5500.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,21 @@ type Device struct {
3333
sockets []*socket
3434
laddr netip.Addr
3535

36-
cmdBuf []byte
36+
cmdBuf [3]byte
3737
}
3838

3939
// New returns a new w5500 driver.
40-
func New() *Device {
40+
func New(bus drivers.SPI, cs PinOutput) *Device {
4141
return &Device{
42-
cmdBuf: make([]byte, 3),
42+
bus: bus,
43+
cs: cs,
4344
}
4445
}
4546

4647
// Config is the configuration for the device.
4748
//
4849
// The SPI bus must be fully configured.
4950
type Config struct {
50-
SPI drivers.SPI
51-
CS PinOutput
5251
DNS Resolver
5352

5453
MAC net.HardwareAddr
@@ -64,13 +63,11 @@ type Config struct {
6463
//
6564
// MAC address must be provided. The other fields are optional.
6665
func (d *Device) Configure(cfg Config) error {
67-
cfg.CS(true)
66+
d.cs(true)
6867

6968
d.mu.Lock()
7069
defer d.mu.Unlock()
7170

72-
d.bus = cfg.SPI
73-
d.cs = cfg.CS
7471
d.dns = cfg.DNS
7572

7673
d.reset()

0 commit comments

Comments
 (0)