Pin toggling via writing PINx - can I tell which chips have it?

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there anything defined by the machine description or ioXXXX.h that tells me whether the chip I am compiling for has the ability to toggle output pins by writing to the PINx register?

 

Right now I have code like:

#if defined(__AVR_ATmega8__)    || defined(__AVR_ATmega8515__) ||	\
    defined(__AVR_ATmega8535__) || defined(__AVR_ATmega16__)   ||	\
    defined(__AVR_ATmega162__)  || defined(__AVR_ATmega32__)   ||	\
    defined(__AVR_ATmega64__)   || defined(__AVR_ATmega128__)
  LED_PORT ^= _BV(LED);
#else
  LED_PIN |= _BV(LED);
#endif

when I would MUCH rather have code like:

#if !defined(__BUILTIN_AVR_HASPINTOGGLE)
  LED_PORT ^= _BV(LED);
#else
  LED_PIN |= _BV(LED);
#endif

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can't think of anything but if this structure appears several times in you files can't you just define HAS_TOGGLE as that composite defined() || defined () ... then use "HAS_TOGGLE" elsewhere ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My recollection is that all the non-ancient AVRs do toggle with PINx.

If all else fails, make HAS_PIN_TOGGLE a non-optional preprocessor parameter.

Code like this will ensure it is non-optional:

if(HAS_PIN_TOGGLE) LED_PIN  =LED_MASK;
else               LED_PORT^=LED_MASK;

 

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think so... maybe checking for other archaic characteristics, like the presence of the URSEL bit (#ifdef URSEL)? But no, it's not general enough since the mega64 and mega128 don't have this bit. Close, though.