|
@ -36,20 +36,14 @@ |
|
|
// Includes
|
|
|
// Includes
|
|
|
// --------------------------------------------------------------------------
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
#include "HAL.h" |
|
|
#include "../../inc/MarlinConfig.h" |
|
|
#include "../shared/HAL_SPI.h" |
|
|
|
|
|
#include "pins_arduino.h" |
|
|
|
|
|
#include "spi_pins.h" |
|
|
|
|
|
#include <SPI.h> |
|
|
#include <SPI.h> |
|
|
|
|
|
|
|
|
#include "../../inc/MarlinConfigPre.h" |
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
// --------------------------------------------------------------------------
|
|
|
// Public Variables
|
|
|
// Public Variables
|
|
|
// --------------------------------------------------------------------------
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
static SPISettings spiConfig; |
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
// --------------------------------------------------------------------------
|
|
|
// Public functions
|
|
|
// Public functions
|
|
|
// --------------------------------------------------------------------------
|
|
|
// --------------------------------------------------------------------------
|
|
@ -82,8 +76,7 @@ void spiBegin() { |
|
|
#if !PIN_EXISTS(SS) |
|
|
#if !PIN_EXISTS(SS) |
|
|
#error "SS_PIN not defined!" |
|
|
#error "SS_PIN not defined!" |
|
|
#endif |
|
|
#endif |
|
|
SET_OUTPUT(SS_PIN); |
|
|
OUT_WRITE(SS_PIN, HIGH); |
|
|
WRITE(SS_PIN, HIGH); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -105,8 +98,11 @@ void spiInit(uint8_t spiRate) { |
|
|
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break; |
|
|
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break; |
|
|
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
|
|
|
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
|
|
|
} |
|
|
} |
|
|
spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0); |
|
|
SPI.setModule(SPI_DEVICE); |
|
|
SPI.begin(); |
|
|
SPI.begin(); |
|
|
|
|
|
SPI.setClockDivider(clock); |
|
|
|
|
|
SPI.setBitOrder(MSBFIRST); |
|
|
|
|
|
SPI.setDataMode(SPI_MODE0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -117,9 +113,9 @@ void spiInit(uint8_t spiRate) { |
|
|
* @details |
|
|
* @details |
|
|
*/ |
|
|
*/ |
|
|
uint8_t spiRec(void) { |
|
|
uint8_t spiRec(void) { |
|
|
SPI.beginTransaction(spiConfig); |
|
|
WRITE(SS_PIN, LOW); |
|
|
uint8_t returnByte = SPI.transfer(0xFF); |
|
|
uint8_t returnByte = SPI.transfer(0xFF); |
|
|
SPI.endTransaction(); |
|
|
WRITE(SS_PIN, HIGH); |
|
|
return returnByte; |
|
|
return returnByte; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -133,9 +129,9 @@ uint8_t spiRec(void) { |
|
|
* @details Uses DMA |
|
|
* @details Uses DMA |
|
|
*/ |
|
|
*/ |
|
|
void spiRead(uint8_t* buf, uint16_t nbyte) { |
|
|
void spiRead(uint8_t* buf, uint16_t nbyte) { |
|
|
SPI.beginTransaction(spiConfig); |
|
|
WRITE(SS_PIN, LOW); |
|
|
SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte); |
|
|
SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte); |
|
|
SPI.endTransaction(); |
|
|
WRITE(SS_PIN, HIGH); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -146,9 +142,9 @@ void spiRead(uint8_t* buf, uint16_t nbyte) { |
|
|
* @details |
|
|
* @details |
|
|
*/ |
|
|
*/ |
|
|
void spiSend(uint8_t b) { |
|
|
void spiSend(uint8_t b) { |
|
|
SPI.beginTransaction(spiConfig); |
|
|
WRITE(SS_PIN, LOW); |
|
|
SPI.send(b); |
|
|
SPI.send(b); |
|
|
SPI.endTransaction(); |
|
|
WRITE(SS_PIN, HIGH); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -160,25 +156,10 @@ void spiSend(uint8_t b) { |
|
|
* @details Use DMA |
|
|
* @details Use DMA |
|
|
*/ |
|
|
*/ |
|
|
void spiSendBlock(uint8_t token, const uint8_t* buf) { |
|
|
void spiSendBlock(uint8_t token, const uint8_t* buf) { |
|
|
SPI.beginTransaction(spiConfig); |
|
|
WRITE(SS_PIN, LOW); |
|
|
SPI.send(token); |
|
|
SPI.send(token); |
|
|
SPI.dmaSend(const_cast<uint8_t*>(buf), 512); |
|
|
SPI.dmaSend(const_cast<uint8_t*>(buf), 512); |
|
|
SPI.endTransaction(); |
|
|
WRITE(SS_PIN, HIGH); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Begin SPI transaction, set clock, bit order, data mode |
|
|
|
|
|
* |
|
|
|
|
|
* @param spiClock Clock setting |
|
|
|
|
|
* @param bitOrder Bit Order setting |
|
|
|
|
|
* @param dataMode Data Mode setting |
|
|
|
|
|
* @return Nothing |
|
|
|
|
|
* |
|
|
|
|
|
* @details Uses an SPI Config via SPISettings |
|
|
|
|
|
*/ |
|
|
|
|
|
void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) { |
|
|
|
|
|
spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode); |
|
|
|
|
|
SPI.beginTransaction(spiConfig); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#if ENABLED(SPI_EEPROM) |
|
|
#if ENABLED(SPI_EEPROM) |
|
|