Skip to content

Commit a943167

Browse files
committed
samd: Reduce a further 48 bytes for non-full builds
Another reduction of -48 bytes can be had if the fine calculation step is skipped. The worst difference compared to the old reference code with my calibration values in the 0° to 60° was 2°C, and the difference at 25°C is 1°C. The final size decrease for non-full builds like Trinket M0 is 268 bytes.
1 parent b251e78 commit a943167

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ports/atmel-samd/common-hal/microcontroller/Processor.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ STATIC float calculate_temperature(uint16_t raw_value) {
122122
int VADCR = ADCR * INT1VR;
123123
int VADCH = ADCH * INT1VH;
124124

125-
int INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */
126-
127125
int VADC = raw_value * 1000;
128126

129127
// Hopefully compiler will remove common subepxressions here.
@@ -134,7 +132,10 @@ STATIC float calculate_temperature(uint16_t raw_value) {
134132
// Coarse Temp Calculation by assume INT1V=1V for this ADC conversion
135133
int coarse_temp = tempR + (tempH - tempR) * (VADC - VADCR) / (VADCH - VADCR);
136134

135+
#if CIRCUITPY_FULL_BUILD
137136
// Calculation to find the real INT1V value during the ADC conversion
137+
int INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */
138+
138139
INT1VM = INT1VR + (((INT1VH - INT1VR) * (coarse_temp - tempR)) / (tempH - tempR));
139140

140141
int VADCM = raw_value * INT1VM;
@@ -143,6 +144,9 @@ STATIC float calculate_temperature(uint16_t raw_value) {
143144
float fine_temp = tempR + (((tempH - tempR) * (VADCM - VADCR)) / (VADCH - VADCR));
144145

145146
return fine_temp / 10;
147+
#else
148+
return coarse_temp / 10.;
149+
#endif
146150
}
147151
#endif // SAMD21
148152

0 commit comments

Comments
 (0)