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

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed May 29, 2024
1 parent 7b514e8 commit 868d137
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 30 deletions.
7 changes: 7 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/ecp5/PullMode.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ee.hrzn.chryse.platform.ecp5

object PullMode {
val UP = "UP"
val DOWN = "DOWN"
val NONE = "NONE"
}
59 changes: 37 additions & 22 deletions src/main/scala/ee/hrzn/chryse/platform/ecp5/ULX3SPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ee.hrzn.chryse.platform.PlatformBoard
import ee.hrzn.chryse.platform.PlatformBoardResources
import ee.hrzn.chryse.platform.resource.Button
import ee.hrzn.chryse.platform.resource.ClockSource
import ee.hrzn.chryse.platform.resource.Connector
import ee.hrzn.chryse.platform.resource.LED
import ee.hrzn.chryse.platform.resource.ResourceData
import ee.hrzn.chryse.platform.resource.SPIFlash
Expand Down Expand Up @@ -44,44 +45,58 @@ class ULX3SPlatformResources extends PlatformBoardResources {
val clock = ClockSource(25_000_000).onPin("G2")

val program =
LED().inverted.onPin("M4").withAttributes("PULLMODE" -> "UP")
LED().onPin("M4").withAttributes("PULLMODE" -> PullMode.UP)

// TODO: also expose RTS, DTR.
// TODO: also expose RTS, DTR inputs.
var uart = UART()
.onPins(rx = "M1", tx = "L4")
// TODO: either just unconditionally set this on, or only when uart.tx is
// accessed.
var uartTxEnable = ResourceData(Output(Bool())).onPin("L3")

// TODO
val led0 = LED().inverted.onPin("B2").withAttributes("DRIVE" -> 4)
val led1 = LED().inverted.onPin("C2").withAttributes("DRIVE" -> 4)
val led2 = LED().inverted.onPin("C1").withAttributes("DRIVE" -> 4)
val led3 = LED().inverted.onPin("D2").withAttributes("DRIVE" -> 4)
val led4 = LED().inverted.onPin("D1").withAttributes("DRIVE" -> 4)
val led5 = LED().inverted.onPin("E2").withAttributes("DRIVE" -> 4)
val led6 = LED().inverted.onPin("E1").withAttributes("DRIVE" -> 4)
val led7 = LED().inverted.onPin("H3").withAttributes("DRIVE" -> 4)
// val leds =
// resource
// .LEDs()
// .onPins("B2", "C2", "C1", "D2", "D1", "E2", "E1", "H3")
// .withAttributes("DRIVE" -> "4")
val leds = Connector(
LED().withAttributes("DRIVE" -> 4),
0 -> "B2",
1 -> "C2",
2 -> "C1",
3 -> "D2",
4 -> "D1",
5 -> "E2",
6 -> "E1",
7 -> "H3",
)

val spiFlash = SPIFlash()
.onPins(
csN = "R2", clock = USRMCLKPin, copi = "W2", cipo = "V2", wpN = "Y2",
holdN = "W1",
)
.withAttributes("PULLMODE" -> "NONE", "DRIVE" -> "4")
.withAttributes("PULLMODE" -> PullMode.NONE, "DRIVE" -> 4)

val buttonPwr =
Button().inverted.onPin("D6").withAttributes("PULLMODE" -> PullMode.UP)
val buttonFire0 =
Button().onPin("R1").withAttributes("PULLMODE" -> PullMode.DOWN)
val buttonFire1 =
Button().onPin("T1").withAttributes("PULLMODE" -> PullMode.DOWN)
val buttonLeft =
Button().onPin("U1").withAttributes("PULLMODE" -> PullMode.DOWN)
val buttonDown =
Button().onPin("V1").withAttributes("PULLMODE" -> PullMode.DOWN)
val buttonUp =
Button().onPin("R18").withAttributes("PULLMODE" -> PullMode.DOWN)
val buttonRight =
Button().onPin("H16").withAttributes("PULLMODE" -> PullMode.DOWN)

// val oledBl = onPin("J4")
// val oledCs = onPin("N2")
// val oledDc = onPin("P1")
// val oledRes = onPin("P2")
// val oledCopi = onPin("P3")
// val oledClk = onPin("P4")

// TODO
val butt0 = Button().inverted.onPin("D6").withAttributes("PULLMODE" -> "UP")
// val buttons =
// DIP switches
// UART
// SD card
// SPI flash
// SDRAM
// ADC
// TRRS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class IceBreakerPlatformResources extends PlatformBoardResources {
.onPins(rx = 6, tx = 9)
.withAttributes("IO_STANDARD" -> IOStandard.LVTTL, "PULLUP" -> 1)

val ledg = LED().inverted.onPin(37)
val ledr = LED().inverted.onPin(11)
val ledg = LED().onPin(37)
val ledr = LED().onPin(11)

var spiFlash =
SPIFlash()
Expand Down
11 changes: 11 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/resource/Disconnected.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ee.hrzn.chryse.platform.resource

import ee.hrzn.chryse.platform.resource.Pin
import ee.hrzn.chryse.platform.resource.PinPlatform

import scala.language.implicitConversions

object Disconnected {
implicit def disconnected2Pin(disc: this.type): Pin =
PinPlatform(this)
}
6 changes: 3 additions & 3 deletions src/main/scala/ee/hrzn/chryse/platform/resource/LED.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package ee.hrzn.chryse.platform.resource

import chisel3._

class LED
extends ResourceData(Output(Bool()))
with ResourceDataUserInvertible {}
class LED extends ResourceData(Output(Bool())) {
_invert = true
}

object LED {
def apply() = new LED
Expand Down
65 changes: 65 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/resource/SPIOLED.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ee.hrzn.chryse.platform.resource

import chisel3._
import chisel3.experimental.Param

class SPIOLED extends ResourceBase {
val cs = ResourceData(Output(Bool()), invert = true)
val clock = ResourceData(Output(Clock()))
val copi = ResourceData(Output(Bool()))
val cipo = ResourceData(Input(Bool()))
val wp = ResourceData(Output(Bool()), invert = true)
val hold = ResourceData(Output(Bool()), invert = true)

def setName(name: String): Unit = {
cs.setName(s"${name}_cs")
clock.setName(s"${name}_clock")
copi.setName(s"${name}_copi")
cipo.setName(s"${name}_cipo")
wp.setName(s"${name}_wp")
hold.setName(s"${name}_hold")
}

def withAttributes(attribs: (String, Param)*): this.type = {
cs.withAttributes(attribs: _*)
clock.withAttributes(attribs: _*)
copi.withAttributes(attribs: _*)
cipo.withAttributes(attribs: _*)
wp.withAttributes(attribs: _*)
hold.withAttributes(attribs: _*)
this
}

def setDefaultAttributes(defaultAttributes: Map[String, Param]): Unit = {
cs.setDefaultAttributes(defaultAttributes)
clock.setDefaultAttributes(defaultAttributes)
copi.setDefaultAttributes(defaultAttributes)
cipo.setDefaultAttributes(defaultAttributes)
wp.setDefaultAttributes(defaultAttributes)
hold.setDefaultAttributes(defaultAttributes)
}

def onPins(
csN: Pin,
clock: Pin,
copi: Pin,
cipo: Pin,
wpN: Pin,
holdN: Pin,
): this.type = {
this.cs.onPin(csN)
this.clock.onPin(clock)
this.copi.onPin(copi)
this.cipo.onPin(cipo)
this.wp.onPin(wpN)
this.hold.onPin(holdN)
this
}

def data: Seq[ResourceData[_ <: Data]] =
Seq(cs, clock, copi, cipo, wp, hold)
}

object SPIOLED {
def apply() = new SPIOLED
}
6 changes: 3 additions & 3 deletions src/test/scala/ee/hrzn/chryse/platform/SimPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class SimPlatformResources extends PlatformBoardResources {

val uart = UART().onPins(rx = "C3", tx = "D4")

val ledg = LED().inverted.onPin("E5")
val ledr = LED().inverted.onPin("F6")
val led3 = LED().inverted.onPin("G7")
val ledg = LED().onPin("E5")
val ledr = LED().onPin("F6")
val led3 = LED().onPin("G7")

val pmod = Connector(
InOut(),
Expand Down

0 comments on commit 868d137

Please sign in to comment.