• After a lot of messing about and reading the spec, I don't think it's possible to have the counter DIR bit change according to a simple high/low on another GPIO as required. The encoder mode of the timer is designed for a quadrature encoder.

    I ended up with a little inline C to switch this bit according to GPIO input edge change like this:

    const native=E.compiledC(`
      // void dir(bool)
      unsigned char *addr=(unsigned char *) 0x40010000;
      void dir(bool state) {
        *addr = (*addr & ~0b00010000) | (state * 0b00010000);
    setWatch(native.dir, B7, {repeat: true, edge: "both", irq: true});