]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/Board/Temperature.h
Merge commit 'fdc38ef3f92af7adeeb4de49550d8838c8a39b5c'
[max/tmk_keyboard.git] / tmk_core / protocol / lufa / LUFA-git / LUFA / Drivers / Board / Temperature.h
1 /*
2              LUFA Library
3      Copyright (C) Dean Camera, 2014.
4
5   dean [at] fourwalledcubicle [dot] com
6            www.lufa-lib.org
7 */
8
9 /*
10   Copyright 2014  Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28   this software.
29 */
30
31 /** \file
32  *  \brief NTC Temperature Sensor board hardware driver.
33  *
34  *  Master include file for the board temperature sensor driver, for the USB boards which contain a temperature sensor.
35  */
36
37 /** \ingroup Group_BoardDrivers
38  *  \defgroup Group_Temperature Temperature Sensor Driver - LUFA/Drivers/Board/Temperature.h
39  *  \brief NTC Temperature Sensor board hardware driver.
40  *
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>
44  *
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.
50  *
51  *  \section Sec_Temperature_ExampleUsage Example Usage
52  *  The following snippet is an example of how this module may be used within a typical
53  *  application.
54  *
55  *  \code
56  *      // Initialize the ADC and board temperature sensor drivers before first use
57  *      ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);
58  *      Temperature_Init();
59  *
60  *      // Display converted temperature in degrees Celsius
61  *      printf("Current Temperature: %d Degrees\r\n", Temperature_GetTemperature());
62  *  \endcode
63  *
64  *  @{
65  */
66
67 #ifndef __TEMPERATURE_H__
68 #define __TEMPERATURE_H__
69
70         /* Includes: */
71                 #include "../../Common/Common.h"
72
73         /* Preprocessor Checks: */
74                 #if ((BOARD == BOARD_USBKEY) || (BOARD == BOARD_STK525) || \
75                      (BOARD == BOARD_STK526) || (BOARD == BOARD_EVK527))
76                         #define TEMPERATURE_SENSOR_DRIVER_COMPATIBLE
77                 #endif
78
79                 #if !defined(__INCLUDE_FROM_TEMPERATURE_C) && !defined(TEMPERATURE_SENSOR_DRIVER_COMPATIBLE)
80                         #error The selected board does not contain a compatible temperature sensor.
81                 #endif
82
83         #if defined(TEMPERATURE_SENSOR_DRIVER_COMPATIBLE)
84
85         /* Includes: */
86                 #include "../Peripheral/ADC.h"
87
88         /* Enable C linkage for C++ Compilers: */
89                 #if defined(__cplusplus)
90                         extern "C" {
91                 #endif
92
93         /* Public Interface - May be used in end-application: */
94                 /* Macros: */
95                         /** ADC channel number for the temperature sensor. */
96                         #define TEMP_ADC_CHANNEL       0
97
98                         /** ADC channel MUX mask for the temperature sensor. */
99                         #define TEMP_ADC_CHANNEL_MASK  ADC_CHANNEL0
100
101                         /** Size of the temperature sensor lookup table, in lookup values */
102                         #define TEMP_TABLE_SIZE        120
103
104                         /** Minimum returnable temperature from the \ref Temperature_GetTemperature() function. */
105                         #define TEMP_MIN_TEMP          TEMP_TABLE_OFFSET_DEGREES
106
107                         /** Maximum returnable temperature from the \ref Temperature_GetTemperature() function. */
108                         #define TEMP_MAX_TEMP          ((TEMP_TABLE_SIZE - 1) + TEMP_TABLE_OFFSET_DEGREES)
109
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.
113                          *
114                          *  \pre The ADC itself (not the ADC channel) must be configured separately before calling the
115                          *       temperature sensor functions.
116                          */
117                         static inline void Temperature_Init(void) ATTR_ALWAYS_INLINE;
118                         static inline void Temperature_Init(void)
119                         {
120                                 ADC_SetupChannel(TEMP_ADC_CHANNEL);
121                         }
122
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.
126                          *
127                          *  \return Signed temperature value in degrees Celsius.
128                          */
129                         int8_t Temperature_GetTemperature(void) ATTR_WARN_UNUSED_RESULT;
130
131         /* Private Interface - For use in library only: */
132         #if !defined(__DOXYGEN__)
133                 /* Macros: */
134                         #define TEMP_TABLE_OFFSET_DEGREES   -21
135         #endif
136
137         /* Disable C linkage for C++ Compilers: */
138                 #if defined(__cplusplus)
139                         }
140                 #endif
141
142         #endif
143
144 #endif
145
146 /** @} */
147