void init(void);

#if   defined(__AVR_ATtiny861__)
/*****************************************
 This is for attiny861
 I/O
              o  = output non inverted
              oi = output inverted
              ih = input  active high
              il = input  active low
              ip = input  pulses

PORTA: leds to ground
  0 
  1 
  2 
  3 
  4 
  5 
  6 
  7 

PORTB:
  0   (MOSI)
  1   (MISO)
  2   (SCK)
  3 hex switch 1
  4 hex switch 2
  5 hex switch 4
  6 hex switch 8
  7   (RESET)

x_DDR bits: 1 == output, 0 == input
x_PULLUP bits: 1 == pullup (if correstsponding x_DDR bit is 0), 0 == no pullup
*/

#define A_DDR     0xff
#define A_PULLUP  ((uint8_t) ~A_DDR)

#define B_DDR     0x87
#define B_PULLUP  ((uint8_t) ~B_DDR)

#define GETHEX    (hex = ~(b.read >> 3) & 0x0f)
#define WRLED     (a.write |= hex)

void init(void) {
  PORT_INIT( A, a, A_DDR, A_PULLUP);
  PORT_INIT( B, b, B_DDR, B_PULLUP);
}

#elif defined(__AVR_ATmega168__)
/*****************************************
 This is for attiny861
 I/O
              o  = output non inverted
              oi = output inverted
              ih = input  active high
              il = input  active low
              ip = input  pulses

PORTB:
  0 
  1 
  2 
  3   (MOSI)
  4   (MISO)
  5   (SCK) 
  6 led 6
  7 led 7

PORTC:
  0 led 0
  1 led 1
  2 led 2
  3 led 3
  4 led 4
  5 led 5
  6   (RESET)
  7 NC

PORTD:
  0 RXD
  1 TXD
  2
  3
  4 hex switch 1
  5 hex switch 2
  6 hex switch 4
  7 hex switch 8

x_DDR bits: 1 == output, 0 == input
x_PULLUP bits: 1 == pullup (if correstsponding x_DDR bit is 0), 0 == no pullup
*/

#define B_DDR     0xc0
#define B_PULLUP  ((uint8_t) ~B_DDR)

#define C_DDR     0x3f
#define C_PULLUP  ((uint8_t) ~C_DDR)

#define D_DDR     0x00
#define D_PULLUP  ((uint8_t) ~D_DDR)

#define GETHEX    (hex = ~(d.read >> 4) & 0x0f)
#define WRLED     (b.write = (hex & B_DDR) | B_PULLUP, c.write = (hex & C_DDR) | C_PULLUP, d.write = D_PULLUP)

void init(void) {
  PORT_INIT( B, b, B_DDR, B_PULLUP);
  PORT_INIT( C, c, C_DDR, C_PULLUP);
  PORT_INIT( D, d, D_DDR, D_PULLUP);
}
#endif
