Skip to content

Commit

Permalink
Support loading of SD for other architectures
Browse files Browse the repository at this point in the history
Plus improved explanatory comments
  • Loading branch information
Bodmer committed Feb 10, 2017
1 parent 55d3b76 commit aa55ce8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

// Images on SD Card must be put in the root folder (top level) to be found
// Use the SdFat or SD library examples to verify your SD Card interface works!

// Uncomment the #define LOAD_SDFAT_LIBRARY in User_Config.h in the JPEGDecoder src folder
// if the Due is used with the SdFat library. SdFat allows bit bashing the SPI if needed.

// The example images used to test this sketch can be found in the library
// JPEGDecoder/extras folder
//----------------------------------------------------------------------------------------------------
Expand All @@ -53,7 +57,7 @@
TFT_HX8357 tft = TFT_HX8357(); // Invoke custom Mega library
#elif defined (ARDUINO_ARCH_SAM)
// Due libraries
#include <SdFat.h> // Use the SdFat library for the Due
#include <SdFat.h> // Use the SdFat library for the Due, see sketch header notes above
SdFat SD; // Permit SD function call for the Due
#include <TFT_HX8357_Due.h> // Hardware-specific Due library
TFT_HX8357_Due tft = TFT_HX8357_Due(); // Invoke custom Due library
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "JPEGDecoder",
"version": "1.7.3",
"version": "1.7.4",
"keywords": "jpeg, jpg, decoder, TFT",
"description": "A JPEG decoder library, tested on Mega, Due and ESP8266",
"repository":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=JPEGDecoder
version=1.7.3
version=1.7.4
author=Bodmer <bodmer@anola.net>, Makoto Kurauchi, Rich Geldreich
maintainer=Bodmer
sentence= Jpeg decoder tested with Arduino Mega, Arduino Due and ESP8266 based NodeMCU 1.0
Expand Down
14 changes: 7 additions & 7 deletions src/JPEGDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ uint8_t JPEGDecoder::pjpeg_need_bytes_callback(uint8_t* pBuf, uint8_t buf_size,
if (jpg_source == JPEG_FS_FILE) g_pInFileFs.read(pBuf,n); // else we are handling a file
#endif

#ifdef LOAD_SD_LIBRARY
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
if (jpg_source == JPEG_SD_FILE) g_pInFileSd.read(pBuf,n); // else we are handling a file
#endif

Expand Down Expand Up @@ -274,13 +274,13 @@ int JPEGDecoder::readSwappedBytes(void) {
int JPEGDecoder::decodeFile(const char *pFilename){

#ifdef ESP8266
#ifdef LOAD_SD_LIBRARY
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
if (*pFilename == '/')
#endif
return decodeFsFile(pFilename);
#endif

#ifdef LOAD_SD_LIBRARY
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
return decodeSdFile(pFilename);
#endif

Expand All @@ -290,13 +290,13 @@ int JPEGDecoder::decodeFile(const char *pFilename){
int JPEGDecoder::decodeFile(const String& pFilename){

#ifdef ESP8266
#ifdef LOAD_SD_LIBRARY
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
if (pFilename.charAt(0) == '/')
#endif
return decodeFsFile(pFilename);
#endif

#ifdef LOAD_SD_LIBRARY
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
return decodeSdFile(pFilename);
#endif

Expand Down Expand Up @@ -345,7 +345,7 @@ int JPEGDecoder::decodeFsFile(fs::File jpgFile) { // This is for the SPIFFS libr
#endif


#ifdef LOAD_SD_LIBRARY
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)

// Call specific to SD filing system in case leading / is used
int JPEGDecoder::decodeSdFile(const char *pFilename) {
Expand Down Expand Up @@ -465,7 +465,7 @@ void JPEGDecoder::abort(void) {
if (jpg_source == JPEG_FS_FILE) if (g_pInFileFs) g_pInFileFs.close();
#endif

#ifdef LOAD_SD_LIBRARY
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
if (jpg_source == JPEG_SD_FILE) if (g_pInFileSd) g_pInFileSd.close();
#endif
}
24 changes: 10 additions & 14 deletions src/JPEGDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ Latest version here:
#include "arduino.h"
#include <pgmspace.h>

// If the sketch has included FS.h without setting FS_NO_GLOBALS then it is likely
// If the sketch has included FS.h without setting FS_NO_GLOBALS first then it is likely
// there will be a redefinition of 'class fs::File' error due to conflict with the
// SD library, so we can't load the SD library.
#if !defined (FS_NO_GLOBALS) && defined (FS_H)
#undef LOAD_SD_LIBRARY
#undef LOAD_SDFAT_LIBRARY
#endif

#ifdef ESP32 // SD library not compatible with ESP32
#undef LOAD_SD_LIBRARY
#endif

#ifdef LOAD_SD_LIBRARY
#include <SD.h>
#undef LOAD_SDFAT_LIBRARY // Compatibility untested
#endif

#ifndef ESP32 // ESP32 does not support SPIFFS yet
Expand All @@ -44,18 +42,16 @@ Latest version here:
#include <FS.h>
#endif

#else
#endif

#ifdef LOAD_SD_LIBRARY
#if defined (ARDUINO_ARCH_AVR)
#include <SD.h> // For the Mega
#elif defined (ARDUINO_ARCH_SAM)
//#include <SdFat.h> // For Due etc where we might need to bit bash the SPI
#include <SD.h> // Alternative
#endif
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
#ifdef LOAD_SDFAT_LIBRARY
#include <SdFat.h> // Alternative where we might need to bit bash the SPI
#else
#include <SD.h> // Default
#endif

#endif


#include "picojpeg.h"

Expand Down
46 changes: 37 additions & 9 deletions src/User_Config.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
// Comment out the next #define if you are not using an SD Card to store the JPEGs
// Comment out the next #defines if you are not using an SD Card to store the JPEGs
// Commenting out the line is NOT essential but will save some FLASH space if
// SD Card access is not needed.
// SD Card access is not needed. Note: use of SdFat is currently untested!

#define LOAD_SD_LIBRARY
#define LOAD_SD_LIBRARY // Default SD Card library
//#define LOAD_SDFAT_LIBRARY // Use SdFat library instead, so SD Card SPI can be bit bashed


// Note for ESP8266 users:
// If the sketch uses SPIFFS and has included FS.h without defining FS_NO_GLOBALS first
// then the JPEGDecoder library will NOT load the SD or SdFat libraries. Use lines thus
// in your sketch (see the examples included in the JPEGDecoder library):
/*
#define FS_NO_GLOBALS
#include <FS.h>
// You will then need to directly reference the SPIFFS File type thus in the sketch, e.g.:
fs::File jpegFile = SPIFFS.open( filename, "r"); // Example
// This will then allow the default method of using the SD library File type to be used
// in the same sketch, e.g.:
File jpegFile = SD.open( filename, FILE_READ);
*/

// This is all to avoid a redefinition of 'class fs::File' error due to a conflict between the
// duplicate definitions in the SD library and the SPIFFS library.


#ifdef ESP8266
// Comment out the next #define if you do not want the bytes swapped in the
// the image blocks returned by read(). Swapping the bytes does mean pixel blocks can be
// written to the screen faster using the ESP8266 SPI library writePattern()
// member function. Comment out for "normal" byte order. Images will look pyscodelic
// with wrong colours if the byte order is not right for your sketch!
// #define SWAP_BYTES
// Unomment out the next #define if you want the bytes swapped in the image blocks
// returned by read().

// Swapping the bytes is only needed to use the ESP8266 SPI library writePattern()
// member function and it is better to use readSwappedBytes() instead of read() in
// the sketch. Images will look pyscodelic with wrong colours if the SPI transmit byte
// order is not right for your sketch!

// #define SWAP_BYTES // Deprecated, only included for backwards compatibility
#endif

0 comments on commit aa55ce8

Please sign in to comment.