I need to pass port addresses and pin locations from one file to a library, so that the addresses and pins are resolved at link time. (The library can not know which port or pin the user will define).
Here's what I've tried: typedef struct { TWI_PINS pin_reg, ///< pin input register dir_reg, ///< data direction register port_reg; ///< port output register } TWI_PORT; // A port for a bit-banged TWI It's use in main.c is: TWI_PORT *pTWI = (TWI_PORT *)0x33 ; // Port C The file in the library references the port this way: pTWI->port_reg which works just as I wanted: 122 0088 E091 0000 lds r30,pTWI 123 008c F091 0000 lds r31,(pTWI)+1 124 0090 8281 ldd r24,Z+2 Now I need a way to pass in to the library the proper pin to tweak. I tried this: typedef struct { unsigned clock_pin:1; ///< Clock pin on port pin 0 unsigned data_pin:1; ///< Data pin on port pin 1 unsigned nused_pin:6; ///< Temporarily not used pins } TWI_PINS ; and then the library references the pin like this: pTWI->port_reg.data_pin = 1; But the compiler hard codes the pin value: 125 0092 E091 0000 lds r30,pTWI 126 0094 F091 0000 lds r31,(pTWI)+1 Does anyone have a suggestion for how to pass the pin position to my library file? I guess I could define a global variable: const uint8_t clock_pin = _BV(0); const uint8_t data_pin = _BV(1); But this is not as clean as the bitwise structure definition. Ideas? Thanks. Keith _______________________________________________ AVR-chat mailing list AVR-chat@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-chat