aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-01-31 18:27:49 +0100
committerKarel Kočí <cynerd@email.cz>2017-01-31 18:49:57 +0100
commit5062173627f9d1741061312ceeadd44d4bc0fc24 (patch)
treece63caf1c2a8f99ecd6326f8a47fcc22cf04f0aa
downloadturris-lcd-example-5062173627f9d1741061312ceeadd44d4bc0fc24.tar.gz
turris-lcd-example-5062173627f9d1741061312ceeadd44d4bc0fc24.tar.bz2
turris-lcd-example-5062173627f9d1741061312ceeadd44d4bc0fc24.zip
Initial commit
-rw-r--r--.gitignore8
-rw-r--r--.gitmodules3
-rw-r--r--Makefile98
-rwxr-xr-xconfigure152
m---------liblcd0
-rw-r--r--src/turris-lcd.cpp17
6 files changed, 278 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..39b8314
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+.*
+*.o
+
+!.gitignore
+!.gitmodules
+
+turris-lcd
+build
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..8f42eb3
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "liblcd"]
+ path = liblcd
+ url = https://github.com/Cynerd/liquidcrystal-i2c.git
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9c2cc47
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,98 @@
+MAKEFLAGS += --no-builtin-rules
+
+# This variable can be overwritten to show executed commands
+Q ?= @
+
+# Default output path. This is used when output (writable) directory is different
+# than project directory. You shouldn't be setting it by hand, but it is used in
+# external Makefiles.
+O ?= .
+
+# Load configuration
+-include $(O)/.config.mk
+
+.PHONY: all
+all: $(O)/turris-lcd
+
+ifeq ($(DEBUG),yes)
+CFLAGS += -ggdb -DDEBUG
+endif
+CFLAGS += -Wall
+CFLAGS += -Iliblcd -include $(O)/build/config.h
+
+# Apply CPREFIX
+CXX:=$(CPREFIX)$(CXX)
+
+### Source files list ###########################
+SRC = turris-lcd.cpp
+### End of source files list ####################
+
+CSRC = $(patsubst %,src/%,$(filter %.cpp,$(SRC)))
+
+OBJ = $(patsubst src/%.cpp,$(O)/build/%.o,$(CSRC))
+DEP = $(patsubst src/%.cpp,$(O)/build/%.d,$(CSRC))
+
+.PHONY: help
+help:
+ @echo "General extendable macro language make targets:"
+ @echo " turris-lcd - Build geml executable"
+ @echo " help - Prints this text help."
+ @echo " clean - Cleans builded files"
+ @echo " prune - Same as clean but also removes configuration."
+ @echo "Some enviroment variables to be defined:"
+ @echo " Q - Define emty to show executed commands"
+
+# Cleaning
+.PHONY: clean
+clean::
+ @echo " CLEAN build"
+ $(Q)$(RM) -r $(O)/build
+ $(Q)$(RM) $(O)/.config.mk
+ @echo " CLEAN turris-lcd"
+ $(Q)$(RM) $(O)/turris-lcd
+.PHONY: prune
+prune:: clean
+ @echo " CLEAN configuration"
+ $(Q)$(RM) $(O)/.config $(O)/.config.mk
+ @echo " CLEAN liblcd"
+ $(Q)$(MAKE) -C liblcd clean
+
+## Building targets ##
+ifeq (,$(filter clean prune help \
+ ,$(MAKECMDGOALS))) # Ignore build targets if goal is not building
+
+ifeq ($(DEBUG),yes)
+-include $(DEP) # If developing, use dependencies from source files
+.PHONY: dependency dep
+dependency dep:: $(DEP)
+$(DEP): $(O)/build/%.d: src/%.cpp
+ @mkdir -p "$(@D)"
+ @echo " DEP $@"
+ $(Q)$(CXX) -MM -MG -MT '$*.o $@' $(CFLAGS) $< -MF $@
+endif # DEBUG
+
+$(O)/turris-lcd: $(OBJ) liblcd/libliquidcrystali2c.a
+ @echo " LD $@"
+ $(Q)$(CXX) $(LDFLAGS) $^ -o $@
+
+$(OBJ): $(O)/build/%.o: src/%.cpp $(O)/build/config.h
+ @mkdir -p "$(@D)"
+ @echo " CXX $@"
+ $(Q)$(CXX) -c $(CFLAGS) $< -o $@
+
+$(O)/build/config.h: $(O)/.config
+ @mkdir -p "$(@D)"
+ @echo " CONF $@"
+ $(Q)$(O)/configure --op-h > $@
+
+liblcd/libliquidcrystali2c.a:
+ $(Q)$(MAKE) -C liblcd static
+endif
+
+## Configuation files ##
+$(O)/.config:
+ $(error Please run configure script first)
+
+$(O)/.config.mk: $(O)/.config
+ @echo " CONF $@"
+ $(Q)$(O)/configure --op-makefile > $@
diff --git a/configure b/configure
new file mode 100755
index 0000000..f10ef90
--- /dev/null
+++ b/configure
@@ -0,0 +1,152 @@
+#!/bin/sh
+# vim:ft=sh:ts=4:sw=4:noexpandtab
+set -e
+
+# Configured variables #####################################################
+# Described in following format:
+# name:initial value:type:if exported to makefile:if exported to C header
+# Where type can be just a string (in C in "") or plain. None implies plain.
+CNFS="CBUILD:::F:F
+CHOST:::F:F
+DEBUG:no::T:F
+CPREFIX:::T:F
+CCX:g++::T:F
+CFLAGS:::T:F
+LFLAGS:::T:F"
+############################################################################
+# TODO add options to fine tune installation directories
+
+print_help() {
+ echo "Usage: ./configure [OPTION]..."
+ echo "GEML configuration script. Execute this script to configure project"
+ echo "and prepare it for building."
+ echo
+ echo " --help, -h Give this help list"
+ echo " --debug, -d Enable development features."
+ echo " --release, -r Disable development features for project."
+ echo " --dep-check Force depencency check."
+ echo " --build=CBUILD System compiler prefix on which project is"
+ echo " built."
+ echo " --host=CHOST Compiler prefix for system program and"
+ echo " libraries will run on."
+ echo
+ echo "Environment variables:"
+ echo " CPREFIX Compilation tools prefix."
+ echo " CXX C++ compiler command."
+ echo " CFLAGS C++ compiler flags."
+ echo " LDFLAGS C++ Linker flags."
+}
+
+CONFIG_FILE=.config
+CONFIGURED_FILE=.configured # TODO
+
+# Backup variables from environment
+ENVVARS="CPREFIX CXX CFLAGS LDFLAGS"
+for E in $ENVVARS; do
+ eval "[ -n \"\${$E+y}\" ]" && eval "BACKUP_$E=\$$E"
+done
+
+# Load default configuration if variable not set from environment
+eval `echo "$CNFS" | sed -ne 's/^\([^:]*\):\([^:]*\).*$/\1=\2/p'`
+
+# Load existing configuration
+if [ -f "$CONFIG_FILE" ]; then
+ . ./"$CONFIG_FILE"
+fi
+
+# Functions used for arguments parsing. Handles both --*=* and --* * arguments.
+# First arguments is option name. Second is $1 and third $2
+set_options() {
+ if [[ "$2" == --*=* ]]; then
+ VAL="$(echo "$2" | sed 's/--[^=]*=//')"
+ else
+ VAL="$3"
+ fi
+}
+
+# Requested operation.
+# c - Configure, default configuration behavior
+# m - Prints output for Makefile
+# h - Prints C header file
+OP=c
+
+# Parse arguments
+while [ "$#" -gt 0 ]; do
+ case $1 in
+ -h|--help)
+ print_help
+ exit 0
+ ;;
+ -d|--debug)
+ DEBUG=yes
+ ;;
+ -r|--release)
+ DEBUG=no
+ ;;
+ --op-makefile)
+ OP=m
+ ;;
+ --op-h)
+ OP=h
+ ;;
+ *)
+ echo Warning: Unknown option $1 1>&2
+ ;;
+ esac
+ shift
+done
+
+# Recover from enviroment variables
+for E in $ENVVARS; do
+ eval "[ -n \"\${BACKUP_$E+y}\" ]" && eval "$E=\$BACKUP_$E"
+done
+
+# Basically save configuration to file
+configure() {
+ echo "# linux-lcd configuration file" > "$CONFIG_FILE"
+ echo "# Please do not edit this file directly." >> "$CONFIG_FILE"
+ echo "$CNFS" | while read L; do
+ NAME=`echo "$L" | grep -o -E '^[^:]*'`
+ eval "VALUE=\$$NAME"
+ echo "$NAME=$VALUE" >> "$CONFIG_FILE"
+ done
+ echo "Configuration written to \"$CONFIG_FILE\""
+}
+
+makefile() {
+ echo "$CNFS" | while read L; do
+ if [ `echo $L | awk -F ':' '{ print $4 }'` != "T" ]; then
+ continue
+ fi
+ NAME=`echo "$L" | grep -o -E '^[^:]*'`
+ eval "VALUE=\$$NAME"
+ echo "$NAME := $VALUE"
+ done
+}
+
+cheader() {
+ echo "$CNFS" | while read L; do
+ if [ `echo $L | awk -F ':' '{ print $5 }'` != "T" ]; then
+ continue
+ fi
+ NAME=`echo "$L" | grep -o -E '^[^:]*'`
+ eval "VALUE=\$$NAME"
+ if [ "`echo $L | awk -F ':' '{ print $3 }'`" = "string" ]; then
+ echo "#define $NAME \"$VALUE\""
+ else
+ echo "#define $NAME $VALUE"
+ fi
+ done
+}
+
+case $OP in
+ c)
+ configure
+ ;;
+ m)
+ makefile
+ ;;
+ h)
+ cheader
+ ;;
+esac
diff --git a/liblcd b/liblcd
new file mode 160000
+Subproject 9d2a982638e8b84fa335e29b8fe7fdf17ea8aed
diff --git a/src/turris-lcd.cpp b/src/turris-lcd.cpp
new file mode 100644
index 0000000..d9509e0
--- /dev/null
+++ b/src/turris-lcd.cpp
@@ -0,0 +1,17 @@
+#include <iostream>
+#include <LiquidCrystal_I2C.h>
+
+using namespace std;
+
+int main(int argc, char *argv[]) {
+ // Initialize LCD
+ LiquidCrystal_I2C lcd("/dev/i2c-2", 0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
+ lcd.begin(20, 4);
+
+ lcd.on();
+ lcd.clear();
+
+ lcd.print("Turris Omnia");
+
+ return 0;
+}