Standardize Marlin SPI (part 1) (#19989)
This commit is contained in:
@ -25,7 +25,6 @@
|
||||
#if HAS_SPI_FLASH
|
||||
|
||||
#include "W25Qxx.h"
|
||||
#include <SPI.h>
|
||||
|
||||
W25QXXFlash W25QXX;
|
||||
|
||||
@ -41,6 +40,11 @@ W25QXXFlash W25QXX;
|
||||
#ifndef SPI_FLASH_CS_PIN
|
||||
#define SPI_FLASH_CS_PIN W25QXX_CS_PIN
|
||||
#endif
|
||||
#ifndef NC
|
||||
#define NC -1
|
||||
#endif
|
||||
|
||||
MarlinSPI W25QXXFlash::mySPI(SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN, SPI_FLASH_SCK_PIN, NC);
|
||||
|
||||
#define W25QXX_CS_H OUT_WRITE(SPI_FLASH_CS_PIN, HIGH)
|
||||
#define W25QXX_CS_L OUT_WRITE(SPI_FLASH_CS_PIN, LOW)
|
||||
@ -69,11 +73,11 @@ void W25QXXFlash::init(uint8_t spiRate) {
|
||||
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
|
||||
default: clock = SPI_CLOCK_DIV2;// Default from the SPI library
|
||||
}
|
||||
SPI.setModule(SPI_DEVICE);
|
||||
SPI.begin();
|
||||
SPI.setClockDivider(clock);
|
||||
SPI.setBitOrder(MSBFIRST);
|
||||
SPI.setDataMode(SPI_MODE0);
|
||||
|
||||
mySPI.setClockDivider(clock);
|
||||
mySPI.setBitOrder(MSBFIRST);
|
||||
mySPI.setDataMode(SPI_MODE0);
|
||||
mySPI.begin();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,12 +86,12 @@ void W25QXXFlash::init(uint8_t spiRate) {
|
||||
* @return Byte received
|
||||
*/
|
||||
uint8_t W25QXXFlash::spi_flash_Rec() {
|
||||
const uint8_t returnByte = SPI.transfer(0xFF);
|
||||
const uint8_t returnByte = mySPI.transfer(0xFF);
|
||||
return returnByte;
|
||||
}
|
||||
|
||||
uint8_t W25QXXFlash::spi_flash_read_write_byte(uint8_t data) {
|
||||
const uint8_t returnByte = SPI.transfer(data);
|
||||
const uint8_t returnByte = mySPI.transfer(data);
|
||||
return returnByte;
|
||||
}
|
||||
|
||||
@ -100,7 +104,9 @@ uint8_t W25QXXFlash::spi_flash_read_write_byte(uint8_t data) {
|
||||
*
|
||||
* @details Uses DMA
|
||||
*/
|
||||
void W25QXXFlash::spi_flash_Read(uint8_t* buf, uint16_t nbyte) { SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte); }
|
||||
void W25QXXFlash::spi_flash_Read(uint8_t* buf, uint16_t nbyte) {
|
||||
mySPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send a single byte on SPI port
|
||||
@ -109,7 +115,7 @@ void W25QXXFlash::spi_flash_Read(uint8_t* buf, uint16_t nbyte) { SPI.dmaTransfer
|
||||
*
|
||||
* @details
|
||||
*/
|
||||
void W25QXXFlash::spi_flash_Send(uint8_t b) { SPI.send(b); }
|
||||
void W25QXXFlash::spi_flash_Send(uint8_t b) { mySPI.transfer(b); }
|
||||
|
||||
/**
|
||||
* @brief Write token and then write from 512 byte buffer to SPI (for SD card)
|
||||
@ -120,8 +126,8 @@ void W25QXXFlash::spi_flash_Send(uint8_t b) { SPI.send(b); }
|
||||
* @details Use DMA
|
||||
*/
|
||||
void W25QXXFlash::spi_flash_SendBlock(uint8_t token, const uint8_t* buf) {
|
||||
SPI.send(token);
|
||||
SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
|
||||
mySPI.transfer(token);
|
||||
mySPI.dmaSend(const_cast<uint8_t*>(buf), 512);
|
||||
}
|
||||
|
||||
uint16_t W25QXXFlash::W25QXX_ReadID(void) {
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include HAL_PATH(../HAL, MarlinSPI.h)
|
||||
|
||||
#define W25X_WriteEnable 0x06
|
||||
#define W25X_WriteDisable 0x04
|
||||
#define W25X_ReadStatusReg 0x05
|
||||
@ -49,6 +51,8 @@
|
||||
#define SPI_FLASH_PerWritePageSize 256
|
||||
|
||||
class W25QXXFlash {
|
||||
private:
|
||||
static MarlinSPI mySPI;
|
||||
public:
|
||||
void init(uint8_t spiRate);
|
||||
static uint8_t spi_flash_Rec();
|
||||
|
Reference in New Issue
Block a user