-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore_leds.py
executable file
·42 lines (31 loc) · 1.06 KB
/
core_leds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# LambdaConcept - 2017
# Pierre-Olivier Vauboin - [email protected]
from litex.gen import *
from litex.soc.interconnect.csr import *
class PWM(Module):
def __init__(self, out, level):
counter = Signal(12) # Just to reduce brightness
self.comb += [
If(counter < level,
out.eq(1),
).Else(
out.eq(0),
),
]
self.sync += [
counter.eq(counter + 1),
]
class RGBLeds(Module, AutoCSR):
def __init__(self, pads):
self.leds = pads
self.csr_led0 = CSRStorage(24)
self.csr_led1 = CSRStorage(24)
self.csr_led2 = CSRStorage(24)
self.csr_led3 = CSRStorage(24)
for i in range(4):
csr_led = getattr(self, 'csr_led{}'.format(i))
self.submodules += PWM(self.leds.r[i], csr_led.storage[16:24])
self.submodules += PWM(self.leds.g[i], csr_led.storage[8:16])
self.submodules += PWM(self.leds.b[i], csr_led.storage[0:8])