Skip to content

Commit 4be5e91

Browse files
authored
Merge pull request #3966 from dhalbert/samd-dac-channels
fix atmel-samd DAC channel selection logic
2 parents bfdaa6e + 452d66d commit 4be5e91

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

ports/atmel-samd/common-hal/analogio/AnalogOut.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,22 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
5555
mp_raise_NotImplementedError(translate("No DAC on chip"));
5656
#else
5757

58-
int channel = -1;
59-
60-
#if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02)
61-
if (pin->number != PIN_PA02) {
62-
channel = 0;
63-
}
64-
#endif
65-
#if defined(PIN_PA05) && defined(PIN_PA05) && !defined(IGNORE_PIN_PA05)
66-
if (pin->number != PIN_PA05) {
67-
channel = 1;
68-
}
69-
#endif
70-
71-
if(channel == -1) {
72-
mp_raise_ValueError(translate("AnalogOut not supported on given pin"));
58+
uint8_t channel;
59+
switch (pin->number) {
60+
#if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02)
61+
case PIN_PA02:
62+
channel = 0;
63+
break;
64+
#endif
65+
66+
#if defined(SAM_D5X_E5X) && defined(PIN_PA05) && !defined(IGNORE_PIN_PA05)
67+
case PIN_PA05:
68+
channel = 1;
69+
break;
70+
#endif
71+
72+
default:
73+
mp_raise_ValueError(translate("AnalogOut not supported on given pin"));
7374
return;
7475
}
7576

0 commit comments

Comments
 (0)