Port manipulation with bitread

No need to store anything separately, it can be stored directly inline.

If you have an Uno, you will need to remove PORTA, or possibly add some on a Mega, however here is the basic principle which can be expanded for PIN and DDR registers too.

Also #define can be used to mask missing ports on different AVR's

static struct{
  inline volatile uint8_t &operator []( char i ){
    switch( i ){
      case 'A': return PORTA;
      case 'B': return PORTB;
      case 'C': return PORTC;
      case 'D': return PORTD;        
    };
    return GPIOR0;  //For safety we can return GPIO on error
  }
} port;

Access the ports like this:

port[ 'A' ] = 0b11001100;

port[ 'B' ] = port[ 'C' ];

Edit: modified switch :slight_smile: