Skip to content

Commit

Permalink
Merge pull request #34 from sparkfun/release_candidate
Browse files Browse the repository at this point in the history
v1.3.2
  • Loading branch information
PaulZC authored Apr 5, 2021
2 parents 1775ff1 + 5beb1c1 commit 8cb3b04
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 46 deletions.
87 changes: 87 additions & 0 deletions examples/Example11_BigFont/Example11_BigFont.ino
Original file line number Diff line number Diff line change
@@ -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 <Wire.h>
#include <SFE_MicroOLED.h> //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
}
}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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":
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=SparkFun Micro OLED Breakout
version=1.3.1
version=1.3.2
author=SparkFun Electronics <techsupport@sparkfun.com>
maintainer=SparkFun Electronics <sparkfun.com>
sentence=Library for the <a href="https://www.sparkfun.com/products/13003">SparkFun Micro OLED Breakout</a>.
Expand Down
96 changes: 70 additions & 26 deletions src/SFE_MicroOLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,85 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include <Arduino.h>
#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
#include <avr/pgmspace.h>
#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 <avr/pgmspace.h>
#else
#include <pgmspace.h>
#include <pgmspace.h>
#endif
#include <SFE_MicroOLED.h>

#ifndef _BV
#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
};

Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/SFE_MicroOLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <Wire.h> // Needed for TwoWire - even if we are using SPI or Parallel
#include <SPI.h> // Needed for SPIClass - even if we are using I2C or Parallel

#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
#include <avr/pgmspace.h>
#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 <avr/pgmspace.h>
#else
#include <pgmspace.h>
#include <pgmspace.h>
#endif

#define I2C_ADDRESS_SA0_0 0b0111100
Expand Down
9 changes: 6 additions & 3 deletions src/util/7segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <avr/pgmspace.h>
static const unsigned char sevensegment [] PROGMEM = {
#else
#include <pgmspace.h>
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,
Expand Down
11 changes: 7 additions & 4 deletions src/util/font5x7.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <avr/pgmspace.h>
static const unsigned char font5x7[] PROGMEM = {
#else
#include <pgmspace.h>
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,
Expand Down
9 changes: 6 additions & 3 deletions src/util/font8x16.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <avr/pgmspace.h>
static const unsigned char font8x16[] PROGMEM = {
#else
#include <pgmspace.h>
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,
Expand Down
9 changes: 7 additions & 2 deletions src/util/fontlargeletter31x48.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <avr/pgmspace.h>
static const unsigned char fontlargeletter31x48 [] PROGMEM = {
#else
#include <pgmspace.h>
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,
Expand Down
9 changes: 6 additions & 3 deletions src/util/fontlargenumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <avr/pgmspace.h>
static const unsigned char fontlargenumber[] PROGMEM = {
#else
#include <pgmspace.h>
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,
Expand Down

0 comments on commit 8cb3b04

Please sign in to comment.