From d5c828736be9dbd04820103dbb8cd4ee2f0ab5b7 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 21 Nov 2013 12:35:31 +0100 Subject: [PATCH] Revert "SPI library to new format" --- .../arduino/avr/libraries/SPI}/SPI.cpp | 2 +- .../arduino/avr/libraries/SPI/SPI.h | 0 .../BarometricPressureSensor.ino | 0 .../DigitalPotControl/DigitalPotControl.ino | 0 .../arduino/avr/libraries/SPI}/keywords.txt | 0 .../arduino/sam/libraries/SPI}/SPI.cpp | 2 +- .../arduino/sam/libraries/SPI/SPI.h | 0 .../BarometricPressureSensor.ino | 16 ++--- .../DigitalPotControl/DigitalPotControl.ino | 71 +++++++++++++++++++ .../arduino/sam/libraries/SPI}/keywords.txt | 0 libraries/SPI/keywords.txt | 36 ---------- libraries/SPI/library.properties | 10 --- libraries/SPI/src/SPI.h | 1 - 13 files changed, 81 insertions(+), 57 deletions(-) rename {libraries/SPI/arch/avr => hardware/arduino/avr/libraries/SPI}/SPI.cpp (98%) rename libraries/SPI/arch/avr/SPI_Class.h => hardware/arduino/avr/libraries/SPI/SPI.h (100%) rename {libraries => hardware/arduino/avr/libraries}/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino (100%) rename {libraries => hardware/arduino/avr/libraries}/SPI/examples/DigitalPotControl/DigitalPotControl.ino (100%) rename {libraries/SPI/arch/avr => hardware/arduino/avr/libraries/SPI}/keywords.txt (100%) rename {libraries/SPI/arch/sam => hardware/arduino/sam/libraries/SPI}/SPI.cpp (99%) rename libraries/SPI/arch/sam/SPI_Class.h => hardware/arduino/sam/libraries/SPI/SPI.h (100%) rename {libraries/SPI/examples/BarometricPressureSensor => hardware/arduino/sam/libraries/SPI/examples}/BarometricPressureSensor/BarometricPressureSensor.ino (93%) create mode 100644 hardware/arduino/sam/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino rename {libraries/SPI/arch/sam => hardware/arduino/sam/libraries/SPI}/keywords.txt (100%) delete mode 100644 libraries/SPI/keywords.txt delete mode 100644 libraries/SPI/library.properties delete mode 100644 libraries/SPI/src/SPI.h diff --git a/libraries/SPI/arch/avr/SPI.cpp b/hardware/arduino/avr/libraries/SPI/SPI.cpp similarity index 98% rename from libraries/SPI/arch/avr/SPI.cpp rename to hardware/arduino/avr/libraries/SPI/SPI.cpp index 5a37404df..5e48073f7 100644 --- a/libraries/SPI/arch/avr/SPI.cpp +++ b/hardware/arduino/avr/libraries/SPI/SPI.cpp @@ -9,7 +9,7 @@ */ #include "pins_arduino.h" -#include "SPI_Class.h" +#include "SPI.h" SPIClass SPI; diff --git a/libraries/SPI/arch/avr/SPI_Class.h b/hardware/arduino/avr/libraries/SPI/SPI.h similarity index 100% rename from libraries/SPI/arch/avr/SPI_Class.h rename to hardware/arduino/avr/libraries/SPI/SPI.h diff --git a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/hardware/arduino/avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino similarity index 100% rename from libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino rename to hardware/arduino/avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino diff --git a/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/hardware/arduino/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino similarity index 100% rename from libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino rename to hardware/arduino/avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino diff --git a/libraries/SPI/arch/avr/keywords.txt b/hardware/arduino/avr/libraries/SPI/keywords.txt similarity index 100% rename from libraries/SPI/arch/avr/keywords.txt rename to hardware/arduino/avr/libraries/SPI/keywords.txt diff --git a/libraries/SPI/arch/sam/SPI.cpp b/hardware/arduino/sam/libraries/SPI/SPI.cpp similarity index 99% rename from libraries/SPI/arch/sam/SPI.cpp rename to hardware/arduino/sam/libraries/SPI/SPI.cpp index 565de94fc..9517e2226 100644 --- a/libraries/SPI/arch/sam/SPI.cpp +++ b/hardware/arduino/sam/libraries/SPI/SPI.cpp @@ -8,7 +8,7 @@ * published by the Free Software Foundation. */ -#include "SPI_Class.h" +#include "SPI.h" SPIClass::SPIClass(Spi *_spi, uint32_t _id, void(*_initCb)(void)) : spi(_spi), id(_id), initCb(_initCb), initialized(false) diff --git a/libraries/SPI/arch/sam/SPI_Class.h b/hardware/arduino/sam/libraries/SPI/SPI.h similarity index 100% rename from libraries/SPI/arch/sam/SPI_Class.h rename to hardware/arduino/sam/libraries/SPI/SPI.h diff --git a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor/BarometricPressureSensor.ino b/hardware/arduino/sam/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino similarity index 93% rename from libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor/BarometricPressureSensor.ino rename to hardware/arduino/sam/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino index a5c630b4a..8104fcbc2 100644 --- a/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor/BarometricPressureSensor.ino +++ b/hardware/arduino/sam/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -1,5 +1,5 @@ /* - SCP1000 Barometric Pressure Sensor Display + 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: @@ -29,8 +29,9 @@ 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 -cont byte READ = 0b00000000; // SCP1000's read command +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; @@ -87,13 +88,14 @@ void loop() { 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 - dataToSend = thisRegister & READ; - + 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: @@ -127,7 +129,7 @@ void writeRegister(byte thisRegister, byte thisValue) { // 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: - dataToSend = thisRegister | WRITE; + byte dataToSend = thisRegister | WRITE; // take the chip select low to select the device: digitalWrite(chipSelectPin, LOW); @@ -139,5 +141,3 @@ void writeRegister(byte thisRegister, byte thisValue) { digitalWrite(chipSelectPin, HIGH); } - - diff --git a/hardware/arduino/sam/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/hardware/arduino/sam/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino new file mode 100644 index 000000000..b135a74f4 --- /dev/null +++ b/hardware/arduino/sam/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/libraries/SPI/arch/sam/keywords.txt b/hardware/arduino/sam/libraries/SPI/keywords.txt similarity index 100% rename from libraries/SPI/arch/sam/keywords.txt rename to hardware/arduino/sam/libraries/SPI/keywords.txt diff --git a/libraries/SPI/keywords.txt b/libraries/SPI/keywords.txt deleted file mode 100644 index fa7616581..000000000 --- a/libraries/SPI/keywords.txt +++ /dev/null @@ -1,36 +0,0 @@ -####################################### -# 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/libraries/SPI/library.properties b/libraries/SPI/library.properties deleted file mode 100644 index 8f708548c..000000000 --- a/libraries/SPI/library.properties +++ /dev/null @@ -1,10 +0,0 @@ -name=SPI -author=cmaglie -email=Cristian Maglie -sentence=Handle communications through SPI bus -paragraph=This library implements the standard function available for the SPI bus. -url=http://arduino.cc/en/Reference/SPI -architectures=avr,sam -version=1.0 -dependencies= -core-dependencies=arduino (>=1.5.0) diff --git a/libraries/SPI/src/SPI.h b/libraries/SPI/src/SPI.h deleted file mode 100644 index e1afcb432..000000000 --- a/libraries/SPI/src/SPI.h +++ /dev/null @@ -1 +0,0 @@ -#include