[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-libc-dev] Wishlist: place static bool in GPIO registers
From: |
Shaun Jackman |
Subject: |
Re: [avr-libc-dev] Wishlist: place static bool in GPIO registers |
Date: |
Wed, 19 Dec 2007 14:25:36 -0700 |
On Dec 19, 2007 1:24 PM, Stu Bell <address@hidden> wrote:
...
> The real problem with a full workup would be a macro to help define
> "bit" variables. For example it would be cool to do something like the
> following:
>
> #define DECLARE_BIT_VARIABLE(var,port,bnum) \
> #define (name) ((volatile BitRegisterType*)_SFR_MEM_ADDR( (port )
> )->bit ## bnum
>
>
> The above code is completely wrong, as the preprocessor won't allow a
> declare within a declare. Does someone have a clue how to "nicely"
> declare a bit variable other than putting the above into a long
> explanation in the comment header/documentation (which will surely be
> ignored by the noobs)?
...
The bit-field approach solves my primary complaint by not needing any
accessor functions. Both if (my_flag) and my_flag = true; work as
expected. As for the declaration, perhaps
#define my_flag (GPIOR0_BIT.bit0)
would be sufficient, where GPIOR0_BIT is defined by avr-libc as
#define GPIOR0_BIT (*(volatile BitRegisterType *)_SFR_MEM_ADDR(GPIOR0))
Cheers,
Shaun