diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2020-10-05 11:28:57 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2020-10-29 11:55:06 -0400 |
commit | 97d49105b7643f63a70cb724a0633e36b8746ce1 (patch) | |
tree | cf29899ad6a0e6661f8b58086c8d0f3f3dda4489 /src/atsam/adc.c | |
parent | 6a67afaff16d142abaf98c8debf9b723a9d5a64b (diff) | |
download | kutter-97d49105b7643f63a70cb724a0633e36b8746ce1.tar.gz kutter-97d49105b7643f63a70cb724a0633e36b8746ce1.tar.xz kutter-97d49105b7643f63a70cb724a0633e36b8746ce1.zip |
atsam: Support reading chip based temperature sensor on sam3/sam4s
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/atsam/adc.c')
-rw-r--r-- | src/atsam/adc.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/atsam/adc.c b/src/atsam/adc.c index 73dfcd59..5e5fe420 100644 --- a/src/atsam/adc.c +++ b/src/atsam/adc.c @@ -1,6 +1,6 @@ // Analog to digital support // -// Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net> +// Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net> // // This file may be distributed under the terms of the GNU GPLv3 license. @@ -12,17 +12,20 @@ #include "internal.h" // GPIO #include "sched.h" // sched_shutdown +#define ADC_TEMPERATURE_PIN 0xfe +DECL_ENUMERATION("pin", "ADC_TEMPERATURE", ADC_TEMPERATURE_PIN); + static const uint8_t adc_pins[] = { #if CONFIG_MACH_SAM3X GPIO('A', 2), GPIO('A', 3), GPIO('A', 4), GPIO('A', 6), GPIO('A', 22), GPIO('A', 23), GPIO('A', 24), GPIO('A', 16), GPIO('B', 12), GPIO('B', 13), GPIO('B', 17), GPIO('B', 18), - GPIO('B', 19), GPIO('B', 20), GPIO('B', 21) + GPIO('B', 19), GPIO('B', 20), GPIO('B', 21), ADC_TEMPERATURE_PIN #elif CONFIG_MACH_SAM4S GPIO('A', 17), GPIO('A', 18), GPIO('A', 19), GPIO('A', 20), GPIO('B', 0), GPIO('B', 1), GPIO('B', 2), GPIO('B', 3), GPIO('A', 21), GPIO('A', 22), GPIO('C', 13), GPIO('C', 15), - GPIO('C', 12), GPIO('C', 29), GPIO('C', 30) + GPIO('C', 12), GPIO('C', 29), GPIO('C', 30), ADC_TEMPERATURE_PIN #endif }; @@ -50,8 +53,13 @@ gpio_adc_setup(uint8_t pin) | ADC_MR_TRANSFER(1)); } - // Place pin in input floating mode - gpio_in_setup(pin, 0); + if (pin == ADC_TEMPERATURE_PIN) { + // Enable temperature sensor + ADC->ADC_ACR |= ADC_ACR_TSON; + } else { + // Place pin in input floating mode + gpio_in_setup(pin, 0); + } return (struct gpio_adc){ .chan = 1 << chan }; } |