2020-08-09 21:56:20 +02:00
|
|
|
#!/usr/bin/env -S python3 -m dg
|
|
|
|
import "/nmigen_dg/*"
|
|
|
|
import "/nmigen/cli/main"
|
|
|
|
|
|
|
|
# iCEBreaker 7-Segment Pmod
|
|
|
|
|
2020-08-09 22:54:51 +02:00
|
|
|
Segment7x2 = subclass Elaboratable where
|
|
|
|
__init__ = decimal: True ~> None where
|
2020-08-09 21:56:20 +02:00
|
|
|
@number = Signal 8 # i
|
2020-08-09 22:54:51 +02:00
|
|
|
@segs = Signal 7 # o
|
|
|
|
@select = Signal 1 # o
|
|
|
|
@decimal = decimal
|
2020-08-09 21:56:20 +02:00
|
|
|
|
|
|
|
elaborate = platform ~> m where with m = Module! =>
|
|
|
|
select = Signal!
|
2020-08-15 02:08:36 +02:00
|
|
|
Sync$ select :== ~select
|
2020-08-09 21:56:20 +02:00
|
|
|
|
2020-08-09 22:54:51 +02:00
|
|
|
seg7 = Submodule$ Segment7!
|
2020-08-09 21:56:20 +02:00
|
|
|
|
2020-08-15 02:08:36 +02:00
|
|
|
Comb$ seg7.number :== if
|
|
|
|
@decimal => Mux select
|
2020-08-09 22:54:51 +02:00
|
|
|
@number // 10
|
|
|
|
@number % 10
|
2020-08-15 02:08:36 +02:00
|
|
|
otherwise => Mux select
|
|
|
|
@number >> 4
|
|
|
|
@number & 0x0f
|
2020-08-09 21:56:20 +02:00
|
|
|
|
2020-08-15 02:08:36 +02:00
|
|
|
Comb$ @segs :== seg7.segs
|
|
|
|
Comb$ @select :== select
|
2020-08-09 21:56:20 +02:00
|
|
|
|
|
|
|
|
2020-08-09 22:54:51 +02:00
|
|
|
Segment7 = subclass Elaboratable where
|
2020-08-09 21:56:20 +02:00
|
|
|
__init__ = self -> None where
|
2020-08-09 22:54:51 +02:00
|
|
|
@number = Signal 4 # i
|
|
|
|
@segs = Signal 7 # o
|
2020-08-09 21:56:20 +02:00
|
|
|
|
|
|
|
elaborate = platform ~> m where with m = Module! =>
|
2020-08-09 22:54:51 +02:00
|
|
|
Switch @number
|
2020-08-15 02:08:36 +02:00
|
|
|
0x0 ,-> Comb$ @segs :== 0b0111111
|
|
|
|
0x1 ,-> Comb$ @segs :== 0b0000110
|
|
|
|
0x2 ,-> Comb$ @segs :== 0b1011011
|
|
|
|
0x3 ,-> Comb$ @segs :== 0b1001111
|
|
|
|
0x4 ,-> Comb$ @segs :== 0b1100110
|
|
|
|
0x5 ,-> Comb$ @segs :== 0b1101101
|
|
|
|
0x6 ,-> Comb$ @segs :== 0b1111101
|
|
|
|
0x7 ,-> Comb$ @segs :== 0b0000111
|
|
|
|
0x8 ,-> Comb$ @segs :== 0b1111111
|
|
|
|
0x9 ,-> Comb$ @segs :== 0b1101111
|
|
|
|
0xa ,-> Comb$ @segs :== 0b1110111
|
|
|
|
0xb ,-> Comb$ @segs :== 0b1111100
|
|
|
|
0xc ,-> Comb$ @segs :== 0b0111001
|
|
|
|
0xd ,-> Comb$ @segs :== 0b1011110
|
|
|
|
0xe ,-> Comb$ @segs :== 0b1111001
|
|
|
|
0xf ,-> Comb$ @segs :== 0b1110001
|
2020-08-09 21:56:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__" =>
|
2020-08-09 22:54:51 +02:00
|
|
|
design = Segment7x2!
|
|
|
|
main design ports: [design.number, design.segs, design.select]
|