Browse Source

Switched to Sanguino 0023r4

This is the actual Sanguino release for Arduino 023.
It has full ATmega1284p support.

Reference:
https://code.google.com/p/sanguino/downloads/detail?name=Sanguino-0023r4.zip&can=2&q=
Dirk Eichel 11 years ago
parent
commit
5bfba7720e

+ 0
- 135
ArduinoAddons/Arduino_0.xx/Sanguino/cores/arduino/Copy of wiring.h View File

@@ -1,135 +0,0 @@
1
-/*
2
-  wiring.h - Partial implementation of the Wiring API for the ATmega8.
3
-  Part of Arduino - http://www.arduino.cc/
4
-
5
-  Copyright (c) 2005-2006 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$
23
-*/
24
-
25
-#ifndef Wiring_h
26
-#define Wiring_h
27
-
28
-#include <avr/io.h>
29
-#include <stdlib.h>
30
-#include "binary.h"
31
-
32
-#ifdef __cplusplus
33
-extern "C"{
34
-#endif
35
-
36
-#define HIGH 0x1
37
-#define LOW  0x0
38
-
39
-#define INPUT 0x0
40
-#define OUTPUT 0x1
41
-
42
-#define true 0x1
43
-#define false 0x0
44
-
45
-#define PI 3.1415926535897932384626433832795
46
-#define HALF_PI 1.5707963267948966192313216916398
47
-#define TWO_PI 6.283185307179586476925286766559
48
-#define DEG_TO_RAD 0.017453292519943295769236907684886
49
-#define RAD_TO_DEG 57.295779513082320876798154814105
50
-
51
-#define SERIAL  0x0
52
-#define DISPLAY 0x1
53
-
54
-#define LSBFIRST 0
55
-#define MSBFIRST 1
56
-
57
-#define CHANGE 1
58
-#define FALLING 2
59
-#define RISING 3
60
-
61
-#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
62
-#define INTERNAL1V1 2
63
-#define INTERNAL2V56 3
64
-#else
65
-#define INTERNAL 3
66
-#endif
67
-#define DEFAULT 1
68
-#define EXTERNAL 0
69
-
70
-// undefine stdlib's abs if encountered
71
-#ifdef abs
72
-#undef abs
73
-#endif
74
-
75
-#define min(a,b) ((a)<(b)?(a):(b))
76
-#define max(a,b) ((a)>(b)?(a):(b))
77
-#define abs(x) ((x)>0?(x):-(x))
78
-#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
79
-#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
80
-#define radians(deg) ((deg)*DEG_TO_RAD)
81
-#define degrees(rad) ((rad)*RAD_TO_DEG)
82
-#define sq(x) ((x)*(x))
83
-
84
-#define interrupts() sei()
85
-#define noInterrupts() cli()
86
-
87
-#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
88
-#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
89
-#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
90
-
91
-#define lowByte(w) ((uint8_t) ((w) & 0xff))
92
-#define highByte(w) ((uint8_t) ((w) >> 8))
93
-
94
-#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
95
-#define bitSet(value, bit) ((value) |= (1UL << (bit)))
96
-#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
97
-#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
98
-
99
-
100
-typedef unsigned int word;
101
-
102
-#define bit(b) (1UL << (b))
103
-
104
-typedef uint8_t boolean;
105
-typedef uint8_t byte;
106
-
107
-void init(void);
108
-
109
-void pinMode(uint8_t, uint8_t);
110
-void digitalWrite(uint8_t, uint8_t);
111
-int digitalRead(uint8_t);
112
-int analogRead(uint8_t);
113
-void analogReference(uint8_t mode);
114
-void analogWrite(uint8_t, int);
115
-
116
-unsigned long millis(void);
117
-unsigned long micros(void);
118
-void delay(unsigned long);
119
-void delayMicroseconds(unsigned int us);
120
-unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
121
-
122
-void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
123
-uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
124
-
125
-void attachInterrupt(uint8_t, void (*)(void), int mode);
126
-void detachInterrupt(uint8_t);
127
-
128
-void setup(void);
129
-void loop(void);
130
-
131
-#ifdef __cplusplus
132
-} // extern "C"
133
-#endif
134
-
135
-#endif

+ 129
- 13
ArduinoAddons/Arduino_0.xx/Sanguino/cores/arduino/HardwareSerial.cpp View File

@@ -37,7 +37,11 @@
37 37
 // using a ring buffer (I think), in which rx_buffer_head is the index of the
38 38
 // location to which to write the next incoming character and rx_buffer_tail
39 39
 // is the index of the location from which to read.
40
-#define RX_BUFFER_SIZE 128
40
+#if (RAMEND < 1000)
41
+  #define RX_BUFFER_SIZE 32
42
+#else
43
+  #define RX_BUFFER_SIZE 128
44
+#endif
41 45
 
42 46
 struct ring_buffer
43 47
 {
@@ -46,11 +50,22 @@ struct ring_buffer
46 50
   int tail;
47 51
 };
48 52
 
49
-ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
53
+#if defined(UBRRH) || defined(UBRR0H)
54
+  ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
55
+#endif
56
+#if defined(UBRR1H)
57
+  ring_buffer rx_buffer1  =  { { 0 }, 0, 0 };
58
+#endif
59
+#if defined(UBRR2H)
60
+  ring_buffer rx_buffer2  =  { { 0 }, 0, 0 };
61
+#endif
62
+#if defined(UBRR3H)
63
+  ring_buffer rx_buffer3  =  { { 0 }, 0, 0 };
64
+#endif
50 65
 
51 66
 inline void store_char(unsigned char c, ring_buffer *rx_buffer)
52 67
 {
53
-  int i = (unsigned int)(rx_buffer->head + 1) & (RX_BUFFER_SIZE -1);
68
+  int i = (unsigned int)(rx_buffer->head + 1) % RX_BUFFER_SIZE;
54 69
 
55 70
   // if we should be storing the received character into the location
56 71
   // just before the tail (meaning that the head would advance to the
@@ -62,13 +77,95 @@ inline void store_char(unsigned char c, ring_buffer *rx_buffer)
62 77
   }
63 78
 }
64 79
 
