|
8 | 8 | package machine
|
9 | 9 |
|
10 | 10 | import (
|
11 |
| - "device" |
12 | 11 | "device/arm"
|
13 | 12 | "device/sam"
|
14 | 13 | "errors"
|
@@ -1301,43 +1300,21 @@ var (
|
1301 | 1300 | // spi.Tx(nil, rx)
|
1302 | 1301 | //
|
1303 | 1302 | 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) |
1306 | 1310 |
|
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 |
1322 | 1315 | }
|
1323 | 1316 |
|
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) |
1341 | 1318 | }
|
1342 | 1319 |
|
1343 | 1320 | return nil
|
@@ -1390,48 +1367,6 @@ func (spi SPI) txrx(tx, rx []byte) {
|
1390 | 1367 | rx[len(rx)-1] = byte(spi.Bus.DATA.Get())
|
1391 | 1368 | }
|
1392 | 1369 |
|
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 |
| - |
1435 | 1370 | // TCC is one timer/counter peripheral, which consists of a counter and multiple
|
1436 | 1371 | // output channels (that can be connected to actual pins). You can set the
|
1437 | 1372 | // frequency using SetPeriod, but only for all the channels in this TCC
|
|
0 commit comments