Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
### Releases v1.2.0

1. Add STM32_TimerInterrupt Library
  • Loading branch information
khoih-prog authored Nov 13, 2020
1 parent 73e09a0 commit 5f56fa4
Show file tree
Hide file tree
Showing 33 changed files with 549 additions and 33 deletions.
3 changes: 2 additions & 1 deletion src/ESP32TimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src/ESP8266TimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src/ISR_Timer-Impl_Generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src/ISR_Timer_Generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src/NRF52TimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/
/*
nRF52 has 5 Hardware TIMERs: NRF_TIMER0-NRF_TIMER4
Expand Down
3 changes: 2 additions & 1 deletion src/SAMDTimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/
/*
SAMD21
Expand Down
3 changes: 2 additions & 1 deletion src/SAMDUETimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#pragma once
Expand Down
156 changes: 156 additions & 0 deletions src/STM32TimerInterrupt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/****************************************************************************************************************************
STM32TimerInterrupt.h
For STM32 boards
Written by Khoi Hoang
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
unsigned long miliseconds), you just consume only one Hardware timer and avoid conflicting with other cores' tasks.
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Based on SimpleTimer - A timer library for Arduino.
Author: [email protected]
Copyright (c) 2010 OTTOTECNICA Italy
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#pragma once

#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
#endif

#ifndef TIMER_INTERRUPT_DEBUG
#define TIMER_INTERRUPT_DEBUG 0
#endif

class STM32TimerInterrupt;

typedef STM32TimerInterrupt STM32Timer;

typedef void (*timerCallback) (void);


class STM32TimerInterrupt
{
private:
TIM_TypeDef* _timer;
HardwareTimer* _hwTimer = NULL;

timerCallback _callback; // pointer to the callback function
float _frequency; // Timer frequency
uint32_t _timerCount; // count to activate timer

public:

STM32TimerInterrupt(TIM_TypeDef* timer)
{
_timer = timer;

_hwTimer = new HardwareTimer(_timer);

_callback = NULL;
};

~STM32TimerInterrupt()
{
if (_hwTimer)
delete _hwTimer;
}

// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be addes in the future by adding similar functions here or to STM32-hal-timer.c
bool setFrequency(float frequency, timerCallback callback)
{
// select timer frequency is 1MHz for better accuracy. We don't use 16-bit prescaler for now.
// Will use later if very low frequency is needed.
_frequency = 1000000;
_timerCount = (uint32_t) _frequency / frequency;

#if (TIMER_INTERRUPT_DEBUG > 0)
Serial.println("STM32TimerInterrupt: Timer Input Freq (Hz) = " + String(_hwTimer->getTimerClkFreq()) + ", _fre = " + String(_frequency)
+ ", _count = " + String((uint32_t) (_timerCount)));
#endif

_hwTimer->setCount(0, MICROSEC_FORMAT);
_hwTimer->setOverflow(_timerCount, MICROSEC_FORMAT);

_hwTimer->attachInterrupt(callback);
_hwTimer->resume();

return true;
}

// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be addes in the future by adding similar functions here or to STM32-hal-timer.c
bool setInterval(unsigned long interval, timerCallback callback)
{
return setFrequency((float) (1000000.0f / interval), callback);
}

bool attachInterrupt(float frequency, timerCallback callback)
{
return setFrequency(frequency, callback);
}

// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be addes in the future by adding similar functions here or to STM32-hal-timer.c
bool attachInterruptInterval(unsigned long interval, timerCallback callback)
{
return setFrequency( (float) ( 1000000.0f / interval), callback);
}

void detachInterrupt()
{
_hwTimer->detachInterrupt();
}

void disableTimer(void)
{
//_hwTimer->detachInterrupt();
_hwTimer->pause();
}

// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely
void reattachInterrupt()
{
setFrequency(_frequency, _callback);
}

// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely
void enableTimer(void)
{
//setFrequency(_frequency, _callback);
_hwTimer->setCount(0, MICROSEC_FORMAT);
_hwTimer->resume();
}

// Just stop clock source, clear the count
void stopTimer(void)
{
_hwTimer->pause();
_hwTimer->setCount(0, MICROSEC_FORMAT);
}

// Just reconnect clock source, start current count from 0
void restartTimer(void)
{
_hwTimer->setCount(0, MICROSEC_FORMAT);
_hwTimer->resume();
}
}; // class STM32TimerInterrupt
3 changes: 2 additions & 1 deletion src/TeensyTimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src/TimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/


Expand Down
11 changes: 9 additions & 2 deletions src/TimerInterrupt_Generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#pragma once

#define TIMER_INTERRUPT_GENERIC_VERSION "1.1.0"
#define TIMER_INTERRUPT_GENERIC_VERSION "1.2.0"

#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)

Expand Down Expand Up @@ -74,6 +75,12 @@
#define TIMER_INTERRUPT_USING_TEENSY true
#include "TeensyTimerInterrupt.h"

#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )

#define TIMER_INTERRUPT_USING_STM32 true
#include "STM32TimerInterrupt.h"
#else

#error Unsupported Board! Please check your Tools->Board setting.
Expand Down
3 changes: 2 additions & 1 deletion src_cpp/ESP32TimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src_cpp/ESP8266TimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src_cpp/ISR_Timer_Generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#include "ISR_Timer_Generic.h"
Expand Down
3 changes: 2 additions & 1 deletion src_cpp/ISR_Timer_Generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src_cpp/NRF52TimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/
/*
nRF52 has 5 Hardware TIMERs: NRF_TIMER0-NRF_TIMER4
Expand Down
3 changes: 2 additions & 1 deletion src_cpp/SAMDTimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
*****************************************************************************************************************************/
/*
SAMD21
Expand Down
Loading

0 comments on commit 5f56fa4

Please sign in to comment.