#include <stdint.h>
#include "app_urv_regs.h"

/* Ch0: input  (bit 1, en 6)
   ch1: --     (bit 0, en 7).
   ch2: --     (bit 2, en 9)
   ch3: output (bit 5, en 8)
   ch4: output (bit 4, en 11)  */

#define SLOT pins_5

//            ch0        ch1        ch3         ch2       ch4
#define OEN ((1 << 6) | (1 << 7) | (1 << 8) | (1 << 9) | (0 << 11))

void
init (void)
{
  volatile struct app_urv_regs *regs =
    (volatile struct app_urv_regs *)0x00000;

  regs->relays.SLOT = OEN;
}

void
main (void)
{
  volatile struct app_urv_regs *regs =
    (volatile struct app_urv_regs *)0x00000;

  while (1) {
    unsigned v = regs->loops.SLOT;

    v = !! (v & 0x27);
      // v = (v & 2) >> 1;
    //    v |= regs->loops.pins_4 & 1;

    regs->relays.SLOT = (v << 4) | OEN;
  }
}
