DK-TM4C129X: Add support for on-board TMP100 temperature sensor

This commit is contained in:
Gregory Nutt 2015-01-06 11:50:56 -06:00
parent 2b522bab9e
commit 383a47fb28
9 changed files with 179 additions and 16 deletions

View File

@ -36,6 +36,7 @@ Contents
- Buttons and LEDs
- Serial Console
- Networking Support
- Temperature Sensor
- DK-TM4129X Configuration Options
- Configurations
@ -648,6 +649,37 @@ f Application Configuration -> Network Utilities
CONFIG_NSH_NETINIT_RETRYMSEC=2000 : Configure the network monitor as you like
CONFIG_NSH_NETINIT_SIGNO=18
Temperature Sensor
==================
Support for the on-board TMP-100 temperature sensor is available. This
uses the driver for the compatible LM-75 part. To set up the temperature
sensor, add the following to the NuttX configuration file:
System Type -> Tiva/Stellaris Peripheral Selection
CONFIG_TIVA_I2C6=y
Drivers -> I2C Support
CONFIG_I2C=y
Drivers -> Sensors
CONFIG_I2C_LM75=y
Then you can implement logic like the following to use the temperature sensor:
#include <nuttx/sensors/lm75.h>
#include <arch/board/board.h>
ret = tiva_tmp100_initialize("/dev/temp"); /* Register the temperature sensor */
fd = open("/dev/temp", O_RDONLY); /* Open the temperature sensor device */
ret = ioctl(fd, SNIOC_FAHRENHEIT, 0); /* Select Fahrenheit */
bytesread = read(fd, buffer, 8*sizeof(b16_t)); /* Read temperature samples */
More complex temperature sensor operations are also available. See the IOCTL
commands enumerated in include/nuttx/sensors/lm75.h. Also read the descriptions
of the tiva_tmp100_initialize() and tiva_tmp100_attach() interfaces in the
arch/board/board.h file (sames as configs/dk-tm4c129x/include/board.h).
DK-TM4129X Configuration Options
================================

View File

@ -108,14 +108,14 @@
* --- ------------ -----------------
*/
/* LED index values for use with tm4c_setled() */
/* LED index values for use with tiva_setled() */
#define BOARD_LED_R 0
#define BOARD_LED_G 1
#define BOARD_LED_B 2
#define BOARD_NLEDS 3
/* LED bits for use with tm4c_setleds() */
/* LED bits for use with tiva_setleds() */
#define BOARD_LED_R_BIT (1 << BOARD_LED_R)
#define BOARD_LED_G_BIT (1 << BOARD_LED_G)
@ -244,7 +244,7 @@
void tiva_boardinitialize(void);
/************************************************************************************
* Name: tm4c_ledinit, tm4c_setled, and tm4c_setleds
* Name: tiva_ledinit, tiva_setled, and tiva_setleds
*
* Description:
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board LED. If
@ -254,9 +254,27 @@ void tiva_boardinitialize(void);
************************************************************************************/
#ifndef CONFIG_ARCH_LEDS
void tm4c_ledinit(void);
void tm4c_setled(int led, bool ledon);
void tm4c_setleds(uint8_t ledset);
void tiva_ledinit(void);
void tiva_setled(int led, bool ledon);
void tiva_setleds(uint8_t ledset);
#endif
/************************************************************************************
* Name: tiva_tmp100_initialize
*
* Description:
* Initialize and register the TMP-100 Temperature Sensor driver.
*
* Input parameters:
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
************************************************************************************/
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_STM32_I2C1)
int tiva_tmp100_initialize(FAR const char *devpath);
#endif
#endif /* __ASSEMBLY__ */

View File

@ -59,6 +59,10 @@ ifeq ($(CONFIG_NSH_ARCHINIT),y)
CSRCS += tm4c_nsh.c
endif
ifeq ($(CONFIG_I2C_LM75),y)
CSRCS += tm4c_tmp100.c
endif
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)

View File

