Statistics
| Branch: | Tag: | Revision:

root / LUFA / Drivers / Board / Temperature.h @ 978b99e5

History | View | Annotate | Download (5.27 KB)

1
/*
2
             LUFA Library
3
     Copyright (C) Dean Camera, 2011.
4

5
  dean [at] fourwalledcubicle [dot] com
6
           www.lufa-lib.org
7
*/
8

    
9
/*
10
  Copyright 2011  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 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
 *  \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_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_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_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
                #include "../Peripheral/ADC.h"
73

    
74
                #if (BOARD == BOARD_NONE)
75
                        #error The Board Temperature Sensor driver cannot be used if the makefile BOARD option is not set.
76
                #elif ((BOARD != BOARD_USBKEY) && (BOARD != BOARD_STK525) && \
77
                       (BOARD != BOARD_STK526) && (BOARD != BOARD_USER) &&   \
78
                           (BOARD != BOARD_EVK527))
79
                        #error The selected board does not contain a compatible temperature sensor.
80
                #endif
81

    
82
        /* Enable C linkage for C++ Compilers: */
83
                #if defined(__cplusplus)
84
                        extern "C" {
85
                #endif
86

    
87
        /* Public Interface - May be used in end-application: */
88
                /* Macros: */
89
                        /** ADC channel number for the temperature sensor. */
90
                        #define TEMP_ADC_CHANNEL       0
91

    
92
                        /** ADC channel MUX mask for the temperature sensor. */
93
                        #define TEMP_ADC_CHANNEL_MASK  ADC_CHANNEL0
94
                        
95
                        /** Size of the temperature sensor lookup table, in lookup values */
96
                        #define TEMP_TABLE_SIZE        120
97

    
98
                        /** Minimum returnable temperature from the \ref Temperature_GetTemperature() function. */
99
                        #define TEMP_MIN_TEMP          TEMP_TABLE_OFFSET_DEGREES
100

    
101
                        /** Maximum returnable temperature from the \ref Temperature_GetTemperature() function. */
102
                        #define TEMP_MAX_TEMP          ((TEMP_TABLE_SIZE - 1) + TEMP_TABLE_OFFSET_DEGREES)
103

    
104
                /* Inline Functions: */
105
                        /** Initializes the temperature sensor driver, including setting up the appropriate ADC channel.
106
                         *  This must be called before any other temperature sensor routines.
107
                         *
108
                         *  \pre The ADC itself (not the ADC channel) must be configured separately before calling the
109
                         *       temperature sensor functions.
110
                         */
111
                        static inline void Temperature_Init(void) ATTR_ALWAYS_INLINE;
112
                        static inline void Temperature_Init(void)
113
                        {
114
                                ADC_SetupChannel(TEMP_ADC_CHANNEL);
115
                        }
116

    
117
                /* Function Prototypes: */
118
                        /** Performs a complete ADC on the temperature sensor channel, and converts the result into a
119
                         *  valid temperature between \ref TEMP_MIN_TEMP and \ref TEMP_MAX_TEMP in degrees Celsius.
120
                         *
121
                         *  \return Signed temperature value in degrees Celsius.
122
                         */
123
                        int8_t Temperature_GetTemperature(void) ATTR_WARN_UNUSED_RESULT;
124

    
125
        /* Private Interface - For use in library only: */
126
        #if !defined(__DOXYGEN__)
127
                /* Macros: */
128
                        #define TEMP_TABLE_OFFSET_DEGREES   -21
129
        #endif
130

    
131
        /* Disable C linkage for C++ Compilers: */
132
                #if defined(__cplusplus)
133
                        }
134
                #endif
135

    
136
#endif
137

    
138
/** @} */
139