Add driver to read temperature from lm75 chip.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 5 Oct 2009 19:24:08 +0000 (19:24 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 5 Oct 2009 19:24:08 +0000 (19:24 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3033 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/cfg/cfg_lm75.h [new file with mode: 0644]
bertos/drv/lm75.c [new file with mode: 0644]
bertos/drv/lm75.h [new file with mode: 0644]
bertos/hw/hw_lm75.h [new file with mode: 0644]

diff --git a/bertos/cfg/cfg_lm75.h b/bertos/cfg/cfg_lm75.h
new file mode 100644 (file)
index 0000000..91b347a
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief Configuration file for the LM75 sensor temperature.
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#ifndef CFG_LM75_H
+#define CFG_LM75_H
+
+/**
+ * Module logging level.
+ *
+ * $WIZ$ type = "enum"
+ * $WIZ$ value_list = "log_level"
+ */
+#define LM75_LOG_LEVEL      LOG_LVL_WARN
+
+/**
+ * Module logging format.
+ *
+ * $WIZ$ type = "enum"
+ * $WIZ$ value_list = "log_format"
+ */
+#define LM75_LOG_FORMAT     LOG_FMT_TERSE
+
+#endif /* CFG_AX25_H */
diff --git a/bertos/drv/lm75.c b/bertos/drv/lm75.c
new file mode 100644 (file)
index 0000000..845fa3a
--- /dev/null
@@ -0,0 +1,84 @@
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief LM75 sensor temperature family.
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ *
+ */
+
+#include "lm75.h"
+
+#include "hw/hw_lm75.h"
+
+#include "cfg/cfg_lm75.h"
+
+#include <cfg/debug.h>
+
+// Define logging setting (for cfg/log.h module).
+#define LOG_LEVEL   LM75_LOG_LEVEL
+#define LOG_FORMAT  LM75_LOG_FORMAT
+
+#include <cfg/log.h>
+
+#include <drv/i2c.h>
+
+#define SELECT_ADDRESS(addr)   LM75_ADDRESS_BYTE | (addr << 1)
+
+deci_celsius_t lm75_read(addr_t sens_addr)
+{
+       uint8_t data[2];
+       int16_t degree;
+       int16_t deci_degree;
+
+       i2c_start_w(SELECT_ADDRESS(sens_addr));
+       i2c_put(LM75_PAD_BYTE);
+       i2c_start_r(SELECT_ADDRESS(sens_addr));
+       i2c_recv(&data, sizeof(data));
+
+       degree = (uint16_t)data[0];
+       deci_degree = (uint16_t)(((data[1] >> 7) & 1 ) * 5);
+
+       LOG_INFO("[%d.%d C]\n", degree, deci_degree);
+
+       return degree * 10 + deci_degree;
+}
+
+void lm75_init(void)
+{
+       i2c_init();
+       LOG_INFO("Init I2C module.\n");
+
+       LM75_HW_INIT();
+}
+
+
diff --git a/bertos/drv/lm75.h b/bertos/drv/lm75.h
new file mode 100644 (file)
index 0000000..8c7ee4e
--- /dev/null
@@ -0,0 +1,58 @@
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief LM75 sensor temperature family.
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ *
+ * $WIZ$ module_name = "lm75"
+ * $WIZ$ module_depends = "timer", "i2c"
+ * $WIZ$ module_configuration = "bertos/cfg/cfg_lm75.h"
+ * $WIZ$ module_hw = "bertos/hw/hw_lm75.h"
+ */
+
+#ifndef DRV_LM75_H
+#define DRV_LM75_H
+
+#include <cpu/types.h>
+
+#define LM75_ADDRESS_BYTE    0x91
+#define LM75_PAD_BYTE        0x0
+
+typedef int16_t deci_celsius_t;
+typedef uint8_t addr_t;
+
+deci_celsius_t lm75_read(addr_t sens_addr);
+
+void lm75_init(void);
+
+#endif /* DRV_LM75_H */
diff --git a/bertos/hw/hw_lm75.h b/bertos/hw/hw_lm75.h
new file mode 100644 (file)
index 0000000..290dae0
--- /dev/null
@@ -0,0 +1,49 @@
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
+ * All Rights Reserved.
+ * -->
+ *
+ * \brief Hardware macro definition.
+ *
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+#ifndef HW_LM75_H
+#define HW_LM75_H
+
+#warning TODO:This is an example implentation, you must implement it!
+
+#define LM75_HW_INIT() \
+       do { \
+       /* Pin init */\
+       } while (0)
+
+#endif /* HW_LM75_H */
+