Skip to content

Commit

Permalink
openglcd
Browse files Browse the repository at this point in the history
  • Loading branch information
olikraus committed May 29, 2014
1 parent 9ba2d6c commit 9f74bfa
Show file tree
Hide file tree
Showing 6 changed files with 899 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ M2tklib ChangeLog
* Changed default behavioir for M2_ALGIN (Issue 121)
* New element: M2_COMBOFN (Issue 122)
* New tutorial on event sources (Issues 117 and 123)
2014-05-05 v1.12 Oliver Kraus <[email protected]>
2014-xx-xx v1.12 Oliver Kraus <[email protected]>
* M2_TEXT update

* Native support for openGLCD
289 changes: 289 additions & 0 deletions arduino/openglcd/Menu2L/Makefile.105.duemilanove
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@

#
# Arduino-1.0 Makefile
#
# written by [email protected]
#
# 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 .pde 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
# 005 05 Apr 2012 m2tklib
# 006 26 Mar 2013 glcd port
# 007 29 May 2014 openglcd port

#=== 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
# mini Arduino Mini
# lilypad328 LilyPad Arduino w/ ATmega328
BOARD:=atmega328

# additional definitions
#DEFS:=-DARDUINO=105


#U8G_PATH:=$(shell cd ../../../../../u8g/u8glib && pwd)/csrc/
#U8G_CPP_PATH:=$(shell cd ../../../../../u8g/u8glib && pwd)/cppsrc/
#U8G_FONT_PATH:=$(shell cd ../../../../../u8g/u8glib && pwd)/sfntsrc/

M2TKLIB_PATH:=$(shell cd ../../.. && pwd)/src/
M2TKCPP_PATH:=$(shell cd ../../.. && pwd)/cpp/
M2DEV_PATH:=$(shell cd ../../.. && pwd)/dev/openglcd/
M2DEV2_PATH:=$(shell cd ../../.. && pwd)/dev/arduino/


# 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-openglcd/

# 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/ttyUSB0

# List of all libaries which should be included.
EXTRA_DIRS=$(ARDUINO_PATH)libraries/LiquidCrystal/
EXTRA_DIRS+=$(ARDUINO_PATH)libraries/openGLCD/
#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 ===
PDESRC:=$(shell ls *.pde)
TARGETNAME=$(basename $(PDESRC))

CDIRS:=$(EXTRA_DIRS) $(addsuffix utility/,$(EXTRA_DIRS))
CDIRS:=*.c utility/*.c $(M2TKLIB_PATH)*.c $(M2DEV_PATH)*.c $(M2DEV2_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))
CPPDIRS:=*.cpp utility/*.cpp $(addsuffix *.cpp,$(CPPDIRS)) $(M2DEV_PATH)*.cpp $(M2TKCPP_PATH)/*.cpp $(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),$(PDESRC:.pde=.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. -I$(M2TKLIB_PATH) -I$(M2DEV_PATH) -I$(M2TKCPP_PATH)
COMMON_FLAGS += -I$(ARDUINO_PATH)hardware/arduino/cores/arduino
COMMON_FLAGS += -I$(ARDUINO_PATH)hardware/arduino/variants/$(VARIANT)
COMMON_FLAGS += -I.
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 .pde

.elf.hex:
@$(OBJCOPY) -O ihex -R .eeprom $< $@

$(TMPDIRPATH)%.cpp: %.pde
@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))


99 changes: 99 additions & 0 deletions arduino/openglcd/Menu2L/Menu2L.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
2LMenu.pde
openGLCD Example
m2tklib = Mini Interative Interface Toolkit Library
Copyright (C) 2014 [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 <openGLCD.h> // inform Arduino IDE that we will use openGLCD library
#include "M2tk.h"
#include "m2ghopenglcd.h"

#include "fonts/System5x7.h"
#include "fonts/Arial14.h"

uint8_t uiKeySelectPin = 3;
uint8_t uiKeyDownPin = 2;
uint8_t uiKeyUpPin = 1;
uint8_t uiKeyExitPin = 0;


//=================================================
// Forward declaration of the toplevel element
M2_EXTERN_ALIGN(top_el_expandable_menu);

// Left entry: Menu name. Submenus must have a '.' at the beginning
// Right entry: Reference to the target dialog box (In this example all menus call the toplevel element again
m2_menu_entry m2_2lmenu_data[] =
{
{ "Menu 1", NULL },
{ ". Sub 1-1", &top_el_expandable_menu },
{ ". Sub 1-2", &top_el_expandable_menu },
{ "Menu 2", &top_el_expandable_menu },
{ "Menu 3", NULL },
{ ". Sub 3-1", &top_el_expandable_menu },
{ ". Sub 3-2", &top_el_expandable_menu },
{ "Menu 4", &top_el_expandable_menu },
{ "Menu 5", NULL },
{ ". Sub 5-1", &top_el_expandable_menu },
{ ". Sub 5-2", &top_el_expandable_menu },
{ ". Sub 5-3", &top_el_expandable_menu },
{ NULL, NULL },
};

// The first visible line and the total number of visible lines.
// Both values are written by M2_2LMENU and read by M2_VSB
uint8_t m2_2lmenu_first;
uint8_t m2_2lmenu_cnt;

// M2_2LMENU definition
// Option l4 = four visible lines
// Option e15 = first column has a width of 15 pixel
// Option W43 = second column has a width of 43/64 of the display width

M2_2LMENU(el_2lmenu,"l4e15W43",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0');
M2_SPACE(el_space, "W1h1");
M2_VSB(el_vsb, "l4W2r1", &m2_2lmenu_first, &m2_2lmenu_cnt);
M2_LIST(list_2lmenu) = { &el_2lmenu, &el_space, &el_vsb };
M2_HLIST(el_hlist, NULL, list_2lmenu);
M2_ALIGN(top_el_expandable_menu, "-1|1W64H64", &el_hlist);

// m2 object and constructor
M2tk m2(&top_el_expandable_menu, m2_es_arduino, m2_eh_4bs, m2_gh_openglcd_ffs);

void setup() {
m2.setFont(0, System5x7);
//m2.setFont(0, Arial14);

m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
m2.setPin(M2_KEY_NEXT, uiKeyDownPin);
m2.setPin(M2_KEY_PREV, uiKeyUpPin);
m2.setPin(M2_KEY_EXIT, uiKeyExitPin);
}

void loop() {
m2.checkKey();
if ( m2.handleKey() ) {
m2.draw();
}
}


Loading

0 comments on commit 9f74bfa

Please sign in to comment.