From 00732a1d8b7b1d852e4671856ba58d1426f7b0b7 Mon Sep 17 00:00:00 2001 From: Ivan Seidel Date: Mon, 28 Oct 2013 14:33:13 -0200 Subject: [PATCH 1/4] Restructured folders to Arduino 1.5 Library specification https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specifi cation --- DueTimer.cpp => arch/sam/DueTimer.cpp | 0 DueTimer.h => src/DueTimer.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename DueTimer.cpp => arch/sam/DueTimer.cpp (100%) rename DueTimer.h => src/DueTimer.h (100%) diff --git a/DueTimer.cpp b/arch/sam/DueTimer.cpp similarity index 100% rename from DueTimer.cpp rename to arch/sam/DueTimer.cpp diff --git a/DueTimer.h b/src/DueTimer.h similarity index 100% rename from DueTimer.h rename to src/DueTimer.h From c21f28d50fc81e3e35b16f78337bfc144cfcf0e2 Mon Sep 17 00:00:00 2001 From: Ivan Seidel Date: Mon, 28 Oct 2013 15:58:32 -0200 Subject: [PATCH 2/4] Changed files name to be generic --- arch/sam/{DueTimer.cpp => ArduinoTimer.cpp} | 96 ++++++++++++--------- arch/sam/ArduinoTimer.h | 77 +++++++++++++++++ src/BaseTimer.h | 27 ++++++ src/DueTimer.h | 79 ----------------- 4 files changed, 159 insertions(+), 120 deletions(-) rename arch/sam/{DueTimer.cpp => ArduinoTimer.cpp} (69%) create mode 100644 arch/sam/ArduinoTimer.h create mode 100644 src/BaseTimer.h delete mode 100644 src/DueTimer.h diff --git a/arch/sam/DueTimer.cpp b/arch/sam/ArduinoTimer.cpp similarity index 69% rename from arch/sam/DueTimer.cpp rename to arch/sam/ArduinoTimer.cpp index c3ec50d..f325258 100644 --- a/arch/sam/DueTimer.cpp +++ b/arch/sam/ArduinoTimer.cpp @@ -1,6 +1,6 @@ /* - DueTimer.cpp - Implementation of Timers defined on DueTimer.h - For instructions, go to https://github.com/ivanseidel/DueTimer + ArduinoTimer.cpp - Implementation of Timers defined on ArduinoTimer.h + For instructions, go to https://github.com/ivanseidel/ArduinoTimer Created by Ivan Seidel Gomes, March, 2013. Modified by Philipp Klaus, June 2013. @@ -8,9 +8,9 @@ Released into the public domain. */ -#include "DueTimer.h" +#include -const DueTimer::Timer DueTimer::Timers[9] = { +const ArduinoTimer::Timer ArduinoTimer::Timers[9] = { {TC0,0,TC0_IRQn}, {TC0,1,TC1_IRQn}, {TC0,2,TC2_IRQn}, @@ -22,46 +22,46 @@ const DueTimer::Timer DueTimer::Timers[9] = { {TC2,2,TC8_IRQn}, }; -void (*DueTimer::callbacks[9])() = {}; -double DueTimer::_frequency[9] = {-1,-1,-1,-1,-1,-1,-1,-1,-1}; +void (*ArduinoTimer::callbacks[9])() = {}; +double ArduinoTimer::_frequency[9] = {-1,-1,-1,-1,-1,-1,-1,-1,-1}; /* Initializing all timers, so you can use them like this: Timer0.start(); */ -DueTimer Timer(0); - -DueTimer Timer0(0); -DueTimer Timer1(1); -DueTimer Timer2(2); -DueTimer Timer3(3); -DueTimer Timer4(4); -DueTimer Timer5(5); -DueTimer Timer6(6); -DueTimer Timer7(7); -DueTimer Timer8(8); - -DueTimer::DueTimer(int _timer){ +ArduinoTimer Timer(0); + +ArduinoTimer Timer0(0); +ArduinoTimer Timer1(1); +ArduinoTimer Timer2(2); +ArduinoTimer Timer3(3); +ArduinoTimer Timer4(4); +ArduinoTimer Timer5(5); +ArduinoTimer Timer6(6); +ArduinoTimer Timer7(7); +ArduinoTimer Timer8(8); + +ArduinoTimer::ArduinoTimer(int _timer){ /* - The constructor of the class DueTimer + The constructor of the class ArduinoTimer */ timer = _timer; } -DueTimer DueTimer::getAvailable(){ +ArduinoTimer ArduinoTimer::getAvailable(){ /* Return the first timer with no callback set */ for(int i = 0; i < 9; i++){ if(!callbacks[i]) - return DueTimer(i); + return ArduinoTimer(i); } // Default, return Timer0; - return DueTimer(0); + return ArduinoTimer(0); } -DueTimer DueTimer::attachInterrupt(void (*isr)()){ +ArduinoTimer ArduinoTimer::attachInterrupt(void (*isr)()){ /* Links the function passed as argument to the timer of the object */ @@ -71,7 +71,7 @@ DueTimer DueTimer::attachInterrupt(void (*isr)()){ return *this; } -DueTimer DueTimer::detachInterrupt(){ +ArduinoTimer ArduinoTimer::detachInterrupt(){ /* Links the function passed as argument to the timer of the object */ @@ -83,7 +83,7 @@ DueTimer DueTimer::detachInterrupt(){ return *this; } -DueTimer DueTimer::start(long microseconds){ +ArduinoTimer ArduinoTimer::start(long microseconds){ /* Start the timer If a period is set, then sets the period and start the timer @@ -101,7 +101,7 @@ DueTimer DueTimer::start(long microseconds){ return *this; } -DueTimer DueTimer::stop(){ +ArduinoTimer ArduinoTimer::stop(){ /* Stop the timer */ @@ -111,7 +111,7 @@ DueTimer DueTimer::stop(){ return *this; } -uint8_t DueTimer::bestClock(double frequency, uint32_t& retRC){ +uint8_t ArduinoTimer::bestClock(double frequency, uint32_t& retRC){ /* Pick the best Clock, thanks to Ogle Basil Hall! @@ -151,7 +151,7 @@ uint8_t DueTimer::bestClock(double frequency, uint32_t& retRC){ } -DueTimer DueTimer::setFrequency(double frequency){ +ArduinoTimer ArduinoTimer::setFrequency(double frequency){ /* Set the timer frequency (in Hz) */ @@ -194,7 +194,7 @@ DueTimer DueTimer::setFrequency(double frequency){ return *this; } -DueTimer DueTimer::setPeriod(long microseconds){ +ArduinoTimer ArduinoTimer::setPeriod(long microseconds){ /* Set the period of the timer (in microseconds) */ @@ -205,7 +205,7 @@ DueTimer DueTimer::setPeriod(long microseconds){ return *this; } -double DueTimer::getFrequency(){ +double ArduinoTimer::getFrequency(){ /* Get current time frequency */ @@ -213,7 +213,7 @@ double DueTimer::getFrequency(){ return _frequency[timer]; } -long DueTimer::getPeriod(){ +long ArduinoTimer::getPeriod(){ /* Get current time period */ @@ -228,37 +228,51 @@ long DueTimer::getPeriod(){ */ void TC0_Handler(){ TC_GetStatus(TC0, 0); - DueTimer::callbacks[0](); + ArduinoTimer::callbacks[0](); } void TC1_Handler(){ TC_GetStatus(TC0, 1); - DueTimer::callbacks[1](); + ArduinoTimer::callbacks[1](); } void TC2_Handler(){ TC_GetStatus(TC0, 2); - DueTimer::callbacks[2](); + ArduinoTimer::callbacks[2](); } void TC3_Handler(){ TC_GetStatus(TC1, 0); - DueTimer::callbacks[3](); + ArduinoTimer::callbacks[3](); } void TC4_Handler(){ TC_GetStatus(TC1, 1); - DueTimer::callbacks[4](); + ArduinoTimer::callbacks[4](); } void TC5_Handler(){ TC_GetStatus(TC1, 2); - DueTimer::callbacks[5](); + ArduinoTimer::callbacks[5](); } void TC6_Handler(){ TC_GetStatus(TC2, 0); - DueTimer::callbacks[6](); + ArduinoTimer::callbacks[6](); } void TC7_Handler(){ TC_GetStatus(TC2, 1); - DueTimer::callbacks[7](); + ArduinoTimer::callbacks[7](); } void TC8_Handler(){ TC_GetStatus(TC2, 2); - DueTimer::callbacks[8](); + ArduinoTimer::callbacks[8](); } + +// Just to call Timer.getAvailable instead of Timer::getAvailable() : +extern ArduinoTimer Timer; + +extern ArduinoTimer Timer0; +extern ArduinoTimer Timer1; +extern ArduinoTimer Timer2; +extern ArduinoTimer Timer3; +extern ArduinoTimer Timer4; +extern ArduinoTimer Timer5; +extern ArduinoTimer Timer6; +extern ArduinoTimer Timer7; +extern ArduinoTimer Timer8; + diff --git a/arch/sam/ArduinoTimer.h b/arch/sam/ArduinoTimer.h new file mode 100644 index 0000000..80946df --- /dev/null +++ b/arch/sam/ArduinoTimer.h @@ -0,0 +1,77 @@ +/* + ArduinoTimer.h - ArduinoTimer header file, definition of methods and attributes... + For instructions, go to https://github.com/ivanseidel/ArduinoTimer + + Created by Ivan Seidel Gomes, October, 2013. + Modified by Philipp Klaus, June 2013. + Released into the public domain. +*/ + +#ifndef ArduinoTimer_h +#define ArduinoTimer_h + +#include "Arduino.h" + +#include + +class ArduinoTimer +{ +protected: + int timerId; + + // Stores the object timer frequency + // (allows to access current timer period and frequency): + static double _frequency[9]; + + // Picks the best clock to lower the error + static uint8_t bestClock(double frequency, uint32_t& retRC); + +public: + struct Timer + { + Tc *tc; + uint32_t channel; + IRQn_Type irq; + }; + + static ArduinoTimer getAvailable(); + + // Store timer configuration (static, as it's fix for every object) + static const Timer Timers[9]; + + // Needs to be public, because the handlers are outside class: + static void (*callbacks[9])(); + + ArduinoTimer(int _timerId); + + virtual BaseTimer attachInterrupt(void (*isr)()); + virtual BaseTimer detachInterrupt(); + + virtual BaseTimer start(long microseconds = -1); + virtual BaseTimer stop(); + + virtual BaseTimer setFrequency(double frequency); + virtual double getFrequency(); + + virtual BaseTimer setPeriod(long microseconds); + virtual long getPeriod(); +}; + +// Just to call Timer.getAvailable instead of Timer::getAvailable() : +extern ArduinoTimer Timer; + +extern ArduinoTimer Timer0; +extern ArduinoTimer Timer1; +extern ArduinoTimer Timer2; +extern ArduinoTimer Timer3; +extern ArduinoTimer Timer4; +extern ArduinoTimer Timer5; +extern ArduinoTimer Timer6; +extern ArduinoTimer Timer7; +extern ArduinoTimer Timer8; + +#endif + +#else + #pragma message("Ops! Trying to include ArduinoTimer on another device?") +#endif diff --git a/src/BaseTimer.h b/src/BaseTimer.h new file mode 100644 index 0000000..a32e91b --- /dev/null +++ b/src/BaseTimer.h @@ -0,0 +1,27 @@ +/* + BaseTimer.h - Basic Timer interface + For instructions, go to https://github.com/ivanseidel/???? + + Created by Ivan Seidel Gomes, October, 2013. + Released into the public domain. +*/ + +#ifndef BaseTimer_h +#define BaseTimer_h + +class BaseTimer{ +protected: + virtual BaseTimer attachInterrupt(void (*isr)()); + virtual BaseTimer detachInterrupt(); + + virtual BaseTimer start(long microseconds = -1); + virtual BaseTimer stop(); + + virtual BaseTimer setFrequency(double frequency); + virtual double getFrequency(); + + virtual BaseTimer setPeriod(long microseconds); + virtual long getPeriod(); +}; + +#endif \ No newline at end of file diff --git a/src/DueTimer.h b/src/DueTimer.h deleted file mode 100644 index 03cb12d..0000000 --- a/src/DueTimer.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - DueTimer.h - DueTimer header file, definition of methods and attributes... - For instructions, go to https://github.com/ivanseidel/DueTimer - - Created by Ivan Seidel Gomes, March, 2013. - Modified by Philipp Klaus, June 2013. - Released into the public domain. -*/ - -#ifdef __arm__ - -#ifndef DueTimer_h -#define DueTimer_h - -#include "Arduino.h" - -#include - -class DueTimer -{ -protected: - - // Represents the timer id (index for the array of Timer structs) - int timer; - - // Stores the object timer frequency - // (allows to access current timer period and frequency): - static double _frequency[9]; - - // Picks the best clock to lower the error - static uint8_t bestClock(double frequency, uint32_t& retRC); - -public: - struct Timer - { - Tc *tc; - uint32_t channel; - IRQn_Type irq; - }; - - static DueTimer getAvailable(); - - // Store timer configuration (static, as it's fix for every object) - static const Timer Timers[9]; - - // Needs to be public, because the handlers are outside class: - static void (*callbacks[9])(); - - DueTimer(int _timer); - DueTimer attachInterrupt(void (*isr)()); - DueTimer detachInterrupt(); - DueTimer start(long microseconds = -1); - DueTimer stop(); - DueTimer setFrequency(double frequency); - DueTimer setPeriod(long microseconds); - - - double getFrequency(); - long getPeriod(); -}; - -// Just to call Timer.getAvailable instead of Timer::getAvailable() : -extern DueTimer Timer; - -extern DueTimer Timer0; -extern DueTimer Timer1; -extern DueTimer Timer2; -extern DueTimer Timer3; -extern DueTimer Timer4; -extern DueTimer Timer5; -extern DueTimer Timer6; -extern DueTimer Timer7; -extern DueTimer Timer8; - -#endif - -#else - #pragma message("Ops! Trying to include DueTimer on another device?") -#endif From e6f50f24fcabe789ef1bc873f8292df6229648c9 Mon Sep 17 00:00:00 2001 From: Ivan Seidel Date: Mon, 28 Oct 2013 16:35:38 -0200 Subject: [PATCH 3/4] ArchTimer is the included header for the selected archtecture --- arch/sam/ArchTimer.h | 38 ++++++++ arch/sam/ArduinoTimer.cpp | 196 ++++++++++++++++++++------------------ arch/sam/ArduinoTimer.h | 77 --------------- src/ArduinoTimer.h | 44 +++++++++ 4 files changed, 183 insertions(+), 172 deletions(-) create mode 100644 arch/sam/ArchTimer.h delete mode 100644 arch/sam/ArduinoTimer.h create mode 100644 src/ArduinoTimer.h diff --git a/arch/sam/ArchTimer.h b/arch/sam/ArchTimer.h new file mode 100644 index 0000000..85945e3 --- /dev/null +++ b/arch/sam/ArchTimer.h @@ -0,0 +1,38 @@ +/* + ArchTimer.h - SAM Only definitions + For instructions, go to https://github.com/ivanseidel/ArduinoTimer + + Created by Ivan Seidel Gomes, October, 2013. + Released into the public domain. +*/ + +/** + * SAM Only definitions + * -------------------- + */ + +/* + Frequencyes for the timers are saved here +*/ +double ArduinoTimer_frequency[9]; + +/* + Picks the best clock to lower the error +*/ +uint8_t ArduinoTimer_bestClock(double frequency, uint32_t& retRC); + +/* + Represents a SAM Timer configuration +*/ +struct ArduinoTimer_Timer_t +{ + Tc *tc; + uint32_t channel; + IRQn_Type irq; +}; + +// Store timer configuration (static, as it's fix for every object) +const Timer ArduinoTimer_Timers[9]; + +// Needs to be public, because the handlers are outside class: +void (*ArduinoTimer_callbacks[9])(); diff --git a/arch/sam/ArduinoTimer.cpp b/arch/sam/ArduinoTimer.cpp index f325258..f0f54dc 100644 --- a/arch/sam/ArduinoTimer.cpp +++ b/arch/sam/ArduinoTimer.cpp @@ -1,5 +1,6 @@ /* ArduinoTimer.cpp - Implementation of Timers defined on ArduinoTimer.h + This is the class used by ArduinoDue For instructions, go to https://github.com/ivanseidel/ArduinoTimer Created by Ivan Seidel Gomes, March, 2013. @@ -10,7 +11,7 @@ #include -const ArduinoTimer::Timer ArduinoTimer::Timers[9] = { +const ArduinoTimer_Timer_t ArduinoTimer_Timers[9] = { {TC0,0,TC0_IRQn}, {TC0,1,TC1_IRQn}, {TC0,2,TC2_IRQn}, @@ -22,8 +23,8 @@ const ArduinoTimer::Timer ArduinoTimer::Timers[9] = { {TC2,2,TC8_IRQn}, }; -void (*ArduinoTimer::callbacks[9])() = {}; -double ArduinoTimer::_frequency[9] = {-1,-1,-1,-1,-1,-1,-1,-1,-1}; +void (*ArduinoTimer_callbacks[9])() = {}; +double ArduinoTimer_frequency[9] = {-1,-1,-1,-1,-1,-1,-1,-1,-1}; /* Initializing all timers, so you can use them like this: Timer0.start(); @@ -40,130 +41,131 @@ ArduinoTimer Timer6(6); ArduinoTimer Timer7(7); ArduinoTimer Timer8(8); -ArduinoTimer::ArduinoTimer(int _timer){ - /* - The constructor of the class ArduinoTimer - */ +/* + Pick the best Clock, thanks to Ogle Basil Hall! + + Timer Definition + TIMER_CLOCK1 MCK / 2 + TIMER_CLOCK2 MCK / 8 + TIMER_CLOCK3 MCK / 32 + TIMER_CLOCK4 MCK /128 +*/ +uint8_t ArduinoTimer_bestClock(double frequency, uint32_t& retRC){ + struct { + uint8_t flag; + uint8_t divisor; + } clockConfig[] = { + { TC_CMR_TCCLKS_TIMER_CLOCK1, 2 }, + { TC_CMR_TCCLKS_TIMER_CLOCK2, 8 }, + { TC_CMR_TCCLKS_TIMER_CLOCK3, 32 }, + { TC_CMR_TCCLKS_TIMER_CLOCK4, 128 } + }; + float ticks; + float error; + int clkId = 3; + int bestClock = 3; + float bestError = 1.0; + do + { + ticks = (float) VARIANT_MCK / frequency / (float) clockConfig[clkId].divisor; + error = abs(ticks - round(ticks)); + if (abs(error) < bestError) + { + bestClock = clkId; + bestError = error; + } + } while (clkId-- > 0); + ticks = (float) VARIANT_MCK / frequency / (float) clockConfig[bestClock].divisor; + retRC = (uint32_t) round(ticks); + return clockConfig[bestClock].flag; +} - timer = _timer; +/* + The constructor of the class ArduinoTimer +*/ +ArduinoTimer::ArduinoTimer(int _timerId){ + + timerId = _timerId; } +/* + Return the first timer with no callback set +*/ ArduinoTimer ArduinoTimer::getAvailable(){ - /* - Return the first timer with no callback set - */ for(int i = 0; i < 9; i++){ - if(!callbacks[i]) + if(!ArduinoTimer_callbacks[i]) return ArduinoTimer(i); } // Default, return Timer0; return ArduinoTimer(0); } +/* + Links the function passed as argument to the timer of the object +*/ ArduinoTimer ArduinoTimer::attachInterrupt(void (*isr)()){ - /* - Links the function passed as argument to the timer of the object - */ - callbacks[timer] = isr; + ArduinoTimer_callbacks[timerId] = isr; return *this; } +/* + Links the function passed as argument to the timer of the object +*/ ArduinoTimer ArduinoTimer::detachInterrupt(){ - /* - Links the function passed as argument to the timer of the object - */ stop(); // Stop the currently running timer - callbacks[timer] = NULL; + ArduinoTimer_callbacks[timerId] = NULL; return *this; } +/* + Start the timer + If a period is set, then sets the period and start the timer +*/ ArduinoTimer ArduinoTimer::start(long microseconds){ - /* - Start the timer - If a period is set, then sets the period and start the timer - */ if(microseconds > 0) setPeriod(microseconds); - if(_frequency[timer] <= 0) + if(_frequency[timerId] <= 0) setFrequency(1); - NVIC_ClearPendingIRQ(Timers[timer].irq); - NVIC_EnableIRQ(Timers[timer].irq); + NVIC_ClearPendingIRQ(Timers[timerId].irq); + NVIC_EnableIRQ(Timers[timerId].irq); return *this; } +/* + Stop the timer +*/ ArduinoTimer ArduinoTimer::stop(){ - /* - Stop the timer - */ - NVIC_DisableIRQ(Timers[timer].irq); + NVIC_DisableIRQ(Timers[timerId].irq); return *this; } -uint8_t ArduinoTimer::bestClock(double frequency, uint32_t& retRC){ - /* - Pick the best Clock, thanks to Ogle Basil Hall! - - Timer Definition - TIMER_CLOCK1 MCK / 2 - TIMER_CLOCK2 MCK / 8 - TIMER_CLOCK3 MCK / 32 - TIMER_CLOCK4 MCK /128 - */ - struct { - uint8_t flag; - uint8_t divisor; - } clockConfig[] = { - { TC_CMR_TCCLKS_TIMER_CLOCK1, 2 }, - { TC_CMR_TCCLKS_TIMER_CLOCK2, 8 }, - { TC_CMR_TCCLKS_TIMER_CLOCK3, 32 }, - { TC_CMR_TCCLKS_TIMER_CLOCK4, 128 } - }; - float ticks; - float error; - int clkId = 3; - int bestClock = 3; - float bestError = 1.0; - do - { - ticks = (float) VARIANT_MCK / frequency / (float) clockConfig[clkId].divisor; - error = abs(ticks - round(ticks)); - if (abs(error) < bestError) - { - bestClock = clkId; - bestError = error; - } - } while (clkId-- > 0); - ticks = (float) VARIANT_MCK / frequency / (float) clockConfig[bestClock].divisor; - retRC = (uint32_t) round(ticks); - return clockConfig[bestClock].flag; -} +/* + Set the timer frequency (in Hz) +*/ ArduinoTimer ArduinoTimer::setFrequency(double frequency){ - /* - Set the timer frequency (in Hz) - */ // Prevent negative frequencies if(frequency <= 0) { frequency = 1; } // Remember the frequency - _frequency[timer] = frequency; + _frequency[timerId] = frequency; // Get current timer configuration - Timer t = Timers[timer]; + Timer t = Timers[timerId]; uint32_t rc = 0; uint8_t clock; @@ -194,10 +196,10 @@ ArduinoTimer ArduinoTimer::setFrequency(double frequency){ return *this; } +/* + Set the period of the timer (in microseconds) +*/ ArduinoTimer ArduinoTimer::setPeriod(long microseconds){ - /* - Set the period of the timer (in microseconds) - */ // Convert period in microseconds to frequency in Hz double frequency = 1000000.0 / microseconds; @@ -205,65 +207,69 @@ ArduinoTimer ArduinoTimer::setPeriod(long microseconds){ return *this; } +/* + Get current time frequency +*/ double ArduinoTimer::getFrequency(){ - /* - Get current time frequency - */ - return _frequency[timer]; + return _frequency[timerId]; } +/* + Get current time period +*/ long ArduinoTimer::getPeriod(){ - /* - Get current time period - */ return 1.0/getFrequency()*1000000; } - /* Implementation of the timer callbacks defined in arduino-1.5.2/hardware/arduino/sam/system/CMSIS/Device/ATMEL/sam3xa/include/sam3x8e.h */ void TC0_Handler(){ TC_GetStatus(TC0, 0); - ArduinoTimer::callbacks[0](); + ArduinoTimer_callbacks[0](); } void TC1_Handler(){ TC_GetStatus(TC0, 1); - ArduinoTimer::callbacks[1](); + ArduinoTimer_callbacks[1](); } void TC2_Handler(){ TC_GetStatus(TC0, 2); - ArduinoTimer::callbacks[2](); + ArduinoTimer_callbacks[2](); } void TC3_Handler(){ TC_GetStatus(TC1, 0); - ArduinoTimer::callbacks[3](); + ArduinoTimer_callbacks[3](); } void TC4_Handler(){ TC_GetStatus(TC1, 1); - ArduinoTimer::callbacks[4](); + ArduinoTimer_callbacks[4](); } void TC5_Handler(){ TC_GetStatus(TC1, 2); - ArduinoTimer::callbacks[5](); + ArduinoTimer_callbacks[5](); } void TC6_Handler(){ TC_GetStatus(TC2, 0); - ArduinoTimer::callbacks[6](); + ArduinoTimer_callbacks[6](); } void TC7_Handler(){ TC_GetStatus(TC2, 1); - ArduinoTimer::callbacks[7](); + ArduinoTimer_callbacks[7](); } void TC8_Handler(){ TC_GetStatus(TC2, 2); - ArduinoTimer::callbacks[8](); + ArduinoTimer_callbacks[8](); } -// Just to call Timer.getAvailable instead of Timer::getAvailable() : +/* + Allows the use of methods like this: + Timer.getAvailable(); + instead of + Timer::getAvailable(); +*/ extern ArduinoTimer Timer; extern ArduinoTimer Timer0; diff --git a/arch/sam/ArduinoTimer.h b/arch/sam/ArduinoTimer.h deleted file mode 100644 index 80946df..0000000 --- a/arch/sam/ArduinoTimer.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - ArduinoTimer.h - ArduinoTimer header file, definition of methods and attributes... - For instructions, go to https://github.com/ivanseidel/ArduinoTimer - - Created by Ivan Seidel Gomes, October, 2013. - Modified by Philipp Klaus, June 2013. - Released into the public domain. -*/ - -#ifndef ArduinoTimer_h -#define ArduinoTimer_h - -#include "Arduino.h" - -#include - -class ArduinoTimer -{ -protected: - int timerId; - - // Stores the object timer frequency - // (allows to access current timer period and frequency): - static double _frequency[9]; - - // Picks the best clock to lower the error - static uint8_t bestClock(double frequency, uint32_t& retRC); - -public: - struct Timer - { - Tc *tc; - uint32_t channel; - IRQn_Type irq; - }; - - static ArduinoTimer getAvailable(); - - // Store timer configuration (static, as it's fix for every object) - static const Timer Timers[9]; - - // Needs to be public, because the handlers are outside class: - static void (*callbacks[9])(); - - ArduinoTimer(int _timerId); - - virtual BaseTimer attachInterrupt(void (*isr)()); - virtual BaseTimer detachInterrupt(); - - virtual BaseTimer start(long microseconds = -1); - virtual BaseTimer stop(); - - virtual BaseTimer setFrequency(double frequency); - virtual double getFrequency(); - - virtual BaseTimer setPeriod(long microseconds); - virtual long getPeriod(); -}; - -// Just to call Timer.getAvailable instead of Timer::getAvailable() : -extern ArduinoTimer Timer; - -extern ArduinoTimer Timer0; -extern ArduinoTimer Timer1; -extern ArduinoTimer Timer2; -extern ArduinoTimer Timer3; -extern ArduinoTimer Timer4; -extern ArduinoTimer Timer5; -extern ArduinoTimer Timer6; -extern ArduinoTimer Timer7; -extern ArduinoTimer Timer8; - -#endif - -#else - #pragma message("Ops! Trying to include ArduinoTimer on another device?") -#endif diff --git a/src/ArduinoTimer.h b/src/ArduinoTimer.h new file mode 100644 index 0000000..ad79aed --- /dev/null +++ b/src/ArduinoTimer.h @@ -0,0 +1,44 @@ +/* + ArduinoTimer.h - ArduinoTimer header file, definition of methods and attributes + For instructions, go to https://github.com/ivanseidel/ArduinoTimer + + Created by Ivan Seidel Gomes, October, 2013. + Modified by Philipp Klaus, June 2013. + Released into the public domain. +*/ + +#ifndef ArduinoTimer_h +#define ArduinoTimer_h + +#include + +/* + Includes specific archtecture timer definitions +*/ +#include + +class ArduinoTimer: public BaseTimer +{ +protected: + int timerId; + +public: + + static virtual ArduinoTimer getAvailable(); + + ArduinoTimer(int _timerId); + + virtual ArduinoTimer attachInterrupt(void (*isr)()); + virtual ArduinoTimer detachInterrupt(); + + virtual ArduinoTimer start(long microseconds = -1); + virtual ArduinoTimer stop(); + + virtual ArduinoTimer setFrequency(double frequency); + virtual double getFrequency(); + + virtual ArduinoTimer setPeriod(long microseconds); + virtual long getPeriod(); +}; + +#endif From dfcb844cee25ba88917fb7f45202501c8a12f423 Mon Sep 17 00:00:00 2001 From: Ivan Seidel Date: Mon, 28 Oct 2013 16:42:52 -0200 Subject: [PATCH 4/4] initial properties set --- examples/AvaliableTimer/AvaliableTimer.pde | 2 +- library.properties | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 library.properties diff --git a/examples/AvaliableTimer/AvaliableTimer.pde b/examples/AvaliableTimer/AvaliableTimer.pde index 332698e..b5ed827 100644 --- a/examples/AvaliableTimer/AvaliableTimer.pde +++ b/examples/AvaliableTimer/AvaliableTimer.pde @@ -1,4 +1,4 @@ -#include +#include void playVideogame(){ Serial.println("[- ] I'm playing Videogame!"); diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..a590f82 --- /dev/null +++ b/library.properties @@ -0,0 +1,10 @@ +name=ArduinoTimer +author=ivanseidel +email=Ivan Seidel +sentence=A Generic library to integrate Timer capability +paragraph=....... +url=http://github.com/ivanseidel +architectures=sam +version=1.0 +dependencies= +core-dependencies=arduino (>=1.5.0) \ No newline at end of file