X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmain%2Fscala%2Fdevices%2Fi2c%2FI2CPins.scala;h=2e294238d0b5286b1c50a2407aa1a8d5331f0f08;hb=1feaefe4c5c8e36682f29508b8e5e2ee9c4d7038;hp=d7017bca46f249010bf648bd2613baa94aa0472c;hpb=9d2a173b15ff2f9c546d95261fd171cf6da51328;p=sifive-blocks.git diff --git a/src/main/scala/devices/i2c/I2CPins.scala b/src/main/scala/devices/i2c/I2CPins.scala index d7017bc..2e29423 100644 --- a/src/main/scala/devices/i2c/I2CPins.scala +++ b/src/main/scala/devices/i2c/I2CPins.scala @@ -2,26 +2,27 @@ package sifive.blocks.devices.i2c import Chisel._ -import sifive.blocks.devices.gpio.{GPIOPin, GPIOOutputPinCtrl} -import sifive.blocks.util.ShiftRegisterInit +import chisel3.experimental.{withClockAndReset} +import freechips.rocketchip.util.SynchronizerShiftRegInit +import sifive.blocks.devices.pinctrl.{Pin, PinCtrl} +class I2CPins[T <: Pin](pingen: () => T) extends Bundle { -class I2CPinsIO extends Bundle { - val scl = new GPIOPin - val sda = new GPIOPin -} + val scl: T = pingen() + val sda: T = pingen() -class I2CGPIOPort(syncStages: Int = 0) extends Module { - val io = new Bundle{ - val i2c = new I2CPort().flip() - val pins = new I2CPinsIO - } + override def cloneType: this.type = + this.getClass.getConstructors.head.newInstance(pingen).asInstanceOf[this.type] - GPIOOutputPinCtrl(io.pins.scl, io.i2c.scl.out, pue=true.B, ie = true.B) - io.pins.scl.o.oe := io.i2c.scl.oe - io.i2c.scl.in := ShiftRegisterInit(io.pins.scl.i.ival, syncStages, Bool(true)) + def fromPort(i2c: I2CPort, clock: Clock, reset: Bool, syncStages: Int = 0) = { + withClockAndReset(clock, reset) { + scl.outputPin(i2c.scl.out, pue=true.B, ie = true.B) + scl.o.oe := i2c.scl.oe + i2c.scl.in := SynchronizerShiftRegInit(scl.i.ival, syncStages, init = Bool(true)) - GPIOOutputPinCtrl(io.pins.sda, io.i2c.sda.out, pue=true.B, ie = true.B) - io.pins.sda.o.oe := io.i2c.sda.oe - io.i2c.sda.in := ShiftRegisterInit(io.pins.sda.i.ival, syncStages, Bool(true)) + sda.outputPin(i2c.sda.out, pue=true.B, ie = true.B) + sda.o.oe := i2c.sda.oe + i2c.sda.in := SynchronizerShiftRegInit(sda.i.ival, syncStages, init = Bool(true)) + } + } }