Created
November 3, 2019 21:06
-
-
Save jgibbard/41fac674e625d834d46480be40b2915a to your computer and use it in GitHub Desktop.
DE10 Nano LED / Key demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mmap import mmap | |
import time | |
import struct | |
LWFPGASLVS_OFST = 0xFF200000 | |
LED_PIO_BASE = 0x3000 | |
LED_SPAN = 0x10 | |
KEY_BASE = 0x5000 | |
KEY_SPAN = 0x10 | |
counter = 0 | |
with open("/dev/mem", "w+b") as f: | |
led = mmap(f.fileno(), LED_SPAN, offset=(LWFPGASLVS_OFST + LED_PIO_BASE)) | |
key = mmap(f.fileno(), KEY_SPAN, offset=(LWFPGASLVS_OFST + KEY_BASE)) | |
while True: | |
print(struct.unpack("<L", key[0:4])[0]) | |
if counter == 0x80: | |
counter = 0 | |
else: | |
counter += 1 | |
led[0:4] = struct.pack("<L", counter) | |
time.sleep(0.005) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment