mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
Fix in sam SPI library initialization when using multiple CS (extended API).
http://forum.arduino.cc/index.php?topic=189682.0
This commit is contained in:
parent
ca90bf75cb
commit
b0dc317422
@ -4,6 +4,7 @@ ARDUINO 1.5.5 BETA
|
||||
[libraries]
|
||||
* avr: Fixed buffer overflow in File::doBuffer() (dreggy)
|
||||
* avr: Fixed timeout in Bridge::transfer()
|
||||
* sam: Fixed SPI initialization (when using extended API and multiple CS)
|
||||
|
||||
ARDUINO 1.5.4 BETA 2013.09.10
|
||||
|
||||
|
@ -11,15 +11,13 @@
|
||||
#include "SPI_Class.h"
|
||||
|
||||
SPIClass::SPIClass(Spi *_spi, uint32_t _id, void(*_initCb)(void)) :
|
||||
spi(_spi), id(_id), initCb(_initCb)
|
||||
spi(_spi), id(_id), initCb(_initCb), initialized(false)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
void SPIClass::begin() {
|
||||
initCb();
|
||||
SPI_Configure(spi, id, SPI_MR_MSTR | SPI_MR_PS | SPI_MR_MODFDIS);
|
||||
SPI_Enable(spi);
|
||||
init();
|
||||
|
||||
// NPCS control is left to the user
|
||||
|
||||
@ -30,9 +28,7 @@ void SPIClass::begin() {
|
||||
}
|
||||
|
||||
void SPIClass::begin(uint8_t _pin) {
|
||||
initCb();
|
||||
SPI_Configure(spi, id, SPI_MR_MSTR | SPI_MR_PS | SPI_MR_MODFDIS);
|
||||
SPI_Enable(spi);
|
||||
init();
|
||||
|
||||
uint32_t spiPin = BOARD_PIN_TO_SPI_PIN(_pin);
|
||||
PIO_Configure(
|
||||
@ -47,6 +43,15 @@ void SPIClass::begin(uint8_t _pin) {
|
||||
setBitOrder(_pin, MSBFIRST);
|
||||
}
|
||||
|
||||
void SPIClass::init() {
|
||||
if (initialized)
|
||||
return;
|
||||
initCb();
|
||||
SPI_Configure(spi, id, SPI_MR_MSTR | SPI_MR_PS | SPI_MR_MODFDIS);
|
||||
SPI_Enable(spi);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void SPIClass::end(uint8_t _pin) {
|
||||
uint32_t spiPin = BOARD_PIN_TO_SPI_PIN(_pin);
|
||||
// Setting the pin as INPUT will disconnect it from SPI peripheral
|
||||
@ -55,6 +60,7 @@ void SPIClass::end(uint8_t _pin) {
|
||||
|
||||
void SPIClass::end() {
|
||||
SPI_Disable(spi);
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
void SPIClass::setBitOrder(uint8_t _pin, BitOrder _bitOrder) {
|
||||
|
@ -54,12 +54,15 @@ class SPIClass {
|
||||
void setClockDivider(uint8_t _div) { setClockDivider(BOARD_SPI_DEFAULT_SS, _div); };
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
Spi *spi;
|
||||
uint32_t id;
|
||||
BitOrder bitOrder[SPI_CHANNELS_NUM];
|
||||
uint32_t divider[SPI_CHANNELS_NUM];
|
||||
uint32_t mode[SPI_CHANNELS_NUM];
|
||||
void (*initCb)(void);
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
#if SPI_INTERFACES_COUNT > 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user