Skip to content

Instantly share code, notes, and snippets.

@ktemkin
Created July 19, 2020 13:32
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 ktemkin/7e203073d46ef6dae45717a549bd440c to your computer and use it in GitHub Desktop.
Save ktemkin/7e203073d46ef6dae45717a549bd440c to your computer and use it in GitHub Desktop.
# The badge's LEDs are wired in a non-straightforward way. Here, the
# LEDResources represent each of the common anodes of a collection of RGB LEDs.
# A single one of their cathodes defaults to connected via a FET; the other
# cathodes are normally-off. Accordingly, they act as normal single-color LEDs
# unless the cathode signals are explicitly driven.
#
# The LEDs on the badge were meant to be a puzzle; so each cathode signal
# corresponds to a different color on each LED. This means there's no
# straightforward way of creating pin definitions; you'll need to use the
# following mapping to find the cathode pin number below.
led_cathode_mappings = [
{'r': 0, 'g': 1, 'b': 2}, # LED1: by default, red
{'r': 2, 'g': 1, 'b': 0}, # LED2: by default, blue
{'r': 0, 'g': 1, 'b': 2}, # LED3: by default, red
{'r': 2, 'g': 1, 'b': 0}, # LED4: by default, blue
{'r': 0, 'g': 1, 'b': 2}, # LED5: by default, red
{'r': 2, 'g': 1, 'b': 0}, # LED6: by default, blue
{'r': 2, 'g': 0, 'b': 1}, # LED7: by default, green
{'r': 0, 'g': 1, 'b': 2}, # LED8: by default, red
{'r': 0, 'g': 1, 'b': 2}, # LED9: by default, red
# Note: [LED10 is disconnected by default; bridge R60 to make things work]
{'r': 2, 'g': 1, 'b': 0}, # LED10: by default, blue
{'r': 1, 'g': 0, 'b': 2}, # LED11: by default, green
]
resources = [
# [snip]
# See note above for LED anode/cathode information.
# Short version is: these work as normal LEDs until you touch their cathodes.
*LEDResources(pins="E3 D3 C3 C4 C2 B1 B20 B19 A18 K20 K19",
attrs=Attrs(IO_TYPE="LVCMOS33")),
Resource("led_cathodes", 0, Pins("P19 L18 K18"), Attrs(IO_TYPE="LVCMOS33")),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment