Skip to content

Commit d6c26eb

Browse files
committed
Analog2DigitalConverter, RealTimeClock, TimerCounter: attach ISR handler on demand
1 parent 726e04b commit d6c26eb

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"type": "git",
1313
"url": "https://github.com/jnsbyr/arduino-samd21lpe"
1414
},
15-
"version": "1.0.8",
15+
"version": "1.0.9",
1616
"examples": "examples/*/*.ino",
1717
"license": "Apache-2.0",
1818
"frameworks": "arduino",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SAMD21 Low Power Extensions
2-
version=1.0.8
2+
version=1.0.9
33
author=Jens B.
44
maintainer=Jens B.
55
sentence=low power extensions for SAMD21

src/Analog2DigitalConverter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ void Analog2DigitalConverter::start(uint8_t muxPosVal, void (*callback)())
253253
NVIC_DisableIRQ(ADC_IRQn);
254254
NVIC_ClearPendingIRQ(ADC_IRQn);
255255
NVIC_SetPriority(ADC_IRQn, 0x00);
256+
#ifndef SAMD21LPE_USE_STATIC_ISR_HANDLER
257+
System::getVectorTable().pfnADC_Handler = (void*)isrHandler;
258+
#endif
256259
NVIC_EnableIRQ(ADC_IRQn);
257260

258261
// enable result ready interrupt
@@ -472,7 +475,9 @@ const Analog2DigitalConverter::Pin Analog2DigitalConverter::PIN_MAPPING[Analog2D
472475
{ 0, 11, PORT_PA11 }
473476
};
474477

478+
#ifdef SAMD21LPE_USE_STATIC_ISR_HANDLER
475479
void ADC_Handler()
476480
{
477481
SAMD21LPE::Analog2DigitalConverter::isrHandler();
478482
}
483+
#endif

src/RealTimeClock.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ void RealTimeClock::enable(uint8_t clkGenId, uint32_t clkGenFrequency, uint8_t c
5757
NVIC_DisableIRQ(RTC_IRQn);
5858
NVIC_ClearPendingIRQ(RTC_IRQn);
5959
NVIC_SetPriority(RTC_IRQn, min(irqPriority, (1 << __NVIC_PRIO_BITS) - 1));
60+
#ifndef SAMD21LPE_USE_STATIC_ISR_HANDLER
61+
System::getVectorTable().pfnRTC_Handler = (void*)isrHandler;
62+
#endif
6063
NVIC_EnableIRQ(RTC_IRQn);
6164

6265
// setup RTC for mode 0, no continuous read, optionally clear on match (periodic timer) and enable
@@ -81,6 +84,9 @@ void RealTimeClock::disable()
8184
// clear RTC interrupts
8285
NVIC_DisableIRQ(RTC_IRQn);
8386
NVIC_ClearPendingIRQ(RTC_IRQn);
87+
#ifndef SAMD21LPE_USE_STATIC_ISR_HANDLER
88+
System::getVectorTable().pfnRTC_Handler = nullptr;
89+
#endif
8490
}
8591

8692
uint32_t RealTimeClock::toClockTicks(uint32_t duration) const
@@ -206,10 +212,12 @@ void RealTimeClock::isrHandler()
206212
}
207213
}
208214

215+
#ifdef SAMD21LPE_USE_STATIC_ISR_HANDLER
209216
/**
210217
* SAMD21 RTC interrupt handler
211218
*/
212219
void RTC_Handler()
213220
{
214221
RealTimeClock::instance().isrHandler();
215222
}
223+
#endif

src/TimerCounter.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ bool TimerCounter::enable(uint8_t id, uint8_t clkGenId, uint32_t clkGenFrequency
122122
NVIC_DisableIRQ(irq);
123123
NVIC_ClearPendingIRQ(irq);
124124
NVIC_SetPriority(irq, irqPriority);
125+
#ifndef SAMD21LPE_USE_STATIC_ISR_HANDLER
126+
switch (id)
127+
{
128+
case 3:
129+
System::getVectorTable().pfnTC3_Handler = (void*)isrHandlerTC3;
130+
break;
131+
132+
case 4:
133+
System::getVectorTable().pfnTC4_Handler = (void*)isrHandlerTC4;
134+
break;
135+
136+
case 5:
137+
System::getVectorTable().pfnTC5_Handler = (void*)isrHandlerTC5;
138+
break;
139+
}
140+
#endif
125141
NVIC_EnableIRQ(irq);
126142

127143
// enable overflow interrupt (needed for oneshot mode)
@@ -359,6 +375,8 @@ void TimerCounter::isrHandler(uint8_t id)
359375

360376
TimerCounter* TimerCounter::timerCounter[3] = { nullptr };
361377

378+
#ifdef SAMD21LPE_USE_STATIC_ISR_HANDLER
379+
362380
/**
363381
* SAMD21 TC3 interrupt handler
364382
*/
@@ -382,3 +400,5 @@ void TC5_Handler()
382400
{
383401
SAMD21LPE::TimerCounter::isrHandler(2);
384402
}
403+
404+
#endif

0 commit comments

Comments
 (0)