2013-09-17 12:15:22 -04:00
|
|
|
from migen.fhdl.std import *
|
|
|
|
from migen.flow.actor import *
|
|
|
|
from migen.bank.description import CSRStorage
|
2013-11-20 18:33:22 -05:00
|
|
|
from migen.genlib.record import Record
|
|
|
|
from migen.genlib.fsm import FSM, NextState
|
2013-09-17 12:15:22 -04:00
|
|
|
from migen.actorlib import spi
|
|
|
|
|
2013-11-17 17:41:18 -05:00
|
|
|
_hbits = 12
|
2013-09-17 12:15:22 -04:00
|
|
|
_vbits = 12
|
|
|
|
|
|
|
|
bpp = 32
|
|
|
|
bpc = 10
|
|
|
|
pixel_layout_s = [
|
|
|
|
("pad", bpp-3*bpc),
|
|
|
|
("r", bpc),
|
|
|
|
("g", bpc),
|
|
|
|
("b", bpc)
|
|
|
|
]
|
2013-11-17 17:41:18 -05:00
|
|
|
def pixel_layout(pack_factor):
|
|
|
|
return [("p"+str(i), pixel_layout_s) for i in range(pack_factor)]
|
2013-09-17 12:15:22 -04:00
|
|
|
|
|
|
|
bpc_phy = 8
|
|
|
|
phy_layout_s = [
|
|
|
|
("r", bpc_phy),
|
|
|
|
("g", bpc_phy),
|
|
|
|
("b", bpc_phy)
|
|
|
|
]
|
2013-11-17 17:41:18 -05:00
|
|
|
def phy_layout(pack_factor):
|
|
|
|
r = [("hsync", 1), ("vsync", 1), ("de", 1)]
|
|
|
|
for i in range(pack_factor):
|
|
|
|
r.append(("p"+str(i), phy_layout_s))
|
|
|
|
return r
|
2013-09-17 12:15:22 -04:00
|
|
|
|
|
|
|
class FrameInitiator(spi.SingleGenerator):
|
2013-11-20 18:33:22 -05:00
|
|
|
def __init__(self, bus_aw, pack_factor, ndmas=1):
|
2013-11-17 17:41:18 -05:00
|
|
|
h_alignment_bits = log2_int(pack_factor)
|
|
|
|
hbits_dyn = _hbits - h_alignment_bits
|
2013-11-20 18:33:22 -05:00
|
|
|
bus_alignment_bits = h_alignment_bits + log2_int(bpp//8)
|
2013-09-17 12:15:22 -04:00
|
|
|
layout = [
|
2013-11-17 17:41:18 -05:00
|
|
|
("hres", hbits_dyn, 640, h_alignment_bits),
|
|
|
|
("hsync_start", hbits_dyn, 656, h_alignment_bits),
|
|
|
|
("hsync_end", hbits_dyn, 752, h_alignment_bits),
|
|
|
|
("hscan", hbits_dyn, 800, h_alignment_bits),
|
2014-10-17 05:14:35 -04:00
|
|
|
|
2013-09-17 12:15:22 -04:00
|
|
|
("vres", _vbits, 480),
|
|
|
|
("vsync_start", _vbits, 492),
|
|
|
|
("vsync_end", _vbits, 494),
|
2013-11-20 18:33:22 -05:00
|
|
|
("vscan", _vbits, 525),
|
|
|
|
|
|
|
|
("length", bus_aw + bus_alignment_bits, 640*480*bpp//8, bus_alignment_bits)
|
2013-09-17 12:15:22 -04:00
|
|
|
]
|
2013-11-20 18:33:22 -05:00
|
|
|
layout += [("base"+str(i), bus_aw + bus_alignment_bits, 0, bus_alignment_bits)
|
|
|
|
for i in range(ndmas)]
|
|
|
|
spi.SingleGenerator.__init__(self, layout, spi.MODE_CONTINUOUS)
|
|
|
|
|
|
|
|
timing_subr = ["hres", "hsync_start", "hsync_end", "hscan",
|
|
|
|
"vres", "vsync_start", "vsync_end", "vscan"]
|
|
|
|
|
|
|
|
def dma_subr(self, i=0):
|
|
|
|
return ["length", "base"+str(i)]
|
2013-09-17 12:15:22 -04:00
|
|
|
|
|
|
|
class VTG(Module):
|
2013-11-17 17:41:18 -05:00
|
|
|
def __init__(self, pack_factor):
|
|
|
|
hbits_dyn = _hbits - log2_int(pack_factor)
|
2013-11-20 18:33:22 -05:00
|
|
|
timing_layout = [
|
|
|
|
("hres", hbits_dyn),
|
|
|
|
("hsync_start", hbits_dyn),
|
|
|
|
("hsync_end", hbits_dyn),
|
|
|
|
("hscan", hbits_dyn),
|
|
|
|
("vres", _vbits),
|
|
|
|
("vsync_start", _vbits),
|
|
|
|
("vsync_end", _vbits),
|
|
|
|
("vscan", _vbits)]
|
|
|
|
self.timing = Sink(timing_layout)
|
2013-11-17 17:41:18 -05:00
|
|
|
self.pixels = Sink(pixel_layout(pack_factor))
|
|
|
|
self.phy = Source(phy_layout(pack_factor))
|
2013-09-17 12:15:22 -04:00
|
|
|
self.busy = Signal()
|
|
|
|
|
2013-11-20 18:33:22 -05:00
|
|
|
###
|
|
|
|
|
2013-09-17 12:15:22 -04:00
|
|
|
hactive = Signal()
|
|
|
|
vactive = Signal()
|
|
|
|
active = Signal()
|
2014-10-17 05:14:35 -04:00
|
|
|
|
2013-11-17 17:41:18 -05:00
|
|
|
hcounter = Signal(hbits_dyn)
|
2013-09-17 12:15:22 -04:00
|
|
|
vcounter = Signal(_vbits)
|
2014-10-17 05:14:35 -04:00
|
|
|
|
2013-09-17 12:15:22 -04:00
|
|
|
skip = bpc - bpc_phy
|
|
|
|
self.comb += [
|
|
|
|
active.eq(hactive & vactive),
|
|
|
|
If(active,
|
|
|
|
[getattr(getattr(self.phy.payload, p), c).eq(getattr(getattr(self.pixels.payload, p), c)[skip:])
|
2013-11-17 17:41:18 -05:00
|
|
|
for p in ["p"+str(i) for i in range(pack_factor)] for c in ["r", "g", "b"]],
|
2014-10-20 11:13:33 -04:00
|
|
|
self.phy.de.eq(1)
|
2013-09-17 12:15:22 -04:00
|
|
|
),
|
2013-11-20 18:33:22 -05:00
|
|
|
self.pixels.ack.eq(self.phy.ack & active)
|
2013-09-17 12:15:22 -04:00
|
|
|
]
|
2013-11-20 18:33:22 -05:00
|
|
|
|
|
|
|
load_timing = Signal()
|
|
|
|
tr = Record(timing_layout)
|
|
|
|
self.sync += If(load_timing, tr.eq(self.timing.payload))
|
|
|
|
|
|
|
|
generate_en = Signal()
|
|
|
|
generate_frame_done = Signal()
|
2013-09-17 12:15:22 -04:00
|
|
|
self.sync += [
|
2013-11-20 18:33:22 -05:00
|
|
|
generate_frame_done.eq(0),
|
|
|
|
If(generate_en,
|
2013-11-19 17:48:00 -05:00
|
|
|
hcounter.eq(hcounter + 1),
|
2014-10-17 05:14:35 -04:00
|
|
|
|
2013-11-19 17:48:00 -05:00
|
|
|
If(hcounter == 0, hactive.eq(1)),
|
2013-11-20 18:33:22 -05:00
|
|
|
If(hcounter == tr.hres, hactive.eq(0)),
|
2014-10-20 11:13:33 -04:00
|
|
|
If(hcounter == tr.hsync_start, self.phy.hsync.eq(1)),
|
|
|
|
If(hcounter == tr.hsync_end, self.phy.hsync.eq(0)),
|
2013-11-20 18:33:22 -05:00
|
|
|
If(hcounter == tr.hscan,
|
2013-11-19 17:48:00 -05:00
|
|
|
hcounter.eq(0),
|
2013-11-20 18:33:22 -05:00
|
|
|
If(vcounter == tr.vscan,
|
2013-11-19 17:48:00 -05:00
|
|
|
vcounter.eq(0),
|
2013-11-20 18:33:22 -05:00
|
|
|
generate_frame_done.eq(1)
|
2013-11-19 17:48:00 -05:00
|
|
|
).Else(
|
|
|
|
vcounter.eq(vcounter + 1)
|
|
|
|
)
|
|
|
|
),
|
2014-10-17 05:14:35 -04:00
|
|
|
|
2013-11-19 17:48:00 -05:00
|
|
|
If(vcounter == 0, vactive.eq(1)),
|
2013-11-20 18:33:22 -05:00
|
|
|
If(vcounter == tr.vres, vactive.eq(0)),
|
2014-10-20 11:13:33 -04:00
|
|
|
If(vcounter == tr.vsync_start, self.phy.vsync.eq(1)),
|
|
|
|
If(vcounter == tr.vsync_end, self.phy.vsync.eq(0))
|
2013-09-17 12:15:22 -04:00
|
|
|
)
|
|
|
|
]
|
2013-11-20 18:33:22 -05:00
|
|
|
|
|
|
|
self.submodules.fsm = FSM()
|
|
|
|
self.fsm.act("GET_TIMING",
|
|
|
|
self.timing.ack.eq(1),
|
|
|
|
load_timing.eq(1),
|
|
|
|
If(self.timing.stb, NextState("GENERATE"))
|
|
|
|
)
|
|
|
|
self.fsm.act("GENERATE",
|
|
|
|
self.busy.eq(1),
|
|
|
|
If(~active | self.pixels.stb,
|
|
|
|
self.phy.stb.eq(1),
|
|
|
|
If(self.phy.ack, generate_en.eq(1))
|
|
|
|
),
|
|
|
|
If(generate_frame_done, NextState("GET_TIMING"))
|
|
|
|
)
|