diff --git a/Adafruit_SPITFT.cpp b/Adafruit_SPITFT.cpp index 66f3e35..05d71ab 100644 --- a/Adafruit_SPITFT.cpp +++ b/Adafruit_SPITFT.cpp @@ -888,6 +888,19 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) { #endif // end USE_SPI_DMA } +/*! + @brief Allow changing the SPI clock speed after initialization + @param freq Desired frequency of SPI clock, may not be the + end frequency you get based on what the chip can do! +*/ +void Adafruit_SPITFT::setSPISpeed(uint32_t freq) { +#if defined(SPI_HAS_TRANSACTION) + hwspi.settings = SPISettings(freq, MSBFIRST, hwspi._mode); +#else + hwspi._freq = freq; // Save freq value for later +#endif +} + /*! @brief Call before issuing command(s) or data to display. Performs chip-select (if required) and starts an SPI transaction (if diff --git a/Adafruit_SPITFT.h b/Adafruit_SPITFT.h index 985ed3c..da2507b 100644 --- a/Adafruit_SPITFT.h +++ b/Adafruit_SPITFT.h @@ -71,7 +71,7 @@ typedef volatile ADAGFX_PORT_t* PORTreg_t; ///< PORT register type #define DEFAULT_SPI_FREQ 16000000L ///< Hardware SPI default speed #endif -#if defined(ADAFRUIT_PYPORTAL) || defined(ADAFRUIT_PYBADGE_M4_EXPRESS) || defined(ADAFRUIT_PYGAMER_M4_EXPRESS) || defined(ADAFRUIT_HALLOWING_M4_EXPRESS) +#if defined(ADAFRUIT_PYPORTAL) || defined(ADAFRUIT_PYBADGE_M4_EXPRESS) || defined(ADAFRUIT_PYGAMER_M4_EXPRESS)|| defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) #define USE_SPI_DMA ///< Auto DMA if using PyPortal #else //#define USE_SPI_DMA ///< If set, use DMA if available @@ -190,6 +190,7 @@ class Adafruit_SPITFT : public Adafruit_GFX { // 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, uint8_t spiMode = SPI_MODE0); + void setSPISpeed(uint32_t freq); // Chip select and/or hardware SPI transaction start as needed: void startWrite(void); // Chip deselect and/or hardware SPI transaction end as needed: