2020-08-15 02:20:42 +02:00
|
|
|
import "/nmigen_boards.icebreaker/ICEBreakerPlatform"
|
|
|
|
import "/nmigen_dg/*"
|
|
|
|
import "/sys"
|
2020-08-15 15:48:53 +02:00
|
|
|
import "common/to_signed"
|
|
|
|
import "modules/vga/DviController12"
|
2020-08-19 22:48:38 +02:00
|
|
|
import "stdio/ice40pll/add_domain_from_pll"
|
2020-08-15 02:20:42 +02:00
|
|
|
import "resources/pmod"
|
|
|
|
|
|
|
|
|
2020-08-15 15:46:37 +02:00
|
|
|
|
2020-08-15 02:20:42 +02:00
|
|
|
Top = subclass Elaboratable where
|
2020-08-19 16:33:41 +02:00
|
|
|
__init__ = x y fps ~> None where
|
|
|
|
@x, @y, @fps = x, y, fps
|
2020-08-16 23:47:35 +02:00
|
|
|
|
2020-08-15 02:20:42 +02:00
|
|
|
elaborate = platform ~> m where with m = Module! =>
|
|
|
|
|
2020-08-15 15:48:53 +02:00
|
|
|
# Configure DVI controller
|
2020-08-19 16:33:41 +02:00
|
|
|
dvi = Submodule.dvi$ DviController12 @x @y @fps
|
2020-08-15 15:48:53 +02:00
|
|
|
|
2020-08-19 22:48:38 +02:00
|
|
|
# setup clock
|
|
|
|
pll_config = add_domain_from_pll platform dvi.pix_freq
|
2020-08-15 02:20:42 +02:00
|
|
|
|
2020-08-15 15:46:37 +02:00
|
|
|
|
2020-08-16 23:30:36 +02:00
|
|
|
# Feed a picture to the DVI controller
|
|
|
|
|
|
|
|
scroll = Signal 8
|
|
|
|
|
2020-08-19 16:33:41 +02:00
|
|
|
period = int$ pll_config.achieved / @fps
|
2020-08-16 23:30:36 +02:00
|
|
|
counter = Signal$ range period
|
2020-08-17 00:34:12 +02:00
|
|
|
Sync$ counter ::= counter - 1
|
2020-08-15 02:20:42 +02:00
|
|
|
When (counter==0) $ ->
|
2020-08-17 00:34:12 +02:00
|
|
|
Sync$ counter ::= int period
|
|
|
|
Sync$ scroll ::= scroll + 1
|
2020-08-15 02:20:42 +02:00
|
|
|
|
2020-08-17 00:34:12 +02:00
|
|
|
Sync$ dvi.r ::= 0x0
|
|
|
|
Sync$ dvi.g ::= 0x0
|
|
|
|
Sync$ dvi.b ::= 0x0
|
2020-08-16 23:47:35 +02:00
|
|
|
cx = to_signed dvi.pixel_x - (@x // 2)
|
|
|
|
cy = to_signed dvi.pixel_y - (@y // 2)
|
2020-08-19 16:33:41 +02:00
|
|
|
rx = cx * cx
|
|
|
|
ry = cy * cy
|
2020-08-16 23:47:35 +02:00
|
|
|
tx1 = (dvi.pixel_x - scroll ) & (1<<5)
|
|
|
|
ty1 = (dvi.pixel_y - scroll ) & (1<<5)
|
|
|
|
tx2 = (dvi.pixel_x + scroll ) & (1<<6)
|
2020-08-16 23:30:36 +02:00
|
|
|
ty2 = (dvi.pixel_y + scroll + 40) & (1<<6)
|
|
|
|
When
|
|
|
|
rx + ry < 200**2 ,->
|
2020-08-17 00:34:12 +02:00
|
|
|
Sync$ dvi.r ::= 0xF
|
|
|
|
#Sync$ dvi.g ::= 0xF
|
|
|
|
Sync$ dvi.b ::= 0xF
|
2020-08-19 16:33:41 +02:00
|
|
|
|
2020-08-16 23:30:36 +02:00
|
|
|
tx1 ^ ty1 ,->
|
2020-08-17 00:34:12 +02:00
|
|
|
Sync$ dvi.b ::= 0xF
|
2020-08-19 16:33:41 +02:00
|
|
|
|
2020-08-16 23:30:36 +02:00
|
|
|
tx2 ^ ty2 ,->
|
2020-08-17 00:34:12 +02:00
|
|
|
Sync$ dvi.r ::= 0xF
|
|
|
|
Sync$ dvi.g ::= 0xF
|
2020-08-15 15:48:53 +02:00
|
|
|
|
2020-08-15 02:20:42 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__" =>
|
|
|
|
plat = ICEBreakerPlatform!
|
|
|
|
plat.add_resources$ pmod.dvi_12bit 0
|
|
|
|
plat.add_resources$ plat.break_off_pmod
|
2020-08-16 23:47:35 +02:00
|
|
|
plat.build (Top 800 480) do_program: ("--flash" in sys.argv) synth_opts: "-dsp"
|