From 702875d5a624c228768c55e0128f9ab625ad5181 Mon Sep 17 00:00:00 2001 From: Zane Bauman Date: Thu, 18 Jul 2024 07:59:29 -0400 Subject: [PATCH] Allow using ATtiny84 --- Adafruit_GrayOLED.cpp | 3 ++- Adafruit_GrayOLED.h | 5 +++-- Adafruit_SPITFT.cpp | 52 +++++++++++++++++++++---------------------- Adafruit_SPITFT.h | 29 ++++++++++++------------ 4 files changed, 46 insertions(+), 43 deletions(-) diff --git a/Adafruit_GrayOLED.cpp b/Adafruit_GrayOLED.cpp index f487861b..7c448252 100644 --- a/Adafruit_GrayOLED.cpp +++ b/Adafruit_GrayOLED.cpp @@ -15,7 +15,8 @@ * */ -#if !defined(__AVR_ATtiny85__) // Not for ATtiny, at all +// Not for ATtiny, at all +#if !defined(__AVR_ATtiny85__) && !defined(__AVR_ATtiny84__) #include "Adafruit_GrayOLED.h" #include diff --git a/Adafruit_GrayOLED.h b/Adafruit_GrayOLED.h index 8ec7b23d..e1f097fc 100644 --- a/Adafruit_GrayOLED.h +++ b/Adafruit_GrayOLED.h @@ -24,7 +24,8 @@ #ifndef _Adafruit_GRAYOLED_H_ #define _Adafruit_GRAYOLED_H_ -#if !defined(__AVR_ATtiny85__) // Not for ATtiny, at all +// Not for ATtiny, at all +#if !defined(__AVR_ATtiny85__) && !defined(__AVR_ATtiny84__) #include #include @@ -96,5 +97,5 @@ class Adafruit_GrayOLED : public Adafruit_GFX { TwoWire *_theWire = NULL; ///< The underlying hardware I2C }; -#endif // end __AVR_ATtiny85__ +#endif // end __AVR_ATtiny85__ __AVR_ATtiny84__ #endif // _Adafruit_GrayOLED_H_ diff --git a/Adafruit_SPITFT.cpp b/Adafruit_SPITFT.cpp index 1e576cc7..6032815f 100644 --- a/Adafruit_SPITFT.cpp +++ b/Adafruit_SPITFT.cpp @@ -31,8 +31,8 @@ * BSD license, all text here must be included in any redistribution. */ -#if !defined(__AVR_ATtiny85__) && \ - !defined(__AVR_ATtiny84__) // Not for ATtiny, at all +// Not for ATtiny, at all +#if !defined(__AVR_ATtiny85__) && !defined(__AVR_ATtiny84__) #include "Adafruit_SPITFT.h" @@ -871,7 +871,7 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) { DMA_ADDRESS_INCREMENT_STEP_SIZE_1; descriptor[d].DSTADDR.reg = (uint32_t)tft8.writePort; } -#endif // __SAMD51 +#endif // __SAMD51 } // end parallel-specific DMA setup lastFillColor = 0x0000; @@ -879,13 +879,13 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) { dma.setCallback(dma_callback); return; // Success! // else clean up any partial allocation... - } // end descriptor memalign() + } // end descriptor memalign() free(pixelBuf[0]); pixelBuf[0] = pixelBuf[1] = NULL; - } // end pixelBuf malloc() - // Don't currently have a descriptor delete function in - // ZeroDMA lib, but if we did, it would be called here. - } // end addDescriptor() + } // end pixelBuf malloc() + // Don't currently have a descriptor delete function in + // ZeroDMA lib, but if we did, it would be called here. + } // end addDescriptor() dma.free(); // Deallocate DMA channel } #endif // end USE_SPI_DMA @@ -1319,11 +1319,11 @@ void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len) { dma.trigger(); while (dma_busy) ; // Wait for completion - // Unfortunately blocking is necessary. An earlier version returned - // immediately and checked dma_busy on startWrite() instead, but it - // 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. + // Unfortunately blocking is necessary. An earlier version returned + // immediately and checked dma_busy on startWrite() instead, but it + // 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__) || defined(ARDUINO_SAMD_ZERO) if (connection == TFT_HARD_SPI) { // SAMD51: SPI DMA seems to leave the SPI peripheral in a freaky @@ -2035,9 +2035,9 @@ uint16_t Adafruit_SPITFT::readcommand16(uint16_t addr) { result = *(volatile uint16_t *)tft8.readPort; // 16-bit read *(volatile uint16_t *)tft8.dirSet = 0xFFFF; // Output state #else // !HAS_PORT_SET_CLR - *(volatile uint16_t *)tft8.portDir = 0x0000; // Input state - result = *(volatile uint16_t *)tft8.readPort; // 16-bit read - *(volatile uint16_t *)tft8.portDir = 0xFFFF; // Output state + *(volatile uint16_t *)tft8.portDir = 0x0000; // Input state + result = *(volatile uint16_t *)tft8.readPort; // 16-bit read + *(volatile uint16_t *)tft8.portDir = 0xFFFF; // Output state #endif // end !HAS_PORT_SET_CLR TFT_RD_HIGH(); // Read line HIGH endWrite(); @@ -2192,17 +2192,17 @@ uint8_t Adafruit_SPITFT::spiRead(void) { w = *tft8.readPort; // Read value from port *tft8.portDir = 0xFF; // Restore port to output #else // !__AVR__ - if (!tft8.wide) { // 8-bit TFT connection + if (!tft8.wide) { // 8-bit TFT connection #if defined(HAS_PORT_SET_CLR) - *tft8.dirClr = 0xFF; // Set port to input state - w = *tft8.readPort; // Read value from port - *tft8.dirSet = 0xFF; // Restore port to output + *tft8.dirClr = 0xFF; // Set port to input state + w = *tft8.readPort; // Read value from port + *tft8.dirSet = 0xFF; // Restore port to output #else // !HAS_PORT_SET_CLR - *tft8.portDir = 0x00; // Set port to input state - w = *tft8.readPort; // Read value from port - *tft8.portDir = 0xFF; // Restore port to output + *tft8.portDir = 0x00; // Set port to input state + w = *tft8.readPort; // Read value from port + *tft8.portDir = 0xFF; // Restore port to output #endif // end HAS_PORT_SET_CLR - } else { // 16-bit TFT connection + } else { // 16-bit TFT connection #if defined(HAS_PORT_SET_CLR) *(volatile uint16_t *)tft8.dirClr = 0xFFFF; // Input state w = *(volatile uint16_t *)tft8.readPort; // 16-bit read @@ -2213,7 +2213,7 @@ uint8_t Adafruit_SPITFT::spiRead(void) { *(volatile uint16_t *)tft8.portDir = 0xFFFF; // Output state #endif // end !HAS_PORT_SET_CLR } - TFT_RD_HIGH(); // Read line HIGH + TFT_RD_HIGH(); // Read line HIGH #endif // end !__AVR__ #else // !USE_FAST_PINIO w = 0; // Parallel TFT is NOT SUPPORTED without USE_FAST_PINIO @@ -2559,4 +2559,4 @@ inline void Adafruit_SPITFT::TFT_RD_LOW(void) { #endif // end !USE_FAST_PINIO } -#endif // end __AVR_ATtiny85__ +#endif // end __AVR_ATtiny85__ __AVR_ATtiny84__ diff --git a/Adafruit_SPITFT.h b/Adafruit_SPITFT.h index 8064a742..e0d09d63 100644 --- a/Adafruit_SPITFT.h +++ b/Adafruit_SPITFT.h @@ -20,7 +20,8 @@ #ifndef _ADAFRUIT_SPITFT_H_ #define _ADAFRUIT_SPITFT_H_ -#if !defined(__AVR_ATtiny85__) // Not for ATtiny, at all +// Not for ATtiny, at all +#if !defined(__AVR_ATtiny85__) && !defined(__AVR_ATtiny84__) #include "Adafruit_GFX.h" #include @@ -31,8 +32,8 @@ typedef uint8_t ADAGFX_PORT_t; ///< PORT values are 8-bit #define USE_FAST_PINIO ///< Use direct PORT register access #elif defined(ARDUINO_STM32_FEATHER) // WICED -typedef class HardwareSPI SPIClass; ///< SPI is a bit odd on WICED -typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit +typedef class HardwareSPI SPIClass; ///< SPI is a bit odd on WICED +typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit #elif defined(__arm__) #if defined(ARDUINO_ARCH_SAMD) // Adafruit M0, M4 @@ -78,8 +79,8 @@ typedef volatile ADAGFX_PORT_t *PORTreg_t; ///< PORT register type defined(ADAFRUIT_CIRCUITPLAYGROUND_M0) #define USE_SPI_DMA ///< Auto DMA #else - //#define USE_SPI_DMA ///< If set, - // use DMA if available + // #define USE_SPI_DMA ///< If set, + // use DMA if available #endif // Another "oops" name -- this now also handles parallel DMA. // If DMA is enabled, Arduino sketch MUST #include @@ -396,8 +397,8 @@ class Adafruit_SPITFT : public Adafruit_GFX { PORTreg_t dcPortSet; ///< PORT register for data/command SET PORTreg_t dcPortClr; ///< PORT register for data/command CLEAR #else // !HAS_PORT_SET_CLR - PORTreg_t csPort; ///< PORT register for chip select - PORTreg_t dcPort; ///< PORT register for data/command + PORTreg_t csPort; ///< PORT register for chip select + PORTreg_t dcPort; ///< PORT register for data/command #endif // end HAS_PORT_SET_CLR #endif // end USE_FAST_PINIO #if defined(__cplusplus) && (__cplusplus >= 201100) @@ -447,8 +448,8 @@ class Adafruit_SPITFT : public Adafruit_GFX { volatile uint32_t *writePort; ///< PORT register for DATA WRITE volatile uint32_t *readPort; ///< PORT (PIN) register for DATA READ #else - volatile uint8_t *writePort; ///< PORT register for DATA WRITE - volatile uint8_t *readPort; ///< PORT (PIN) register for DATA READ + volatile uint8_t *writePort; ///< PORT register for DATA WRITE + volatile uint8_t *readPort; ///< PORT (PIN) register for DATA READ #endif #if defined(HAS_PORT_SET_CLR) // Port direction register pointers are always 8-bit regardless of @@ -507,10 +508,10 @@ class Adafruit_SPITFT : public Adafruit_GFX { ADAGFX_PORT_t dcPinMask; ///< Bitmask for data/command #endif // end !KINETISK #else // !HAS_PORT_SET_CLR - ADAGFX_PORT_t csPinMaskSet; ///< Bitmask for chip select SET (OR) - ADAGFX_PORT_t csPinMaskClr; ///< Bitmask for chip select CLEAR (AND) - ADAGFX_PORT_t dcPinMaskSet; ///< Bitmask for data/command SET (OR) - ADAGFX_PORT_t dcPinMaskClr; ///< Bitmask for data/command CLEAR (AND) + ADAGFX_PORT_t csPinMaskSet; ///< Bitmask for chip select SET (OR) + ADAGFX_PORT_t csPinMaskClr; ///< Bitmask for chip select CLEAR (AND) + ADAGFX_PORT_t dcPinMaskSet; ///< Bitmask for data/command SET (OR) + ADAGFX_PORT_t dcPinMaskClr; ///< Bitmask for data/command CLEAR (AND) #endif // end HAS_PORT_SET_CLR #endif // end USE_FAST_PINIO uint8_t connection; ///< TFT_HARD_SPI, TFT_SOFT_SPI, etc. @@ -526,5 +527,5 @@ class Adafruit_SPITFT : public Adafruit_GFX { uint32_t _freq = 0; ///< Dummy var to keep subclasses happy }; -#endif // end __AVR_ATtiny85__ +#endif // end __AVR_ATtiny85__ __AVR_ATtiny84__ #endif // end _ADAFRUIT_SPITFT_H_