mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-18 12:54:25 +01:00
SPI: Removed methods that sets params for all channels. Added default PIN (unconnected on Due Board).
This commit is contained in:
parent
3062c550b0
commit
31402570fe
@ -17,54 +17,34 @@ SPIClass::SPIClass(Spi *_spi, uint32_t _id, void(*_initCb)(void)) :
|
||||
|
||||
SPI_Configure(spi, id, SPI_MR_MSTR | SPI_MR_PS);
|
||||
SPI_Enable(spi);
|
||||
setClockDivider(1);
|
||||
setDataMode(SPI_MODE0);
|
||||
}
|
||||
|
||||
void SPIClass::begin(uint8_t _pin) {
|
||||
if (_pin == 0)
|
||||
return;
|
||||
PIO_Configure(g_APinDescription[_pin].pPort,
|
||||
PIO_Configure(
|
||||
g_APinDescription[_pin].pPort,
|
||||
g_APinDescription[_pin].ulPinType,
|
||||
g_APinDescription[_pin].ulPin,
|
||||
g_APinDescription[_pin].ulPinConfiguration);
|
||||
setClockDivider(_pin, 1);
|
||||
setDataMode(_pin, SPI_MODE0);
|
||||
}
|
||||
|
||||
void SPIClass::end() {
|
||||
SPI_Disable(spi);
|
||||
}
|
||||
|
||||
//void SPIClass::setBitOrder(uint8_t bitOrder) {
|
||||
// setBitOrder(bitOrder, 0);
|
||||
// setBitOrder(bitOrder, 1);
|
||||
// setBitOrder(bitOrder, 2);
|
||||
// setBitOrder(bitOrder, 3);
|
||||
//}
|
||||
|
||||
//void SPIClass::setBitOrder(uint8_t bitOrder, uint8_t _channel) {
|
||||
//void SPIClass::setBitOrder(uint8_t _bitOrder, uint8_t _channel) {
|
||||
// // Not supported
|
||||
//}
|
||||
|
||||
void SPIClass::setDataMode(uint8_t _mode) {
|
||||
setDataMode(PIN_SPI_SS0, _mode);
|
||||
setDataMode(PIN_SPI_SS1, _mode);
|
||||
setDataMode(PIN_SPI_SS2, _mode);
|
||||
setDataMode(PIN_SPI_SS3, _mode);
|
||||
}
|
||||
|
||||
void SPIClass::setDataMode(uint8_t _pin, uint8_t _mode) {
|
||||
uint32_t _channel = SPI_PIN_TO_SPI_CHANNEL(_pin);
|
||||
mode[_channel] = _mode | SPI_CSR_CSAAT;
|
||||
SPI_ConfigureNPCS(spi, _channel, mode[_channel] | SPI_CSR_SCBR(divider[_channel]));
|
||||
}
|
||||
|
||||
void SPIClass::setClockDivider(uint8_t _divider) {
|
||||
setClockDivider(PIN_SPI_SS0, _divider);
|
||||
setClockDivider(PIN_SPI_SS1, _divider);
|
||||
setClockDivider(PIN_SPI_SS2, _divider);
|
||||
setClockDivider(PIN_SPI_SS3, _divider);
|
||||
}
|
||||
|
||||
void SPIClass::setClockDivider(uint8_t _pin, uint8_t _divider) {
|
||||
uint32_t _channel = SPI_PIN_TO_SPI_CHANNEL(_pin);
|
||||
divider[_channel] = _divider;
|
||||
@ -99,15 +79,18 @@ void SPIClass::detachInterrupt(void) {
|
||||
|
||||
#if SPI_INTERFACES_COUNT > 0
|
||||
static void SPI_0_Init(void) {
|
||||
PIO_Configure(g_APinDescription[PIN_SPI_MOSI].pPort,
|
||||
PIO_Configure(
|
||||
g_APinDescription[PIN_SPI_MOSI].pPort,
|
||||
g_APinDescription[PIN_SPI_MOSI].ulPinType,
|
||||
g_APinDescription[PIN_SPI_MOSI].ulPin,
|
||||
g_APinDescription[PIN_SPI_MOSI].ulPinConfiguration);
|
||||
PIO_Configure(g_APinDescription[PIN_SPI_MISO].pPort,
|
||||
PIO_Configure(
|
||||
g_APinDescription[PIN_SPI_MISO].pPort,
|
||||
g_APinDescription[PIN_SPI_MISO].ulPinType,
|
||||
g_APinDescription[PIN_SPI_MISO].ulPin,
|
||||
g_APinDescription[PIN_SPI_MISO].ulPinConfiguration);
|
||||
PIO_Configure(g_APinDescription[PIN_SPI_SCK].pPort,
|
||||
PIO_Configure(
|
||||
g_APinDescription[PIN_SPI_SCK].pPort,
|
||||
g_APinDescription[PIN_SPI_SCK].ulPinType,
|
||||
g_APinDescription[PIN_SPI_SCK].ulPin,
|
||||
g_APinDescription[PIN_SPI_SCK].ulPinConfiguration);
|
||||
|
@ -28,6 +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(byte _channel, uint8_t _data, SPITransferMode _mode = SPI_LAST);
|
||||
|
||||
// SPI Configuration methods
|
||||
@ -36,18 +37,19 @@ class SPIClass {
|
||||
void detachInterrupt(void);
|
||||
|
||||
void begin(uint8_t _channel);
|
||||
void begin(void) { begin(PIN_SPI_SS_DEFAULT); };
|
||||
void end(void);
|
||||
|
||||
// These methods sets the same parameters on all channels
|
||||
//void setBitOrder(uint8_t);
|
||||
void setDataMode(uint8_t);
|
||||
void setClockDivider(uint8_t);
|
||||
|
||||
// These methods sets a parameter on a single channel
|
||||
// void setBitOrder(uint8_t _channel, uint8_t);
|
||||
// These methods sets a parameter on a single pin
|
||||
//void setBitOrder(uint8_t _channel, uint8_t);
|
||||
void setDataMode(uint8_t _channel, uint8_t);
|
||||
void setClockDivider(uint8_t _channel, uint8_t);
|
||||
|
||||
// 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); };
|
||||
|
||||
private:
|
||||
Spi *spi;
|
||||
uint32_t id;
|
||||
|
@ -6,16 +6,18 @@
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// Start SPI with FLASH device
|
||||
SPI.begin(FLASH);
|
||||
SPI.setClockDivider(2); // We are too fast with 1
|
||||
// Half clock speed: we are too fast with 1
|
||||
SPI.setClockDivider(FLASH, 2);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println("Sending 'Identify' cmd to flash => 9F");
|
||||
|
||||
// Send "identify" command (9f) and receive response
|
||||
// on the same SPI transaction. Parameter SPI_CONTINUE
|
||||
// keeps the SS pin active.
|
||||
Serial.println("Sending 'Identify' cmd to flash => 9F");
|
||||
SPI.transfer(FLASH, 0x9f, SPI_CONTINUE);
|
||||
char a1 = SPI.transfer(FLASH, 0x00, SPI_CONTINUE);
|
||||
char a2 = SPI.transfer(FLASH, 0x00, SPI_CONTINUE);
|
||||
@ -30,5 +32,6 @@ void loop() {
|
||||
Serial.print(a3, HEX);
|
||||
Serial.print(a4, HEX);
|
||||
Serial.println(a5, HEX);
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ extern "C"{
|
||||
#define PIN_SPI_SS1 (4u)
|
||||
#define PIN_SPI_SS2 (0u)
|
||||
#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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user