more examples

This commit is contained in:
olikraus 2016-06-26 20:50:12 +02:00
parent 3ed157d8ba
commit e9ddf44cb6
9 changed files with 1243 additions and 8 deletions

View File

@ -16,4 +16,7 @@ https://github.com/olikraus/u8g2 ChangeLog
* User interface functions
* Little Rook Chess ported
* ST7920 HW and SW SPI
2016-06-26 v2.0.7 olikraus@gmail.com
* drawLine
* GraphicsTest Example

View File

@ -65,8 +65,8 @@ Major Changes (Code rework required)
This includes drawStrP(), getStrWidthP(), etc
Use the print function with the F() macro instead.
- In U8glib font transparency was defined in the .begin() statement. This is now
handled by setFontMode
- Screen rotation does not exisit any more:
handled by setFontMode().
- Screen rotation is handled by the constructor in u8g2
The functions undoRotation, setRot90, setRot180 and setRot270 are
replaced by the first argument of the constructor
- Screen scaling is not there in u8g2
@ -77,12 +77,10 @@ Major Changes (Code rework required)
- getMode(): Is not available any more because there is only one monochrome mode.
- setDefaultForegroundColor(), setDefaultBackgroundColor() and
setDefaultMidColor() are not required any more. These functions do not
exist in U8g2
exist in U8g2. Use setDrawColor() instead.
- getFontLineSpacing() and setFontLineSpacingFactor() are not supported any more.
- setFontRefHeightText(), setFontRefHeightExtendedText() and setFontRefHeightAll() are
not supported as of now. Maybe this will be added in the future.
- getStrPixelWidth() is replaced by getStrWidth() instead
- setHardwareBackup() not yet supported. Might be implemented later
- getStrPixelWidth() is replaced by getStrWidth()
- setHardwareBackup() not supported any more. Might be implemented later
- Cursor functions are not available. This includes:
setCursorFont(), setCursorStyle(), setCursorPos(), setCursorColor(),
enableCursor(), disableCursor(), drawCursor()

View File

