From 356aa341a384baf8cfdd5dbf7212389d5b4e7b85 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 30 Jul 2019 14:06:43 -0700 Subject: [PATCH] Updated examples to work with new SdFat and SPIFlash changes --- .gitignore | 1 + examples/BreakoutSSD1331/BreakoutSSD1331.ino | 59 ++++++++++++++--- examples/BreakoutSSD1351/BreakoutSSD1351.ino | 57 +++++++++++++--- .../BreakoutST7735-128x128.ino | 57 +++++++++++++--- .../BreakoutST7735-160x128.ino | 57 +++++++++++++--- .../BreakoutST7735-160x80.ino | 57 +++++++++++++--- .../BreakoutST7789-320x240.ino | 55 +++++++++++++--- .../FeatherWingST7735/FeatherWingST7735.ino | 65 +++++++++++++++---- examples/ShieldILI9341/ShieldILI9341.ino | 63 ++++++++++++++---- examples/ShieldST7735/ShieldST7735.ino | 57 +++++++++++++--- 10 files changed, 441 insertions(+), 87 deletions(-) diff --git a/.gitignore b/.gitignore index c2a26c0..a1d6885 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ Doxyfile* doxygen_sqlite3.db html +*.DS_Store diff --git a/examples/BreakoutSSD1331/BreakoutSSD1331.ino b/examples/BreakoutSSD1331/BreakoutSSD1331.ino index 03c89c7..c7b2e7c 100644 --- a/examples/BreakoutSSD1331/BreakoutSSD1331.ino +++ b/examples/BreakoutSSD1331/BreakoutSSD1331.ino @@ -1,18 +1,21 @@ // Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino. -// Demonstrates loading images to the screen, to RAM, and how to query -// image file dimensions. +// Demonstrates loading images from SD card or flash memory to the screen, +// to RAM, and how to query image file dimensions. // Requires three BMP files in root directory of SD card: // rgbwheel.bmp, miniwoof.bmp and wales.bmp. // As written, this uses the microcontroller's SPI interface for the screen // (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno, // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below. -#include -#include #include // Core graphics library #include // Hardware-specific library +#include // SD card & FAT filesystem library +#include // SPI / QSPI flash library #include // Image-reading functions +// Comment out the next line to load from SPI/QSPI flash instead of SD card: +#define USE_SD_CARD + // Color definitions #define BLACK 0x0000 #define BLUE 0x001F @@ -31,9 +34,28 @@ #define TFT_DC 8 // TFT display/command pin #define SD_CS 4 // SD card select pin -Adafruit_SSD1331 tft = Adafruit_SSD1331(&SPI, TFT_CS, TFT_DC, TFT_RST); +#if defined(USE_SD_CARD) + SdFat SD; // SD card filesystem + Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys +#else + // SPI or QSPI flash filesystem (i.e. CIRCUITPY drive) + #if defined(__SAMD51__) || defined(NRF52840_XXAA) + Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, + PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3); + #else + #if (SPI_INTERFACES_COUNT == 1) + Adafruit_FlashTransport_SPI flashTransport(SS, &SPI); + #else + Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1); + #endif + #endif + Adafruit_SPIFlash flash(&flashTransport); + FatFileSystem filesys; + Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys +#endif -Adafruit_ImageReader reader; // Class w/image-reading functions + +Adafruit_SSD1331 tft = Adafruit_SSD1331(&SPI, TFT_CS, TFT_DC, TFT_RST); Adafruit_Image img; // An image loaded into RAM int32_t width = 0, // BMP image dimensions height = 0; @@ -49,11 +71,28 @@ void setup(void) { tft.begin(); // Initialize screen - Serial.print(F("Initializing SD card...")); - if(!SD.begin(SD_CS)) { - Serial.println(F("failed!")); - for(;;); // Loop here forever + // The Adafruit_ImageReader constructor call (above, before setup()) + // accepts an uninitialized SdFat or FatFileSystem object. This MUST + // BE INITIALIZED before using any of the image reader functions! + Serial.print(F("Initializing filesystem...")); +#if defined(USE_SD_CARD) + // SD card is pretty straightforward, a single call... + if(!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires + Serial.println(F("SD begin() failed")); + for(;;); // Fatal error, do not continue } +#else + // SPI or QSPI flash requires two steps, one to access the bare flash + // memory itself, then the second to access the filesystem within... + if(!flash.begin()) { + Serial.println(F("flash begin() failed")); + for(;;); + } + if(!filesys.begin(&flash)) { + Serial.println(F("filesys begin() failed")); + for(;;); + } +#endif Serial.println(F("OK!")); // Fill screen blue. Not a required step, this just shows that we're diff --git a/examples/BreakoutSSD1351/BreakoutSSD1351.ino b/examples/BreakoutSSD1351/BreakoutSSD1351.ino index b212588..1101a2c 100644 --- a/examples/BreakoutSSD1351/BreakoutSSD1351.ino +++ b/examples/BreakoutSSD1351/BreakoutSSD1351.ino @@ -1,18 +1,21 @@ // Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino. -// Demonstrates loading images to the screen, to RAM, and how to query -// image file dimensions. +// Demonstrates loading images from SD card or flash memory to the screen, +// to RAM, and how to query image file dimensions. // Requires three BMP files in root directory of SD card: // rgbwheel.bmp, miniwoof.bmp and wales.bmp. // As written, this uses the microcontroller's SPI interface for the screen // (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno, // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below. -#include -#include #include // Core graphics library #include // Hardware-specific library +#include // SD card & FAT filesystem library +#include // SPI / QSPI flash library #include // Image-reading functions +// Comment out the next line to load from SPI/QSPI flash instead of SD card: +#define USE_SD_CARD + // Color definitions #define BLACK 0x0000 #define BLUE 0x001F @@ -35,9 +38,28 @@ #define TFT_DC 4 // TFT display/command pin #define TFT_RST 6 // Or set to -1 and connect to Arduino RESET pin +#if defined(USE_SD_CARD) + SdFat SD; // SD card filesystem + Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys +#else + // SPI or QSPI flash filesystem (i.e. CIRCUITPY drive) + #if defined(__SAMD51__) || defined(NRF52840_XXAA) + Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, + PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3); + #else + #if (SPI_INTERFACES_COUNT == 1) + Adafruit_FlashTransport_SPI flashTransport(SS, &SPI); + #else + Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1); + #endif + #endif + Adafruit_SPIFlash flash(&flashTransport); + FatFileSystem filesys; + Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys +#endif + Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, TFT_CS, TFT_DC, TFT_RST); -Adafruit_ImageReader reader; // Class w/image-reading functions Adafruit_Image img; // An image loaded into RAM int32_t width = 0, // BMP image dimensions height = 0; @@ -53,11 +75,28 @@ void setup(void) { tft.begin(); // Initialize screen - Serial.print(F("Initializing SD card...")); - if(!SD.begin(SD_CS)) { - Serial.println(F("failed!")); - for(;;); // Loop here forever + // The Adafruit_ImageReader constructor call (above, before setup()) + // accepts an uninitialized SdFat or FatFileSystem object. This MUST + // BE INITIALIZED before using any of the image reader functions! + Serial.print(F("Initializing filesystem...")); +#if defined(USE_SD_CARD) + // SD card is pretty straightforward, a single call... + if(!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires + Serial.println(F("SD begin() failed")); + for(;;); // Fatal error, do not continue } +#else + // SPI or QSPI flash requires two steps, one to access the bare flash + // memory itself, then the second to access the filesystem within... + if(!flash.begin()) { + Serial.println(F("flash begin() failed")); + for(;;); + } + if(!filesys.begin(&flash)) { + Serial.println(F("filesys begin() failed")); + for(;;); + } +#endif Serial.println(F("OK!")); // Fill screen blue. Not a required step, this just shows that we're diff --git a/examples/BreakoutST7735-128x128/BreakoutST7735-128x128.ino b/examples/BreakoutST7735-128x128/BreakoutST7735-128x128.ino index 4642bcf..0d089fb 100644 --- a/examples/BreakoutST7735-128x128/BreakoutST7735-128x128.ino +++ b/examples/BreakoutST7735-128x128/BreakoutST7735-128x128.ino @@ -1,18 +1,21 @@ // Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino. -// Demonstrates loading images to the screen, to RAM, and how to query -// image file dimensions. +// Demonstrates loading images from SD card or flash memory to the screen, +// to RAM, and how to query image file dimensions. // Requires three BMP files in root directory of SD card: // rgbwheel.bmp, miniwoof.bmp and wales.bmp. // As written, this uses the microcontroller's SPI interface for the screen // (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno, // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below. -#include -#include #include // Core graphics library #include // Hardware-specific library +#include // SD card & FAT filesystem library +#include // SPI / QSPI flash library #include // Image-reading functions +// Comment out the next line to load from SPI/QSPI flash instead of SD card: +#define USE_SD_CARD + // TFT display and SD card share the hardware SPI interface, using // 'select' pins for each to identify the active device on the bus. @@ -21,8 +24,27 @@ #define TFT_DC 8 // TFT display/command pin #define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin +#if defined(USE_SD_CARD) + SdFat SD; // SD card filesystem + Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys +#else + // SPI or QSPI flash filesystem (i.e. CIRCUITPY drive) + #if defined(__SAMD51__) || defined(NRF52840_XXAA) + Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, + PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3); + #else + #if (SPI_INTERFACES_COUNT == 1) + Adafruit_FlashTransport_SPI flashTransport(SS, &SPI); + #else + Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1); + #endif + #endif + Adafruit_SPIFlash flash(&flashTransport); + FatFileSystem filesys; + Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys +#endif + Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); -Adafruit_ImageReader reader; // Class w/image-reading functions Adafruit_Image img; // An image loaded into RAM int32_t width = 0, // BMP image dimensions height = 0; @@ -38,11 +60,28 @@ void setup(void) { tft.initR(INITR_144GREENTAB); // Initialize screen - Serial.print(F("Initializing SD card...")); - if(!SD.begin(SD_CS)) { - Serial.println(F("failed!")); - for(;;); // Loop here forever + // The Adafruit_ImageReader constructor call (above, before setup()) + // accepts an uninitialized SdFat or FatFileSystem object. This MUST + // BE INITIALIZED before using any of the image reader functions! + Serial.print(F("Initializing filesystem...")); +#if defined(USE_SD_CARD) + // SD card is pretty straightforward, a single call... + if(!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires + Serial.println(F("SD begin() failed")); + for(;;); // Fatal error, do not continue } +#else + // SPI or QSPI flash requires two steps, one to access the bare flash + // memory itself, then the second to access the filesystem within... + if(!flash.begin()) { + Serial.println(F("flash begin() failed")); + for(;;); + } + if(!filesys.begin(&flash)) { + Serial.println(F("filesys begin() failed")); + for(;;); + } +#endif Serial.println(F("OK!")); // Fill screen blue. Not a required step, this just shows that we're diff --git a/examples/BreakoutST7735-160x128/BreakoutST7735-160x128.ino b/examples/BreakoutST7735-160x128/BreakoutST7735-160x128.ino index 48566b2..9f2ffec 100644 --- a/examples/BreakoutST7735-160x128/BreakoutST7735-160x128.ino +++ b/examples/BreakoutST7735-160x128/BreakoutST7735-160x128.ino @@ -1,18 +1,21 @@ // Adafruit_ImageReader test for Adafruit ST7735 TFT Breakout for Arduino. -// Demonstrates loading images to the screen, to RAM, and how to query -// image file dimensions. +// Demonstrates loading images from SD card or flash memory to the screen, +// to RAM, and how to query image file dimensions. // Requires three BMP files in root directory of SD card: // parrot.bmp, miniwoof.bmp and wales.bmp. // As written, this uses the microcontroller's SPI interface for the screen // (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno, // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below. -#include -#include #include // Core graphics library #include // Hardware-specific library +#include // SD card & FAT filesystem library +#include // SPI / QSPI flash library #include // Image-reading functions +// Comment out the next line to load from SPI/QSPI flash instead of SD card: +#define USE_SD_CARD + // TFT display and SD card share the hardware SPI interface, using // 'select' pins for each to identify the active device on the bus. @@ -21,8 +24,27 @@ #define TFT_DC 8 // TFT display/command pin #define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin +#if defined(USE_SD_CARD) + SdFat SD; // SD card filesystem + Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys +#else + // SPI or QSPI flash filesystem (i.e. CIRCUITPY drive) + #if defined(__SAMD51__) || defined(NRF52840_XXAA) + Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, + PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3); + #else + #if (SPI_INTERFACES_COUNT == 1) + Adafruit_FlashTransport_SPI flashTransport(SS, &SPI); + #else + Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1); + #endif + #endif + Adafruit_SPIFlash flash(&flashTransport); + FatFileSystem filesys; + Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys +#endif + Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); -Adafruit_ImageReader reader; // Class w/image-reading functions Adafruit_Image img; // An image loaded into RAM int32_t width = 0, // BMP image dimensions height = 0; @@ -38,11 +60,28 @@ void setup(void) { tft.initR(INITR_BLACKTAB); // Initialize screen - Serial.print(F("Initializing SD card...")); - if(!SD.begin(SD_CS)) { - Serial.println(F("failed!")); - for(;;); // Loop here forever + // The Adafruit_ImageReader constructor call (above, before setup()) + // accepts an uninitialized SdFat or FatFileSystem object. This MUST + // BE INITIALIZED before using any of the image reader functions! + Serial.print(F("Initializing filesystem...")); +#if defined(USE_SD_CARD) + // SD card is pretty straightforward, a single call... + if(!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires + Serial.println(F("SD begin() failed")); + for(;;); // Fatal error, do not continue } +#else + // SPI or QSPI flash requires two steps, one to access the bare flash + // memory itself, then the second to access the filesystem within... + if(!flash.begin()) { + Serial.println(F("flash begin() failed")); + for(;;); + } + if(!filesys.begin(&flash)) { + Serial.println(F("filesys begin() failed")); + for(;;); + } +#endif Serial.println(F("OK!")); // Fill screen blue. Not a required step, this just shows that we're diff --git a/examples/BreakoutST7735-160x80/BreakoutST7735-160x80.ino b/examples/BreakoutST7735-160x80/BreakoutST7735-160x80.ino index cb5169e..423df0b 100644 --- a/examples/BreakoutST7735-160x80/BreakoutST7735-160x80.ino +++ b/examples/BreakoutST7735-160x80/BreakoutST7735-160x80.ino @@ -1,6 +1,6 @@ // Adafruit_ImageReader test for Adafruit Mini TFT Breakout for Arduino. -// Demonstrates loading images to the screen, to RAM, and how to query -// image file dimensions. +// Demonstrates loading images from SD card or flash memory to the screen, +// to RAM, and how to query image file dimensions. // OPEN THE ARDUINO SERIAL MONITOR WINDOW TO START PROGRAM. // Requires three BMP files in root directory of SD card: // minibot.bmp, rgbwheel.bmp and wales.bmp. @@ -8,22 +8,44 @@ // (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno, // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below. -#include -#include #include // Core graphics library #include // Hardware-specific library +#include // SD card & FAT filesystem library +#include // SPI / QSPI flash library #include // Image-reading functions // TFT display and SD card share the hardware SPI interface, using // 'select' pins for each to identify the active device on the bus. +// Comment out the next line to load from SPI/QSPI flash instead of SD card: +#define USE_SD_CARD + #define SD_CS 4 // SD card chip select #define TFT_CS 10 // TFT select pin #define TFT_DC 8 // TFT data/command pin #define TFT_RST 9 // Or set to -1 and connect TFT RST to Arduino reset pin +#if defined(USE_SD_CARD) + SdFat SD; // SD card filesystem + Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys +#else + // SPI or QSPI flash filesystem (i.e. CIRCUITPY drive) + #if defined(__SAMD51__) || defined(NRF52840_XXAA) + Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, + PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3); + #else + #if (SPI_INTERFACES_COUNT == 1) + Adafruit_FlashTransport_SPI flashTransport(SS, &SPI); + #else + Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1); + #endif + #endif + Adafruit_SPIFlash flash(&flashTransport); + FatFileSystem filesys; + Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys +#endif + Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); -Adafruit_ImageReader reader; // Class w/image-reading functions Adafruit_Image img; // An image loaded into RAM int32_t width = 0, // BMP image dimensions height = 0; @@ -40,11 +62,28 @@ void setup(void) { tft.initR(INITR_MINI160x80); // Initialize screen Serial.println(F("TFT initialized.")); - Serial.print(F("Initializing SD card...")); - if(!SD.begin(SD_CS)) { - Serial.println(F("failed!")); - for(;;); // Loop here forever + // The Adafruit_ImageReader constructor call (above, before setup()) + // accepts an uninitialized SdFat or FatFileSystem object. This MUST + // BE INITIALIZED before using any of the image reader functions! + Serial.print(F("Initializing filesystem...")); +#if defined(USE_SD_CARD) + // SD card is pretty straightforward, a single call... + if(!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires + Serial.println(F("SD begin() failed")); + for(;;); // Fatal error, do not continue } +#else + // SPI or QSPI flash requires two steps, one to access the bare flash + // memory itself, then the second to access the filesystem within... + if(!flash.begin()) { + Serial.println(F("flash begin() failed")); + for(;;); + } + if(!filesys.begin(&flash)) { + Serial.println(F("filesys begin() failed")); + for(;;); + } +#endif Serial.println(F("OK!")); // Fill screen blue. Not a required step, this just shows that we're diff --git a/examples/BreakoutST7789-320x240/BreakoutST7789-320x240.ino b/examples/BreakoutST7789-320x240/BreakoutST7789-320x240.ino index 22c46b1..cf4a04d 100644 --- a/examples/BreakoutST7789-320x240/BreakoutST7789-320x240.ino +++ b/examples/BreakoutST7789-320x240/BreakoutST7789-320x240.ino @@ -7,12 +7,15 @@ // (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno, // MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below. -#include -#include #include // Core graphics library #include // Hardware-specific library for ST7789 +#include // SD card & FAT filesystem library +#include // SPI / QSPI flash library #include // Image-reading functions +// Comment out the next line to load from SPI/QSPI flash instead of SD card: +#define USE_SD_CARD + // TFT display and SD card share the hardware SPI interface, using // 'select' pins for each to identify the active device on the bus. @@ -21,8 +24,27 @@ #define TFT_DC 8 // TFT display/command pin #define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin +#if defined(USE_SD_CARD) + SdFat SD; // SD card filesystem + Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys +#else + // SPI or QSPI flash filesystem (i.e. CIRCUITPY drive) + #if defined(__SAMD51__) || defined(NRF52840_XXAA) + Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, + PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3); + #else + #if (SPI_INTERFACES_COUNT == 1) + Adafruit_FlashTransport_SPI flashTransport(SS, &SPI); + #else + Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1); + #endif + #endif + Adafruit_SPIFlash flash(&flashTransport); + FatFileSystem filesys; + Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys +#endif + Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); -Adafruit_ImageReader reader; // Class w/image-reading functions Adafruit_Image img; // An image loaded into RAM int32_t width = 0, // BMP image dimensions height = 0; @@ -36,13 +58,30 @@ void setup(void) { while(!Serial); // Wait for Serial Monitor before continuing #endif - tft.init(240, 320); // Init ST7789 240x240 + tft.init(240, 320); // Init ST7789 320x240 - Serial.print(F("Initializing SD card...")); - if(!SD.begin(SD_CS)) { - Serial.println(F("failed!")); - for(;;); // Loop here forever + // The Adafruit_ImageReader constructor call (above, before setup()) + // accepts an uninitialized SdFat or FatFileSystem object. This MUST + // BE INITIALIZED before using any of the image reader functions! + Serial.print(F("Initializing filesystem...")); +#if defined(USE_SD_CARD) + // SD card is pretty straightforward, a single call... + if(!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires + Serial.println(F("SD begin() failed")); + for(;;); // Fatal error, do not continue } +#else + // SPI or QSPI flash requires two steps, one to access the bare flash + // memory itself, then the second to access the filesystem within... + if(!flash.begin()) { + Serial.println(F("flash begin() failed")); + for(;;); + } + if(!filesys.begin(&flash)) { + Serial.println(F("filesys begin() failed")); + for(;;); + } +#endif Serial.println(F("OK!")); // Fill screen blue. Not a required step, this just shows that we're diff --git a/examples/FeatherWingST7735/FeatherWingST7735.ino b/examples/FeatherWingST7735/FeatherWingST7735.ino index 9089e4f..2ad9f22 100644 --- a/examples/FeatherWingST7735/FeatherWingST7735.ino +++ b/examples/FeatherWingST7735/FeatherWingST7735.ino @@ -1,27 +1,51 @@ // Adafruit_ImageReader test for Mini TFT FeatherWing. Demonstrates loading -// images to the screen, to RAM, and how to query image file dimensions. -// OPEN THE ARDUINO SERIAL MONITOR WINDOW TO START PROGRAM. -// Requires three BMP files in root directory of SD card: -// minibot.bmp, rgbwheel.bmp and wales.bmp. +// images from SD card or flash memory to the screen, to RAM, and how to +// query image file dimensions. OPEN THE ARDUINO SERIAL MONITOR WINDOW TO +// START PROGRAM. Requires three BMP files in root directory of SD card or +// flash: minibot.bmp, rgbwheel.bmp and wales.bmp. // This ONLY demonstrates BMP loading. Other features of the FeatherWing // (stick, buttons, backlight control) are NOT demonstrated here, // see other ST7735 library examples for that. // MINI TFT FEATHERWING REQUIRES Adafruit_Seesaw LIBRARY. -#include -#include #include // Core graphics library #include // Hardware-specific library +#include // SD card & FAT filesystem library +#include // SPI / QSPI flash library #include // Image-reading functions #include // Part of Seesaw library +// Comment out the next line to load from SPI/QSPI flash instead of SD card: +#define USE_SD_CARD + #define TFT_CS 5 // TFT chip select (FeatherWing) #define TFT_DC 6 // TFT data/command select (FeatherWing) #define TFT_RST -1 // FeatherWing uses Seesaw for TFT reset -#define SD_CS 4 // SD card chip select (Feather AdaLogger 32u4 or M0) + +#define SD_CS 4 // SD card chip select (Feather AdaLogger 32u4 or M0) OR use 10 + // for Adalogger FeatherWing + +#if defined(USE_SD_CARD) + SdFat SD; // SD card filesystem + Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys +#else + // SPI or QSPI flash filesystem (i.e. CIRCUITPY drive) + #if defined(__SAMD51__) || defined(NRF52840_XXAA) + Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, + PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3); + #else + #if (SPI_INTERFACES_COUNT == 1) + Adafruit_FlashTransport_SPI flashTransport(SS, &SPI); + #else + Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1); + #endif + #endif + Adafruit_SPIFlash flash(&flashTransport); + FatFileSystem filesys; + Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys +#endif Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); -Adafruit_ImageReader reader; // Class w/image-reading functions Adafruit_Image img; // An image loaded into RAM int32_t width = 0, // BMP image dimensions height = 0; @@ -46,11 +70,28 @@ void setup(void) { tft.initR(INITR_MINI160x80); // Initialize screen Serial.println(F("TFT initialized.")); - Serial.print(F("Initializing SD card...")); - if(!SD.begin(SD_CS)) { - Serial.println(F("failed!")); - for(;;); // Loop here forever + // The Adafruit_ImageReader constructor call (above, before setup()) + // accepts an uninitialized SdFat or FatFileSystem object. This MUST + // BE INITIALIZED before using any of the image reader functions! + Serial.print(F("Initializing filesystem...")); +#if defined(USE_SD_CARD) + // SD card is pretty straightforward, a single call... + if(!SD.begin(SD_CS, SD_SCK_MHZ(25))) { // ESP32 requires 25 MHz limit + Serial.println(F("SD begin() failed")); + for(;;); // Fatal error, do not continue } +#else + // SPI or QSPI flash requires two steps, one to access the bare flash + // memory itself, then the second to access the filesystem within... + if(!flash.begin()) { + Serial.println(F("flash begin() failed")); + for(;;); + } + if(!filesys.begin(&flash)) { + Serial.println(F("filesys begin() failed")); + for(;;); + } +#endif Serial.println(F("OK!")); // Fill screen blue. Not a required step, this just shows that we're diff --git a/examples/ShieldILI9341/ShieldILI9341.ino b/examples/ShieldILI9341/ShieldILI9341.ino index aacdf71..6dad711 100644 --- a/examples/ShieldILI9341/ShieldILI9341.ino +++ b/examples/ShieldILI9341/ShieldILI9341.ino @@ -1,27 +1,49 @@ // Adafruit_ImageReader test for Adafruit ILI9341 TFT Shield for Arduino. -// Demonstrates loading images to the screen, to RAM, and how to query -// image file dimensions. +// Demonstrates loading images from SD card or flash memory to the screen, +// to RAM, and how to query image file dimensions. // Requires three BMP files in root directory of SD card: // purple.bmp, parrot.bmp and wales.bmp. +// As written, this uses the microcontroller's SPI interface for the screen +// (not 'bitbang') and must be wired to specific pins (e.g. for Arduino Uno, +// MOSI = pin 11, MISO = 12, SCK = 13). Other pins are configurable below. -#include -#include #include // Core graphics library #include // Hardware-specific library +#include // SD card & FAT filesystem library +#include // SPI / QSPI flash library #include // Image-reading functions +// Comment out the next line to load from SPI/QSPI flash instead of SD card: +#define USE_SD_CARD + // TFT display and SD card share the hardware SPI interface, using // 'select' pins for each to identify the active device on the bus. -// Hardware SPI pins are specific to the Arduino board type and -// cannot be remapped to alternate pins. For Arduino Uno, -// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK. #define SD_CS 4 // SD card select pin #define TFT_CS 10 // TFT select pin #define TFT_DC 9 // TFT display/command pin +#if defined(USE_SD_CARD) + SdFat SD; // SD card filesystem + Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys +#else + // SPI or QSPI flash filesystem (i.e. CIRCUITPY drive) + #if defined(__SAMD51__) || defined(NRF52840_XXAA) + Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, + PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3); + #else + #if (SPI_INTERFACES_COUNT == 1) + Adafruit_FlashTransport_SPI flashTransport(SS, &SPI); + #else + Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1); + #endif + #endif + Adafruit_SPIFlash flash(&flashTransport); + FatFileSystem filesys; + Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys +#endif + Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); -Adafruit_ImageReader reader; // Class w/image-reading functions Adafruit_Image img; // An image loaded into RAM int32_t width = 0, // BMP image dimensions height = 0; @@ -37,11 +59,28 @@ void setup(void) { tft.begin(); // Initialize screen - Serial.print(F("Initializing SD card...")); - if(!SD.begin(SD_CS)) { - Serial.println(F("failed!")); - for(;;); // Loop here forever + // The Adafruit_ImageReader constructor call (above, before setup()) + // accepts an uninitialized SdFat or FatFileSystem object. This MUST + // BE INITIALIZED before using any of the image reader functions! + Serial.print(F("Initializing filesystem...")); +#if defined(USE_SD_CARD) + // SD card is pretty straightforward, a single call... + if(!SD.begin(SD_CS, SD_SCK_MHZ(25))) { // ESP32 requires 25 MHz limit + Serial.println(F("SD begin() failed")); + for(;;); // Fatal error, do not continue } +#else + // SPI or QSPI flash requires two steps, one to access the bare flash + // memory itself, then the second to access the filesystem within... + if(!flash.begin()) { + Serial.println(F("flash begin() failed")); + for(;;); + } + if(!filesys.begin(&flash)) { + Serial.println(F("filesys begin() failed")); + for(;;); + } +#endif Serial.println(F("OK!")); // Fill screen blue. Not a required step, this just shows that we're diff --git a/examples/ShieldST7735/ShieldST7735.ino b/examples/ShieldST7735/ShieldST7735.ino index 5d8b6e0..1e54491 100644 --- a/examples/ShieldST7735/ShieldST7735.ino +++ b/examples/ShieldST7735/ShieldST7735.ino @@ -1,6 +1,6 @@ // Adafruit_ImageReader test for Adafruit ST7735 TFT Shield for Arduino. -// Demonstrates loading images to the screen, to RAM, and how to query -// image file dimensions. +// Demonstrates loading images from SD card or flash memory to the screen, +// to RAM, and how to query image file dimensions. // Requires three BMP files in root directory of SD card: // parrot.bmp, miniwoof.bmp and wales.bmp. // This ONLY demonstrates BMP loading. Other features of the shield @@ -8,14 +8,17 @@ // see other ST7735 library examples for that. // CURRENT TFT SHIELD REQUIRES Adafruit_Seesaw LIBRARY. -#include -#include #include // Core graphics library #include // Hardware-specific library +#include // SD card & FAT filesystem library +#include // SPI / QSPI flash library #include // Image-reading functions #include // IF EARLY TFT SHIELD (no Seesaw), #include // THESE TWO LINES CAN BE REMOVED. +// Comment out the next line to load from SPI/QSPI flash instead of SD card: +#define USE_SD_CARD + // TFT display and SD card share the hardware SPI interface, using // 'select' pins for each to identify the active device on the bus. @@ -24,9 +27,28 @@ #define TFT_DC 8 // TFT display/command pin #define TFT_RST -1 // TFT reset pin +#if defined(USE_SD_CARD) + SdFat SD; // SD card filesystem + Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys +#else + // SPI or QSPI flash filesystem (i.e. CIRCUITPY drive) + #if defined(__SAMD51__) || defined(NRF52840_XXAA) + Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, + PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3); + #else + #if (SPI_INTERFACES_COUNT == 1) + Adafruit_FlashTransport_SPI flashTransport(SS, &SPI); + #else + Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1); + #endif + #endif + Adafruit_SPIFlash flash(&flashTransport); + FatFileSystem filesys; + Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys +#endif + Adafruit_TFTShield18 seesaw; Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); -Adafruit_ImageReader reader; // Class w/image-reading functions Adafruit_Image img; // An image loaded into RAM int32_t width = 0, // BMP image dimensions height = 0; @@ -50,11 +72,28 @@ void setup(void) { tft.initR(INITR_BLACKTAB); // Initialize screen - Serial.print(F("Initializing SD card...")); - if(!SD.begin(SD_CS)) { - Serial.println(F("failed!")); - for(;;); // Loop here forever + // The Adafruit_ImageReader constructor call (above, before setup()) + // accepts an uninitialized SdFat or FatFileSystem object. This MUST + // BE INITIALIZED before using any of the image reader functions! + Serial.print(F("Initializing filesystem...")); +#if defined(USE_SD_CARD) + // SD card is pretty straightforward, a single call... + if(!SD.begin(SD_CS, SD_SCK_MHZ(25))) { // ESP32 requires 25 MHz limit + Serial.println(F("SD begin() failed")); + for(;;); // Fatal error, do not continue } +#else + // SPI or QSPI flash requires two steps, one to access the bare flash + // memory itself, then the second to access the filesystem within... + if(!flash.begin()) { + Serial.println(F("flash begin() failed")); + for(;;); + } + if(!filesys.begin(&flash)) { + Serial.println(F("filesys begin() failed")); + for(;;); + } +#endif Serial.println(F("OK!")); // Fill screen blue. Not a required step, this just shows that we're