1
0

pinctrl: Create extendable Signal classes

This commit is contained in:
Megan Wachs
2017-09-22 13:17:31 -07:00
parent 38f537c438
commit 81e301f9f7
6 changed files with 42 additions and 60 deletions

View File

@ -9,18 +9,19 @@ import sifive.blocks.devices.pinctrl.{Pin}
// even though it looks like something that more directly talks to
// a pin. It also makes it possible to change the exact
// type of pad this connects to.
class GPIOPins[T <: Pin] (pingen: ()=> T, c: GPIOParams) extends Bundle {
class GPIOSignals[T <: Data] (pingen: ()=> T, c: GPIOParams) extends Bundle {
val pins = Vec(c.width, pingen())
}
override def cloneType: this.type =
this.getClass.getConstructors.head.newInstance(pingen, c).asInstanceOf[this.type]
class GPIOPins[T <: Pin] (pingen: ()=> T, c: GPIOParams) extends GPIOSignals[T](pingen, c)
def fromPort(port: GPIOPortIO){
object GPIOPinsFromPort {
def apply[T <: Pin](pins: GPIOSignals[T], port: GPIOPortIO){
// This will just match up the components of the Bundle that
// exist in both.
(pins zip port.pins) foreach {case (pin, port) =>
(pins.pins zip port.pins) foreach {case (pin, port) =>
pin <> port
}
}