Skip to content

Commit aa55ce8

Browse files
committed
Support loading of SD for other architectures
Plus improved explanatory comments
1 parent 55d3b76 commit aa55ce8

6 files changed

Lines changed: 61 additions & 33 deletions

File tree

examples/Other libraries/Mega and Due/TFT_SDcard_jpg/TFT_SDcard_jpg.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434

3535
// Images on SD Card must be put in the root folder (top level) to be found
3636
// Use the SdFat or SD library examples to verify your SD Card interface works!
37+
38+
// Uncomment the #define LOAD_SDFAT_LIBRARY in User_Config.h in the JPEGDecoder src folder
39+
// if the Due is used with the SdFat library. SdFat allows bit bashing the SPI if needed.
40+
3741
// The example images used to test this sketch can be found in the library
3842
// JPEGDecoder/extras folder
3943
//----------------------------------------------------------------------------------------------------
@@ -53,7 +57,7 @@
5357
TFT_HX8357 tft = TFT_HX8357(); // Invoke custom Mega library
5458
#elif defined (ARDUINO_ARCH_SAM)
5559
// Due libraries
56-
#include <SdFat.h> // Use the SdFat library for the Due
60+
#include <SdFat.h> // Use the SdFat library for the Due, see sketch header notes above
5761
SdFat SD; // Permit SD function call for the Due
5862
#include <TFT_HX8357_Due.h> // Hardware-specific Due library
5963
TFT_HX8357_Due tft = TFT_HX8357_Due(); // Invoke custom Due library

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "JPEGDecoder",
3-
"version": "1.7.3",
3+
"version": "1.7.4",
44
"keywords": "jpeg, jpg, decoder, TFT",
55
"description": "A JPEG decoder library, tested on Mega, Due and ESP8266",
66
"repository":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=JPEGDecoder
2-
version=1.7.3
2+
version=1.7.4
33
author=Bodmer <bodmer@anola.net>, Makoto Kurauchi, Rich Geldreich
44
maintainer=Bodmer
55
sentence= Jpeg decoder tested with Arduino Mega, Arduino Due and ESP8266 based NodeMCU 1.0

src/JPEGDecoder.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ uint8_t JPEGDecoder::pjpeg_need_bytes_callback(uint8_t* pBuf, uint8_t buf_size,
8080
if (jpg_source == JPEG_FS_FILE) g_pInFileFs.read(pBuf,n); // else we are handling a file
8181
#endif
8282

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

@@ -274,13 +274,13 @@ int JPEGDecoder::readSwappedBytes(void) {
274274
int JPEGDecoder::decodeFile(const char *pFilename){
275275

276276
#ifdef ESP8266
277-
#ifdef LOAD_SD_LIBRARY
277+
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
278278
if (*pFilename == '/')
279279
#endif
280280
return decodeFsFile(pFilename);
281281
#endif
282282

283-
#ifdef LOAD_SD_LIBRARY
283+
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
284284
return decodeSdFile(pFilename);
285285
#endif
286286

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

292292
#ifdef ESP8266
293-
#ifdef LOAD_SD_LIBRARY
293+
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
294294
if (pFilename.charAt(0) == '/')
295295
#endif
296296
return decodeFsFile(pFilename);
297297
#endif
298298

299-
#ifdef LOAD_SD_LIBRARY
299+
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
300300
return decodeSdFile(pFilename);
301301
#endif
302302

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

347347

348-
#ifdef LOAD_SD_LIBRARY
348+
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
349349

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

468-
#ifdef LOAD_SD_LIBRARY
468+
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
469469
if (jpg_source == JPEG_SD_FILE) if (g_pInFileSd) g_pInFileSd.close();
470470
#endif
471471
}

src/JPEGDecoder.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,17 @@ Latest version here:
2323
#include "arduino.h"
2424
#include <pgmspace.h>
2525

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

3334
#ifdef ESP32 // SD library not compatible with ESP32
3435
#undef LOAD_SD_LIBRARY
35-
#endif
36-
37-
#ifdef LOAD_SD_LIBRARY
38-
#include <SD.h>
36+
#undef LOAD_SDFAT_LIBRARY // Compatibility untested
3937
#endif
4038

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

47-
#else
45+
#endif
4846

49-
#ifdef LOAD_SD_LIBRARY
50-
#if defined (ARDUINO_ARCH_AVR)
51-
#include <SD.h> // For the Mega
52-
#elif defined (ARDUINO_ARCH_SAM)
53-
//#include <SdFat.h> // For Due etc where we might need to bit bash the SPI
54-
#include <SD.h> // Alternative
55-
#endif
47+
#if defined (LOAD_SD_LIBRARY) || defined (LOAD_SDFAT_LIBRARY)
48+
#ifdef LOAD_SDFAT_LIBRARY
49+
#include <SdFat.h> // Alternative where we might need to bit bash the SPI
50+
#else
51+
#include <SD.h> // Default
5652
#endif
57-
5853
#endif
54+
5955

6056
#include "picojpeg.h"
6157

src/User_Config.h

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
1-
// Comment out the next #define if you are not using an SD Card to store the JPEGs
1+
// Comment out the next #defines if you are not using an SD Card to store the JPEGs
22
// Commenting out the line is NOT essential but will save some FLASH space if
3-
// SD Card access is not needed.
3+
// SD Card access is not needed. Note: use of SdFat is currently untested!
44

5-
#define LOAD_SD_LIBRARY
5+
#define LOAD_SD_LIBRARY // Default SD Card library
6+
//#define LOAD_SDFAT_LIBRARY // Use SdFat library instead, so SD Card SPI can be bit bashed
7+
8+
9+
// Note for ESP8266 users:
10+
// If the sketch uses SPIFFS and has included FS.h without defining FS_NO_GLOBALS first
11+
// then the JPEGDecoder library will NOT load the SD or SdFat libraries. Use lines thus
12+
// in your sketch (see the examples included in the JPEGDecoder library):
13+
/*
14+
#define FS_NO_GLOBALS
15+
#include <FS.h>
16+
17+
// You will then need to directly reference the SPIFFS File type thus in the sketch, e.g.:
18+
19+
fs::File jpegFile = SPIFFS.open( filename, "r"); // Example
20+
21+
// This will then allow the default method of using the SD library File type to be used
22+
// in the same sketch, e.g.:
23+
24+
File jpegFile = SD.open( filename, FILE_READ);
25+
26+
*/
27+
28+
// This is all to avoid a redefinition of 'class fs::File' error due to a conflict between the
29+
// duplicate definitions in the SD library and the SPIFFS library.
30+
631

732
#ifdef ESP8266
8-
// Comment out the next #define if you do not want the bytes swapped in the
9-
// the image blocks returned by read(). Swapping the bytes does mean pixel blocks can be
10-
// written to the screen faster using the ESP8266 SPI library writePattern()
11-
// member function. Comment out for "normal" byte order. Images will look pyscodelic
12-
// with wrong colours if the byte order is not right for your sketch!
13-
// #define SWAP_BYTES
33+
// Unomment out the next #define if you want the bytes swapped in the image blocks
34+
// returned by read().
35+
36+
// Swapping the bytes is only needed to use the ESP8266 SPI library writePattern()
37+
// member function and it is better to use readSwappedBytes() instead of read() in
38+
// the sketch. Images will look pyscodelic with wrong colours if the SPI transmit byte
39+
// order is not right for your sketch!
40+
41+
// #define SWAP_BYTES // Deprecated, only included for backwards compatibility
1442
#endif

0 commit comments

Comments
 (0)