1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Some Due pins are connected to both PWM and SPI pins on SAM3X. This patch fix SPI side.

This commit is contained in:
Cristian Maglie 2012-06-08 22:34:38 +02:00
parent e43dcd8bed
commit 22e24fd5e0
4 changed files with 47 additions and 28 deletions

View File

@ -15,18 +15,17 @@ SPIClass::SPIClass(Spi *_spi, uint32_t _id, void(*_initCb)(void)) :
{
initCb();
SPI_Configure(spi, id, SPI_MR_MSTR | SPI_MR_PS);
SPI_Configure(spi, id, SPI_MR_MSTR | SPI_MR_PS | SPI_MR_MODFDIS);
SPI_Enable(spi);
}
void SPIClass::begin(uint8_t _pin) {
if (_pin == 0)
return;
uint32_t spiPin = BOARD_PIN_TO_SPI_PIN(_pin);
PIO_Configure(
g_APinDescription[_pin].pPort,
g_APinDescription[_pin].ulPinType,
g_APinDescription[_pin].ulPin,
g_APinDescription[_pin].ulPinConfiguration);
g_APinDescription[spiPin].pPort,
g_APinDescription[spiPin].ulPinType,
g_APinDescription[spiPin].ulPin,
g_APinDescription[spiPin].ulPinConfiguration);
setClockDivider(_pin, 1);
setDataMode(_pin, SPI_MODE0);
}
@ -40,19 +39,19 @@ void SPIClass::end() {
//}
void SPIClass::setDataMode(uint8_t _pin, uint8_t _mode) {
uint32_t _channel = SPI_PIN_TO_SPI_CHANNEL(_pin);
uint32_t _channel = BOARD_PIN_TO_SPI_CHANNEL(_pin);
mode[_channel] = _mode | SPI_CSR_CSAAT;
SPI_ConfigureNPCS(spi, _channel, mode[_channel] | SPI_CSR_SCBR(divider[_channel]));
SPI_ConfigureNPCS(spi, _channel, mode[_channel] | SPI_CSR_SCBR(divider[_channel]) | SPI_CSR_DLYBCT(1));
}
void SPIClass::setClockDivider(uint8_t _pin, uint8_t _divider) {
uint32_t _channel = SPI_PIN_TO_SPI_CHANNEL(_pin);
uint32_t _channel = BOARD_PIN_TO_SPI_CHANNEL(_pin);
divider[_channel] = _divider;
SPI_ConfigureNPCS(spi, _channel, mode[_channel] | SPI_CSR_SCBR(divider[_channel]));
SPI_ConfigureNPCS(spi, _channel, mode[_channel] | SPI_CSR_SCBR(divider[_channel]) | SPI_CSR_DLYBCT(1));
}
byte SPIClass::transfer(byte _pin, uint8_t _data, SPITransferMode _mode) {
uint32_t _channel = SPI_PIN_TO_SPI_CHANNEL(_pin);
uint32_t _channel = BOARD_PIN_TO_SPI_CHANNEL(_pin);
uint32_t d = _data | SPI_PCS(_channel);
if (_mode == SPI_LAST)
d |= SPI_TDR_LASTXFER;

View File

@ -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(PIN_SPI_SS_DEFAULT, _data, _mode); }
//byte transfer(uint8_t _data, SPITransferMode _mode = SPI_LAST) { transfer(BOARD_PIN_SS_DEFAULT, _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(PIN_SPI_SS_DEFAULT); };
//void begin(void) { begin(BOARD_PIN_SS_DEFAULT); };
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(PIN_SPI_SS_DEFAULT, _mode); };
void setClockDivider(uint8_t _div) { setClockDivider(PIN_SPI_SS_DEFAULT, _div); };
//void setDataMode(uint8_t _mode) { setDataMode(BOARD_PIN_SS_DEFAULT, _mode); };
//void setClockDivider(uint8_t _div) { setClockDivider(BOARD_PIN_SS_DEFAULT, _div); };
private:
Spi *spi;

View File

