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

Commit 5f56fa4

Browse files
authored
v1.2.0
### Releases v1.2.0 1. Add STM32_TimerInterrupt Library
1 parent 73e09a0 commit 5f56fa4

33 files changed

+549
-33
lines changed

src/ESP32TimerInterrupt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2626
Licensed under MIT license
2727
28-
Version: 1.1.0
28+
Version: 1.2.0
2929
3030
Version Modified By Date Comments
3131
------- ----------- ---------- -----------
3232
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
33+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
3334
*****************************************************************************************************************************/
3435

3536
#pragma once

src/ESP8266TimerInterrupt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2525
Licensed under MIT license
2626
27-
Version: 1.1.0
27+
Version: 1.2.0
2828
2929
Version Modified By Date Comments
3030
------- ----------- ---------- -----------
3131
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
32+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
3233
*****************************************************************************************************************************/
3334

3435
#pragma once

src/ISR_Timer-Impl_Generic.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2020
Licensed under MIT license
2121
22-
Version: 1.1.0
22+
Version: 1.2.0
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
2728
*****************************************************************************************************************************/
2829

2930
#pragma once

src/ISR_Timer_Generic.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2020
Licensed under MIT license
2121
22-
Version: 1.1.0
22+
Version: 1.2.0
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
2728
*****************************************************************************************************************************/
2829

2930
#pragma once

src/NRF52TimerInterrupt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2020
Licensed under MIT license
2121
22-
Version: 1.1.0
22+
Version: 1.2.0
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
2728
*****************************************************************************************************************************/
2829
/*
2930
nRF52 has 5 Hardware TIMERs: NRF_TIMER0-NRF_TIMER4

src/SAMDTimerInterrupt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2020
Licensed under MIT license
2121
22-
Version: 1.1.0
22+
Version: 1.2.0
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
2728
*****************************************************************************************************************************/
2829
/*
2930
SAMD21

src/SAMDUETimerInterrupt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2020
Licensed under MIT license
2121
22-
Version: 1.1.0
22+
Version: 1.2.0
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
2728
*****************************************************************************************************************************/
2829

2930
#pragma once

src/STM32TimerInterrupt.h

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/****************************************************************************************************************************
2+
STM32TimerInterrupt.h
3+
For STM32 boards
4+
Written by Khoi Hoang
5+
6+
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
7+
unsigned long miliseconds), you just consume only one Hardware timer and avoid conflicting with other cores' tasks.
8+
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
9+
Therefore, their executions are not blocked by bad-behaving functions / tasks.
10+
This important feature is absolutely necessary for mission-critical tasks.
11+
12+
Based on SimpleTimer - A timer library for Arduino.
13+
14+
Copyright (c) 2010 OTTOTECNICA Italy
15+
16+
Based on BlynkTimer.h
17+
Author: Volodymyr Shymanskyy
18+
19+
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
20+
Licensed under MIT license
21+
22+
Version: 1.2.0
23+
24+
Version Modified By Date Comments
25+
------- ----------- ---------- -----------
26+
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
28+
*****************************************************************************************************************************/
29+
30+
#pragma once
31+
32+
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
33+
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
34+
defined(STM32WB) || defined(STM32MP1) )
35+
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
36+
#endif
37+
38+
#ifndef TIMER_INTERRUPT_DEBUG
39+
#define TIMER_INTERRUPT_DEBUG 0
40+
#endif
41+
42+
class STM32TimerInterrupt;
43+
44+
typedef STM32TimerInterrupt STM32Timer;
45+
46+
typedef void (*timerCallback) (void);
47+
48+
49+
class STM32TimerInterrupt
50+
{
51+
private:
52+
TIM_TypeDef* _timer;
53+
HardwareTimer* _hwTimer = NULL;
54+
55+
timerCallback _callback; // pointer to the callback function
56+
float _frequency; // Timer frequency
57+
uint32_t _timerCount; // count to activate timer
58+
59+
public:
60+
61+
STM32TimerInterrupt(TIM_TypeDef* timer)
62+
{
63+
_timer = timer;
64+
65+
_hwTimer = new HardwareTimer(_timer);
66+
67+
_callback = NULL;
68+
};
69+
70+
~STM32TimerInterrupt()
71+
{
72+
if (_hwTimer)
73+
delete _hwTimer;
74+
}
75+
76+
// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
77+
// No params and duration now. To be addes in the future by adding similar functions here or to STM32-hal-timer.c
78+
bool setFrequency(float frequency, timerCallback callback)
79+
{
80+
// select timer frequency is 1MHz for better accuracy. We don't use 16-bit prescaler for now.
81+
// Will use later if very low frequency is needed.
82+
_frequency = 1000000;
83+
_timerCount = (uint32_t) _frequency / frequency;
84+
85+
#if (TIMER_INTERRUPT_DEBUG > 0)
86+
Serial.println("STM32TimerInterrupt: Timer Input Freq (Hz) = " + String(_hwTimer->getTimerClkFreq()) + ", _fre = " + String(_frequency)
87+
+ ", _count = " + String((uint32_t) (_timerCount)));
88+
#endif
89+
90+
_hwTimer->setCount(0, MICROSEC_FORMAT);
91+
_hwTimer->setOverflow(_timerCount, MICROSEC_FORMAT);
92+
93+
_hwTimer->attachInterrupt(callback);
94+
_hwTimer->resume();
95+
96+
return true;
97+
}
98+
99+
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
100+
// No params and duration now. To be addes in the future by adding similar functions here or to STM32-hal-timer.c
101+
bool setInterval(unsigned long interval, timerCallback callback)
102+
{
103+
return setFrequency((float) (1000000.0f / interval), callback);
104+
}
105+
106+
bool attachInterrupt(float frequency, timerCallback callback)
107+
{
108+
return setFrequency(frequency, callback);
109+
}
110+
111+
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
112+
// No params and duration now. To be addes in the future by adding similar functions here or to STM32-hal-timer.c
113+
bool attachInterruptInterval(unsigned long interval, timerCallback callback)
114+
{
115+
return setFrequency( (float) ( 1000000.0f / interval), callback);
116+
}
117+
118+
void detachInterrupt()
119+
{
120+
_hwTimer->detachInterrupt();
121+
}
122+
123+
void disableTimer(void)
124+
{
125+
//_hwTimer->detachInterrupt();
126+
_hwTimer->pause();
127+
}
128+
129+
// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely
130+
void reattachInterrupt()
131+
{
132+
setFrequency(_frequency, _callback);
133+
}
134+
135+
// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely
136+
void enableTimer(void)
137+
{
138+
//setFrequency(_frequency, _callback);
139+
_hwTimer->setCount(0, MICROSEC_FORMAT);
140+
_hwTimer->resume();
141+
}
142+
143+
// Just stop clock source, clear the count
144+
void stopTimer(void)
145+
{
146+
_hwTimer->pause();
147+
_hwTimer->setCount(0, MICROSEC_FORMAT);
148+
}
149+
150+
// Just reconnect clock source, start current count from 0
151+
void restartTimer(void)
152+
{
153+
_hwTimer->setCount(0, MICROSEC_FORMAT);
154+
_hwTimer->resume();
155+
}
156+
}; // class STM32TimerInterrupt

