From 1595002fcefa092d16d6367826d7843e7c5c0edd Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 23 Nov 2018 01:55:10 +0100 Subject: extended ardiuno stub --- contrib/radiohead.patch | 4 +- lib/Arduino.h | 27 +++++- lib/arduino-minimal.h | 62 ------------ lib/arduino-stub.cpp | 248 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 274 insertions(+), 67 deletions(-) delete mode 100644 lib/arduino-minimal.h diff --git a/contrib/radiohead.patch b/contrib/radiohead.patch index e844a0a..4f9939f 100644 --- a/contrib/radiohead.patch +++ b/contrib/radiohead.patch @@ -1,6 +1,6 @@ diff -Nur RadioHead.orig/RadioHead.h RadioHead/RadioHead.h --- RadioHead.orig/RadioHead.h 2018-11-15 02:40:23.000000000 +0100 -+++ RadioHead/RadioHead.h 2018-11-22 02:28:56.058105167 +0100 ++++ RadioHead/RadioHead.h 2018-11-23 01:50:55.920760834 +0100 @@ -317,8 +317,6 @@ cd /tmp mkdir RadioHead @@ -20,7 +20,7 @@ diff -Nur RadioHead.orig/RadioHead.h RadioHead/RadioHead.h #include #define RH_HAVE_HARDWARE_SPI #include -+ #include ++ #include // For Steve Childress port to ARM M4 w/CMSIS with STM's Hardware Abstraction lib. // See ArduinoWorkarounds.h (not supplied) diff --git a/lib/Arduino.h b/lib/Arduino.h index 3698392..ac7031d 100644 --- a/lib/Arduino.h +++ b/lib/Arduino.h @@ -143,8 +143,8 @@ void delayMicroseconds(unsigned int us); // void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); // uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); -// void attachInterrupt(uint8_t, void (*)(void), int mode); -// void detachInterrupt(uint8_t); +void attachInterrupt(uint8_t, void (*)(void), int mode); +void detachInterrupt(uint8_t); // 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. @@ -215,6 +215,29 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; #define TIMER5B 17 #define TIMER5C 18 + +#define EXTERNAL_INT_0 0 +#define EXTERNAL_INT_1 1 +#define EXTERNAL_INT_2 2 +#define EXTERNAL_INT_3 3 +#define EXTERNAL_INT_4 4 +#define EXTERNAL_INT_5 5 +#define EXTERNAL_INT_6 6 +#define EXTERNAL_INT_7 7 + +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__) || \ + defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__) +#define EXTERNAL_NUM_INTERRUPTS 8 +#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) +#define EXTERNAL_NUM_INTERRUPTS 3 +#elif defined(__AVR_ATmega32U4__) +#define EXTERNAL_NUM_INTERRUPTS 5 +#else +#define EXTERNAL_NUM_INTERRUPTS 2 +#endif + +typedef void (*voidFuncPtr)(void); + #ifdef __cplusplus } // extern "C" #endif diff --git a/lib/arduino-minimal.h b/lib/arduino-minimal.h deleted file mode 100644 index fcac3ab..0000000 --- a/lib/arduino-minimal.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * spreadspace avr utils - * - * - * Copyright (C) 2013-2018 Christian Pointner - * - * This file is part of spreadspace avr utils. - * - * spreadspace avr utils is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * spreadspace avr utils is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with spreadspace avr utils. If not, see . - */ - -#ifndef SPREADAVR_arduino_minimal_h_INCLUDED -#define SPREADAVR_arduino_minimal_h_INCLUDED - -#ifdef __cplusplus -extern "C"{ -#endif - -#define HIGH 0x1 -#define LOW 0x0 - -#define INPUT 0x0 -#define OUTPUT 0x1 -#define INPUT_PULLUP 0x2 - -#define CHANGE 1 -#define FALLING 2 -#define RISING 3 - -unsigned long millis(void); -void delay(unsigned long); - -void pinMode(uint8_t, uint8_t); -void digitalWrite(uint8_t, uint8_t); -// int digitalRead(uint8_t); -// int analogRead(uint8_t); -// void analogReference(uint8_t mode); -// void analogWrite(uint8_t, int); - -void attachInterrupt(uint8_t, void (*)(void), int mode); -//void detachInterrupt(uint8_t); - -#ifdef __cplusplus -} // extern "C" -#endif - -// WMath prototypes -long random(long); -long random(long, long); - -#endif diff --git a/lib/arduino-stub.cpp b/lib/arduino-stub.cpp index d848e8d..c130a45 100644 --- a/lib/arduino-stub.cpp +++ b/lib/arduino-stub.cpp @@ -329,7 +329,7 @@ void init() * real cooperative scheduler. */ static void __empty() { - // Empty + // Empty } void yield(void) __attribute__ ((weak, alias("__empty"))); @@ -761,6 +761,252 @@ void analogWrite(uint8_t pin, int val) } } +// ****************** +// this is from Arduino's WInterrupts.c + +static void nothing(void) { +} + +static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS] = { +#if EXTERNAL_NUM_INTERRUPTS > 8 + #warning There are more than 8 external interrupts. Some callbacks may not be initialized. + nothing, +#endif +#if EXTERNAL_NUM_INTERRUPTS > 7 + nothing, +#endif +#if EXTERNAL_NUM_INTERRUPTS > 6 + nothing, +#endif +#if EXTERNAL_NUM_INTERRUPTS > 5 + nothing, +#endif +#if EXTERNAL_NUM_INTERRUPTS > 4 + nothing, +#endif +#if EXTERNAL_NUM_INTERRUPTS > 3 + nothing, +#endif +#if EXTERNAL_NUM_INTERRUPTS > 2 + nothing, +#endif +#if EXTERNAL_NUM_INTERRUPTS > 1 + nothing, +#endif +#if EXTERNAL_NUM_INTERRUPTS > 0 + nothing, +#endif +}; +// volatile static voidFuncPtr twiIntFunc; + +void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { + if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { + intFunc[interruptNum] = userFunc; + + // Configure the interrupt mode (trigger on low input, any change, rising + // edge, or falling edge). The mode constants were chosen to correspond + // to the configuration bits in the hardware register, so we simply shift + // the mode into place. + + // Enable the interrupt. + + switch (interruptNum) { +#if defined(__AVR_ATmega32U4__) + // I hate doing this, but the register assignment differs between the 1280/2560 + // and the 32U4. Since avrlib defines registers PCMSK1 and PCMSK2 that aren't + // even present on the 32U4 this is the only way to distinguish between them. + case 0: + EICRA = (EICRA & ~((1<