🎨 Replace some infrequently-used macros

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

View file

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

View file

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