src/TeensyTimerInterrupt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2020
Licensed under MIT license
2121
22-
Version: 1.1.0
22+
Version: 1.2.0
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
2728
*****************************************************************************************************************************/
2829

2930
#pragma once

src/TimerInterrupt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2727
Licensed under MIT license
2828
29-
Version: 1.1.0
29+
Version: 1.2.0
3030
3131
Version Modified By Date Comments
3232
------- ----------- ---------- -----------
3333
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
34+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
3435
*****************************************************************************************************************************/
3536

3637

src/TimerInterrupt_Generic.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2020
Licensed under MIT license
2121
22-
Version: 1.1.0
22+
Version: 1.2.0
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
2728
*****************************************************************************************************************************/
2829

2930
#pragma once
3031

31-
#define TIMER_INTERRUPT_GENERIC_VERSION "1.1.0"
32+
#define TIMER_INTERRUPT_GENERIC_VERSION "1.2.0"
3233

3334
#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__)
3435

@@ -74,6 +75,12 @@
7475
#define TIMER_INTERRUPT_USING_TEENSY true
7576
#include "TeensyTimerInterrupt.h"
7677

78+
#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
79+
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
80+
defined(STM32WB) || defined(STM32MP1) )
81+
82+
#define TIMER_INTERRUPT_USING_STM32 true
83+
#include "STM32TimerInterrupt.h"
7784
#else
7885

7986
#error Unsupported Board! Please check your Tools->Board setting.

src_cpp/ESP32TimerInterrupt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2626
Licensed under MIT license
2727
28-
Version: 1.1.0
28+
Version: 1.2.0
2929
3030
Version Modified By Date Comments
3131
------- ----------- ---------- -----------
3232
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
33+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
3334
*****************************************************************************************************************************/
3435

3536
#pragma once

src_cpp/ESP8266TimerInterrupt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2525
Licensed under MIT license
2626
27-
Version: 1.1.0
27+
Version: 1.2.0
2828
2929
Version Modified By Date Comments
3030
------- ----------- ---------- -----------
3131
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
32+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
3233
*****************************************************************************************************************************/
3334

3435
#pragma once

src_cpp/ISR_Timer_Generic.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2020
Licensed under MIT license
2121
22-
Version: 1.1.0
22+
Version: 1.2.0
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
2728
*****************************************************************************************************************************/
2829

2930
#include "ISR_Timer_Generic.h"

src_cpp/ISR_Timer_Generic.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2020
Licensed under MIT license
2121
22-
Version: 1.1.0
22+
Version: 1.2.0
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
2728
*****************************************************************************************************************************/
2829

2930
#pragma once

src_cpp/NRF52TimerInterrupt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2020
Licensed under MIT license
2121
22-
Version: 1.1.0
22+
Version: 1.2.0
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
2728
*****************************************************************************************************************************/
2829
/*
2930
nRF52 has 5 Hardware TIMERs: NRF_TIMER0-NRF_TIMER4

src_cpp/SAMDTimerInterrupt.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt_Generic
2020
Licensed under MIT license
2121
22-
Version: 1.1.0
22+
Version: 1.2.0
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.1.0 K Hoang 10/11/2020 Initial Super-Library coding to merge all TimerInterrupt Libraries
27+
1.2.0 K Hoang 12/11/2020 Add STM32_TimerInterrupt Library
2728
*****************************************************************************************************************************/
2829
/*
2930
SAMD21

0 commit comments

Comments
 (0)