40
40
ErrLSBNotSupported = errors .New ("SPI LSB unsupported on PL022" )
41
41
ErrSPITimeout = errors .New ("SPI timeout" )
42
42
ErrSPIBaud = errors .New ("SPI baud too low or above 66.5Mhz" )
43
+ errSPIInvalidSDI = errors .New ("invalid SPI SDI pin" )
44
+ errSPIInvalidSDO = errors .New ("invalid SPI SDO pin" )
45
+ errSPIInvalidSCK = errors .New ("invalid SPI SCK pin" )
43
46
)
44
47
45
48
type SPI struct {
@@ -162,7 +165,7 @@ func (spi SPI) GetBaudRate() uint32 {
162
165
// No pin configuration is needed of SCK, SDO and SDI needed after calling Configure.
163
166
func (spi SPI ) Configure (config SPIConfig ) error {
164
167
const defaultBaud uint32 = 115200
165
- if config .SCK == 0 {
168
+ if config .SCK == 0 && config . SDO == 0 && config . SDI == 0 {
166
169
// set default pins if config zero valued or invalid clock pin supplied.
167
170
switch spi .Bus {
168
171
case rp .SPI0 :
@@ -175,6 +178,25 @@ func (spi SPI) Configure(config SPIConfig) error {
175
178
config .SDI = SPI1_SDI_PIN
176
179
}
177
180
}
181
+ var okSDI , okSDO , okSCK bool
182
+ switch spi .Bus {
183
+ case rp .SPI0 :
184
+ okSDI = config .SDI == 0 || config .SDI == 4 || config .SDI == 17
185
+ okSDO = config .SDO == 3 || config .SDO == 7 || config .SDO == 19
186
+ okSCK = config .SCK == 2 || config .SCK == 6 || config .SCK == 18
187
+ case rp .SPI1 :
188
+ okSDI = config .SDI == 8 || config .SDI == 12
189
+ okSDO = config .SDO == 11 || config .SDO == 15
190
+ okSDO = config .SCK == 10 || config .SCK == 14
191
+ }
192
+
193
+ if ! okSDI {
194
+ return errSPIInvalidSDI
195
+ } else if ! okSDO {
196
+ return errSPIInvalidSDO
197
+ } else if ! okSCK {
198
+ return errSPIInvalidSCK
199
+ }
178
200
if config .DataBits < 4 || config .DataBits > 16 {
179
201
config .DataBits = 8
180
202
}
0 commit comments