import Chisel._
import config.Field
-import diplomacy.LazyModule
-import rocketchip.{HasTopLevelNetworks,HasTopLevelNetworksBundle,HasTopLevelNetworksModule}
+import diplomacy.{LazyModule,LazyMultiIOModuleImp}
+import rocketchip.{HasSystemNetworks}
import uncore.tilelink2.TLFragmenter
case object PeripheryI2CKey extends Field[Seq[I2CParams]]
-trait HasPeripheryI2C extends HasTopLevelNetworks {
+trait HasPeripheryI2C extends HasSystemNetworks {
val i2cParams = p(PeripheryI2CKey)
val i2c = i2cParams map { params =>
val i2c = LazyModule(new TLI2C(peripheryBusBytes, params))
}
}
-trait HasPeripheryI2CBundle extends HasTopLevelNetworksBundle{
- val outer: HasPeripheryI2C
- val i2cs = Vec(outer.i2cParams.size, new I2CPort)
+trait HasPeripheryI2CBundle {
+ val i2cs: Vec[I2CPort]
+
+ def toGPIOPins(syncStages: Int = 0): Seq[I2CGPIOPort] = i2cs.map { i =>
+ val pin = Module(new I2CGPIOPort(syncStages))
+ pin.io.i2c <> i
+ pin
+ }
}
-trait HasPeripheryI2CModule extends HasTopLevelNetworksModule {
+trait HasPeripheryI2CModuleImp extends LazyMultiIOModuleImp with HasPeripheryI2CBundle {
val outer: HasPeripheryI2C
- val io: HasPeripheryI2CBundle
- (io.i2cs zip outer.i2c).foreach { case (io, device) =>
+ val i2cs = IO(Vec(outer.i2cParams.size, new I2CPort))
+
+ (i2cs zip outer.i2c).foreach { case (io, device) =>
io <> device.module.io.port
}
}