I guess you got close, but I'll help. You must not have tried to compile it.
static inline void setup_input_w_pullup(uint8_t port, uint8_t pin){
*(volatile uint8_t*)(PORTS__OFFSET + PORTS__OFFSET_GAP * port + DATA_DIR_SET) = 0x01 << pin;
*(volatile uint8_t*)(PORTS__OFFSET + PORTS__OFFSET_GAP * port + PIN_CONTROL + pin) = 0x01 << PULLUP;
}
//I assume this is close to what you want
#define SW1_PORT PORT_A
#define SW1_PIN PIN_2
//OR
#define SW1 PORT_A,PIN_2
//#define SW1 PIN_2,PORTA //<- wrong order, but will get no complaints
int main(){
setup_input_w_pullup(SW1_PORT, SW1_PIN); //ok
setup_input_w_pullup(SW1_PIN, SW1_PORT); //<- wrong usage, but no error
setup_input_w_pullup(PORT_A, PULLUP); //<- wrong usage, but no error
//OR
setup_input_w_pullup(SW1); //<- cannot mix up order unless define uses mixed up order
}
I guess we are just going to do 1, and not 2 and 3 also.
In my simple example, there is a reason I did not create defines for anything- they are only used in one place so its not needed. I did not comment the code, but that would take care of it-
static inline void pin_dir(PIN_t pin, DIR_t io){
//io- OUT=1 (DIRSET) IN=2 (DIRCLR)
((volatile uint8_t*)(pin & 0XFF0))[io] = 1<<(pin&7);
}
You could also eliminate many defines-
#define PORT_BASE 0x400
#define PORT_A 0x00
#define PORT_B 0x20
#define PORT_C 0x40
#define PORT_D 0x60
#define PORT_E 0x80
#define PORT_F 0xA0
static inline void setup_input_w_pullup(uint8_t port, uint8_t pin){
//PORT_BASE = PORTA base address
//[1]=DIRSET
((volatile uint8_t*)(PORT_BASE+port))[1] = 1 << pin;
//0x10 = PINCTRL offset, PULLUPEN = bit3
((volatile uint8_t*)(PORT_BASE+port))[0x10+pin] = 1 << 3;
}
#define SW1_PORT PORT_A
#define SW1_PIN 2
//OR
#define SW1 PORT_A,2
//#define SW1 2,PORTA //<- wrong order, but no complaints
The comments would take care of filling in the user about what bits/registers are used. Either that or they have to hunt down the define.
Or simply forget the defines altogether (I'm probably getting annoying).