65
-// fixed by Mark Sproul this is on the 644/644p
66
-//SIGNAL(SIG_USART_RECV)
67
-SIGNAL(USART0_RX_vect)
68
-{
69
-  unsigned char c  =  UDR0;
70
-  store_char(c, &rx_buffer);
71
-}
80
+#if defined(USART_RX_vect)
81
+  SIGNAL(USART_RX_vect)
82
+  {
83
+  #if defined(UDR0)
84
+    unsigned char c  =  UDR0;
85
+  #elif defined(UDR)
86
+    unsigned char c  =  UDR;  //  atmega8535
87
+  #else
88
+    #error UDR not defined
89
+  #endif
90
+    store_char(c, &rx_buffer);
91
+  }
92
+#elif defined(SIG_USART0_RECV) && defined(UDR0)
93
+  SIGNAL(SIG_USART0_RECV)
94
+  {
95
+    unsigned char c  =  UDR0;
96
+    store_char(c, &rx_buffer);
97
+  }
98
+#elif defined(SIG_UART0_RECV) && defined(UDR0)
99
+  SIGNAL(SIG_UART0_RECV)
100
+  {
101
+    unsigned char c  =  UDR0;
102
+    store_char(c, &rx_buffer);
103
+  }
104
+//#elif defined(SIG_USART_RECV)
105
+#elif defined(USART0_RX_vect)
106
+  // fixed by Mark Sproul this is on the 644/644p
107
+  //SIGNAL(SIG_USART_RECV)
108
+  SIGNAL(USART0_RX_vect)
109
+  {
110
+  #if defined(UDR0)
111
+    unsigned char c  =  UDR0;
112
+  #elif defined(UDR)
113
+    unsigned char c  =  UDR;  //  atmega8, atmega32
114
+  #else
115
+    #error UDR not defined
116
+  #endif
117
+    store_char(c, &rx_buffer);
118
+  }
119
+#elif defined(SIG_UART_RECV)
120
+  // this is for atmega8
121
+  SIGNAL(SIG_UART_RECV)
122
+  {
123
+  #if defined(UDR0)
124
+    unsigned char c  =  UDR0;  //  atmega645
125
+  #elif defined(UDR)
126
+    unsigned char c  =  UDR;  //  atmega8
127
+  #endif
128
+    store_char(c, &rx_buffer);
129
+  }
130
+#elif defined(USBCON)
131
+  #warning No interrupt handler for usart 0
132
+  #warning Serial(0) is on USB interface
133
+#else
134
+  #error No interrupt handler for usart 0
135
+#endif
136
+
137
+//#if defined(SIG_USART1_RECV)
138
+#if defined(USART1_RX_vect)
139
+  //SIGNAL(SIG_USART1_RECV)
140
+  SIGNAL(USART1_RX_vect)
141
+  {
142
+    unsigned char c = UDR1;
143
+    store_char(c, &rx_buffer1);
144
+  }
145
+#elif defined(SIG_USART1_RECV)
146
+  #error SIG_USART1_RECV
147
+#endif
148
+
149
+#if defined(USART2_RX_vect) && defined(UDR2)
150
+  SIGNAL(USART2_RX_vect)
151
+  {
152
+    unsigned char c = UDR2;
153
+    store_char(c, &rx_buffer2);
154
+  }
155
+#elif defined(SIG_USART2_RECV)
156
+  #error SIG_USART2_RECV
157
+#endif
158
+
159
+#if defined(USART3_RX_vect) && defined(UDR3)
160
+  SIGNAL(USART3_RX_vect)
161
+  {
162
+    unsigned char c = UDR3;
163
+    store_char(c, &rx_buffer3);
164
+  }
165
+#elif defined(SIG_USART3_RECV)
166
+  #error SIG_USART3_RECV
167
+#endif
168
+
72 169
 
73 170
 
74 171
 // Constructors ////////////////////////////////////////////////////////////////
@@ -134,7 +231,7 @@ void HardwareSerial::end()
134 231
 
135 232
 int HardwareSerial::available(void)
136 233
 {
137
-  return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) & (RX_BUFFER_SIZE-1);
234
+  return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
138 235
 }
139 236
 
140 237
 int HardwareSerial::peek(void)
@@ -153,7 +250,7 @@ int HardwareSerial::read(void)
153 250
     return -1;
154 251
   } else {
155 252
     unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
156
-    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) & (RX_BUFFER_SIZE-1);
253
+    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
157 254
     return c;
158 255
   }
159 256
 }
@@ -181,7 +278,26 @@ void HardwareSerial::write(uint8_t c)
181 278
 }
182 279
 
183 280
 // Preinstantiate Objects //////////////////////////////////////////////////////
184
-HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
281
+
282
+#if defined(UBRRH) && defined(UBRRL)
283
+  HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE, U2X);
284
+#elif defined(UBRR0H) && defined(UBRR0L)
285
+  HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
286
+#elif defined(USBCON)
287
+  #warning no serial port defined  (port 0)
288
+#else
289
+  #error no serial port defined  (port 0)
290
+#endif
291
+
292
+#if defined(UBRR1H)
293
+  HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1);
294
+#endif
295
+#if defined(UBRR2H)
296
+  HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2);
297
+#endif
298
+#if defined(UBRR3H)
299
+  HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3);
300
+#endif
185 301
 
186 302
 #endif // whole file
187 303
 

+ 42
- 11
ArduinoAddons/Arduino_0.xx/Sanguino/cores/arduino/WInterrupts.c View File

@@ -46,7 +46,6 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
46 46
     // the mode into place.
47 47
       
48 48
     // Enable the interrupt.
