1 // See LICENSE for license details.
2 package sifive.blocks.devices.spi
5 import chisel3.experimental.{withClockAndReset}
6 import sifive.blocks.devices.pinctrl.{PinCtrl, Pin}
8 class SPISignals[T <: Data] (pingen: ()=> T, c: SPIParamsBase) extends SPIBundle(c) {
11 val dq = Vec(4, pingen())
12 val cs = Vec(c.csWidth, pingen())
14 override def cloneType: this.type =
15 this.getClass.getConstructors.head.newInstance(pingen, c).asInstanceOf[this.type]
19 class SPIPins[T <: Pin] (pingen: ()=> T, c: SPIParamsBase) extends SPISignals(pingen, c) {
21 override def cloneType: this.type =
22 this.getClass.getConstructors.head.newInstance(pingen, c).asInstanceOf[this.type]
24 def fromPort(spi: SPIPortIO, clock: Clock, reset: Bool,
25 syncStages: Int = 0, driveStrength: Bool = Bool(false)) {
27 withClockAndReset(clock, reset) {
28 sck.outputPin(spi.sck, ds = driveStrength)
30 (dq zip spi.dq).foreach {case (p, s) =>
31 p.outputPin(s.o, pue = Bool(true), ds = driveStrength)
34 s.i := ShiftRegister(p.i.ival, syncStages)
37 (cs zip spi.cs) foreach { case (c, s) =>
38 c.outputPin(s, ds = driveStrength)