|
|
@ -1,3 +1,24 @@
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
|
|
|
|
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
|
|
|
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
|
|
|
|
|
|
|
|
|
|
|
#include "HAL.h"
|
|
|
|
#include "HAL.h"
|
|
|
@ -8,32 +29,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
static SPISettings spiConfig;
|
|
|
|
static SPISettings spiConfig;
|
|
|
|
|
|
|
|
|
|
|
|
// Standard SPI functions
|
|
|
|
|
|
|
|
/** Initialize SPI bus */
|
|
|
|
|
|
|
|
void spiBegin(void) {
|
|
|
|
void spiBegin(void) {
|
|
|
|
#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);
|
|
|
|
|
|
|
|
SET_OUTPUT(SCK_PIN);
|
|
|
|
SET_OUTPUT(SCK_PIN);
|
|
|
|
SET_INPUT(MISO_PIN);
|
|
|
|
SET_INPUT(MISO_PIN);
|
|
|
|
SET_OUTPUT(MOSI_PIN);
|
|
|
|
SET_OUTPUT(MOSI_PIN);
|
|
|
|
|
|
|
|
|
|
|
|
//#if DISABLED(SOFTWARE_SPI)
|
|
|
|
#if 0 && DISABLED(SOFTWARE_SPI)
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
// set SS high - may be chip select for another SPI device
|
|
|
|
// set SS high - may be chip select for another SPI device
|
|
|
|
#if SET_SPI_SS_HIGH
|
|
|
|
#if SET_SPI_SS_HIGH
|
|
|
|
WRITE(SS_PIN, HIGH);
|
|
|
|
WRITE(SS_PIN, HIGH);
|
|
|
|
#endif // SET_SPI_SS_HIGH
|
|
|
|
#endif
|
|
|
|
// set a default rate
|
|
|
|
// set a default rate
|
|
|
|
spiInit(SPI_HALF_SPEED); // 1
|
|
|
|
spiInit(SPI_HALF_SPEED); // 1
|
|
|
|
#endif // SOFTWARE_SPI
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Configure SPI for specified SPI speed */
|
|
|
|
|
|
|
|
void spiInit(uint8_t spiRate) {
|
|
|
|
void spiInit(uint8_t spiRate) {
|
|
|
|
// Use datarates Marlin uses
|
|
|
|
// Use Marlin data-rates
|
|
|
|
uint32_t clock;
|
|
|
|
uint32_t clock;
|
|
|
|
switch (spiRate) {
|
|
|
|
switch (spiRate) {
|
|
|
|
case SPI_FULL_SPEED: clock = 10000000; break;
|
|
|
|
case SPI_FULL_SPEED: clock = 10000000; break;
|
|
|
@ -49,44 +65,39 @@ void spiInit(uint8_t spiRate) {
|
|
|
|
SPI.begin();
|
|
|
|
SPI.begin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** SPI receive a byte */
|
|
|
|
|
|
|
|
uint8_t spiRec(void) {
|
|
|
|
uint8_t spiRec(void) {
|
|
|
|
SPI.beginTransaction(spiConfig);
|
|
|
|
SPI.beginTransaction(spiConfig);
|
|
|
|
uint8_t returnByte = SPI.transfer(0xFF);
|
|
|
|
uint8_t returnByte = SPI.transfer(0xFF);
|
|
|
|
SPI.endTransaction();
|
|
|
|
SPI.endTransaction();
|
|
|
|
return returnByte;
|
|
|
|
return returnByte;
|
|
|
|
// SPDR = 0xFF;
|
|
|
|
//SPDR = 0xFF;
|
|
|
|
// while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
|
|
|
//while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
|
|
|
// return SPDR;
|
|
|
|
//return SPDR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** SPI read data */
|
|
|
|
|
|
|
|
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
|
|
|
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
|
|
|
SPI.beginTransaction(spiConfig);
|
|
|
|
SPI.beginTransaction(spiConfig);
|
|
|
|
SPI.transfer(buf, nbyte);
|
|
|
|
SPI.transfer(buf, nbyte);
|
|
|
|
SPI.endTransaction();
|
|
|
|
SPI.endTransaction();
|
|
|
|
//if (nbyte-- == 0) return;
|
|
|
|
//if (nbyte-- == 0) return;
|
|
|
|
// SPDR = 0xFF;
|
|
|
|
// SPDR = 0xFF;
|
|
|
|
//for (uint16_t i = 0; i < nbyte; i++) {
|
|
|
|
//for (uint16_t i = 0; i < nbyte; i++) {
|
|
|
|
// while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
|
|
|
// while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
|
|
|
// buf[i] = SPDR;
|
|
|
|
// buf[i] = SPDR;
|
|
|
|
// SPDR = 0xFF;
|
|
|
|
// SPDR = 0xFF;
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
//while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
|
|
|
//while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
|
|
|
//buf[nbyte] = SPDR;
|
|
|
|
//buf[nbyte] = SPDR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** SPI send a byte */
|
|
|
|
|
|
|
|
void spiSend(uint8_t b) {
|
|
|
|
void spiSend(uint8_t b) {
|
|
|
|
SPI.beginTransaction(spiConfig);
|
|
|
|
SPI.beginTransaction(spiConfig);
|
|
|
|
SPI.transfer(b);
|
|
|
|
SPI.transfer(b);
|
|
|
|
SPI.endTransaction();
|
|
|
|
SPI.endTransaction();
|
|
|
|
// SPDR = b;
|
|
|
|
//SPDR = b;
|
|
|
|
// while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
|
|
|
//while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** SPI send block */
|
|
|
|
|
|
|
|
void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
|
|
|
void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
|
|
|
SPI.beginTransaction(spiConfig);
|
|
|
|
SPI.beginTransaction(spiConfig);
|
|
|
|
SPDR = token;
|
|
|
|
SPDR = token;
|
|
|
@ -100,11 +111,9 @@ void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
|
|
|
SPI.endTransaction();
|
|
|
|
SPI.endTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Begin SPI transaction, set clock, bit order, data mode
|
|
|
|
/** Begin SPI transaction, set clock, bit order, data mode */
|
|
|
|
|
|
|
|
void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
|
|
|
|
void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
|
|
|
|
spiConfig = SPISettings(spiClock, bitOrder, dataMode);
|
|
|
|
spiConfig = SPISettings(spiClock, bitOrder, dataMode);
|
|
|
|
|
|
|
|
|
|
|
|
SPI.beginTransaction(spiConfig);
|
|
|
|
SPI.beginTransaction(spiConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|