49
-      
50 49
     switch (interruptNum) {
51 50
 #if defined(EICRA) && defined(EICRB) && defined(EIMSK)
52 51
     case 2:
@@ -81,6 +80,19 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
81 80
       EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
82 81
       EIMSK |= (1 << INT7);
83 82
       break;
83
+#elif defined(EICRA) && defined(EIMSK)
84
+    case 0:
85
+      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
86
+      EIMSK |= (1 << INT0);
87
+      break;
88
+    case 1:
89
+      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
90
+      EIMSK |= (1 << INT1);
91
+      break;
92
+    case 2:
93
+      EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
94
+      EIMSK |= (1 << INT2);
95
+      break;
84 96
 #else
85 97
     case 0:
86 98
     #if defined(EICRA) && defined(ISC00) && defined(EIMSK)
@@ -123,15 +135,6 @@ void detachInterrupt(uint8_t interruptNum) {
123 135
     // ATmega8.  There, INT0 is 6 and INT1 is 7.)
124 136
     switch (interruptNum) {
125 137
 #if defined(EICRA) && defined(EICRB) && defined(EIMSK)
126
-    case 2:
127
-      EIMSK &= ~(1 << INT0);
128
-      break;
129
-    case 3:
130
-      EIMSK &= ~(1 << INT1);
131
-      break;
132
-    case 4:
133
-      EIMSK &= ~(1 << INT2);
134
-      break;
135 138
     case 5:
136 139
       EIMSK &= ~(1 << INT3);
137 140
       break;
@@ -147,6 +150,17 @@ void detachInterrupt(uint8_t interruptNum) {
147 150
     case 7:
148 151
       EIMSK &= ~(1 << INT7);
149 152
       break;
153
+#elif defined(EICRA) && defined(EIMSK)
154
+    case 0:
155
+      EIMSK &= ~(1 << INT0);
156
+      break;
157
+    case 1:
158
+      EIMSK &= ~(1 << INT1);
159
+      break;
160
+    case 2:
161
+      EIMSK &= ~(1 << INT2);
162
+      break;
163
+
150 164
 #else
151 165
     case 0:
152 166
     #if defined(EIMSK) && defined(INT0)
@@ -184,8 +198,8 @@ void attachInterruptTwi(void (*userFunc)(void) ) {
184 198
 }
185 199
 */
186 200
 
187
-#if defined(EICRA) && defined(EICRB)
188 201
 
202
+#if defined(EICRA) && defined(EICRB)
189 203
 SIGNAL(INT0_vect) {
190 204
   if(intFunc[EXTERNAL_INT_2])
191 205
     intFunc[EXTERNAL_INT_2]();
@@ -226,6 +240,23 @@ SIGNAL(INT7_vect) {
226 240
     intFunc[EXTERNAL_INT_7]();
227 241
 }
228 242
 
243
+#elif defined(EICRA)
244
+
245
+SIGNAL(INT0_vect) {
246
+  if(intFunc[EXTERNAL_INT_0])
247
+    intFunc[EXTERNAL_INT_0]();
248
+}
249
+
250
+SIGNAL(INT1_vect) {
251
+  if(intFunc[EXTERNAL_INT_1])
252
+    intFunc[EXTERNAL_INT_1]();
253
+}
254
+
255
+SIGNAL(INT2_vect) {
256
+  if(intFunc[EXTERNAL_INT_2])
257
+    intFunc[EXTERNAL_INT_2]();
258
+}
259
+
229 260
 #else
230 261
 
231 262
 SIGNAL(INT0_vect) {

+ 520
- 93
ArduinoAddons/Arduino_0.xx/Sanguino/cores/arduino/pins_arduino.c View File

@@ -19,17 +19,54 @@
19 19
   Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 20
   Boston, MA  02111-1307  USA
21 21
 
22
-  $Id: pins_arduino.c 254 2007-04-20 23:17:38Z mellis $
22
+  Changelog
23
+  -----------
24
+  11/25/11  - ryan@ryanmsutton.com - Add pins for Sanguino 644P and 1284P
25
+  $Id$
23 26
 */
24 27
 
25 28
 #include <avr/io.h>
26 29
 #include "wiring_private.h"
27 30
 #include "pins_arduino.h"
28 31
 
29
-// On the Sanguino board, digital pins are also used
32
+// On the Arduino board, digital pins are also used
30 33
 // for the analog output (software PWM).  Analog input
31 34
 // pins are a separate set.
32 35
 
36
+// ATMEL ATMEGA8 & 168 / ARDUINO
37
+//
38
+//                  +-\/-+
39
+//            PC6  1|    |28  PC5 (AI 5)
40
+//      (D 0) PD0  2|    |27  PC4 (AI 4)
41
+//      (D 1) PD1  3|    |26  PC3 (AI 3)
42
+//      (D 2) PD2  4|    |25  PC2 (AI 2)
43
+// PWM+ (D 3) PD3  5|    |24  PC1 (AI 1)
44
+//      (D 4) PD4  6|    |23  PC0 (AI 0)
45
+//            VCC  7|    |22  GND
46
+//            GND  8|    |21  AREF
47
+//            PB6  9|    |20  AVCC
48
+//            PB7 10|    |19  PB5 (D 13)
49
+// PWM+ (D 5) PD5 11|    |18  PB4 (D 12)
50
+// PWM+ (D 6) PD6 12|    |17  PB3 (D 11) PWM
51
+//      (D 7) PD7 13|    |16  PB2 (D 10) PWM
52
+//      (D 8) PB0 14|    |15  PB1 (D 9) PWM
53
+//                  +----+
54
+//
55
+// (PWM+ indicates the additional PWM pins on the ATmega168.)
56
+
57
+// ATMEL ATMEGA1280 / ARDUINO
58
+//
59
+// 0-7 PE0-PE7   works
60
+// 8-13 PB0-PB5  works
61
+// 14-21 PA0-PA7 works 
62
+// 22-29 PH0-PH7 works
63
+// 30-35 PG5-PG0 works
64
+// 36-43 PC7-PC0 works
65
+// 44-51 PJ7-PJ0 works
66
+// 52-59 PL7-PL0 works
67
+// 60-67 PD7-PD0 works
68
+// A0-A7 PF0-PF7
69
+// A8-A15 PK0-PK7
33 70
 // ATMEL ATMEGA644P / SANGUINO
34 71
 //
35 72
 //                   +---\/---+
@@ -55,53 +92,457 @@
55 92
 //  PWM (D 14) PD6 20|        |21  PD7 (D 15) PWM
56 93
 //                   +--------+
57 94
 //
58
-
59 95
 #define PA 1
60 96
 #define PB 2
61 97
 #define PC 3
62 98
 #define PD 4
99
+#define PE 5
100
+#define PF 6
101
+#define PG 7
102
+#define PH 8
103
+#define PJ 10
104
+#define PK 11
105
+#define PL 12
106
+
107
+
108
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
109
+const uint16_t PROGMEM port_to_mode_PGM[] = {
110
+	NOT_A_PORT,
111
+	&DDRA,
112
+	&DDRB,
113
+	&DDRC,
114
+	&DDRD,
115
+	&DDRE,
116
+	&DDRF,
117
+	&DDRG,
118
+	&DDRH,
119
+	NOT_A_PORT,
120
+	&DDRJ,
121
+	&DDRK,
122
+	&DDRL,
123
+};
63 124
 
125
+const uint16_t PROGMEM port_to_output_PGM[] = {
126
+	NOT_A_PORT,
127
+	&PORTA,
128
+	&PORTB,
129
+	&PORTC,
130
+	&PORTD,
131
+	&PORTE,
132
+	&PORTF,
133
+	&PORTG,
134
+	&PORTH,
135
+	NOT_A_PORT,
136
+	&PORTJ,
137
+	&PORTK,
138
+	&PORTL,
139
+};
140
+
141
+const uint16_t PROGMEM port_to_input_PGM[] = {
142
+	NOT_A_PIN,
143
+	&PINA,
144
+	&PINB,
145
+	&PINC,
146
+	&PIND,
147
+	&PINE,
148
+	&PINF,
149
+	&PING,
150
+	&PINH,
151
+	NOT_A_PIN,
152
+	&PINJ,
153
+	&PINK,
154
+	&PINL,
155
+};
156
+
157
+const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
158
+	// PORTLIST		
159
+	// -------------------------------------------		
160
+	PE	, // PE 0 ** 0 ** USART0_RX	
161
+	PE	, // PE 1 ** 1 ** USART0_TX	
162
+	PE	, // PE 4 ** 2 ** PWM2	
163
+	PE	, // PE 5 ** 3 ** PWM3	
164
+	PG	, // PG 5 ** 4 ** PWM4	
165
+	PE	, // PE 3 ** 5 ** PWM5	
166
+	PH	, // PH 3 ** 6 ** PWM6	
167
+	PH	, // PH 4 ** 7 ** PWM7	
168
+	PH	, // PH 5 ** 8 ** PWM8	
169
+	PH	, // PH 6 ** 9 ** PWM9	
170
+	PB	, // PB 4 ** 10 ** PWM10	
171
+	PB	, // PB 5 ** 11 ** PWM11	
172
+	PB	, // PB 6 ** 12 ** PWM12	
173
+	PB	, // PB 7 ** 13 ** PWM13	
174
+	PJ	, // PJ 1 ** 14 ** USART3_TX	
175
+	PJ	, // PJ 0 ** 15 ** USART3_RX	
176
+	PH	, // PH 1 ** 16 ** USART2_TX	
177
+	PH	, // PH 0 ** 17 ** USART2_RX	
178
+	PD	, // PD 3 ** 18 ** USART1_TX	
179
+	PD	, // PD 2 ** 19 ** USART1_RX	
180
+	PD	, // PD 1 ** 20 ** I2C_SDA	
181
+	PD	, // PD 0 ** 21 ** I2C_SCL	
182
+	PA	, // PA 0 ** 22 ** D22	
183
+	PA	, // PA 1 ** 23 ** D23	
184
+	PA	, // PA 2 ** 24 ** D24	
185
+	PA	, // PA 3 ** 25 ** D25	
186
+	PA	, // PA 4 ** 26 ** D26	
187
+	PA	, // PA 5 ** 27 ** D27	
188
+	PA	, // PA 6 ** 28 ** D28	
189
+	PA	, // PA 7 ** 29 ** D29	
190
+	PC	, // PC 7 ** 30 ** D30	
191
+	PC	, // PC 6 ** 31 ** D31	
192
+	PC	, // PC 5 ** 32 ** D32	
193
+	PC	, // PC 4 ** 33 ** D33	
194
+	PC	, // PC 3 ** 34 ** D34	
195
+	PC	, // PC 2 ** 35 ** D35	
196
+	PC	, // PC 1 ** 36 ** D36	
197
+	PC	, // PC 0 ** 37 ** D37	
198
+	PD	, // PD 7 ** 38 ** D38	
199
+	PG	, // PG 2 ** 39 ** D39	
200
+	PG	, // PG 1 ** 40 ** D40	
201
+	PG	, // PG 0 ** 41 ** D41	
202
+	PL	, // PL 7 ** 42 ** D42	
203
+	PL	, // PL 6 ** 43 ** D43	
204
+	PL	, // PL 5 ** 44 ** D44	
205
+	PL	, // PL 4 ** 45 ** D45	
206
+	PL	, // PL 3 ** 46 ** D46	
207
+	PL	, // PL 2 ** 47 ** D47	
208
+	PL	, // PL 1 ** 48 ** D48	
209
+	PL	, // PL 0 ** 49 ** D49	
210
+	PB	, // PB 3 ** 50 ** SPI_MISO	
211
+	PB	, // PB 2 ** 51 ** SPI_MOSI	
212
+	PB	, // PB 1 ** 52 ** SPI_SCK	
213
+	PB	, // PB 0 ** 53 ** SPI_SS	
214
+	PF	, // PF 0 ** 54 ** A0	
215
+	PF	, // PF 1 ** 55 ** A1	
216
+	PF	, // PF 2 ** 56 ** A2	
217
+	PF	, // PF 3 ** 57 ** A3	
218
+	PF	, // PF 4 ** 58 ** A4	
219
+	PF	, // PF 5 ** 59 ** A5	
220
+	PF	, // PF 6 ** 60 ** A6	
221
+	PF	, // PF 7 ** 61 ** A7	
222
+	PK	, // PK 0 ** 62 ** A8	
223
+	PK	, // PK 1 ** 63 ** A9	
224
+	PK	, // PK 2 ** 64 ** A10	
225
+	PK	, // PK 3 ** 65 ** A11	
226
+	PK	, // PK 4 ** 66 ** A12	
227
+	PK	, // PK 5 ** 67 ** A13	
228
+	PK	, // PK 6 ** 68 ** A14	
229
+	PK	, // PK 7 ** 69 ** A15	
230
+};
231
+
232
+const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
233
+	// PIN IN PORT		
234
+	// -------------------------------------------		
235
+	_BV( 0 )	, // PE 0 ** 0 ** USART0_RX	
236
+	_BV( 1 )	, // PE 1 ** 1 ** USART0_TX	
237
+	_BV( 4 )	, // PE 4 ** 2 ** PWM2	
238
+	_BV( 5 )	, // PE 5 ** 3 ** PWM3	
239
+	_BV( 5 )	, // PG 5 ** 4 ** PWM4	
240
+	_BV( 3 )	, // PE 3 ** 5 ** PWM5	
241
+	_BV( 3 )	, // PH 3 ** 6 ** PWM6	
242
+	_BV( 4 )	, // PH 4 ** 7 ** PWM7	
243
+	_BV( 5 )	, // PH 5 ** 8 ** PWM8	
244
+	_BV( 6 )	, // PH 6 ** 9 ** PWM9	
245
+	_BV( 4 )	, // PB 4 ** 10 ** PWM10	
246
+	_BV( 5 )	, // PB 5 ** 11 ** PWM11	
247
+	_BV( 6 )	, // PB 6 ** 12 ** PWM12	
248
+	_BV( 7 )	, // PB 7 ** 13 ** PWM13	
249
+	_BV( 1 )	, // PJ 1 ** 14 ** USART3_TX	
250
+	_BV( 0 )	, // PJ 0 ** 15 ** USART3_RX	
251
+	_BV( 1 )	, // PH 1 ** 16 ** USART2_TX	
252
+	_BV( 0 )	, // PH 0 ** 17 ** USART2_RX	
253
+	_BV( 3 )	, // PD 3 ** 18 ** USART1_TX	
254
+	_BV( 2 )	, // PD 2 ** 19 ** USART1_RX	
255
+	_BV( 1 )	, // PD 1 ** 20 ** I2C_SDA	
256
+	_BV( 0 )	, // PD 0 ** 21 ** I2C_SCL	
257
+	_BV( 0 )	, // PA 0 ** 22 ** D22	
258
+	_BV( 1 )	, // PA 1 ** 23 ** D23	
259
+	_BV( 2 )	, // PA 2 ** 24 ** D24	
260
+	_BV( 3 )	, // PA 3 ** 25 ** D25	
261
+	_BV( 4 )	, // PA 4 ** 26 ** D26	
262
+	_BV( 5 )	, // PA 5 ** 27 ** D27	
263
+	_BV( 6 )	, // PA 6 ** 28 ** D28	
264
+	_BV( 7 )	, // PA 7 ** 29 ** D29	
265
+	_BV( 7 )	, // PC 7 ** 30 ** D30	
266
+	_BV( 6 )	, // PC 6 ** 31 ** D31	
267
+	_BV( 5 )	, // PC 5 ** 32 ** D32	
268
+	_BV( 4 )	, // PC 4 ** 33 ** D33	
269
+	_BV( 3 )	, // PC 3 ** 34 ** D34	
270
+	_BV( 2 )	, // PC 2 ** 35 ** D35	
271
+	_BV( 1 )	, // PC 1 ** 36 ** D36	
272
+	_BV( 0 )	, // PC 0 ** 37 ** D37	
273
+	_BV( 7 )	, // PD 7 ** 38 ** D38	
274
+	_BV( 2 )	, // PG 2 ** 39 ** D39	
275
+	_BV( 1 )	, // PG 1 ** 40 ** D40	
276
+	_BV( 0 )	, // PG 0 ** 41 ** D41	
277
+	_BV( 7 )	, // PL 7 ** 42 ** D42	
278
+	_BV( 6 )	, // PL 6 ** 43 ** D43	
279
+	_BV( 5 )	, // PL 5 ** 44 ** D44	
280
+	_BV( 4 )	, // PL 4 ** 45 ** D45	
281
+	_BV( 3 )	, // PL 3 ** 46 ** D46	
282
+	_BV( 2 )	, // PL 2 ** 47 ** D47	
283
+	_BV( 1 )	, // PL 1 ** 48 ** D48	
284
+	_BV( 0 )	, // PL 0 ** 49 ** D49	
285
+	_BV( 3 )	, // PB 3 ** 50 ** SPI_MISO	
286
+	_BV( 2 )	, // PB 2 ** 51 ** SPI_MOSI	
287
+	_BV( 1 )	, // PB 1 ** 52 ** SPI_SCK	
288
+	_BV( 0 )	, // PB 0 ** 53 ** SPI_SS	
289
+	_BV( 0 )	, // PF 0 ** 54 ** A0	
290
+	_BV( 1 )	, // PF 1 ** 55 ** A1	
291
+	_BV( 2 )	, // PF 2 ** 56 ** A2	
292
+	_BV( 3 )	, // PF 3 ** 57 ** A3	
293
+	_BV( 4 )	, // PF 4 ** 58 ** A4	
294
+	_BV( 5 )	, // PF 5 ** 59 ** A5	
295
+	_BV( 6 )	, // PF 6 ** 60 ** A6	
296
+	_BV( 7 )	, // PF 7 ** 61 ** A7	
297
+	_BV( 0 )	, // PK 0 ** 62 ** A8	
298
+	_BV( 1 )	, // PK 1 ** 63 ** A9	
299
+	_BV( 2 )	, // PK 2 ** 64 ** A10	
300
+	_BV( 3 )	, // PK 3 ** 65 ** A11	
301
+	_BV( 4 )	, // PK 4 ** 66 ** A12	
302
+	_BV( 5 )	, // PK 5 ** 67 ** A13	
303
+	_BV( 6 )	, // PK 6 ** 68 ** A14	
304
+	_BV( 7 )	, // PK 7 ** 69 ** A15	
305
+};
306
+
307
+const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
308
+	// TIMERS		
309
+	// -------------------------------------------		
310
+	NOT_ON_TIMER	, // PE 0 ** 0 ** USART0_RX	
311
+	NOT_ON_TIMER	, // PE 1 ** 1 ** USART0_TX	
312
+	TIMER3B	, // PE 4 ** 2 ** PWM2	
313
+	TIMER3C	, // PE 5 ** 3 ** PWM3	
314
+	TIMER0B	, // PG 5 ** 4 ** PWM4	
315
+	TIMER3A	, // PE 3 ** 5 ** PWM5	
316
+	TIMER4A	, // PH 3 ** 6 ** PWM6	
317
+	TIMER4B	, // PH 4 ** 7 ** PWM7	
318
+	TIMER4C	, // PH 5 ** 8 ** PWM8	
319
+	TIMER2B	, // PH 6 ** 9 ** PWM9	
320
+	TIMER2A	, // PB 4 ** 10 ** PWM10	
321
+	TIMER1A	, // PB 5 ** 11 ** PWM11	
322
+	TIMER1B	, // PB 6 ** 12 ** PWM12	
323
+	TIMER0A	, // PB 7 ** 13 ** PWM13	
324
+	NOT_ON_TIMER	, // PJ 1 ** 14 ** USART3_TX	
325
+	NOT_ON_TIMER	, // PJ 0 ** 15 ** USART3_RX	
326
+	NOT_ON_TIMER	, // PH 1 ** 16 ** USART2_TX	
327
+	NOT_ON_TIMER	, // PH 0 ** 17 ** USART2_RX	
328
+	NOT_ON_TIMER	, // PD 3 ** 18 ** USART1_TX	
329
+	NOT_ON_TIMER	, // PD 2 ** 19 ** USART1_RX	
330
+	NOT_ON_TIMER	, // PD 1 ** 20 ** I2C_SDA	
331
+	NOT_ON_TIMER	, // PD 0 ** 21 ** I2C_SCL	
332
+	NOT_ON_TIMER	, // PA 0 ** 22 ** D22	
333
+	NOT_ON_TIMER	, // PA 1 ** 23 ** D23	
334
+	NOT_ON_TIMER	, // PA 2 ** 24 ** D24	
335
+	NOT_ON_TIMER	, // PA 3 ** 25 ** D25	
336
+	NOT_ON_TIMER	, // PA 4 ** 26 ** D26	
337
+	NOT_ON_TIMER	, // PA 5 ** 27 ** D27	
338
+	NOT_ON_TIMER	, // PA 6 ** 28 ** D28	
339
+	NOT_ON_TIMER	, // PA 7 ** 29 ** D29	
340
+	NOT_ON_TIMER	, // PC 7 ** 30 ** D30	
341
+	NOT_ON_TIMER	, // PC 6 ** 31 ** D31	
342
+	NOT_ON_TIMER	, // PC 5 ** 32 ** D32	
343
+	NOT_ON_TIMER	, // PC 4 ** 33 ** D33	
344
+	NOT_ON_TIMER	, // PC 3 ** 34 ** D34	
345
+	NOT_ON_TIMER	, // PC 2 ** 35 ** D35	
346
+	NOT_ON_TIMER	, // PC 1 ** 36 ** D36	
347
+	NOT_ON_TIMER	, // PC 0 ** 37 ** D37	
348
+	NOT_ON_TIMER	, // PD 7 ** 38 ** D38	
349
+	NOT_ON_TIMER	, // PG 2 ** 39 ** D39	
350
+	NOT_ON_TIMER	, // PG 1 ** 40 ** D40	
351
+	NOT_ON_TIMER	, // PG 0 ** 41 ** D41	
352
+	NOT_ON_TIMER	, // PL 7 ** 42 ** D42	
353
+	NOT_ON_TIMER	, // PL 6 ** 43 ** D43	
354
+	TIMER5C	, // PL 5 ** 44 ** D44	
355
+	TIMER5B	, // PL 4 ** 45 ** D45	
356
+	TIMER5A	, // PL 3 ** 46 ** D46	
357
+	NOT_ON_TIMER	, // PL 2 ** 47 ** D47	
358
+	NOT_ON_TIMER	, // PL 1 ** 48 ** D48	
359
+	NOT_ON_TIMER	, // PL 0 ** 49 ** D49	
360
+	NOT_ON_TIMER	, // PB 3 ** 50 ** SPI_MISO	
361
+	NOT_ON_TIMER	, // PB 2 ** 51 ** SPI_MOSI	
362
+	NOT_ON_TIMER	, // PB 1 ** 52 ** SPI_SCK	
363
+	NOT_ON_TIMER	, // PB 0 ** 53 ** SPI_SS	
364
+	NOT_ON_TIMER	, // PF 0 ** 54 ** A0	
365
+	NOT_ON_TIMER	, // PF 1 ** 55 ** A1	
366
+	NOT_ON_TIMER	, // PF 2 ** 56 ** A2	
367
+	NOT_ON_TIMER	, // PF 3 ** 57 ** A3	
368
+	NOT_ON_TIMER	, // PF 4 ** 58 ** A4	
369
+	NOT_ON_TIMER	, // PF 5 ** 59 ** A5	
370
+	NOT_ON_TIMER	, // PF 6 ** 60 ** A6	
371
+	NOT_ON_TIMER	, // PF 7 ** 61 ** A7	
372
+	NOT_ON_TIMER	, // PK 0 ** 62 ** A8	
373
+	NOT_ON_TIMER	, // PK 1 ** 63 ** A9	
374
+	NOT_ON_TIMER	, // PK 2 ** 64 ** A10	
375
+	NOT_ON_TIMER	, // PK 3 ** 65 ** A11	
376
+	NOT_ON_TIMER	, // PK 4 ** 66 ** A12	
377
+	NOT_ON_TIMER	, // PK 5 ** 67 ** A13	
378
+	NOT_ON_TIMER	, // PK 6 ** 68 ** A14	
379
+	NOT_ON_TIMER	, // PK 7 ** 69 ** A15	
380
+};
381
+#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
64 382
 // these arrays map port names (e.g. port B) to the
65 383
 // appropriate addresses for various functions (e.g. reading
66 384
 // and writing)
67
-const uint8_t PROGMEM port_to_mode_PGM[] =
385
+const uint16_t PROGMEM port_to_mode_PGM[] =
68 386
 {
69
-	NOT_A_PORT,
70
-	(uint8_t) (uint16_t) &DDRA,
71
-	(uint8_t) (uint16_t) &DDRB,
72
-	(uint8_t) (uint16_t) &DDRC,
73
-	(uint8_t) (uint16_t) &DDRD,
387
+        NOT_A_PORT,
388
+    &DDRA,
389
+        &DDRB,
390
+        &DDRC,
391
+        &DDRD,
74 392
 };
75 393
 
76
-const uint8_t PROGMEM port_to_output_PGM[] =
394
+const uint16_t PROGMEM port_to_output_PGM[] =
395
+{
396
+        NOT_A_PORT,
397
+        &PORTA,
398
+        &PORTB,
399
+        &PORTC,
400
+        &PORTD,
401
+};
402
+const uint16_t PROGMEM port_to_input_PGM[] =
403
+{
404
+        NOT_A_PORT,
405
+        &PINA,
406
+        &PINB,
407
+        &PINC,
408
+        &PIND,
409
+};
410
+const uint8_t PROGMEM digital_pin_to_port_PGM[] =
411
+{
412
+        PB, /* 0 */
413
+        PB,
414
+        PB,
415
+        PB,
416
+        PB,
417
+        PB,
418
+        PB,
419
+        PB,
420
+        PD, /* 8 */
421
+        PD,
422
+        PD,
423
+        PD,
424
+        PD,
425
+        PD,
426
+        PD,
427
+        PD,
428
+        PC, /* 16 */
429
+        PC,
430
+        PC,
431
+        PC,
432
+        PC,
433
+        PC,
434
+        PC,
435
+        PC,
436
+        PA, /* 24 */
437
+        PA,
438
+        PA,
439
+        PA,
440
+        PA,
441
+        PA,
442
+        PA,
443
+        PA  /* 31 */
444
+};
445
+const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
446
+{
447
+        _BV(0), /* 0, port B */
448
+        _BV(1),
449
+        _BV(2),
450
+        _BV(3),
451
+        _BV(4),
452
+        _BV(5),
453
+        _BV(6),
454
+        _BV(7),
455
+        _BV(0), /* 8, port D */
456
+        _BV(1),
457
+        _BV(2),
458
+        _BV(3),
459
+        _BV(4),
460
+        _BV(5),
461
+        _BV(6),
462
+        _BV(7),
463
+        _BV(0), /* 16, port C */
464
+        _BV(1),
465
+        _BV(2),
466
+        _BV(3),
467
+        _BV(4),
468
+        _BV(5),
469
+        _BV(6),
470
+        _BV(7),
471
+        _BV(7), /* 24, port A */
472
+        _BV(6),
473
+        _BV(5),
474
+        _BV(4),
475
+        _BV(3),
476
+        _BV(2),
477
+        _BV(1),
478
+        _BV(0)
479
+};
480
+const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
77 481
 {
482
+        NOT_ON_TIMER,   /* 0  - PB0 */
483
+        NOT_ON_TIMER,   /* 1  - PB1 */
484
+        NOT_ON_TIMER,   /* 2  - PB2 */
485
+        TIMER0A,        /* 3  - PB3 */
486
+        TIMER0B,                /* 4  - PB4 */
487
+        NOT_ON_TIMER,   /* 5  - PB5 */
488
+        NOT_ON_TIMER,   /* 6  - PB6 */
489
+        NOT_ON_TIMER,   /* 7  - PB7 */
490
+        NOT_ON_TIMER,   /* 8  - PD0 */
491
+        NOT_ON_TIMER,   /* 9  - PD1 */
492
+        NOT_ON_TIMER,   /* 10 - PD2 */
493
+        NOT_ON_TIMER,   /* 11 - PD3 */
494
+        TIMER1B,        /* 12 - PD4 */
495
+        TIMER1A,        /* 13 - PD5 */
496
+        TIMER2B,        /* 14 - PD6 */
497
+        TIMER2A,        /* 15 - PD7 */
498
+        NOT_ON_TIMER,   /* 16 - PC0 */
499
+        NOT_ON_TIMER,   /* 17 - PC1 */
500
+        NOT_ON_TIMER,   /* 18 - PC2 */
501
+        NOT_ON_TIMER,   /* 19 - PC3 */
502
+        NOT_ON_TIMER,   /* 20 - PC4 */
503
+        NOT_ON_TIMER,   /* 21 - PC5 */
504
+        NOT_ON_TIMER,   /* 22 - PC6 */
505
+        NOT_ON_TIMER,   /* 23 - PC7 */
506
+        NOT_ON_TIMER,   /* 24 - PA0 */
507
+        NOT_ON_TIMER,   /* 25 - PA1 */
508
+        NOT_ON_TIMER,   /* 26 - PA2 */
509
+        NOT_ON_TIMER,   /* 27 - PA3 */
510
+        NOT_ON_TIMER,   /* 28 - PA4 */
511
+        NOT_ON_TIMER,   /* 29 - PA5 */
512
+        NOT_ON_TIMER,   /* 30 - PA6 */
513
+        NOT_ON_TIMER   /* 31 - PA7 */
514
+};
515
+
516
+#else
517
+// these arrays map port names (e.g. port B) to the
518
+// appropriate addresses for various functions (e.g. reading
519
+// and writing)
520
+const uint16_t PROGMEM port_to_mode_PGM[] = {
521
+	NOT_A_PORT,
78 522
 	NOT_A_PORT,
79
-	(uint8_t) (uint16_t) &PORTA,
80
-	(uint8_t) (uint16_t) &PORTB,
81
-	(uint8_t) (uint16_t) &PORTC,
82
-	(uint8_t) (uint16_t) &PORTD,
523
+	&DDRB,
524
+	&DDRC,
525
+	&DDRD,
83 526
 };
84 527
 
85
-const uint8_t PROGMEM port_to_input_PGM[] =
86
-{
528
+const uint16_t PROGMEM port_to_output_PGM[] = {
87 529
 	NOT_A_PORT,
88
-	(uint8_t) (uint16_t) &PINA,
89
-	(uint8_t) (uint16_t) &PINB,
90
-	(uint8_t) (uint16_t) &PINC,
91
-	(uint8_t) (uint16_t) &PIND,
530
+	NOT_A_PORT,
531
+	&PORTB,
532
+	&PORTC,
533
+	&PORTD,
92 534
 };
93 535
 
94
-const uint8_t PROGMEM digital_pin_to_port_PGM[] =
95
-{
96
-	PB, /* 0 */
97
-	PB,
98
-	PB,
99
-	PB,
100
-	PB,
101
-	PB,
102
-	PB,
103
-	PB,
104
-	PD, /* 8 */
536
+const uint16_t PROGMEM port_to_input_PGM[] = {
537
+	NOT_A_PORT,
538
+	NOT_A_PORT,
539
+	&PINB,
540
+	&PINC,
541
+	&PIND,
542
+};
543
+
544
+const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
545
+	PD, /* 0 */
105 546
 	PD,
106 547
 	PD,
107 548
 	PD,
@@ -109,27 +550,22 @@ const uint8_t PROGMEM digital_pin_to_port_PGM[] =
109 550
 	PD,
110 551
 	PD,
111 552
 	PD,
112
-	PC, /* 16 */
113
-	PC,
553
+	PB, /* 8 */
554
+	PB,
555
+	PB,
556
+	PB,
557
+	PB,
558
+	PB,
559
+	PC, /* 14 */
114 560
 	PC,
115 561
 	PC,
116 562
 	PC,
117 563
 	PC,
118
-   	PC,
119 564
 	PC,
120
-	PA, /* 24 */
121
-	PA,
122
-	PA,
123
-	PA,
124
-	PA,
125
-	PA,
126
-	PA,
127
-	PA  /* 31 */
128 565
 };
129 566
 
130
-const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
131
-{
132
-	_BV(0), /* 0, port B */
567
+const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
568
+	_BV(0), /* 0, port D */
133 569
 	_BV(1),
134 570
 	_BV(2),
135 571
 	_BV(3),
@@ -137,64 +573,55 @@ const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
137 573
 	_BV(5),
138 574
 	_BV(6),
139 575
 	_BV(7),
140
-	_BV(0), /* 8, port D */
576
+	_BV(0), /* 8, port B */
141 577
 	_BV(1),
142 578
 	_BV(2),
143 579
 	_BV(3),
144 580
 	_BV(4),
145 581
 	_BV(5),
146
-	_BV(6),
147
-	_BV(7),
148
-	_BV(0), /* 16, port C */
582
+	_BV(0), /* 14, port C */
149 583
 	_BV(1),
150 584
 	_BV(2),
151 585
 	_BV(3),
152 586
 	_BV(4),
153 587
 	_BV(5),
154
-	_BV(6),
155
-	_BV(7),
156
-	_BV(7), /* 24, port A */
157
-	_BV(6),
158
-	_BV(5),
159
-	_BV(4),
160
-	_BV(3),
161
-	_BV(2),
162
-	_BV(1),
163
-	_BV(0)
164 588
 };
165 589
 
166
-const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
167
-{
168
-	NOT_ON_TIMER, 	/* 0  - PB0 */
169
-	NOT_ON_TIMER, 	/* 1  - PB1 */
170
-	NOT_ON_TIMER, 	/* 2  - PB2 */
171
-	TIMER0A,     	/* 3  - PB3 */
172
-	TIMER0B, 		/* 4  - PB4 */
173
-	NOT_ON_TIMER, 	/* 5  - PB5 */
174
-	NOT_ON_TIMER, 	/* 6  - PB6 */
175
-	NOT_ON_TIMER,	/* 7  - PB7 */
176
-	NOT_ON_TIMER, 	/* 8  - PD0 */
177
-	NOT_ON_TIMER, 	/* 9  - PD1 */
178
-	NOT_ON_TIMER, 	/* 10 - PD2 */
179
-	NOT_ON_TIMER, 	/* 11 - PD3 */
180
-	TIMER1B,     	/* 12 - PD4 */
181
-	TIMER1A,     	/* 13 - PD5 */
182
-	TIMER2B,     	/* 14 - PD6 */
183
-	TIMER2A,     	/* 15 - PD7 */
184
-	NOT_ON_TIMER, 	/* 16 - PC0 */
185
-	NOT_ON_TIMER,   /* 17 - PC1 */
186
-	NOT_ON_TIMER,   /* 18 - PC2 */
187
-	NOT_ON_TIMER,   /* 19 - PC3 */
188
-	NOT_ON_TIMER,   /* 20 - PC4 */
189
-	NOT_ON_TIMER,   /* 21 - PC5 */
190
-	NOT_ON_TIMER,   /* 22 - PC6 */
191
-	NOT_ON_TIMER,   /* 23 - PC7 */
192
-	NOT_ON_TIMER,   /* 24 - PA0 */
193
-	NOT_ON_TIMER,   /* 25 - PA1 */
194
-	NOT_ON_TIMER,   /* 26 - PA2 */
195
-	NOT_ON_TIMER,   /* 27 - PA3 */
196
-	NOT_ON_TIMER,   /* 28 - PA4 */
197
-	NOT_ON_TIMER,   /* 29 - PA5 */
198
-	NOT_ON_TIMER,   /* 30 - PA6 */
199
-	NOT_ON_TIMER   /* 31 - PA7 */
590
+const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
591
+	NOT_ON_TIMER, /* 0 - port D */
592
+	NOT_ON_TIMER,
593
+	NOT_ON_TIMER,
594
+	// on the ATmega168, digital pin 3 has hardware pwm
595
+#if defined(__AVR_ATmega8__)
596
+	NOT_ON_TIMER,
597
+#else
598
+	TIMER2B,
599
+#endif
600
+	NOT_ON_TIMER,
601
+	// on the ATmega168, digital pins 5 and 6 have hardware pwm
602
+#if defined(__AVR_ATmega8__)
603
+	NOT_ON_TIMER,
604
+	NOT_ON_TIMER,
605
+#else
606
+	TIMER0B,
607
+	TIMER0A,
608
+#endif
609
+	NOT_ON_TIMER,
610
+	NOT_ON_TIMER, /* 8 - port B */
611
+	TIMER1A,
612
+	TIMER1B,
613
+#if defined(__AVR_ATmega8__)
614
+	TIMER2,
615
+#else
616
+	TIMER2A,
617
+#endif
618
+	NOT_ON_TIMER,
619
+	NOT_ON_TIMER,
620
+	NOT_ON_TIMER,
621
+	NOT_ON_TIMER, /* 14 - port C */
622
+	NOT_ON_TIMER,
623
+	NOT_ON_TIMER,
624
+	NOT_ON_TIMER,
625
+	NOT_ON_TIMER,
200 626
 };
627
+#endif

+ 32
- 8
ArduinoAddons/Arduino_0.xx/Sanguino/cores/arduino/pins_arduino.h View File

@@ -39,19 +39,43 @@
39 39
 #define TIMER2A 6
40 40
 #define TIMER2B 7
41 41
 
42
+#define TIMER3A 8
43
+#define TIMER3B 9
44
+#define TIMER3C 10
45
+#define TIMER4A 11
46
+#define TIMER4B 12
47
+#define TIMER4C 13
48
+#define TIMER5A 14
49
+#define TIMER5B 15
50
+#define TIMER5C 16
51
+
52
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
53
+const static uint8_t SS   = 53;
54
+const static uint8_t MOSI = 51;
55
+const static uint8_t MISO = 50;
56
+const static uint8_t SCK  = 52;
57
+#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
42 58
 const static uint8_t SS   = 4;
43 59
 const static uint8_t MOSI = 5;
44 60
 const static uint8_t MISO = 6;
45 61
 const static uint8_t SCK  = 7;
46 62
 
47
-extern const uint8_t PROGMEM port_to_mode_PGM[];
48
-extern const uint8_t PROGMEM port_to_input_PGM[];
49
-extern const uint8_t PROGMEM port_to_output_PGM[];
63
+#else
64
+const static uint8_t SS   = 10;
65
+const static uint8_t MOSI = 11;
66
+const static uint8_t MISO = 12;
67
+const static uint8_t SCK  = 13;
68
+#endif
69
+
70
+// On the ATmega1280, the addresses of some of the port registers are
71
+// greater than 255, so we can't store them in uint8_t's.
72
+extern const uint16_t PROGMEM port_to_mode_PGM[];
73
+extern const uint16_t PROGMEM port_to_input_PGM[];
74
+extern const uint16_t PROGMEM port_to_output_PGM[];
50 75
 
51 76
 extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
52
-extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
77
+// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
53 78
 extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
54
-
55 79
 extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
56 80
 
57 81
 // Get the bit location within the hardware port of the given virtual pin.
@@ -63,8 +87,8 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
63 87
 #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
64 88
 #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
65 89
 #define analogInPinToBit(P) (P)
66
-#define portOutputRegister(P) ( (volatile uint8_t *)( (uint16_t) pgm_read_byte( port_to_output_PGM + (P))) )
67
-#define portInputRegister(P) ( (volatile uint8_t *)( (uint16_t) pgm_read_byte( port_to_input_PGM + (P))) )
68
-#define portModeRegister(P) ( (volatile uint8_t *)( (uint16_t) pgm_read_byte( port_to_mode_PGM + (P))) )
90
+#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
91
+#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
92
+#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
69 93
 
70 94
 #endif

+ 4
- 2
ArduinoAddons/Arduino_0.xx/Sanguino/cores/arduino/wiring.h View File

@@ -25,7 +25,6 @@
25 25
 #ifndef Wiring_h
26 26
 #define Wiring_h
27 27
 
28
-#include <math.h>
29 28
 #include <avr/io.h>
30 29
 #include <stdlib.h>
31 30
 #include "binary.h"
@@ -77,7 +76,10 @@ extern "C"{
77 76
 #define max(a,b) ((a)>(b)?(a):(b))
78 77
 #define abs(x) ((x)>0?(x):-(x))
79 78
 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
80
-#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
79
+
80
+// Removed to work with newer AVRLIBC
81
+//#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
82
+
81 83
 #define radians(deg) ((deg)*DEG_TO_RAD)
82 84
 #define degrees(rad) ((rad)*RAD_TO_DEG)
83 85
 #define sq(x) ((x)*(x))

+ 4
- 2
ArduinoAddons/Arduino_0.xx/Sanguino/cores/arduino/wiring_private.h View File

@@ -24,10 +24,10 @@
24 24
 
25 25
 #ifndef WiringPrivate_h
26 26
 #define WiringPrivate_h
27
-#include <math.h>
27
+
28 28
 #include <avr/io.h>
29 29
 #include <avr/interrupt.h>
30
-#include <util/delay.h>
30
+#include <avr/delay.h>
31 31
 #include <stdio.h>
32 32
 #include <stdarg.h>
33 33
 
@@ -55,6 +55,8 @@ extern "C"{
55 55
 
56 56
 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
57 57
 #define EXTERNAL_NUM_INTERRUPTS 8
58
+#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
59
+#define EXTERNAL_NUM_INTERRUPTS 3
58 60
 #else
59 61
 #define EXTERNAL_NUM_INTERRUPTS 2
60 62
 #endif

Loading…
Cancel
Save