Skip to content

Commit d502f5d

Browse files
committed
Correct #1216
Also add EB, DU support to the library (this library is shared with DxCore.
1 parent ce3f0c1 commit d502f5d

3 files changed

Lines changed: 114 additions & 20 deletions

File tree

megaavr/libraries/Comparator/library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=Comparator
2-
version=1.3.0
2+
version=1.3.1
33
author=MCUdude
44
maintainer=MCUdude, Spence Konde
55
sentence=A library for interfacing with the built-in analog comparators.
6-
paragraph=1.3.0 - add enclosing namespace to fix conflict with other @MCUDude libraries, move interrupt stuff to it's own file so if not used, it isn't included in the binary, both to save space and permit manually defined (hence more performant) interrupts. 1.2.0 - Harmonize with megaTinyCore, it is now compatible with all part families. Fix a few bugs, fix Interrupt example. Add getPeripheral(). 1.1.1 - add read(), output py inverted and non-inverted, external output no external output options. Eliminate pin direction stuff - AC periph has auto-direction when it takes over a pin (SK) 1.0.1 - fix DX compatibility issues, output bug (SK).
6+
paragraph=1.3.1 - Fix bug regarding fourth positive input pin of comparator 3 on tinyAVR 1-series. Add support for EB and DU-series. 1.3.0 - add enclosing namespace to fix conflict with other @MCUDude libraries, move interrupt stuff to it's own file so if not used, it isn't included in the binary, both to save space and permit manually defined (hence more performant) interrupts. 1.2.0 - Harmonize with megaTinyCore, it is now compatible with all part families. Fix a few bugs, fix Interrupt example. Add getPeripheral(). 1.1.1 - add read(), output py inverted and non-inverted, external output no external output options. Eliminate pin direction stuff - AC periph has auto-direction when it takes over a pin (SK) 1.0.1 - fix DX compatibility issues, output bug (SK).
77
category=Signal Input/Output
88
url=https://github.com/MCUdude/MegaCoreX
99
dot_a_linkage=true

megaavr/libraries/Comparator/src/Comparator.cpp

Lines changed: 100 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
#include "Comparator.h"
33
#include "Arduino.h"
44
/*
5-
PIN | DA/DB AC0 | DA/DB AC1 | DA/DB AC2 | DD AC0 | EA AC0 | EA AC1 | Mega AC0 |
6-
-------|-----------|-----------|-----------|----------|----------|----------|----------|
7-
IN P0# | PIN_PD2 | PIN_PD2 | PIN_PD2 | PIN_PD2* | PIN_PD2 | PIN_PD2 | PIN_PD2 |
8-
IN P1 | PIN_PE0* | PIN_PD3 | PIN_PD4 | n/a | PIN_PE0* | PIN_PD3 | PIN_PD4 |
9-
IN P2 | PIN_PE2* | PIN_PD4 | PIN_PE1* | n/a | PIN_PE2* | PIN_PD4 | PIN_PD6 |
10-
IN P3# | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD1 |
11-
IN P4= | n/a | n/a | n/a | PIN_PC3! | PIN_PC3 | PIN_PC3 | n/a |
12-
IN N0 | PIN_PD3 | PIN_PD5 | PIN_PD7 | PIN_PD3* | PIN_PD3 | PIN_PD5 | PIN_PD3 |
13-
IN N1# | PIN_PD0* | PIN_PD0* | PIN_PD0* | n/a | PIN_PD0 | PIN_PD0 | PIN_PD5 |
14-
IN N2# | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 |
15-
IN N3= | n/a | n/a | n/a | PIN_PC2! | PIN_PC2 | PIN_PC2 | n/a |
16-
OUT | PIN_PA7 | PIN_PA7 | PIN_PA7 | PIN_PA7* | PIN_PA7 | PIN_PA7 | PIN_PA7 |
17-
AltOUT | PIN_PC6* | PIN_PC6* | PIN_PC6* | n/a | PIN_PC6* | PIN_PC6* | n/a |
5+
PIN | DA/DB AC0 | DA/DB AC1 | DA/DB AC2 | DD AC0 | EA AC0 | EA AC1 | Mega AC0 | EB AC0 | EB AC1 | DU AC0 |
6+
-------|-----------|-----------|-----------|----------|----------|----------|----------|---------|---------|---------|
7+
IN P0# | PIN_PD2 | PIN_PD2 | PIN_PD2 | PIN_PD2* | PIN_PD2 | PIN_PD2 | PIN_PD2 | PIN_PD2 | PIN_PD2 | PIN_p |
8+
IN P1 | PIN_PE0* | PIN_PD3 | PIN_PD4 | n/a | PIN_PE0* | PIN_PD3 | PIN_PD4 | n/a | PIN_PD3 | n/a |
9+
IN P2 | PIN_PE2* | PIN_PD4 | PIN_PE1* | n/a | PIN_PE2* | PIN_PD4 | PIN_PD6 | n/a | PIN_PD4 | n/a |
10+
IN P3# | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD6 | PIN_PD1 | PIN_PD6 | PIN_PD6 | PIN_PD6 |
11+
IN P4= | n/a | n/a | n/a | PIN_PC3! | PIN_PC3 | PIN_PC3 | n/a | PIN_PC3 | PIN_PC3 | PIN_PC3 |
12+
IN P5 | n/a | n/a | n/a | n/a | n/a | n/a | n/a | PIN_PD4 | PIN_PA6 | n/a |
13+
IN P6 | n/a | n/a | n/a | n/a | n/a | n/a | n/a | PIN_PD5 | PIN_PA7 | n/a |
14+
IN N0 | PIN_PD3 | PIN_PD5 | PIN_PD7 | PIN_PD3* | PIN_PD3 | PIN_PD5 | PIN_PD3 | PIN_PD3 | PIN_PD5 | PIN_PD5 |
15+
IN N1# | PIN_PD0* | PIN_PD0* | PIN_PD0* | n/a | PIN_PD0 | PIN_PD0 | PIN_PD5 | PIN_PD0 | PIN_PD0 | PIN_PD0 |
16+
IN N2# | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 | PIN_PD7 |
17+
IN N3= | n/a | n/a | n/a | PIN_PC2! | PIN_PC2 | PIN_PC2 | n/a | PIN_PC2 | PIN_PC2 | n/a |
18+
OUT | PIN_PA7 | PIN_PA7 | PIN_PA7 | PIN_PA7* | PIN_PA7 | PIN_PA7 | PIN_PA7 | PIN_PA7 | PIN_PA7 | PIN_PA7 |
19+
AltOUT | PIN_PC6* | PIN_PC6* | PIN_PC6* | n/a | PIN_PC6* | PIN_PC6* | n/a | n/a | n/a | n/a |
1820
*/
1921
#if (defined(ANALOG_COMP_PINS_DA_DB))
2022
/* P0, P1, P2, P3, N0, N1, N2 */
@@ -71,6 +73,11 @@ AltOUT | PIN_PC6* | PIN_PC6* | PIN_PC6* | n/a | PIN_PC6* | PIN_PC6* |
7173
#if defined(AC1_AC_vect)
7274
AnalogComparator Comparator1(1, AC1, PORTD.PIN2CTRL, PORTD.PIN3CTRL, PORTD.PIN4CTRL, PORTD.PIN6CTRL, PORTC.PIN3CTRL,/* EA-series has no MVIO */ PORTD.PIN5CTRL, PORTD.PIN0CTRL, PORTD.PIN7CTRL, PORTC.PIN2CTRL);
7375
#endif
76+
#elif defined(ANALOG_COMP_PINS_EB)
77+
/* EB: 2 ACs: P0, P1, P2, P3, P4, P5, P6, N0, N1, N2, N3 */
78+
AnalogComparator Comparator0(0, AC0, PORTD.PIN2CTRL, AC_NULL_REG, AC_NULL_REG, PORTD.PIN6CTRL, PORTC.PIN3CTRL, PORTD.PIN4CTRL, PORTD.PIN5CTRL, PORTD.PIN3CTRL, PORTD.PIN0CTRL, PORTD.PIN7CTRL, PORTC.PIN2CTRL);
79+
AnalogComparator Comparator1(1, AC1, PORTD.PIN2CTRL, PORTD.PIN3CTRL, PORTD.PIN4CTRL, PORTD.PIN6CTRL, PORTC.PIN3CTRL, PORTA.PIN6CTRL, PORTA.PIN7CTRL, PORTD.PIN5CTRL, PORTD.PIN0CTRL, PORTD.PIN7CTRL, PORTC.PIN2CTRL);
80+
#endif
7481
#elif defined(ANALOG_COMP_PINS_MEGA)
7582
/* mega0:1 AC P0, P1, P2, P3, N0, N1, N2*/
7683
#if defined(AC0_AC_vect)
@@ -107,7 +114,7 @@ AltOUT | PIN_PC6* | PIN_PC6* | PIN_PC6* | n/a | PIN_PC6* | PIN_PC6* |
107114
/* other golden 1-series: 3 AC P0, P1 (AC1 on 24 only), P2, P3, N0, N1*/
108115
AnalogComparator Comparator0(0, AC0, PORTA.PIN7CTRL, PORTB.PIN5CTRL, PORTB.PIN1CTRL, PORTA.PIN6CTRL, PORTA.PIN6CTRL, PORTB.PIN4CTRL);
109116
AnalogComparator Comparator1(1, AC1, PORTA.PIN7CTRL, PORTB.PIN6CTRL, PORTB.PIN0CTRL, PORTA.PIN4CTRL, PORTA.PIN5CTRL, PORTB.PIN7CTRL);
110-
AnalogComparator Comparator2(2, AC2, PORTA.PIN6CTRL, PORTB.PIN0CTRL, PORTB.PIN5CTRL, PORTA.PIN7CTRL, PORTA.PIN7CTRL, PORTB.PIN6CTRL);
117+
AnalogComparator Comparator2(2, AC2, PORTA.PIN6CTRL, PORTB.PIN0CTRL, PORTB.PIN5CTRL, PORTB.PIN7CTRL, PORTA.PIN7CTRL, PORTB.PIN6CTRL);
111118

112119
#elif defined(ANALOG_COMP_PINS_TINY_TWO_14)
113120
/* 14-pin 2-series: 1 AC P0, P2, N0, N2*/
@@ -198,6 +205,35 @@ AnalogComparator::AnalogComparator(
198205
IN1_N(in1_n),
199206
IN2_N(in2_n),
200207
IN3_N(in3_n) { }
208+
#elif defined(ANALOG_COMP_PINS_EB) /*9 inputs P0, P1, P2, P3, P4, N0, N1, N2, N3 */
209+
AnalogComparator::AnalogComparator(
210+
const uint8_t comp_number,
211+
AC_t& ac,
212+
register8_t& in0_p,
213+
register8_t& in1_p,
214+
register8_t& in2_p,
215+
register8_t& in3_p,
216+
register8_t& in4_p,
217+
register8_t& in5_p,
218+
register8_t& in6_p,
219+
register8_t& in0_n,
220+
register8_t& in1_n,
221+
register8_t& in2_n,
222+
register8_t& in3_n
223+
)
224+
: comparator_number(comp_number),
225+
AC(ac),
226+
IN0_P(in0_p),
227+
IN1_P(in1_p),
228+
IN2_P(in2_p),
229+
IN3_P(in3_p),
230+
IN4_P(in4_p),
231+
IN3_P(in5_p),
232+
IN4_P(in6_p),
233+
IN0_N(in0_n),
234+
IN1_N(in1_n),
235+
IN2_N(in2_n),
236+
IN3_N(in3_n) { }
201237
/* Start of tinyAVR */
202238
#elif defined(ANALOG_COMP_PINS_TINY_FEW)
203239
AnalogComparator::AnalogComparator(
@@ -484,6 +520,31 @@ void AnalogComparator::init() {
484520
} else if (input_n == comparator::in_n::in3) {
485521
IN3_N = PORT_ISC_INPUT_DISABLE_gc;
486522
}
523+
#elif defined(ANALOG_COMP_PINS_EB)
524+
if (input_p == comparator::in_p::in0) {
525+
IN0_P = PORT_ISC_INPUT_DISABLE_gc;
526+
} else if (input_p == comparator::in_p::in1) {
527+
IN1_P = PORT_ISC_INPUT_DISABLE_gc;
528+
} else if (input_p == comparator::in_p::in2) {
529+
IN2_P = PORT_ISC_INPUT_DISABLE_gc;
530+
} else if (input_p == comparator::in_p::in3) {
531+
IN3_P = PORT_ISC_INPUT_DISABLE_gc;
532+
} else if (input_p == comparator::in_p::in4) {
533+
IN4_P = PORT_ISC_INPUT_DISABLE_gc;
534+
} else if (input_p == comparator::in_p::in5) {
535+
IN5_P = PORT_ISC_INPUT_DISABLE_gc;
536+
} else if (input_p == comparator::in_p::in6) {
537+
IN6_P = PORT_ISC_INPUT_DISABLE_gc;
538+
}
539+
if (input_n == comparator::in_n::in0) {
540+
IN0_N = PORT_ISC_INPUT_DISABLE_gc;
541+
} else if (input_n == comparator::in_n::in1) {
542+
IN1_N = PORT_ISC_INPUT_DISABLE_gc;
543+
} else if (input_n == comparator::in_n::in2) {
544+
IN2_N = PORT_ISC_INPUT_DISABLE_gc;
545+
} else if (input_n == comparator::in_n::in3) {
546+
IN3_N = PORT_ISC_INPUT_DISABLE_gc;
547+
}
487548
#endif
488549
#else /* tinyAVR */
489550
if (input_p == comparator::in_p::in0) {
@@ -607,6 +668,31 @@ void AnalogComparator::stop(bool restorepins) {
607668
} else if (input_n == comparator::in_n::in3) {
608669
IN3_N = 0;
609670
}
671+
#elif defined(ANALOG_COMP_PINS_EB)
672+
if (input_p == comparator::in_p::in0) {
673+
IN0_P = 0;
674+
} else if (input_p == comparator::in_p::in1) {
675+
IN1_P = 0;
676+
} else if (input_p == comparator::in_p::in2) {
677+
IN2_P = 0;
678+
} else if (input_p == comparator::in_p::in3) {
679+
IN3_P = 0;
680+
} else if (input_p == comparator::in_p::in4) {
681+
IN4_P = 0;
682+
} else if (input_p == comparator::in_p::in3) {
683+
IN5_P = 0;
684+
} else if (input_p == comparator::in_p::in4) {
685+
IN6_P = 0;
686+
}
687+
if (input_n == comparator::in_n::in0) {
688+
IN0_N = 0;
689+
} else if (input_n == comparator::in_n::in1) {
690+
IN1_N = 0;
691+
} else if (input_n == comparator::in_n::in2) {
692+
IN2_N = 0;
693+
} else if (input_n == comparator::in_n::in3) {
694+
IN3_N = 0;
695+
}
610696
#endif
611697
#else /* tinyAVR */
612698
if (input_p == comparator::in_p::in0) {

megaavr/libraries/Comparator/src/Comparator.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#if defined(DB_28_PINS) || defined(DB_32_PINS)
1616
#define ANALOG_COMP_NO_N1
1717
#endif
18-
#elif defined(__AVR_DD__)
18+
#elif defined(__AVR_DD__) || defined(__AVR_DU__)
1919
/* DD:1 AC: P0, P3, P4, N0, N2, N3 */
2020
#define ANALOG_COMP_PINS_DD
2121
#define AC_NULL_REG _SFR_MEM8(0x04B0)
@@ -26,6 +26,10 @@
2626
#if !defined(PORTE)
2727
#define AC_NULL_REG _SFR_MEM8(0x04B0)
2828
#endif
29+
#elif defined(__AVR_EB__)
30+
/* EA:2 ACs: P0, P1, P2, P3, P4, N0, N1, N2, N3 */
31+
#define ANALOG_COMP_PINS_EB
32+
#define AC_NULL_REG _SFR_MEM8(0x04B0)
2933
#else
3034
/* mega0:1 AC P0, P1, P2, P3, N0, N1, N2 */
3135
#define ANALOG_COMP_PINS_MEGA
@@ -99,10 +103,14 @@ namespace comparator {
99103
#endif
100104
in3 = 0x03,
101105
pd6 = 0x03,
102-
#if defined(__AVR_DD__) || defined(__AVR_EA__)
106+
#if defined(__AVR_DD__) || defined(__AVR_EA__) || defined(__AVR_EB__) || defined(__AVR_DU__)
103107
in4 = 0x04,
104108
pc3 = 0x04,
105-
#endif
109+
#endif
110+
#if defined(__AVR_EB__)
111+
in5 = 0x05,
112+
in6 = 0x06,
113+
#endif
106114
};
107115
};
108116

@@ -117,7 +125,7 @@ namespace comparator {
117125
pd7 = 0x02,
118126
#if defined(__AVR_DD__) || defined(__AVR_EA__) || defined(__AVR_EB__)
119127
in3 = 0x03,
120-
pc3 = 0x03,
128+
pc2 = 0x03,
121129
dacref = 0x04
122130
#else
123131
dacref = 0x03

0 commit comments

Comments
 (0)