diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a65b417 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +lib diff --git a/LowPower.cpp b/LowPower.cpp index 5543bd6..bb1e88c 100644 --- a/LowPower.cpp +++ b/LowPower.cpp @@ -660,10 +660,10 @@ void LowPowerClass::idle(period_t period, adc_t adc, timer5_t timer5, void LowPowerClass::adcNoiseReduction(period_t period, adc_t adc, timer2_t timer2) { - // Temporary clock source variable - unsigned char clockSource = 0; - #if !defined(__AVR_ATmega32U4__) + // Temporary clock source variable + unsigned char clockSource = 0; + if (timer2 == TIMER2_OFF) { if (TCCR2B & CS22) clockSource |= (1 << CS22); @@ -804,10 +804,10 @@ void LowPowerClass::powerDown(period_t period, adc_t adc, bod_t bod) void LowPowerClass::powerSave(period_t period, adc_t adc, bod_t bod, timer2_t timer2) { - // Temporary clock source variable + #if !defined(__AVR_ATmega32U4__) + // Temporary clock source variable unsigned char clockSource = 0; - #if !defined(__AVR_ATmega32U4__) if (timer2 == TIMER2_OFF) { if (TCCR2B & CS22) clockSource |= (1 << CS22); @@ -948,10 +948,10 @@ void LowPowerClass::powerStandby(period_t period, adc_t adc, bod_t bod) void LowPowerClass::powerExtStandby(period_t period, adc_t adc, bod_t bod, timer2_t timer2) { - // Temporary clock source variable - unsigned char clockSource = 0; - #if !defined(__AVR_ATmega32U4__) + // Temporary clock source variable + unsigned char clockSource = 0; + if (timer2 == TIMER2_OFF) { if (TCCR2B & CS22) clockSource |= (1 << CS22); diff --git a/LowPower.h b/LowPower.h index 82f6f44..d52c0b8 100644 --- a/LowPower.h +++ b/LowPower.h @@ -1,8 +1,6 @@ #ifndef LowPower_h #define LowPower_h -#include "Arduino.h" - enum period_t { SLEEP_15MS, diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4de724d --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +# A Makefile that will produce a ./lib//liblowpower.a file per supported MCU. +# Copyright (C) 2018 Pieter du Preez +# +# 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 . + +# NOTE: All libs will be compiled with an 8MHz clock, +# unless CPU_FREQ is set at make-time. +# eg. overriding all mcus to 16Mhz: +# CPU_FREQ=16000000L make clean all + +CPU_FREQ ?= 8000000L + +# NOTE: The atsamd21g18a is not supported by this Makefile. +SUPPORTED_MCUS = \ +atmega168 \ +atmega328p \ +atmega32u4 \ +atmega2560 \ +atmega256rfr2 + +# Default to the standard Linux tool paths. +TOOLCHAIN_PATH ?= /usr/bin + +CC = $(abspath $(TOOLCHAIN_PATH))/avr-gcc +CXX = $(abspath $(TOOLCHAIN_PATH))/avr-g++ +AR = $(abspath $(TOOLCHAIN_PATH))/avr-ar +SIZE = $(abspath $(TOOLCHAIN_PATH))/avr-size + +TARGETS = $(addprefix lib/,$(addsuffix /liblowpower.a,$(SUPPORTED_MCUS))) +SIZES = $(addsuffix _size,$(SUPPORTED_MCUS)) + +# The following line is a work-around for issue #14: +atmega168_DEFINES = -DSLEEP_MODE_EXT_STANDBY=SLEEP_MODE_STANDBY + +all: $(TARGETS) + +%_dir: + mkdir -p lib/$* + +lib/%/liblowpower.a: lib/%/LowPower.o + $(AR) -r $@ $< + $(MAKE) $*_size + +%_size: lib/%/liblowpower.a + $(SIZE) --format=avr --mcu=$* lib/$*/liblowpower.a + +lib/%/LowPower.o: LowPower.cpp LowPower.h %_dir + $(CXX) -c -std=c++11 -pedantic -fverbose-asm -Werror -Os -I$(AVR_INCLUDE) -DF_CPU=$(CPU_FREQ) $($*_DEFINES) -mmcu=$* -o $@ $< + +clean: + rm -rf lib