Skip to content

Commit fc5bd7f

Browse files
authored
Merge pull request #1 from arduino/master
update from arduino head
2 parents b367b67 + c8a1dd9 commit fc5bd7f

File tree

8 files changed

+50
-27
lines changed

8 files changed

+50
-27
lines changed

cores/arduino/Arduino.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ extern const uint8_t digital_pin_to_port[];
9090
extern const uint8_t digital_pin_to_bit_mask[];
9191
extern const uint8_t digital_pin_to_bit_position[];
9292
extern const uint8_t digital_pin_to_timer[];
93+
extern const uint8_t analog_pin_to_channel[];
9394

9495
// Get the bit location within the hardware port of the given virtual pin.
9596
// This comes from the pins_*.c file for the active board configuration.
@@ -155,5 +156,12 @@ bool isDoubleBondedActive(uint8_t pin);
155156

156157
#endif
157158

159+
#ifdef __cplusplus
160+
extern "C" {
161+
#endif
158162
#include "pins_arduino.h"
163+
#ifdef __cplusplus
164+
} // extern "C"
165+
#endif
166+
159167
#endif

cores/arduino/UART.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "api/HardwareSerial.h"
2828
#include "pins_arduino.h"
2929

30+
using namespace arduino;
31+
3032
// Define constants and variables for buffering incoming serial data. We're
3133
// using a ring buffer (I think), in which head is the index of the location
3234
// to which to write the next incoming character and tail is the index of the

cores/arduino/WInterrupts.c renamed to cores/arduino/WInterrupts.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232

3333
#include "wiring_private.h"
3434

35-
static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
35+
static volatile voidFuncPtrParam intFunc[EXTERNAL_NUM_INTERRUPTS];
36+
static void* args[EXTERNAL_NUM_INTERRUPTS];
3637

