Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Makefile that will produce ./lib/<MCU>/liblowpower.a files. #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
16 changes: 8 additions & 8 deletions LowPower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions LowPower.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef LowPower_h
#define LowPower_h

#include "Arduino.h"

enum period_t
{
SLEEP_15MS,
Expand Down
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# A Makefile that will produce a ./lib/<MCU>/liblowpower.a file per supported MCU.
# Copyright (C) 2018 Pieter du Preez <[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 <https://www.gnu.org/licenses/>.

# 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