Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
iCE40 IO stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed May 24, 2024
1 parent c97f0d7 commit f0fdad8
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/ee/hrzn/chryse/platform/ice40/ICE40Top.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ICE40Top[Top <: Module](

private val clki = Wire(Clock())

private val clk_gb = Module(new SB_GB)
clk_gb.USER_SIGNAL_TO_GLOBAL_BUFFER := clki
private val clk_gb = Module(new SB_GB_IO)
clk_gb.PACKAGE_PIN := clki
private val clk = clk_gb.GLOBAL_BUFFER_OUTPUT

private val timerLimit = (15e-6 * platform.clockHz).toInt
Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/ice40/IOStandard.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ee.hrzn.chryse.platform.ice40

object IOStandard {
val LV_CMOS = "SB_LVCMOS"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final case class IceBreakerPlatform(ubtnReset: Boolean = false)
}

class IceBreakerPlatformResources extends PlatformBoardResources {
// TODO: IO_STANDARD=SB_LVCMOS needs to be set on most.
// TODO: IO_STANDARD=SB_LVCMOS needs to be set on most SB_IOs.
val clock = resource.ClockSource(12_000_000).onPin(35)

val ubtn = resource.Button().inverted.onPin(10)
Expand Down
10 changes: 10 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/ice40/PinType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ee.hrzn.chryse.platform.ice40

// See SiliconBlue ICE™ Technology Library.
object PinType {
val PIN_INPUT = 0x1

val PIN_NO_OUTPUT = 0x0
val PIN_OUTPUT = 0x18
val PIN_OUTPUT_TRISTATE = 0x28
}
9 changes: 0 additions & 9 deletions src/main/scala/ee/hrzn/chryse/platform/ice40/SB_GB.scala

This file was deleted.

15 changes: 15 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/ice40/SB_GB_IO.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ee.hrzn.chryse.platform.ice40

import chisel3._
import chisel3.experimental.ExtModule

class SB_GB_IO(pinType: Int = (PinType.PIN_INPUT | PinType.PIN_NO_OUTPUT))
extends ExtModule(
Map(
"IO_STANDARD" -> IOStandard.LV_CMOS,
"PIN_TYPE" -> pinType,
),
) {
val PACKAGE_PIN = IO(Input(Clock()))
val GLOBAL_BUFFER_OUTPUT = IO(Output(Clock()))
}
32 changes: 32 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/ice40/SB_IO.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ee.hrzn.chryse.platform.ice40

import chisel3._
import chisel3.experimental.Analog
import chisel3.experimental.ExtModule

class SB_IO(
pinType: Int,
ioStandard: String = IOStandard.LV_CMOS,
pullup: Boolean = false,
) extends ExtModule(
Map(
"IO_STANDARD" -> ioStandard,
"PIN_TYPE" -> pinType,
"PULLUP" -> (if (pullup) 1 else 0),
),
) {

private def genPin(): Data = {
if (pinType == PinType.PIN_INPUT)
Input(Bool())
else if (pinType == PinType.PIN_OUTPUT)
Output(Bool())
else if (pinType == (PinType.PIN_INPUT | PinType.PIN_OUTPUT_TRISTATE))
Analog(1.W)
else
throw new IllegalArgumentException(s"unhandled pinType: $pinType")

}
val PACKAGE_PIN = IO(genPin())
val GLOBAL_BUFFER_OUTPUT = IO(genPin())
}

0 comments on commit f0fdad8

Please sign in to comment.