Skip to content

Commit f133320

Browse files
committed
Add support for inverting the polarity of the output
1 parent 9b9a580 commit f133320

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

adafruit_tm1814.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,7 @@
3434
# Datasheet high times for a "1" bit are 650 (min) 720 (typ) 1000 (max) ns
3535
#
3636
# Operating PIO at 14x the bit clock lets us achieve nominal 357ns and 714ns
37-
_program = Program(
38-
f"""
39-
.side_set 1
40-
.wrap_target
41-
pull block side 1
42-
out y, 32 side 1 ; get count of pixel bits
43-
44-
bitloop:
45-
pull ifempty side 1 ; drive low
46-
out x 1 side 1 [4]
47-
jmp !x do_zero side 0 [3] ; drive low and branch depending on bit val
48-
jmp y--, bitloop side 0 [3] ; drive low for a one (long pulse)
49-
jmp end_sequence side 1 ; sequence is over
50-
51-
do_zero:
52-
jmp y--, bitloop side 1 [3] ; drive high for a zero (short pulse)
53-
54-
end_sequence:
55-
pull block side 1 ; get fresh delay value
56-
out y, 32 side 1 ; get delay count
57-
wait_reset:
58-
jmp y--, wait_reset side 1 ; wait until delay elapses
59-
.wrap
60-
"""
61-
)
37+
_pio_source = ()
6238

6339
TM1814_MIN_CURRENT = 6.5
6440
TM1814_MAX_CURRENT = 38
@@ -101,6 +77,7 @@ class TM1814PixelBackground( # pylint: disable=too-few-public-methods
10177
below.
10278
:param str pixel_order: Set the pixel color channel order. WRGB is set by
10379
default. Only 4-bytes-per-pixel formats are supported.
80+
:param bool inverted: True to invert the polarity of the output signal.
10481
"""
10582

10683
def __init__( # noqa: PLR0913
@@ -111,10 +88,35 @@ def __init__( # noqa: PLR0913
11188
brightness: float = 1.0,
11289
pixel_order: str = "WRGB",
11390
current_control: float | tuple[float, float, float, float] = 38.0,
91+
inverted: bool = False,
11492
):
11593
if len(pixel_order) != 4:
11694
raise ValueError("Invalid pixel_order")
11795

96+
_program = Program(f"""
97+
.side_set 1
98+
.wrap_target
99+
pull block side {not inverted:1d}
100+
out y, 32 side {not inverted:1d} ; get count of pixel bits
101+
102+
bitloop:
103+
pull ifempty side {not inverted:1d} ; drive low
104+
out x 1 side {not inverted:1d} [4]
105+
jmp !x do_zero side {inverted:1d} [3] ; drive low and branch depending on bit val
106+
jmp y--, bitloop side {inverted:1d} [3] ; drive low for a one (long pulse)
107+
jmp end_sequence side {not inverted:1d} ; sequence is over
108+
109+
do_zero:
110+
jmp y--, bitloop side {not inverted:1d} [3] ; drive high for a zero (short pulse)
111+
112+
end_sequence:
113+
pull block side {not inverted:1d} ; get fresh delay value
114+
out y, 32 side {not inverted:1d} ; get delay count
115+
wait_reset:
116+
jmp y--, wait_reset side {not inverted:1d} ; wait until delay elapses
117+
.wrap
118+
""")
119+
118120
byte_count = 4 * n
119121
bit_count = byte_count * 8 + 64 # count the 64 brightness bits
120122

0 commit comments

Comments
 (0)