Skip to content

Instantly share code, notes, and snippets.

@JChristensen
Created May 2, 2014 18:59
Show Gist options
  • Save JChristensen/764bfde7ff82c1062659 to your computer and use it in GitHub Desktop.
Save JChristensen/764bfde7ff82c1062659 to your computer and use it in GitHub Desktop.
Changes made to the Arduino 1.0 core files for maniacbug's mighty-1284p core.
diff --git a/arduino-1.0/hardware/arduino/cores/arduino/Arduino.h b/mighty-1284p/cores/standard/Arduino.h
index ebd374a..2e35a35 100644
--- a/arduino-1.0/hardware/arduino/cores/arduino/Arduino.h
+++ b/mighty-1284p/cores/standard/Arduino.h
@@ -45,7 +45,7 @@ extern "C"{
#define EXTERNAL 1
#define INTERNAL 2
#else
-#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__)
#define INTERNAL1V1 2
#define INTERNAL2V56 3
#else
@@ -123,14 +123,14 @@ void loop(void);
// On the ATmega1280, the addresses of some of the port registers are
// greater than 255, so we can't store them in uint8_t's.
-extern const uint16_t PROGMEM port_to_mode_PGM[];
-extern const uint16_t PROGMEM port_to_input_PGM[];
-extern const uint16_t PROGMEM port_to_output_PGM[];
+extern const uint16_t port_to_mode_PGM[];
+extern const uint16_t port_to_input_PGM[];
+extern const uint16_t port_to_output_PGM[];
-extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
-// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
-extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
-extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
+extern const uint8_t digital_pin_to_port_PGM[];
+// extern const uint8_t digital_pin_to_bit_PGM[];
+extern const uint8_t digital_pin_to_bit_mask_PGM[];
+extern const uint8_t digital_pin_to_timer_PGM[];
// Get the bit location within the hardware port of the given virtual pin.
// This comes from the pins_*.c file for the active board configuration.
@@ -211,4 +211,4 @@ long map(long, long, long, long, long);
#include "pins_arduino.h"
-#endif
\ No newline at end of file
+#endif
diff --git a/arduino-1.0/hardware/arduino/cores/arduino/Print.cpp b/mighty-1284p/cores/standard/Print.cpp
index ff9b154..4b9f59d 100644
--- a/arduino-1.0/hardware/arduino/cores/arduino/Print.cpp
+++ b/mighty-1284p/cores/standard/Print.cpp
@@ -41,7 +41,7 @@ size_t Print::write(const uint8_t *buffer, size_t size)
size_t Print::print(const __FlashStringHelper *ifsh)
{
- const prog_char *p = (const prog_char *)ifsh;
+ const char *p = (const char *)ifsh;
size_t n = 0;
while (1) {
unsigned char c = pgm_read_byte(p++);
diff --git a/arduino-1.0/hardware/arduino/cores/arduino/WInterrupts.c b/mighty-1284p/cores/standard/WInterrupts.c
index 75c713b..3b9fe08 100644
--- a/arduino-1.0/hardware/arduino/cores/arduino/WInterrupts.c
+++ b/mighty-1284p/cores/standard/WInterrupts.c
@@ -32,7 +32,7 @@
#include "wiring_private.h"
-volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
+static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
// volatile static voidFuncPtr twiIntFunc;
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
@@ -110,6 +110,19 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
#warning attachInterrupt may need some more work for this cpu (case 1)
#endif
break;
+
+ case 2:
+ #if defined(EICRA) && defined(ISC20) && defined(ISC21) && defined(EIMSK)
+ EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
+ EIMSK |= (1 << INT2);
+ #elif defined(MCUCR) && defined(ISC20) && defined(ISC21) && defined(GICR)
+ MCUCR = (MCUCR & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
+ GICR |= (1 << INT2);
+ #elif defined(MCUCR) && defined(ISC20) && defined(GIMSK) && defined(GIMSK)
+ MCUCR = (MCUCR & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
+ GIMSK |= (1 << INT2);
+ #endif
+ break;
#endif
}
}
@@ -237,6 +250,13 @@ SIGNAL(INT1_vect) {
intFunc[EXTERNAL_INT_1]();
}
+#if defined(EICRA) && defined(ISC20)
+SIGNAL(INT2_vect) {
+ if(intFunc[EXTERNAL_INT_2])
+ intFunc[EXTERNAL_INT_2]();
+}
+#endif
+
#endif
/*
diff --git a/arduino-1.0/hardware/arduino/cores/arduino/WString.cpp b/mighty-1284p/cores/standard/WString.cpp
index 3e81331..c6839fc 100644
--- a/arduino-1.0/hardware/arduino/cores/arduino/WString.cpp
+++ b/mighty-1284p/cores/standard/WString.cpp
@@ -500,7 +500,7 @@ int String::lastIndexOf( char theChar ) const
int String::lastIndexOf(char ch, unsigned int fromIndex) const
{
- if (fromIndex >= len || fromIndex < 0) return -1;
+ if (fromIndex >= len) return -1;
char tempchar = buffer[fromIndex + 1];
buffer[fromIndex + 1] = '\0';
char* temp = strrchr( buffer, ch );
@@ -516,7 +516,7 @@ int String::lastIndexOf(const String &s2) const
int String::lastIndexOf(const String &s2, unsigned int fromIndex) const
{
- if (s2.len == 0 || len == 0 || s2.len > len || fromIndex < 0) return -1;
+ if (s2.len == 0 || len == 0 || s2.len > len) return -1;
if (fromIndex >= len) fromIndex = len - 1;
int found = -1;
for (char *p = buffer; p <= buffer + fromIndex; p++) {
diff --git a/arduino-1.0/hardware/arduino/cores/arduino/WString.h b/mighty-1284p/cores/standard/WString.h
index d76d2a3..947325e 100644
--- a/arduino-1.0/hardware/arduino/cores/arduino/WString.h
+++ b/mighty-1284p/cores/standard/WString.h
@@ -35,7 +35,7 @@
// -std=c++0x
class __FlashStringHelper;
-#define F(string_literal) (reinterpret_cast<__FlashStringHelper *>(PSTR(string_literal)))
+#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
// An inherited class for holding the result of a concatenation. These
// result objects are assumed to be writable by subsequent concatenations.
diff --git a/arduino-1.0/hardware/arduino/cores/arduino/wiring_analog.c b/mighty-1284p/cores/standard/wiring_analog.c
index 902b153..55e1cc5 100644
--- a/arduino-1.0/hardware/arduino/cores/arduino/wiring_analog.c
+++ b/mighty-1284p/cores/standard/wiring_analog.c
@@ -41,28 +41,31 @@ int analogRead(uint8_t pin)
{
uint8_t low, high;
-#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
- if (pin >= 54) pin -= 54; // allow for channel or pin numbers
-#elif defined(__AVR_ATmega32U4__)
- if (pin >= 18) pin -= 18; // allow for channel or pin numbers
+// allow for channel or pin numbers
+#if defined(digitalPinToAnalogPin)
+ if (digitalPinToAnalogPin(pin) != -1 )
+ pin = digitalPinToAnalogPin(pin);
#else
- if (pin >= 14) pin -= 14; // allow for channel or pin numbers
+ if (pin >= A0) pin -= A0;
#endif
-#if defined(__AVR_ATmega32U4__)
- pin = analogPinToChannel(pin);
- ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
-#elif defined(ADCSRB) && defined(MUX5)
+#if defined(analogPinToChannel)
+ uint8_t channel = analogPinToChannel(pin);
+#else
+ uint8_t channel = pin;
+#endif
+
+#if defined(ADCSRB) && defined(MUX5)
// the MUX5 bit of ADCSRB selects whether we're reading from channels
// 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high).
- ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
+ ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((channel >> 3) & 0x01) << MUX5);
#endif
// set the analog reference (high two bits of ADMUX) and select the
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
// to 0 (the default).
#if defined(ADMUX)
- ADMUX = (analog_reference << 6) | (pin & 0x07);
+ ADMUX = (analog_reference << 6) | (channel & 0x07);
#endif
// without a delay, we seem to read from the wrong channel
diff --git a/arduino-1.0/hardware/arduino/cores/arduino/wiring_private.h b/mighty-1284p/cores/standard/wiring_private.h
index 41d1d40..f0ceb0c 100644
--- a/arduino-1.0/hardware/arduino/cores/arduino/wiring_private.h
+++ b/mighty-1284p/cores/standard/wiring_private.h
@@ -54,6 +54,8 @@ extern "C"{
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define EXTERNAL_NUM_INTERRUPTS 8
+#elif defined(__AVR_ATmega1284P__)
+#define EXTERNAL_NUM_INTERRUPTS 3
#else
#define EXTERNAL_NUM_INTERRUPTS 2
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment