Merged from external project:
authorbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 9 Oct 2008 14:04:34 +0000 (14:04 +0000)
committerbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 9 Oct 2008 14:04:34 +0000 (14:04 +0000)
**********
r22497 | batt | 2008-10-08 19:01:03 +0200 (Wed, 08 Oct 2008) | 1 line

Add first skel of PCF8574 driver.
**********

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1887 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/drv/pcf8574.c [new file with mode: 0644]
bertos/drv/pcf8574.h [new file with mode: 0644]

diff --git a/bertos/drv/pcf8574.c b/bertos/drv/pcf8574.c
new file mode 100644 (file)
index 0000000..a9ed659
--- /dev/null
@@ -0,0 +1,82 @@
+/**
+ * \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 2007 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief PCF8574 i2c port expander driver.
+ *
+ * This driver controls the PCF8574.
+ * The PCF8574 is an 8bit i2c port expander.
+ * You can read/write 8 pins through an i2c bus.
+ * The pins are quasi-bidirectionals, this mean that
+ * without the need of a direction register you can use
+ * each pin as input or output, see datasheet on how this
+ * is achieved.
+ *
+ * \version $Id: ft245rl.c 22301 2008-09-09 16:53:17Z batt $
+ * \author Francesco Sacchi <batt@develer.com>
+ */
+
+#include "pcf8574.h"
+#include <drv/i2c.h>
+
+/**
+ * Read PCF8574 \a pcf bit status.
+ * \return the pins status or EOF on errors.
+ */
+int pcf8574_get(Pcf8574 *pcf)
+{
+       if (!i2c_start_r(PCF8574ID | ((pcf->addr << 1) & 0xF7)))
+               return EOF;
+
+       int data = i2c_get(false);
+       i2c_stop();
+       return data;
+}
+
+/**
+ * Write to PCF8574 \a pcf port \a data.
+ * \return true if ok, false on errors.
+ */
+bool pcf8574_put(Pcf8574 *pcf, uint8_t data)
+{
+       return  i2c_start_w(PCF8574ID | ((pcf->addr << 1) & 0xF7)) && i2c_put(data) && i2c_stop();
+}
+
+/**
+ * Init a PCF8574 on the bus with addr \a addr.
+ * \return true if device is found, false otherwise.
+ */
+bool pcf8574_init(Pcf8574 *pcf, pcf8574_addr addr)
+{
+       MOD_CHECK(i2c);
+       pcf->addr = addr;
+       return pcf8574_get(pcf) != EOF;
+}
diff --git a/bertos/drv/pcf8574.h b/bertos/drv/pcf8574.h
new file mode 100644 (file)
index 0000000..7d53d95
--- /dev/null
@@ -0,0 +1,59 @@
+/**
+ * \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 2007 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief PCF8574 i2c port expander driver (interface).
+ *
+ * \version $Id: ft245rl.c 22301 2008-09-09 16:53:17Z batt $
+ * \author Francesco Sacchi <batt@develer.com>
+ */
+
+#ifndef DRV_PCF8574_H
+#define DRV_PCF8574_H
+
+#include <cfg/compiler.h>
+
+typedef uint8_t pcf8574_addr;
+
+/**
+ * Context for accessing a PCF8574.
+ */
+typedef struct Pcf8574
+{
+       pcf8574_addr addr;
+} Pcf8574;
+
+
+int pcf8574_get(Pcf8574 *pcf);
+bool pcf8574_put(Pcf8574 *pcf, uint8_t data);
+bool pcf8574_init(Pcf8574 *pcf, pcf8574_addr addr);
+
+#endif /* DRV_PCF8574_H */