37-
void attachInterrupt(uint8_t pin, void (*userFunc)(void), PinStatus mode) {
38+
void attachInterruptParam(pin_size_t pin, void (*userFunc)(void*), PinStatus mode, void* params) {
3839

3940
/* Get bit position and check pin validity */
4041
uint8_t bit_pos = digitalPinToBitPosition(pin);
@@ -46,24 +47,27 @@ void attachInterrupt(uint8_t pin, void (*userFunc)(void), PinStatus mode) {
4647
/* Check interrupt number and apply function pointer to correct array index */
4748
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
4849
intFunc[interruptNum] = userFunc;
50+
args[interruptNum] = params;
4951

5052
// Configure the interrupt mode (trigger on low input, any change, rising
5153
// edge, or falling edge). The mode constants were chosen to correspond
5254
// to the configuration bits in the hardware register, so we simply apply
5355
// the setting in the pin control register
5456

57+
int isc_mode;
58+
5559
switch (mode) {
5660
case CHANGE:
57-
mode = PORT_ISC_BOTHEDGES_gc;
61+
isc_mode = PORT_ISC_BOTHEDGES_gc;
5862
break;
5963
case FALLING:
60-
mode = PORT_ISC_FALLING_gc;
64+
isc_mode = PORT_ISC_FALLING_gc;
6165
break;
6266
case RISING:
63-
mode = PORT_ISC_RISING_gc;
67+
isc_mode = PORT_ISC_RISING_gc;
6468
break;
6569
case LOW:
66-
mode = PORT_ISC_LEVEL_gc;
70+
isc_mode = PORT_ISC_LEVEL_gc;
6771
break;
6872
default:
6973
// AVR doesn't support level triggered interrupts
@@ -80,10 +84,14 @@ void attachInterrupt(uint8_t pin, void (*userFunc)(void), PinStatus mode) {
8084
*pin_ctrl_reg &= ~(PORT_ISC_gm);
8185

8286
/* Apply ISC setting */
83-
*pin_ctrl_reg |= mode;
87+
*pin_ctrl_reg |= isc_mode;
8488
}
8589
}
8690

91+
void attachInterrupt(uint8_t pin, void (*userFunc)(void), PinStatus mode) {
92+
attachInterruptParam(pin, (voidFuncPtrParam)userFunc, mode, NULL);
93+
}
94+
8795
void detachInterrupt(uint8_t pin) {
8896
/* Get bit position and check pin validity */
8997
uint8_t bit_pos = digitalPinToBitPosition(pin);
@@ -127,7 +135,7 @@ static void port_interrupt_handler(uint8_t port) {
127135
if(intFunc[interrupt_num] != 0){
128136

129137
/* Call function */
130-
intFunc[interrupt_num]();
138+
intFunc[interrupt_num](args[interrupt_num]);
131139
}
132140
}
133141
bit_pos++;

cores/arduino/wiring_analog.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
#include "wiring_private.h"
26-
#include "pins_arduino.h"
2726
#include "Arduino.h"
2827

2928
uint8_t analog_reference = DEFAULT;

libraries/SPI/src/SPI.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#define SPI_IMODE_EXTINT 1
2525
#define SPI_IMODE_GLOBAL 2
2626

27-
const SPISettings DEFAULT_SPI_SETTINGS = SPISettings();
28-
2927
SPIClass::SPIClass(uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI, uint8_t uc_pinSS, uint8_t uc_mux)
3028
{
3129
initialized = false;
@@ -66,7 +64,7 @@ void SPIClass::init()
6664
initialized = true;
6765
}
6866

69-
void SPIClass::config(SPISettings settings)
67+
void SPIClass::config(SPISettingsMegaAVR settings)
7068
{
7169
SPI0.CTRLA = settings.ctrla;
7270
SPI0.CTRLB = settings.ctrlb;
@@ -173,7 +171,7 @@ void SPIClass::reattachMaskedInterrupts() {
173171
}
174172
}
175173

176-
void SPIClass::beginTransaction(SPISettings settings)
174+
void SPIClass::beginTransaction(SPISettingsMegaAVR settings)
177175
{
178176
if (interruptMode != SPI_IMODE_NONE)
179177
{

libraries/SPI/src/SPI.h

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// - endTransaction()
3232
// - usingInterrupt()
3333
// - SPISetting(clock, bitOrder, dataMode)
34-
#define SPI_HAS_TRANSACTION 1
34+
// #define SPI_HAS_TRANSACTION 1
3535

3636
// SPI_HAS_NOTUSINGINTERRUPT means that SPI has notUsingInterrupt() method
3737
#define SPI_HAS_NOTUSINGINTERRUPT 1
@@ -52,9 +52,9 @@
5252
#define EXTERNAL_NUM_INTERRUPTS NUM_TOTAL_PINS
5353
#endif
5454

55-
class SPISettings {
55+
class SPISettingsMegaAVR : public arduino::SPISettings {
5656
public:
57-
SPISettings(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) {
57+
SPISettingsMegaAVR(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) {
5858
if (__builtin_constant_p(clock)) {
5959
init_AlwaysInline(clock, bitOrder, dataMode);
6060
} else {
@@ -63,7 +63,9 @@ class SPISettings {
6363
}
6464

6565
// Default speed set to 4MHz, SPI mode set to MODE 0 and Bit order set to MSB first.
66-
SPISettings() { init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0); }
66+
SPISettingsMegaAVR() { init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0); }
67+
68+
SPISettingsMegaAVR(SPISettings& x) { SPISettingsMegaAVR(x.getClockFreq(), x.getBitOrder(), x.getDataMode()); }
6769

6870
private:
6971
void init_MightInline(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) {
@@ -142,12 +144,12 @@ class SPISettings {
142144
/* member variables containing the desired SPI settings */
143145
uint8_t ctrla;
144146
uint8_t ctrlb;
145-
friend class SPIClass;
147+
friend class SPIClassMegaAVR;
146148
};
147149

148-
class SPIClass {
150+
class SPIClassMegaAVR : public arduino::HardwareSPI {
149151
public:
150-
SPIClass(uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI, uint8_t uc_pinSS, uint8_t uc_mux);
152+
SPIClassMegaAVR(uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI, uint8_t uc_pinSS, uint8_t uc_mux);
151153

152154
byte transfer(uint8_t data);
153155
uint16_t transfer16(uint16_t data);
@@ -156,7 +158,10 @@ class SPIClass {
156158
// Transaction Functions
157159
void usingInterrupt(int interruptNumber);
158160
void notUsingInterrupt(int interruptNumber);
159-
void beginTransaction(SPISettings settings);
161+
void beginTransaction(SPISettingsMegaAVR settings);
162+
void beginTransaction(SPISettings settings) {
163+
beginTransaction(SPISettingsMegaAVR(settings));
164+
}
160165
void endTransaction(void);
161166

162167
void begin();
@@ -169,13 +174,16 @@ class SPIClass {
169174
private:
170175

171176
void init();
172-
void config(SPISettings settings);
177+
void config(SPISettingsMegaAVR settings);
178+
void config(SPISettings settings) {
179+
config(SPISettingsMegaAVR(settings));
180+
}
173181

174182
// These undocumented functions should not be used. SPI.transfer()
175183
// polls the hardware flag which is automatically cleared as the
176184
// AVR responds to SPI's interrupt
177-
inline static void attachInterrupt() { SPI0.INTCTRL |= (SPI_IE_bm); }
178-
inline static void detachInterrupt() { SPI0.INTCTRL &= ~(SPI_IE_bm); }
185+
inline void attachInterrupt() { SPI0.INTCTRL |= (SPI_IE_bm); }
186+
inline void detachInterrupt() { SPI0.INTCTRL &= ~(SPI_IE_bm); }
179187

180188
void detachMaskedInterrupts();
181189
void reattachMaskedInterrupts();
@@ -199,6 +207,7 @@ class SPIClass {
199207
#endif
200208
};
201209

210+
#define SPIClass SPIClassMegaAVR
202211

203212
#if SPI_INTERFACES_COUNT > 0
204213
extern SPIClass SPI;

platform.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification
77

88
name=Arduino megaAVR Boards
9-
version=1.8.5
9+
version=1.8.6
1010

1111
# AVR compile variables
1212
# ---------------------
@@ -79,7 +79,7 @@ recipe.output.save_file={build.project_name}.{build.variant}.hex
7979

8080
## Compute size
8181
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
82-
recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).*
82+
recipe.size.regex=^(?:\.text|\.data|\.rodata|\.bootloader)\s+([0-9]+).*
8383
recipe.size.regex.data=^(?:\.data|\.bss|\.noinit)\s+([0-9]+).*
8484
recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
8585

variants/nona4809/pins_arduino.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ const uint8_t analog_pin_to_channel[] = {
273273

274274
#endif
275275

276-
extern const uint8_t analog_pin_to_channel[];
277276
#define digitalPinToAnalogInput(p) ((p < ANALOG_INPUT_OFFSET) ? analog_pin_to_channel[p] : analog_pin_to_channel[p - ANALOG_INPUT_OFFSET] )
278277

279278
// These serial port names are intended to allow libraries and architecture-neutral

0 commit comments

Comments
 (0)