@ -0,0 +1,362 @@
/*
FPS.ino
Frames Per Second: Display Performance Test
>>> Before compiling: Please remove comment from the constructor of the
>>> connected graphics display (see below).
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
Copyright (c) 2016, olikraus@gmail.com
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.
==============
U8glib
ST7920_192X32, SPI: FPS: Box=7.6 @=9.8 iFPS: Box=11.4 @=14.7
ST7920_192X32, 8Bit: FPS: Box=6.2 @=7.5 iFPS: Box=9.3 @=11.2
DOGM128 SW SPI: FPS: Box=5.1 @=5.9 Pix=2.6 iFPS: Box=10.2 @=11.8 Pix=5.2
DOGM128 HW SPI: FPS: Box=5.5 @=6.3 iFPS: Box=11.0 @=12.6
DOGXL160 SW SPI: FPS: Box=1.7 @=1.9 iFPS: Box=6.9 @=7.7
DOGXL160 HW SPI: FPS: Box=1.8 @=2.1
NHD27OLED_BW, SW SPI: FPS: Box=3.0 @=3.7
NHD27OLED_BW, HW SPI: FPS: Box=3.5 @=4.5
NHD27OLED_2X_BW, SW SPI: FPS: Box=3.8 @=4.9
NHD27OLED_2X_BW, HW SPI: FPS: Box=4.6 @=6.4
30 Sep 2012
NHD27OLED_BW, SW SPI: FPS: Clip=9.2 Box=3.9 @=4.4 NEW_CODE
NHD27OLED_BW, SW SPI: FPS: Clip=9.2 Box=3.6 @=4.5
NHD27OLED_BW, HW SPI: FPS: Clip=16.3 Box=4.7 @=5.6
NHD27OLED_2X_BW, SW SPI: FPS: Clip=9.7 Box=4.5 @=5.8
NHD27OLED_2X_BW, SW SPI: FPS: Clip=18.0 Box=5.8 @=7.9
1 Oct 2012
ST7920_192X32, 8Bit: FPS: Box=7.2 @=10.0
DOGM128 SW SPI: FPS: Box=5.2 @=6.6 Pix=2.6
DOGM128 HW SPI: FPS: Clip=33.2 Box=5.5 @=7.1
DOGXL160 SW SPI: FPS: Box=1.7 @=2.0
DOGXL160 HW SPI: FPS: Box=1.8 @=2.2
DOGXL160 GR SW SPI: FPS: Box=1.1 @=1.3
1 Mar 2013
ST7920_192X32_1X, SPI: FPS: Clip=10.3 Box=5.5 @=7.2 Pix=3.9
ST7920_192X32_4X, SPI: FPS: Clip=10.9 Box=6.7 @=8.8 Pix=7.4
ST7920_192X32_1X, 8Bit: FPS: Clip=14.2 Box=6.1 @=8.4 Pix=4.2
ST7920_192X32_4X, 8Bit: FPS: Clip=14.2 Box=7.8 @=10.7 Pix=8.7
ST7920_192X32_1X, HW SPI: FPS: Clip=14.2 Box=6.3 @=8.7 Pix=4.3
ST7920_192X32_4X, HW SPI: FPS: Clip=15.3 Box=8.0 @=11.2 Pix=9.0
2 Jun 2013
U8GLIB_DOGM128 SW SPI: FPS: Clip=23.9 Box=4.5 @=6.6 Pix=2.1
U8GLIB_DOGM128_2X SW SPI: FPS: Clip=28.5 Box=6.6 @=9.7 Pix=3.9
U8GLIB_DOGM128_2X HW SPI: FPS: Clip=40.8 Box=7.1 @=10.8 Pix=4.1
3 Jun 2013
U8GLIB_ST7920_192X32_1X -Os SW SPI FPS: Clip=11.0 Box=5.4 @=7.1 Pix=3.9 Size=11828
U8GLIB_ST7920_192X32_1X -O3 SW SPI FPS: Clip=10.9 Box=5.6 @=7.5 Pix=4.0 Size=13800
U8GLIB_ST7920_192X32_1X -Os SW SPI FPS: Clip=16.8 Box=6.7 @=9.6 Pix=4.5 Size=11858 (new seq data output)
U8GLIB_ST7920_192X32_1X -Os HW SPI FPS: Clip=25.7 Box=7.5 @=11.3 Pix=4.8 (new seq data output)
6 Jun 2013
U8GLIB_DOGS102 u8g(13, 11, 10, 9); STD SW SPI FPS: Clip=9.5 Box=7.6 @=8.2 Pix=6.2 Size=15652
U8GLIB_DOGS102 u8g(13, 11, 10, 9); SW SPI FPS: Clip=19.1 Box=12.8 @=14.0 Pix=9.2 Size=15532
12 Jun 2013
SSD1351_128X128_332 SW SPI Clip=1.3 Box=0.7 @=0.9 Pix=0.4
SSD1351_128X128_332 HW SPI Clip=3.6 Box=1.1 @=1.5 Pix=0.5
24 Jun 2013
Uno SSD1351_128X128_332 SW SPI Clip=1.4 Box=0.8 @=0.9 Pix=0.4
Uno SSD1351_128X128_332 HW SPI Clip=4.4 Box=1.2 @=1.6 Pix=0.5
Uno SSD1351_128X128_HICOLOR HW SPI Clip=3.7 Box=0.8 @=1.0 Pix=0.3
Mega2560 SSD1351_128X128_332 HW SPI Clip=4.4 Box=1.2 @=1.6 Pix=0.5
Mega2560 SSD1351_128X128_4X_332 HW SPI Clip=4.6 Box=2.3 @=2.8 Pix=1.5
Mega2560 SSD1351_128X128_HICOLOR HW SPI Clip=3.6 Box=0.8 @=1.0 Pix=0.3
Mega2560 SSD1351_128X128_4X_HICOLOR HW SPI Clip=4.2 Box=1.7 @=2.1 Pix=1.0
Due SSD1351_128X128_332 HW SPI Clip=24.6 Box=6.3 @=7.8 Pix=2.8
Due SSD1351_128X128_4X_332 HW SPI Clip=28.1 Box=13.0 @=15.1 Pix=8.5
Due SSD1351_128X128_HICOLOR HW SPI Clip=20.8 Box=3.4 @=4.5 Pix=1.4
Due SSD1351_128X128_4X_HICOLOR HW SPI Clip=26.3 Box=8.9 @=11.1 Pix=4.8
Due SSD1351_128X128_4X_HICOLOR SW SPI Clip=0.4 Box=0.4 @=0.4 Pix=0.4
Due DOGS102 u8g(13, 11, 10, 9); SW SPI FPS: Clip=19.1 Box=13.1 @=14.3 Pix=9.4
Due DOGS102 u8g(10, 9); HW SPI FPS: Clip=128.9 Box=30.7 @=40.6 Pix=15.4
Due NHD27OLED_BW u8g(10, 9) HW SPI FPS: Clip=53.0 Box=19.6 @=23.8 Pix=10.6
Due NHD27OLED_2X_BW u8g(10, 9) HW SPI FPS: Clip=57.0 Box=25.3 @=31.7 Pix=18.1
Due NHD27OLED_GR u8g(10, 9) HW SPI FPS: Clip=34.1 Box=11.7 @=13.7 Pix=5.6
Due NHD27OLED_2X_GR u8g(10, 9) HW SPI FPS: Clip=38.1 Box=15.5 @=20.0 Pix=8.8
28. Apr 2016
Uno DOGS102 u8g(13, 11, 10, 9); SW SPI FPS: Clip=26.6 Box=6.1 @=8.5 Pix=2.8 11548 Bytes
Uno DOGS102 u8g(10, 9); HW SPI FPS: Clip=33.1 Box=6.4 @=9.1 Pix=2.9 11366 Bytes
==============
U8g2
28. Apr 2016
Uno DOGS102 u8g(13, 11, 10, 9); SW SPI FPS: Clip=3.0 Box=3.3 @=2.1 Pix=2.4 11472 Bytes
Uno DOGS102 u8g(10, 9); HW SPI FPS: Clip=24.5 Box=87.4 @=5.0 Pix=7.3 11554 Bytes
15. Mai 2016
Uno U8G2_UC1701_DOGS102_1_4W_SW_SPI SW SPI FPS: Clip=3.5 Box=3.8 @=2.3 Pix=2.7 Arduino Flash Size: 13262 Bytes
Uno U8G2_UC1701_DOGS102_1_4W_HW_SPI HW SPI FPS: Clip=26.3 Box=90.5 @=5.1 Pix=8.5 Arduino Flash Size: 13370 Bytes
Uno U8G2_UC1701_DOGS102_F_4W_HW_SPI HW SPI FPS: Clip=50.6 Box=119.6 @=9.4 Pix=15.7 Arduino Flash Size: 13370 Bytes
16. Mai 2016 (improved SW 4-Wire SPI)
Uno U8G2_UC1701_DOGS102_1_4W_SW_SPI SW SPI FPS: Clip=18.6 Box=42.2 @=4.7 Pix=7.7
24. Mai 2016
Uno U8G2_ST7565_DOGM128_1_4W_SW_SPI SW SPI FPS: Clip=18.1 Box=35.8 @=3.9 Pix=6.2
Uno U8G2_ST7565_DOGM128_1_4W_HW_SPI HW SPI FPS: Clip=25.4 Box=78.7 @=4.2 Pix=6.9
*/
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
/*
U8glib Example Overview:
Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.
*/
// Please UNCOMMENT one of the contructor lines below
// U8g2 Contructor List (Frame Buffer)
// The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp
// Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected
//U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6); // Arduboy (Production, Kickstarter Edition)
//U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display
//U8G2_SSD1306_128X64_NONAME_F_6800 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_8080 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8);
//U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 21, /* data=*/ 20, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather M0 Basic Proto + FeatherWing OLED
//U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED
//U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED
//U8G2_LD7032_60X32_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* cs=*/ 9, /* dc=*/ 10, /* reset=*/ 8); // SW SPI Nano Board
//U8G2_LD7032_60X32_F_4W_SW_I2C u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* reset=*/ U8X8_PIN_NONE); // NOT TESTED!
//U8G2_UC1701_EA_DOGS102_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_UC1701_EA_DOGS102_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_ST7920_192X32_F_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ U8X8_PIN_NONE, /*dc=*/ 17, /*reset=*/ U8X8_PIN_NONE);
//U8G2_ST7920_192X32_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE);
//U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE);
//U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8);
//U8G2_ST7920_128X64_F_HW_SPI u8g2(U8G2_R0, /* CS=*/ 10, /* reset=*/ 8);
//U8G2_ST7565_EA_DOGM128_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_ST7565_EA_DOGM128_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_ST7565_NHD_C12832_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_ST7565_NHD_C12832_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
// End of constructor list
typedef u8g2_uint_t u8g_uint_t;
#define SECONDS 10
uint8_t flip_color = 0;
uint8_t draw_color = 1;
void draw_set_screen(void) {
// graphic commands to redraw the complete screen should be placed here
u8g2.setColorIndex(flip_color);
u8g2.drawBox( 0, 0, u8g2.getWidth(), u8g2.getHeight() );
}
void draw_clip_test(void) {
u8g_uint_t i, j, k;
char buf[3] = "AB";
k = 0;
u8g2.setColorIndex(draw_color);
u8g2.setFont(u8g2_font_6x10_tf);
for( i = 0; i < 6; i++ ) {
for( j = 1; j < 8; j++ ) {
u8g2.drawHLine(i-3, k, j);
u8g2.drawHLine(i-3+10, k, j);
u8g2.drawVLine(k+20, i-3, j);
u8g2.drawVLine(k+20, i-3+10, j);
k++;
}
}
u8g2.setFontDirection(0);
u8g2.drawStr(0-3, 50, buf);
u8g2.setFontDirection(2);
u8g2.drawStr(0+3, 50, buf);
u8g2.setFontDirection(0);
u8g2.drawStr(u8g2.getWidth()-3, 40, buf);
u8g2.setFontDirection(2);
u8g2.drawStr(u8g2.getWidth()+3, 40, buf);
u8g2.setFontDirection(1);
u8g2.drawStr(u8g2.getWidth()-10, 0-3, buf);
u8g2.setFontDirection(3);
u8g2.drawStr(u8g2.getWidth()-10, 3, buf);
u8g2.setFontDirection(1);
u8g2.drawStr(u8g2.getWidth()-20, u8g2.getHeight()-3, buf);
u8g2.setFontDirection(3);
u8g2.drawStr(u8g2.getWidth()-20, u8g2.getHeight()+3, buf);
u8g2.setFontDirection(0);
}
void draw_char(void) {
char buf[2] = "@";
u8g_uint_t i, j;
// graphic commands to redraw the complete screen should be placed here
u8g2.setColorIndex(draw_color);
u8g2.setFont(u8g2_font_6x10_tf);
j = 8;
for(;;) {
i = 0;
for(;;) {
u8g2.drawStr( i, j, buf);
i += 8;
if ( i > u8g2.getWidth() )
break;
}
j += 8;
if ( j > u8g2.getHeight() )
break;
}
}
void draw_pixel(void) {
u8g_uint_t x, y, w2, h2;
u8g2.setColorIndex(draw_color);
w2 = u8g2.getWidth();
h2 = u8g2.getHeight();
w2 /= 2;
h2 /= 2;
for( y = 0; y < h2; y++ ) {
for( x = 0; x < w2; x++ ) {
if ( (x + y) & 1 ) {
u8g2.drawPixel(x,y);
u8g2.drawPixel(x,y+h2);
u8g2.drawPixel(x+w2,y);
u8g2.drawPixel(x+w2,y+h2);
}
}
}
}
// returns unadjusted FPS
uint16_t execute_with_fps(void (*draw_fn)(void)) {
uint16_t FPS10 = 0;
uint32_t time;
time = millis() + SECONDS*1000;
// picture loop
do {
u8g2.clearBuffer();
draw_fn();
u8g2.sendBuffer();
FPS10++;
flip_color = flip_color ^ 1;
} while( millis() < time );
return FPS10;
}
const char *convert_FPS(uint16_t fps) {
static char buf[6];
strcpy(buf, u8g2_u8toa( (uint8_t)(fps/10), 3));
buf[3] = '.';
buf[4] = (fps % 10) + '0';
buf[5] = '\0';
return buf;
}
void show_result(const char *s, uint16_t fps) {
// assign default color value
u8g2.setColorIndex(draw_color);
u8g2.setFont(u8g2_font_8x13B_tf);
u8g2.firstPage();
do {
u8g2.drawStr(0,12, s);
u8g2.drawStr(0,24, convert_FPS(fps));
} while( u8g2.nextPage() );
}
void setup(void) {
u8g2.begin();
// flip screen, if required
// u8g2.setRot180();
// assign default color value
draw_color = 1; // pixel on
}
void loop(void) {
uint16_t fps;
fps = execute_with_fps(draw_clip_test);
show_result("draw clip test", fps);
delay(5000);
fps = execute_with_fps(draw_set_screen);
show_result("clear screen", fps);
delay(5000);
fps = execute_with_fps(draw_char);
show_result("draw @", fps);
delay(5000);
fps = execute_with_fps(draw_pixel);
show_result("draw pixel", fps);
delay(5000);
}

