add ability to change SPI speed after init

This commit is contained in:
Ladyada 2019-09-13 00:10:35 -04:00
parent 3a48b56fa8
commit e3073d243f
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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: