mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-20 21:01:25 +03:00
Some Due pins are connected to both PWM and SPI pins on SAM3X. This patch fix SPI side.
This commit is contained in:
@ -15,18 +15,17 @@ SPIClass::SPIClass(Spi *_spi, uint32_t _id, void(*_initCb)(void)) :
|
|||||||
{
|
{
|
||||||
initCb();
|
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);
|
SPI_Enable(spi);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPIClass::begin(uint8_t _pin) {
|
void SPIClass::begin(uint8_t _pin) {
|
||||||
if (_pin == 0)
|
uint32_t spiPin = BOARD_PIN_TO_SPI_PIN(_pin);
|
||||||
return;
|
|
||||||
PIO_Configure(
|
PIO_Configure(
|
||||||
g_APinDescription[_pin].pPort,
|
g_APinDescription[spiPin].pPort,
|
||||||
g_APinDescription[_pin].ulPinType,
|
g_APinDescription[spiPin].ulPinType,
|
||||||
g_APinDescription[_pin].ulPin,
|
g_APinDescription[spiPin].ulPin,
|
||||||
g_APinDescription[_pin].ulPinConfiguration);
|
g_APinDescription[spiPin].ulPinConfiguration);
|
||||||
setClockDivider(_pin, 1);
|
setClockDivider(_pin, 1);
|
||||||
setDataMode(_pin, SPI_MODE0);
|
setDataMode(_pin, SPI_MODE0);
|
||||||
}
|
}
|
||||||
@ -40,19 +39,19 @@ void SPIClass::end() {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
void SPIClass::setDataMode(uint8_t _pin, uint8_t _mode) {
|
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;
|
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) {
|
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;
|
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) {
|
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);
|
uint32_t d = _data | SPI_PCS(_channel);
|
||||||
if (_mode == SPI_LAST)
|
if (_mode == SPI_LAST)
|
||||||
d |= SPI_TDR_LASTXFER;
|
d |= SPI_TDR_LASTXFER;
|
||||||
|
@ -28,7 +28,7 @@ class SPIClass {
|
|||||||
public:
|
public:
|
||||||
SPIClass(Spi *_spi, uint32_t _id, void(*_initCb)(void));
|
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);
|
byte transfer(byte _channel, uint8_t _data, SPITransferMode _mode = SPI_LAST);
|
||||||
|
|
||||||
// SPI Configuration methods
|
// SPI Configuration methods
|
||||||
@ -37,7 +37,7 @@ class SPIClass {
|
|||||||
void detachInterrupt(void);
|
void detachInterrupt(void);
|
||||||
|
|
||||||
void begin(uint8_t _channel);
|
void begin(uint8_t _channel);
|
||||||
void begin(void) { begin(PIN_SPI_SS_DEFAULT); };
|
//void begin(void) { begin(BOARD_PIN_SS_DEFAULT); };
|
||||||
void end(void);
|
void end(void);
|
||||||
|
|
||||||
// These methods sets a parameter on a single pin
|
// 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
|
// 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 setBitOrder(uint8_t _order) { setBitOrder(PIN_SPI_SS_DEFAULT, _order); };
|
||||||
void setDataMode(uint8_t _mode) { setDataMode(PIN_SPI_SS_DEFAULT, _mode); };
|
//void setDataMode(uint8_t _mode) { setDataMode(BOARD_PIN_SS_DEFAULT, _mode); };
|
||||||
void setClockDivider(uint8_t _div) { setClockDivider(PIN_SPI_SS_DEFAULT, _div); };
|
//void setClockDivider(uint8_t _div) { setClockDivider(BOARD_PIN_SS_DEFAULT, _div); };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Spi *spi;
|
Spi *spi;
|
||||||
|
@ -26,12 +26,14 @@
|
|||||||
* 2 TIOA0 | PB25
|
* 2 TIOA0 | PB25
|
||||||
* 3 TIOA7 | PC28
|
* 3 TIOA7 | PC28
|
||||||
* 4 NPCS1 | PA29
|
* 4 NPCS1 | PA29
|
||||||
|
* TIOB6 | PC26
|
||||||
* 5 TIOA6 | PC25
|
* 5 TIOA6 | PC25
|
||||||
* 6 PWML7 | PC24
|
* 6 PWML7 | PC24
|
||||||
* 7 PWML6 | PC23
|
* 7 PWML6 | PC23
|
||||||
* 8 PWML5 | PC22
|
* 8 PWML5 | PC22
|
||||||
* 9 PWML4 | PC21
|
* 9 PWML4 | PC21
|
||||||
* 10 TIOB7 | PC29
|
* 10 NPCS0 | PA28
|
||||||
|
* TIOB7 | PC29
|
||||||
* 11 TIOA8 | PD7
|
* 11 TIOA8 | PD7
|
||||||
* 12 TIOB8 | PD8
|
* 12 TIOB8 | PD8
|
||||||
* 13 TIOB0 | PB27
|
* 13 TIOB0 | PB27
|
||||||
@ -73,7 +75,7 @@
|
|||||||
* 49 | PC14
|
* 49 | PC14
|
||||||
* 50 | PC13
|
* 50 | PC13
|
||||||
* 51 | PC12
|
* 51 | PC12
|
||||||
* 52 | PB21
|
* 52 NPCS2 | PB21
|
||||||
* 53 | PB14
|
* 53 | PB14
|
||||||
* A0 | PA16
|
* A0 | PA16
|
||||||
* A1 | PA24
|
* A1 | PA24
|
||||||
@ -135,7 +137,7 @@ extern const PinDescription g_APinDescription[]=
|
|||||||
// 2
|
// 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
|
{ 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
|
{ 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
|
// 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
|
{ 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
|
// 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
|
{ 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
|
// END
|
||||||
{ NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, 0, NO_ADC, NO_ADC, NO_PWM, NO_TC }
|
{ NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, 0, NO_ADC, NO_ADC, NO_PWM, NO_TC }
|
||||||
} ;
|
} ;
|
||||||
|
@ -67,7 +67,7 @@ extern "C"{
|
|||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// Number of pins defined in PinDescription array
|
// Number of pins defined in PinDescription array
|
||||||
#define PINS_COUNT (84u)
|
#define PINS_COUNT (88u)
|
||||||
|
|
||||||
// LEDs
|
// LEDs
|
||||||
#define PIN_LED_13 (13u)
|
#define PIN_LED_13 (13u)
|
||||||
@ -86,19 +86,31 @@ extern "C"{
|
|||||||
#define SPI_INTERFACE_ID ID_SPI0
|
#define SPI_INTERFACE_ID ID_SPI0
|
||||||
#define SPI_CHANNELS_NUM 4
|
#define SPI_CHANNELS_NUM 4
|
||||||
#define PIN_SPI_SS0 (77u)
|
#define PIN_SPI_SS0 (77u)
|
||||||
#define PIN_SPI_SS1 (4u)
|
#define PIN_SPI_SS1 (87u)
|
||||||
#define PIN_SPI_SS2 (0u)
|
#define PIN_SPI_SS2 (86u)
|
||||||
#define PIN_SPI_SS3 (78u)
|
#define PIN_SPI_SS3 (78u)
|
||||||
#define PIN_SPI_SS_DEFAULT PIN_SPI_SS2
|
|
||||||
#define PIN_SPI_MOSI (75u)
|
#define PIN_SPI_MOSI (75u)
|
||||||
#define PIN_SPI_MISO (74u)
|
#define PIN_SPI_MISO (74u)
|
||||||
#define PIN_SPI_SCK (76u)
|
#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 ;
|
#define BOARD_PIN_TO_SPI_PIN(x) \
|
||||||
static const uint8_t SS1 = PIN_SPI_SS1 ;
|
(x==BOARD_SPI_SS0 ? PIN_SPI_SS0 : \
|
||||||
static const uint8_t SS2 = PIN_SPI_SS2 ;
|
(x==BOARD_SPI_SS1 ? PIN_SPI_SS1 : \
|
||||||
static const uint8_t SS3 = PIN_SPI_SS3 ;
|
(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 MOSI = PIN_SPI_MOSI ;
|
||||||
static const uint8_t MISO = PIN_SPI_MISO ;
|
static const uint8_t MISO = PIN_SPI_MISO ;
|
||||||
static const uint8_t SCK = PIN_SPI_SCK ;
|
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||||
|
Reference in New Issue
Block a user