summaryrefslogtreecommitdiffstats
path: root/watch-library/hardware/watch
diff options
context:
space:
mode:
authorJoey Castillo <joeycastillo@utexas.edu>2022-01-26 20:36:49 -0500
committerJoey Castillo <joeycastillo@utexas.edu>2022-01-26 20:36:49 -0500
commitfe5a3eecff0ca2fcaf5ac5eb00a8aa50b5064ece (patch)
tree7883e3f9a51eb8587f227b9ebe09d6554e989084 /watch-library/hardware/watch
parentf036d6a515b73400e7ea6dea09dfaf2a1ad0080a (diff)
parent5d5e5b125a383174f1891d37498415cc10fe84fe (diff)
downloadSensor-Watch-fe5a3eecff0ca2fcaf5ac5eb00a8aa50b5064ece.tar.gz
Sensor-Watch-fe5a3eecff0ca2fcaf5ac5eb00a8aa50b5064ece.tar.bz2
Sensor-Watch-fe5a3eecff0ca2fcaf5ac5eb00a8aa50b5064ece.zip
Merge branch 'main' of github.com:joeycastillo/Sensor-Watch into main
Diffstat (limited to 'watch-library/hardware/watch')
-rw-r--r--watch-library/hardware/watch/watch_adc.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/watch-library/hardware/watch/watch_adc.c b/watch-library/hardware/watch/watch_adc.c
index 5ba7abdf..32f06680 100644
--- a/watch-library/hardware/watch/watch_adc.c
+++ b/watch-library/hardware/watch/watch_adc.c
@@ -23,6 +23,7 @@
*/
#include "watch_adc.h"
+#include "driver_init.h"
static void _watch_sync_adc(void) {
while (ADC->SYNCBUSY.reg);
@@ -138,13 +139,30 @@ void watch_set_analog_sampling_length(uint8_t cycles) {
_watch_sync_adc();
}
+static inline uint32_t _watch_adc_get_reference_voltage(const watch_adc_reference_voltage reference) {
+ switch (reference) {
+ case ADC_REFERENCE_INTREF:
+ return ADC_REFCTRL_REFSEL_INTREF_Val;
+ break;
+ case ADC_REFERENCE_VCC_DIV1POINT6:
+ return ADC_REFCTRL_REFSEL_INTVCC0_Val;
+ break;
+ case ADC_REFERENCE_VCC_DIV2:
+ return ADC_REFCTRL_REFSEL_INTVCC1_Val;
+ break;
+ case ADC_REFERENCE_VCC:
+ return ADC_REFCTRL_REFSEL_INTVCC2_Val;
+ break;
+ }
+}
+
void watch_set_analog_reference_voltage(watch_adc_reference_voltage reference) {
ADC->CTRLA.bit.ENABLE = 0;
if (reference == ADC_REFERENCE_INTREF) SUPC->VREF.bit.VREFOE = 1;
else SUPC->VREF.bit.VREFOE = 0;
- ADC->REFCTRL.bit.REFSEL = reference;
+ ADC->REFCTRL.bit.REFSEL = _watch_adc_get_reference_voltage(reference);
ADC->CTRLA.bit.ENABLE = 1;
_watch_sync_adc();
// throw away one measurement after reference change (the channel doesn't matter).