- /* handle the extremes first (they won't interpolate well! ;-) */
- if (val == 0)
- return (long) tempLUT[0];
- if (val == 1023)
- return (long) tempLUT[255];
-
- if (twoBits == 0)
- return (long) tempLUT[eightBits];
- else {
- /* do some interpolation by multipying the lower and upper
- bounds by 25, 50 or 75, then /100. */
- temp = ((25 * (4 - twoBits)) * tempLUT[eightBits]
- + (25 * twoBits) * tempLUT[eightBits + 1]);
- /* increase the magnitude by 50 to achieve rounding. */
- if (temp > 0)
- temp += 50;
- else
- temp -= 50;
- return (temp / 100);
- }
+ /* no interpolation for these */
+ if (twoBits == 0 || eightBits == 255)
+ return TEMP_FROM_REG(eightBits);
+
+ /* do some linear interpolation */
+ return (tempLUT[eightBits] * (4 - twoBits) +
+ tempLUT[eightBits + 1] * twoBits) * 25;