From 301585f1fc02658a901ab7f71ae837b3b3f5fd76 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 9 Jun 2012 15:02:51 +0200 Subject: [PATCH] SPI library compatibility fix --- hardware/arduino/sam/libraries/SPI/SPI.cpp | 8 ++++++++ hardware/arduino/sam/libraries/SPI/SPI.h | 8 ++++---- hardware/arduino/sam/variants/arduino_due_x/variant.cpp | 2 +- hardware/arduino/sam/variants/arduino_due_x/variant.h | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/hardware/arduino/sam/libraries/SPI/SPI.cpp b/hardware/arduino/sam/libraries/SPI/SPI.cpp index a1a18123b..b9c4bfd66 100644 --- a/hardware/arduino/sam/libraries/SPI/SPI.cpp +++ b/hardware/arduino/sam/libraries/SPI/SPI.cpp @@ -19,6 +19,14 @@ SPIClass::SPIClass(Spi *_spi, uint32_t _id, void(*_initCb)(void)) : SPI_Enable(spi); } +void SPIClass::begin() { + // NPCS control is left to the user + + // Default speed set to 500Khz + setClockDivider(BOARD_SPI_DEFAULT_SS, 168); + setDataMode(BOARD_SPI_DEFAULT_SS, SPI_MODE0); +} + void SPIClass::begin(uint8_t _pin) { uint32_t spiPin = BOARD_PIN_TO_SPI_PIN(_pin); PIO_Configure( diff --git a/hardware/arduino/sam/libraries/SPI/SPI.h b/hardware/arduino/sam/libraries/SPI/SPI.h index 2e1acf1b1..093d12de5 100644 --- a/hardware/arduino/sam/libraries/SPI/SPI.h +++ b/hardware/arduino/sam/libraries/SPI/SPI.h @@ -28,7 +28,7 @@ class SPIClass { public: SPIClass(Spi *_spi, uint32_t _id, void(*_initCb)(void)); - //byte transfer(uint8_t _data, SPITransferMode _mode = SPI_LAST) { transfer(BOARD_PIN_SS_DEFAULT, _data, _mode); } + byte transfer(uint8_t _data, SPITransferMode _mode = SPI_LAST) { return transfer(BOARD_SPI_DEFAULT_SS, _data, _mode); } byte transfer(byte _channel, uint8_t _data, SPITransferMode _mode = SPI_LAST); // SPI Configuration methods @@ -37,7 +37,7 @@ class SPIClass { void detachInterrupt(void); void begin(uint8_t _channel); - //void begin(void) { begin(BOARD_PIN_SS_DEFAULT); }; + void begin(void); void end(void); // These methods sets a parameter on a single pin @@ -47,8 +47,8 @@ class SPIClass { // These methods sets the same parameters but on default pin PIN_SPI_SS_DEFAULT //void setBitOrder(uint8_t _order) { setBitOrder(PIN_SPI_SS_DEFAULT, _order); }; - //void setDataMode(uint8_t _mode) { setDataMode(BOARD_PIN_SS_DEFAULT, _mode); }; - //void setClockDivider(uint8_t _div) { setClockDivider(BOARD_PIN_SS_DEFAULT, _div); }; + void setDataMode(uint8_t _mode) { setDataMode(BOARD_SPI_DEFAULT_SS, _mode); }; + void setClockDivider(uint8_t _div) { setClockDivider(BOARD_SPI_DEFAULT_SS, _div); }; private: Spi *spi; diff --git a/hardware/arduino/sam/variants/arduino_due_x/variant.cpp b/hardware/arduino/sam/variants/arduino_due_x/variant.cpp index 07a274dfc..806f7446a 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/variant.cpp +++ b/hardware/arduino/sam/variants/arduino_due_x/variant.cpp @@ -102,7 +102,7 @@ * SO | PA25 * SI | PA26 * SCK | PA27 - * #CS SS3 | PB23 + * #CS NPCS3 | PB23 * * * USB pin | PORT diff --git a/hardware/arduino/sam/variants/arduino_due_x/variant.h b/hardware/arduino/sam/variants/arduino_due_x/variant.h index 1f662a948..2ba898ca0 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/variant.h +++ b/hardware/arduino/sam/variants/arduino_due_x/variant.h @@ -96,7 +96,7 @@ extern "C"{ #define BOARD_SPI_SS1 (4u) #define BOARD_SPI_SS2 (52u) #define BOARD_SPI_SS3 PIN_SPI_SS3 -#define BOARD_PIN_SS_DEFAULT BOARD_SPI_SS2 +#define BOARD_SPI_DEFAULT_SS BOARD_SPI_SS2 #define BOARD_PIN_TO_SPI_PIN(x) \ (x==BOARD_SPI_SS0 ? PIN_SPI_SS0 : \