#include <avr/io.h>

#include "avrport.h"

#if defined(PORTA)
struct port_t a;
#endif
#if defined(PORTB)
struct port_t b;
#endif
#if defined(PORTC)
struct port_t c;
#endif
#if defined(PORTD)
struct port_t d;
#endif
#if defined(PORTE)
struct port_t e;
#endif
#if defined(PORTF)
struct port_t f;
#endif
#if defined(PORTG)
struct port_t g;
#endif
#if defined(PORTH)
struct port_t h;
#endif
#if defined(PORTI)
struct port_t i;
#endif
#if defined(PORTJ)
struct port_t j;
#endif
#if defined(PORTK)
struct port_t k;
#endif
#if defined(PORTL)
struct port_t l;
#endif

/*
  output values from last run or from init;  input;  init for new round

  Note: since we write all 8 bits of PORTx we must include the pullup bits
*/
#define RUNIT(X,x) PORT ## X = x.write; x.read = PIN ## X; x.write = x.pullup

void port_run(void) {
#if defined(PORTA)
  RUNIT(A,a);
#endif
#if defined(PORTB)
  RUNIT(B,b);
#endif
#if defined(PORTC)
  RUNIT(C,c);
#endif
#if defined(PORTD)
  RUNIT(D,d);
#endif
#if defined(PORTE)
  RUNIT(E,e);
#endif
#if defined(PORTF)
  RUNIT(F,f);
#endif
#if defined(PORTG)
  RUNIT(G,g);
#endif
#if defined(PORTH)
  RUNIT(H,h);
#endif
#if defined(PORTI)
  RUNIT(I,i);
#endif
#if defined(PORTJ)
  RUNIT(J,j);
#endif
#if defined(PORTK)
  RUNIT(K,k);
#endif
#if defined(PORTL)
  RUNIT(L,l);
#endif

}
