Skip to content

Instantly share code, notes, and snippets.

@jgibbard
Created November 3, 2019 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgibbard/41fac674e625d834d46480be40b2915a to your computer and use it in GitHub Desktop.
Save jgibbard/41fac674e625d834d46480be40b2915a to your computer and use it in GitHub Desktop.
DE10 Nano LED / Key demo
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