+ ir_record_pulse(ir_last_pulse, IR_INF);
+ ir_last_pulse = 0;
+ }
+ }
+}
+
+static u32 ir_get_pulse(void)
+{
+ u32 out = 0;
+
+ cm_disable_interrupts();
+ if (ir_pulses_rx != ir_pulses_tx) {
+ out = ir_pulses[ir_pulses_rx];
+ ir_pulses_rx = (ir_pulses_rx + 1) % IR_MAX_PULSES;
+ }
+ cm_enable_interrupts();
+ return out;
+}
+
+// Decoder for Onkyo RC-748S
+
+static void ir_decode(void)
+{
+ u32 pulse = ir_get_pulse();
+ if (!pulse)
+ return;
+
+ uint mark = IR_MARK(pulse);
+ uint space = IR_SPACE(pulse);
+
+#ifdef IR_TEST
+ debug_printf("IR: %d %d\n", mark, space);
+ return;
+#endif
+
+ static u16 ir_bits;
+ static u32 ir_code;
+#define IR_ERR 0xff
+
+ // debug_printf("IR(%d): %d %d\n", ir_bits, mark, space);
+
+ if (space == IR_INF) {
+ ir_bits = 0;
+ } else if (ir_bits == IR_ERR) {
+ // Error state
+ } else if (ir_bits == 0) {
+ // Start?
+ if (between(mark, 8900, 9200)) {
+ if (between(space, 4200, 4600)) {
+ ir_bits = 1;
+ ir_code = 0;
+ } else if (between(space, 2000, 2300)) {
+ debug_printf("IR: => REP\n");
+ ir_bits = IR_ERR;
+ }
+ }
+ } else {
+ if (between(mark, 500, 700)) {
+ ir_bits++;
+ if (between(space, 400, 700)) {
+ // 0
+ } else if (between(space, 1500, 1800)) {
+ // 1
+ ir_code |= 1U << (33 - ir_bits);
+ } else {
+ ir_bits = IR_ERR;
+ }
+ if (ir_bits == 33) {
+ debug_printf("IR: => %08x\n", (uint)ir_code);
+ disp[3] ^= 0x01;
+ display_update();
+ ir_bits = IR_ERR;
+ ep82_send(ir_code);
+ }
+ } else {
+ ir_bits = IR_ERR;