3 Copyright (C) Dean Camera, 2010.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2010 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 disclaim 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 Master include file for the board temperature sensor 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
40 * \section Sec_Dependencies Module Source Dependencies
41 * The following files must be built with any user project that uses this module:
42 * - LUFA/Drivers/Board/Temperature.c <i>(Makefile source module name: LUFA_SRC_TEMPERATURE)</i>
44 * \section Module Description
45 * Temperature sensor driver. This provides an easy to use interface for the hardware temperature sensor located
46 * on many boards. It provides an interface to configure the sensor and appropriate ADC channel, plus read out the
47 * current temperature in degrees C. It is designed for and will only work with the temperature sensor located on the
48 * official Atmel USB AVR boards, as each sensor has different characteristics.
53 #ifndef __TEMPERATURE_H__
54 #define __TEMPERATURE_H__
57 #include <avr/pgmspace.h>
59 #include "../../Common/Common.h"
60 #include "../Peripheral/ADC.h"
62 #if (BOARD == BOARD_NONE)
63 #error The Board Temperature Sensor driver cannot be used if the makefile BOARD option is not set.
64 #elif ((BOARD != BOARD_USBKEY) && (BOARD != BOARD_STK525) && \
65 (BOARD != BOARD_STK526) && (BOARD != BOARD_USER) && \
66 (BOARD != BOARD_EVK527))
67 #error The selected board does not contain a temperature sensor.
70 /* Enable C linkage for C++ Compilers: */
71 #if defined(__cplusplus)
75 /* Public Interface - May be used in end-application: */
77 /** ADC channel number for the temperature sensor. */
78 #define TEMP_ADC_CHANNEL 0
80 /** ADC channel MUX mask for the temperature sensor. */
81 #define TEMP_ADC_CHANNEL_MASK ADC_CHANNEL0
83 /** Minimum returnable temperature from the \ref Temperature_GetTemperature() function. */
84 #define TEMP_MIN_TEMP TEMP_TABLE_OFFSET
86 /** Maximum returnable temperature from the \ref Temperature_GetTemperature() function. */
87 #define TEMP_MAX_TEMP ((TEMP_TABLE_SIZE - 1) + TEMP_TABLE_OFFSET)
89 /* Inline Functions: */
90 /** Initialises the temperature sensor driver, including setting up the appropriate ADC channel.
91 * This must be called before any other temperature sensor routines.
93 * \pre The ADC itself (not the ADC channel) must be configured separately before calling the
94 * temperature sensor functions.
96 static inline void Temperature_Init(void) ATTR_ALWAYS_INLINE
;
97 static inline void Temperature_Init(void)
99 ADC_SetupChannel(TEMP_ADC_CHANNEL
);
102 /* Function Prototypes: */
103 /** Performs a complete ADC on the temperature sensor channel, and converts the result into a
104 * valid temperature between \ref TEMP_MIN_TEMP and \ref TEMP_MAX_TEMP in degrees Celsius.
106 * \return Signed temperature value in degrees Celsius.
108 int8_t Temperature_GetTemperature(void) ATTR_WARN_UNUSED_RESULT
;
110 /* Private Interface - For use in library only: */
111 #if !defined(__DOXYGEN__)
113 #define TEMP_TABLE_SIZE (sizeof(Temperature_Lookup) / sizeof(Temperature_Lookup[0]))
114 #define TEMP_TABLE_OFFSET -21
117 /* Disable C linkage for C++ Compilers: */
118 #if defined(__cplusplus)