sketchbook
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
io_regs.h
Go to the documentation of this file.
1 #ifndef IO_REGS_H
2 #define IO_REGS_H
3 
4 /* IO port mapping, used in port.h and unused.c
5  *
6  * addr format:
7  * Bits 7-4 identifes the port (A=0, B=1, ...)
8  * Bits 3-1 bits are bit position in the port.
9  *
10  * _P_REGS uses bit 7-4 to create pin,ddr,port pointers.
11  */
12 
13 #ifdef __AVR_ATmega8__
14 /* Mega8 layout:
15  * 0x2D, 0x2E, 0x2F (irrelevant, there is no port A)
16  * 0x30 PIND, 0x31 DDRD, 0x32 PORTD
17  * 0x33 PINC, 0x34 DDRC, 0x35 PORTC
18  * 0x36 PINB, 0x37 DDRB, 0x38 PORTB
19  */
20 #define _P_REGS(addr) \
21  uint8_t _i=3*(4-(adr>>3)); \
22  uint8_t *pin __attribute__((unused)) = (uint8_t *)(0x2D+_i); \
23  uint8_t *ddr __attribute__((unused)) = (uint8_t *)(0x2D+_i+1); \
24  uint8_t *port __attribute__((unused)) = (uint8_t *)(0x2D+_i+2);
25 
26 
27 #else
28 
29 
30 /* Mega48/88/168 and others have
31  * 0x20, 0x21, 0x22 Reserved (there is no port A)
32  * 0x23 PINB, 0x24 DDRB, 0x25 PORTB
33  * 0x26 PINC, 0x27 DDRC, 0x28 PORTC
34  * 0x29 PIND, 0x2A DDRD, 0x2B PORTD
35  */
36 #define _P_REGS(addr) \
37  uint8_t _i=3*(adr>>3); \
38  uint8_t *pin __attribute__((unused)) = (uint8_t *)(0x20+_i); \
39  uint8_t *ddr __attribute__((unused)) = (uint8_t *)(0x20+_i+1); \
40  uint8_t *port __attribute__((unused)) = (uint8_t *)(0x20+_i+2);
41 #endif
42 
43 
44 #endif // IO_REGS_H