@ -122,6 +122,7 @@
* I2C address is 0x4A
*/
#define TMP100_I2CBUS 6
#define TMP100_I2CADDR 0x4a
/* Speaker outputs *****************************************************************/

View File

@ -0,0 +1,103 @@
/****************************************************************************
* configs/dk-tm4c129x/src/tiva_tmp100.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#include <nuttx/i2c.h>
#include <nuttx/sensors/lm75.h>
#include "tiva_i2c.h"
#include "dk-tm4c129x.h"
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && \
defined(CONFIG_TIVA_I2C6)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: tiva_tmp100_initialize
*
* Description:
* Initialize and register the LM-75 Temperature Sensor driver.
*
* Input parameters:
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int tiva_tmp100_initialize(FAR const char *devpath)
{
FAR struct i2c_dev_s *i2c;
int ret;
/* Get an instance of the I2C6 interface */
i2c = up_i2cinitialize(TMP100_I2CBUS);
if (!i2c)
{
return -ENODEV;
}
/* Then register the temperature sensor */
ret = lm75_register(devpath, i2c, TMP100_I2CADDR);
if (ret < 0)
{
(void)up_i2cuninitialize(i2c);
}
return ret;
}
#endif /* CONFIG_I2C && CONFIG_I2C_LM75 && CONFIG_TIVA_I2C6 */

View File

@ -365,7 +365,7 @@ Then you can implement logic like the following to use the temperature sensor:
ret = ioctl(fd, SNIOC_FAHRENHEIT, 0); /* Select Fahrenheit */
bytesread = read(fd, buffer, 8*sizeof(b16_t)); /* Read temperature samples */
More complex temperature sensor operations are also available. See the IOCTAL
More complex temperature sensor operations are also available. See the IOCTL
commands enumerated in include/nuttx/sensors/lm75.h. Also read the descriptions
of the stm32_lm75initialize() and stm32_lm75attach() interfaces in the
arch/board/board.h file (sames as configs/stm3210e-eval/include/board.h).

View File

@ -222,7 +222,8 @@
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C" {
extern "C"
{
#else
#define EXTERN extern
#endif
@ -235,12 +236,12 @@ extern "C" {
*
* Description:
* All STM32 architectures must provide the following entry point. This entry point
* is called early in the intitialization -- after all memory has been configured
* is called early in the initialization -- after all memory has been configured
* and mapped but before any devices have been initialized.
*
************************************************************************************/
EXTERN void stm32_boardinitialize(void);
void stm32_boardinitialize(void);
/************************************************************************************
* Name: stm3210e_lcdclear
@ -254,7 +255,7 @@ EXTERN void stm32_boardinitialize(void);
************************************************************************************/
#ifdef CONFIG_STM32_FSMC
EXTERN void stm3210e_lcdclear(uint16_t color);
void stm3210e_lcdclear(uint16_t color);
#endif
/************************************************************************************
@ -272,7 +273,7 @@ EXTERN void stm3210e_lcdclear(uint16_t color);
************************************************************************************/
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_STM32_I2C1)
EXTERN int stm32_lm75initialize(FAR const char *devpath);
int stm32_lm75initialize(FAR const char *devpath);
#endif
/************************************************************************************
@ -290,7 +291,7 @@ EXTERN int stm32_lm75initialize(FAR const char *devpath);
************************************************************************************/
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_STM32_I2C1)
EXTERN xcpt_t stm32_lm75attach(xcpt_t irqhandler);
xcpt_t stm32_lm75attach(xcpt_t irqhandler);
#endif
#undef EXTERN

View File

@ -60,6 +60,10 @@ config LM75
default n
select I2C
select I2C_LM75
---help---
Enable driver support for the STMicro LM-75 temperature sensor.
This should also work with compatible temperature sensors such as
the TI TMP100/101.
config QENCODER
bool "Qencoder"

View File

@ -331,7 +331,7 @@ static ssize_t lm75_read(FAR struct file *filep, FAR char *buffer, size_t buflen
for (i = 0; i < nsamples; i++)
{
b16_t temp;
b16_t temp = 0;
/* Read the next b16_t temperature value */