From 6ad770e86f2758995ed8730505c9ae165ed8ef59 Mon Sep 17 00:00:00 2001 From: Andreas Watterott Date: Mon, 13 Nov 2017 12:49:06 +0100 Subject: No fixed value for USB power current. --- cores/arduino/USBCore.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cores') diff --git a/cores/arduino/USBCore.h b/cores/arduino/USBCore.h index 18560b6..5e0c7b3 100644 --- a/cores/arduino/USBCore.h +++ b/cores/arduino/USBCore.h @@ -97,6 +97,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 @@ -267,7 +270,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 } -- cgit v1.2.3-18-g5258 From 0c5aa78ff40d208a1341b3dae84166e837901070 Mon Sep 17 00:00:00 2001 From: Shriramana Sharma Date: Sat, 11 Aug 2018 11:11:01 +0530 Subject: Add `bitToggle` macro to complement `bitSet` etc --- cores/arduino/Arduino.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cores') diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 09c1448..808ff19 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -111,6 +111,7 @@ 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 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 -- cgit v1.2.3-18-g5258 From c6ce36d56cd5e874e60c3ba8a36cc77c307df718 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Sat, 18 Aug 2018 09:09:15 +0100 Subject: Add placement new operator --- cores/arduino/new.cpp | 4 ++++ cores/arduino/new.h | 1 + 2 files changed, 5 insertions(+) (limited to 'cores') diff --git a/cores/arduino/new.cpp b/cores/arduino/new.cpp index cf6f89c..bfb219d 100644 --- a/cores/arduino/new.cpp +++ b/cores/arduino/new.cpp @@ -26,6 +26,10 @@ void *operator new[](size_t size) { return malloc(size); } +void * operator new(size_t size, void * ptr) { + return ptr; +} + void operator delete(void * ptr) { free(ptr); } diff --git a/cores/arduino/new.h b/cores/arduino/new.h index 6e1b68f..7690911 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); void operator delete(void * ptr); void operator delete[](void * ptr); -- cgit v1.2.3-18-g5258 From b410611ffcdcb822d69c828f01dd6216c1ef3348 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Sat, 18 Aug 2018 09:27:06 +0100 Subject: Prevent possible compiler warning Casting to void is a well known trick for prevening 'unused parameter' warnings. --- cores/arduino/new.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'cores') diff --git a/cores/arduino/new.cpp b/cores/arduino/new.cpp index bfb219d..86a1fa5 100644 --- a/cores/arduino/new.cpp +++ b/cores/arduino/new.cpp @@ -27,6 +27,7 @@ void *operator new[](size_t size) { } void * operator new(size_t size, void * ptr) { + (void)size; return ptr; } -- cgit v1.2.3-18-g5258 From 6a717473175cc7d900fe67bc071f7e7c72f01e29 Mon Sep 17 00:00:00 2001 From: Pharap <2933055+Pharap@users.noreply.github.com> Date: Fri, 26 Oct 2018 19:34:34 +0100 Subject: Add noexcept specifier to placement new operator The standard mandates that placement new should be have a noexcept specifier. --- cores/arduino/new.cpp | 2 +- cores/arduino/new.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'cores') diff --git a/cores/arduino/new.cpp b/cores/arduino/new.cpp index 86a1fa5..fc30cf8 100644 --- a/cores/arduino/new.cpp +++ b/cores/arduino/new.cpp @@ -26,7 +26,7 @@ void *operator new[](size_t size) { return malloc(size); } -void * operator new(size_t size, void * ptr) { +void * operator new(size_t size, void * ptr) noexcept { (void)size; return ptr; } diff --git a/cores/arduino/new.h b/cores/arduino/new.h index 7690911..763f5cc 100644 --- a/cores/arduino/new.h +++ b/cores/arduino/new.h @@ -23,7 +23,7 @@ void * operator new(size_t size); void * operator new[](size_t size); -void * operator new(size_t size, void * ptr); +void * operator new(size_t size, void * ptr) noexcept; void operator delete(void * ptr); void operator delete[](void * ptr); -- cgit v1.2.3-18-g5258 From c87bc7ba9a94cbeca3b652ea068c4bdb38c76b6c Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 11 Dec 2018 00:01:57 +0100 Subject: Add USBDevice.isSuspended() Based on code originally by Rob van der Veer , this adds USBDevice.isSuspended(), so user sketches can run custom code in their `loop` methods after checking if the device is suspended or not. Signed-off-by: Gergely Nagy --- cores/arduino/USBAPI.h | 2 ++ cores/arduino/USBCore.cpp | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'cores') diff --git a/cores/arduino/USBAPI.h b/cores/arduino/USBAPI.h index 479ced9..701a14f 100644 --- a/cores/arduino/USBAPI.h +++ b/cores/arduino/USBAPI.h @@ -65,6 +65,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 81f689d..c0a4c7c 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -855,4 +855,10 @@ bool USBDevice_::wakeupHost() return false; } +bool USBDevice_::isSuspended() +{ + return (_usbSuspendState & (1 << SUSPI)); +} + + #endif /* if defined(USBCON) */ -- cgit v1.2.3-18-g5258 From c27aef0ed6638a635d92fcb97412dbd3e65e8c31 Mon Sep 17 00:00:00 2001 From: Paulo Costa Date: Fri, 4 Jan 2019 15:41:14 -0200 Subject: Remove commented out code for I2C interrupts on WInterrupts.c These are currently implemented by the Wire library, on twi.c --- cores/arduino/WInterrupts.c | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'cores') diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c index cef1106..ac72dda 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) { @@ -274,11 +273,6 @@ void detachInterrupt(uint8_t interruptNum) { } } -/* -void attachInterruptTwi(void (*userFunc)(void) ) { - twiIntFunc = userFunc; -} -*/ #define IMPLEMENT_ISR(vect, interrupt) \ ISR(vect) { \ @@ -314,11 +308,3 @@ IMPLEMENT_ISR(INT2_vect, EXTERNAL_INT_2) #endif #endif - -/* -ISR(TWI_vect) { - if(twiIntFunc) - twiIntFunc(); -} -*/ - -- cgit v1.2.3-18-g5258 From 8f752bf8c2785049eca2b546f8105ff856a06f48 Mon Sep 17 00:00:00 2001 From: "Paul R. Nash" Date: Mon, 21 Jan 2019 17:23:44 -0800 Subject: Add parameters names to common prototypes Putting the parameter names in these commonly used prototypes makes syntax help like VS Code's Intellisense work 99% more useful. Without them, it doesn't give you the names of the parameters and you have to remember the semantics yourself. :( --- cores/arduino/Arduino.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'cores') diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 09c1448..e178cf4 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -130,16 +130,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 +147,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); -- cgit v1.2.3-18-g5258 From 9e9f54d34dbab45e152d8163e048a879d736eedf Mon Sep 17 00:00:00 2001 From: David Madison Date: Sun, 17 Feb 2019 12:07:22 -0500 Subject: Define descriptor return var in pluggable block Avoids unused variable warning if USB is enabled but pluggable USB is not --- cores/arduino/USBCore.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'cores') diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index c0a4c7c..dc6bc38 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -496,14 +496,13 @@ bool SendConfiguration(int maxlen) static bool SendDescriptor(USBSetup& setup) { - int ret; u8 t = setup.wValueH; if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t) return SendConfiguration(setup.wLength); InitControl(setup.wLength); #ifdef PLUGGABLE_USB_ENABLED - ret = PluggableUSB().getDescriptor(setup); + int ret = PluggableUSB().getDescriptor(setup); if (ret != 0) { return (ret > 0 ? true : false); } -- cgit v1.2.3-18-g5258 From 649f978224d79947d679612e4bcb326280f4f963 Mon Sep 17 00:00:00 2001 From: luca Date: Fri, 26 Apr 2019 14:32:43 +0200 Subject: Minor optimization in shiftOut function --- cores/arduino/wiring_shift.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'cores') diff --git a/cores/arduino/wiring_shift.c b/cores/arduino/wiring_shift.c index 2b6f7a8..042a95a 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); + val <<= 1; + } digitalWrite(clockPin, HIGH); digitalWrite(clockPin, LOW); -- cgit v1.2.3-18-g5258 From 4d074e8a54d5395cafbb2c860f55304b329d83ab Mon Sep 17 00:00:00 2001 From: luca Date: Fri, 26 Apr 2019 20:21:27 +0200 Subject: Fixed shiftOut in MSBFIRST mode HIGH/LOW --- cores/arduino/wiring_shift.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores') diff --git a/cores/arduino/wiring_shift.c b/cores/arduino/wiring_shift.c index 042a95a..a9b3be5 100644 --- a/cores/arduino/wiring_shift.c +++ b/cores/arduino/wiring_shift.c @@ -46,7 +46,7 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) digitalWrite(dataPin, val & 1); val >>= 1; } else { - digitalWrite(dataPin, val & 128); + digitalWrite(dataPin, (val & 128) != 0); val <<= 1; } -- cgit v1.2.3-18-g5258 From b237dcc8e23abb9e79228e3a175a5286131f9f7a Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Sat, 8 Jun 2019 21:50:17 +0200 Subject: Do not claim AT-protocol in CDC interface descriptor The CDC code presents itself as a virtual serial port. However, it also sets the "bFunctionProtocol" value to 1, which means it supports AT-commands, which is not actually the case. This might cause problems with some software, such as ModemManager. Originally, ModemManager would be very liberal with probing serial devices, using a blacklist to prevent probing non-modems such as Arduinos. Since version 1.7.990, it has supported a "strict" mode where it tries to be more restrained in what devices it probes. For CDC ACM devices, this means it will only probe devices that claim to support AT-commands. However, it also stopped applying the blacklist (intending to eventually remove the blacklist), meaning it would again probe Arduinos. This new strict policy is not the upstream default, but is enabled in Debian (since Buster) and Ubuntu (since bionic 18.04.2). The proper way to fix this, is to not claim AT comand support in the USB device descriptor, which is what this commit does. The Arduino will still show up as a virtual serial port, just not be probed by ModemManager in strict mode. For the commit that introduced the strict mode in ModemManager, see https://cgit.freedesktop.org/ModemManager/ModemManager/commit/src?id=ee570d44dc117dc69f23e83313dd877f76c5e3e0 --- cores/arduino/CDC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores') diff --git a/cores/arduino/CDC.cpp b/cores/arduino/CDC.cpp index 142f8f6..4ff6b9b 100644 --- a/cores/arduino/CDC.cpp +++ b/cores/arduino/CDC.cpp @@ -41,7 +41,7 @@ static u8 wdtcsr_save; extern const CDCDescriptor _cdcInterface PROGMEM; const CDCDescriptor _cdcInterface = { - D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1), + D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0), // CDC communication interface D_INTERFACE(CDC_ACM_INTERFACE,1,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0), -- cgit v1.2.3-18-g5258 From c270eaabf4b7e85b0cfbb96c57817af5995b5ad8 Mon Sep 17 00:00:00 2001 From: Jeff Rowberg Date: Mon, 29 Jul 2019 12:16:41 -0400 Subject: Add null pointer test to String destructor --- cores/arduino/WString.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores') 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); } /*********************************************/ -- cgit v1.2.3-18-g5258 From 29bfd08cd7fc1399f897255f81804595a4776d16 Mon Sep 17 00:00:00 2001 From: Akihiro YAMAZAKI Date: Wed, 4 Sep 2019 20:04:45 +0900 Subject: remove unnecessary if branch checking `length` in below while statement --- cores/arduino/Stream.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'cores') 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(); -- cgit v1.2.3-18-g5258 From becb995388d7cbdd5f9cfbd41b82c7152ef6513f Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 16 Sep 2019 09:58:35 +0200 Subject: Adding parenthesis around 'bitvalue' allowing correct macro expansion when using with ternary operator such as bitWrite(value, bit, some_computed_value == 5 ? 1: 0);' --- cores/arduino/Arduino.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cores') diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 09c1448..d1a46d0 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -111,7 +111,7 @@ 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 bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit)) // avr-libc defines _NOP() since 1.6.2 #ifndef _NOP -- cgit v1.2.3-18-g5258 From c8d6aef6d9331af1ec8dea6f78b4e43174cdb55d Mon Sep 17 00:00:00 2001 From: Manuel Reimer Date: Wed, 25 Sep 2019 10:06:30 +0200 Subject: Interrupt ordering for 32u2 and 16u2 MCU (#66) * Interrupt ordering for 32u2 and 16u2 MCU * Added missing chip variants --- cores/arduino/WInterrupts.c | 71 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'cores') diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c index ac72dda..38ea158 100644 --- a/cores/arduino/WInterrupts.c +++ b/cores/arduino/WInterrupts.c @@ -102,6 +102,39 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { EICRB = (EICRB & ~((1<