From caa734fddc597184c32ce482e812b6f32c6a4aae Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 5 Sep 2023 15:08:42 +0200 Subject: [PATCH] Ported legacy TestIncludesToIncludeFoldersDuplicateLibs* test --- .../integrationtest/compile_4/compile_test.go | 60 ++- .../compile_4/testdata/libraries/SPI/SPI.cpp | 201 ++++++++ .../compile_4/testdata/libraries/SPI/SPI.h | 324 ++++++++++++ .../testdata/libraries/SPI/keywords.txt | 36 ++ .../testdata/libraries/SPI/library.properties | 11 + .../user_hardware/arduino/avr/.gitkeep | 0 .../my_avr_platform/avr/boards.txt | 89 ++++ .../stk500v2/stk500boot_v2_mega2560.hex | 469 ++++++++++++++++++ .../my_avr_platform/avr/libraries/SPI/SPI.cpp | 201 ++++++++ .../my_avr_platform/avr/libraries/SPI/SPI.h | 324 ++++++++++++ .../BarometricPressureSensor.ino | 143 ++++++ .../DigitalPotControl/DigitalPotControl.ino | 71 +++ .../avr/libraries/SPI/keywords.txt | 36 ++ .../avr/libraries/SPI/library.properties | 10 + .../my_avr_platform/avr/platform.txt | 9 + .../user_hardware/my_symlinked_avr_platform | 1 + .../test/includes_to_include_folders_test.go | 91 ---- 17 files changed, 1978 insertions(+), 98 deletions(-) create mode 100644 internal/integrationtest/compile_4/testdata/libraries/SPI/SPI.cpp create mode 100644 internal/integrationtest/compile_4/testdata/libraries/SPI/SPI.h create mode 100644 internal/integrationtest/compile_4/testdata/libraries/SPI/keywords.txt create mode 100644 internal/integrationtest/compile_4/testdata/libraries/SPI/library.properties create mode 100644 internal/integrationtest/compile_4/testdata/user_hardware/arduino/avr/.gitkeep create mode 100644 internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/boards.txt create mode 100644 internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex create mode 100644 internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/SPI.cpp create mode 100644 internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/SPI.h create mode 100644 internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino create mode 100644 internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino create mode 100644 internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/keywords.txt create mode 100644 internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/library.properties create mode 100644 internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/platform.txt create mode 120000 internal/integrationtest/compile_4/testdata/user_hardware/my_symlinked_avr_platform delete mode 100644 legacy/builder/test/includes_to_include_folders_test.go diff --git a/internal/integrationtest/compile_4/compile_test.go b/internal/integrationtest/compile_4/compile_test.go index 47eca9fda34..3735db7fbfa 100644 --- a/internal/integrationtest/compile_4/compile_test.go +++ b/internal/integrationtest/compile_4/compile_test.go @@ -63,6 +63,11 @@ func TestCompileOfProblematicSketches(t *testing.T) { _, _, err = cli.Run("lib", "install", "CapacitiveSensor@0.5") require.NoError(t, err) + // Install custom hardware required for tests + customHwDir, err := paths.New("testdata", "user_hardware").Abs() + require.NoError(t, err) + require.NoError(t, customHwDir.CopyDirTo(cli.SketchbookDir().Join("hardware"))) + integrationtest.CLISubtests{ {"SketchWithInlineFunction", testBuilderSketchWithInlineFunction}, {"SketchWithConst", testBuilderSketchWithConst}, @@ -98,6 +103,7 @@ func TestCompileOfProblematicSketches(t *testing.T) { {"USBHostExample", testBuilderUSBHostExample}, {"SketchWithConflictingLibraries", testBuilderSketchWithConflictingLibraries}, {"SketchLibraryProvidesAllIncludes", testBuilderSketchLibraryProvidesAllIncludes}, + {"UserHardware", testBuilderWithUserHardware}, }.Run(t, env, cli) } @@ -566,6 +572,39 @@ func testBuilderSketchLibraryProvidesAllIncludes(t *testing.T, env *integrationt }) } +func testBuilderWithUserHardware(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { + coreSPILib, err := cli.SketchbookDir().Join("hardware", "my_avr_platform", "avr", "libraries", "SPI").Abs() + require.NoError(t, err) + sketchPath := coreSPILib.Join("examples", "BarometricPressureSensor", "BarometricPressureSensor.ino") + + t.Run("TestIncludesToIncludeFoldersDuplicateLibs", func(t *testing.T) { + out, err := tryBuild(t, env, cli, "my_avr_platform:avr:custom_yun", &buildOptions{ + Sketch: sketchPath, + NoTestLibraries: true, + }) + require.NoError(t, err) + + importedLibraries := out.BuilderResult.UsedLibraries + require.Equal(t, 1, len(importedLibraries)) + require.Equal(t, "SPI", importedLibraries[0].Name) + require.True(t, importedLibraries[0].SourceDir.EquivalentTo(coreSPILib)) + }) + + t.Run("TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatform", func(t *testing.T) { + SPILib, err := paths.New("testdata", "libraries", "SPI").Abs() + require.NoError(t, err) + out, err := tryBuild(t, env, cli, "my_avr_platform:avr:custom_yun", &buildOptions{ + Sketch: sketchPath, + }) + require.NoError(t, err) + + importedLibraries := out.BuilderResult.UsedLibraries + require.Equal(t, 1, len(importedLibraries)) + require.Equal(t, "SPI", importedLibraries[0].Name) + require.True(t, importedLibraries[0].SourceDir.EquivalentTo(SPILib)) + }) +} + func tryBuildAvrLeonardo(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) { _, err := tryBuild(t, env, cli, "arduino:avr:leonardo") require.NoError(t, err) @@ -587,10 +626,12 @@ type builderLibrary struct { } type buildOptions struct { - Sketch *paths.Path - NoClean bool - AllWarnings bool - Verbose bool + Sketch *paths.Path + NoTestLibraries bool + CustomLibPath *paths.Path + NoClean bool + AllWarnings bool + Verbose bool } func tryBuild(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI, fqbn string, optionsArg ...*buildOptions) (*builderOutput, error) { @@ -606,14 +647,19 @@ func tryBuild(t *testing.T, env *integrationtest.Environment, cli *integrationte require.Len(t, optionsArg, 1) options = optionsArg[0] } - libsPath, err := paths.New("testdata", "libraries").Abs() - require.NoError(t, err) args := []string{ "compile", "-b", fqbn, - "--libraries", libsPath.String(), "--format", "json", options.Sketch.String()} + if !options.NoTestLibraries { + libsPath, err := paths.New("testdata", "libraries").Abs() + require.NoError(t, err) + args = append(args, "--libraries", libsPath.String()) + } + if options.CustomLibPath != nil { + args = append(args, "--library", options.CustomLibPath.String()) + } if !options.NoClean { args = append(args, "--clean") } diff --git a/internal/integrationtest/compile_4/testdata/libraries/SPI/SPI.cpp b/internal/integrationtest/compile_4/testdata/libraries/SPI/SPI.cpp new file mode 100644 index 00000000000..af14e07b12f --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/SPI/SPI.cpp @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2010 by Cristian Maglie + * Copyright (c) 2014 by Paul Stoffregen (Transaction API) + * Copyright (c) 2014 by Matthijs Kooijman (SPISettings AVR) + * Copyright (c) 2014 by Andrew J. Kroll (atomicity fixes) + * SPI Master library for arduino. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +#include "SPI.h" + +SPIClass SPI; + +uint8_t SPIClass::initialized = 0; +uint8_t SPIClass::interruptMode = 0; +uint8_t SPIClass::interruptMask = 0; +uint8_t SPIClass::interruptSave = 0; +#ifdef SPI_TRANSACTION_MISMATCH_LED +uint8_t SPIClass::inTransactionFlag = 0; +#endif + +void SPIClass::begin() +{ + uint8_t sreg = SREG; + noInterrupts(); // Protect from a scheduler and prevent transactionBegin + if (!initialized) { + // Set SS to high so a connected chip will be "deselected" by default + uint8_t port = digitalPinToPort(SS); + uint8_t bit = digitalPinToBitMask(SS); + volatile uint8_t *reg = portModeRegister(port); + + // if the SS pin is not already configured as an output + // then set it high (to enable the internal pull-up resistor) + if(!(*reg & bit)){ + digitalWrite(SS, HIGH); + } + + // When the SS pin is set as OUTPUT, it can be used as + // a general purpose output port (it doesn't influence + // SPI operations). + pinMode(SS, OUTPUT); + + // Warning: if the SS pin ever becomes a LOW INPUT then SPI + // automatically switches to Slave, so the data direction of + // the SS pin MUST be kept as OUTPUT. + SPCR |= _BV(MSTR); + SPCR |= _BV(SPE); + + // Set direction register for SCK and MOSI pin. + // MISO pin automatically overrides to INPUT. + // By doing this AFTER enabling SPI, we avoid accidentally + // clocking in a single bit since the lines go directly + // from "input" to SPI control. + // http://code.google.com/p/arduino/issues/detail?id=888 + pinMode(SCK, OUTPUT); + pinMode(MOSI, OUTPUT); + } + initialized++; // reference count + SREG = sreg; +} + +void SPIClass::end() { + uint8_t sreg = SREG; + noInterrupts(); // Protect from a scheduler and prevent transactionBegin + // Decrease the reference counter + if (initialized) + initialized--; + // If there are no more references disable SPI + if (!initialized) { + SPCR &= ~_BV(SPE); + interruptMode = 0; + #ifdef SPI_TRANSACTION_MISMATCH_LED + inTransactionFlag = 0; + #endif + } + SREG = sreg; +} + +// mapping of interrupt numbers to bits within SPI_AVR_EIMSK +#if defined(__AVR_ATmega32U4__) + #define SPI_INT0_MASK (1< + * Copyright (c) 2014 by Paul Stoffregen (Transaction API) + * Copyright (c) 2014 by Matthijs Kooijman (SPISettings AVR) + * Copyright (c) 2014 by Andrew J. Kroll (atomicity fixes) + * SPI Master library for arduino. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +#ifndef _SPI_H_INCLUDED +#define _SPI_H_INCLUDED + +#include + +// SPI_HAS_TRANSACTION means SPI has beginTransaction(), endTransaction(), +// usingInterrupt(), and SPISetting(clock, bitOrder, dataMode) +#define SPI_HAS_TRANSACTION 1 + +// SPI_HAS_NOTUSINGINTERRUPT means that SPI has notUsingInterrupt() method +#define SPI_HAS_NOTUSINGINTERRUPT 1 + +// SPI_ATOMIC_VERSION means that SPI has atomicity fixes and what version. +// This way when there is a bug fix you can check this define to alert users +// of your code if it uses better version of this library. +// This also implies everything that SPI_HAS_TRANSACTION as documented above is +// available too. +#define SPI_ATOMIC_VERSION 1 + +// Uncomment this line to add detection of mismatched begin/end transactions. +// A mismatch occurs if other libraries fail to use SPI.endTransaction() for +// each SPI.beginTransaction(). Connect an LED to this pin. The LED will turn +// on if any mismatch is ever detected. +//#define SPI_TRANSACTION_MISMATCH_LED 5 + +#ifndef LSBFIRST +#define LSBFIRST 0 +#endif +#ifndef MSBFIRST +#define MSBFIRST 1 +#endif + +#define SPI_CLOCK_DIV4 0x00 +#define SPI_CLOCK_DIV16 0x01 +#define SPI_CLOCK_DIV64 0x02 +#define SPI_CLOCK_DIV128 0x03 +#define SPI_CLOCK_DIV2 0x04 +#define SPI_CLOCK_DIV8 0x05 +#define SPI_CLOCK_DIV32 0x06 + +#define SPI_MODE0 0x00 +#define SPI_MODE1 0x04 +#define SPI_MODE2 0x08 +#define SPI_MODE3 0x0C + +#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR +#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR +#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR + +// define SPI_AVR_EIMSK for AVR boards with external interrupt pins +#if defined(EIMSK) + #define SPI_AVR_EIMSK EIMSK +#elif defined(GICR) + #define SPI_AVR_EIMSK GICR +#elif defined(GIMSK) + #define SPI_AVR_EIMSK GIMSK +#endif + +class SPISettings { +public: + SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) { + if (__builtin_constant_p(clock)) { + init_AlwaysInline(clock, bitOrder, dataMode); + } else { + init_MightInline(clock, bitOrder, dataMode); + } + } + SPISettings() { + init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0); + } +private: + void init_MightInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) { + init_AlwaysInline(clock, bitOrder, dataMode); + } + void init_AlwaysInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) + __attribute__((__always_inline__)) { + // Clock settings are defined as follows. Note that this shows SPI2X + // inverted, so the bits form increasing numbers. Also note that + // fosc/64 appears twice + // SPR1 SPR0 ~SPI2X Freq + // 0 0 0 fosc/2 + // 0 0 1 fosc/4 + // 0 1 0 fosc/8 + // 0 1 1 fosc/16 + // 1 0 0 fosc/32 + // 1 0 1 fosc/64 + // 1 1 0 fosc/64 + // 1 1 1 fosc/128 + + // We find the fastest clock that is less than or equal to the + // given clock rate. The clock divider that results in clock_setting + // is 2 ^^ (clock_div + 1). If nothing is slow enough, we'll use the + // slowest (128 == 2 ^^ 7, so clock_div = 6). + uint8_t clockDiv; + + // When the clock is known at compiletime, use this if-then-else + // cascade, which the compiler knows how to completely optimize + // away. When clock is not known, use a loop instead, which generates + // shorter code. + if (__builtin_constant_p(clock)) { + if (clock >= F_CPU / 2) { + clockDiv = 0; + } else if (clock >= F_CPU / 4) { + clockDiv = 1; + } else if (clock >= F_CPU / 8) { + clockDiv = 2; + } else if (clock >= F_CPU / 16) { + clockDiv = 3; + } else if (clock >= F_CPU / 32) { + clockDiv = 4; + } else if (clock >= F_CPU / 64) { + clockDiv = 5; + } else { + clockDiv = 6; + } + } else { + uint32_t clockSetting = F_CPU / 2; + clockDiv = 0; + while (clockDiv < 6 && clock < clockSetting) { + clockSetting /= 2; + clockDiv++; + } + } + + // Compensate for the duplicate fosc/64 + if (clockDiv == 6) + clockDiv = 7; + + // Invert the SPI2X bit + clockDiv ^= 0x1; + + // Pack into the SPISettings class + spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) | + (dataMode & SPI_MODE_MASK) | ((clockDiv >> 1) & SPI_CLOCK_MASK); + spsr = clockDiv & SPI_2XCLOCK_MASK; + } + uint8_t spcr; + uint8_t spsr; + friend class SPIClass; +}; + + +class SPIClass { +public: + // Initialize the SPI library + static void begin(); + + // If SPI is used from within an interrupt, this function registers + // that interrupt with the SPI library, so beginTransaction() can + // prevent conflicts. The input interruptNumber is the number used + // with attachInterrupt. If SPI is used from a different interrupt + // (eg, a timer), interruptNumber should be 255. + static void usingInterrupt(uint8_t interruptNumber); + // And this does the opposite. + static void notUsingInterrupt(uint8_t interruptNumber); + // Note: the usingInterrupt and notUsingInterrupt functions should + // not to be called from ISR context or inside a transaction. + // For details see: + // https://github.com/arduino/Arduino/pull/2381 + // https://github.com/arduino/Arduino/pull/2449 + + // Before using SPI.transfer() or asserting chip select pins, + // this function is used to gain exclusive access to the SPI bus + // and configure the correct settings. + inline static void beginTransaction(SPISettings settings) { + if (interruptMode > 0) { + uint8_t sreg = SREG; + noInterrupts(); + + #ifdef SPI_AVR_EIMSK + if (interruptMode == 1) { + interruptSave = SPI_AVR_EIMSK; + SPI_AVR_EIMSK &= ~interruptMask; + SREG = sreg; + } else + #endif + { + interruptSave = sreg; + } + } + + #ifdef SPI_TRANSACTION_MISMATCH_LED + if (inTransactionFlag) { + pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT); + digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH); + } + inTransactionFlag = 1; + #endif + + SPCR = settings.spcr; + SPSR = settings.spsr; + } + + // Write to the SPI bus (MOSI pin) and also receive (MISO pin) + inline static uint8_t transfer(uint8_t data) { + SPDR = data; + /* + * The following NOP introduces a small delay that can prevent the wait + * loop form iterating when running at the maximum speed. This gives + * about 10% more speed, even if it seems counter-intuitive. At lower + * speeds it is unnoticed. + */ + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; // wait + return SPDR; + } + inline static uint16_t transfer16(uint16_t data) { + union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } in, out; + in.val = data; + if (!(SPCR & _BV(DORD))) { + SPDR = in.msb; + asm volatile("nop"); // See transfer(uint8_t) function + while (!(SPSR & _BV(SPIF))) ; + out.msb = SPDR; + SPDR = in.lsb; + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; + out.lsb = SPDR; + } else { + SPDR = in.lsb; + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; + out.lsb = SPDR; + SPDR = in.msb; + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; + out.msb = SPDR; + } + return out.val; + } + inline static void transfer(void *buf, size_t count) { + if (count == 0) return; + uint8_t *p = (uint8_t *)buf; + SPDR = *p; + while (--count > 0) { + uint8_t out = *(p + 1); + while (!(SPSR & _BV(SPIF))) ; + uint8_t in = SPDR; + SPDR = out; + *p++ = in; + } + while (!(SPSR & _BV(SPIF))) ; + *p = SPDR; + } + // After performing a group of transfers and releasing the chip select + // signal, this function allows others to access the SPI bus + inline static void endTransaction(void) { + #ifdef SPI_TRANSACTION_MISMATCH_LED + if (!inTransactionFlag) { + pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT); + digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH); + } + inTransactionFlag = 0; + #endif + + if (interruptMode > 0) { + #ifdef SPI_AVR_EIMSK + uint8_t sreg = SREG; + #endif + noInterrupts(); + #ifdef SPI_AVR_EIMSK + if (interruptMode == 1) { + SPI_AVR_EIMSK = interruptSave; + SREG = sreg; + } else + #endif + { + SREG = interruptSave; + } + } + } + + // Disable the SPI bus + static void end(); + + // This function is deprecated. New applications should use + // beginTransaction() to configure SPI settings. + inline static void setBitOrder(uint8_t bitOrder) { + if (bitOrder == LSBFIRST) SPCR |= _BV(DORD); + else SPCR &= ~(_BV(DORD)); + } + // This function is deprecated. New applications should use + // beginTransaction() to configure SPI settings. + inline static void setDataMode(uint8_t dataMode) { + SPCR = (SPCR & ~SPI_MODE_MASK) | dataMode; + } + // This function is deprecated. New applications should use + // beginTransaction() to configure SPI settings. + inline static void setClockDivider(uint8_t clockDiv) { + SPCR = (SPCR & ~SPI_CLOCK_MASK) | (clockDiv & SPI_CLOCK_MASK); + SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((clockDiv >> 2) & SPI_2XCLOCK_MASK); + } + // These undocumented functions should not be used. SPI.transfer() + // polls the hardware flag which is automatically cleared as the + // AVR responds to SPI's interrupt + inline static void attachInterrupt() { SPCR |= _BV(SPIE); } + inline static void detachInterrupt() { SPCR &= ~_BV(SPIE); } + +private: + static uint8_t initialized; + static uint8_t interruptMode; // 0=none, 1=mask, 2=global + static uint8_t interruptMask; // which interrupts to mask + static uint8_t interruptSave; // temp storage, to restore state + #ifdef SPI_TRANSACTION_MISMATCH_LED + static uint8_t inTransactionFlag; + #endif +}; + +extern SPIClass SPI; + +#endif diff --git a/internal/integrationtest/compile_4/testdata/libraries/SPI/keywords.txt b/internal/integrationtest/compile_4/testdata/libraries/SPI/keywords.txt new file mode 100644 index 00000000000..fa7616581aa --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/SPI/keywords.txt @@ -0,0 +1,36 @@ +####################################### +# Syntax Coloring Map SPI +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +SPI KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### +begin KEYWORD2 +end KEYWORD2 +transfer KEYWORD2 +setBitOrder KEYWORD2 +setDataMode KEYWORD2 +setClockDivider KEYWORD2 + + +####################################### +# Constants (LITERAL1) +####################################### +SPI_CLOCK_DIV4 LITERAL1 +SPI_CLOCK_DIV16 LITERAL1 +SPI_CLOCK_DIV64 LITERAL1 +SPI_CLOCK_DIV128 LITERAL1 +SPI_CLOCK_DIV2 LITERAL1 +SPI_CLOCK_DIV8 LITERAL1 +SPI_CLOCK_DIV32 LITERAL1 +SPI_CLOCK_DIV64 LITERAL1 +SPI_MODE0 LITERAL1 +SPI_MODE1 LITERAL1 +SPI_MODE2 LITERAL1 +SPI_MODE3 LITERAL1 \ No newline at end of file diff --git a/internal/integrationtest/compile_4/testdata/libraries/SPI/library.properties b/internal/integrationtest/compile_4/testdata/libraries/SPI/library.properties new file mode 100644 index 00000000000..7e55b100497 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/libraries/SPI/library.properties @@ -0,0 +1,11 @@ +name=SPI +version=1.0 +author=Arduino +maintainer=Arduino +sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus. For all Arduino boards, BUT Arduino DUE. +paragraph= +url=http://arduino.cc/en/Reference/SPI +architectures=avr +types=Arduino +category=Other + diff --git a/internal/integrationtest/compile_4/testdata/user_hardware/arduino/avr/.gitkeep b/internal/integrationtest/compile_4/testdata/user_hardware/arduino/avr/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/boards.txt b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/boards.txt new file mode 100644 index 00000000000..bf794a46f71 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/boards.txt @@ -0,0 +1,89 @@ +menu.cpu=Processor + +custom_yun.name=Arduino Yún +custom_yun.upload.via_ssh=true + +custom_yun.build.core=arduino:arduino +custom_yun.bootloader.tool=arduino:avrdude +custom_yun.upload.tool=arduino:avrdude + +custom_yun.vid.0=0x2341 +custom_yun.pid.0=0x0041 +custom_yun.vid.1=0x2341 +custom_yun.pid.1=0x8041 +custom_yun.upload.protocol=avr109 +custom_yun.upload.maximum_size=28672 +custom_yun.upload.maximum_data_size=2560 +custom_yun.upload.speed=57600 +custom_yun.upload.disable_flushing=true +custom_yun.upload.use_1200bps_touch=true +custom_yun.upload.wait_for_upload_port=true + +custom_yun.bootloader.low_fuses=0xff +custom_yun.bootloader.high_fuses=0xd8 +custom_yun.bootloader.extended_fuses=0xfb +custom_yun.bootloader.file=caterina/Caterina-custom_yun.hex +custom_yun.bootloader.unlock_bits=0x3F +custom_yun.bootloader.lock_bits=0x2F + +custom_yun.build.mcu=atmega32u4 +custom_yun.build.f_cpu=16000000L +custom_yun.build.vid=0x2341 +custom_yun.build.pid=0x8041 +custom_yun.build.usb_product="Arduino My" +custom_yun.build.board=AVR_YUN +custom_yun.build.variant=arduino:yun +custom_yun.build.extra_flags={build.usb_flags} + +mymega.name=Arduino Mega or Mega 2560 + +mymega.vid.0=0x2341 +mymega.pid.0=0x0010 +mymega.vid.1=0x2341 +mymega.pid.1=0x0042 +mymega.vid.2=0x2A03 +mymega.pid.2=0x0010 +mymega.vid.3=0x2A03 +mymega.pid.3=0x0042 + +mymega.upload.tool=avrdude +mymega.upload.maximum_data_size=8192 + +mymega.bootloader.tool=avrdude +mymega.bootloader.low_fuses=0xFF +mymega.bootloader.unlock_bits=0x3F +mymega.bootloader.lock_bits=0x0F + +mymega.build.f_cpu=16000000L +mymega.build.core=arduino +mymega.build.variant=mega + +mymega.menu.cpu.atmega2560=ATmega2560 (Mega 2560) + +mymega.menu.cpu.atmega2560.upload.protocol=wiring +mymega.menu.cpu.atmega2560.upload.maximum_size=253952 +mymega.menu.cpu.atmega2560.upload.speed=115200 + +mymega.menu.cpu.atmega2560.bootloader._folder=stk500v2 +mymega.menu.cpu.atmega2560.bootloader.high_fuses=0xD8 +mymega.menu.cpu.atmega2560.bootloader.extended_fuses=0xFD +mymega.menu.cpu.atmega2560.bootloader.file={bootloader._folder}/stk500boot_v2_mega2560.hex + +mymega.menu.cpu.atmega2560.build.mcu=atmega2560 +# Do not define build.board to test autogeneration +#mymega.menu.cpu.atmega2560.build.board=AVR_MYMEGA2560 + +mymega.menu.cpu.atmega1280=ATmega1280 + +mymega.menu.cpu.atmega1280.upload.protocol=arduino +mymega.menu.cpu.atmega1280.upload.maximum_size=126976 +mymega.menu.cpu.atmega1280.upload.speed=57600 + +mymega.menu.cpu.atmega1280.bootloader._folder=atmega +mymega.menu.cpu.atmega1280.bootloader.high_fuses=0xDA +mymega.menu.cpu.atmega1280.bootloader.extended_fuses=0xF5 +mymega.menu.cpu.atmega1280.bootloader.file={bootloader._folder}/ATmegaBOOT_168_atmega1280.hex + +mymega.menu.cpu.atmega1280.build.mcu=atmega1280 +# define custom build.board for testing +mymega.menu.cpu.atmega1280.build.board=MYMEGA1280 diff --git a/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex new file mode 100644 index 00000000000..c52e690a102 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex @@ -0,0 +1,469 @@ +:020000023000CC +:10E000000D9489F10D94B2F10D94B2F10D94B2F129 +:10E010000D94B2F10D94B2F10D94B2F10D94B2F1F0 +:10E020000D94B2F10D94B2F10D94B2F10D94B2F1E0 +:10E030000D94B2F10D94B2F10D94B2F10D94B2F1D0 +:10E040000D94B2F10D94B2F10D94B2F10D94B2F1C0 +:10E050000D94B2F10D94B2F10D94B2F10D94B2F1B0 +:10E060000D94B2F10D94B2F10D94B2F10D94B2F1A0 +:10E070000D94B2F10D94B2F10D94B2F10D94B2F190 +:10E080000D94B2F10D94B2F10D94B2F10D94B2F180 +:10E090000D94B2F10D94B2F10D94B2F10D94B2F170 +:10E0A0000D94B2F10D94B2F10D94B2F10D94B2F160 +:10E0B0000D94B2F10D94B2F10D94B2F10D94B2F150 +:10E0C0000D94B2F10D94B2F10D94B2F10D94B2F140 +:10E0D0000D94B2F10D94B2F10D94B2F10D94B2F130 +:10E0E0000D94B2F141546D656761323536300041AF +:10E0F000726475696E6F206578706C6F72657220DE +:10E1000073746B3530305632206279204D4C530099 +:10E11000426F6F746C6F616465723E004875683F52 +:10E1200000436F6D70696C6564206F6E203D200048 +:10E130004350552054797065202020203D20005FF9 +:10E140005F4156525F415243485F5F3D2000415658 +:10E1500052204C696243205665723D20004743437C +:10E160002056657273696F6E203D20004350552024 +:10E1700049442020202020203D20004C6F7720663D +:10E18000757365202020203D20004869676820665F +:10E190007573652020203D200045787420667573D6 +:10E1A00065202020203D20004C6F636B2066757336 +:10E1B000652020203D20004D617220203720323024 +:10E1C000313300312E362E3800342E332E350056A2 +:10E1D00023202020414444522020206F7020636F70 +:10E1E00064652020202020696E73747275637469E1 +:10E1F0006F6E2061646472202020496E74657272B3 +:10E20000757074006E6F20766563746F7200726A49 +:10E210006D702020006A6D70200057686174207056 +:10E220006F72743A00506F7274206E6F7420737541 +:10E2300070706F72746564004D7573742062652030 +:10E2400061206C6574746572002000577269747483 +:10E25000696E672045450052656164696E672045B7 +:10E26000450045452065727220636E743D00504F35 +:10E27000525400303D5A65726F2061646472003FF1 +:10E280003D43505520737461747300403D454550C3 +:10E29000524F4D207465737400423D426C696E6B41 +:10E2A000204C454400453D44756D70204545505215 +:10E2B0004F4D00463D44756D7020464C415348001B +:10E2C000483D48656C70004C3D4C69737420492F83 +:10E2D0004F20506F72747300513D51756974005234 +:10E2E0003D44756D702052414D00563D73686F7707 +:10E2F00020696E7465727275707420566563746FF0 +:10E30000727300593D506F727420626C696E6B00BD +:10E310002A0011241FBECFEFD1E2DEBFCDBF01E046 +:10E320000CBF12E0A0E0B2E0EEE1FDEF03E00BBFB6 +:10E3300002C007900D92A030B107D9F712E0A0E01B +:10E34000B2E001C01D92AE30B107E1F70F9460F367 +:10E350000D948DFE01E20EBF0FEF0DBF11241FBE05 +:10E360000D9460F30D9400F020E030E040ED57E0B4 +:10E3700005C0FA013197F1F72F5F3F4F2817390792 +:10E38000C0F308959C01260F311DC901A0E0B0E043 +:10E390002F5F3F4FABBFFC018791882361F08093D3 +:10E3A000C6008091C00086FFFCCF8091C0008064D1 +:10E3B0008093C000EACF08958DE08093C6008091DD +:10E3C000C00086FFFCCF8091C00080648093C000B5 +:10E3D0008AE08093C6008091C00086FFFCCF8091C8 +:10E3E000C00080648093C00008950F94C2F10F9420 +:10E3F000DCF10895FC019081992359F09093C600B7 +:10E400008091C00086FFFCCF8091C0008064809323 +:10E41000C0003196992379F70895282F982F929567 +:10E420009F70892F805D8A3308F0895F8093C600D2 +:10E430008091C00086FFFCCF8091C00080648093F3 +:10E44000C000822F8F70982F905D9A3308F0995FEB +:10E450009093C6008091C00086FFFCCF8091C000E1 +:10E4600080648093C00008959C01FB01853691056E +:10E470001CF46330710594F0C90164E670E00F94F8 +:10E480002EFE605D7F4F6093C6008091C00086FFC6 +:10E49000FCCF8091C00080648093C0002B30310598 +:10E4A00014F43297B4F0C90164E670E00F942EFEC4 +:10E4B0006AE070E00F942EFE605D7F4F6093C600AF +:10E4C0008091C00086FFFCCF8091C0008064809363 +:10E4D000C000C9016AE070E00F942EFEC0968093E0 +:10E4E000C6008091C00086FFFCCF8091C000806490 +:10E4F0008093C00008951F93182F8EE692EE60E07F +:10E500000F94C2F11093C6008091C00086FFFCCF2B +:10E510008091C00080648093C0000F94DCF11F9153 +:10E5200008952F923F924F925F926F927F928F92B7 +:10E530009F92AF92BF92CF92DF92EF92FF920F9392 +:10E540001F93DF93CF93CDB7DEB762970FB6F894E2 +:10E55000DEBF0FBECDBF382E622ECA01DB015C01CB +:10E560006D01772420E2222E2E010894411C511CBB +:10E570008BC081E0A81680E0B80681E0C80680E084 +:10E58000D80628F0C601AA27BB270F940DF2BB2797 +:10E59000AD2D9C2D8B2D0F940DF28A2D0F940DF225 +:10E5A0002092C6008091C00086FFFCCF8091C00001 +:10E5B00080648093C0009DE29093C6008091C0006B +:10E5C00086FFFCCF8091C00080648093C0002092C1 +:10E5D000C6008091C00086FFFCCF8091C00080649F +:10E5E0008093C00019828601750188249924A1E0D6 +:10E5F0003A1651F03A1620F0B2E03B1661F409C029 +:10E600000BBFF701779007C0C7010F9477FE782EF4 +:10E6100002C0F7017080872D0F940DF22092C60082 +:10E620008091C00086FFFCCF8091C0008064809301 +:10E63000C000872D8052F401EF70F0708F3520F408 +:10E64000E40DF51D708204C0E40DF51D8EE280839B +:10E650000894E11CF11C011D111D0894811C911CE2 +:10E6600090E18916910409F0C2CF80E190E0A0E02A +:10E67000B0E0A80EB91ECA1EDB1E198AC2010F9493 +:10E68000FAF10F94DCF16A94662009F072CF629679 +:10E690000FB6F894DEBF0FBECDBFCF91DF911F91B3 +:10E6A0000F91FF90EF90DF90CF90BF90AF909F9031 +:10E6B0008F907F906F905F904F903F902F90089534 +:10E6C0002F923F924F925F926F927F928F929F9282 +:10E6D000AF92BF92CF92DF92EF92FF920F931F9370 +:10E6E000DF93CF93CDB7DEB7CD53D1400FB6F894BB +:10E6F000DEBF0FBECDBF01E20EBF0FEF0DBF94B75F +:10E70000F894A89514BE80916000886180936000A1 +:10E7100010926000789493FF05C0E0910002F091A0 +:10E7200001021995279A2F9A8091C00082608093E8 +:10E73000C00080E18093C40088E18093C1000000A4 +:10E74000EE24FF24870144E0A42EB12CCC24DD2448 +:10E7500024C0C5010197F1F70894E11CF11C011DCB +:10E76000111D21E2E2162EE4F20620E0020720E06D +:10E77000120718F031E0C32ED12CC801B70127ECE5 +:10E780003BE140E050E00F9441FE611571058105C9 +:10E79000910519F485B1805885B98091C00087FD35 +:10E7A00003C0C114D104A9F2A6014F5F5F4FC25E3E +:10E7B000DE4F59834883CE51D140C25EDE4F8881FF +:10E7C0009981CE51D140019711F00D9410FEC05D9A +:10E7D000DE4F19821882C053D14060E0C15DDE4F28 +:10E7E0001882CF52D14088249924C35DDE4F19820C +:10E7F0001882CD52D140C05EDE4F188219821A8233 +:10E800001B82C052D140CE5CDE4F188219821A8220 +:10E810001B82C253D140EE24FF2487010BBFF701B6 +:10E8200007911691C45CDE4F19830883CC53D14005 +:10E830000D940BFEC25EDE4F28813981CE51D1404E +:10E840002130310509F52091C600C25EDE4F1982E4 +:10E850001882CE51D14022C02F5F3F4F4F4F5F4FA4 +:10E86000213082E138078AE7480780E0580780F0C6 +:10E87000C45CDE4FE881F981CC53D140EF5FFF4F9C +:10E8800019F0EE27FF27099420E030E040E050E047 +:10E890008091C00087FFE0CF2091C600C35DDE4FAE +:10E8A00048815981CD52D1404F5F5F4FC35DDE4FEC +:10E8B00059834883CD52D140213209F063C64A3092 +:10E8C000510508F05FC60894811C911C53E0851621 +:10E8D000910409F059C600E010E018C081E280936D +:10E8E000C6008091C00086FFFCCF8091C00080648C +:10E8F0008093C0002F5F3F4F2931310579F70F9486 +:10E90000DCF10F5F1F4F0530110519F020E030E0FA +:10E91000E5CF10920A0210920B0210920C02109294 +:10E920000D02109206021092070210920802109235 +:10E930000902109202021092030210920402109235 +:10E9400005028FEE90EE60E00F94F5F180E191EE1C +:10E9500060E00F94C2F18091C00087FFFCCF9091DE +:10E96000C600903608F09F759032B8F09093C600BC +:10E970008091C00086FFFCCF8091C00080648093AE +:10E98000C000A0E2A093C6008091C00086FFFCCF2B +:10E990008091C00080648093C000983409F4D7C18E +:10E9A0009934B8F4923409F459C1933458F490333B +:10E9B00019F1903308F4E3C59F33A1F1903409F0C5 +:10E9C000DEC5BDC0953409F470C1963409F0D7C5D1 +:10E9D00098C1923509F42BC2933538F49C3409F46C +:10E9E000F5C1913509F0CBC518C2963509F445C279 +:10E9F000993509F0C4C567C483E792EE62E00F94CD +:10EA0000F5F110920602109207021092080210927D +:10EA1000090210920A0210920B0210920C0210923C +:10EA20000D0213C18FE792EE62E00F94F5F18FEEC5 +:10EA300090EE60E00F94F5F181E291EE60E00F94CA +:10EA4000C2F187EB91EE60E00F94F5F180E391EE77 +:10EA500060E00F94C2F184EE90EE60E00F94F5F167 +:10EA60008FE391EE60E00F94C2F186E090E061E008 +:10EA700070E00F9434F20F94DCF18DE591EE60E0DC +:10EA80000F94C2F189EC91EE60E00F94F5F18EE401 +:10EA900091EE60E00F94C2F183EC91EE60E00F9490 +:10EAA000F5F18CE691EE60E00F94C2F18EE10F94E7 +:10EAB0000DF288E90F940DF281E00F940DF20F949E +:10EAC000DCF18BE791EE60E00F94C2F119E0E0E039 +:10EAD000F0E010935700E4918E2F0F940DF20F94F5 +:10EAE000DCF18AE891EE60E00F94C2F1E3E0F0E03F +:10EAF00010935700E4918E2F0F940DF20F94DCF1D8 +:10EB000089E991EE60E00F94C2F1E2E0F0E0109349 +:10EB10005700E4918E2F0F940DF20F94DCF188EAE8 +:10EB200091EE60E00F94C2F1E1E0F0E01093570045 +:10EB30001491812F0F940DF20F94DCF107CF8BE825 +:10EB400092EE62E00F94F5F18BE492EE60E00F94A8 +:10EB5000F5F10F94DCF100E010E019C0C8016F2D51 +:10EB60000F947FFEFF2031F489E492EE60E00F9471 +:10EB7000C2F10BC0F092C6008091C00086FFFCCFAE +:10EB80008091C00080648093C0000F5F1F4FC80158 +:10EB900081519F41A0E0B0E0ABBFFC01F790BAE229 +:10EBA000FB1621F0E2E000301E07C1F60F94DCF105 +:10EBB0000F94DCF187E592EE60E00F94F5F10F948D +:10EBC000DCF1CC24DD2400E010E01EC0C8010F946D +:10EBD00077FEF82E882331F489E492EE60E00F94FA +:10EBE000C2F10BC08093C6008091C00086FFFCCFAD +:10EBF0008091C00080648093C000FE1419F00894D6 +:10EC0000C11CD11C0F5F1F4FC80181519F41A0E063 +:10EC1000B0E0ABBFFC01E790FAE2EF1621F022E092 +:10EC20000030120799F60F94DCF10F94DCF182E6C4 +:10EC300092EE60E00F94C2F1C60161E070E00F94C3 +:10EC400034F20F94DCF10F94DCF110920202109276 +:10EC50000302109204021092050278CE89E992EE26 +:10EC600062E00F94F5F1279A2F9A16C02F9880E052 +:10EC700090E0E0EDF7E03197F1F7019684369105E9 +:10EC8000C1F72F9A80E090E0E0EDF7E03197F1F7DF +:10EC9000019684369105C1F78091C00087FFE6CFC9 +:10ECA0008091C00087FFFCCF64C485EA92EE62E0E9 +:10ECB0000F94F5F140910202509103026091040219 +:10ECC0007091050281E020E10F9491F2809102029F +:10ECD00090910302A0910402B091050280509F4FD1 +:10ECE000AF4FBF4F8093020290930302A0930402A0 +:10ECF000B093050280509041A040B04008F426CE69 +:10ED0000A4CF83EB92EE62E00F94F5F140910602FE +:10ED100050910702609108027091090280E020E1A1 +:10ED20000F9491F28091060290910702A09108023F +:10ED3000B091090280509F4FAF4FBF4F80930602A2 +:10ED400090930702A0930802B0930902FFCD80ECD4 +:10ED500092EE62E00F94F5F183E792EE60E00F949B +:10ED6000F5F18FE792EE60E00F94F5F18BE892EE0B +:10ED700060E00F94F5F189E992EE60E00F94F5F10F +:10ED800085EA92EE60E00F94F5F183EB92EE60E09D +:10ED90000F94F5F180EC92EE60E00F94F5F187ECC2 +:10EDA00092EE60E00F94F5F188ED92EE60E00F9442 +:10EDB000F5F18FED92EE60E00F94F5F18AEE92EEB0 +:10EDC00060E00F94F5F183E093EEBDCD87EC92EE19 +:10EDD00062E00F94F5F181E40F947BF282E40F94EA +:10EDE0007BF283E40F947BF284E40F947BF285E45E +:10EDF0000F947BF286E40F947BF287E40F947BF20E +:10EE000088E40F947BF28AE40F947BF28BE40F94F6 +:10EE10007BF28CE40F947BF299CD88ED92EE62E068 +:10EE20000F94F5F1772473948824992409C48FED05 +:10EE300092EE62E00F94F5F140910A0250910B02BC +:10EE400060910C0270910D0282E020E10F9491F22A +:10EE500080910A0290910B02A0910C02B0910D02D8 +:10EE600080509F4FAF4FBF4F80930A0290930B0289 +:10EE7000A0930C02B0930D0269CD8AEE92EE62E08F +:10EE80000F94F5F184EE90EE60E00F94F5F18FECC5 +:10EE900091EE60E00F94F5F1662477244301CC5D98 +:10EEA000DE4F19821882C452D140D401C301B695F5 +:10EEB000A79597958795CA5DDE4F88839983AA8326 +:10EEC000BB83C652D140CC5DDE4FA881B981C4520C +:10EED000D1401196CC5DDE4FB983A883C452D14096 +:10EEE000CD0162E070E00F9434F2B0E2B093C6005E +:10EEF0008091C00086FFFCCF8091C0008064809329 +:10EF0000C000EDE2E093C6008091C00086FFFCCF18 +:10EF10008091C00080648093C000F0E2F093C6004E +:10EF20008091C00086FFFCCF8091C00080648093F8 +:10EF3000C000CA5DDE4FE880F9800A811B81C6529D +:10EF4000D140BB27A12F902F8F2D0F940DF2CA5DBA +:10EF5000DE4F8881C652D1400F940DF2B0E2FB2EF5 +:10EF6000F092C6008091C00086FFFCCF8091C00067 +:10EF700080648093C0000DE30093C6008091C000C0 +:10EF800086FFFCCF8091C00080648093C00010E2B7 +:10EF90001093C6008091C00086FFFCCF8091C00016 +:10EFA00080648093C0008BBEF3012791C65DDE4F65 +:10EFB0002883CA52D140A22EBB24CC24DD2408943D +:10EFC000611C711C811C911C8BBEF3018791282E42 +:10EFD0003324442455240894611C711C811C911C09 +:10EFE0008BBEF3013791C55DDE4F3883CB52D140E4 +:10EFF0000894611C711C811C911C8BBEF30147910C +:10F00000C45DDE4F4883CC52D140ADEFEA2EAFEF66 +:10F01000FA2EAFEF0A2FAFEF1A2F6E0C7F1C801E57 +:10F02000911E142D032DF22CEE24EA0CFB1C0C1D5A +:10F030001D1D0F940DF220E22093C6008091C000A8 +:10F0400086FFFCCF8091C00080648093C000C65DC5 +:10F05000DE4F8881CA52D1400F940DF230E23093D6 +:10F06000C6008091C00086FFFCCF8091C000806404 +:10F070008093C000C45DDE4F8881CC52D1400F9494 +:10F080000DF240E24093C6008091C00086FFFCCFA5 +:10F090008091C00080648093C000C55DDE4F888190 +:10F0A000CB52D1400F940DF250E25093C6008091A4 +:10F0B000C00086FFFCCF8091C00080648093C000B8 +:10F0C0008FEFE8168FEFF80680E0080780E018075A +:10F0D00031F484E092EE60E00F94C2F1DFC0D80119 +:10F0E000C7018070907CA070B0708050904CA040A0 +:10F0F000B040D1F52FEF3FE340E050E0E222F322B1 +:10F1000004231523CA5DDE4FA880B980CA80DB8046 +:10F11000C652D140AE0CBF1CC01ED11EAA0CBB1CD7 +:10F12000CC1CDD1C8EE092EE60E00F94C2F1BB2798 +:10F13000A12F902F8F2D0F940DF28E2D0F940DF285 +:10F1400030E23093C6008091C00086FFFCCF8091F2 +:10F15000C00080648093C0004EE34093C60080915D +:10F16000C00086FFFCCF87C08EE09EEFA0E0B0E03D +:10F17000E822F9220A231B239CE0E91694E9F90608 +:10F1800090E0090790E0190709F088C0C45DDE4FE0 +:10F19000A881CC52D140EA2EFF2400E010E0102FCD +:10F1A0000F2DFE2CEE24C55DDE4FB881CB52D14031 +:10F1B000EB0EF11C011D111DD601C501817090706F +:10F1C000A070B070DC0199278827E80EF91E0A1F8D +:10F1D0001B1F20EF30E040E050E0A222B322C42207 +:10F1E000D52241E1AA0CBB1CCC1CDD1C4A95D1F7F1 +:10F1F000EA0CFB1C0C1D1D1D81E090E0A0E0B0E0BE +:10F20000282239224A225B2235E1220C331C441C7D +:10F21000551C3A95D1F7E20CF31C041D151D57013E +:10F220006801AA0CBB1CCC1CDD1C85E192EE60E0E1 +:10F230000F94C2F1C801AA27BB270F940DF2BB2778 +:10F24000A12F902F8F2D0F940DF28E2D0F940DF274 +:10F2500090E29093C6008091C00086FFFCCF809121 +:10F26000C00080648093C000AEE3A093C60080918C +:10F27000C00086FFFCCF8091C00080648093C000F6 +:10F28000C601AA27BB270F940DF2BB27AD2D9C2DDD +:10F290008B2D0F940DF28A2D0F940DF20F94DCF14B +:10F2A000CC5DDE4FE881F981C452D140F99709F471 +:10F2B0004DCBF4E0EF2EF12C012D112D6E0C7F1CA7 +:10F2C000801E911EF2CD83E093EE62E00F94F5F183 +:10F2D0008AE192EE60E00F94C2F18091C00087FF56 +:10F2E000FCCF1091C6001F751093C6008091C0001E +:10F2F00086FFFCCF8091C00080648093C0000F9493 +:10F30000DCF1812F81548A3108F036C1163409F4BA +:10F3100095C0173490F4133409F44EC0143430F40B +:10F320001134F1F0123409F01DC130C0143409F465 +:10F3300059C0153409F016C16BC01A3409F4C4C0A1 +:10F340001B3438F4173409F48FC0183409F00AC19B +:10F35000A1C01B3409F4D2C01C3409F003C1E8C0B9 +:10F360008FEF81B90DC082B1809582B980E090E0C5 +:10F37000E0EDF7E03197F1F70196883C9105C1F790 +:10F380008091C00087FFEFCF12B8EFC08FEF84B934 +:10F390000DC085B1809585B980E090E0E0EDF7E0A3 +:10F3A0003197F1F70196883C9105C1F78091C00033 +:10F3B00087FFEFCF15B8D9C08FEF87B90DC088B1DF +:10F3C000809588B980E090E0E0EDF7E03197F1F7C3 +:10F3D0000196883C9105C1F78091C00087FFEFCF6F +:10F3E00018B8C3C08FEF8AB90DC08BB180958BB9A7 +:10F3F00080E090E0E0EDF7E03197F1F70196883C8E +:10F400009105C1F78091C00087FFEFCF1BB8ADC059 +:10F410008FEF8DB90DC08EB180958EB980E090E0F0 +:10F42000E0EDF7E03197F1F70196883C9105C1F7DF +:10F430008091C00087FFEFCF1EB897C08FEF80BBD1 +:10F440000DC081B3809581BB80E090E0E0EDF7E0F6 +:10F450003197F1F70196883C9105C1F78091C00082 +:10F4600087FFEFCF11BA81C08FEF83BB0DC084B38C +:10F47000809584BB80E090E0E0EDF7E03197F1F714 +:10F480000196883C9105C1F78091C00087FFEFCFBE +:10F4900014BA6BC08FEF809301010FC080910201FD +:10F4A00080958093020180E090E0E0EDF7E03197F5 +:10F4B000F1F70196883C9105C1F78091C00087FF64 +:10F4C000EDCF1092020151C08FEF809304010FC065 +:10F4D0008091050180958093050180E090E0E0ED4A +:10F4E000F7E03197F1F70196883C9105C1F78091DB +:10F4F000C00087FFEDCF1092050137C08FEF8093DA +:10F5000007010FC08091080180958093080180E079 +:10F5100090E0E0EDF7E03197F1F70196883C910536 +:10F52000C1F78091C00087FFEDCF109208011DC088 +:10F530008FEF80930A010FC080910B01809580931B +:10F540000B0180E090E0E0EDF7E03197F1F70196F4 +:10F55000883C9105C1F78091C00087FFEDCF1092E4 +:10F560000B0103C085E292EEEEC98091C00087FFD7 +:10F57000FCCF8091C600EAC988E392EEE4C98CE131 +:10F5800091EEE1C988249924933011F1943028F444 +:10F59000913089F09230B8F408C0953061F195301F +:10F5A000F0F0963009F048C043C02B3109F042C951 +:10F5B00091E06BE13FC96227C15DDE4F2883CF52E6 +:10F5C000D14092E037C9B22FA0E0622793E032C960 +:10F5D000822F90E0A82BB92B622794E02BC92E3004 +:10F5E00009F039C3622795E0C05DDE4F19821882A9 +:10F5F000C053D1401FC9E1E0F0E0EC0FFD1FC05D3A +:10F60000DE4F08811981C053D140E00FF11F2083E4 +:10F610000F5F1F4FC05DDE4F19830883C053D14079 +:10F6200062270A171B0709F005C9D80196E002C92D +:10F63000261709F010C303C0973009F0FBC87724E0 +:10F640009981933109F412C19431C8F4963009F4C8 +:10F65000D8C0973050F4923009F406C1933009F4C1 +:10F660006DC0913009F059C253C0913109F477C08F +:10F67000923108F0BBC0903109F04FC2F5C098310B +:10F6800009F487C0993150F4953109F4EFC09531F0 +:10F6900008F4C6C1963109F040C2C2C19A3109F4DA +:10F6A0006CC09A3108F491C09B3109F45BC09D3164 +:10F6B00009F033C29D81903359F48F81882311F46E +:10F6C0009EE11CC0813011F091E018C098E916C08D +:10F6D000892F807591F0903539F4E0E0F0E089E011 +:10F6E0008093570094910AC0983539F4E3E0F0E034 +:10F6F00089E080935700949101C090E01A821B82A8 +:10F700008D818C831D829E831F8227E030E009C299 +:10F710001A8288E08B8381E48C8386E58D8382E581 +:10F720008E8389E48F8383E5888780E589878FE5E9 +:10F730008A8782E38B872BE030E0F3C18A818139AD +:10F7400041F0823941F0803911F48FE005C080E04A +:10F7500003C082E001C08AE01A828B8344C0772410 +:10F76000739482C08D81882311F48EE12CC0813086 +:10F7700011F081E028C088E926C01A82E1E0F0E0BB +:10F7800089E08093570084918B831C8224E030E0D1 +:10F79000C8C18B81803589F48C81883039F4E2E0EE +:10F7A000F0E089E08093570084910DC0E0E0F0E044 +:10F7B00089E080935700849106C0E3E0F0E089E09F +:10F7C0008093570084911A82DFCF8D81836C99E0FA +:10F7D000E1E0F0E0082E90935700E89507B600FCB2 +:10F7E000FDCF1A821B8223E030E09BC180EC8A832C +:10F7F000CE5CDE4F188219821A821B82C253D1401E +:10F800008EC18A8190E0A0E0B0E0582F44273327D2 +:10F8100022278B8190E0A0E0B0E0DC0199278827C7 +:10F82000282B392B4A2B5B2B8D8190E0A0E0B0E098 +:10F83000282B392B4A2B5B2B8C8190E0A0E0B0E089 +:10F84000BA2FA92F982F8827282B392B4A2B5B2BCF +:10F85000220F331F441F551FC05EDE4F288339839C +:10F860004A835B83C052D1401A8259C13A81C95C34 +:10F87000DE4F3883C753D140CA5CDE4F1882C6536F +:10F88000D1408B81C82EDD24CA5CDE4F488159816E +:10F89000C653D140C42AD52A933109F082C0CE5C28 +:10F8A000DE4F88819981AA81BB81C253D1408050AB +:10F8B000904CA340B04030F583E0CE5CDE4FE88052 +:10F8C000F9800A811B81C253D140F70100935B008C +:10F8D00080935700E89507B600FCFDCFCE5CDE4F65 +:10F8E000088119812A813B81C253D14000501F4FAA +:10F8F0002F4F3F4FCE5CDE4F088319832A833B8313 +:10F90000C253D140C05EDE4F488159816A817B81FC +:10F91000C052D140DE011B9631E08C9111962C91A2 +:10F9200011971296C75CDE4F2883C953D140C85C3B +:10F93000DE4F1882C853D14090E0C85CDE4FE881AA +:10F94000F981C853D1408E2B9F2B0C01FA01609393 +:10F950005B0030935700E89511244E5F5F4F6F4F67 +:10F960007F4F0EEFE02E0FEFF02ECE0CDF1CC114F8 +:10F97000D10499F685E0C05EDE4F088119812A81A5 +:10F980003B81C052D140F80120935B008093570027 +:10F99000E89507B600FCFDCF81E180935700E8951C +:10F9A00035C0C05EDE4F88819981AA81BB81C0527B +:10F9B000D140B695A795979587957C018601ABE0D8 +:10F9C000AA2EB12CAC0EBD1E0BC0D5016D915D01F0 +:10F9D000C7010F947FFE0894E11CF11C01501040F8 +:10F9E0000115110591F7A60160E070E0440F551F65 +:10F9F000661F771FC05EDE4FE880F9800A811B8199 +:10FA0000C052D1404E0D5F1D601F711F1A82C05E33 +:10FA1000DE4F488359836A837B83C052D1407FC0C5 +:10FA2000FA80C55CDE4FF882CB53D140C65CDE4F16 +:10FA30001882CA53D1408B81C82EDD24C65CDE4FAC +:10FA400008811981CA53D140C02AD12A1A828981DA +:10FA5000BE016D5F7F4F843121F59601C05EDE4FA0 +:10FA6000E880F9800A811B81C052D1400BBFF701A9 +:10FA700087919691DB018C9311969C936E5F7F4FDB +:10FA8000D801C7010296A11DB11DC05EDE4F88835B +:10FA90009983AA83BB83C052D14022503040F1F6F3 +:10FAA00036C0C05EDE4F288139814A815B81C052F9 +:10FAB000D1400894C108D108760100E010E0089414 +:10FAC000C11CD11C0894E11CF11C011D111DE20E8A +:10FAD000F31E041F151F21BDBB27A52F942F832FB5 +:10FAE00082BD2F5F3F4F4F4F5F4FF89A80B5DB01CC +:10FAF0008D93BD012E153F054007510761F7C05E8C +:10FB0000DE4F288339834A835B83C052D1409601FC +:10FB10002D5F3F4FFB01108204C080EC8A8322E0FE +:10FB200030E08BE18093C6008091C00086FFFCCF5F +:10FB30008091C00080648093C000C15DDE4FF88179 +:10FB4000CF52D140F093C6008091C00086FFFCCF19 +:10FB50008091C00080648093C000432F3093C60022 +:10FB60008091C00086FFFCCF8091C00080648093AC +:10FB7000C000922F2093C6008091C00086FFFCCF6A +:10FB80008091C00080648093C0008EE08093C600A6 +:10FB90008091C00086FFFCCF8091C000806480937C +:10FBA000C00065E1C15DDE4FE880CF52D1406E25D7 +:10FBB00069276427FE01319610C090819093C6009A +:10FBC0008091C00086FFFCCF31968091C000806498 +:10FBD0008093C0006927215030402115310569F715 +:10FBE0006093C6008091C00086FFFCCF8091C0006A +:10FBF00080648093C00085B1805885B9772081F4F6 +:10FC0000C15DDE4F0881CF52D1400F5FC15DDE4F35 +:10FC10000883CF52D14090E0A0E0B0E00D941AF4F8 +:10FC200027982F9880E090E020ED37E0F901319798 +:10FC3000F1F7019684369105C9F700008091C00064 +:10FC40008D7F8093C00081E180935700E895EE2777 +:10FC5000FF270994FFCF90E00D941AF497FB092E2B +:10FC600007260AD077FD04D02ED006D000201AF443 +:10FC7000709561957F4F0895F6F7909581959F4F08 +:10FC80000895A1E21A2EAA1BBB1BFD010DC0AA1FDD +:10FC9000BB1FEE1FFF1FA217B307E407F50720F0F5 +:10FCA000A21BB30BE40BF50B661F771F881F991F70 +:10FCB0001A9469F760957095809590959B01AC01B9 +:10FCC000BD01CF010895AA1BBB1B51E107C0AA1FAC +:10FCD000BB1FA617B70710F0A61BB70B881F991FED +:10FCE0005A95A9F780959095BC01CD010895F99991 +:10FCF000FECF92BD81BDF89A992780B50895262F31 +:10FD0000F999FECF1FBA92BD81BD20BD0FB6F89400 +:0EFD1000FA9AF99A0FBE01960895F894FFCF63 +:040000033000E000E9 +:00000001FF diff --git a/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/SPI.cpp b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/SPI.cpp new file mode 100644 index 00000000000..af14e07b12f --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/SPI.cpp @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2010 by Cristian Maglie + * Copyright (c) 2014 by Paul Stoffregen (Transaction API) + * Copyright (c) 2014 by Matthijs Kooijman (SPISettings AVR) + * Copyright (c) 2014 by Andrew J. Kroll (atomicity fixes) + * SPI Master library for arduino. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +#include "SPI.h" + +SPIClass SPI; + +uint8_t SPIClass::initialized = 0; +uint8_t SPIClass::interruptMode = 0; +uint8_t SPIClass::interruptMask = 0; +uint8_t SPIClass::interruptSave = 0; +#ifdef SPI_TRANSACTION_MISMATCH_LED +uint8_t SPIClass::inTransactionFlag = 0; +#endif + +void SPIClass::begin() +{ + uint8_t sreg = SREG; + noInterrupts(); // Protect from a scheduler and prevent transactionBegin + if (!initialized) { + // Set SS to high so a connected chip will be "deselected" by default + uint8_t port = digitalPinToPort(SS); + uint8_t bit = digitalPinToBitMask(SS); + volatile uint8_t *reg = portModeRegister(port); + + // if the SS pin is not already configured as an output + // then set it high (to enable the internal pull-up resistor) + if(!(*reg & bit)){ + digitalWrite(SS, HIGH); + } + + // When the SS pin is set as OUTPUT, it can be used as + // a general purpose output port (it doesn't influence + // SPI operations). + pinMode(SS, OUTPUT); + + // Warning: if the SS pin ever becomes a LOW INPUT then SPI + // automatically switches to Slave, so the data direction of + // the SS pin MUST be kept as OUTPUT. + SPCR |= _BV(MSTR); + SPCR |= _BV(SPE); + + // Set direction register for SCK and MOSI pin. + // MISO pin automatically overrides to INPUT. + // By doing this AFTER enabling SPI, we avoid accidentally + // clocking in a single bit since the lines go directly + // from "input" to SPI control. + // http://code.google.com/p/arduino/issues/detail?id=888 + pinMode(SCK, OUTPUT); + pinMode(MOSI, OUTPUT); + } + initialized++; // reference count + SREG = sreg; +} + +void SPIClass::end() { + uint8_t sreg = SREG; + noInterrupts(); // Protect from a scheduler and prevent transactionBegin + // Decrease the reference counter + if (initialized) + initialized--; + // If there are no more references disable SPI + if (!initialized) { + SPCR &= ~_BV(SPE); + interruptMode = 0; + #ifdef SPI_TRANSACTION_MISMATCH_LED + inTransactionFlag = 0; + #endif + } + SREG = sreg; +} + +// mapping of interrupt numbers to bits within SPI_AVR_EIMSK +#if defined(__AVR_ATmega32U4__) + #define SPI_INT0_MASK (1< + * Copyright (c) 2014 by Paul Stoffregen (Transaction API) + * Copyright (c) 2014 by Matthijs Kooijman (SPISettings AVR) + * Copyright (c) 2014 by Andrew J. Kroll (atomicity fixes) + * SPI Master library for arduino. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +#ifndef _SPI_H_INCLUDED +#define _SPI_H_INCLUDED + +#include + +// SPI_HAS_TRANSACTION means SPI has beginTransaction(), endTransaction(), +// usingInterrupt(), and SPISetting(clock, bitOrder, dataMode) +#define SPI_HAS_TRANSACTION 1 + +// SPI_HAS_NOTUSINGINTERRUPT means that SPI has notUsingInterrupt() method +#define SPI_HAS_NOTUSINGINTERRUPT 1 + +// SPI_ATOMIC_VERSION means that SPI has atomicity fixes and what version. +// This way when there is a bug fix you can check this define to alert users +// of your code if it uses better version of this library. +// This also implies everything that SPI_HAS_TRANSACTION as documented above is +// available too. +#define SPI_ATOMIC_VERSION 1 + +// Uncomment this line to add detection of mismatched begin/end transactions. +// A mismatch occurs if other libraries fail to use SPI.endTransaction() for +// each SPI.beginTransaction(). Connect an LED to this pin. The LED will turn +// on if any mismatch is ever detected. +//#define SPI_TRANSACTION_MISMATCH_LED 5 + +#ifndef LSBFIRST +#define LSBFIRST 0 +#endif +#ifndef MSBFIRST +#define MSBFIRST 1 +#endif + +#define SPI_CLOCK_DIV4 0x00 +#define SPI_CLOCK_DIV16 0x01 +#define SPI_CLOCK_DIV64 0x02 +#define SPI_CLOCK_DIV128 0x03 +#define SPI_CLOCK_DIV2 0x04 +#define SPI_CLOCK_DIV8 0x05 +#define SPI_CLOCK_DIV32 0x06 + +#define SPI_MODE0 0x00 +#define SPI_MODE1 0x04 +#define SPI_MODE2 0x08 +#define SPI_MODE3 0x0C + +#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR +#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR +#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR + +// define SPI_AVR_EIMSK for AVR boards with external interrupt pins +#if defined(EIMSK) + #define SPI_AVR_EIMSK EIMSK +#elif defined(GICR) + #define SPI_AVR_EIMSK GICR +#elif defined(GIMSK) + #define SPI_AVR_EIMSK GIMSK +#endif + +class SPISettings { +public: + SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) { + if (__builtin_constant_p(clock)) { + init_AlwaysInline(clock, bitOrder, dataMode); + } else { + init_MightInline(clock, bitOrder, dataMode); + } + } + SPISettings() { + init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0); + } +private: + void init_MightInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) { + init_AlwaysInline(clock, bitOrder, dataMode); + } + void init_AlwaysInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) + __attribute__((__always_inline__)) { + // Clock settings are defined as follows. Note that this shows SPI2X + // inverted, so the bits form increasing numbers. Also note that + // fosc/64 appears twice + // SPR1 SPR0 ~SPI2X Freq + // 0 0 0 fosc/2 + // 0 0 1 fosc/4 + // 0 1 0 fosc/8 + // 0 1 1 fosc/16 + // 1 0 0 fosc/32 + // 1 0 1 fosc/64 + // 1 1 0 fosc/64 + // 1 1 1 fosc/128 + + // We find the fastest clock that is less than or equal to the + // given clock rate. The clock divider that results in clock_setting + // is 2 ^^ (clock_div + 1). If nothing is slow enough, we'll use the + // slowest (128 == 2 ^^ 7, so clock_div = 6). + uint8_t clockDiv; + + // When the clock is known at compiletime, use this if-then-else + // cascade, which the compiler knows how to completely optimize + // away. When clock is not known, use a loop instead, which generates + // shorter code. + if (__builtin_constant_p(clock)) { + if (clock >= F_CPU / 2) { + clockDiv = 0; + } else if (clock >= F_CPU / 4) { + clockDiv = 1; + } else if (clock >= F_CPU / 8) { + clockDiv = 2; + } else if (clock >= F_CPU / 16) { + clockDiv = 3; + } else if (clock >= F_CPU / 32) { + clockDiv = 4; + } else if (clock >= F_CPU / 64) { + clockDiv = 5; + } else { + clockDiv = 6; + } + } else { + uint32_t clockSetting = F_CPU / 2; + clockDiv = 0; + while (clockDiv < 6 && clock < clockSetting) { + clockSetting /= 2; + clockDiv++; + } + } + + // Compensate for the duplicate fosc/64 + if (clockDiv == 6) + clockDiv = 7; + + // Invert the SPI2X bit + clockDiv ^= 0x1; + + // Pack into the SPISettings class + spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) | + (dataMode & SPI_MODE_MASK) | ((clockDiv >> 1) & SPI_CLOCK_MASK); + spsr = clockDiv & SPI_2XCLOCK_MASK; + } + uint8_t spcr; + uint8_t spsr; + friend class SPIClass; +}; + + +class SPIClass { +public: + // Initialize the SPI library + static void begin(); + + // If SPI is used from within an interrupt, this function registers + // that interrupt with the SPI library, so beginTransaction() can + // prevent conflicts. The input interruptNumber is the number used + // with attachInterrupt. If SPI is used from a different interrupt + // (eg, a timer), interruptNumber should be 255. + static void usingInterrupt(uint8_t interruptNumber); + // And this does the opposite. + static void notUsingInterrupt(uint8_t interruptNumber); + // Note: the usingInterrupt and notUsingInterrupt functions should + // not to be called from ISR context or inside a transaction. + // For details see: + // https://github.com/arduino/Arduino/pull/2381 + // https://github.com/arduino/Arduino/pull/2449 + + // Before using SPI.transfer() or asserting chip select pins, + // this function is used to gain exclusive access to the SPI bus + // and configure the correct settings. + inline static void beginTransaction(SPISettings settings) { + if (interruptMode > 0) { + uint8_t sreg = SREG; + noInterrupts(); + + #ifdef SPI_AVR_EIMSK + if (interruptMode == 1) { + interruptSave = SPI_AVR_EIMSK; + SPI_AVR_EIMSK &= ~interruptMask; + SREG = sreg; + } else + #endif + { + interruptSave = sreg; + } + } + + #ifdef SPI_TRANSACTION_MISMATCH_LED + if (inTransactionFlag) { + pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT); + digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH); + } + inTransactionFlag = 1; + #endif + + SPCR = settings.spcr; + SPSR = settings.spsr; + } + + // Write to the SPI bus (MOSI pin) and also receive (MISO pin) + inline static uint8_t transfer(uint8_t data) { + SPDR = data; + /* + * The following NOP introduces a small delay that can prevent the wait + * loop form iterating when running at the maximum speed. This gives + * about 10% more speed, even if it seems counter-intuitive. At lower + * speeds it is unnoticed. + */ + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; // wait + return SPDR; + } + inline static uint16_t transfer16(uint16_t data) { + union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } in, out; + in.val = data; + if (!(SPCR & _BV(DORD))) { + SPDR = in.msb; + asm volatile("nop"); // See transfer(uint8_t) function + while (!(SPSR & _BV(SPIF))) ; + out.msb = SPDR; + SPDR = in.lsb; + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; + out.lsb = SPDR; + } else { + SPDR = in.lsb; + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; + out.lsb = SPDR; + SPDR = in.msb; + asm volatile("nop"); + while (!(SPSR & _BV(SPIF))) ; + out.msb = SPDR; + } + return out.val; + } + inline static void transfer(void *buf, size_t count) { + if (count == 0) return; + uint8_t *p = (uint8_t *)buf; + SPDR = *p; + while (--count > 0) { + uint8_t out = *(p + 1); + while (!(SPSR & _BV(SPIF))) ; + uint8_t in = SPDR; + SPDR = out; + *p++ = in; + } + while (!(SPSR & _BV(SPIF))) ; + *p = SPDR; + } + // After performing a group of transfers and releasing the chip select + // signal, this function allows others to access the SPI bus + inline static void endTransaction(void) { + #ifdef SPI_TRANSACTION_MISMATCH_LED + if (!inTransactionFlag) { + pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT); + digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH); + } + inTransactionFlag = 0; + #endif + + if (interruptMode > 0) { + #ifdef SPI_AVR_EIMSK + uint8_t sreg = SREG; + #endif + noInterrupts(); + #ifdef SPI_AVR_EIMSK + if (interruptMode == 1) { + SPI_AVR_EIMSK = interruptSave; + SREG = sreg; + } else + #endif + { + SREG = interruptSave; + } + } + } + + // Disable the SPI bus + static void end(); + + // This function is deprecated. New applications should use + // beginTransaction() to configure SPI settings. + inline static void setBitOrder(uint8_t bitOrder) { + if (bitOrder == LSBFIRST) SPCR |= _BV(DORD); + else SPCR &= ~(_BV(DORD)); + } + // This function is deprecated. New applications should use + // beginTransaction() to configure SPI settings. + inline static void setDataMode(uint8_t dataMode) { + SPCR = (SPCR & ~SPI_MODE_MASK) | dataMode; + } + // This function is deprecated. New applications should use + // beginTransaction() to configure SPI settings. + inline static void setClockDivider(uint8_t clockDiv) { + SPCR = (SPCR & ~SPI_CLOCK_MASK) | (clockDiv & SPI_CLOCK_MASK); + SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((clockDiv >> 2) & SPI_2XCLOCK_MASK); + } + // These undocumented functions should not be used. SPI.transfer() + // polls the hardware flag which is automatically cleared as the + // AVR responds to SPI's interrupt + inline static void attachInterrupt() { SPCR |= _BV(SPIE); } + inline static void detachInterrupt() { SPCR &= ~_BV(SPIE); } + +private: + static uint8_t initialized; + static uint8_t interruptMode; // 0=none, 1=mask, 2=global + static uint8_t interruptMask; // which interrupts to mask + static uint8_t interruptSave; // temp storage, to restore state + #ifdef SPI_TRANSACTION_MISMATCH_LED + static uint8_t inTransactionFlag; + #endif +}; + +extern SPIClass SPI; + +#endif diff --git a/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino new file mode 100644 index 00000000000..8104fcbc252 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -0,0 +1,143 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Shows the output of a Barometric Pressure Sensor on a + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + http://www.vti.fi/en/support/obsolete_products/pressure_sensors/ + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + Circuit: + SCP1000 sensor attached to pins 6, 7, 10 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + modified 14 August 2010 + by Tom Igoe + */ + +// the sensor communicates using SPI, so include the library: +#include + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading +const byte READ = 0b11111100; // SCP1000's read command +const byte WRITE = 0b00000010; // SCP1000's write command + +// pins used for the connection with the sensor +// the other you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +void setup() { + Serial.begin(9600); + + // start the SPI library: + SPI.begin(); + + // initalize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + // give the sensor time to set up: + delay(100); +} + +void loop() { + //Select High Resolution Mode + writeRegister(0x03, 0x0A); + + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to celsius and display it: + float realTemp = (float)tempData / 20.0; + Serial.print("Temp[C]="); + Serial.print(realTemp); + + + //Read the pressure data highest 3 bits: + byte pressure_data_high = readRegister(0x1F, 1); + pressure_data_high &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressure_data_low = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + long pressure = ((pressure_data_high << 16) | pressure_data_low) / 4; + + // display the temperature: + Serial.println("\tPressure [Pa]=" + String(pressure)); + } +} + +//Read from or write to register from the SCP1000: +unsigned int readRegister(byte thisRegister, int bytesToRead ) { + byte inByte = 0; // incoming byte from the SPI + unsigned int result = 0; // result to return + Serial.print(thisRegister, BIN); + Serial.print("\t"); + // SCP1000 expects the register name in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the address and the command into one byte + byte dataToSend = thisRegister & READ; + Serial.println(thisRegister, BIN); + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + SPI.transfer(dataToSend); + // send a value of 0 to read the first byte returned: + result = SPI.transfer(0x00); + // decrement the number of bytes left to read: + bytesToRead--; + // if you still have another byte to read: + if (bytesToRead > 0) { + // shift the first byte left, then get the second byte: + result = result << 8; + inByte = SPI.transfer(0x00); + // combine the byte you just got with the previous one: + result = result | inByte; + // decrement the number of bytes left to read: + bytesToRead--; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return(result); +} + + +//Sends a write command to SCP1000 + +void writeRegister(byte thisRegister, byte thisValue) { + + // SCP1000 expects the register address in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the register address and the command into one byte: + byte dataToSend = thisRegister | WRITE; + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(dataToSend); //Send register location + SPI.transfer(thisValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} + diff --git a/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino new file mode 100644 index 00000000000..b135a74f4ed --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -0,0 +1,71 @@ +/* + Digital Pot Control + + This example controls an Analog Devices AD5206 digital potentiometer. + The AD5206 has 6 potentiometer channels. Each channel's pins are labeled + A - connect this to voltage + W - this is the pot's wiper, which changes when you set it + B - connect this to ground. + + The AD5206 is SPI-compatible,and to command it, you send two bytes, + one with the channel number (0 - 5) and one with the resistance value for the + channel (0 - 255). + + The circuit: + * All A pins of AD5206 connected to +5V + * All B pins of AD5206 connected to ground + * An LED and a 220-ohm resisor in series connected from each W pin to ground + * CS - to digital pin 10 (SS pin) + * SDI - to digital pin 11 (MOSI pin) + * CLK - to digital pin 13 (SCK pin) + + created 10 Aug 2010 + by Tom Igoe + + Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 + +*/ + + +// inslude the SPI library: +#include + + +// set pin 10 as the slave select for the digital pot: +const int slaveSelectPin = 10; + +void setup() { + // set the slaveSelectPin as an output: + pinMode (slaveSelectPin, OUTPUT); + // initialize SPI: + SPI.begin(); +} + +void loop() { + // go through the six channels of the digital pot: + for (int channel = 0; channel < 6; channel++) { + // change the resistance on this channel from min to max: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, level); + delay(10); + } + // wait a second at the top: + delay(100); + // change the resistance on this channel from max to min: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, 255 - level); + delay(10); + } + } + +} + +void digitalPotWrite(int address, int value) { + // take the SS pin low to select the chip: + digitalWrite(slaveSelectPin, LOW); + // send in the address and value via SPI: + SPI.transfer(address); + SPI.transfer(value); + // take the SS pin high to de-select the chip: + digitalWrite(slaveSelectPin, HIGH); +} diff --git a/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/keywords.txt b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/keywords.txt new file mode 100644 index 00000000000..fa7616581aa --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/keywords.txt @@ -0,0 +1,36 @@ +####################################### +# Syntax Coloring Map SPI +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +SPI KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### +begin KEYWORD2 +end KEYWORD2 +transfer KEYWORD2 +setBitOrder KEYWORD2 +setDataMode KEYWORD2 +setClockDivider KEYWORD2 + + +####################################### +# Constants (LITERAL1) +####################################### +SPI_CLOCK_DIV4 LITERAL1 +SPI_CLOCK_DIV16 LITERAL1 +SPI_CLOCK_DIV64 LITERAL1 +SPI_CLOCK_DIV128 LITERAL1 +SPI_CLOCK_DIV2 LITERAL1 +SPI_CLOCK_DIV8 LITERAL1 +SPI_CLOCK_DIV32 LITERAL1 +SPI_CLOCK_DIV64 LITERAL1 +SPI_MODE0 LITERAL1 +SPI_MODE1 LITERAL1 +SPI_MODE2 LITERAL1 +SPI_MODE3 LITERAL1 \ No newline at end of file diff --git a/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/library.properties b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/library.properties new file mode 100644 index 00000000000..07af8696109 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/libraries/SPI/library.properties @@ -0,0 +1,10 @@ +name=SPI +version=1.0 +author=Arduino +maintainer=Arduino +sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus. For all Arduino boards, BUT Arduino DUE. +paragraph= +url=http://arduino.cc/en/Reference/SPI +architectures=avr +types=Arduino + diff --git a/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/platform.txt b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/platform.txt new file mode 100644 index 00000000000..cc0be0a0c5f --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/user_hardware/my_avr_platform/avr/platform.txt @@ -0,0 +1,9 @@ + +# Arduino AVR Core and platform. +# ------------------------------ + +# For more info: +# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification + +name=My AVR Boards +version=9.9.9 \ No newline at end of file diff --git a/internal/integrationtest/compile_4/testdata/user_hardware/my_symlinked_avr_platform b/internal/integrationtest/compile_4/testdata/user_hardware/my_symlinked_avr_platform new file mode 120000 index 00000000000..8f67ba7ea89 --- /dev/null +++ b/internal/integrationtest/compile_4/testdata/user_hardware/my_symlinked_avr_platform @@ -0,0 +1 @@ +my_avr_platform \ No newline at end of file diff --git a/legacy/builder/test/includes_to_include_folders_test.go b/legacy/builder/test/includes_to_include_folders_test.go deleted file mode 100644 index 83424d582b6..00000000000 --- a/legacy/builder/test/includes_to_include_folders_test.go +++ /dev/null @@ -1,91 +0,0 @@ -// This file is part of arduino-cli. -// -// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) -// -// This software is released under the GNU General Public License version 3, -// which covers the main part of arduino-cli. -// The terms of this license can be found at: -// https://www.gnu.org/licenses/gpl-3.0.en.html -// -// You can be released from the requirements of the above licenses by purchasing -// a commercial license. Buying such a license is mandatory if you want to -// modify or otherwise use the software for commercial activities involving the -// Arduino software without disclosing the source code of your own applications. -// To purchase a commercial license, send an email to license@arduino.cc. - -package test - -import ( - "path/filepath" - "sort" - "testing" - - bldr "github.com/arduino/arduino-cli/arduino/builder" - "github.com/arduino/arduino-cli/legacy/builder" - "github.com/arduino/arduino-cli/legacy/builder/types" - paths "github.com/arduino/go-paths-helper" - "github.com/stretchr/testify/require" -) - -func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) { - ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), - BuiltInLibrariesDirs: paths.New("downloaded_libraries"), - Verbose: true, - } - ctx = prepareBuilderTestContext(t, ctx, paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"), "my_avr_platform:avr:custom_yun") - defer cleanUpBuilderTestContext(t, ctx) - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - - importedLibraries := ctx.ImportedLibraries - sort.Sort(ByLibraryName(importedLibraries)) - require.Equal(t, 1, len(importedLibraries)) - require.Equal(t, "SPI", importedLibraries[0].Name) - requireEquivalentPaths(t, importedLibraries[0].SourceDir.String(), filepath.Join("user_hardware", "my_avr_platform", "avr", "libraries", "SPI")) -} - -func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatform(t *testing.T) { - ctx := &types.Context{ - HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"), - BuiltInToolsDirs: paths.NewPathList("downloaded_tools"), - BuiltInLibrariesDirs: paths.New("downloaded_libraries"), - OtherLibrariesDirs: paths.NewPathList("libraries"), - Verbose: true, - } - ctx = prepareBuilderTestContext(t, ctx, paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"), "my_avr_platform:avr:custom_yun") - defer cleanUpBuilderTestContext(t, ctx) - - var _err error - commands := []types.Command{ - &builder.ContainerSetupHardwareToolsLibsSketchAndProps{}, - types.BareCommand(func(ctx *types.Context) error { - ctx.LineOffset, _err = bldr.PrepareSketchBuildPath(ctx.Sketch, ctx.SourceOverride, ctx.SketchBuildPath) - return _err - }), - &builder.ContainerFindIncludes{}, - } - for _, command := range commands { - err := command.Run(ctx) - NoError(t, err) - } - - importedLibraries := ctx.ImportedLibraries - sort.Sort(ByLibraryName(importedLibraries)) - require.Equal(t, 1, len(importedLibraries)) - require.Equal(t, "SPI", importedLibraries[0].Name) - requireEquivalentPaths(t, importedLibraries[0].SourceDir.String(), filepath.Join("libraries", "SPI")) -}