Skip to content

Commit 7212afb

Browse files
committed
just a change or two...
1 parent ae5349d commit 7212afb

33 files changed

Lines changed: 379 additions & 254 deletions

File tree

ChangeLog.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ These items are in addition to what was listed under changes already in release.
1313

1414
## 1.6.0
1515
These are typically planned for release in a future version (usually the next one) as noted.
16-
* Add support for not-yet-announced S class DA-series parts, which are identical but for having the new EB-series lockdown thingie. There are no changes needed.
1716
* Support for the PTC peripheral on DA parts
18-
* Correct bug with EA-series parts having the SYSCFG0 fuse burned incorrectly. This would brick any EA-series part programmed. Luckily as uploading doesn't work right, few people have managed to do this.
17+
* Correct bug with EA-series parts having the SYSCFG0 fuse set during normal uploads, which is inappropriate, because if the UPDIPINCFG bit is not 1, the chip can only be reprogrammed with an exotic HV programmer.
18+
* Corrected a bug with EA-series parts incorrectly calculating the UPDIPINCFG bit as 0 in all cases. In combination with the above, unlucky users who were able to get an upload to attempt would promptly brick the chip, since nobody has HV programmers. Sorry bout that \o/ I'm not even certain there is a programming problem, or if I'd just attempted to program every chip I had mounted on a board....
19+
* Correct bug with EA-series parts failing to correctly configure clock speed.
20+
* Add support for EB-series to tools menus, permitting compile tests.
21+
* Brutal restructuring of Arduino.h.
22+
* keywords.txt for DxCore contained numerous deficiencies of varying severities. It was rebuilt de novo. Slightly less disorganized this time.
23+
* device_timer_pins.h design deemed hopelessly defective. Functionally identical file regenerated de novo,
1924

2025

2126
### 1.5.11 (Emergency fix)

megaavr/boards.txt

Lines changed: 162 additions & 118 deletions
Large diffs are not rendered by default.

megaavr/cores/dxcore/Arduino.h

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,86 @@ See Ref_Analog.md for more information of the representations of "analog pins".
519519

520520

521521
#include "pins_arduino.h"
522+
/* The Variant file must do one of the following */
523+
/* 1. Use the same pin order as this core's default pin mapping (recommended)
524+
* 2. Number each pin (port * 8) + bit_position, and define HYPERRATIONAL_PIN_NUMBERS (also recommended)
525+
* 3. Define NONCANONICAL_PIN_NUMBERS and use any pin numbering. (recommended if you must use a layout that departs significantly from the above)
526+
* 4. Define SPECIAL_PIN_NUMBERS, and provide a _digitalPinToCanon(pin) macro that takes an Arduino pin number, and returns (port * 8) + bit_position
527+
* (Only if you can do it better than the standard noncanonical implementation - that implementation is not grotesque, but it's also not great.
528+
* each table lookup takes the form lds lds add adc ld, 7 words and 10 clocks, so the whole thing is probably on the order of 20 and 26)
529+
* This change permits underlying logic to be written with a single byte to represent a pin, which is present in some obscure parts of the code
530+
* mostly involving interrupts.
531+
* Note that for constant pins known at compile time, these should all be able to be constant folded, it's only compile time unknown pins
532+
* where this applies. And only for the rare cases where we end up doing this, often interrupt related.
533+
* A lot of this comes back to the question of whether to leave "holes" for missing pins in the numbering. There are two forces pulling in
534+
* opposite directions here: each ghost pin takes up 4b for it's entries in the pin table (and it's sort of absurd for a 28-pin part to have
535+
* 47 logical pins because they were missing PB, PE, and 4 pins of PC and PF, but they make this sort of conversion (and a number of
536+
* similar ones) much easier.
537+
*/
522538

