@@ -203,16 +203,8 @@ func (a ADC) Get() uint16 {
203
203
// SPI on the NRF.
204
204
type SPI struct {
205
205
Bus * nrf.SPIM_Type
206
- buf * [1 ]byte // 1-byte buffer for the Transfer method
207
206
}
208
207
209
- // There are 3 SPI interfaces on the NRF528xx.
210
- var (
211
- SPI0 = SPI {Bus : nrf .SPIM0 , buf : new ([1 ]byte )}
212
- SPI1 = SPI {Bus : nrf .SPIM1 , buf : new ([1 ]byte )}
213
- SPI2 = SPI {Bus : nrf .SPIM2 , buf : new ([1 ]byte )}
214
- )
215
-
216
208
// SPIConfig is used to store config info for SPI.
217
209
type SPIConfig struct {
218
210
Frequency uint32
@@ -224,7 +216,7 @@ type SPIConfig struct {
224
216
}
225
217
226
218
// Configure is intended to setup the SPI interface.
227
- func (spi SPI ) Configure (config SPIConfig ) error {
219
+ func (spi * SPI ) Configure (config SPIConfig ) error {
228
220
// Disable bus to configure it
229
221
spi .Bus .ENABLE .Set (nrf .SPIM_ENABLE_ENABLE_Disabled )
230
222
@@ -276,10 +268,9 @@ func (spi SPI) Configure(config SPIConfig) error {
276
268
}
277
269
278
270
// Transfer writes/reads a single byte using the SPI interface.
279
- func (spi SPI ) Transfer (w byte ) (byte , error ) {
280
- buf := spi .buf [:]
281
- buf [0 ] = w
282
- err := spi .Tx (buf [:], buf [:])
271
+ func (spi * SPI ) Transfer (w byte ) (byte , error ) {
272
+ buf := []byte {w }
273
+ err := spi .Tx (buf , buf )
283
274
return buf [0 ], err
284
275
}
285
276
@@ -288,7 +279,7 @@ func (spi SPI) Transfer(w byte) (byte, error) {
288
279
// as bytes read. Therefore, if the number of bytes don't match it will be
289
280
// padded until they fit: if len(w) > len(r) the extra bytes received will be
290
281
// dropped and if len(w) < len(r) extra 0 bytes will be sent.
291
- func (spi SPI ) Tx (w , r []byte ) error {
282
+ func (spi * SPI ) Tx (w , r []byte ) error {
292
283
// Unfortunately the hardware (on the nrf52832) only supports up to 255
293
284
// bytes in the buffers, so if either w or r is longer than that the
294
285
// transfer needs to be broken up in pieces.
0 commit comments