-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jianxu1@chinaums.com
committed
Dec 8, 2021
1 parent
da5170f
commit 02de9a6
Showing
28 changed files
with
347,826 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
============ BSD License for U8g2 for Adafruit GFX Code ============ | ||
BSD 2-Clause License | ||
|
||
Copyright (c) 2018, olikraus | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
============ X11 Fonts COUR, HELV, NCEN, TIM, SYMB ============ | ||
|
||
For fonts derived from the following files, the license below applies. | ||
COURB08.BDF COURB10.BDF COURB12.BDF COURB14.BDF COURB18.BDF | ||
COURB24.BDF COURR08.BDF COURR10.BDF COURR12.BDF COURR14.BDF | ||
COURR18.BDF COURR24.BDF HELVB08.BDF HELVB10.BDF HELVB12.BDF HELVB14.BDF | ||
HELVB18.BDF HELVB24.BDF HELVR08.BDF HELVR10.BDF HELVR12.BDF HELVR14.BDF | ||
HELVR18.BDF HELVR24.BDF NCENB08.BDF NCENB10.BDF NCENB12.BDF | ||
NCENB14.BDF NCENB18.BDF NCENB24.BDF NCENR08.BDF NCENR10.BDF | ||
NCENR12.BDF NCENR14.BDF NCENR18.BDF NCENR24.BDF SYMB08.BDF SYMB10.BDF | ||
SYMB12.BDF SYMB14.BDF SYMB18.BDF SYMB24.BDF TIMB08.BDF TIMB10.BDF | ||
TIMB12.BDF TIMB14.BDF TIMB18.BDF TIMB24.BDF TIMR08.BDF TIMR10.BDF | ||
TIMR12.BDF TIMR14.BDF TIMR18.BDF TIMR24.BDF | ||
|
||
Copyright 1984-1989, 1994 Adobe Systems Incorporated. | ||
Copyright 1988, 1994 Digital Equipment Corporation. | ||
|
||
Adobe is a trademark of Adobe Systems Incorporated which may be | ||
registered in certain jurisdictions. | ||
Permission to use these trademarks is hereby granted only in | ||
association with the images described in this file. | ||
|
||
Permission to use, copy, modify, distribute and sell this software | ||
and its documentation for any purpose and without fee is hereby | ||
granted, provided that the above copyright notices appear in all | ||
copies and that both those copyright notices and this permission | ||
notice appear in supporting documentation, and that the names of | ||
Adobe Systems and Digital Equipment Corporation not be used in | ||
advertising or publicity pertaining to distribution of the software | ||
without specific, written prior permission. Adobe Systems and | ||
Digital Equipment Corporation make no representations about the | ||
suitability of this software for any purpose. It is provided "as | ||
is" without express or implied warranty. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
|
||
[tocstart]: # (toc start) | ||
|
||
* [U8g2_for_Adafruit_GFX](#u8g2_for_adafruit_gfx) | ||
* [What is U8g2_for_Adafruit_GFX?](#what-is-u8g2_for_adafruit_gfx) | ||
* [Which Adafruit GFX Libraries are Supported?](#which-adafruit-gfx-libraries-are-supported) | ||
* [How to use U8g2_for_Adafruit_GFX?](#how-to-use-u8g2_for_adafruit_gfx) | ||
* [Reference](#reference) | ||
* [Command Reference](#command-reference) | ||
* [Differences to U8g2](#differences-to-u8g2) | ||
|
||
[tocend]: # (toc end) | ||
|
||
# U8g2_for_Adafruit_GFX | ||
|
||
Download: [https://github.com/olikraus/U8g2_for_Adafruit_GFX/archive/master.zip](https://github.com/olikraus/U8g2_for_Adafruit_GFX/archive/master.zip) | ||
|
||
## What is U8g2_for_Adafruit_GFX? | ||
- Arduino Library | ||
- Adds a the [U8g2](https://github.com/olikraus/u8g2) text drawing engine to all Adafruit GFX based Arduino librarys. | ||
- All [U8g2 fonts](https://github.com/olikraus/u8g2/wiki/fntlistall) can be used | ||
- Support for UTF-8 and Unicode | ||
- Support for Arduino print() command and F() Macro | ||
|
||
U8g2 is a graphics library for monochrome displays. U8g2 supports many | ||
displays, some of them are also supported by Adafruit GFX based libraries. | ||
Others are supported by Adafruit GFX libraries, but are not supported by U8g2. | ||
`U8g2_for_Adafruit_GFX` connects to an existing Adafruit Library and adds support for | ||
U8g2 fonts to all Adafruit GFX based libraries. | ||
|
||
## Which Adafruit GFX Libraries are Supported? | ||
|
||
All libraries based on the Adafruit GFX engine are supported. This is a incomplete | ||
list of such libraries. Probably many more are supported: | ||
|
||
- [https://github.com/adafruit/Adafruit_SSD1306](https://github.com/adafruit/Adafruit_SSD1306) (tested) | ||
- [https://github.com/adafruit/Adafruit-ST7735-Library](https://github.com/adafruit/Adafruit-ST7735-Library) (not tested) | ||
- [https://github.com/adafruit/Adafruit-Graphic-VFD-Display-Library](https://github.com/adafruit/Adafruit-Graphic-VFD-Display-Library) (not tested) | ||
- [https://github.com/adafruit/Adafruit-HX8340B](https://github.com/adafruit/Adafruit-HX8340B) (not tested) | ||
- [https://github.com/adafruit/Adafruit_HX8357_Library](https://github.com/adafruit/Adafruit_HX8357_Library) (not tested) | ||
- [https://github.com/adafruit/Adafruit_ILI9340](https://github.com/adafruit/Adafruit_ILI9340) (not tested) | ||
- [https://github.com/adafruit/Adafruit_ILI9341](https://github.com/adafruit/Adafruit_ILI9341) (not tested) | ||
- [https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library](https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library) (not tested) | ||
|
||
|
||
## How to use U8g2_for_Adafruit_GFX? | ||
|
||
This is a complete example for `U8g2_for_Adafruit_GFX` connected to Adafruit SSD1306 | ||
library: | ||
|
||
``` | ||
#include <Adafruit_SSD1306.h> | ||
#include <U8g2_for_Adafruit_GFX.h> | ||
Adafruit_SSD1306 display(/*MOSI*/ 11, /*CLK*/ 13, /*DC*/ 9, /*RESET*/ 8, /*CS*/ 10); | ||
U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx; | ||
void setup() { | ||
display.begin(SSD1306_SWITCHCAPVCC); | ||
u8g2_for_adafruit_gfx.begin(display); // connect u8g2 procedures to Adafruit GFX | ||
} | ||
void loop() { | ||
display.clearDisplay(); // clear the graphcis buffer | ||
u8g2_for_adafruit_gfx.setFontMode(1); // use u8g2 transparent mode (this is default) | ||
u8g2_for_adafruit_gfx.setFontDirection(0); // left to right (this is default) | ||
u8g2_for_adafruit_gfx.setForegroundColor(WHITE); // apply Adafruit GFX color | ||
u8g2_for_adafruit_gfx.setFont(u8g2_font_helvR14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall | ||
u8g2_for_adafruit_gfx.setCursor(0,20); // start writing at this position | ||
u8g2_for_adafruit_gfx.print(F("Hello World")); | ||
u8g2_for_adafruit_gfx.setCursor(0,40); // start writing at this position | ||
u8g2_for_adafruit_gfx.print(F("Umlaut ÄÖÜ")); // UTF-8 string with german umlaut chars | ||
display.display(); // make everything visible | ||
delay(2000); | ||
} | ||
``` | ||
|
||
# Reference | ||
|
||
## Command Reference | ||
|
||
- `U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx`: Constructor call. This must be | ||
the first command. No paramenters are required. | ||
- `void u8g2_for_adafruit_gfx.begin(Adafruit_GFX &gfx)`: Connect to Adafruit GFX library | ||
- `void u8g2_for_adafruit_gfx.setFont(const uint8_t *font)`: Assign u8g2 font, see [here](https://github.com/olikraus/u8g2/wiki/fntlistall) for a list. | ||
Note: The list from the u8g2 project might be a little bit newer, so maybe not allways all fonts are available for this project. | ||
See also: [https://github.com/olikraus/u8g2/wiki/u8g2reference#setfont](https://github.com/olikraus/u8g2/wiki/u8g2reference#setfont) | ||
- `void u8g2_for_adafruit_gfx.setFontMode(uint8_t is_transparent)`: Define, whether the background color should be drawn or not. | ||
See also: [https://github.com/olikraus/u8g2/wiki/u8g2reference#setfontmode](https://github.com/olikraus/u8g2/wiki/u8g2reference#setfontmode) | ||
- `void u8g2_for_adafruit_gfx.setFontDirection(uint8_t dir)`: Identical to the u8g2 command | ||
[https://github.com/olikraus/u8g2/wiki/u8g2reference#setfontdirection](https://github.com/olikraus/u8g2/wiki/u8g2reference#setfontdirection) | ||
- `void u8g2_for_adafruit_gfx.setForegroundColor(uint8_t dir)`: Set the foreground color for the text. | ||
- `void u8g2_for_adafruit_gfx.setBackgroundColor(uint8_t dir)`: Set the background color for the text. This is only required if the font mode is not set to transparent. | ||
- `void u8g2_for_adafruit_gfx.setCursor(int16_t x, int16_t y)`: Specify the x/y position for the next print() command. This x/y position is the lower left baseline of a character. | ||
For "Arduino" this will be the lower left corner of the A character. | ||
- `void u8g2_for_adafruit_gfx.print(...)`: This is the standard Arduino print function. Any text given here will be output on the display via Adafruit GFX library. | ||
See [here](https://www.arduino.cc/en/Serial/Print) for further description. Note: This function supports UTF-8. | ||
- `int8_t u8g2_for_adafruit_gfx.getFontAscent(void)`: The height of the character 'A' in the current font. | ||
- `int8_t u8g2_for_adafruit_gfx.getFontDescent(void)`: The extend of 'g' below baseline. This value usually is negative. | ||
- `int16_t u8g2_for_adafruit_gfx.getUTF8Width(const char *str)`: Return the width of the provided string. | ||
It is assumed, that `str` is encoded in UTF8 (this is default for Arduino IDE and gcc/g++). | ||
|
||
|
||
## Differences to U8g2 | ||
There are some minor differences to the U8g2 library: | ||
- For U8g2 the color is specified with the `setDrawColor()` function. | ||
- The `print()` command supports UTF-8 by default. It also can not be disabled. For U8g2 the UTF-8 support must be enabled first. | ||
- This library does not support the change of the reference position. The reference position is the lower left baseline of a character. | ||
|
||
## Release Procedure | ||
- Copy font file u8g2_fonts.c to "src" folder | ||
- Change the include file in u8g2_fonts.c from "u8g2.h" to "u8g2_fonts.h" | ||
- Update the list of fonts in "U8g2_for_Adafruit_GFX.h" | ||
- Update keywords.txt | ||
- Update version in library.properties | ||
|
||
|
||
|
43 changes: 43 additions & 0 deletions
43
...8g2_for_Adafruit_GFX/examples/Boxed_Text_Adafruit_SSD1306/Boxed_Text_Adafruit_SSD1306.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Hello_Adafruit_SSD1306.ino | ||
Demonstrates how to draw a fitting box around a text. | ||
List of all U8g2 fonts: https://github.com/olikraus/u8g2/wiki/fntlistall | ||
*/ | ||
#include <Adafruit_SSD1306.h> | ||
#include <U8g2_for_Adafruit_GFX.h> | ||
|
||
Adafruit_SSD1306 display(/*MOSI*/ 11, /*CLK*/ 13, /*DC*/ 9, /*RESET*/ 8, /*CS*/ 10); | ||
U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx; | ||
|
||
void setup() { | ||
display.begin(SSD1306_SWITCHCAPVCC); | ||
u8g2_for_adafruit_gfx.begin(display); // connect u8g2 procedures to Adafruit GFX | ||
} | ||
|
||
void loop() { | ||
const char s[] = "gfx LCD"; | ||
/* width and height of the text */ | ||
int16_t height; | ||
int16_t width; | ||
/* desired position of the text */ | ||
int16_t x = 4; | ||
int16_t y = 25; | ||
display.clearDisplay(); // clear the graphcis buffer | ||
u8g2_for_adafruit_gfx.setFont(u8g2_font_helvB14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall | ||
u8g2_for_adafruit_gfx.setFontMode(1); // use u8g2 transparent mode (this is default) | ||
u8g2_for_adafruit_gfx.setFontDirection(0); // left to right (this is default) | ||
u8g2_for_adafruit_gfx.setForegroundColor(WHITE); // apply Adafruit GFX color | ||
u8g2_for_adafruit_gfx.setCursor(x, y); // start writing at this position | ||
u8g2_for_adafruit_gfx.print(s); | ||
/* calculate the size of the box into which the text will fit */ | ||
height = u8g2_for_adafruit_gfx.getFontAscent() - u8g2_for_adafruit_gfx.getFontDescent(); | ||
width = u8g2_for_adafruit_gfx.getUTF8Width(s); | ||
/* draw the box around the text*/ | ||
display.drawRect(x, y-u8g2_for_adafruit_gfx.getFontAscent(), width, height, WHITE); | ||
display.display(); // make everything visible | ||
delay(2000); | ||
} |
53 changes: 53 additions & 0 deletions
53
lib/U8g2_for_Adafruit_GFX/examples/Hello_Adafruit_ILI9341/Hello_Adafruit_ILI9341.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Hello_Adafruit_ILI9341.ino | ||
Demonstrates how to connect U8g2_for_Adafruit_GFX to Adafruit SSD1306 library. | ||
U8g2_for_Adafruit_GFX: | ||
- Use U8g2 fonts with Adafruit GFX | ||
- Support for UTF-8 in print statement | ||
- 90, 180 and 270 degree text direction | ||
List of all U8g2 fonts: https://github.com/olikraus/u8g2/wiki/fntlistall | ||
*/ | ||
#include "SPI.h" | ||
#include "Adafruit_GFX.h" | ||
#include "Adafruit_ILI9341.h" | ||
#include "U8g2_for_Adafruit_GFX.h" | ||
|
||
#define TFT_DC 9 | ||
#define TFT_CS 10 | ||
|
||
Adafruit_ILI9341 display = Adafruit_ILI9341(TFT_CS, TFT_DC); | ||
|
||
U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx; | ||
|
||
void setup() { | ||
display.begin(); | ||
display.setRotation(1); | ||
display.fillScreen(ILI9341_BLACK); | ||
u8g2_for_adafruit_gfx.begin(display); // connect u8g2 procedures to Adafruit GFX | ||
} | ||
|
||
unsigned long x = 0; | ||
|
||
void loop() { | ||
|
||
u8g2_for_adafruit_gfx.setFontMode(0); // use u8g2 none transparent mode | ||
u8g2_for_adafruit_gfx.setFontDirection(0); // left to right (this is default) | ||
u8g2_for_adafruit_gfx.setForegroundColor(ILI9341_WHITE); // apply Adafruit GFX color | ||
u8g2_for_adafruit_gfx.setFont(u8g2_font_helvR14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall | ||
u8g2_for_adafruit_gfx.setCursor(0,20); // start writing at this position | ||
u8g2_for_adafruit_gfx.print("Hello World"); | ||
u8g2_for_adafruit_gfx.setCursor(0,40); // start writing at this position | ||
u8g2_for_adafruit_gfx.print("Umlaut ÄÖÜ"); // UTF-8 string with german umlaut chars | ||
|
||
u8g2_for_adafruit_gfx.setFont(u8g2_font_inb63_mn); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall | ||
u8g2_for_adafruit_gfx.setFontMode(0); // use u8g2 none transparent mode | ||
u8g2_for_adafruit_gfx.setCursor(0,220); // start writing at this position | ||
u8g2_for_adafruit_gfx.print(x); // UTF-8 string with german umlaut chars | ||
x++; | ||
delay(1000); | ||
} |
39 changes: 39 additions & 0 deletions
39
lib/U8g2_for_Adafruit_GFX/examples/Hello_Adafruit_SSD1306/Hello_Adafruit_SSD1306.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Hello_Adafruit_SSD1306.ino | ||
Demonstrates how to connect U8g2_for_Adafruit_GFX to Adafruit SSD1306 library. | ||
U8g2_for_Adafruit_GFX: | ||
- Use U8g2 fonts with Adafruit GFX | ||
- Support for UTF-8 in print statement | ||
- 90, 180 and 270 degree text direction | ||
List of all U8g2 fonts: https://github.com/olikraus/u8g2/wiki/fntlistall | ||
*/ | ||
#include <Adafruit_SSD1306.h> | ||
#include <U8g2_for_Adafruit_GFX.h> | ||
|
||
Adafruit_SSD1306 display(/*MOSI*/ 11, /*CLK*/ 13, /*DC*/ 9, /*RESET*/ 8, /*CS*/ 10); | ||
U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx; | ||
|
||
void setup() { | ||
display.begin(SSD1306_SWITCHCAPVCC); | ||
u8g2_for_adafruit_gfx.begin(display); // connect u8g2 procedures to Adafruit GFX | ||
} | ||
|
||
void loop() { | ||
display.clearDisplay(); // clear the graphcis buffer | ||
u8g2_for_adafruit_gfx.setFont(u8g2_font_helvR14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall | ||
u8g2_for_adafruit_gfx.setFontMode(1); // use u8g2 transparent mode (this is default) | ||
u8g2_for_adafruit_gfx.setFontDirection(0); // left to right (this is default) | ||
u8g2_for_adafruit_gfx.setForegroundColor(WHITE); // apply Adafruit GFX color | ||
u8g2_for_adafruit_gfx.setCursor(0,20); // start writing at this position | ||
u8g2_for_adafruit_gfx.print("Hello World"); | ||
u8g2_for_adafruit_gfx.setCursor(0,40); // start writing at this position | ||
u8g2_for_adafruit_gfx.print("Umlaut ÄÖÜ"); // UTF-8 string with german umlaut chars | ||
display.display(); // make everything visible | ||
delay(2000); | ||
} | ||
|
Oops, something went wrong.