summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorDan Halbert <halbert@adafruit.com>2021-01-12 13:01:50 -0500
committerGitHub <noreply@github.com>2021-01-12 13:01:50 -0500
commit4be5e914ac50650b87175aa04adee9a14f1adc27 (patch)
tree0dda9811431b49bfa58cbf17331ba62a6252c402 /ports
parentbfdaa6eb9c0720454435e496107adb5e2f8ec660 (diff)
parent452d66dd0ec117e9015ff9ce8162326c4bfc6b1a (diff)
Merge pull request #3966 from dhalbert/samd-dac-channels
fix atmel-samd DAC channel selection logic
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/common-hal/analogio/AnalogOut.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/ports/atmel-samd/common-hal/analogio/AnalogOut.c b/ports/atmel-samd/common-hal/analogio/AnalogOut.c
index 1565b0a8f..3ddd9cac6 100644
--- a/ports/atmel-samd/common-hal/analogio/AnalogOut.c
+++ b/ports/atmel-samd/common-hal/analogio/AnalogOut.c
@@ -55,21 +55,22 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
mp_raise_NotImplementedError(translate("No DAC on chip"));
#else
- int channel = -1;
-
- #if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02)
- if (pin->number != PIN_PA02) {
- channel = 0;
- }
- #endif
- #if defined(PIN_PA05) && defined(PIN_PA05) && !defined(IGNORE_PIN_PA05)
- if (pin->number != PIN_PA05) {
- channel = 1;
- }
- #endif
-
- if(channel == -1) {
- mp_raise_ValueError(translate("AnalogOut not supported on given pin"));
+ uint8_t channel;
+ switch (pin->number) {
+ #if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02)
+ case PIN_PA02:
+ channel = 0;
+ break;
+ #endif
+
+ #if defined(SAM_D5X_E5X) && defined(PIN_PA05) && !defined(IGNORE_PIN_PA05)
+ case PIN_PA05:
+ channel = 1;
+ break;
+ #endif
+
+ default:
+ mp_raise_ValueError(translate("AnalogOut not supported on given pin"));
return;
}