+/* "recording" data */
+static noinline void do_from_step(void)
+{
+ uint32_t s;
+
+ // should hopefully give atomic fixed_state read..
+ s = g.pl[0].fixed_state32;
+ g.pl[0].fixed_state32 = g.pl[0].pending_state32;
+ g.stream_from[g.pos_from.i][0] = s;
+ g.stream_from[g.pos_from.i][1] = s >> 8;
+ g.pos_from.i = (g.pos_from.i + 1) & STREAM_BUF_MASK;
+}
+
+static void pl1th_isr_fixed_do_from(void)
+{
+ uint32_t isfr, th;
+
+ isfr = PL1_ISFR;
+ PL1_ISFR = isfr;
+ th = PL1_TH();
+
+ GPIOD_PDOR = g.pl[0].fixed_state[th];
+ if (th)
+ do_from_step();
+ g.edge_cnt++;
+}
+
+static void vsync_isr_frameinc_do_from(void)
+{
+ uint32_t isfr;
+
+ isfr = VSYNC_ISFR;
+ VSYNC_ISFR = isfr;
+
+ do_from_step();
+ g.frame_cnt++;
+}
+
+/* * */
+static void choose_isrs(void)
+{
+ void (*pl1th_handler)(void) = pl1th_isr_fixed;
+ void (*pl2th_handler)(void) = pl2th_isr_fixed;
+ void (*vsync_handler)(void) = vsync_isr_nop;
+
+ if (g.stream_enable_to) {
+ switch (g.inc_mode) {
+ case INC_MODE_VSYNC:
+ pl1th_handler = pl1th_isr_do_to;
+ pl2th_handler = pl2th_isr_do_to_p1d;
+ vsync_handler = vsync_isr_frameinc;
+ break;
+ case INC_MODE_SHARED_PL1:
+ pl1th_handler = pl1th_isr_do_to_inc;
+ pl2th_handler = pl2th_isr_do_to_p1d;
+ break;
+ case INC_MODE_SHARED_PL2:
+ pl1th_handler = pl1th_isr_do_to;
+ pl2th_handler = pl2th_isr_do_to_inc_pl1;
+ break;
+ case INC_MODE_SEPARATE:
+ pl1th_handler = pl1th_isr_do_to_inc;
+ pl2th_handler = pl2th_isr_do_to_inc;
+ break;
+ }
+ }
+ else if (g.stream_enable_from) {
+ g.use_pending = 1;
+ switch (g.inc_mode) {
+ case INC_MODE_VSYNC:
+ vsync_handler = vsync_isr_frameinc_do_from;
+ break;
+ case INC_MODE_SHARED_PL1:
+ pl1th_handler = pl1th_isr_fixed_do_from;
+ break;
+ case INC_MODE_SHARED_PL2:
+ case INC_MODE_SEPARATE:
+ /* TODO */
+ break;
+ }
+ }
+
+ attachInterruptVector(IRQ_PORTD, pl1th_handler);
+ attachInterruptVector(IRQ_PORTC, pl2th_handler);
+ attachInterruptVector(IRQ_PORTA, vsync_handler);
+}
+
+static noinline void choose_isrs_idle(void)
+{
+ attachInterruptVector(IRQ_PORTD, pl1th_isr_fixed);
+ attachInterruptVector(IRQ_PORTC, pl2th_isr_fixed);
+ attachInterruptVector(IRQ_PORTA, vsync_isr_nop);
+}
+