MuraxSim add switch
This commit is contained in:
parent
53970dd284
commit
9b2cd7b234
|
@ -1,15 +1,13 @@
|
|||
package vexriscv
|
||||
|
||||
import java.awt
|
||||
import java.awt.event.{ActionEvent, ActionListener}
|
||||
import java.awt.event.{ActionEvent, ActionListener, MouseEvent, MouseListener}
|
||||
|
||||
import spinal.sim._
|
||||
import spinal.core._
|
||||
import spinal.core.sim._
|
||||
import vexriscv.demo.{Murax, MuraxConfig}
|
||||
import java.awt.{Color, Dimension, Graphics, GridLayout}
|
||||
import javax.annotation.processing.SupportedSourceVersion
|
||||
import javax.swing.{BoxLayout, JButton, JFrame, JPanel}
|
||||
import javax.swing._
|
||||
|
||||
import spinal.lib.com.jtag.sim.JtagTcp
|
||||
import spinal.lib.com.uart.sim.{UartDecoder, UartEncoder}
|
||||
|
@ -53,25 +51,19 @@ object MuraxSim {
|
|||
val guiToSim = mutable.Queue[Any]()
|
||||
|
||||
var ledsValue = 0l
|
||||
var switchValue : () => BigInt = null
|
||||
val ledsFrame = new JFrame{
|
||||
setLayout(new BoxLayout(getContentPane, BoxLayout.Y_AXIS))
|
||||
add(new JPanel{
|
||||
val ledDiameter = 20
|
||||
val blackThickness = 2
|
||||
override def paintComponent(g : Graphics) : Unit = {
|
||||
for(i <- 0 to 7) {
|
||||
g.setColor(Color.BLACK)
|
||||
val x = i*ledDiameter + 1
|
||||
g.fillOval(x,1,ledDiameter,ledDiameter);
|
||||
if (((ledsValue >> (7-i)) & 1) != 0) {
|
||||
g.setColor(Color.GREEN.darker())
|
||||
g.fillOval(x+blackThickness,3,ledDiameter-blackThickness*2,ledDiameter-blackThickness*2);
|
||||
}
|
||||
}
|
||||
g.setColor(Color.BLACK)
|
||||
}
|
||||
this.setPreferredSize(new Dimension(ledDiameter*8+2, ledDiameter+2))
|
||||
|
||||
add(new JLedArray(8){
|
||||
override def getValue = ledsValue
|
||||
})
|
||||
add{
|
||||
val switches = new JSwitchArray(8)
|
||||
switchValue = switches.getValue
|
||||
switches
|
||||
}
|
||||
|
||||
add(new JButton("Reset"){
|
||||
addActionListener(new ActionListener {
|
||||
override def actionPerformed(actionEvent: ActionEvent): Unit = {
|
||||
|
@ -87,6 +79,12 @@ object MuraxSim {
|
|||
|
||||
}
|
||||
|
||||
//Fast refresh
|
||||
clockDomain.onSampling{
|
||||
dut.io.gpioA.read #= (dut.io.gpioA.write.toLong & dut.io.gpioA.writeEnable.toLong) | (switchValue() << 8)
|
||||
}
|
||||
|
||||
//Slow refresh
|
||||
while(true){
|
||||
sleep(mainClkPeriod*50000)
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package vexriscv
|
||||
|
||||
import java.awt.{Color, Dimension, Graphics}
|
||||
import java.awt.event.{MouseEvent, MouseListener}
|
||||
import javax.swing.JPanel
|
||||
|
||||
abstract class JLedArray(ledCount : Int,ledDiameter : Int = 20, blackThickness : Int = 2) extends JPanel{
|
||||
def getValue() : BigInt
|
||||
|
||||
override def paintComponent(g : Graphics) : Unit = {
|
||||
val value = getValue()
|
||||
for(i <- 0 to ledCount-1) {
|
||||
g.setColor(Color.BLACK)
|
||||
val x = i*ledDiameter + 1
|
||||
g.fillOval(x,1,ledDiameter,ledDiameter)
|
||||
if (((value >> (ledCount-1-i)) & 1) != 0) {
|
||||
g.setColor(Color.GREEN.darker())
|
||||
g.fillOval(x+blackThickness,3,ledDiameter-blackThickness*2,ledDiameter-blackThickness*2);
|
||||
}
|
||||
}
|
||||
g.setColor(Color.BLACK)
|
||||
}
|
||||
this.setPreferredSize(new Dimension(ledDiameter*ledCount+2, ledDiameter+2))
|
||||
}
|
||||
|
||||
class JSwitchArray(ledCount : Int,switchDiameter : Int = 20, blackThickness : Int = 2) extends JPanel{
|
||||
var value = BigInt(0)
|
||||
def getValue() = value
|
||||
addMouseListener(new MouseListener {
|
||||
override def mouseExited(mouseEvent: MouseEvent): Unit = {}
|
||||
override def mousePressed(mouseEvent: MouseEvent): Unit = {}
|
||||
override def mouseReleased(mouseEvent: MouseEvent): Unit = {}
|
||||
override def mouseEntered(mouseEvent: MouseEvent): Unit = {}
|
||||
override def mouseClicked(mouseEvent: MouseEvent): Unit = {
|
||||
val idx = ledCount-1-(mouseEvent.getX-2)/switchDiameter
|
||||
value ^= BigInt(1) << idx
|
||||
}
|
||||
})
|
||||
override def paintComponent(g : Graphics) : Unit = {
|
||||
for(i <- 0 to ledCount-1) {
|
||||
g.setColor(Color.GRAY.darker())
|
||||
val x = i*switchDiameter + 1
|
||||
g.fillRect(x,1,switchDiameter,switchDiameter)
|
||||
if (((value >> (ledCount-1-i)) & 1) != 0) {
|
||||
g.setColor(Color.GRAY)
|
||||
}else{
|
||||
g.setColor(Color.GRAY.brighter())
|
||||
}
|
||||
g.fillRect(x+blackThickness,3,switchDiameter-blackThickness*2,switchDiameter-blackThickness*2);
|
||||
|
||||
}
|
||||
g.setColor(Color.BLACK)
|
||||
}
|
||||
this.setPreferredSize(new Dimension(switchDiameter*ledCount+2, switchDiameter+2))
|
||||
}
|
Loading…
Reference in New Issue