Code:
#ifndef _AVR_PORT_ENUM_H_
#define _AVR_PORT_ENUM_H_
/***********************************************************/
#ifndef ID_TO_BIT
#define ID_TO_BIT(pinid) \
(1<<((pinid)&7))
#endif /* ID_TO_BIT */
#define PIN_ID(c,n) \
((PORT ## c ## _ID << 3) | (n))
#define ENUM_PIN(letter,pin) \
PORT ## letter ## _ ## pin = PIN_ID(letter,pin)
#define ENUM_PORT(p) \
ENUM_PIN (p,0), \
ENUM_PIN (p,1), \
ENUM_PIN (p,2), \
ENUM_PIN (p,3), \
ENUM_PIN (p,4), \
ENUM_PIN (p,5), \
ENUM_PIN (p,6), \
ENUM_PIN (p,7)
/*
* Enumerate all ports of respective MCU,
* giving us the desired values like PORTD_1 or PORTB_4, e.g.
*/
#if defined(__AVR_AT90S2313__)
enum {
ENUM_PORT (B),
ENUM_PIN (D,0),
ENUM_PIN (D,1),
ENUM_PIN (D,2),
ENUM_PIN (D,3),
ENUM_PIN (D,4),
ENUM_PIN (D,5),
ENUM_PIN (D,6),
ENUM_PIN_LAST
};
#elif defined(__AVR_ATmega8__)
enum {
ENUM_PORT (B),
ENUM_PIN (C,0),
ENUM_PIN (C,1),
ENUM_PIN (C,2),
ENUM_PIN (C,3),
ENUM_PIN (C,4),
ENUM_PIN (C,5),
ENUM_PIN (C,6),
ENUM_PORT (D),
ENUM_PIN_LAST
};
#elif defined(__AVR_AT90S2333__) || defined(__AVR_AT90S4433__)
enum {
ENUM_PIN (B,0),
ENUM_PIN (B,1),
ENUM_PIN (B,2),
ENUM_PIN (B,3),
ENUM_PIN (B,4),
ENUM_PIN (B,5),
ENUM_PIN (C,0),
ENUM_PIN (C,1),
ENUM_PIN (C,2),
ENUM_PIN (C,3),
ENUM_PIN (C,4),
ENUM_PIN (C,5),
ENUM_PORT (D),
ENUM_PIN_LAST
};
#elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || \
defined(__AVR_AT90S4434__) || defined(__AVR_AT90S8535__) || \
defined(__AVR_ATmega163__)
enum {
ENUM_PORT (A),
ENUM_PORT (B),
ENUM_PORT (C),
ENUM_PORT (D),
ENUM_PIN_LAST
};
#else
#error Please define available ports for MCU
#endif
#if 0
/* Code snippet from avr-gcc source */
static const struct mcu_type_s avr_mcu_types[] = {
/* Classic, <= 8K. */
{ "avr2", 2, NULL },
{ "at90s2313", 2, "__AVR_AT90S2313__" },
{ "at90s2323", 2, "__AVR_AT90S2323__" },
{ "at90s2333", 2, "__AVR_AT90S2333__" },
{ "at90s2343", 2, "__AVR_AT90S2343__" },
{ "attiny22", 2, "__AVR_ATtiny22__" },
{ "attiny26", 2, "__AVR_ATtiny26__" },
{ "at90s4414", 2, "__AVR_AT90S4414__" },
{ "at90s4433", 2, "__AVR_AT90S4433__" },
{ "at90s4434", 2, "__AVR_AT90S4434__" },
{ "at90s8515", 2, "__AVR_AT90S8515__" },
{ "at90c8534", 2, "__AVR_AT90C8534__" },
{ "at90s8535", 2, "__AVR_AT90S8535__" },
{ "at86rf401", 2, "__AVR_AT86RF401__" },
/* Classic, > 8K. */
{ "avr3", 3, NULL },
{ "atmega103", 3, "__AVR_ATmega103__" },
{ "atmega603", 3, "__AVR_ATmega603__" },
{ "at43usb320", 3, "__AVR_AT43USB320__" },
{ "at43usb355", 3, "__AVR_AT43USB355__" },
{ "at76c711", 3, "__AVR_AT76C711__" },
/* Enhanced, <= 8K. */
{ "avr4", 4, NULL },
{ "atmega8", 4, "__AVR_ATmega8__" },
{ "atmega8515", 4, "__AVR_ATmega8515__" },
{ "atmega8535", 4, "__AVR_ATmega8535__" },
/* Enhanced, > 8K. */
{ "avr5", 5, NULL },
{ "atmega16", 5, "__AVR_ATmega16__" },
{ "atmega161", 5, "__AVR_ATmega161__" },
{ "atmega162", 5, "__AVR_ATmega162__" },
{ "atmega163", 5, "__AVR_ATmega163__" },
{ "atmega169", 5, "__AVR_ATmega169__" },
{ "atmega32", 5, "__AVR_ATmega32__" },
{ "atmega323", 5, "__AVR_ATmega323__" },
{ "atmega64", 5, "__AVR_ATmega64__" },
{ "atmega128", 5, "__AVR_ATmega128__" },
{ "at94k", 5, "__AVR_AT94K__" },
/* Assembler only. */
{ "avr1", 1, NULL },
{ "at90s1200", 1, "__AVR_AT90S1200__" },
{ "attiny11", 1, "__AVR_ATtiny11__" },
{ "attiny12", 1, "__AVR_ATtiny12__" },
{ "attiny15", 1, "__AVR_ATtiny15__" },
{ "attiny28", 1, "__AVR_ATtiny28__" },
{ NULL, 0, NULL }
};
#endif /* 0 */
#endif /* _AVR_PORT_ENUM_H_ */
Das sieht alles recht kompliziert aus, aber das kann man wie eine Black Box benutzen und muss es nicht verstehen. Diese beiden Dateien verwende ich in allen Projekten. Sie liegen in einem Verzeichnis ausserhalb der
Lesezeichen