Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * SpinalHDL
- * Copyright (c) Dolu, All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3.0 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library.
- */
- package MyCode
- //import MyCode.VgaCtrl.{Rgb, VgaTimingsHV}
- import spinal.core._
- import spinal.lib._
- import spinal.lib.cpu.riscv.impl.UtilsTest.TopLevel
- class VgaCtrl(rgbConfig: RgbConfig, timingsWidth: Int = 12) extends Component {
- val io = new Bundle {
- val softReset = in Bool
- val timings = in(VgaTimings(timingsWidth))
- val colorStream = slave Stream (Rgb(rgbConfig))
- val error = out Bool
- val frameStart = out Bool
- val vga = master(Vga(rgbConfig))
- }
- case class HVArea(timingsHV: VgaTimingsHV, enable: Bool) extends Area {
- val counter = Reg(UInt(timingsWidth bit)) init(0)
- val syncStart = counter === timingsHV.syncStart
- val syncEnd = counter === timingsHV.syncEnd
- val colorStart = counter === timingsHV.colorStart
- val colorEnd = counter === timingsHV.colorEnd
- when(enable) {
- counter := counter + 1
- when(syncEnd) {
- counter := 0
- }
- val h = HVArea(io.timings.h, True)
- val v = HVArea(io.timings.v, h.syncEnd)
- val colorEn = h.colorEn && v.colorEn
- io.pixels.ready := colorEn
- io.error := colorEn && ! io.pixels.valid
- io.frameStart := v.syncEnd
- io.vga.hSync := h.sync
- io.vga.vSync := v.sync
- io.vga.colorEn := colorEn
- io.vga.color := io.pixels.payload
- }
- val sync = RegInit(False) setWhen(syncStart) clearWhen(syncEnd)
- val colorEn = RegInit(False) setWhen(colorStart) clearWhen(colorEnd)
- when(io.softReset) {
- counter := 0
- sync := False
- colorEn := False
- }
- }
- val h = HVArea(io.timings.h, True)
- val v = HVArea(io.timings.v, h.syncEnd)
- }
- case class RgbConfig(rWidth : Int,gWidth : Int,bWidth : Int){
- def getWidth = rWidth + gWidth + bWidth
- }
- case class Rgb(c: RgbConfig) extends Bundle{
- val r = UInt(c.rWidth bit)
- val g = UInt(c.gWidth bit)
- val b = UInt(c.bWidth bit)
- }
- case class Vga (rgbConfig: RgbConfig) extends Bundle with IMasterSlave{
- val vSync = Bool
- val hSync = Bool
- val colorEn = Bool
- val color = Rgb(rgbConfig)
- override def asMaster() = this.asOutput()
- override def asSlave() = this.asInput()
- }
- case class VgaTimingsHV(timingsWidth: Int) extends Bundle {
- val colorStart = UInt(timingsWidth bit)
- val colorEnd = UInt(timingsWidth bit)
- val syncStart = UInt(timingsWidth bit)
- val syncEnd = UInt(timingsWidth bit)
- }
- case class VgaTimings(timingsWidth: Int) extends Bundle {
- val h = VgaTimingsHV(timingsWidth)
- val v = VgaTimingsHV(timingsWidth)
- def setAs_h640_v480_r60: Unit = {
- h.syncStart := 96 - 1
- h.syncEnd := 800 - 1
- h.colorStart := 96 + 16 - 1
- h.colorEnd := 800 - 48 - 1
- v.syncStart := 2 - 1
- v.syncEnd := 525 - 1
- v.colorStart := 2 + 10 - 1
- v.colorEnd := 525 - 33 - 1
- }
- def setAs_h64_v64_r60: Unit = {
- h.syncStart := 96 - 1
- h.syncEnd := 800 - 1
- h.colorStart := 96 + 16 - 1 + 288
- h.colorEnd := 800 - 48 - 1 - 288
- v.syncStart := 2 - 1
- v.syncEnd := 525 - 1
- v.colorStart := 2 + 10 - 1 + 208
- v.colorEnd := 525 - 33 - 1 - 208
- }
- }
- object VgaCtrl {
- def main(args: Array[String]) {
- SpinalVhdl(new TopLevel)
- }
- }
- /*Error:(68, 34) value setWhen is not a member of spinal.core.Bool
- val sync = RegInit(False) setWhen(syncStart) clearWhen(syncEnd)
- ^
- Error:(69, 34) value setWhen is not a member of spinal.core.Bool
- val colorEn = RegInit(False) setWhen(colorStart) clearWhen(colorEnd)
- ^
- Error:(56, 10) value pixels is not a member of spinal.core.Bundle{val softReset: spinal.core.Bool; val timings: MyCode.VgaTimings; val colorStream: spinal.lib.Stream[MyCode.Rgb]; val error: spinal.core.Bool; val frameStart: spinal.core.Bool; val vga: MyCode.Vga}
- io.pixels.ready := colorEn
- ^
- Error:(64, 26) value pixels is not a member of spinal.core.Bundle{val softReset: spinal.core.Bool; val timings: MyCode.VgaTimings; val colorStream: spinal.lib.Stream[MyCode.Rgb]; val error: spinal.core.Bool; val frameStart: spinal.core.Bool; val vga: MyCode.Vga}
- io.vga.color := io.pixels.payload
- ^*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement