1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-27 05:48:43 +00:00

🎨 Replace some infrequently-used macros

This commit is contained in:
Scott Lahteine 2021-09-18 18:24:39 -05:00
parent f367a3987d
commit c88e85c939
2 changed files with 21 additions and 72 deletions

View File

@ -26,39 +26,22 @@
#include "tft_spi.h"
//TFT_SPI tft;
SPIClass TFT_SPI::SPIx(1);
#define TFT_CS_H WRITE(TFT_CS_PIN, HIGH)
#define TFT_CS_L WRITE(TFT_CS_PIN, LOW)
#define TFT_DC_H WRITE(TFT_DC_PIN, HIGH)
#define TFT_DC_L WRITE(TFT_DC_PIN, LOW)
#define TFT_RST_H WRITE(TFT_RESET_PIN, HIGH)
#define TFT_RST_L WRITE(TFT_RESET_PIN, LOW)
#define TFT_BLK_H WRITE(TFT_BACKLIGHT_PIN, HIGH)
#define TFT_BLK_L WRITE(TFT_BACKLIGHT_PIN, LOW)
void TFT_SPI::Init() {
#if PIN_EXISTS(TFT_RESET)
SET_OUTPUT(TFT_RESET_PIN);
TFT_RST_H;
OUT_WRITE(TFT_RESET_PIN, HIGH);
delay(100);
#endif
#if PIN_EXISTS(TFT_BACKLIGHT)
SET_OUTPUT(TFT_BACKLIGHT_PIN);
TFT_BLK_H;
OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
#endif
SET_OUTPUT(TFT_DC_PIN);
SET_OUTPUT(TFT_CS_PIN);
TFT_DC_H;
TFT_CS_H;
WRITE(TFT_DC_PIN, HIGH);
WRITE(TFT_CS_PIN, HIGH);
/**
* STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
@ -97,7 +80,7 @@ void TFT_SPI::Init() {
void TFT_SPI::DataTransferBegin(uint16_t DataSize) {
SPIx.setDataSize(DataSize);
SPIx.begin();
TFT_CS_L;
WRITE(TFT_CS_PIN, LOW);
}
uint32_t TFT_SPI::GetID() {
@ -116,7 +99,7 @@ uint32_t TFT_SPI::ReadID(uint16_t Reg) {
SPIx.setDataSize(DATASIZE_8BIT);
SPIx.setClock(SPI_CLOCK_DIV64);
SPIx.begin();
TFT_CS_L;
WRITE(TFT_CS_PIN, LOW);
WriteReg(Reg);
LOOP_L_N(i, 4) {
@ -131,21 +114,15 @@ uint32_t TFT_SPI::ReadID(uint16_t Reg) {
return data >> 7;
}
bool TFT_SPI::isBusy() {
return false;
}
bool TFT_SPI::isBusy() { return false; }
void TFT_SPI::Abort() {
DataTransferEnd();
}
void TFT_SPI::Abort() { DataTransferEnd(); }
void TFT_SPI::Transmit(uint16_t Data) {
SPIx.transfer(Data);
}
void TFT_SPI::Transmit(uint16_t Data) { SPIx.transfer(Data); }
void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
DataTransferBegin(DATASIZE_16BIT); //16
TFT_DC_H;
DataTransferBegin(DATASIZE_16BIT);
WRITE(TFT_DC_PIN, HIGH);
SPIx.dmaSend(Data, Count, MemoryIncrease);
DataTransferEnd();
}

View File

@ -26,36 +26,20 @@
#include "tft_spi.h"
// TFT_SPI tft;
SPIClass TFT_SPI::SPIx(1);
#define TFT_CS_H OUT_WRITE(TFT_CS_PIN, HIGH)
#define TFT_CS_L OUT_WRITE(TFT_CS_PIN, LOW)
#define TFT_DC_H OUT_WRITE(TFT_DC_PIN, HIGH)
#define TFT_DC_L OUT_WRITE(TFT_DC_PIN, LOW)
#define TFT_RST_H OUT_WRITE(TFT_RST_PIN, HIGH)
#define TFT_RST_L OUT_WRITE(TFT_RST_PIN, LOW)
#define TFT_BLK_H OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH)
#define TFT_BLK_L OUT_WRITE(TFT_BACKLIGHT_PIN, LOW)
void TFT_SPI::Init() {
#if PIN_EXISTS(TFT_RESET)
// OUT_WRITE(TFT_RESET_PIN, HIGH);
TFT_RST_H;
OUT_WRITE(TFT_RST_PIN, HIGH);
delay(100);
#endif
#if PIN_EXISTS(TFT_BACKLIGHT)
// OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
TFT_BLK_H;
OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
#endif
TFT_DC_H;
TFT_CS_H;
OUT_WRITE(TFT_DC_PIN, HIGH);
OUT_WRITE(TFT_CS_PIN, HIGH);
/**
* STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
@ -87,7 +71,7 @@ void TFT_SPI::Init() {
void TFT_SPI::DataTransferBegin(uint16_t DataSize) {
SPIx.setDataSize(DataSize);
SPIx.begin();
TFT_CS_L;
OUT_WRITE(TFT_CS_PIN, LOW);
}
#ifdef TFT_DEFAULT_DRIVER
@ -129,28 +113,16 @@ uint32_t TFT_SPI::ReadID(uint16_t Reg) {
#endif
}
bool TFT_SPI::isBusy() {
return false;
}
bool TFT_SPI::isBusy() { return false; }
void TFT_SPI::Abort() {
DataTransferEnd();
}
void TFT_SPI::Abort() { DataTransferEnd(); }
void TFT_SPI::Transmit(uint16_t Data) {
SPIx.send(Data);
}
void TFT_SPI::Transmit(uint16_t Data) { SPIx.send(Data); }
void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
DataTransferBegin();
TFT_DC_H;
if (MemoryIncrease == DMA_MINC_ENABLE) {
SPIx.dmaSend(Data, Count, true);
}
else {
SPIx.dmaSend(Data, Count, false);
}
OUT_WRITE(TFT_DC_PIN, HIGH);
SPIx.dmaSend(Data, Count, MemoryIncrease == DMA_MINC_ENABLE);
DataTransferEnd();
}