780e8cc35f5dc6fffa4321ede941769837cc6965
[sifive-blocks.git] / src / main / scala / devices / spi / SPIPins.scala
1 // See LICENSE for license details.
2 package sifive.blocks.devices.spi
3
4 import Chisel._
5 import chisel3.experimental.{withClockAndReset}
6 import sifive.blocks.devices.pinctrl.{PinCtrl, Pin}
7
8 class SPIPins[T <: Pin] (pingen: ()=> T, c: SPIParamsBase) extends SPIBundle(c) {
9
10 val sck = pingen()
11 val dq = Vec(4, pingen())
12 val cs = Vec(c.csWidth, pingen())
13
14 override def cloneType: this.type =
15 this.getClass.getConstructors.head.newInstance(pingen, c).asInstanceOf[this.type]
16
17 def fromPort(spi: SPIPortIO, clock: Clock, reset: Bool,
18 syncStages: Int = 0, driveStrength: Bool = Bool(false)) {
19
20 withClockAndReset(clock, reset) {
21 sck.outputPin(spi.sck, ds = driveStrength)
22
23 (dq zip spi.dq).foreach {case (p, s) =>
24 p.outputPin(s.o, pue = Bool(true), ds = driveStrength)
25 p.o.oe := s.oe
26 p.o.ie := ~s.oe
27 s.i := ShiftRegister(p.i.ival, syncStages)
28 }
29
30 (cs zip spi.cs) foreach { case (c, s) =>
31 c.outputPin(s, ds = driveStrength)
32 }
33 }
34 }
35 }