issue #98
This commit is contained in:
parent
6c995f3289
commit
55f311e65e
|
@ -59,9 +59,10 @@ static const uint8_t u8x8_d_ssd1306_128x64_noname_init_seq[] = {
|
|||
// U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
|
||||
|
||||
U8X8_CA(0x0da, 0x012), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
|
||||
U8X8_CA(0x081, 0x0cf), /* [2] set contrast control */
|
||||
U8X8_CA(0x0d9, 0x0f1), /* [2] pre-charge period 0x022/f1*/
|
||||
U8X8_CA(0x0db, 0x040), /* vcomh deselect level */
|
||||
U8X8_CA(0x081, 0x0ef), /* [2] set contrast control, */
|
||||
U8X8_CA(0x0d9, 0x0a1), /* [2] pre-charge period 0x022/f1*/
|
||||
U8X8_CA(0x0db, 0x000), /* vcomh deselect level 0x000 .. 0x070, low nibble always 0 */
|
||||
// if vcomh is 0, then this will give the biggest range for contrast control issue #98
|
||||
|
||||
U8X8_C(0x02e), /* Deactivate scroll */
|
||||
U8X8_C(0x0a4), /* output ram to display */
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
|
||||
HelloWorld.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.
|
||||
|
||||
This is a page buffer example.
|
||||
*/
|
||||
|
||||
// Please UNCOMMENT one of the contructor lines below
|
||||
// U8g2 Contructor List (Picture Loop Page 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_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=*/ 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);
|
||||
//U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display
|
||||
//U8G2_SSD1306_128X64_NONAME_1_6800 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8);
|
||||
//U8G2_SSD1306_128X64_NONAME_1_8080 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8);
|
||||
//U8G2_SH1106_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
|
||||
//U8G2_SSD1306_128X32_UNIVISION_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 21, /* data=*/ 20, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather M0 Basic Proto + FeatherWing OLED
|
||||
//U8G2_SSD1306_128X32_UNIVISION_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED
|
||||
//U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED
|
||||
//U8G2_SSD1306_64X48_ER_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // EastRising 0.66" OLED breakout board, Uno: A4=SDA, A5=SCL, 5V powered
|
||||
//U8G2_SSD1322_NHD_256X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h
|
||||
//U8G2_SSD1322_NHD_256X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h
|
||||
//U8G2_SSD1325_NHD_128X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
|
||||
//U8G2_SSD1325_NHD_128X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
|
||||
//U8G2_LD7032_60X32_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* cs=*/ 9, /* dc=*/ 10, /* reset=*/ 8); // SW SPI Nano Board
|
||||
//U8G2_LD7032_60X32_1_4W_SW_I2C u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* reset=*/ U8X8_PIN_NONE); // NOT TESTED!
|
||||
//U8G2_UC1701_EA_DOGS102_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
|
||||
//U8G2_UC1701_EA_DOGS102_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
|
||||
//U8G2_ST7920_192X32_1_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_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE);
|
||||
//U8G2_ST7920_128X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18 /* A4 */, /*cs=*/ U8X8_PIN_NONE, /*dc/rs=*/ 17 /* A3 */, /*reset=*/ 15 /* A1 */); // Remember to set R/W to 0
|
||||
//U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE);
|
||||
//U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8);
|
||||
//U8G2_ST7920_128X64_1_HW_SPI u8g2(U8G2_R0, /* CS=*/ 10, /* reset=*/ 8);
|
||||
//U8G2_ST7565_EA_DOGM128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
|
||||
//U8G2_ST7565_EA_DOGM128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
|
||||
//U8G2_ST7565_NHD_C12832_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
|
||||
//U8G2_ST7565_NHD_C12832_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
|
||||
//U8G2_T6963_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND
|
||||
//U8G2_T6963_256X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND
|
||||
//U8G2_SED1330_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect /RD = E with +5V, enable is /WR = RW, FG with GND, 14=Uno Pin A0
|
||||
//U8G2_SED1330_240X128_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // A0 is dc pin, /WR = RW = GND, enable is /RD = E
|
||||
//U8G2_RA8835_NHD_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect /RD = E with +5V, enable is /WR = RW, FG with GND, 14=Uno Pin A0
|
||||
//U8G2_RA8835_NHD_240X128_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // A0 is dc pin, /WR = RW = GND, enable is /RD = E
|
||||
//U8G2_UC1608_ERC24064_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due ERC24064-1 Test Setup
|
||||
//U8G2_UC1610_EA_DOGXL160_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE);
|
||||
//U8G2_UC1610_EA_DOGXL160_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE);
|
||||
//U8G2_UC1611_EA_DOGM240_1_2ND_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); // Due, 2nd I2C, DOGM240 Test Board
|
||||
//U8G2_UC1611_EA_DOGM240_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board
|
||||
//U8G2_UC1611_EA_DOGXL240_1_2ND_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); // Due, 2nd I2C, DOGXL240 Test Board
|
||||
//U8G2_UC1611_EA_DOGXL240_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// End of constructor list
|
||||
|
||||
|
||||
void testContrast(uint8_t contrast)
|
||||
{
|
||||
static char cstr[6];
|
||||
static char vstr[4];
|
||||
u8g2.setContrast(contrast);
|
||||
strcpy( cstr, u8x8_u8toa(contrast, 3));
|
||||
u8g2.firstPage();
|
||||
do {
|
||||
//u8g2.setFont(u8g2_font_ncenB14_tr);
|
||||
u8g2.setFont(u8g2_font_courB24_tn);
|
||||
u8g2.drawStr(0,28, cstr);
|
||||
u8g2.drawBox(64, 0, 10, 64);
|
||||
u8g2.drawBox(76, 0, 2, 64);
|
||||
u8g2.drawBox(80, 0, 1, 64);
|
||||
u8g2.drawBox(82, 0, 1, 64);
|
||||
|
||||
u8g2.drawBox(0, 32, 128, 10);
|
||||
u8g2.drawBox(0, 44, 128, 2);
|
||||
u8g2.drawBox(0, 48, 128, 1);
|
||||
u8g2.drawBox(0, 50, 128, 1);
|
||||
|
||||
} while ( u8g2.nextPage() );
|
||||
}
|
||||
|
||||
|
||||
void setup(void) {
|
||||
|
||||
/* U8g2 Project: SSD1306 Test Board */
|
||||
//pinMode(10, OUTPUT);
|
||||
//pinMode(9, OUTPUT);
|
||||
//digitalWrite(10, 0);
|
||||
//digitalWrite(9, 0);
|
||||
|
||||
/* U8g2 Project: T6963 Test Board */
|
||||
//pinMode(18, OUTPUT);
|
||||
//digitalWrite(18, 1);
|
||||
|
||||
u8g2.begin();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop(void) {
|
||||
uint8_t i;
|
||||
i = 255;
|
||||
do
|
||||
{
|
||||
testContrast(255-i);
|
||||
delay(15);
|
||||
i-=5;
|
||||
} while( i != 0 );
|
||||
i = 255;
|
||||
delay(100);
|
||||
do
|
||||
{
|
||||
testContrast(i);
|
||||
delay(15);
|
||||
i-=5;
|
||||
} while( i != 0 );
|
||||
delay(100);
|
||||
}
|
||||
|
|
@ -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 -Wextra -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))
|
||||
|
||||
|
Loading…
Reference in New Issue