@ -26,12 +26,14 @@
* 2 TIOA0 | PB25
* 3 TIOA7 | PC28
* 4 NPCS1 | PA29
* TIOB6 | PC26
* 5 TIOA6 | PC25
* 6 PWML7 | PC24
* 7 PWML6 | PC23
* 8 PWML5 | PC22
* 9 PWML4 | PC21
* 10 TIOB7 | PC29
* 10 NPCS0 | PA28
* TIOB7 | PC29
* 11 TIOA8 | PD7
* 12 TIOB8 | PD8
* 13 TIOB0 | PB27
@ -73,7 +75,7 @@
* 49 | PC14
* 50 | PC13
* 51 | PC12
* 52 | PB21
* 52 NPCS2 | PB21
* 53 | PB14
* A0 | PA16
* A1 | PA24
@ -135,7 +137,7 @@ extern const PinDescription g_APinDescription[]=
// 2
{ PIOB, PIO_PB25B_TIOA0, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NO_PWM, TC0_CHA0 }, // TIOA0
{ PIOC, PIO_PC28B_TIOA7, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NO_PWM, TC2_CHA7 }, // TIOA7
{ PIOA, PIO_PA29A_SPI0_NPCS1,ID_PIOA,PIO_PERIPH_A,PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC }, // NPCS1
{ PIOC, PIO_PC26B_TIOB6, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NO_PWM, TC2_CHB6 }, // TIOB6
// 5
{ PIOC, PIO_PC25B_TIOA6, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NO_PWM, TC0_CHA2 }, // TIOA6
@ -275,6 +277,12 @@ extern const PinDescription g_APinDescription[]=
// 85 - USB
{ PIOB, PIO_PB11A_UOTGID|PIO_PB10A_UOTGVBOF, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL,NO_ADC, NO_ADC, NO_PWM, NO_TC }, // ID - VBOF
// 86 - SPI CS2
{ PIOB, PIO_PB21B_SPI0_NPCS2, ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC }, // NPCS2
// 87 - SPI CS1
{ PIOA, PIO_PA29A_SPI0_NPCS1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL, NO_ADC, NO_ADC, NO_PWM, NO_TC }, // NPCS1
// END
{ NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, 0, NO_ADC, NO_ADC, NO_PWM, NO_TC }
} ;

View File

@ -67,7 +67,7 @@ extern "C"{
*----------------------------------------------------------------------------*/
// Number of pins defined in PinDescription array
#define PINS_COUNT (84u)
#define PINS_COUNT (88u)
// LEDs
#define PIN_LED_13 (13u)
@ -86,19 +86,31 @@ extern "C"{
#define SPI_INTERFACE_ID ID_SPI0
#define SPI_CHANNELS_NUM 4
#define PIN_SPI_SS0 (77u)
#define PIN_SPI_SS1 (4u)
#define PIN_SPI_SS2 (0u)
#define PIN_SPI_SS1 (87u)
#define PIN_SPI_SS2 (86u)
#define PIN_SPI_SS3 (78u)
#define PIN_SPI_SS_DEFAULT PIN_SPI_SS2
#define PIN_SPI_MOSI (75u)
#define PIN_SPI_MISO (74u)
#define PIN_SPI_SCK (76u)
#define SPI_PIN_TO_SPI_CHANNEL(x) (x==PIN_SPI_SS0 ? 0 : (x==PIN_SPI_SS1 ? 1 : (x==PIN_SPI_SS2 ? 2 : 3)))
#define BOARD_SPI_SS0 (10u)
#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
static const uint8_t SS = PIN_SPI_SS0 ;
static const uint8_t SS1 = PIN_SPI_SS1 ;
static const uint8_t SS2 = PIN_SPI_SS2 ;
static const uint8_t SS3 = PIN_SPI_SS3 ;
#define BOARD_PIN_TO_SPI_PIN(x) \
(x==BOARD_SPI_SS0 ? PIN_SPI_SS0 : \
(x==BOARD_SPI_SS1 ? PIN_SPI_SS1 : \
(x==BOARD_SPI_SS2 ? PIN_SPI_SS2 : PIN_SPI_SS3 )))
#define BOARD_PIN_TO_SPI_CHANNEL(x) \
(x==BOARD_SPI_SS0 ? 0 : \
(x==BOARD_SPI_SS1 ? 1 : \
(x==BOARD_SPI_SS2 ? 2 : 3)))
static const uint8_t SS = BOARD_SPI_SS0 ;
static const uint8_t SS1 = BOARD_SPI_SS1 ;
static const uint8_t SS2 = BOARD_SPI_SS2 ;
static const uint8_t SS3 = BOARD_SPI_SS3 ;
static const uint8_t MOSI = PIN_SPI_MOSI ;
static const uint8_t MISO = PIN_SPI_MISO ;
static const uint8_t SCK = PIN_SPI_SCK ;