Skip to content

Commit 6f61b83

Browse files
sago35deadprogram
authored andcommitted
atsamd21: remove special handling for SPI-24mhz
1 parent 8dfefb4 commit 6f61b83

File tree

1 file changed

+12
-77
lines changed

1 file changed

+12
-77
lines changed

src/machine/machine_atsamd21.go

Lines changed: 12 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package machine
99

1010
import (
11-
"device"
1211
"device/arm"
1312
"device/sam"
1413
"errors"
@@ -1301,43 +1300,21 @@ var (
13011300
// spi.Tx(nil, rx)
13021301
//
13031302
func (spi SPI) Tx(w, r []byte) error {
1304-
if spi.Bus.BAUD.Get() == 0x00 {
1305-
// When the SPI Freq is 24MHz, special processing is performed to improve the speed.
1303+
switch {
1304+
case w == nil:
1305+
// read only, so write zero and read a result.
1306+
spi.rx(r)
1307+
case r == nil:
1308+
// write only
1309+
spi.tx(w)
13061310

1307-
switch {
1308-
case w == nil:
1309-
// read only, so write zero and read a result.
1310-
spi.rx(r)
1311-
case r == nil:
1312-
// write only
1313-
spi.tx24mhz(w)
1314-
1315-
default:
1316-
// write/read
1317-
if len(w) != len(r) {
1318-
return ErrTxInvalidSliceSize
1319-
}
1320-
1321-
spi.txrx24mhz(w, r)
1311+
default:
1312+
// write/read
1313+
if len(w) != len(r) {
1314+
return ErrTxInvalidSliceSize
13221315
}
13231316

1324-
} else {
1325-
switch {
1326-
case w == nil:
1327-
// read only, so write zero and read a result.
1328-
spi.rx(r)
1329-
case r == nil:
1330-
// write only
1331-
spi.tx(w)
1332-
1333-
default:
1334-
// write/read
1335-
if len(w) != len(r) {
1336-
return ErrTxInvalidSliceSize
1337-
}
1338-
1339-
spi.txrx(w, r)
1340-
}
1317+
spi.txrx(w, r)
13411318
}
13421319

13431320
return nil
@@ -1390,48 +1367,6 @@ func (spi SPI) txrx(tx, rx []byte) {
13901367
rx[len(rx)-1] = byte(spi.Bus.DATA.Get())
13911368
}
13921369

1393-
// tx24mhz is a special tx/rx function for CPU Clock 48 Mhz and SPI Freq 24 Mhz
1394-
func (spi SPI) tx24mhz(tx []byte) {
1395-
spi.Bus.DATA.Set(uint32(tx[0]))
1396-
device.Asm("nop")
1397-
device.Asm("nop")
1398-
device.Asm("nop")
1399-
device.Asm("nop")
1400-
device.Asm("nop")
1401-
device.Asm("nop")
1402-
1403-
for i := 1; i < len(tx); i++ {
1404-
spi.Bus.DATA.Set(uint32(tx[i]))
1405-
device.Asm("nop")
1406-
device.Asm("nop")
1407-
spi.Bus.DATA.Get()
1408-
}
1409-
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPI_INTFLAG_RXC) {
1410-
}
1411-
spi.Bus.DATA.Get()
1412-
}
1413-
1414-
// txrx24mhz is a special tx/rx function for CPU Clock 48 Mhz and SPI Freq 24 Mhz
1415-
func (spi SPI) txrx24mhz(tx, rx []byte) {
1416-
spi.Bus.DATA.Set(uint32(tx[0]))
1417-
device.Asm("nop")
1418-
device.Asm("nop")
1419-
device.Asm("nop")
1420-
device.Asm("nop")
1421-
device.Asm("nop")
1422-
device.Asm("nop")
1423-
1424-
for i := 1; i < len(rx); i++ {
1425-
spi.Bus.DATA.Set(uint32(tx[i]))
1426-
device.Asm("nop")
1427-
device.Asm("nop")
1428-
rx[i-1] = byte(spi.Bus.DATA.Get())
1429-
}
1430-
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPI_INTFLAG_RXC) {
1431-
}
1432-
rx[len(rx)-1] = byte(spi.Bus.DATA.Get())
1433-
}
1434-
14351370
// TCC is one timer/counter peripheral, which consists of a counter and multiple
14361371
// output channels (that can be connected to actual pins). You can set the
14371372
// frequency using SetPeriod, but only for all the channels in this TCC

0 commit comments

Comments
 (0)