Now there are a lot of different ways of achieving what i want to achieve, but i'm wondering how people do this elegantly!
Imagine i have a function, that needs to be able to work with multiple periferals of the same type, say for example, a function that writes a byte to a uart. however,i'd like to programatically have that function write to any of the multiple uarts on the chip, eh UART0 or UART1 to UARTn basically.
Calling the function could be uart_write(0,0xFF) eg write 0xFF to Uart0 (eg to UDR0)
various programming options exist:
1) Have some form of if() or State.Case afair in the function, that basically logically decides to which register to write
clunky, and difficult to keep upto date as different chips have different numbers of registers
2) Send the function an address pointer, where some other external array does the setting of that pointer to the appropriate value, and that array is preloaded with the address of the register needed
seems like a lot of work, addresses will have to be setup before run time (could be done with consts by #defines as it wouldn't change at run time)
What about if that function needs to access more than one register? Say i need to send a byte to the uart transmisson register (UDR) but also then enable the transmission complete interrupt for that register, which if obviously at a completely different location. Now i either need more logic, or more look up tables to "map" all that together!
I'm sure there is an elegant way to handle this (in "c" with AVRstudio) but i just can't quite think what it might be right now!
And suggestions anybody?