Statistics
| Branch: | Revision:

root / arduino-1.0 / hardware / arduino / variants / leonardo / pins_arduino.h @ 58d82c77

History | View | Annotate | Download (6.08 KB)

1
/*
2
  pins_arduino.h - Pin definition functions for Arduino
3
  Part of Arduino - http://www.arduino.cc/
4

5
  Copyright (c) 2007 David A. Mellis
6

7
  This library is free software; you can redistribute it and/or
8
  modify it under the terms of the GNU Lesser General Public
9
  License as published by the Free Software Foundation; either
10
  version 2.1 of the License, or (at your option) any later version.
11

12
  This library is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
  Lesser General Public License for more details.
16

17
  You should have received a copy of the GNU Lesser General
18
  Public License along with this library; if not, write to the
19
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
  Boston, MA  02111-1307  USA
21

22
  $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
23
*/
24

    
25
#ifndef Pins_Arduino_h
26
#define Pins_Arduino_h
27

    
28
#include <avr/pgmspace.h>
29

    
30
#define ARDUINO_MODEL_USB_PID        0x0034
31

    
32
#define TX_RX_LED_INIT        DDRD |= (1<<5), DDRB |= (1<<0)
33
#define TXLED0                        PORTD |= (1<<5)
34
#define TXLED1                        PORTD &= ~(1<<5)
35
#define RXLED0                        PORTB |= (1<<0)
36
#define RXLED1                        PORTB &= ~(1<<0)
37

    
38
const static uint8_t SDA = 2;
39
const static uint8_t SCL = 3;
40

    
41
// Map SPI port to 'new' pins D14..D17
42
const static uint8_t SS   = 17;
43
const static uint8_t MOSI = 16;
44
const static uint8_t MISO = 14;
45
const static uint8_t SCK  = 15;
46

    
47
// Mapping of analog pins as digital I/O
48
// A6-A11 share with digital pins
49
const static uint8_t A0 = 18;
50
const static uint8_t A1 = 19;
51
const static uint8_t A2 = 20;
52
const static uint8_t A3 = 21;
53
const static uint8_t A4 = 22;
54
const static uint8_t A5 = 23;
55
const static uint8_t A6 = 24;        // D4
56
const static uint8_t A7 = 25;        // D6
57
const static uint8_t A8 = 26;        // D8
58
const static uint8_t A9 = 27;        // D9
59
const static uint8_t A10 = 28;        // D10
60
const static uint8_t A11 = 29;        // D12
61

    
62
//        __AVR_ATmega32U4__ has an unusual mapping of pins to channels
63
extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
64
#define analogPinToChannel(P)  ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
65

    
66
#ifdef ARDUINO_MAIN
67

    
68
// On the Arduino board, digital pins are also used
69
// for the analog output (software PWM).  Analog input
70
// pins are a separate set.
71

    
72
// ATMEL ATMEGA32U4 / ARDUINO LEONARDO
73
//
74
// D0                                PD2                                        RXD1/INT2
75
// D1                                PD3                                        TXD1/INT3
76
// D2                                PD1                SDA                        SDA/INT1
77
// D3#                                PD0                PWM8/SCL        OC0B/SCL/INT0
78
// D4                A6                PD4                                        ADC8
79
// D5#                                PC6                ???                        OC3A/#OC4A
80
// D6#                A7                PD7                FastPWM                #OC4D/ADC10
81
// D7                                PE6                                        INT6/AIN0
82
//
83
// D8                A8                PB4                                        ADC11/PCINT4
84
// D9#                A9                PB5                PWM16                OC1A/#OC4B/ADC12/PCINT5
85
// D10#                A10                PB6                PWM16                OC1B/0c4B/ADC13/PCINT6
86
// D11#                                PB7                PWM8/16                0C0A/OC1C/#RTS/PCINT7
87
// D12                A11                PD6                                        T1/#OC4D/ADC9
88
// D13#                                PC7                PWM10                CLK0/OC4A
89
//
90
// A0                D18                PF7                                        ADC7
91
// A1                D19                PF6                                        ADC6
92
// A2                D20         PF5                                        ADC5
93
// A3                D21         PF4                                        ADC4
94
// A4                D22                PF1                                        ADC1
95
// A5                D23         PF0                                        ADC0
96
//
97
// New pins D14..D17 to map SPI port to digital pins
98
//
99
// MISO                D14                PB3                                        MISO,PCINT3
100
// SCK                D15                PB1                                        SCK,PCINT1
101
// MOSI                D16                PB2                                        MOSI,PCINT2
102
// SS                D17                PB0                                        RXLED,SS/PCINT0
103
//
104
// TXLED                        PD5
105
// RXLED                    PB0
106
// HWB                                PE2                                        HWB
107

    
108
// these arrays map port names (e.g. port B) to the
109
// appropriate addresses for various functions (e.g. reading
110
// and writing)
111
const uint16_t PROGMEM port_to_mode_PGM[] = {
112
        NOT_A_PORT,
113
        NOT_A_PORT,
114
        (uint16_t) &DDRB,
115
        (uint16_t) &DDRC,
116
        (uint16_t) &DDRD,
117
        (uint16_t) &DDRE,
118
        (uint16_t) &DDRF,
119
};
120

    
121
const uint16_t PROGMEM port_to_output_PGM[] = {
122
        NOT_A_PORT,
123
        NOT_A_PORT,
124
        (uint16_t) &PORTB,
125
        (uint16_t) &PORTC,
126
        (uint16_t) &PORTD,
127
        (uint16_t) &PORTE,
128
        (uint16_t) &PORTF,
129
};
130

    
131
const uint16_t PROGMEM port_to_input_PGM[] = {
132
        NOT_A_PORT,
133
        NOT_A_PORT,
134
        (uint16_t) &PINB,
135
        (uint16_t) &PINC,
136
        (uint16_t) &PIND,
137
        (uint16_t) &PINE,
138
        (uint16_t) &PINF,
139
};
140

    
141
const uint8_t PROGMEM digital_pin_to_port_PGM[30] = {
142
        PD, // D0 - PD2
143
        PD,        // D1 - PD3
144
        PD, // D2 - PD1
145
        PD,        // D3 - PD0
146
        PD,        // D4 - PD4
147
        PC, // D5 - PC6
148
        PD, // D6 - PD7
149
        PE, // D7 - PE6
150
        
151
        PB, // D8 - PB4
152
        PB,        // D9 - PB5
153
        PB, // D10 - PB6
154
        PB,        // D11 - PB7
155
        PD, // D12 - PD6
156
        PC, // D13 - PC7
157
        
158
        PB,        // D14 - MISO - PB3
159
        PB,        // D15 - SCK - PB1
160
        PB,        // D16 - MOSI - PB2
161
        PB,        // D17 - SS - PB0
162
        
163
        PF,        // D18 - A0 - PF7
164
        PF, // D19 - A1 - PF6
165
        PF, // D20 - A2 - PF5
166
        PF, // D21 - A3 - PF4
167
        PF, // D22 - A4 - PF1
168
        PF, // D23 - A5 - PF0
169
        
170
        PD, // D24 / D4 - A6 - PD4
171
        PD, // D25 / D6 - A7 - PD7
172
        PB, // D26 / D8 - A8 - PB4
173
        PB, // D27 / D9 - A9 - PB5
174
        PB, // D28 / D10 - A10 - PB6
175
        PD, // D29 / D12 - A11 - PD6
176
};
177

    
178
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[30] = {
179
        _BV(2), // D0 - PD2
180
        _BV(3),        // D1 - PD3
181
        _BV(1), // D2 - PD1
182
        _BV(0),        // D3 - PD0
183
        _BV(4),        // D4 - PD4
184
        _BV(6), // D5 - PC6
185
        _BV(7), // D6 - PD7
186
        _BV(6), // D7 - PE6
187
        
188
        _BV(4), // D8 - PB4
189
        _BV(5),        // D9 - PB5
190
        _BV(6), // D10 - PB6
191
        _BV(7),        // D11 - PB7
192
        _BV(6), // D12 - PD6
193
        _BV(7), // D13 - PC7
194
        
195
        _BV(3),        // D14 - MISO - PB3
196
        _BV(1),        // D15 - SCK - PB1
197
        _BV(2),        // D16 - MOSI - PB2
198
        _BV(0),        // D17 - SS - PB0
199
        
200
        _BV(7),        // D18 - A0 - PF7
201
        _BV(6), // D19 - A1 - PF6
202
        _BV(5), // D20 - A2 - PF5
203
        _BV(4), // D21 - A3 - PF4
204
        _BV(1), // D22 - A4 - PF1
205
        _BV(0), // D23 - A5 - PF0
206
        
207
        _BV(4), // D24 / D4 - A6 - PD4
208
        _BV(7), // D25 / D6 - A7 - PD7
209
        _BV(4), // D26 / D8 - A8 - PB4
210
        _BV(5), // D27 / D9 - A9 - PB5
211
        _BV(6), // D28 / D10 - A10 - PB6
212
        _BV(6), // D29 / D12 - A11 - PD6
213
};
214

    
215
const uint8_t PROGMEM digital_pin_to_timer_PGM[18] = {
216
        NOT_ON_TIMER,        
217
        NOT_ON_TIMER,
218
        NOT_ON_TIMER,
219
        TIMER0B,                /* 3 */
220
        NOT_ON_TIMER,
221
        TIMER3A,                /* 5 */
222
        TIMER4D,                /* 6 */
223
        NOT_ON_TIMER,        
224
        
225
        NOT_ON_TIMER,        
226
        TIMER1A,                /* 9 */
227
        TIMER1B,                /* 10 */
228
        TIMER0A,                /* 11 */
229
        
230
        NOT_ON_TIMER,        
231
        TIMER4A,                /* 13 */
232
        
233
        NOT_ON_TIMER,        
234
        NOT_ON_TIMER,
235
};
236

    
237
const uint8_t PROGMEM analog_pin_to_channel_PGM[12] = {
238
        7,        // A0                                PF7                                        ADC7
239
        6,        // A1                                PF6                                        ADC6        
240
        5,        // A2                                PF5                                        ADC5        
241
        4,        // A3                                PF4                                        ADC4
242
        1,        // A4                                PF1                                        ADC1        
243
        0,        // A5                                PF0                                        ADC0        
244
        8,        // A6                D4                PD4                                        ADC8
245
        10,        // A7                D6                PD7                                        ADC10
246
        11,        // A8                D8                PB4                                        ADC11
247
        12,        // A9                D9                PB5                                        ADC12
248
        13,        // A10                D10                PB6                                        ADC13
249
        9        // A11                D12                PD6                                        ADC9
250
};
251

    
252
#endif /* ARDUINO_MAIN */
253
#endif /* Pins_Arduino_h */