diff --git a/examples/Example11_BigFont/Example11_BigFont.ino b/examples/Example11_BigFont/Example11_BigFont.ino new file mode 100644 index 0000000..3300479 --- /dev/null +++ b/examples/Example11_BigFont/Example11_BigFont.ino @@ -0,0 +1,87 @@ +/* + SFE_MicroOLED Library Demo + Paul Clark @ SparkFun Electronics + Original Creation Date: April 3rd, 2021 + + This sketch demonstrates how to use the Large Letter 31x48 font. + This font is disabled by default. To enable it, you need to edit + SFE_MicroOLED.cpp and change line 85 (or thereabouts) from: + #define INCLUDE_FONT_LARGELETTER 0 + to: + #define INCLUDE_FONT_LARGELETTER 1 + + Hardware Connections: + This example assumes you are using Qwiic. See the SPI examples for + a detailed breakdown of connection info. + + Want to support open source hardware? Buy a board from SparkFun! + https://www.sparkfun.com/products/13003 + https://www.sparkfun.com/products/14532 + + This code is beerware; if you see me (or any other SparkFun employee) at the + local, and you've found our code helpful, please buy us a round! + + Distributed as-is; no warranty is given. +*/ + +#include +#include //Click here to get the library: http://librarymanager/All#SparkFun_Micro_OLED + +#define PIN_RESET 9 + +// From version v1.3, we can instantiate oled like this (but only for I2C) +MicroOLED oled(PIN_RESET); + +void setup() +{ + Serial.begin(115200); // Begin the Serial port + Serial.println(F("SparkFun MicroOLED Example")); + + delay(100); + Wire.begin(); + + // This is the new way of initializing the OLED. + // We can pass a different I2C address and TwoWire port + // If 0x3D does not work, try 0x3C + oled.begin(0x3D, Wire); // Initialize the OLED + + // Print the total number of fonts loaded into memory + Serial.print(F("There are ")); + Serial.print(oled.getTotalFonts()); + Serial.println(F(" fonts available")); + + oled.clear(ALL); // Clear the display's internal memory + oled.display(); // Display what's in the buffer (splashscreen) + + delay(1000); // Delay 1000 ms + + oled.clear(PAGE); // Clear the buffer. + + if (oled.setFontType(4) == 0) // Set font to type 4 (fontlargeletter31x48) + { + Serial.println(F("Could not enable font 4 (fontlargeletter31x48)!")); + Serial.println(F("Have you changed the #define INCLUDE_FONT_LARGELETTER to 1 in SFE_MicroOLED.cpp?")); + Serial.println(F("Freezing...")); + while (1) + ; // Do nothing more + } +} + +void loop() +{ + // Demonstrate font 4 + // There are 58 possible characters in the font 4 type: A - z + // Lets run through all of them and print them out! + for (int i = 'A'; i <= 'z'; i += 2) + { + oled.clear(PAGE); // Clear the screen + + oled.setCursor(0, 0); // Set cursor to top-left + + oled.write(i); // Write a byte out as a character + oled.write(i+1); // Write the next byte out as a character + oled.display(); // Draw on the screen + + delay(500); // Delay 500 ms + } +} diff --git a/library.json b/library.json index 9795482..86e43dc 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "SparkFun Micro OLED Breakout", - "version": "1.3.1", + "version": "1.3.2", "keywords": "display oled", "description": "Library for the SparkFun Micro OLED Breakout", "repository": diff --git a/library.properties b/library.properties index 197e759..35682dd 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun Micro OLED Breakout -version=1.3.1 +version=1.3.2 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Library for the SparkFun Micro OLED Breakout. diff --git a/src/SFE_MicroOLED.cpp b/src/SFE_MicroOLED.cpp index 6583771..c688070 100644 --- a/src/SFE_MicroOLED.cpp +++ b/src/SFE_MicroOLED.cpp @@ -34,10 +34,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ******************************************************************************/ #include -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) -#include +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) + #include #else -#include + #include #endif #include @@ -45,36 +47,72 @@ along with this program. If not, see . #define _BV(x) (1 << x) #endif -// The 31x48 font is handy, but uses a big chunk of flash memory - about 7k. -// If you want to use font 4 in your sketch, uncomment out the line below: -//#define INCLUDE_LARGE_LETTER_FONT - // This fixed ugly GCC warning "only initialized variables can be placed into program memory area" #if defined(__AVR__) #undef PROGMEM #define PROGMEM __attribute__((section(".progmem.data"))) #endif -// Add header of the fonts here. Remove as many as possible to conserve FLASH memory. -#include "util/font5x7.h" -#include "util/font8x16.h" -#include "util/fontlargenumber.h" -#include "util/7segment.h" -#include "util/fontlargeletter31x48.h" - -// Change the total fonts included -#ifdef INCLUDE_LARGE_LETTER_FONT -#define TOTALFONTS 5 -#else -#define TOTALFONTS 4 +// Add header of the fonts here. +// Fonts that aren't included the section below are excluded by the compiler. +#include "util/font5x7.h" // Font 0 +#include "util/font8x16.h" // Font 1 +#include "util/7segment.h" // Font 2 +#include "util/fontlargenumber.h" // Font 3 +#include "util/fontlargeletter31x48.h" // Font 4 (excluded by default - see below) + +#define MAXFONTS 5 // Do not change this line - except when _adding_ new fonts + +// To save flash memory, change these to zeros for the fonts you want to exclude. +// In particular, the 31x48 font is handy, but uses a big +// chunk of flash memory - about 7k. It is excluded by default. +// +// If you are compiling the code using your own makefile, you can use compiler flags to include +// or exclude individual fonts. E.g.: -DINCLUDE_FONT_LARGELETTER=1 or -DINCLUDE_FONT_LARGENUMBER=0 +#ifndef INCLUDE_FONT_5x7 +#define INCLUDE_FONT_5x7 1 // Change this to 0 to exclude the 5x7 font +#endif +#ifndef INCLUDE_FONT_8x16 +#define INCLUDE_FONT_8x16 1 // Change this to 0 to exclude the 8x16 font +#endif +#ifndef INCLUDE_FONT_7SEG +#define INCLUDE_FONT_7SEG 1 // Change this to 0 to exclude the seven segment font #endif +#ifndef INCLUDE_FONT_LARGENUMBER +#define INCLUDE_FONT_LARGENUMBER 1 // Change this to 0 to exclude the large number font +#endif +#ifndef INCLUDE_FONT_LARGELETTER +#define INCLUDE_FONT_LARGELETTER 0 // Change this to 1 to include the large letter font +#endif + -// Add the font name as declared in the header file. Remove as many as possible to conserve FLASH memory. +// Add the font name as declared in the header file. +// Exclude as many as possible to conserve FLASH memory. const unsigned char *MicroOLED::fontsPointer[] = { - font5x7, font8x16, sevensegment, fontlargenumber -#ifdef INCLUDE_LARGE_LETTER_FONT - , +#if INCLUDE_FONT_5x7 + font5x7, +#else + NULL, +#endif +#if INCLUDE_FONT_8x16 + font8x16, +#else + NULL, +#endif +#if INCLUDE_FONT_7SEG + sevensegment, +#else + NULL, +#endif +#if INCLUDE_FONT_LARGENUMBER + fontlargenumber, +#else + NULL, +#endif +#if INCLUDE_FONT_LARGELETTER fontlargeletter31x48 +#else + NULL #endif }; @@ -997,7 +1035,13 @@ uint8_t MicroOLED::getFontTotalChar(void) */ uint8_t MicroOLED::getTotalFonts(void) { - return TOTALFONTS; + uint8_t totalFonts = 0; + for (uint8_t thisFont = 0; thisFont < MAXFONTS; thisFont++) + { + if (fontsPointer[thisFont] != NULL) + totalFonts++; + } + return (totalFonts); } /** \brief Get font type. @@ -1015,8 +1059,8 @@ uint8_t MicroOLED::getFontType(void) */ uint8_t MicroOLED::setFontType(uint8_t type) { - if ((type >= TOTALFONTS) || (type < 0)) - return false; + if ((type >= MAXFONTS) || (fontsPointer[type] == NULL)) + return false; fontType = type; fontWidth = pgm_read_byte(fontsPointer[fontType] + 0); diff --git a/src/SFE_MicroOLED.h b/src/SFE_MicroOLED.h index 5e79e84..534ec81 100644 --- a/src/SFE_MicroOLED.h +++ b/src/SFE_MicroOLED.h @@ -44,10 +44,12 @@ along with this program. If not, see . #include // Needed for TwoWire - even if we are using SPI or Parallel #include // Needed for SPIClass - even if we are using I2C or Parallel -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) -#include +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) + #include #else -#include + #include #endif #define I2C_ADDRESS_SA0_0 0b0111100 diff --git a/src/util/7segment.h b/src/util/7segment.h index 61fe37b..1559559 100644 --- a/src/util/7segment.h +++ b/src/util/7segment.h @@ -25,13 +25,16 @@ July 27, 2015 #ifndef FONT7SEGMENT_H #define FONT7SEGMENT_H -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM + static const unsigned char sevensegment [] = { +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include + static const unsigned char sevensegment [] PROGMEM = { #else #include + static const unsigned char sevensegment [] PROGMEM = { #endif - -static const unsigned char sevensegment [] PROGMEM = { // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) 10,16,46,13,1,30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/util/font5x7.h b/src/util/font5x7.h index 5392c17..5851a19 100644 --- a/src/util/font5x7.h +++ b/src/util/font5x7.h @@ -25,14 +25,17 @@ July 27, 2015 #ifndef FONT5X7_H #define FONT5X7_H -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) +// Standard ASCII 5x7 font +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM + static const unsigned char font5x7[] = { +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include + static const unsigned char font5x7[] PROGMEM = { #else #include + static const unsigned char font5x7[] PROGMEM = { #endif - -// Standard ASCII 5x7 font -static const unsigned char font5x7[] PROGMEM = { // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) 5,8,0,255,12,75, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/util/font8x16.h b/src/util/font8x16.h index e518666..6025af3 100644 --- a/src/util/font8x16.h +++ b/src/util/font8x16.h @@ -24,13 +24,16 @@ July 27, 2015 #ifndef FONT8X16_H #define FONT8X16_H -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM + static const unsigned char font8x16[] = { +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include + static const unsigned char font8x16[] PROGMEM = { #else #include + static const unsigned char font8x16[] PROGMEM = { #endif - -static const unsigned char font8x16[] PROGMEM = { // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) 8,16,32,96,2,56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, diff --git a/src/util/fontlargeletter31x48.h b/src/util/fontlargeletter31x48.h index 6b954a1..e9f9440 100644 --- a/src/util/fontlargeletter31x48.h +++ b/src/util/fontlargeletter31x48.h @@ -19,12 +19,17 @@ August 13, 2015 #ifndef FONTLARGELETTER31X48_H #define FONTLARGELETTER31X48_H -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) + +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM + static const unsigned char fontlargeletter31x48 [] = { +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include + static const unsigned char fontlargeletter31x48 [] PROGMEM = { #else #include + static const unsigned char fontlargeletter31x48 [] PROGMEM = { #endif -static const unsigned char fontlargeletter31x48 [] PROGMEM = { // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) 31,48,65,58,0,62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF8, 0xF8, 0xF8, 0xF8, diff --git a/src/util/fontlargenumber.h b/src/util/fontlargenumber.h index dc87bb8..bc640f7 100644 --- a/src/util/fontlargenumber.h +++ b/src/util/fontlargenumber.h @@ -25,13 +25,16 @@ July 27, 2015 #ifndef FONTLARGENUMBER_H #define FONTLARGENUMBER_H -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM + static const unsigned char fontlargenumber[] = { +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include + static const unsigned char fontlargenumber[] PROGMEM = { #else #include + static const unsigned char fontlargenumber[] PROGMEM = { #endif - -static const unsigned char fontlargenumber[] PROGMEM = { // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) 12,48,48,11,1,32, 0x00, 0xC0, 0xF8, 0x7C, 0x3E, 0x3E, 0xFC, 0xF8, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0,