Oops - with new changes to the way the device Configuration Descriptor is retrieved...
[pub/USBasp.git] / LUFA / Drivers / Board / Temperature.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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.
20
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
28 this software.
29 */
30
31 /** \file
32 *
33 * Temperature sensor board driver for the USB boards which contain a temperature sensor.
34 */
35
36 /** \ingroup Group_BoardDrivers
37 * @defgroup Group_Temperature Temperature Driver - LUFA/Drivers/Board/Temperature.h
38 *
39 * \section Sec_Dependencies Module Source Dependencies
40 * The following files must be built with any user project that uses this module:
41 * - LUFA/Drivers/Board/Temperature.c
42 *
43 * \section Module Description
44 * Temperature sensor driver. This provides an easy to use interface for the hardware temperature sensor located
45 * on many boards. It provides an interface to configure the sensor and appropriate ADC channel, plus read out the
46 * current temperature in degrees C. It is designed for and will only work with the temperature sensor located on the
47 * official Atmel USB AVR boards, as each sensor has different characteristics.
48 *
49 * @{
50 */
51
52 #ifndef __TEMPERATURE_H__
53 #define __TEMPERATURE_H__
54
55 /* Macros: */
56 #if !defined(__DOXYGEN__)
57 #define INCLUDE_FROM_BOARD_DRIVER
58 #endif
59
60 /* Includes: */
61 #include <avr/pgmspace.h>
62
63 #include "../../Common/Common.h"
64 #include "../Peripheral/ADC.h"
65
66 #if !defined(BOARD)
67 #error BOARD must be set in makefile to a value specified in BoardTypes.h.
68 #elif (BOARD != BOARD_USBKEY) && (BOARD != BOARD_STK525) && (BOARD != BOARD_STK526) && (BOARD != BOARD_USER)
69 #error The selected board does not contain a temperature sensor.
70 #endif
71
72 /* Enable C linkage for C++ Compilers: */
73 #if defined(__cplusplus)
74 extern "C" {
75 #endif
76
77 /* Public Interface - May be used in end-application: */
78 /* Macros: */
79 /** ADC channel number for the temperature sensor. */
80 #define TEMP_ADC_CHANNEL 0
81
82 /** Minimum returnable temperature from the \ref Temperature_GetTemperature() function. */
83 #define TEMP_MIN_TEMP TEMP_TABLE_OFFSET
84
85 /** Maximum returnable temperature from the \ref Temperature_GetTemperature() function. */
86 #define TEMP_MAX_TEMP ((TEMP_TABLE_SIZE - 1) + TEMP_TABLE_OFFSET)
87
88 /* Pseudo-Function Macros: */
89 #if defined(__DOXYGEN__)
90 /** Initializes the temperature sensor driver, including setting up the appropriate ADC channel.
91 * This must be called before any other temperature sensor routines.
92 *
93 * The ADC itself (not the ADC channel) must be configured separately before calling the temperature
94 * sensor functions.
95 */
96 static inline void Temperature_Init(void);
97 #else
98 #define Temperature_Init() ADC_SetupChannel(TEMP_ADC_CHANNEL);
99 #endif
100
101 /* Function Prototypes: */
102 /** Performs a complete ADC on the temperature sensor channel, and converts the result into a
103 * valid temperature between \ref TEMP_MIN_TEMP and \ref TEMP_MAX_TEMP in degrees Celsius.
104 *
105 * \return Signed temperature in degrees Celsius
106 */
107 int8_t Temperature_GetTemperature(void) ATTR_WARN_UNUSED_RESULT;
108
109 /* Private Interface - For use in library only: */
110 #if !defined(__DOXYGEN__)
111 /* Macros: */
112 #define TEMP_TABLE_SIZE (sizeof(Temperature_Lookup) / sizeof(Temperature_Lookup[0]))
113 #define TEMP_TABLE_OFFSET -21
114 #endif
115
116 /* Disable C linkage for C++ Compilers: */
117 #if defined(__cplusplus)
118 }
119 #endif
120
121 #endif
122
123 /** @} */