diff options
Diffstat (limited to 'cores')
| -rw-r--r-- | cores/arduino/Arduino.h | 19 | ||||
| -rw-r--r-- | cores/arduino/Stream.cpp | 1 | ||||
| -rw-r--r-- | cores/arduino/USBAPI.h | 2 | ||||
| -rw-r--r-- | cores/arduino/USBCore.cpp | 6 | ||||
| -rw-r--r-- | cores/arduino/USBCore.h | 5 | ||||
| -rw-r--r-- | cores/arduino/WInterrupts.c | 85 | ||||
| -rw-r--r-- | cores/arduino/WString.cpp | 2 | ||||
| -rw-r--r-- | cores/arduino/new.cpp | 5 | ||||
| -rw-r--r-- | cores/arduino/new.h | 1 | ||||
| -rw-r--r-- | cores/arduino/wiring_shift.c | 11 | 
10 files changed, 106 insertions, 31 deletions
| diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 09c1448..91eeb16 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -111,7 +111,8 @@ void yield(void);  #define bitRead(value, bit) (((value) >> (bit)) & 0x01)  #define bitSet(value, bit) ((value) |= (1UL << (bit)))  #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) -#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) +#define bitToggle(value, bit) ((value) ^= (1UL << (bit))) +#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))  // avr-libc defines _NOP() since 1.6.2  #ifndef _NOP @@ -130,16 +131,16 @@ void initVariant(void);  int atexit(void (*func)()) __attribute__((weak)); -void pinMode(uint8_t, uint8_t); -void digitalWrite(uint8_t, uint8_t); -int digitalRead(uint8_t); -int analogRead(uint8_t); +void pinMode(uint8_t pin, uint8_t mode); +void digitalWrite(uint8_t pin, uint8_t val); +int digitalRead(uint8_t pin); +int analogRead(uint8_t pin);  void analogReference(uint8_t mode); -void analogWrite(uint8_t, int); +void analogWrite(uint8_t pin, int val);  unsigned long millis(void);  unsigned long micros(void); -void delay(unsigned long); +void delay(unsigned long ms);  void delayMicroseconds(unsigned int us);  unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);  unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); @@ -147,8 +148,8 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);  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 interruptNum, void (*userFunc)(void), int mode); +void detachInterrupt(uint8_t interruptNum);  void setup(void);  void loop(void); diff --git a/cores/arduino/Stream.cpp b/cores/arduino/Stream.cpp index d284631..9eff663 100644 --- a/cores/arduino/Stream.cpp +++ b/cores/arduino/Stream.cpp @@ -218,7 +218,6 @@ size_t Stream::readBytes(char *buffer, size_t length)  size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)  { -  if (length < 1) return 0;    size_t index = 0;    while (index < length) {      int c = timedRead(); diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 0f7d171..47221b8 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -66,6 +66,8 @@ public:  	void detach();	// Serial port goes down too...  	void poll();  	bool wakeupHost(); // returns false, when wakeup cannot be processed + +	bool isSuspended();  };  extern USBDevice_ USBDevice; diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index 6e820a1..b384984 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -825,4 +825,10 @@ bool USBDevice_::wakeupHost()  	return false;  } +bool USBDevice_::isSuspended() +{ +	return (_usbSuspendState & (1 << SUSPI)); +} + +  #endif /* if defined(USBCON) */ diff --git a/cores/arduino/USBCore.h b/cores/arduino/USBCore.h index eafdbe5..578e1b8 100644 --- a/cores/arduino/USBCore.h +++ b/cores/arduino/USBCore.h @@ -87,6 +87,9 @@  // bMaxPower in Configuration Descriptor  #define USB_CONFIG_POWER_MA(mA)                ((mA)/2) +#ifndef USB_CONFIG_POWER + #define USB_CONFIG_POWER                      (500) +#endif  // bEndpointAddress in Endpoint Descriptor  #define USB_ENDPOINT_DIRECTION_MASK            0x80 @@ -166,7 +169,7 @@ typedef struct  	{ 18, 1, USB_VERSION, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }  #define D_CONFIG(_totalLength,_interfaces) \ -	{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED | USB_CONFIG_REMOTE_WAKEUP, USB_CONFIG_POWER_MA(500) } +	{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED | USB_CONFIG_REMOTE_WAKEUP, USB_CONFIG_POWER_MA(USB_CONFIG_POWER) }  #define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \  	{ 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 } diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c index cef1106..38ea158 100644 --- a/cores/arduino/WInterrupts.c +++ b/cores/arduino/WInterrupts.c @@ -65,7 +65,6 @@ static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS] = {      nothing,  #endif  }; -// volatile static voidFuncPtr twiIntFunc;  void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {    if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { @@ -103,6 +102,39 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {          EICRB = (EICRB & ~((1<<ISC60) | (1<<ISC61))) | (mode << ISC60);          EIMSK |= (1<<INT6);          break; +#elif defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__) +    case 0: +      EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); +      EIMSK |= (1 << INT0); +      break; +    case 1: +      EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); +      EIMSK |= (1 << INT1); +      break; +    case 2: +      EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20); +      EIMSK |= (1 << INT2); +      break; +    case 3: +      EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30); +      EIMSK |= (1 << INT3); +      break; +    case 4: +      EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40); +      EIMSK |= (1 << INT4); +      break; +    case 5: +      EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50); +      EIMSK |= (1 << INT5); +      break; +    case 6: +      EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60); +      EIMSK |= (1 << INT6); +      break; +    case 7: +      EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70); +      EIMSK |= (1 << INT7); +      break;  #elif defined(EICRA) && defined(EICRB) && defined(EIMSK)      case 2:        EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); @@ -205,7 +237,32 @@ void detachInterrupt(uint8_t interruptNum) {          break;	      case 4:          EIMSK &= ~(1<<INT6); -        break;	 +        break; +#elif defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__) +    case 0: +      EIMSK &= ~(1 << INT0); +      break; +    case 1: +      EIMSK &= ~(1 << INT1); +      break; +    case 2: +      EIMSK &= ~(1 << INT2); +      break; +    case 3: +      EIMSK &= ~(1 << INT3); +      break; +    case 4: +      EIMSK &= ~(1 << INT4); +      break; +    case 5: +      EIMSK &= ~(1 << INT5); +      break; +    case 6: +      EIMSK &= ~(1 << INT6); +      break; +    case 7: +      EIMSK &= ~(1 << INT7); +      break;  #elif defined(EICRA) && defined(EICRB) && defined(EIMSK)      case 2:        EIMSK &= ~(1 << INT0); @@ -274,11 +331,6 @@ void detachInterrupt(uint8_t interruptNum) {    }  } -/* -void attachInterruptTwi(void (*userFunc)(void) ) { -  twiIntFunc = userFunc; -} -*/  #define IMPLEMENT_ISR(vect, interrupt) \    ISR(vect) { \ @@ -293,6 +345,17 @@ IMPLEMENT_ISR(INT2_vect, EXTERNAL_INT_2)  IMPLEMENT_ISR(INT3_vect, EXTERNAL_INT_3)  IMPLEMENT_ISR(INT6_vect, EXTERNAL_INT_4) +#elif defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__) + +IMPLEMENT_ISR(INT0_vect, EXTERNAL_INT_0) +IMPLEMENT_ISR(INT1_vect, EXTERNAL_INT_1) +IMPLEMENT_ISR(INT2_vect, EXTERNAL_INT_2) +IMPLEMENT_ISR(INT3_vect, EXTERNAL_INT_3) +IMPLEMENT_ISR(INT4_vect, EXTERNAL_INT_4) +IMPLEMENT_ISR(INT5_vect, EXTERNAL_INT_5) +IMPLEMENT_ISR(INT6_vect, EXTERNAL_INT_6) +IMPLEMENT_ISR(INT7_vect, EXTERNAL_INT_7) +  #elif defined(EICRA) && defined(EICRB)  IMPLEMENT_ISR(INT0_vect, EXTERNAL_INT_2) @@ -314,11 +377,3 @@ IMPLEMENT_ISR(INT2_vect, EXTERNAL_INT_2)  #endif  #endif - -/* -ISR(TWI_vect) { -  if(twiIntFunc) -    twiIntFunc(); -} -*/ - diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index f2572d6..043fda7 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -121,7 +121,7 @@ String::String(double value, unsigned char decimalPlaces)  String::~String()  { -	free(buffer); +	if (buffer) free(buffer);  }  /*********************************************/ diff --git a/cores/arduino/new.cpp b/cores/arduino/new.cpp index cf6f89c..fc30cf8 100644 --- a/cores/arduino/new.cpp +++ b/cores/arduino/new.cpp @@ -26,6 +26,11 @@ void *operator new[](size_t size) {    return malloc(size);  } +void * operator new(size_t size, void * ptr) noexcept { +  (void)size; +  return ptr; +} +  void operator delete(void * ptr) {    free(ptr);  } diff --git a/cores/arduino/new.h b/cores/arduino/new.h index 6e1b68f..763f5cc 100644 --- a/cores/arduino/new.h +++ b/cores/arduino/new.h @@ -23,6 +23,7 @@  void * operator new(size_t size);  void * operator new[](size_t size); +void * operator new(size_t size, void * ptr) noexcept;  void operator delete(void * ptr);  void operator delete[](void * ptr); diff --git a/cores/arduino/wiring_shift.c b/cores/arduino/wiring_shift.c index 2b6f7a8..a9b3be5 100644 --- a/cores/arduino/wiring_shift.c +++ b/cores/arduino/wiring_shift.c @@ -42,10 +42,13 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)  	uint8_t i;  	for (i = 0; i < 8; i++)  { -		if (bitOrder == LSBFIRST) -			digitalWrite(dataPin, !!(val & (1 << i))); -		else	 -			digitalWrite(dataPin, !!(val & (1 << (7 - i)))); +		if (bitOrder == LSBFIRST) { +			digitalWrite(dataPin, val & 1); +			val >>= 1; +		} else {	 +			digitalWrite(dataPin, (val & 128) != 0); +			val <<= 1; +		}  		digitalWrite(clockPin, HIGH);  		digitalWrite(clockPin, LOW);		 | 
