I'm currently working on an MSP430 board and I'm trying to create libraries for it so I can easily use them on my project. I'm starting with basic Digital I/O functions.
Say for example I need to set P1.0 ON. In that case, normally what I do is:
P1SEL &= (~BIT0); // Set P1.0 SEL for GPIO
P1DIR |= BIT0; // Set P1.0 as Output
P1OUT |= BIT0; // Set P1.0 HIGH
But I need to write a function that will just take Port Num, Pin and Value and set the above registers. Something like this:
void setVal(int x, int y) {
PxSEL &= (~BITy);
PxDIR |= BITy;
PxOUT |= BITy;
}
Where x is Port and Y is Pin. Is there a way I can implement such a function? OR has this been done before? If yes, please share the link for the same. I was thinking out maybe using a lookup table and selecting the Register via indexing. But I'm not sure if that's a good approach. Any help would be appreciated.
Thanks
uint16_t BITy = 1 << y;
. To get the Port registers, you'll probably have to look at the raw addresses and figure out how to calculate them fromy
. \$\endgroup\$