aboutsummaryrefslogtreecommitdiff
path: root/fsm
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-11-19 01:56:17 -0700
committerSelene ToyKeeper2023-11-19 01:56:17 -0700
commit76db685f66baa7787ad94ce91585e7cba8b94cfb (patch)
tree29499c612872908c7232984655aa65bcb70d3056 /fsm
parentadded dac-scale.py: short script to calculate avrdd DAC+Vref values from leve... (diff)
downloadanduril-76db685f66baa7787ad94ce91585e7cba8b94cfb.tar.gz
anduril-76db685f66baa7787ad94ce91585e7cba8b94cfb.tar.bz2
anduril-76db685f66baa7787ad94ce91585e7cba8b94cfb.zip
started refactoring fsm/adc.*, but need a checkpoint before continuing
Diffstat (limited to 'fsm')
-rw-r--r--fsm/adc.c23
-rw-r--r--fsm/adc.h15
2 files changed, 14 insertions, 24 deletions
diff --git a/fsm/adc.c b/fsm/adc.c
index 6d4eeb1..13a76b6 100644
--- a/fsm/adc.c
+++ b/fsm/adc.c
@@ -15,14 +15,14 @@
#include <avr/sleep.h>
-static inline void set_admux_therm() {
+static inline void adc_therm_mode() {
hwdef_set_admux_therm();
adc_channel = 1;
adc_sample_count = 0; // first result is unstable
ADC_start_measurement();
}
-inline void set_admux_voltage() {
+void adc_voltage_mode() {
hwdef_set_admux_voltage();
adc_channel = 0;
adc_sample_count = 0; // first result is unstable
@@ -30,21 +30,6 @@ inline void set_admux_voltage() {
}
-#ifdef TICK_DURING_STANDBY
- // needs a special sleep mode to get accurate measurements quickly
- // ... full power-down ends up using more power overall, and causes
- // some weird issues when the MCU doesn't stay awake enough cycles
- // to complete a reading
- #define adc_sleep_mode mcu_adc_sleep_mode
-#endif
-
-#define ADC_start_measurement mcu_adc_start_measurement
-
-// set up ADC for reading battery voltage
-#define ADC_on mcu_adc_on
-// stop the ADC
-#define ADC_off mcu_adc_off
-
#ifdef USE_VOLTAGE_DIVIDER
static inline uint8_t calc_voltage_divider(uint16_t value) {
// use 9.7 fixed-point to get sufficient precision
@@ -160,7 +145,7 @@ void adc_deferred() {
ADC_voltage_handler();
#ifdef USE_THERMAL_REGULATION
// set the correct type of measurement for next time
- if (! go_to_standby) set_admux_therm();
+ if (! go_to_standby) adc_therm_mode();
#endif
}
#endif
@@ -170,7 +155,7 @@ void adc_deferred() {
ADC_temperature_handler();
#ifdef USE_LVP
// set the correct type of measurement for next time
- set_admux_voltage();
+ adc_voltage_mode();
#endif
}
#endif
diff --git a/fsm/adc.h b/fsm/adc.h
index e4046a4..65d7d6c 100644
--- a/fsm/adc.h
+++ b/fsm/adc.h
@@ -32,6 +32,9 @@ volatile uint8_t adc_reset = 2;
#endif
#endif
+
+void adc_voltage_mode();
+
#ifdef TICK_DURING_STANDBY
volatile uint8_t adc_active_now = 0; // sleep LVP needs a different sleep mode
#endif
@@ -103,14 +106,16 @@ static inline void ADC_temperature_handler();
//inline void ADC_on();
-#define ADC_on mcu_adc_on
+#define ADC_on adc_voltage_mode
//inline void ADC_off();
#define ADC_off mcu_adc_off
//inline void ADC_start_measurement();
#define ADC_start_measurement mcu_adc_start_measurement
-#ifdef TICK_DURING_STANDBY
- //inline void adc_sleep_mode();
- #define adc_sleep_mode mcu_adc_sleep_mode
-#endif
+// needs a special sleep mode to get accurate measurements quickly
+// ... full power-down ends up using more power overall, and causes
+// some weird issues when the MCU doesn't stay awake enough cycles
+// to complete a reading
+//inline void adc_sleep_mode();
+#define adc_sleep_mode mcu_adc_sleep_mode
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.