[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-chat] Passing pins through link
From: |
Keith Gudger |
Subject: |
[avr-chat] Passing pins through link |
Date: |
Thu, 12 Oct 2006 10:30:48 -0700 (PDT) |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-chat] Passing pins through link,
Keith Gudger <=