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 object SPIPinsFromPort {
23 def apply[T <: Pin](pins: SPISignals[T], spi: SPIPortIO, clock: Clock, reset: Bool,
24 syncStages: Int = 0, driveStrength: Bool = Bool(false)) {
26 withClockAndReset(clock, reset) {
27 pins.sck.outputPin(spi.sck, ds = driveStrength)
29 (pins.dq zip spi.dq).foreach {case (p, s) =>
30 p.outputPin(s.o, pue = Bool(true), ds = driveStrength)
33 s.i := ShiftRegister(p.i.ival, syncStages)
36 (pins.cs zip spi.cs) foreach { case (c, s) =>
37 c.outputPin(s, ds = driveStrength)