From 53f331cc122579ebcd374e7f2bf9cf0ba4566b50 Mon Sep 17 00:00:00 2001
From: Stefan Kalscheuer <stefan@stklcode.de>
Date: Fri, 9 Feb 2018 19:38:38 +0100
Subject: [PATCH] Separated Makefile and config; added build instructions

---
 README.md                |  8 +++++
 firmware/Makefile        | 67 ++++++++++++++++------------------------
 firmware/Makefile.config | 43 ++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 41 deletions(-)
 create mode 100644 firmware/Makefile.config

diff --git a/README.md b/README.md
index bc7ae1b..e75a15a 100644
--- a/README.md
+++ b/README.md
@@ -76,6 +76,14 @@ To to so, set the corresponding fields in the _main.h_ file:
 Pinout, button-thresholds and LED-configuration is also present in this file (should be self-explaining).
 
 
+## Build Instructions
+* Required tools: _avr-gcc_, _avr-objcopy_, _avrdude_ (for flashing only), _make_
+* All sources are bundled in the `firmware` directory
+* Check `Makefile.config` for the correct settings, especially tool and port for automated flashing.
+* On first build you might want to set the correct fuse bits, so run `make fuses`
+* Run `make compile info program` for compilation, details about binary, and flashing
+* Check `make help` for all available commands
+
 ## Notes
 
 The Triacs need heatsink.
diff --git a/firmware/Makefile b/firmware/Makefile
index 96675a6..6dd5db4 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -1,58 +1,43 @@
-#	SenseoControl 2.0
-#
-#	File:		Makefile
-#	Author:		Stefan Kalscheuer
-#	Date:		22.04.2013
-#
-# 	Platform:	ATtiny26
-# 				Internal RC-oscillator 8 MHz, CKDIV8 Enabled
+#############################################################################
+#  SenseoControl 2.0                                                        #
+#  Copyright (C) 2013-2018  Stefan Kalscheuer                               #
+#                                                                           #
+#  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 version 3.                                  #
+#                                                                           #
+#  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 <https://www.gnu.org/licenses/>.  #
+#############################################################################
 
+# Include environment config
+include Makefile.config
 
 # Project specific settings
 TARGET = SenseoControl-2.0
 MCU = attiny26
 SRC = main.c
 
-# You probably want to change this to your own programming device
-
-# AVR ISP mkII
-#PGMDEV = avrispmkII
-#PGMOPT = -P usb # Try   -B 10   in case of programming errors
-
-# Pony-STK200
-#PGMDEV = pony-stk200
-#PGMOPT = -E noreset
-
-# STK500
-PGMDEV = stk500v2
-PGMOPT = -P /dev/ttyS0
-
-
-# AVR-GCC and AVRDUDE need to be installed
-CC = avr-gcc
-OBJCOPY = avr-objcopy
-AVRDUDE = avrdude
-REMOVE = rm -f
-
 # Some C flags
-CFLAGS = -Wall -O3
+CFLAGS = -Wall -Wextra -O3
 
 help:
 	@echo
 	@echo "Availiable targets:"
-	@echo "    help - Displays this help"
+	@echo "    help     Displays this help"
 	@echo
-	@echo "    compile - Compiles source code"
-	@echo "    info - Outputs device memory information"
-	@echo "    program - Programs the device"
-	@echo "    clean - Deletes temporary files"
-	@echo "    fuses - Writes fuse settings to device (necessary only once per device)"
+	@echo "    compile  Compiles source code"
+	@echo "    info     Outputs device memory information"
+	@echo "    program  Programs the device"
+	@echo "    clean    Deletes temporary files"
+	@echo "    fuses    Writes fuse settings to device (necessary only once per device)"
 	@echo
-	@echo "    all - Compile, info, program, clean"
-	@echo
-	@echo "IMPORTANT: Device programming may only be possible as super user"
-	@echo
-	@echo "See Makefile for contact information."
+	@echo "    all      Compile, info, program, clean"
 	@echo
 
 all: compile info program clean
diff --git a/firmware/Makefile.config b/firmware/Makefile.config
new file mode 100644
index 0000000..b8cb895
--- /dev/null
+++ b/firmware/Makefile.config
@@ -0,0 +1,43 @@
+#############################################################################
+#  SenseoControl 2.0                                                        #
+#  Copyright (C) 2013-2018  Stefan Kalscheuer                               #
+#                                                                           #
+#  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 version 3.                                  #
+#                                                                           #
+#  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 <https://www.gnu.org/licenses/>.  #
+#############################################################################
+
+#
+# Set toolchain.
+# AVR-GCC and AVRDUDE need to be installed
+#
+CC = avr-gcc
+OBJCOPY = avr-objcopy
+AVRDUDE = avrdude
+REMOVE = rm -f
+
+#
+# You probably want to change this to your own programming device.
+# Some commonly used examples shown below.
+#
+
+# STK500
+PGMDEV = stk500v2
+PGMOPT = -P /dev/ttyS0
+
+
+# AVR ISP mkII
+#PGMDEV = avrispmkII
+#PGMOPT = -P usb # Try   -B 10   in case of programming errors
+
+# Pony-STK200
+#PGMDEV = pony-stk200
+#PGMOPT = -E noreset