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

Commit

Permalink
UART: refactor into one Resource.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed May 22, 2024
1 parent 9171936 commit 22ca7e7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class IceBreakerResources extends BoardResources {

val ubtn = resource.Button().inverted.onPin(10)

val uart_tx = resource.UARTTX().onPin(9)
val uart_rx = resource.UARTRX().onPin(6)
val uart = resource.UART().onPins(rx = 6, tx = 9)

val ledg = resource.LED().inverted.onPin(37)
val ledr = resource.LED().inverted.onPin(11)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import scala.collection.mutable.ArrayBuffer

trait Resource {
def setName(name: String): Unit
def onPin(id: Pin): this.type
def bases(): List[Base[_ <: Data]]
}

Expand Down
25 changes: 25 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/resource/UART.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ee.hrzn.chryse.platform.resource

import chisel3._

class UART extends Resource {
val rx = new Base[Bool](Input(Bool())) {}
val tx = new Base[Bool](Output(Bool())) {}

def setName(name: String): Unit = {
rx.setName(s"${name}_rx")
tx.setName(s"${name}_tx")
}

def onPins(rx: Pin, tx: Pin): this.type = {
this.rx.onPin(rx)
this.tx.onPin(tx)
this
}

def bases(): List[Base[_ <: Data]] = List(rx, tx)
}

object UART {
def apply() = new UART
}
9 changes: 0 additions & 9 deletions src/main/scala/ee/hrzn/chryse/platform/resource/UARTRX.scala

This file was deleted.

9 changes: 0 additions & 9 deletions src/main/scala/ee/hrzn/chryse/platform/resource/UARTTX.scala

This file was deleted.

14 changes: 6 additions & 8 deletions src/test/scala/ee/hrzn/chryse/platform/BoardResourcesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ class BoardResourcesSpec extends AnyFlatSpec with Matchers {
"\\s+".r
.replaceAllIn(rtl, " ") should include(
"module chrysetop( " +
"input clock, ubtn, " +
"output uart_tx, " +
"input uart_rx, " +
"output ledr, pmod1a1, " +
"input clock, ubtn, uart_rx, " +
"output uart_tx, ledr, pmod1a1, " +
"input pmod1a2, " +
"output pmod1b1, " +
"input pmod1b2 " +
Expand All @@ -120,23 +118,23 @@ class BoardResourcesSpec extends AnyFlatSpec with Matchers {
class DetectionTop(platform: Platform) extends Module {
val plat = platform.asInstanceOf[IceBreakerPlatform]
plat.resources.ledg := plat.resources.ubtn
plat.resources.uart_tx := plat.resources.uart_rx
plat.resources.uart.tx := plat.resources.uart.rx
}

class InversionTop(platform: Platform) extends Module {
val plat = platform.asInstanceOf[IceBreakerPlatform]
// User button is inverted.
// UART isn't inverted.
plat.resources.uart_tx := plat.resources.ubtn
plat.resources.uart.tx := plat.resources.ubtn
// LED is inverted.
plat.resources.ledg := plat.resources.ubtn
}

class InOutTop(platform: Platform) extends Module {
val plat = platform.asInstanceOf[IceBreakerPlatform]
// Treat pmod1a1 as output, 1a2 as input.
plat.resources.pmod1a1.o := plat.resources.uart_rx
plat.resources.uart_tx := plat.resources.pmod1a2.i
plat.resources.pmod1a1.o := plat.resources.uart.rx
plat.resources.uart.tx := plat.resources.pmod1a2.i

// Do the same with 1b1 and 1b2, but use inverted inputs/outputs.
plat.resources.pmod1b1.o := plat.resources.ubtn
Expand Down

0 comments on commit 22ca7e7

Please sign in to comment.