@@ -16,12 +16,12 @@ func (e CustomError) Error() string {
16
16
17
17
// SPIComm implements RegisterComm for SPI-based communication
18
18
type SPIComm struct {
19
- spi machine.SPI
19
+ spi * machine.SPI
20
20
CsPins map [uint8 ]machine.Pin // Map to store CS pin for each Driver by its address
21
21
}
22
22
23
23
// NewSPIComm creates a new SPIComm instance.
24
- func NewSPIComm (spi machine.SPI , csPins map [uint8 ]machine.Pin ) * SPIComm {
24
+ func NewSPIComm (spi * machine.SPI , csPins map [uint8 ]machine.Pin ) * SPIComm {
25
25
return & SPIComm {
26
26
spi : spi ,
27
27
CsPins : csPins ,
@@ -31,7 +31,7 @@ func NewSPIComm(spi machine.SPI, csPins map[uint8]machine.Pin) *SPIComm {
31
31
// Setup initializes the SPI communication with the Driver and configures all CS pins.
32
32
func (comm * SPIComm ) Setup () error {
33
33
// Check if SPI is initialized
34
- if comm .spi == (machine. SPI {}) {
34
+ if comm .spi == nil {
35
35
return CustomError ("SPI not initialized" )
36
36
}
37
37
@@ -66,7 +66,7 @@ func (comm *SPIComm) WriteRegister(register uint8, value uint32, driverAddress u
66
66
addressWithWriteAccess := register | 0x80
67
67
68
68
// Send the address and the data to write (split into 4 bytes)
69
- _ , err := spiTransfer40 (& comm .spi , addressWithWriteAccess , value )
69
+ _ , err := spiTransfer40 (comm .spi , addressWithWriteAccess , value )
70
70
if err != nil {
71
71
csPin .High ()
72
72
return CustomError ("Failed to write register" )
@@ -88,7 +88,7 @@ func (comm *SPIComm) ReadRegister(register uint8, driverAddress uint8) (uint32,
88
88
csPin .Low ()
89
89
90
90
// Step 1: Send a dummy write operation to begin the read sequence
91
- _ , err := spiTransfer40 (& comm .spi , register , 0x00 ) // Send dummy data
91
+ _ , err := spiTransfer40 (comm .spi , register , 0x00 ) // Send dummy data
92
92
if err != nil {
93
93
csPin .High ()
94
94
return 0 , CustomError ("Failed to send dummy write" )
@@ -97,7 +97,7 @@ func (comm *SPIComm) ReadRegister(register uint8, driverAddress uint8) (uint32,
97
97
time .Sleep (176 * time .Nanosecond )
98
98
csPin .Low ()
99
99
// Step 2: Send the register read request again to get the actual value
100
- response , err := spiTransfer40 (& comm .spi , register , 0x00 ) // Send again to get actual register data
100
+ response , err := spiTransfer40 (comm .spi , register , 0x00 ) // Send again to get actual register data
101
101
if err != nil {
102
102
csPin .High ()
103
103
return 0 , CustomError ("Failed to read register" )
0 commit comments