~toykeeper/flashlight-firmware/trunk

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-adc.h

  • Committer: Selene Scriven
  • Date: 2020-07-06 20:24:28 UTC
  • mfrom: (188.1.294 fsm)
  • Revision ID: bzr@toykeeper.net-20200706202428-7pyen2ow9q2rtd9p
merged nearly a year of updates from the fsm branch, including the new product map

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#define VOLTAGE_FUDGE_FACTOR 5
39
39
#endif
40
40
#endif
 
41
 
 
42
volatile uint8_t irq_adc = 0;  // ADC interrupt happened?
 
43
uint8_t adc_sample_count = 0;  // skip the first sample; it's junk
 
44
uint8_t adc_channel = 0;  // 0=voltage, 1=temperature
 
45
uint16_t adc_raw[2];  // last ADC measurements (0=voltage, 1=temperature)
 
46
uint16_t adc_smooth[2];  // lowpassed ADC measurements (0=voltage, 1=temperature)
 
47
// ADC code is split into two parts:
 
48
// - ISR: runs immediately at each interrupt, does the bare minimum because time is critical here
 
49
// - deferred: the bulk of the logic runs later when time isn't so critical
 
50
uint8_t adc_deferred_enable = 0;  // stop waiting and run the deferred code
 
51
void adc_deferred();  // do the actual ADC-related calculations
 
52
 
 
53
static inline void ADC_voltage_handler();
41
54
volatile uint8_t voltage = 0;
42
 
volatile uint8_t adcint_enable;  // kludge, because adc auto-retrigger won't turn off
 
55
#ifdef USE_LVP
43
56
void low_voltage();
 
57
#endif
 
58
 
44
59
#ifdef USE_BATTCHECK
45
60
void battcheck();
46
61
#ifdef BATTCHECK_VpT
50
65
#define USE_BLINK_DIGIT
51
66
#endif
52
67
#endif
53
 
#endif
 
68
#endif  // ifdef USE_LVP
54
69
 
55
70
 
56
71
#ifdef USE_THERMAL_REGULATION
57
 
// default 5 seconds between thermal regulation events
58
 
#ifndef THERMAL_WARNING_SECONDS
59
 
#define THERMAL_WARNING_SECONDS 5
60
 
#endif
61
72
// try to keep temperature below 45 C
62
73
#ifndef DEFAULT_THERM_CEIL
63
74
#define DEFAULT_THERM_CEIL 45
70
81
#ifndef THERM_CAL_OFFSET
71
82
#define THERM_CAL_OFFSET 0
72
83
#endif
73
 
// temperature now, in C (ish) * 2  (14.1 fixed-point)
 
84
// temperature now, in C (ish)
74
85
volatile int16_t temperature;
75
 
// temperature in a few seconds, in C (ish) * 2  (14.1 fixed-point)
76
 
volatile int16_t projected_temperature;  // Fight the future!
77
86
uint8_t therm_ceil = DEFAULT_THERM_CEIL;
78
87
int8_t therm_cal_offset = 0;
79
 
//void low_temperature();
80
 
//void high_temperature();
81
88
volatile uint8_t reset_thermal_history = 1;
82
 
#endif
 
89
static inline void ADC_temperature_handler();
 
90
#endif  // ifdef USE_THERMAL_REGULATION
83
91
 
84
92
 
85
93
inline void ADC_on();