View File

@ -0,0 +1,286 @@
#
# Arduino-1.0 Makefile
#
# written by olikraus@gmail.com
#
# Features:
# - boards.txt is used to derive parameters
# - All intermediate files are put into a separate directory (TMPDIRNAME)
# - Simple use: Copy Makefile into the same directory of the .ino file
#
# Limitations:
# - requires UNIX environment
# - TMPDIRNAME must be subdirectory of the current directory.
#
# Targets
# all build everything
# upload build and upload to arduino
# clean remove all temporary files (includes final hex file)
#
# History
# 001 28 Apr 2010 first release
# 002 05 Oct 2010 added 'uno'
# 003 06 Dec 2011 arduino 1.0
# 004 11 Feb 2012 u8glib
#
#=== user configuration ===
# All ...PATH variables must have a '/' at the end
# Board (and prozessor) information: see $(ARDUINO_PATH)hardware/arduino/boards.txt
# Some examples:
# BOARD DESCRIPTION
# uno Arduino Uno
# atmega328 Arduino Duemilanove or Nano w/ ATmega328
# diecimila Arduino Diecimila, Duemilanove, or Nano w/ ATmega168
# mega Arduino Mega
# mega2560 Arduino Mega2560
# mini Arduino Mini
# lilypad328 LilyPad Arduino w/ ATmega328
BOARD:=uno
# additional definitions
#DEFS:=-DARDUINO=105
U8G_PATH:=$(shell cd ../../../.. && pwd)/csrc/
U8G_CPP_PATH:=$(shell cd ../../../.. && pwd)/cppsrc/
#U8G_FONT_PATH:=$(shell cd ../../.. && pwd)/sfntsrc/
# The location where the avr tools (e.g. avr-gcc) are located. Requires a '/' at the end.
# Can be empty if all tools are accessable through the search path
AVR_TOOLS_PATH:=/usr/bin/
# Install path of the arduino software. Requires a '/' at the end.
ARDUINO_PATH:=/home/kraus/prg/arduino-1.0.5-u8glib/
# Install path for avrdude. Requires a '/' at the end. Can be empty if avrdude is in the search path.
AVRDUDE_PATH:=$(ARDUINO_PATH)hardware/tools/
# The unix device where we can reach the arduino board
# Uno: /dev/ttyACM0
# Duemilanove: /dev/ttyUSB0
AVRDUDE_PORT:=/dev/ttyACM0
# List of all libaries which should be included.
EXTRA_DIRS=$(ARDUINO_PATH)libraries/LiquidCrystal/
EXTRA_DIRS+=$(ARDUINO_PATH)libraries/SD/
EXTRA_DIRS+=$(ARDUINO_PATH)libraries/SD/utility/
EXTRA_DIRS+=$(ARDUINO_PATH)libraries/Wire/
EXTRA_DIRS+=$(ARDUINO_PATH)libraries/Wire/utility/
EXTRA_DIRS+=$(ARDUINO_PATH)libraries/SPI/
#EXTRA_DIRS+=$(ARDUINO_PATH)libraries/.../
#=== fetch parameter from boards.txt processor parameter ===
# the basic idea is to get most of the information from boards.txt
BOARDS_TXT:=$(ARDUINO_PATH)hardware/arduino/boards.txt
# get the MCU value from the $(BOARD).build.mcu variable. For the atmega328 board this is atmega328p
MCU:=$(shell sed -n -e "s/$(BOARD).build.mcu=\(.*\)/\1/p" $(BOARDS_TXT))
# get the F_CPU value from the $(BOARD).build.f_cpu variable. For the atmega328 board this is 16000000
F_CPU:=$(shell sed -n -e "s/$(BOARD).build.f_cpu=\(.*\)/\1/p" $(BOARDS_TXT))
# get variant subfolder
VARIANT:=$(shell sed -n -e "s/$(BOARD).build.variant=\(.*\)/\1/p" $(BOARDS_TXT))
# avrdude
# get the AVRDUDE_UPLOAD_RATE value from the $(BOARD).upload.speed variable. For the atmega328 board this is 57600
AVRDUDE_UPLOAD_RATE:=$(shell sed -n -e "s/$(BOARD).upload.speed=\(.*\)/\1/p" $(BOARDS_TXT))
# get the AVRDUDE_PROGRAMMER value from the $(BOARD).upload.protocol variable. For the atmega328 board this is stk500
AVRDUDE_PROGRAMMER:=$(shell sed -n -e "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_TXT))
# use stk500v1, because stk500 will default to stk500v2
#AVRDUDE_PROGRAMMER:=stk500v1
#=== identify user files ===
INOSRC:=$(shell ls *.ino)
TARGETNAME=$(basename $(INOSRC))
CDIRS:=$(EXTRA_DIRS) $(addsuffix utility/,$(EXTRA_DIRS))
CDIRS:=*.c utility/*.c $(U8G_PATH)*.c $(addsuffix *.c,$(CDIRS)) $(ARDUINO_PATH)hardware/arduino/cores/arduino/*.c
CSRC:=$(shell ls $(CDIRS) 2>/dev/null)
CCSRC:=$(shell ls *.cc 2>/dev/null)
CPPDIRS:=$(EXTRA_DIRS) $(addsuffix utility/,$(EXTRA_DIRS)) $(U8G_CPP_PATH)
CPPDIRS:=*.cpp utility/*.cpp $(addsuffix *.cpp,$(CPPDIRS)) $(ARDUINO_PATH)hardware/arduino/cores/arduino/*.cpp
CPPSRC:=$(shell ls $(CPPDIRS) 2>/dev/null)
#=== build internal variables ===
# the name of the subdirectory where everything is stored
TMPDIRNAME:=tmp
TMPDIRPATH:=$(TMPDIRNAME)/
AVRTOOLSPATH:=$(AVR_TOOLS_PATH)
OBJCOPY:=$(AVRTOOLSPATH)avr-objcopy
OBJDUMP:=$(AVRTOOLSPATH)avr-objdump
SIZE:=$(AVRTOOLSPATH)avr-size
CPPSRC:=$(addprefix $(TMPDIRPATH),$(INOSRC:.ino=.cpp)) $(CPPSRC)
COBJ:=$(CSRC:.c=.o)
CCOBJ:=$(CCSRC:.cc=.o)
CPPOBJ:=$(CPPSRC:.cpp=.o)
OBJFILES:=$(COBJ) $(CCOBJ) $(CPPOBJ)
DIRS:= $(dir $(OBJFILES))
DEPFILES:=$(OBJFILES:.o=.d)
# assembler files from avr-gcc -S
ASSFILES:=$(OBJFILES:.o=.s)
# disassembled object files with avr-objdump -S
DISFILES:=$(OBJFILES:.o=.dis)
LIBNAME:=$(TMPDIRPATH)$(TARGETNAME).a
ELFNAME:=$(TMPDIRPATH)$(TARGETNAME).elf
HEXNAME:=$(TMPDIRPATH)$(TARGETNAME).hex
AVRDUDE_FLAGS = -V -F
AVRDUDE_FLAGS += -C $(ARDUINO_PATH)/hardware/tools/avrdude.conf
AVRDUDE_FLAGS += -p $(MCU)
AVRDUDE_FLAGS += -P $(AVRDUDE_PORT)
AVRDUDE_FLAGS += -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += -b $(AVRDUDE_UPLOAD_RATE)
AVRDUDE_FLAGS += -U flash:w:$(HEXNAME)
AVRDUDE = $(AVRDUDE_PATH)avrdude
#=== predefined variable override ===
# use "make -p -f/dev/null" to see the default rules and definitions
# Build C and C++ flags. Include path information must be placed here
COMMON_FLAGS = -DF_CPU=$(F_CPU) -mmcu=$(MCU) $(DEFS) -DARDUINO=100
# COMMON_FLAGS += -gdwarf-2
COMMON_FLAGS += -Os
COMMON_FLAGS += -Wall -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
COMMON_FLAGS += -I$(ARDUINO_PATH)hardware/arduino/cores/arduino
COMMON_FLAGS += -I$(ARDUINO_PATH)hardware/arduino/variants/$(VARIANT)
COMMON_FLAGS += -I. -I$(U8G_PATH) -I$(U8G_CPP_PATH)
COMMON_FLAGS += $(addprefix -I,$(EXTRA_DIRS))
COMMON_FLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections
COMMON_FLAGS += -Wl,--Map=output.map
COMMON_FLAGS += -Wl,--relax
COMMON_FLAGS += -mcall-prologues
CFLAGS = $(COMMON_FLAGS) -std=gnu99 -Wstrict-prototypes
CXXFLAGS = $(COMMON_FLAGS)
# Replace standard build tools by avr tools
CC = $(AVRTOOLSPATH)avr-gcc
CXX = $(AVRTOOLSPATH)avr-g++
AR = @$(AVRTOOLSPATH)avr-ar
# "rm" must be able to delete a directory tree
RM = rm -rf
#=== rules ===
# add rules for the C/C++ files where the .o file is placed in the TMPDIRPATH
# reuse existing variables as far as possible
$(TMPDIRPATH)%.o: %.c
@echo compile $<
@$(COMPILE.c) $(OUTPUT_OPTION) $<
$(TMPDIRPATH)%.o: %.cc
@echo compile $<
@$(COMPILE.cc) $(OUTPUT_OPTION) $<
$(TMPDIRPATH)%.o: %.cpp
@echo compile $<
@$(COMPILE.cpp) $(OUTPUT_OPTION) $<
$(TMPDIRPATH)%.s: %.c
@$(COMPILE.c) $(OUTPUT_OPTION) -S $<
$(TMPDIRPATH)%.s: %.cc
@$(COMPILE.cc) $(OUTPUT_OPTION) -S $<
$(TMPDIRPATH)%.s: %.cpp
@$(COMPILE.cpp) $(OUTPUT_OPTION) -S $<
$(TMPDIRPATH)%.dis: $(TMPDIRPATH)%.o
@$(OBJDUMP) -S $< > $@
.SUFFIXES: .elf .hex .ino
.elf.hex:
@$(OBJCOPY) -O ihex -R .eeprom $< $@
$(TMPDIRPATH)%.cpp: %.ino
@cat $(ARDUINO_PATH)hardware/arduino/cores/arduino/main.cpp > $@
@cat $< >> $@
@echo >> $@
@echo 'extern "C" void __cxa_pure_virtual() { while (1); }' >> $@
.PHONY: all
all: tmpdir $(HEXNAME) assemblersource showsize
ls -al $(HEXNAME) $(ELFNAME)
$(ELFNAME): $(LIBNAME)($(addprefix $(TMPDIRPATH),$(OBJFILES)))
$(LINK.o) $(COMMON_FLAGS) $(LIBNAME) $(LOADLIBES) $(LDLIBS) -o $@
$(LIBNAME)(): $(addprefix $(TMPDIRPATH),$(OBJFILES))
#=== create temp directory ===
# not really required, because it will be also created during the dependency handling
.PHONY: tmpdir
tmpdir:
@test -d $(TMPDIRPATH) || mkdir $(TMPDIRPATH)
#=== create assembler files for each C/C++ file ===
.PHONY: assemblersource
assemblersource: $(addprefix $(TMPDIRPATH),$(ASSFILES)) $(addprefix $(TMPDIRPATH),$(DISFILES))
#=== show the section sizes of the ELF file ===
.PHONY: showsize
showsize: $(ELFNAME)
$(SIZE) $<
#=== clean up target ===
# this is simple: the TMPDIRPATH is removed
.PHONY: clean
clean:
$(RM) $(TMPDIRPATH)
# Program the device.
# step 1: reset the arduino board with the stty command
# step 2: user avrdude to upload the software
.PHONY: upload
upload: $(HEXNAME)
stty -F $(AVRDUDE_PORT) hupcl
$(AVRDUDE) $(AVRDUDE_FLAGS)
# === dependency handling ===
# From the gnu make manual (section 4.14, Generating Prerequisites Automatically)
# Additionally (because this will be the first executed rule) TMPDIRPATH is created here.
# Instead of "sed" the "echo" command is used
# cd $(TMPDIRPATH); mkdir -p $(DIRS) 2> /dev/null; cd ..
DEPACTION=test -d $(TMPDIRPATH) || mkdir $(TMPDIRPATH);\
mkdir -p $(addprefix $(TMPDIRPATH),$(DIRS));\
set -e; echo -n $@ $(dir $@) > $@; $(CC) -MM $(COMMON_FLAGS) $< >> $@
$(TMPDIRPATH)%.d: %.c
@$(DEPACTION)
$(TMPDIRPATH)%.d: %.cc
@$(DEPACTION)
$(TMPDIRPATH)%.d: %.cpp
@$(DEPACTION)
# Include dependency files. If a .d file is missing, a warning is created and the .d file is created
# This warning is not a problem (gnu make manual, section 3.3 Including Other Makefiles)
-include $(addprefix $(TMPDIRPATH),$(DEPFILES))

View File

@ -0,0 +1,231 @@
/*
GraphicsTest.ino
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
Copyright (c) 2016, olikraus@gmail.com
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.
*/
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
/*
U8glib Example Overview:
Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.
*/
// Please UNCOMMENT one of the contructor lines below
// U8g2 Contructor List (Frame Buffer)
// The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp
// Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected
//U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6); // Arduboy (Production, Kickstarter Edition)
//U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display
//U8G2_SSD1306_128X64_NONAME_F_6800 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_F_8080 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8);
//U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 21, /* data=*/ 20, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather M0 Basic Proto + FeatherWing OLED
//U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED
//U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED
//U8G2_LD7032_60X32_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* cs=*/ 9, /* dc=*/ 10, /* reset=*/ 8); // SW SPI Nano Board
//U8G2_LD7032_60X32_F_4W_SW_I2C u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* reset=*/ U8X8_PIN_NONE); // NOT TESTED!
//U8G2_UC1701_EA_DOGS102_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_UC1701_EA_DOGS102_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_ST7920_192X32_F_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ U8X8_PIN_NONE, /*dc=*/ 17, /*reset=*/ U8X8_PIN_NONE);
//U8G2_ST7920_192X32_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE);
//U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE);
//U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8);
//U8G2_ST7920_128X64_F_HW_SPI u8g2(U8G2_R0, /* CS=*/ 10, /* reset=*/ 8);
//U8G2_ST7565_EA_DOGM128_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_ST7565_EA_DOGM128_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_ST7565_NHD_C12832_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_ST7565_NHD_C12832_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
// End of constructor list
void u8g2_prepare(void) {
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setFontRefHeightExtendedText();
u8g2.setDrawColor(1);
u8g2.setFontPosTop();
u8g2.setFontDirection(0);
}
void u8g2_box_frame(uint8_t a) {
u8g2.drawStr( 0, 0, "drawBox");
u8g2.drawBox(5,10,20,10);
u8g2.drawBox(10+a,15,30,7);
u8g2.drawStr( 0, 30, "drawFrame");
u8g2.drawFrame(5,10+30,20,10);
u8g2.drawFrame(10+a,15+30,30,7);
}
void u8g2_disc_circle(uint8_t a) {
u8g2.drawStr( 0, 0, "drawDisc");
u8g2.drawDisc(10,18,9);
u8g2.drawDisc(24+a,16,7);
u8g2.drawStr( 0, 30, "drawCircle");
u8g2.drawCircle(10,18+30,9);
u8g2.drawCircle(24+a,16+30,7);
}
void u8g2_r_frame(uint8_t a) {
u8g2.drawStr( 0, 0, "drawRFrame/Box");
u8g2.drawRFrame(5, 10,40,30, a+1);
u8g2.drawRBox(50, 10,25,40, a+1);
}
void u8g2_string(uint8_t a) {
u8g2.setFontDirection(0);
u8g2.drawStr(30+a,31, " 0");
u8g2.setFontDirection(1);
u8g2.drawStr(30,31+a, " 90");
u8g2.setFontDirection(2);
u8g2.drawStr(30-a,31, " 180");
u8g2.setFontDirection(3);
u8g2.drawStr(30,31-a, " 270");
}
void u8g2_line(uint8_t a) {
u8g2.drawStr( 0, 0, "drawLine");
u8g2.drawLine(7+a, 10, 40, 55);
u8g2.drawLine(7+a*2, 10, 60, 55);
u8g2.drawLine(7+a*3, 10, 80, 55);
u8g2.drawLine(7+a*4, 10, 100, 55);
}
void u8g2_triangle(uint8_t a) {
uint16_t offset = a;
u8g2.drawStr( 0, 0, "drawTriangle");
u8g2.drawTriangle(14,7, 45,30, 10,40);
u8g2.drawTriangle(14+offset,7-offset, 45+offset,30-offset, 57+offset,10-offset);
u8g2.drawTriangle(57+offset*2,10, 45+offset*2,30, 86+offset*2,53);
u8g2.drawTriangle(10+offset,40+offset, 45+offset,30+offset, 86+offset,53+offset);
}
void u8g2_ascii_1() {
char s[2] = " ";
uint8_t x, y;
u8g2.drawStr( 0, 0, "ASCII page 1");
for( y = 0; y < 6; y++ ) {
for( x = 0; x < 16; x++ ) {
s[0] = y*16 + x + 32;
u8g2.drawStr(x*7, y*10+10, s);
}
}
}
void u8g2_ascii_2() {
char s[2] = " ";
uint8_t x, y;
u8g2.drawStr( 0, 0, "ASCII page 2");
for( y = 0; y < 6; y++ ) {
for( x = 0; x < 16; x++ ) {
s[0] = y*16 + x + 160;
u8g2.drawStr(x*7, y*10+10, s);
}
}
}
void u8g2_extra_page(uint8_t a)
{
u8g2.drawStr( 0, 0, "Unicode");
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.setFontPosTop();
u8g2.drawUTF8(0, 24, "☀ ☁");
switch(a) {
case 0:
case 1:
case 2:
case 3:
u8g2.drawUTF8(a*3, 36, "");
break;
case 4:
case 5:
case 6:
case 7:
u8g2.drawUTF8(a*3, 36, "");
break;
}
}
uint8_t draw_state = 0;
void draw(void) {
u8g2_prepare();
switch(draw_state >> 3) {
case 0: u8g2_box_frame(draw_state&7); break;
case 1: u8g2_disc_circle(draw_state&7); break;
case 2: u8g2_r_frame(draw_state&7); break;
case 3: u8g2_string(draw_state&7); break;
case 4: u8g2_line(draw_state&7); break;
case 5: u8g2_triangle(draw_state&7); break;
case 6: u8g2_ascii_1(); break;
case 7: u8g2_ascii_2(); break;
case 8: u8g2_extra_page(draw_state&7); break;
}
}
void setup(void) {
u8g2.begin();
}
void loop(void) {
// picture loop
u8g2.clearBuffer();
draw();
u8g2.sendBuffer();
// increase the state
draw_state++;
if ( draw_state >= 9*8 )
draw_state = 0;
// deley between each page
delay(100);
}

View File

@ -0,0 +1,286 @@
#
# Arduino-1.0 Makefile
#
# written by olikraus@gmail.com
#
# Features:
# - boards.txt is used to derive parameters
# - All intermediate files are put into a separate directory (TMPDIRNAME)
# - Simple use: Copy Makefile into the same directory of the .ino file
#
# Limitations:
# - requires UNIX environment
# - TMPDIRNAME must be subdirectory of the current directory.
#
# Targets
# all build everything
# upload build and upload to arduino
# clean remove all temporary files (includes final hex file)
#
# History
# 001 28 Apr 2010 first release
# 002 05 Oct 2010 added 'uno'
# 003 06 Dec 2011 arduino 1.0
# 004 11 Feb 2012 u8glib
#
#=== user configuration ===
# All ...PATH variables must have a '/' at the end
# Board (and prozessor) information: see $(ARDUINO_PATH)hardware/arduino/boards.txt
# Some examples:
# BOARD DESCRIPTION
# uno Arduino Uno
# atmega328 Arduino Duemilanove or Nano w/ ATmega328
# diecimila Arduino Diecimila, Duemilanove, or Nano w/ ATmega168
# mega Arduino Mega
# mega2560 Arduino Mega2560
# mini Arduino Mini
# lilypad328 LilyPad Arduino w/ ATmega328
BOARD:=uno
# additional definitions
#DEFS:=-DARDUINO=105
U8G_PATH:=$(shell cd ../../../.. && pwd)/csrc/
U8G_CPP_PATH:=$(shell cd ../../../.. && pwd)/cppsrc/
#U8G_FONT_PATH:=$(shell cd ../../.. && pwd)/sfntsrc/
# The location where the avr tools (e.g. avr-gcc) are located. Requires a '/' at the end.
# Can be empty if all tools are accessable through the search path
AVR_TOOLS_PATH:=/usr/bin/
# Install path of the arduino software. Requires a '/' at the end.
ARDUINO_PATH:=/home/kraus/prg/arduino-1.0.5-u8glib/
# Install path for avrdude. Requires a '/' at the end. Can be empty if avrdude is in the search path.
AVRDUDE_PATH:=$(ARDUINO_PATH)hardware/tools/
# The unix device where we can reach the arduino board
# Uno: /dev/ttyACM0
# Duemilanove: /dev/ttyUSB0
AVRDUDE_PORT:=/dev/ttyACM0
# List of all libaries which should be included.
EXTRA_DIRS=$(ARDUINO_PATH)libraries/LiquidCrystal/
EXTRA_DIRS+=$(ARDUINO_PATH)libraries/SD/
EXTRA_DIRS+=$(ARDUINO_PATH)libraries/SD/utility/
EXTRA_DIRS+=$(ARDUINO_PATH)libraries/Wire/
EXTRA_DIRS+=$(ARDUINO_PATH)libraries/Wire/utility/
EXTRA_DIRS+=$(ARDUINO_PATH)libraries/SPI/
#EXTRA_DIRS+=$(ARDUINO_PATH)libraries/.../
#=== fetch parameter from boards.txt processor parameter ===
# the basic idea is to get most of the information from boards.txt
BOARDS_TXT:=$(ARDUINO_PATH)hardware/arduino/boards.txt
# get the MCU value from the $(BOARD).build.mcu variable. For the atmega328 board this is atmega328p
MCU:=$(shell sed -n -e "s/$(BOARD).build.mcu=\(.*\)/\1/p" $(BOARDS_TXT))
# get the F_CPU value from the $(BOARD).build.f_cpu variable. For the atmega328 board this is 16000000
F_CPU:=$(shell sed -n -e "s/$(BOARD).build.f_cpu=\(.*\)/\1/p" $(BOARDS_TXT))
# get variant subfolder
VARIANT:=$(shell sed -n -e "s/$(BOARD).build.variant=\(.*\)/\1/p" $(BOARDS_TXT))
# avrdude
# get the AVRDUDE_UPLOAD_RATE value from the $(BOARD).upload.speed variable. For the atmega328 board this is 57600
AVRDUDE_UPLOAD_RATE:=$(shell sed -n -e "s/$(BOARD).upload.speed=\(.*\)/\1/p" $(BOARDS_TXT))
# get the AVRDUDE_PROGRAMMER value from the $(BOARD).upload.protocol variable. For the atmega328 board this is stk500
AVRDUDE_PROGRAMMER:=$(shell sed -n -e "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_TXT))
# use stk500v1, because stk500 will default to stk500v2
#AVRDUDE_PROGRAMMER:=stk500v1
#=== identify user files ===
INOSRC:=$(shell ls *.ino)
TARGETNAME=$(basename $(INOSRC))
CDIRS:=$(EXTRA_DIRS) $(addsuffix utility/,$(EXTRA_DIRS))
CDIRS:=*.c utility/*.c $(U8G_PATH)*.c $(addsuffix *.c,$(CDIRS)) $(ARDUINO_PATH)hardware/arduino/cores/arduino/*.c
CSRC:=$(shell ls $(CDIRS) 2>/dev/null)
CCSRC:=$(shell ls *.cc 2>/dev/null)
CPPDIRS:=$(EXTRA_DIRS) $(addsuffix utility/,$(EXTRA_DIRS)) $(U8G_CPP_PATH)
CPPDIRS:=*.cpp utility/*.cpp $(addsuffix *.cpp,$(CPPDIRS)) $(ARDUINO_PATH)hardware/arduino/cores/arduino/*.cpp
CPPSRC:=$(shell ls $(CPPDIRS) 2>/dev/null)
#=== build internal variables ===
# the name of the subdirectory where everything is stored
TMPDIRNAME:=tmp
TMPDIRPATH:=$(TMPDIRNAME)/
AVRTOOLSPATH:=$(AVR_TOOLS_PATH)
OBJCOPY:=$(AVRTOOLSPATH)avr-objcopy
OBJDUMP:=$(AVRTOOLSPATH)avr-objdump
SIZE:=$(AVRTOOLSPATH)avr-size
CPPSRC:=$(addprefix $(TMPDIRPATH),$(INOSRC:.ino=.cpp)) $(CPPSRC)
COBJ:=$(CSRC:.c=.o)
CCOBJ:=$(CCSRC:.cc=.o)
CPPOBJ:=$(CPPSRC:.cpp=.o)
OBJFILES:=$(COBJ) $(CCOBJ) $(CPPOBJ)
DIRS:= $(dir $(OBJFILES))
DEPFILES:=$(OBJFILES:.o=.d)
# assembler files from avr-gcc -S
ASSFILES:=$(OBJFILES:.o=.s)
# disassembled object files with avr-objdump -S
DISFILES:=$(OBJFILES:.o=.dis)
LIBNAME:=$(TMPDIRPATH)$(TARGETNAME).a
ELFNAME:=$(TMPDIRPATH)$(TARGETNAME).elf
HEXNAME:=$(TMPDIRPATH)$(TARGETNAME).hex
AVRDUDE_FLAGS = -V -F
AVRDUDE_FLAGS += -C $(ARDUINO_PATH)/hardware/tools/avrdude.conf
AVRDUDE_FLAGS += -p $(MCU)
AVRDUDE_FLAGS += -P $(AVRDUDE_PORT)
AVRDUDE_FLAGS += -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += -b $(AVRDUDE_UPLOAD_RATE)
AVRDUDE_FLAGS += -U flash:w:$(HEXNAME)
AVRDUDE = $(AVRDUDE_PATH)avrdude
#=== predefined variable override ===
# use "make -p -f/dev/null" to see the default rules and definitions
# Build C and C++ flags. Include path information must be placed here
COMMON_FLAGS = -DF_CPU=$(F_CPU) -mmcu=$(MCU) $(DEFS) -DARDUINO=100
# COMMON_FLAGS += -gdwarf-2
COMMON_FLAGS += -Os
COMMON_FLAGS += -Wall -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
COMMON_FLAGS += -I$(ARDUINO_PATH)hardware/arduino/cores/arduino
COMMON_FLAGS += -I$(ARDUINO_PATH)hardware/arduino/variants/$(VARIANT)
COMMON_FLAGS += -I. -I$(U8G_PATH) -I$(U8G_CPP_PATH)
COMMON_FLAGS += $(addprefix -I,$(EXTRA_DIRS))
COMMON_FLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections
COMMON_FLAGS += -Wl,--Map=output.map
COMMON_FLAGS += -Wl,--relax
COMMON_FLAGS += -mcall-prologues
CFLAGS = $(COMMON_FLAGS) -std=gnu99 -Wstrict-prototypes
CXXFLAGS = $(COMMON_FLAGS)
# Replace standard build tools by avr tools
CC = $(AVRTOOLSPATH)avr-gcc
CXX = $(AVRTOOLSPATH)avr-g++
AR = @$(AVRTOOLSPATH)avr-ar
# "rm" must be able to delete a directory tree
RM = rm -rf
#=== rules ===
# add rules for the C/C++ files where the .o file is placed in the TMPDIRPATH
# reuse existing variables as far as possible
$(TMPDIRPATH)%.o: %.c
@echo compile $<
@$(COMPILE.c) $(OUTPUT_OPTION) $<
$(TMPDIRPATH)%.o: %.cc
@echo compile $<
@$(COMPILE.cc) $(OUTPUT_OPTION) $<
$(TMPDIRPATH)%.o: %.cpp
@echo compile $<
@$(COMPILE.cpp) $(OUTPUT_OPTION) $<
$(TMPDIRPATH)%.s: %.c
@$(COMPILE.c) $(OUTPUT_OPTION) -S $<
$(TMPDIRPATH)%.s: %.cc
@$(COMPILE.cc) $(OUTPUT_OPTION) -S $<
$(TMPDIRPATH)%.s: %.cpp
@$(COMPILE.cpp) $(OUTPUT_OPTION) -S $<
$(TMPDIRPATH)%.dis: $(TMPDIRPATH)%.o
@$(OBJDUMP) -S $< > $@
.SUFFIXES: .elf .hex .ino
.elf.hex:
@$(OBJCOPY) -O ihex -R .eeprom $< $@
$(TMPDIRPATH)%.cpp: %.ino
@cat $(ARDUINO_PATH)hardware/arduino/cores/arduino/main.cpp > $@
@cat $< >> $@
@echo >> $@
@echo 'extern "C" void __cxa_pure_virtual() { while (1); }' >> $@
.PHONY: all
all: tmpdir $(HEXNAME) assemblersource showsize
ls -al $(HEXNAME) $(ELFNAME)
$(ELFNAME): $(LIBNAME)($(addprefix $(TMPDIRPATH),$(OBJFILES)))
$(LINK.o) $(COMMON_FLAGS) $(LIBNAME) $(LOADLIBES) $(LDLIBS) -o $@
$(LIBNAME)(): $(addprefix $(TMPDIRPATH),$(OBJFILES))
#=== create temp directory ===
# not really required, because it will be also created during the dependency handling
.PHONY: tmpdir
tmpdir:
@test -d $(TMPDIRPATH) || mkdir $(TMPDIRPATH)
#=== create assembler files for each C/C++ file ===
.PHONY: assemblersource
assemblersource: $(addprefix $(TMPDIRPATH),$(ASSFILES)) $(addprefix $(TMPDIRPATH),$(DISFILES))
#=== show the section sizes of the ELF file ===
.PHONY: showsize
showsize: $(ELFNAME)
$(SIZE) $<
#=== clean up target ===
# this is simple: the TMPDIRPATH is removed
.PHONY: clean
clean:
$(RM) $(TMPDIRPATH)
# Program the device.
# step 1: reset the arduino board with the stty command
# step 2: user avrdude to upload the software
.PHONY: upload
upload: $(HEXNAME)
stty -F $(AVRDUDE_PORT) hupcl
$(AVRDUDE) $(AVRDUDE_FLAGS)
# === dependency handling ===
# From the gnu make manual (section 4.14, Generating Prerequisites Automatically)
# Additionally (because this will be the first executed rule) TMPDIRPATH is created here.
# Instead of "sed" the "echo" command is used
# cd $(TMPDIRPATH); mkdir -p $(DIRS) 2> /dev/null; cd ..
DEPACTION=test -d $(TMPDIRPATH) || mkdir $(TMPDIRPATH);\
mkdir -p $(addprefix $(TMPDIRPATH),$(DIRS));\
set -e; echo -n $@ $(dir $@) > $@; $(CC) -MM $(COMMON_FLAGS) $< >> $@
$(TMPDIRPATH)%.d: %.c
@$(DEPACTION)
$(TMPDIRPATH)%.d: %.cc
@$(DEPACTION)
$(TMPDIRPATH)%.d: %.cpp
@$(DEPACTION)
# Include dependency files. If a .d file is missing, a warning is created and the .d file is created
# This warning is not a problem (gnu make manual, section 3.3 Including Other Makefiles)
-include $(addprefix $(TMPDIRPATH),$(DEPFILES))

View File

@ -58,7 +58,7 @@
// The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp
// Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected
//U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6); // Arduboy (Production, Kickstarter Edition)
//U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6); // Arduboy (Production, Kickstarter Edition)
//U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_1_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8);
//U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* reset=*/ 8);

View File

@ -549,6 +549,69 @@ int main(void)
tga_save_png("u8g2_triangle.png");
/*=========================================*/
/* u8g2_line.png */
u8x8_ClearDisplay(u8g2_GetU8x8(&desc));
u8g2_SetFontPosCenter(&u8g2);
u8g2_FirstPage(&u8g2);
do
{
u8g2_DrawLine(&u8g2, 20, 5, 5, 32);
} while( u8g2_NextPage(&u8g2) );
tga_is_transparent = 1;
u8g2_FirstPage(&desc);
do
{
u8g2_SetFont(&desc, u8g2_font_helvB18_tf);
ra(20,5, "x=20, y=5");
ra(5,32, "x=5, y=32");
//vm(62,19-u8g2_GetDescent(&u8g2), -u8g2_GetDescent(&u8g2));
} while( u8g2_NextPage(&desc) );
tga_is_transparent = 0;
u8g2_SetFontPosBaseline(&u8g2);
tga_save_png("u8g2_line.png");
/*=========================================*/
/* u8g2_font_direction.png */
u8x8_ClearDisplay(u8g2_GetU8x8(&desc));
u8g2_SetFontPosBaseline(&u8g2);
u8g2_FirstPage(&u8g2);
do
{
u8g2_SetFont(&u8g2, u8g2_font_ncenB14_tf);
u8g2_SetFontDirection(&u8g2, 0);
u8g2_DrawStr(&u8g2, 15, 20, "Abc");
u8g2_SetFontDirection(&u8g2, 1);
u8g2_DrawStr(&u8g2, 15, 20, "Abc");
} while( u8g2_NextPage(&u8g2) );
tga_is_transparent = 1;
u8g2_FirstPage(&desc);
do
{
u8g2_SetFont(&desc, u8g2_font_helvB18_tf);
ra(15,20, "x=15, y=20");
//vm(62,19-u8g2_GetDescent(&u8g2), -u8g2_GetDescent(&u8g2));
} while( u8g2_NextPage(&desc) );
tga_is_transparent = 0;
u8g2_SetFontPosBaseline(&u8g2);
u8g2_SetFontDirection(&u8g2, 0);
tga_save_png("u8g2_font_direction.png");
/*=========================================*/
/* u8g2_color.png */

View File

@ -56,6 +56,12 @@ cp ../../../sys/arduino/u8g2_full_buffer/PrintUTF8/*.ino ../../../../U8g2_Arduin
mkdir ../../../../U8g2_Arduino/examples/full_buffer/SelectionList
cp ../../../sys/arduino/u8g2_full_buffer/SelectionList/*.ino ../../../../U8g2_Arduino/examples/full_buffer/SelectionList/.
mkdir ../../../../U8g2_Arduino/examples/full_buffer/GraphicsTest
cp ../../../sys/arduino/u8g2_full_buffer/GraphicsTest/*.ino ../../../../U8g2_Arduino/examples/full_buffer/GraphicsTest/.
mkdir ../../../../U8g2_Arduino/examples/full_buffer/FPS
cp ../../../sys/arduino/u8g2_full_buffer/FPS/*.ino ../../../../U8g2_Arduino/examples/full_buffer/FPS/.
# u8x8
mkdir ../../../../U8g2_Arduino/examples/u8x8/HelloWorld