You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

Temperature.h 5.4KB

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