-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move comparator attach/detachInterrupt and ISR to separate cpp file
This makes it possible for the dot_a_linkage to optimize away the file when the ISR is not in use, saving about 200 bytes for every sketch that includes Logic.h
- Loading branch information
Showing
4 changed files
with
84 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
name=Comparator | ||
version=1.1.0 | ||
version=1.1.1 | ||
author=MCUdude | ||
maintainer=MCUdude | ||
sentence=A library for interfacing with the built-in analog comparator | ||
paragraph= | ||
category=Signal Input/Output | ||
url=https://github.com/MCUdude/MegaCoreX | ||
dot_a_linkage=true | ||
architectures=megaavr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// This file will be optimized away if attachInterrupt or detachInterrupt isn't used in | ||
// user program, thanks to dot_a_linkage set in library.properties | ||
|
||
#include "Comparator.h" | ||
|
||
void AnalogComparator::attachInterrupt(void (*userFunc)(void), uint8_t mode) | ||
{ | ||
AC_INTMODE_t intmode; | ||
switch (mode) | ||
{ | ||
// Set RISING, FALLING or CHANGE interrupt trigger for the comparator output | ||
case RISING: | ||
intmode = AC_INTMODE_POSEDGE_gc; | ||
break; | ||
case FALLING: | ||
intmode = AC_INTMODE_NEGEDGE_gc; | ||
break; | ||
case CHANGE: | ||
intmode = AC_INTMODE_BOTHEDGE_gc; | ||
break; | ||
default: | ||
// Only RISING, FALLING and CHANGE is supported | ||
return; | ||
} | ||
AC.CTRLA = (AC.CTRLA & ~AC_INTMODE_POSEDGE_gc) | intmode; | ||
|
||
// Store function pointer | ||
intFuncAC[comparator_number] = userFunc; | ||
|
||
// Enable interrupt | ||
AC.INTCTRL |= AC_CMP_bm; | ||
} | ||
|
||
void AnalogComparator::detachInterrupt() | ||
{ | ||
// Disable interrupt | ||
AC.INTCTRL &= ~AC_CMP_bm; | ||
} | ||
|
||
#ifdef AC0_AC_vect | ||
ISR(AC0_AC_vect) | ||
{ | ||
// Run user function | ||
intFuncAC[0](); | ||
|
||
// Clear flag | ||
AC0.STATUS = AC_CMP_bm; | ||
} | ||
#endif | ||
|
||
#ifdef AC1_AC_vect | ||
ISR(AC1_AC_vect) | ||
{ | ||
// Run user function | ||
intFuncAC[1](); | ||
|
||
// Clear flag | ||
AC1.STATUS = AC_CMP_bm; | ||
} | ||
#endif | ||
|
||
#ifdef AC2_AC_vect | ||
ISR(AC2_AC_vect) | ||
{ | ||
// Run user function | ||
intFuncAC[2](); | ||
|
||
// Clear flag | ||
AC2.STATUS = AC_CMP_bm; | ||
} | ||
#endif |