What’s the type of an Arduino PORT?

I need to pass the PORT to use to my class.

Typical usage is PORTB |= _BV(bit) to set a bit of a port, aka a pin of the chip. However I need the PORT to be a variable so I can choose which port to write to.

It turns out stackoverflow has the answer. It is an IO address. For example PORTA is :

(volatile uint8_t *)((0x02) + 0x20)

So I might be able to write:

template <(volatile uint8_t *) port> class foo { foo(){ port |= _BV(3); };
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s