X-Git-Url: https://git.libre-soc.org/?p=sifive-blocks.git;a=blobdiff_plain;f=src%2Fmain%2Fscala%2Fdevices%2Fspi%2FSPIPins.scala;h=f8ce8e1d0332bd1b42c0202700001173d57c7432;hp=c5013168cb66c46d5e726d521a794ae50ed8b538;hb=39287b92159e7f7a25635dfe7cc5cb7dc01488bc;hpb=4d74e8f67f871df93f7bb2dfb2fa8bffb641fc4a diff --git a/src/main/scala/devices/spi/SPIPins.scala b/src/main/scala/devices/spi/SPIPins.scala index c501316..f8ce8e1 100644 --- a/src/main/scala/devices/spi/SPIPins.scala +++ b/src/main/scala/devices/spi/SPIPins.scala @@ -2,27 +2,36 @@ package sifive.blocks.devices.spi import Chisel._ +import chisel3.experimental.{withClockAndReset} import sifive.blocks.devices.pinctrl.{PinCtrl, Pin} -class SPIPins[T <: Pin] (pingen: ()=> T, c: SPIParamsBase) extends SPIBundle(c) { +class SPISignals[T <: Data](private val pingen: () => T, c: SPIParamsBase) extends SPIBundle(c) { - val sck: T = pingen() - val dq: Vec[T] = Vec(4, pingen()) - val cs: Vec[T] = Vec(c.csWidth, pingen()) + val sck = pingen() + val dq = Vec(4, pingen()) + val cs = Vec(c.csWidth, pingen()) +} - def fromSPIPort(spi: SPIPortIO, syncStages: Int = 0, driveStrength: Bool = Bool(false)) { - - sck.outputPin(spi.sck, ds = driveStrength) +class SPIPins[T <: Pin] (pingen: ()=> T, c: SPIParamsBase) extends SPISignals(pingen, c) - (dq zip spi.dq).foreach {case (p, s) => - p.outputPin(s.o, pue = Bool(true), ds = driveStrength) - p.o.oe := s.oe - p.o.ie := ~s.oe - s.i := ShiftRegister(p.i.ival, syncStages) - } +object SPIPinsFromPort { + + def apply[T <: Pin](pins: SPISignals[T], spi: SPIPortIO, clock: Clock, reset: Bool, + syncStages: Int = 0, driveStrength: Bool = Bool(false)) { + + withClockAndReset(clock, reset) { + pins.sck.outputPin(spi.sck, ds = driveStrength) + + (pins.dq zip spi.dq).foreach {case (p, s) => + p.outputPin(s.o, pue = Bool(true), ds = driveStrength) + p.o.oe := s.oe + p.o.ie := ~s.oe + s.i := ShiftRegister(p.i.ival, syncStages) + } - (cs zip spi.cs) foreach { case (c, s) => - c.outputPin(s, ds = driveStrength) + (pins.cs zip spi.cs) foreach { case (c, s) => + c.outputPin(s, ds = driveStrength) + } } } }