Add driver for LM-75 temperature sensor
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3947 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
d210450c8a
commit
bdf8ede547
18 changed files with 1125 additions and 321 deletions
10
ChangeLog
10
ChangeLog
|
@ -2022,7 +2022,9 @@
|
|||
* graphics/, include/nuttx/nx: Add new NX interfaces for drawing
|
||||
circles -- both circular outlines and filled circles.
|
||||
* graphic/nxglib/nxglib_spitline.c: Add a "fudge factor" that eliminates
|
||||
some problems for rendering nearly horizontal, wide lines.
|
||||
some problems for rendering nearly horizontal, wide lines. Hmm...
|
||||
but I suspect this fudge factor also leads to new problems rendering
|
||||
very thin, nearly horizontal lines. More tuning is needed.
|
||||
* drivers/analog, include/nuttx/analog, arch/arch/src/lpcxx: (1) Add
|
||||
updates to the ADS1255 driver, (2) fix errors from my last merge (sorry),
|
||||
(3) Add DAC infrastructure, (4) add AD5410 DAC driver, and (5) add
|
||||
|
@ -2031,7 +2033,7 @@
|
|||
'make export' logic. The script now also finds and bundles up all of
|
||||
the architecture-specific header files as well.
|
||||
* drivers/arch/arm/src/stm32/stm32_i2c.c: Add a reset to the I2C
|
||||
initialization logic to prevent spurious interrups when the I2C
|
||||
initialization logic to prevent spurious interrupts when the I2C
|
||||
interrupts are enabled (submitted by Uros Platise).
|
||||
* Scripts/makefiles/documents. Several adjustments, corrections and
|
||||
typo fixes so that NuttX will build correctly on FreeBSD using the
|
||||
|
@ -2064,3 +2066,7 @@
|
|||
(1) Clocking needs to be based on PCLK1, not HCLK and fast speed settings
|
||||
need some additional bits; and (2) Correct a hang that will occur on
|
||||
I2C1 if FSMC is also enabled.
|
||||
* drivers/sensors/lm75.c and include/nuttx/sensors/lm75.h: Add an LM-75
|
||||
temperature sensor driver.
|
||||
* configs/stm3210e-eval/src/up_lm75.c: Add support for the LM-75 on the
|
||||
STMicro STM3210E-EVAL board.
|
||||
|
|
14
TODO
14
TODO
|
@ -1,12 +1,15 @@
|
|||
NuttX TODO List (Last updated August 24, 2011)
|
||||
NuttX TODO List (Last updated September 9, 2011)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This file summarizes known NuttX bugs, limitations, inconsistencies with
|
||||
standards, things that could be improved, and ideas for enhancements.
|
||||
|
||||
nuttx/
|
||||
|
||||
(5) Task/Scheduler (sched/)
|
||||
(1) On-demand paging (sched/)
|
||||
(1) Memory Managment (mm/)
|
||||
(1) Signals (sched/, arch/)
|
||||
(2) Signals (sched/, arch/)
|
||||
(1) pthreads (sched/)
|
||||
(1) C++ Support
|
||||
(5) Binary loaders (binfmt/)
|
||||
|
@ -132,6 +135,13 @@ o Signals (sched/, arch/)
|
|||
Priority: Low, required by standards but not so critical for an
|
||||
embedded system.
|
||||
|
||||
Description: sig_notify() logic does not support SIGEV_THREAD; structure
|
||||
struct sigevent does not provide required members sigev_notify_function
|
||||
or sigev_notify_attributes.
|
||||
Status: Low, there are alternative designs. However, these features
|
||||
are required by the POSIX standard.
|
||||
Priority: Low for now
|
||||
|
||||
o pthreads (sched/)
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
|
@ -934,41 +934,55 @@ int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int
|
|||
|
||||
/* Check for error status conditions */
|
||||
|
||||
if (status & I2C_SR1_BERR)
|
||||
if ((status & I2C_SR1_ERRORMASK) != 0)
|
||||
{
|
||||
/* Bus Error */
|
||||
if (status & I2C_SR1_BERR)
|
||||
{
|
||||
/* Bus Error */
|
||||
|
||||
status_errno = EIO;
|
||||
}
|
||||
else if (status & I2C_SR1_ARLO)
|
||||
{
|
||||
/* Arbitration Lost (master mode) */
|
||||
status_errno = EIO;
|
||||
}
|
||||
else if (status & I2C_SR1_ARLO)
|
||||
{
|
||||
/* Arbitration Lost (master mode) */
|
||||
|
||||
status_errno = EAGAIN;
|
||||
}
|
||||
else if (status & I2C_SR1_AF)
|
||||
{
|
||||
/* Acknowledge Failure */
|
||||
status_errno = EAGAIN;
|
||||
}
|
||||
else if (status & I2C_SR1_AF)
|
||||
{
|
||||
/* Acknowledge Failure */
|
||||
|
||||
status_errno = ENXIO;
|
||||
}
|
||||
else if (status & I2C_SR1_OVR)
|
||||
{
|
||||
/* Overrun/Underrun */
|
||||
status_errno = ENXIO;
|
||||
}
|
||||
else if (status & I2C_SR1_OVR)
|
||||
{
|
||||
/* Overrun/Underrun */
|
||||
|
||||
status_errno = EIO;
|
||||
}
|
||||
else if (status & I2C_SR1_PECERR)
|
||||
{
|
||||
/* PEC Error in reception */
|
||||
status_errno = EIO;
|
||||
}
|
||||
else if (status & I2C_SR1_PECERR)
|
||||
{
|
||||
/* PEC Error in reception */
|
||||
|
||||
status_errno = EPROTO;
|
||||
}
|
||||
else if (status & I2C_SR1_TIMEOUT)
|
||||
{
|
||||
/* Timeout or Tlow Error */
|
||||
status_errno = EPROTO;
|
||||
}
|
||||
else if (status & I2C_SR1_TIMEOUT)
|
||||
{
|
||||
/* Timeout or Tlow Error */
|
||||
|
||||
status_errno = ETIME;
|
||||
status_errno = ETIME;
|
||||
}
|
||||
|
||||
/* This is not an error and should never happen since SMBus is not enabled */
|
||||
|
||||
else if (status & I2C_SR1_SMBALERT)
|
||||
{
|
||||
/* SMBus alert is an optional signal with an interrupt line for devices
|
||||
* that want to trade their ability to master for a pin.
|
||||
*/
|
||||
|
||||
status_errno = EINTR;
|
||||
}
|
||||
}
|
||||
|
||||
/* This is not an error, but should not happen. The BUSY signal can hang,
|
||||
|
@ -982,17 +996,6 @@ int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int
|
|||
status_errno = EBUSY;
|
||||
}
|
||||
|
||||
/* This is not an error and should never happen since SMBus is not enabled */
|
||||
|
||||
else if (status & I2C_SR1_SMBALERT)
|
||||
{
|
||||
/* SMBus alert is an optional signal with an interrupt line for devices
|
||||
* that want to trade their ability to master for a pin.
|
||||
*/
|
||||
|
||||
status_errno = EINTR;
|
||||
}
|
||||
|
||||
/* Re-enable the FSMC */
|
||||
|
||||
stm32_i2c_enablefsmc(ahbenr);
|
||||
|
|
|
@ -255,6 +255,42 @@ EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
|
|||
EXTERN void stm3210e_lcdclear(uint16_t color);
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_lm75initialize
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_STM32_I2C1)
|
||||
EXTERN int stm32_lm75initialize(FAR const char *devpath);
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_lm75attach
|
||||
*
|
||||
* Description:
|
||||
* Attach the LM-75 interrupt handler
|
||||
*
|
||||
* Input parameters:
|
||||
* irqhandler - the LM-75 interrupt handler
|
||||
*
|
||||
* Returned Value:
|
||||
* The previous LM-75 interrupt handler
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_STM32_I2C1)
|
||||
EXTERN xcpt_t stm32_lm75attach(xcpt_t irqhandler);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
|
4
configs/stm3210e-eval/src/Makefile
Executable file → Normal file
4
configs/stm3210e-eval/src/Makefile
Executable file → Normal file
|
@ -56,6 +56,10 @@ ifeq ($(CONFIG_USBSTRG),y)
|
|||
CSRCS += up_usbstrg.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_I2C_LM75),y)
|
||||
CSRCS += up_lm75.c
|
||||
endif
|
||||
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
|
|
0
configs/stm3210e-eval/src/README.txt
Executable file → Normal file
0
configs/stm3210e-eval/src/README.txt
Executable file → Normal file
559
configs/stm3210e-eval/src/stm3210e-internal.h
Executable file → Normal file
559
configs/stm3210e-eval/src/stm3210e-internal.h
Executable file → Normal file
|
@ -1,277 +1,282 @@
|
|||
/************************************************************************************
|
||||
* configs/stm3210e_eval/src/stm3210e_internal.h
|
||||
* arch/arm/src/board/stm3210e_internal.n
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __CONFIGS_STM3210E_EVAL_SRC_STM3210E_INTERNAL_H
|
||||
#define __CONFIGS_STM3210E_EVAL_SRC_STM3210E_INTERNAL_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/************************************************************************************
|
||||
* Definitions
|
||||
************************************************************************************/
|
||||
|
||||
/* How many SPI modules does this chip support? The LM3S6918 supports 2 SPI
|
||||
* modules (others may support more -- in such case, the following must be
|
||||
* expanded).
|
||||
*/
|
||||
|
||||
#if STM32_NSPI < 1
|
||||
# undef CONFIG_STM32_SPI1
|
||||
# undef CONFIG_STM32_SPI2
|
||||
#elif STM32_NSPI < 2
|
||||
# undef CONFIG_STM32_SPI2
|
||||
#endif
|
||||
|
||||
/* STM3210E-EVAL GPIOs **************************************************************/
|
||||
|
||||
/* LEDs */
|
||||
|
||||
#define GPIO_LED1 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN6)
|
||||
#define GPIO_LED2 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN7)
|
||||
#define GPIO_LED3 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN8)
|
||||
#define GPIO_LED4 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN9)
|
||||
|
||||
/* BUTTONS -- NOTE that some have EXTI interrupts configured */
|
||||
|
||||
#define MIN_IRQBUTTON BUTTON_KEY
|
||||
#define MAX_IRQBUTTON JOYSTICK_UP
|
||||
#define NUM_IRQBUTTONS (JOYSTICK_UP - BUTTON_KEY + 1)
|
||||
|
||||
#define GPIO_BTN_WAKEUP (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_PORTA|GPIO_PIN0)
|
||||
#define GPIO_BTN_TAMPER (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_PORTC|GPIO_PIN13)
|
||||
#define GPIO_BTN_KEY (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTG|GPIO_PIN8)
|
||||
#define GPIO_JOY_SEL (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTG|GPIO_PIN7)
|
||||
#define GPIO_JOY_DOWN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTD|GPIO_PIN3)
|
||||
#define GPIO_JOY_LEFT (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTG|GPIO_PIN14)
|
||||
#define GPIO_JOY_RIGHT (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTG|GPIO_PIN13)
|
||||
#define GPIO_JOY_UP (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTG|GPIO_PIN15)
|
||||
|
||||
/* SPI FLASH chip select: PA.4 */
|
||||
|
||||
#define GPIO_FLASH_CS (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN2)
|
||||
|
||||
/* USB Soft Connect Pullup: PB.14 */
|
||||
|
||||
#define GPIO_USB_PULLUP (GPIO_OUTPUT|GPIO_CNF_OUTOD|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN14)
|
||||
|
||||
/************************************************************************************
|
||||
* Public Types
|
||||
************************************************************************************/
|
||||
|
||||
/* GPIO settings that will be altered when external memory is selected */
|
||||
|
||||
struct extmem_save_s
|
||||
{
|
||||
uint32_t gpiod_crl;
|
||||
uint32_t gpiod_crh;
|
||||
uint32_t gpioe_crl;
|
||||
uint32_t gpioe_crh;
|
||||
uint32_t gpiof_crl;
|
||||
uint32_t gpiof_crh;
|
||||
uint32_t gpiog_crl;
|
||||
uint32_t gpiog_crh;
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
* Public data
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/* GPIO configurations common to SRAM and NOR Flash */
|
||||
|
||||
#define NCOMMON_CONFIG 37
|
||||
extern const uint16_t g_commonconfig[NCOMMON_CONFIG];
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_spiinitialize
|
||||
*
|
||||
* Description:
|
||||
* Called to configure SPI chip select GPIO pins for the STM3210E-EVAL board.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void weak_function stm32_spiinitialize(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_usbinitialize
|
||||
*
|
||||
* Description:
|
||||
* Called to setup USB-related GPIO pins for the STM3210E-EVAL board.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void weak_function stm32_usbinitialize(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_extcontextsave
|
||||
*
|
||||
* Description:
|
||||
* Save current GPIOs that will used by external memory configurations
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifdef CONFIG_STM32_FSMC
|
||||
extern void stm32_extcontextsave(struct extmem_save_s *save);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_extcontextrestore
|
||||
*
|
||||
* Description:
|
||||
* Restore GPIOs that were used by external memory configurations
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_extcontextrestore(struct extmem_save_s *restore);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_extmemgpios
|
||||
*
|
||||
* Description:
|
||||
* Initialize GPIOs for NOR or SRAM
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_extmemgpios(const uint16_t *gpios, int ngpios);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_enablefsmc
|
||||
*
|
||||
* Description:
|
||||
* enable clocking to the FSMC module
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_enablefsmc(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_disablefsmc
|
||||
*
|
||||
* Description:
|
||||
* enable clocking to the FSMC module
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_disablefsmc(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_selectnor
|
||||
*
|
||||
* Description:
|
||||
* Initialize to access NOR flash
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_selectnor(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_deselectnor
|
||||
*
|
||||
* Description:
|
||||
* Disable NOR FLASH
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_deselectnor(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_selectsram
|
||||
*
|
||||
* Description:
|
||||
* Initialize to access external SRAM
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_selectsram(void);
|
||||
/************************************************************************************
|
||||
* Name: stm32_deselectsram
|
||||
*
|
||||
* Description:
|
||||
* Disable external SRAM
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_deselectsram(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_selectlcd
|
||||
*
|
||||
* Description:
|
||||
* Initialize to the LCD
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_selectlcd(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_deselectlcd
|
||||
*
|
||||
* Description:
|
||||
* Disable the LCD
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_deselectlcd(void);
|
||||
|
||||
#endif /* CONFIG_STM32_FSMC */
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __CONFIGS_STM3210E_EVAL_SRC_STM3210E_INTERNAL_H */
|
||||
|
||||
/************************************************************************************
|
||||
* configs/stm3210e_eval/src/stm3210e_internal.h
|
||||
* arch/arm/src/board/stm3210e_internal.n
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __CONFIGS_STM3210E_EVAL_SRC_STM3210E_INTERNAL_H
|
||||
#define __CONFIGS_STM3210E_EVAL_SRC_STM3210E_INTERNAL_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/************************************************************************************
|
||||
* Definitions
|
||||
************************************************************************************/
|
||||
|
||||
/* How many SPI modules does this chip support? The LM3S6918 supports 2 SPI
|
||||
* modules (others may support more -- in such case, the following must be
|
||||
* expanded).
|
||||
*/
|
||||
|
||||
#if STM32_NSPI < 1
|
||||
# undef CONFIG_STM32_SPI1
|
||||
# undef CONFIG_STM32_SPI2
|
||||
#elif STM32_NSPI < 2
|
||||
# undef CONFIG_STM32_SPI2
|
||||
#endif
|
||||
|
||||
/* STM3210E-EVAL GPIOs **************************************************************/
|
||||
/* LEDs */
|
||||
|
||||
#define GPIO_LED1 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN6)
|
||||
#define GPIO_LED2 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN7)
|
||||
#define GPIO_LED3 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN8)
|
||||
#define GPIO_LED4 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN9)
|
||||
|
||||
/* BUTTONS -- NOTE that some have EXTI interrupts configured */
|
||||
|
||||
#define MIN_IRQBUTTON BUTTON_KEY
|
||||
#define MAX_IRQBUTTON JOYSTICK_UP
|
||||
#define NUM_IRQBUTTONS (JOYSTICK_UP - BUTTON_KEY + 1)
|
||||
|
||||
#define GPIO_BTN_WAKEUP (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_PORTA|GPIO_PIN0)
|
||||
#define GPIO_BTN_TAMPER (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_PORTC|GPIO_PIN13)
|
||||
#define GPIO_BTN_KEY (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTG|GPIO_PIN8)
|
||||
#define GPIO_JOY_SEL (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTG|GPIO_PIN7)
|
||||
#define GPIO_JOY_DOWN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTD|GPIO_PIN3)
|
||||
#define GPIO_JOY_LEFT (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTG|GPIO_PIN14)
|
||||
#define GPIO_JOY_RIGHT (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTG|GPIO_PIN13)
|
||||
#define GPIO_JOY_UP (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\
|
||||
GPIO_EXTI|GPIO_PORTG|GPIO_PIN15)
|
||||
|
||||
/* SPI FLASH chip select: PA.4 */
|
||||
|
||||
#define GPIO_FLASH_CS (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN2)
|
||||
|
||||
/* USB Soft Connect Pullup: PB.14 */
|
||||
|
||||
#define GPIO_USB_PULLUP (GPIO_OUTPUT|GPIO_CNF_OUTOD|GPIO_MODE_50MHz|\
|
||||
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN14)
|
||||
|
||||
/* LM-75 Temperature Sensor: PB.5 */
|
||||
|
||||
#define GPIO_LM75_OSINT (GPIO_INPUT|GPIO_CNF_INPULLUP|GPIO_MODE_10MHz|\
|
||||
GPIO_EXTI|GPIO_PORTB|GPIO_PIN5)
|
||||
|
||||
/************************************************************************************
|
||||
* Public Types
|
||||
************************************************************************************/
|
||||
|
||||
/* GPIO settings that will be altered when external memory is selected */
|
||||
|
||||
struct extmem_save_s
|
||||
{
|
||||
uint32_t gpiod_crl;
|
||||
uint32_t gpiod_crh;
|
||||
uint32_t gpioe_crl;
|
||||
uint32_t gpioe_crh;
|
||||
uint32_t gpiof_crl;
|
||||
uint32_t gpiof_crh;
|
||||
uint32_t gpiog_crl;
|
||||
uint32_t gpiog_crh;
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
* Public data
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/* GPIO configurations common to SRAM and NOR Flash */
|
||||
|
||||
#define NCOMMON_CONFIG 37
|
||||
extern const uint16_t g_commonconfig[NCOMMON_CONFIG];
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_spiinitialize
|
||||
*
|
||||
* Description:
|
||||
* Called to configure SPI chip select GPIO pins for the STM3210E-EVAL board.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void weak_function stm32_spiinitialize(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_usbinitialize
|
||||
*
|
||||
* Description:
|
||||
* Called to setup USB-related GPIO pins for the STM3210E-EVAL board.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void weak_function stm32_usbinitialize(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_extcontextsave
|
||||
*
|
||||
* Description:
|
||||
* Save current GPIOs that will used by external memory configurations
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifdef CONFIG_STM32_FSMC
|
||||
extern void stm32_extcontextsave(struct extmem_save_s *save);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_extcontextrestore
|
||||
*
|
||||
* Description:
|
||||
* Restore GPIOs that were used by external memory configurations
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_extcontextrestore(struct extmem_save_s *restore);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_extmemgpios
|
||||
*
|
||||
* Description:
|
||||
* Initialize GPIOs for NOR or SRAM
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_extmemgpios(const uint16_t *gpios, int ngpios);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_enablefsmc
|
||||
*
|
||||
* Description:
|
||||
* enable clocking to the FSMC module
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_enablefsmc(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_disablefsmc
|
||||
*
|
||||
* Description:
|
||||
* enable clocking to the FSMC module
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_disablefsmc(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_selectnor
|
||||
*
|
||||
* Description:
|
||||
* Initialize to access NOR flash
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_selectnor(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_deselectnor
|
||||
*
|
||||
* Description:
|
||||
* Disable NOR FLASH
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_deselectnor(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_selectsram
|
||||
*
|
||||
* Description:
|
||||
* Initialize to access external SRAM
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_selectsram(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_deselectsram
|
||||
*
|
||||
* Description:
|
||||
* Disable external SRAM
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_deselectsram(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_selectlcd
|
||||
*
|
||||
* Description:
|
||||
* Initialize to the LCD
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_selectlcd(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_deselectlcd
|
||||
*
|
||||
* Description:
|
||||
* Disable the LCD
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
extern void stm32_deselectlcd(void);
|
||||
|
||||
#endif /* CONFIG_STM32_FSMC */
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __CONFIGS_STM3210E_EVAL_SRC_STM3210E_INTERNAL_H */
|
||||
|
||||
|
|
0
configs/stm3210e-eval/src/up_boot.c
Executable file → Normal file
0
configs/stm3210e-eval/src/up_boot.c
Executable file → Normal file
0
configs/stm3210e-eval/src/up_lcd.c
Executable file → Normal file
0
configs/stm3210e-eval/src/up_lcd.c
Executable file → Normal file
0
configs/stm3210e-eval/src/up_leds.c
Executable file → Normal file
0
configs/stm3210e-eval/src/up_leds.c
Executable file → Normal file
128
configs/stm3210e-eval/src/up_lm75.c
Normal file
128
configs/stm3210e-eval/src/up_lm75.c
Normal file
|
@ -0,0 +1,128 @@
|
|||
/************************************************************************************
|
||||
* configs/stm3210e-eval/src/up_lm75.c
|
||||
* arch/arm/src/board/up_lm75.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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 "stm32.h"
|
||||
#include "stm32_i2c.h"
|
||||
#include "stm3210e-internal.h"
|
||||
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_STM32_I2C1)
|
||||
|
||||
/************************************************************************************
|
||||
* Definitions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_lm75initialize
|
||||
*
|
||||
* 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 stm32_lm75initialize(FAR const char *devpath)
|
||||
{
|
||||
FAR struct i2c_dev_s *i2c;
|
||||
int ret;
|
||||
|
||||
/* Configure PB.5 as Input pull-up. This pin can be used as a temperature
|
||||
* sensor interrupt (not fully implemented).
|
||||
*/
|
||||
|
||||
stm32_configgpio(GPIO_LM75_OSINT);
|
||||
|
||||
/* Get an instance of the I2C1 interface */
|
||||
|
||||
i2c = up_i2cinitialize(1);
|
||||
if (!i2c)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Then register the temperature sensor */
|
||||
|
||||
ret = lm75_register(devpath, i2c, 0x48);
|
||||
if (ret < 0)
|
||||
{
|
||||
(void)up_i2cuninitialize(i2c);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_lm75attach
|
||||
*
|
||||
* Description:
|
||||
* Attach the LM-75 interrupt handler
|
||||
*
|
||||
* Input parameters:
|
||||
* irqhandler - the LM-75 interrupt handler
|
||||
*
|
||||
* Returned Value:
|
||||
* The previous LM-75 interrupt handler
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
xcpt_t stm32_lm75attach(xcpt_t irqhandler)
|
||||
{
|
||||
return stm32_gpiosetevent(GPIO_LM75_OSINT, true, true, true, irqhandler);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_I2C && CONFIG_I2C_LM75 && CONFIG_STM32_I2C1 */
|
0
configs/stm3210e-eval/src/up_nsh.c
Executable file → Normal file
0
configs/stm3210e-eval/src/up_nsh.c
Executable file → Normal file
0
configs/stm3210e-eval/src/up_spi.c
Executable file → Normal file
0
configs/stm3210e-eval/src/up_spi.c
Executable file → Normal file
0
configs/stm3210e-eval/src/up_usbstrg.c
Executable file → Normal file
0
configs/stm3210e-eval/src/up_usbstrg.c
Executable file → Normal file
|
@ -38,6 +38,10 @@
|
|||
|
||||
ifeq ($(CONFIG_I2C),y)
|
||||
CSRCS += lis331dl.c
|
||||
|
||||
ifeq ($(CONFIG_I2C_LM75),y)
|
||||
CSRCS += lm75.c
|
||||
endif
|
||||
endif
|
||||
|
||||
# Include sensor driver build support
|
||||
|
|
473
drivers/sensors/lm75.c
Normal file
473
drivers/sensors/lm75.c
Normal file
|
@ -0,0 +1,473 @@
|
|||
/****************************************************************************
|
||||
* drivers/sensors/lm75.c
|
||||
* Character driver for the STMicro LM-75 Temperature Sensor
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <fixedmath.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs.h>
|
||||
#include <nuttx/i2c.h>
|
||||
#include <nuttx/sensors/lm75.h>
|
||||
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Centigrade to Fahrenheit conversion: F = 9*C/5 + 32 */
|
||||
|
||||
#define B16_9DIV5 (9 * 65536 / 5)
|
||||
#define B16_32 (32 * 65536);
|
||||
|
||||
/****************************************************************************
|
||||
* Private
|
||||
****************************************************************************/
|
||||
|
||||
struct lm75_dev_s
|
||||
{
|
||||
FAR struct i2c_dev_s *i2c; /* I2C interface */
|
||||
uint8_t addr; /* I2C address */
|
||||
bool fahrenheit; /* true: temperature will be reported in fahrenheit */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
/* I2C Helpers */
|
||||
|
||||
static int lm75_readb8(FAR struct lm75_dev_s *priv, uint8_t regaddr,
|
||||
FAR b8_t *regvalue);
|
||||
#if 0 // Not used
|
||||
static int lm75_writeb8(FAR struct lm75_dev_s *priv, uint8_t regaddr,
|
||||
b8_t regval);
|
||||
#endif
|
||||
static int lm75_readtemp(FAR struct lm75_dev_s *priv, b16_t *temp);
|
||||
static int lm75_readconf(FAR struct lm75_dev_s *priv, uint8_t *conf);
|
||||
static int lm75_writeconf(FAR struct lm75_dev_s *priv, uint8_t conf);
|
||||
|
||||
/* Character driver methods */
|
||||
|
||||
static int lm75_open(FAR struct file *filep);
|
||||
static int lm75_close(FAR struct file *filep);
|
||||
static ssize_t lm75_read(FAR struct file *, FAR char *, size_t);
|
||||
static ssize_t lm75_write(FAR struct file *filep, FAR const char *buffer, size_t buflen);
|
||||
static int lm75_ioctl(FAR struct file *filep,int cmd,unsigned long arg);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const struct file_operations lm75_fops =
|
||||
{
|
||||
lm75_open,
|
||||
lm75_close,
|
||||
lm75_read,
|
||||
lm75_write,
|
||||
0,
|
||||
lm75_ioctl
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
, 0
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: lm75_readb8
|
||||
*
|
||||
* Description:
|
||||
* Read a 16-bit register (LM75_TEMP_REG, LM75_THYS_REG, or LM75_TOS_REG)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lm75_readb8(FAR struct lm75_dev_s *priv, uint8_t regaddr,
|
||||
FAR b8_t *regvalue)
|
||||
{
|
||||
uint8_t buffer[2];
|
||||
int ret;
|
||||
|
||||
/* Write the register address */
|
||||
|
||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||
ret = I2C_WRITE(priv->i2c, ®addr, 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Restart and read 16-bits from the register (discarding 7) */
|
||||
|
||||
ret = I2C_READ(priv->i2c, buffer, 2);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Data format is: TTTTTTTT Txxxxxxx where TTTTTTTTT is a nine-bit
|
||||
* temperature value with LSB = 0.5 degrees centigrade. So the raw
|
||||
* data is b8_t
|
||||
*/
|
||||
|
||||
*regvalue = (b8_t)buffer[0] << 8 | (b8_t)buffer[1];
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm75_writeb8
|
||||
*
|
||||
* Description:
|
||||
* Write to a 16-bit register (LM75_TEMP_REG, LM75_THYS_REG, or LM75_TOS_REG)
|
||||
*
|
||||
****************************************************************************/
|
||||
#if 0 // Not used
|
||||
static int lm75_writeb8(FAR struct lm75_dev_s *priv, uint8_t regaddr,
|
||||
b8_t regval)
|
||||
{
|
||||
uint8_t buffer[3];
|
||||
|
||||
/* Set up a 3 byte message to send */
|
||||
|
||||
buffer[0] = regaddr;
|
||||
buffer[1] = regval >> 8;
|
||||
buffer[2] = regval;
|
||||
|
||||
/* Write the register address followed by the data (no RESTART) */
|
||||
|
||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||
return I2C_WRITE(priv->i2c, buffer, 3);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm75_readtemp
|
||||
*
|
||||
* Description:
|
||||
* Read the temperature register with special scaling (LM75_TEMP_REG)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lm75_readtemp(FAR struct lm75_dev_s *priv, b16_t *temp)
|
||||
{
|
||||
b8_t temp8;
|
||||
b16_t temp16;
|
||||
int ret;
|
||||
|
||||
/* Read the raw temperature data. Data format is: TTTTTTTT Txxxxxxx where
|
||||
* TTTTTTTTT is a nine-bit temperature value with LSB = 0.5 degrees centigrade.
|
||||
* So the raw data is b8_t.
|
||||
*/
|
||||
|
||||
ret = lm75_readb8(priv, LM75_TEMP_REG, &temp8);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Convert to b16_t */
|
||||
|
||||
temp16 = b8tob16(temp8);
|
||||
|
||||
/* Was fahrenheit requested? */
|
||||
|
||||
if (priv->fahrenheit)
|
||||
{
|
||||
/* Centigrade to Fahrenheit conversion: F = 9*C/5 + 32 */
|
||||
|
||||
temp16 = b16mulb16(temp16, B16_9DIV5) + B16_32;
|
||||
}
|
||||
|
||||
*temp = temp16;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm75_readconf
|
||||
*
|
||||
* Description:
|
||||
* Read the 8-bit LM75 configuration register
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lm75_readconf(FAR struct lm75_dev_s *priv, uint8_t *conf)
|
||||
{
|
||||
uint8_t buffer;
|
||||
int ret;
|
||||
|
||||
/* Write the configuration register address */
|
||||
|
||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||
|
||||
buffer = LM75_CONF_REG;
|
||||
ret = I2C_WRITE(priv->i2c, &buffer, 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Restart and read 8-bits from the register */
|
||||
|
||||
ret = I2C_READ(priv->i2c, conf, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm75_writeconf
|
||||
*
|
||||
* Description:
|
||||
* Write to a 8-bit LM75 configuration register.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lm75_writeconf(FAR struct lm75_dev_s *priv, uint8_t conf)
|
||||
{
|
||||
uint8_t buffer[2];
|
||||
|
||||
/* Set up a 2 byte message to send */
|
||||
|
||||
buffer[0] = LM75_CONF_REG;
|
||||
buffer[1] = conf;
|
||||
|
||||
/* Write the register address followed by the data (no RESTART) */
|
||||
|
||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||
return I2C_WRITE(priv->i2c, buffer, 2);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm75_open
|
||||
*
|
||||
* Description:
|
||||
* This function is called whenever the LM-75 device is opened.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lm75_open(FAR struct file *filep)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm75_close
|
||||
*
|
||||
* Description:
|
||||
* This routine is called when the LM-75 device is closed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lm75_close(FAR struct file *filep)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm75_read
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t lm75_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct lm75_dev_s *priv = inode->i_private;
|
||||
FAR b16_t *ptr;
|
||||
ssize_t nsamples;
|
||||
int ret;
|
||||
|
||||
/* How many samples were requested to get? */
|
||||
|
||||
nsamples = buflen/sizeof(b16_t);
|
||||
ptr = (FAR b16_t *)buffer;
|
||||
|
||||
/* Get the requested number of samples */
|
||||
|
||||
for (; nsamples > 0; nsamples--)
|
||||
{
|
||||
b16_t temp;
|
||||
|
||||
/* Read the next b16_t temperature value */
|
||||
|
||||
ret = lm75_readtemp(priv, &temp);
|
||||
if (ret < 0)
|
||||
{
|
||||
return (ssize_t)ret;
|
||||
}
|
||||
|
||||
/* Save the temperature value in the user buffer */
|
||||
|
||||
*ptr++ = temp;
|
||||
}
|
||||
|
||||
return nsamples * sizeof(b16_t);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm75_write
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t lm75_write(FAR struct file *filep, FAR const char *buffer,
|
||||
size_t buflen)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm75_ioctl
|
||||
****************************************************************************/
|
||||
|
||||
static int lm75_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct lm75_dev_s *priv = inode->i_private;
|
||||
int ret = OK;
|
||||
|
||||
switch (arg)
|
||||
{
|
||||
/* Read from the configuration register. Arg: uint8_t* pointer */
|
||||
|
||||
case SNIOC_READCONF:
|
||||
{
|
||||
FAR uint8_t *ptr = (FAR uint8_t *)((uintptr_t)arg);
|
||||
ret = lm75_readconf(priv, ptr);
|
||||
}
|
||||
break;
|
||||
|
||||
/* Wrtie to the configuration register. Arg: uint8_t value */
|
||||
|
||||
case SNIOC_WRITECONF:
|
||||
ret = lm75_writeconf(priv, (uint8_t)arg);
|
||||
break;
|
||||
|
||||
/* Shutdown the LM75, Arg: None */
|
||||
|
||||
case SNIOC_SHUTDOWN:
|
||||
{
|
||||
uint8_t conf;
|
||||
ret = lm75_readconf(priv, &conf);
|
||||
if (ret == OK)
|
||||
{
|
||||
ret = lm75_writeconf(priv, conf | LM75_CONF_SHUTDOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Powerup the LM75, Arg: None */
|
||||
|
||||
case SNIOC_POWERUP:
|
||||
{
|
||||
uint8_t conf;
|
||||
ret = lm75_readconf(priv, &conf);
|
||||
if (ret == OK)
|
||||
{
|
||||
ret = lm75_writeconf(priv, conf & ~LM75_CONF_SHUTDOWN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Report samples in Fahrenheit */
|
||||
|
||||
case SNIOC_FAHRENHEIT:
|
||||
priv->fahrenheit = true;
|
||||
break;
|
||||
|
||||
/* Report Samples in Centigrade */
|
||||
|
||||
case SNIOC_CENTIGRADE:
|
||||
priv->fahrenheit = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = -ENOTTY;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm75_register
|
||||
*
|
||||
* Description:
|
||||
* Register the LM-75 character device as 'devpath'
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
|
||||
* i2c - An instance of the I2C interface to use to communicate with LM75
|
||||
* addr - The I2C address of the LM-75. The base I2C address of the LM75
|
||||
* is 0x48. Bits 0-3 can be controlled to get 8 unique addresses from 0x48
|
||||
* through 0x4f.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int lm75_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, uint8_t addr)
|
||||
{
|
||||
FAR struct lm75_dev_s *priv;
|
||||
int ret;
|
||||
|
||||
/* Initialize the LM-75 device structure */
|
||||
|
||||
priv = (FAR struct lm75_dev_s *)malloc(sizeof(struct lm75_dev_s));
|
||||
if (!priv)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
priv->i2c = i2c;
|
||||
priv->addr = addr;
|
||||
priv->fahrenheit = false;
|
||||
|
||||
/* Register the character driver */
|
||||
|
||||
ret = register_driver(devpath, &lm75_fops, 0555, priv);
|
||||
if (ret < 0)
|
||||
{
|
||||
free(priv);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_I2C && CONFIG_I2C_LM75 */
|
|
@ -60,6 +60,7 @@
|
|||
#define _SIOCBASE (0x8b00) /* Socket ioctl commands */
|
||||
#define _ARPBASE (0x8c00) /* ARP ioctl commands */
|
||||
#define _TSBASE (0x8d00) /* Touchscreen ioctl commands */
|
||||
#define _SNBASE (0x8e00) /* Sensor ioctl commands */
|
||||
|
||||
/* Macros used to manage ioctl commands */
|
||||
|
||||
|
@ -161,11 +162,16 @@
|
|||
#define _ARPIOCVALID(c) (_IOC_TYPE(c)==_ARPBASE)
|
||||
#define _ARPIOC(nr) _IOC(_ARPBASE,nr)
|
||||
|
||||
/* NuttX ARP touchscrren ioctl definitions (see nuttx/input/touchscreen.h) **/
|
||||
/* NuttX ARP touchscreen ioctl definitions (see nuttx/input/touchscreen.h) **/
|
||||
|
||||
#define _TSIOCVALID(c) (_IOC_TYPE(c)==_TSBASE)
|
||||
#define _TSIOC(nr) _IOC(_TSBASE,nr)
|
||||
|
||||
/* NuttX ARP sensor ioctl definitions (see nuttx/sensor/*.h) ****************/
|
||||
|
||||
#define _SNIOCVALID(c) (_IOC_TYPE(c)==_SNBASE)
|
||||
#define _SNIOC(nr) _IOC(_SNBASE,nr)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
|
129
include/nuttx/sensors/lm75.h
Normal file
129
include/nuttx/sensors/lm75.h
Normal file
|
@ -0,0 +1,129 @@
|
|||
/****************************************************************************
|
||||
* include/nuttx/lm75.h
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __NUTTX_SENSORSD_LM75_H
|
||||
#define __NUTTX_SENSORSD_LM75_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/ioctl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************
|
||||
* CONFIG_I2C - Enables support for I2C drivers
|
||||
* CONFIG_I2C_LM75 - Enables support for the LM-75 driver
|
||||
*/
|
||||
|
||||
#define CONFIG_LM75_BASEADDR 0x48
|
||||
|
||||
/* IOCTL Commands ***********************************************************/
|
||||
|
||||
#define SNIOC_READCONF _SNIOC(0x0001) /* Arg: uint8_t* pointer */
|
||||
#define SNIOC_WRITECONF _SNIOC(0x0002) /* Arg: uint8_t value */
|
||||
#define SNIOC_SHUTDOWN _SNIOC(0x0003) /* Arg: None */
|
||||
#define SNIOC_POWERUP _SNIOC(0x0004) /* Arg: None */
|
||||
#define SNIOC_FAHRENHEIT _SNIOC(0x0005) /* Arg: None */
|
||||
#define SNIOC_CENTIGRADE _SNIOC(0x0006) /* Arg: None */
|
||||
|
||||
/* LM-75 Register Definitions ***********************************************/
|
||||
/* LM-75 Registers addresses */
|
||||
|
||||
#define LM75_TEMP_REG 0x00 /* Temperature Register */
|
||||
#define LM75_CONF_REG 0x01 /* Configuration Register */
|
||||
#define LM75_THYS_REG 0x02 /* Temperature Register */
|
||||
#define LM75_TOS_REG 0x03 /* Over-temp Shutdown threshold Register */
|
||||
|
||||
/* Configuration Register Bit Definitions */
|
||||
|
||||
#define LM75_CONF_SHUTDOWN (1 << 0) /* Bit 0: Put LM75 goes in low power shutdown mode */
|
||||
#define LM75_CONF_INTMODE (1 << 1) /* Bit 1: 0=Comparator 1=Interrupt mode */
|
||||
#define LM75_CONF_POLARITY (1 << 2) /* Bit 2: 0=O.S. Active low 1=active high */
|
||||
#define LM75_CONF_FAULTQ (3) /* Bits 3-4: # faults before setting O.S. */
|
||||
|
||||
/* NOTE: When temperature values are read, they are return as b16_t, fixed
|
||||
* precision integer values (see include/fixedmath.h).
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Global Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Global Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Global Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lm75_register
|
||||
*
|
||||
* Description:
|
||||
* Register the LM-75 character device as 'devpath'
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
|
||||
* i2c - An instance of the I2C interface to use to communicate with LM75
|
||||
* addr - The I2C address of the LM-75. The base I2C address of the LM75
|
||||
* is 0x48. Bits 0-3 can be controlled to get 8 unique addresses from 0x48
|
||||
* through 0x4f.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int lm75_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c,
|
||||
uint8_t addr);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NUTTX_SENSORSD_LM75_H */
|
Loading…
Reference in a new issue