Skip to content

Commit 6dcaea4

Browse files
committed
A bit of refactor
1 parent 332119f commit 6dcaea4

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/main/scala/spi/SerialSpiTest.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ class SerialSpiTest(id: Int, portName: String = "/dev/tty.usbserial-210292B40860
227227
Thread.sleep(300)
228228
readStatusRegister()
229229
}
230+
231+
def echoPins(sck: Int, mosi: Int, ncs: Int) = {
232+
// println(s"ncs: $ncs, mosi: $mosi, sck: $sck")
233+
val bits = (ncs << 2) | (mosi << 1) | sck
234+
val s = "w4" + (bits + '0').toChar + "4\r"
235+
writeReadSerial(s)
236+
val rx = writeReadSerial("r")
237+
// '8' is MISO bit set
238+
val bit = if (rx(8 - 1) == '8') 1 else 0
239+
// println("rx: " + rx)
240+
// println("bit: " + bit)
241+
bit
242+
}
230243
}
231244

232245
object SerialSpiTest extends App {

src/test/scala/spi/FlashTest.scala

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,10 @@ class FlashTest() extends AnyFlatSpec with ChiselScalatestTester {
2424
test(new SpiMaster) { c =>
2525

2626
def echoPins() = {
27-
val sck = c.spi.sclk.peekInt()
28-
val mosi = c.spi.mosi.peekInt()
29-
val ncs = c.spi.ncs.peekInt()
30-
// println(s"ncs: $ncs, mosi: $mosi, sck: $sck")
31-
val bits = (ncs << 2) | (mosi << 1) | sck
32-
val s = "w4" + (bits + '0').toChar + "4\r"
33-
spi.writeReadSerial(s)
34-
val rx = spi.writeReadSerial("r")
35-
// '8' is MISO bit set
36-
val bit = if (rx(8 - 1) == '8') 1 else 0
37-
// println("rx: " + rx)
38-
// println("bit: " + bit)
27+
val sck = c.spi.sclk.peekInt().toInt
28+
val mosi = c.spi.mosi.peekInt().toInt
29+
val ncs = c.spi.ncs.peekInt().toInt
30+
val bit = spi.echoPins(sck, mosi, ncs)
3931
c.spi.miso.poke(bit)
4032
}
4133
def readWord(addr: Int) = {

0 commit comments

Comments
 (0)