3 Copyright (C) Dean Camera, 2014.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaims all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
32 * \brief NTC Temperature Sensor board hardware driver.
34 * Master include file for the board temperature sensor driver, for the USB boards which contain a temperature sensor.
37 /** \ingroup Group_BoardDrivers
38 * \defgroup Group_Temperature Temperature Sensor Driver - LUFA/Drivers/Board/Temperature.h
39 * \brief NTC Temperature Sensor board hardware driver.
41 * \section Sec_Temperature_Dependencies Module Source Dependencies
42 * The following files must be built with any user project that uses this module:
43 * - LUFA/Drivers/Board/Temperature.c <i>(Makefile source module name: LUFA_SRC_TEMPERATURE)</i>
45 * \section Sec_Temperature_ModDescription Module Description
46 * Temperature sensor driver. This provides an easy to use interface for the hardware temperature sensor located
47 * on many boards. It provides an interface to configure the sensor and appropriate ADC channel, plus read out the
48 * current temperature in degrees C. It is designed for and will only work with the temperature sensor located on the
49 * official Atmel USB AVR boards, as each sensor has different characteristics.
51 * \section Sec_Temperature_ExampleUsage Example Usage
52 * The following snippet is an example of how this module may be used within a typical
56 * // Initialize the ADC and board temperature sensor drivers before first use
57 * ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);
60 * // Display converted temperature in degrees Celsius
61 * printf("Current Temperature: %d Degrees\r\n", Temperature_GetTemperature());
67 #ifndef __TEMPERATURE_H__
68 #define __TEMPERATURE_H__
71 #include "../../Common/Common.h"
73 /* Preprocessor Checks: */
74 #if ((BOARD == BOARD_USBKEY) || (BOARD == BOARD_STK525) || \
75 (BOARD == BOARD_STK526) || (BOARD == BOARD_EVK527))
76 #define TEMPERATURE_SENSOR_DRIVER_COMPATIBLE
79 #if !defined(__INCLUDE_FROM_TEMPERATURE_C) && !defined(TEMPERATURE_SENSOR_DRIVER_COMPATIBLE)
80 #error The selected board does not contain a compatible temperature sensor.
83 #if defined(TEMPERATURE_SENSOR_DRIVER_COMPATIBLE)
86 #include "../Peripheral/ADC.h"
88 /* Enable C linkage for C++ Compilers: */
89 #if defined(__cplusplus)
93 /* Public Interface - May be used in end-application: */
95 /** ADC channel number for the temperature sensor. */
96 #define TEMP_ADC_CHANNEL 0
98 /** ADC channel MUX mask for the temperature sensor. */
99 #define TEMP_ADC_CHANNEL_MASK ADC_CHANNEL0
101 /** Size of the temperature sensor lookup table, in lookup values */
102 #define TEMP_TABLE_SIZE 120
104 /** Minimum returnable temperature from the \ref Temperature_GetTemperature() function. */
105 #define TEMP_MIN_TEMP TEMP_TABLE_OFFSET_DEGREES
107 /** Maximum returnable temperature from the \ref Temperature_GetTemperature() function. */
108 #define TEMP_MAX_TEMP ((TEMP_TABLE_SIZE - 1) + TEMP_TABLE_OFFSET_DEGREES)
110 /* Inline Functions: */
111 /** Initializes the temperature sensor driver, including setting up the appropriate ADC channel.
112 * This must be called before any other temperature sensor routines.
114 * \pre The ADC itself (not the ADC channel) must be configured separately before calling the
115 * temperature sensor functions.
117 static inline void Temperature_Init(void) ATTR_ALWAYS_INLINE;
118 static inline void Temperature_Init(void)
120 ADC_SetupChannel(TEMP_ADC_CHANNEL);
123 /* Function Prototypes: */
124 /** Performs a complete ADC on the temperature sensor channel, and converts the result into a
125 * valid temperature between \ref TEMP_MIN_TEMP and \ref TEMP_MAX_TEMP in degrees Celsius.
127 * \return Signed temperature value in degrees Celsius.
129 int8_t Temperature_GetTemperature(void) ATTR_WARN_UNUSED_RESULT;
131 /* Private Interface - For use in library only: */
132 #if !defined(__DOXYGEN__)
134 #define TEMP_TABLE_OFFSET_DEGREES -21
137 /* Disable C linkage for C++ Compilers: */
138 #if defined(__cplusplus)