539+
#if defined(NONCANONICAL_PIN_NUMBERS)
540+
#define _digitalPinToCanon(pin) (((pin) < NUM_TOTAL_PINS) ? ((digital_pin_to_port[pin] << 3) + digital_pin_to_bit_position[pin] ) : NOT_A_PIN)
541+
#elif defined(HYPERRATIONAL_PIN_NUMBERS) /* Variant must number pins in order, and must skip numbers of pins not present on the chip. */
542+
#define _digitalPinToCanon(pin) (((pin) < NUM_TOTAL_PINS) ? (pin) : NOT_A_PIN)
543+
#elif !defined(SPECIAL_PIN_NUMBERS)
544+
#if _AVR_PINCOUNT == 64
545+
#define _digitalPinToCanon(pin) (((pin) < NUM_TOTAL_PINS) ? (((pin) < PIN_PG0) ? (pin) : (((pin) > PIN_PG7) ? (pin) - 8 : (pin) + 2 )) : NOT_A_PIN)
546+
#elif _AVR_PINCOUNT == 48
547+
#define _digitalPinToCanon(pin) (((pin) < NUM_TOTAL_PINS) ? (((pin) < PIN_PC0) ? (pin) : (pin) + 2 ) : NOT_A_PIN)
548+
#elif _AVR_PINCOUNT == 32
549+
#define _digitalPinToCanon(pin) (((pin) < NUM_TOTAL_PINS) ? (((pin) <= PIN_PA7) ? (pin) : (((pin) < PIN_PD0) ? (pin) + 8 : (((pin) < PIN_PF0) ? (pin) + 12 : (pin) + 20 ))) : NOT_A_PIN)
550+
#elif _AVR_PINCOUNT == 28
551+
#define _digitalPinToCanon(pin) (((pin) <= PIN_PF1) ? (((pin) <= PIN_PA7) ? (pin) : (((pin) < PIN_PD0) ? (pin) + 8 : (((pin) < PIN_PF0) ? (pin) + 12 : (pin) + 20 ))) : (((pin) < NUM_TOTAL_PINS) ? (pin) + 16 : NOT_A_PIN))
552+
#elif _AVR_PINCOUNT == 20 || _AVR_PINCOUNT == 14
553+
#define _digitalPinToCanon(pin) (((pin) < PIN_PF6) ? (((pin) <= PIN_PC0) ? (pin) : (((pin) < PIN_PD0) ? (pin) + 8 : (pin) + 12)) : (((pin) < NUM_TOTAL_PINS) ? (pin) + 26 : NOT_A_PIN))
554+
#endif
555+
#else
556+
#if !defined(_digitalPinToCanon)
557+
#error "Your custom variant says it provides a _digitalPinToCanon (SPECIAL_PIN_NUMBERS defined) but you don't provide one. \n Define NONCANONICAL_PIN_NUMBERS instead to use a possibly slower handler for the general case"
558+
#endif
559+
#endif
560+
// this stuff used to be in the variants.
561+
#if !defined(NUM_DIGITAL_PINS)
562+
/* Despite the name, this actually is a number 1 higher than the highest valid number for a digital pin
563+
* that is, it's the first integer which does not refer to a pin, and the number of digital pins if there
564+
* were no gaps in the numbering. Almost every pin mapping has gaps.
565+
* Tests like if (pin >= NUM_DIGITAL_PIN) return; are ubiquitous.
566+
* So we need to make our NUM_DIGITAL_PINS work like that.
567+
*/
568+
#if defined(PIN_PG7) // if there's a PORTG, that's the last pin. Add 1 to get the first non-pin
569+
#define NUM_DIGITAL_PINS (PIN_PG7 + 1)
570+
#elif defined(PIN_PF7) // if the UPDI pin, PF7 is defined (ie, UPDI can be prorgrammed as GPIO)
571+
#define NUM_DIGITAL_PINS (PIN_PF7 + 1)
572+
#elif defined(PIN_PF6) // otherwise it should be the reset pin, PG6.
573+
#define NUM_DIGITAL_PINS (PIN_PF6 + 1)
574+
#else
575+
#error "The variant file is incorrect, as it indicates no PG7, PF7 or PF6. All supported and announced parts have one or more of those pins."
576+
#endif
577+
#endif
578+
#if !defined(NUM_RESERVED_PINS)
579+
#define NUM_RESERVED_PINS (0)
580+
#endif
581+
#if !defined(NUM_INTERNALLY_USED_PINS)
582+
#if ((CLOCK_SOURCE & 0x03) == 1)
583+
#define NUM_INTERNALLY_USED_PINS (2) // External crystal takes PA0 and PA1
584+
#elif ((CLOCK_SOURCE & 0x03) == 2)
585+
#define NUM_INTERNALLY_USED_PINS (1) // External clock takes out PA0
586+
#else
587+
#define NUM_INTERNALLY_USED_PINS (0)
588+
#endif
589+
#endif
590+
#if !defined(NUM_I2C_PINS)
591+
#define NUM_I2C_PINS (2) // per I2C port in use - this number is nonsensical without qualification is is only for compatibility.
592+
#endif
593+
#if !defined(NUM_SPI_PINS)
594+
#define NUM_SPI_PINS (3) // per SPI port in use - this number is nonsensical without qualification is is only for compatibility.
595+
#endif
596+
#if !defined(NUM_TOTAL_FREE_PINS)
597+
#define NUM_TOTAL_FREE_PINS (PINS_COUNT - NUM_INTERNALLY_USED_PINS)
598+
#endif
599+
#if !defined(NUM_TOTAL_PINS)
600+
#define NUM_TOTAL_PINS (NUM_DIGITAL_PINS) /* Used the same way as NUM_DIGITAL_PINS. so it doesn't mean what it's named - I didn't make the convention*/
601+
#endif
523602
#define CHANNEL0_UNCHANGED (0x40)
524603
#define CHANNEL1_UNCHANGED (0x41)
525604

