Been thinking about this for a while, and there has to be a tidy way to do it, but I haven't figured it out yet.
I usually make a file called "Config.h" that describes the board. It has definitions like
// TouchScreen #define TouchPort PORTB #define TouchYTop 2 #define TouchYBottom 3 #define TouchXTop 0 #define TouchXBottom 1
Which lets me code by name like so:
TouchPort.DIRSET = (1<<TouchXTop) | (1<<TouchXBottom) ; TouchPort.DIRCLR = (1<<TouchYTop) | (1<<TouchYBottom) ; TouchPort.OUTSET = (1<<TouchXTop) ; TouchPort.OUTCLR = (1<<TouchXBottom) ;
And this is very handy for when I discover I've made a mistake counting pins or wish to use the same code on a different board where the pins may be different.
However, the pincontrol registers still trip me up. Inside the code, I have to refer to the pin by number, rather than name:
TouchPort.PIN3CTRL = (3<<3) ;
And this leaves a spot in the code that I have to edit if I need to change something in the Config.h file. Can any of you C mages suggest a way to specify something like:
TouchPort.PIN(TouchYBottom)CTRL = somegibberish