Skip to content

Commit 66af6ad

Browse files
committed
allow custom timings (peter)
1 parent 3a85b63 commit 66af6ad

File tree

1 file changed

+49
-18
lines changed

1 file changed

+49
-18
lines changed

modules/drivers/neopixel/esp32/modneopixel.c

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void xs_neopixel(xsMachine *the)
6262
char *order;
6363
uint8_t shift;
6464

65-
xsmcVars(1);
65+
xsmcVars(3);
6666
#ifdef MODDEF_NEOPIXEL_LENGTH
6767
length = MODDEF_NEOPIXEL_LENGTH;
6868
#else
@@ -130,25 +130,56 @@ void xs_neopixel(xsMachine *the)
130130
shift -= 8;
131131
}
132132

133-
px->timings.mark.level0 = 1;
134-
px->timings.space.level0 = 1;
135-
px->timings.mark.duration0 = 12;
136-
137-
if (1 == wstype) {
138-
px->nbits = 32;
139-
px->timings.mark.duration1 = 12;
140-
px->timings.space.duration0 = 6;
141-
px->timings.space.duration1 = 18;
142-
px->timings.reset.duration0 = 900;
143-
px->timings.reset.duration1 = 900;
133+
px->nbits = (1 == wstype) ? 32 : 24;
134+
if (xsmcHas(xsArg(0), xsID_timing)) {
135+
uint8_t i;
136+
137+
xsmcGet(xsVar(0), xsArg(0), xsID_timing);
138+
for (i = 0; i < 3; i++) {
139+
bit_timing_t *bt;
140+
141+
if (0 == i) {
142+
xsmcGet(xsVar(1), xsVar(0), xsID_mark);
143+
bt = &px->timings.mark;
144+
}
145+
else if (1 == i) {
146+
xsmcGet(xsVar(1), xsVar(0), xsID_reset);
147+
bt = &px->timings.reset;
148+
}
149+
else if (2 == i) {
150+
xsmcGet(xsVar(1), xsVar(0), xsID_space);
151+
bt = &px->timings.space;
152+
}
153+
154+
xsmcGet(xsVar(2), xsVar(1), xsID_level0);
155+
bt->level0 = xsmcToInteger(xsVar(2));
156+
xsmcGet(xsVar(2), xsVar(1), xsID_level1);
157+
bt->level1 = xsmcToInteger(xsVar(2));
158+
xsmcGet(xsVar(2), xsVar(1), xsID_duration0);
159+
bt->duration0 = xsmcToInteger(xsVar(2));
160+
xsmcGet(xsVar(2), xsVar(1), xsID_duration1);
161+
bt->duration1 = xsmcToInteger(xsVar(2));
162+
}
144163
}
145164
else {
146-
px->nbits = 24;
147-
px->timings.mark.duration1 = 14;
148-
px->timings.space.duration0 = 7;
149-
px->timings.space.duration1 = 16;
150-
px->timings.reset.duration0 = 600;
151-
px->timings.reset.duration1 = 600;
165+
px->timings.mark.level0 = 1;
166+
px->timings.space.level0 = 1;
167+
px->timings.mark.duration0 = 12;
168+
169+
if (1 == wstype) {
170+
px->timings.mark.duration1 = 12;
171+
px->timings.space.duration0 = 6;
172+
px->timings.space.duration1 = 18;
173+
px->timings.reset.duration0 = 900;
174+
px->timings.reset.duration1 = 900;
175+
}
176+
else {
177+
px->timings.mark.duration1 = 14;
178+
px->timings.space.duration0 = 7;
179+
px->timings.space.duration1 = 16;
180+
px->timings.reset.duration0 = 600;
181+
px->timings.reset.duration1 = 600;
182+
}
152183
}
153184

154185
np_show(px, MODDEF_NEOPIXEL_RMT_CHANNEL); // pixels are all zero

0 commit comments

Comments
 (0)