@@ -589,7 +668,7 @@ inline __attribute__((always_inline)) void check_valid_digital_pin(pin_size_t pi
589668
// Passing -1/255/NOT_A_PIN to the digital I/O functions is most likely intentional.
590669
badArg("Digital pin is constant, but not a valid pin");
591670
}
592-
#if (CLOCK_SOURCE == 2)
671+
#if (((CLOCK_SOURCE & 0x03) == 2))
593672
#if defined(MEGATINYCORE)
594673
if (pin == PIN_PA3) {
595674
badArg("Constant digital pin PIN_PA3 is used for the external osc, and is not available for other uses.");
@@ -599,7 +678,7 @@ inline __attribute__((always_inline)) void check_valid_digital_pin(pin_size_t pi
599678
badArg("Constant digital pin PIN_PA0 is used for the external osc, and is not available for other uses.");
600679
}
601680
#endif
602-
#elif CLOCK_SOURCE == 1
681+
#elif ((CLOCK_SOURCE & 0x03) == 1)
603682
if (pin < 2) {
604683
badArg("Pin PA0 and PA1 cannot be used for digital I/O because those are used for external crystal clock.");
605684
}

megaavr/cores/dxcore/UART_swap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
#if defined(USART0)
307307
const uint8_t _usart0_pins[][USART_PINS_WIDTH] PROGMEM = {
308308
#if (defined(HWSERIAL0_MUX))
309-
#if (defined(PIN_HWSERIAL0_TX) && defined(PIN_HWSERIAL0_RX) && defined(PIN_HWSERIAL0_XCK) && defined(PIN_HWSERIAL0_XDIR) && ((PIN_HWSERIAL0_TX != NOT_A_PIN && CLOCK_SOURCE == 0) || (PIN_HWSERIAL0_RX != NOT_A_PIN && CLOCK_SOURCE != 1)))
309+
#if (defined(PIN_HWSERIAL0_TX) && defined(PIN_HWSERIAL0_RX) && defined(PIN_HWSERIAL0_XCK) && defined(PIN_HWSERIAL0_XDIR) && ((PIN_HWSERIAL0_TX != NOT_A_PIN && ((CLOCK_SOURCE & 0x03) == 0)) || (PIN_HWSERIAL0_RX != NOT_A_PIN && CLOCK_SOURCE != 1)))
310310
#if !defined(HWSERIAL0_MUX_DEFAULT)
311311
#define HWSERIAL0_MUX_DEFAULT (HWSERIAL0_MUX)
312312
#endif

megaavr/cores/dxcore/device_timer_pins.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,25 @@
7777
#endif
7878

7979
#if defined(TCF0)
80-
#if (CLOCK_SOURCE == 0)
80+
#if (((CLOCK_SOURCE & 0x03) == 0))
8181
#define PIN_TCF0_WO0_DEFAULT PIN_PA0
8282
#else
8383
#define PIN_TCF0_WO0_DEFAULT NOT_A_PIN
8484
#endif
85-
#if (CLOCK_SOURCE == 1)
85+
#if (((CLOCK_SOURCE & 0x03) == 1))
8686
#define PIN_TCF0_WO1_DEFAULT NOT_A_PIN
8787
#else
8888
#define PIN_TCF0_WO1_DEFAULT PIN_PA1
8989
#endif
9090
#endif
9191

9292
#if defined(TCA0)
93-
#if (CLOCK_SOURCE == 0) // PA0 only available when using internal oscillator.
93+
#if (((CLOCK_SOURCE & 0x03) == 0)) // PA0 only available when using internal oscillator.
9494
#define PIN_TCA0_WO0_DEFAULT PIN_PA0
9595
#else
9696
#define PIN_TCA0_WO0_DEFAULT NOT_A_PIN
9797
#endif
98-
#if (CLOCK_SOURCE == 1) // crystal doesn't have PA1 available either
98+
#if (((CLOCK_SOURCE & 0x03) == 1)) // crystal doesn't have PA1 available either
9999
#define PIN_TCA0_WO1_DEFAULT NOT_A_PIN
100100
#else
101101
#define PIN_TCA0_WO1_DEFAULT PIN_PA1

megaavr/cores/dxcore/timers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
#define TIMERD0_WGMODE_SETTING (TCD_WGMODE_ONERAMP_gc)
260260
#endif
261261
#if !defined(TIMERD0_CLOCK_SETTING)
262-
#if (CLOCK_SOURCE != 0)
262+
#if (((CLOCK_SOURCE & 0x03) == 0))
263263
/*
264264
This is ALSO almost indistinguishable! Same F_PWM, but lower internal frequency.
265265
Sync is slower. but the bugs with TCD async events won't happen, and it's easier to do wacky stuff with the PROGEV.

megaavr/cores/dxcore/wiring.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,7 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
20272027

20282028
// These are defaults that could be overridden by variant or arguments passed to compiler
20292029
// They are only relevant for the case of using a crystal.
2030-
#if CLOCK_SOURCE == 1 && defined(CLKCTRL_FRQRANGE_gm)
2030+
#if ((CLOCK_SOURCE & 0x03) == 1) && defined(CLKCTRL_FRQRANGE_gm)
20312031
// In a quick test, with terrible layout (strip-board), I could run a 16 MHz crystal with any of these options!
20322032
// it was an 18 pf crystal with parasitic capacitance of stripboard as loading. User can force it to desired value
20332033
// but nobody is likely to care. Lower speed settings use less power, I *think* - but the datasheet has nothing
@@ -2051,7 +2051,7 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
20512051
#endif
20522052
#if (defined(__AVR_DA__) || defined(__AVR_DB__) || defined(__AVR_DD__) || defined(__AVR_DU__))
20532053
void __attribute__((weak)) init_clock() {
2054-
#if CLOCK_SOURCE == 0
2054+
#if ((CLOCK_SOURCE & 0x03) == 0)
20552055
/* internal can be cranked up to 32 Mhz by just extending the prior pattern from 24 to 28 and 32.
20562056
* F_CPU CLKCTRL_FREQSEL or FRQSEL depending on ATpack version
20572057
* 1 MHz 0x0
@@ -2142,7 +2142,7 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
21422142
#else
21432143
#error "F_CPU defined as an unsupported value for the internal oscillator."
21442144
#endif
2145-
#elif (CLOCK_SOURCE == 1 || CLOCK_SOURCE == 2)
2145+
#elif (((CLOCK_SOURCE & 0x03) == 1) || ((CLOCK_SOURCE & 0x03) == 2))
21462146
/* For this, we care very little, from the perspective of the init code, what the system frequency is - we have little choice but to
21472147
* run at crystal frequency, and THE USER MUST TELL US WHAT THAT IS.
21482148
* It is foolish to determine what we're running at at runtime, as the user should really knoe the basic parameters of the
@@ -2155,7 +2155,7 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
21552155
*/
21562156
#if !defined(CLKCTRL_XOSCHFCTRLA)
21572157
// it's an AVR DA-series or something with that version of CLKCTRL.
2158-
#if (CLOCK_SOURCE == 1)
2158+
#if (((CLOCK_SOURCE & 0x03) == 1))
21592159
#error "AVR DA-series selected, but crystal as clock source specified. DA-series parts only support internal oscillator or external clock."
21602160
#else
21612161
// external clock
@@ -2174,7 +2174,7 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
21742174
// a clock sufficiently broken that it resets instead.
21752175
_PROTECTED_WRITE(CLKCTRL_MCLKCTRLC, CLKCTRL_CFDSRC_CLKMAIN_gc | CLKCTRL_CFDEN_bm);
21762176
_PROTECTED_WRITE(CLKCTRL_MCLKINTCTRL, CLKCTRL_CFD_bm);
2177-
#if (CLOCK_SOURCE == 2)
2177+
#if (((CLOCK_SOURCE & 0x03) == 2))
21782178
// external clock
21792179
// CLKCTRL_SELHF_EXTCLOCK_gc or CLKCTRL_SELHF_EXTCLK_gc? Microchip can't seem to decide, and we can't test for it with the preprocessor because it's a bloody enumerated type.
21802180
// 0x02 is the numeric value of that constant. I can't even provide compatibility defines, because I don't have any way to tell which one it is for a given version of the headers.
@@ -2198,7 +2198,7 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
21982198
}
21992199
#elif defined(__AVR_EA__)
22002200
void __attribute__((weak)) init_clock() {
2201-
#if CLOCK_SOURCE == 0
2201+
#if ((CLOCK_SOURCE & 0x03) == 0)
22022202
// This sucks! Our internal clock sucks! two lousy speeds, selected by fuses? What is this, tinyAVR?
22032203
#if F_CPU == 20000000 || F_CPU == 16000000
22042204
_PROTECTED_WRITE(CLKCTRL_MCLKCTRLB, 0); // turn off prescaler.
@@ -2211,7 +2211,7 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
22112211
#elif F_CPU == 1000000
22122212
_PROTECTED_WRITE(CLKCTRL_MCLKCTRLB, 7); // /16
22132213
#endif
2214-
#elif (CLOCK_SOURCE == 1 || CLOCK_SOURCE == 2)
2214+
#elif (((CLOCK_SOURCE & 0x03) == 1) || ((CLOCK_SOURCE & 0x03) == 2))
22152215
/* For this, we don't really care what speed it is at - we will run at crystal frequency, and THE USER MUST TELL US WHAT THAT IS.
22162216
* It is foolish to determine what we're running at at runtime, as the user should really know the basic parameters of the
22172217
* board, like the speed of the crystal - it's usually printed on the damned thing. We don't prescale from crystals, eveh though
@@ -2226,7 +2226,7 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
22262226
*/
22272227
#if !defined(CLKCTRL_XOSCHFCTRLA)
22282228
// it's an AVR EB-series or something.
2229-
#if (CLOCK_SOURCE == 1)
2229+
#if (((CLOCK_SOURCE & 0x03) == 1))
22302230
#error "AVR EB-series selected, but crystal as clock source specified. EB-series parts only support internal oscillator or external clock."
22312231
#else
22322232
// external clock
@@ -2246,7 +2246,7 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
22462246
// to result in similar failure modes to overclocking.
22472247
_PROTECTED_WRITE(CLKCTRL_MCLKCTRLC, CLKCTRL_CFDSRC_CLKMAIN_gc | CLKCTRL_CFDEN_bm);
22482248
_PROTECTED_WRITE(CLKCTRL_MCLKINTCTRL, CLKCTRL_CFD_bm);
2249-
#if (CLOCK_SOURCE == 2)
2249+
#if (((CLOCK_SOURCE & 0x03) == 2))
22502250
// external clock
22512251
_PROTECTED_WRITE(CLKCTRL_XOSCHFCTRLA, (0x02 | CLKCTRL_ENABLE_bm));
22522252
uint8_t i = 255;
@@ -2280,7 +2280,7 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
22802280
}
22812281
#elif defined(__AVR_EB__)
22822282
void __attribute__((weak)) init_clock() {
2283-
#if CLOCK_SOURCE == 0
2283+
#if ((CLOCK_SOURCE & 0x03) == 0)
22842284
#if F_CPU == 20000000 || F_CPU == 16000000
22852285
_PROTECTED_WRITE(CLKCTRL_MCLKCTRLB, 0); // turn off prescaler.
22862286
#elif F_CPU == 10000000 || F_CPU == 8000000
@@ -2292,9 +2292,9 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
22922292
#elif F_CPU == 1000000
22932293
_PROTECTED_WRITE(CLKCTRL_MCLKCTRLB, 7); // /16
22942294
#endif
2295-
#elif (CLOCK_SOURCE == 1)
2295+
#elif (((CLOCK_SOURCE & 0x03) == 1))
22962296
#error "External high frequency crystal as clock source is not available on the EB-series"
2297-
#elif (CLOCK_SOURCE == 2)
2297+
#elif (((CLOCK_SOURCE & 0x03) == 2))
22982298
/* For this, we don't really care what speed it is at - we will run at crystal frequency, and THE USER MUST TELL US WHAT THAT IS.
22992299
* It is foolish to determine what we're running at at runtime, as the user should really know the basic parameters of the
23002300
* board, like the speed of the crystal - it's usually printed on the damned thing. We don't prescale from crystals, eveh though
@@ -2357,7 +2357,7 @@ void nudge_millis(__attribute__((unused)) uint16_t nudgesize) {
23572357
***********************************************************************************************/
23582358

23592359

2360-
#if (CLOCK_SOURCE == 1 || CLOCK_SOURCE == 2 || CLOCK_SOURCE == 6) // PLL here because you can
2360+
#if (((CLOCK_SOURCE & 0x03) == 1) || ((CLOCK_SOURCE & 0x03) == 2) || CLOCK_SOURCE == 6) // PLL here because you can
23612361
// easily exceed the max speed with the PLL clock. If this behaves like the Dx's clocking
23622362
// the TCD, where if you push it too hard, it will vanish instead of saturating at a max
23632363
// speed

megaavr/extras/Ref_LTO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ inline __attribute__((always_inline)) void check_valid_digital_pin(pin_size_t pi
5656
if (pin >= NUM_TOTAL_PINS && pin != NOT_A_PIN) { // Exception made for NOT_A_PIN - code exists which relies on being able to pass this and have nothing happen.
5757
badArg("Digital pin is constant, but not a valid pin");
5858
}
59-
#if (CLOCK_SOURCE == 2)
59+
#if (((CLOCK_SOURCE & 0x03) == 2))
6060
#if defined(MEGATINYCORE)
6161
if (pin == PIN_PA3) {
6262
badArg("Constant digital pin PIN_PA3 is used for the external osc, and is not available for other uses.");
@@ -66,7 +66,7 @@ inline __attribute__((always_inline)) void check_valid_digital_pin(pin_size_t pi
6666
badArg("Constant digital pin PIN_PA0 is used for the external osc, and is not available for other uses.");
6767
}
6868
#endif
69-
#elif CLOCK_SOURCE == 1
69+
#elif ((CLOCK_SOURCE & 0x03) == 1)
7070
if (pin < 2) {
7171
badArg("Pin PA0 and PA1 cannot be used for digital I/O because those are used for external crystal clock.");
7272
}

megaavr/extras/VariantTemplate.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,12 @@ static const uint8_t A21 = PIN_A21;
432432
};
433433
// But pins that are not usable at all should be marked NOT_A_PIN here
434434
const uint8_t digital_pin_to_bit_position[] = {
435-
#if CLOCK_SOURCE == 0 // PA0 used for external clock and crystal.
435+
#if ((CLOCK_SOURCE & 0x03) == 0) // PA0 used for external clock and crystal.
436436
PIN0_bp, // PA0
437437
#else
438438
NOT_A_PIN,
439439
#endif
440-
#if CLOCK_SOURCE == 1 // PA1 also used for crystal
440+
#if ((CLOCK_SOURCE & 0x03) == 1) // PA1 also used for crystal
441441
NOT_A_PIN, // 1 PA1
442442
#else
443443
// PA1 used for external crystal.
@@ -487,12 +487,12 @@ static const uint8_t A21 = PIN_A21;
487487

488488
// and down here
489489
const uint8_t digital_pin_to_bit_mask[] = {
490-
#if CLOCK_SOURCE == 0 // PA0 used for external clock and crystal.
490+
#if ((CLOCK_SOURCE & 0x03) == 0) // PA0 used for external clock and crystal.
491491
PIN0_bm, // PA0
492492
#else
493493
NOT_A_PIN,
494494
#endif
495-
#if CLOCK_SOURCE == 1 // PA1 also used for crystal
495+
#if ((CLOCK_SOURCE & 0x03) == 1) // PA1 also used for crystal
496496
NOT_A_PIN, // 1 PA1
497497
#else
498498
// PA1 used for external crystal.

0 commit comments

Comments
 (0)