mirror of
https://github.com/adafruit/Adafruit-GFX-Library.git
synced 2024-10-03 18:18:46 -04:00
Add hooks for SPI data mode
This commit is contained in:
parent
fbd16ee4b7
commit
5fa33d0020
@ -500,12 +500,17 @@ Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, tftBusWidth busWidth,
|
||||
is passed, will fall back on a device-specific value.
|
||||
Value is ignored when using software SPI or parallel
|
||||
connection.
|
||||
@param mode SPI mode when using hardware SPI. MUST be one of the
|
||||
values SPI_MODE0, SPI_MODE1, SPI_MODE2 or SPI_MODE3
|
||||
defined in SPI.h. Do NOT attempt to pass '0' for SPI_MODE0
|
||||
and so forth...the values are NOT the same! Use ONLY the
|
||||
defines! (Pity it's not an enum.)
|
||||
@note Another anachronistically-named function; this is called even
|
||||
when the display connection is parallel (not SPI). Also, this
|
||||
could probably be made private...quite a few class functions
|
||||
were generously put in the public section.
|
||||
*/
|
||||
void Adafruit_SPITFT::initSPI(uint32_t freq) {
|
||||
void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) {
|
||||
|
||||
if(!freq) freq = DEFAULT_SPI_FREQ; // If no freq specified, use default
|
||||
|
||||
@ -520,9 +525,10 @@ void Adafruit_SPITFT::initSPI(uint32_t freq) {
|
||||
if(connection == TFT_HARD_SPI) {
|
||||
|
||||
#if defined(SPI_HAS_TRANSACTION)
|
||||
hwspi.settings = SPISettings(freq, MSBFIRST, SPI_MODE0);
|
||||
hwspi.settings = SPISettings(freq, MSBFIRST, spiMode);
|
||||
#else
|
||||
hwspi._freq = freq; // Save freq value for later
|
||||
hwspi._freq = freq; // Save freq value for later
|
||||
hwspi._mode = spiMode; // Save spiMode value for later
|
||||
#endif
|
||||
// Call hwspi._spi->begin() ONLY if this is among the 'established'
|
||||
// SPI interfaces in variant.h. For DIY roll-your-own SERCOM SPIs,
|
||||
@ -1024,14 +1030,14 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len,
|
||||
lastFillLen = 0;
|
||||
if(block) {
|
||||
while(dma_busy); // Wait for last line to complete
|
||||
#if defined(__SAMD51__)
|
||||
#if defined(__SAMD51__) || defined(_SAMD21_)
|
||||
if(connection == TFT_HARD_SPI) {
|
||||
// See SAMD51 note in writeColor()
|
||||
// See SAMD51/21 note in writeColor()
|
||||
hwspi._spi->setDataMode(SPI_MODE0);
|
||||
} else {
|
||||
pinPeripheral(tft8._wr, PIO_OUTPUT); // Switch WR back to GPIO
|
||||
}
|
||||
#endif // end __SAMD51__
|
||||
#endif // end __SAMD51__ || _SAMD21_
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1053,14 +1059,14 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len,
|
||||
void Adafruit_SPITFT::dmaWait(void) {
|
||||
#if defined(USE_SPI_DMA)
|
||||
while(dma_busy);
|
||||
#if defined(__SAMD51__)
|
||||
#if defined(__SAMD51__) || defined(_SAMD21_)
|
||||
if(connection == TFT_HARD_SPI) {
|
||||
// See SAMD51 note in writeColor()
|
||||
// See SAMD51/21 note in writeColor()
|
||||
hwspi._spi->setDataMode(SPI_MODE0);
|
||||
} else {
|
||||
pinPeripheral(tft8._wr, PIO_OUTPUT); // Switch WR back to GPIO
|
||||
}
|
||||
#endif // end __SAMD51__
|
||||
#endif // end __SAMD51__ || _SAMD21_
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1176,10 +1182,12 @@ void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len) {
|
||||
// turns out to be MUCH slower on many graphics operations (as when
|
||||
// drawing lines, pixel-by-pixel), perhaps because it's a volatile
|
||||
// type and doesn't cache. Working on this.
|
||||
#if defined(__SAMD51__)
|
||||
#if defined(__SAMD51__) || defined(_SAMD21_)
|
||||
if(connection == TFT_HARD_SPI) {
|
||||
// SAMD51: SPI DMA seems to leave the SPI peripheral in a freaky
|
||||
// state on completion. Workaround is to explicitly set it back...
|
||||
// (5/17/2019: apparently SAMD21 too, in certain cases, observed
|
||||
// with ST7789 display.)
|
||||
hwspi._spi->setDataMode(SPI_MODE0);
|
||||
} else {
|
||||
pinPeripheral(tft8._wr, PIO_OUTPUT); // Switch WR back to GPIO
|
||||
@ -1782,7 +1790,7 @@ inline void Adafruit_SPITFT::SPI_BEGIN_TRANSACTION(void) {
|
||||
hwspi._spi->setClock(hwspi._freq);
|
||||
#endif
|
||||
hwspi._spi->setBitOrder(MSBFIRST);
|
||||
hwspi._spi->setDataMode(SPI_MODE0);
|
||||
hwspi._spi->setDataMode(hwspi._mode);
|
||||
#endif // end !SPI_HAS_TRANSACTION
|
||||
}
|
||||
}
|
||||
|
@ -181,8 +181,11 @@ class Adafruit_SPITFT : public Adafruit_GFX {
|
||||
// Brief comments here...documented more thoroughly in .cpp file.
|
||||
|
||||
// Subclass' begin() function invokes this to initialize hardware.
|
||||
// freq=0 to use default SPI speed. spiMode must be one of the SPI_MODEn
|
||||
// values defined in SPI.h, which are NOT the same as 0 for SPI_MODE0,
|
||||
// 1 for SPI_MODE1, etc...use ONLY the SPI_MODEn defines! Only!
|
||||
// Name is outdated (interface may be parallel) but for compatibility:
|
||||
void initSPI(uint32_t freq = 0); // 0 = use default SPI speed
|
||||
void initSPI(uint32_t freq = 0, uint8_t spiMode = SPI_MODE0);
|
||||
// Chip select and/or hardware SPI transaction start as needed:
|
||||
void startWrite(void);
|
||||
// Chip deselect and/or hardware SPI transaction end as needed:
|
||||
@ -392,6 +395,7 @@ class Adafruit_SPITFT : public Adafruit_GFX {
|
||||
SPISettings settings; ///< SPI transaction settings
|
||||
#else
|
||||
uint32_t _freq; ///< SPI bitrate (if no SPI transactions)
|
||||
uint32_t _mode; ///< SPI data mode (if no SPI transactions)
|
||||
#endif
|
||||
} hwspi; ///< Hardware SPI values
|
||||
struct { // Values specific to SOFTWARE SPI:
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=Adafruit GFX Library
|
||||
version=1.5.0
|
||||
version=1.5.1
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from.
|
||||
|
Loading…
x
Reference in New Issue
Block a user