[Armadeus-commitlog] armadeus branch, master, updated. release-3.3-328-g508d93e
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2011-02-18 10:26:05
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via 508d93efeed222e611a4c7ac50d8fd00b226349a (commit)
via 9a418c673a945dd7d03a7ba324b0131fe4cd97ae (commit)
via 30de9a33596cea9d5a0cb1df897383c86d38ebb4 (commit)
from 75c993f742796ed130ee404b4cacb364e77fb269 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 508d93efeed222e611a4c7ac50d8fd00b226349a
Merge: 9a418c673a945dd7d03a7ba324b0131fe4cd97ae 75c993f742796ed130ee404b4cacb364e77fb269
Author: Fabien Marteau <fab...@ar...>
Date: Fri Feb 18 11:25:42 2011 +0100
Merge branch 'master' of ssh://armadeus.git.sourceforge.net/gitroot/armadeus/armadeus
commit 9a418c673a945dd7d03a7ba324b0131fe4cd97ae
Author: Fabien Marteau <fab...@ar...>
Date: Fri Feb 18 11:24:12 2011 +0100
[uclibc] adding UCLIBC_SUSV3_LEGACY option to get time in ms
commit 30de9a33596cea9d5a0cb1df897383c86d38ebb4
Author: Fabien Marteau <fab...@ar...>
Date: Fri Feb 11 18:47:27 2011 +0100
[as_devices] Changes as_i2c API
-----------------------------------------------------------------------
Summary of changes:
.../device/armadeus/apf27/uClibc-0.9.30.config.arm | 2 +-
.../target/device/armadeus/apf27/uClibc.config.arm | 2 +-
target/packages/as_devices/c/Makefile | 2 +-
target/packages/as_devices/c/as_i2c.c | 134 +++++++++++++++-----
target/packages/as_devices/c/as_i2c.h | 101 ++++-----------
5 files changed, 134 insertions(+), 107 deletions(-)
diff --git a/buildroot/target/device/armadeus/apf27/uClibc-0.9.30.config.arm b/buildroot/target/device/armadeus/apf27/uClibc-0.9.30.config.arm
index 0ef197a..3cb1cf7 100644
--- a/buildroot/target/device/armadeus/apf27/uClibc-0.9.30.config.arm
+++ b/buildroot/target/device/armadeus/apf27/uClibc-0.9.30.config.arm
@@ -103,7 +103,7 @@ MALLOC_STANDARD=y
MALLOC_GLIBC_COMPAT=y
UCLIBC_DYNAMIC_ATEXIT=y
# COMPAT_ATEXIT is not set
-# UCLIBC_SUSV3_LEGACY is not set
+UCLIBC_SUSV3_LEGACY=y
# UCLIBC_SUSV3_LEGACY_MACROS is not set
# UCLIBC_HAS_STUBS is not set
UCLIBC_HAS_SHADOW=y
diff --git a/buildroot/target/device/armadeus/apf27/uClibc.config.arm b/buildroot/target/device/armadeus/apf27/uClibc.config.arm
index 1ce0190..7beee2b 100644
--- a/buildroot/target/device/armadeus/apf27/uClibc.config.arm
+++ b/buildroot/target/device/armadeus/apf27/uClibc.config.arm
@@ -95,7 +95,7 @@ MALLOC_STANDARD=y
MALLOC_GLIBC_COMPAT=y
UCLIBC_DYNAMIC_ATEXIT=y
# COMPAT_ATEXIT is not set
-# UCLIBC_SUSV3_LEGACY is not set
+UCLIBC_SUSV3_LEGACY=y
# UCLIBC_SUSV3_LEGACY_MACROS is not set
UCLIBC_HAS_SHADOW=y
# UCLIBC_HAS_PROGRAM_INVOCATION_NAME is not set
diff --git a/target/packages/as_devices/c/Makefile b/target/packages/as_devices/c/Makefile
index 77be4a4..ba754b7 100644
--- a/target/packages/as_devices/c/Makefile
+++ b/target/packages/as_devices/c/Makefile
@@ -16,7 +16,7 @@ endif
OBJ += as_93lcxx.o
OBJ += as_spi.o
#OBJ += as_max1027.o
-OBJ += as_max5821.o
+#OBJ += as_max5821.o
OBJ += as_helpers.o
OBJ += as_adc.o
diff --git a/target/packages/as_devices/c/as_i2c.c b/target/packages/as_devices/c/as_i2c.c
index 970bc89..2fa54c6 100644
--- a/target/packages/as_devices/c/as_i2c.c
+++ b/target/packages/as_devices/c/as_i2c.c
@@ -15,11 +15,12 @@
*
*
* Copyright (C) 2009 Benoît Ryder <be...@ry...>
+ * Copyright (C) 2010, 2011 Fabien Marteau <fab...@ar...>
*
*/
-
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
@@ -29,92 +30,156 @@
#include "as_i2c.h"
+#undef ERROR
+#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
/* Format of path to I2C devices */
#define AS_I2C_DEV_PATH_FMT "/dev/i2c-%u"
#define _STR(x) #x
#define AS_I2C_DEV_PATH_SIZE (sizeof(AS_I2C_DEV_PATH_FMT)-2+sizeof(_STR(AS_I2C_DEV_COUNT))-1)
-
-int as_i2c_open(unsigned int i2c_id)
+struct as_i2c_device *as_i2c_open(int aBusNumber)
{
char buf[AS_I2C_DEV_PATH_SIZE];
+ int fdev;
+ struct as_i2c_device *dev;
+
+ snprintf(buf, sizeof(buf), AS_I2C_DEV_PATH_FMT, aBusNumber);
+
+ fdev = open(buf, O_RDWR);
+ if (fdev < 0) {
+ ERROR("Can't open i2c bus /dev/i2c-%d\n", aBusNumber);
+ return NULL;
+ }
- snprintf(buf, sizeof(buf), AS_I2C_DEV_PATH_FMT, i2c_id);
+ dev = malloc(sizeof(struct as_i2c_device));
+ if (dev == NULL) {
+ ERROR("Can't allocate memory for device structure\n");
+ return NULL;
+ }
- return open(buf, O_RDWR);
+ dev->i2c_id = aBusNumber;
+ dev->slave_addr = 0;
+ dev->fi2c = fdev;
+
+ return dev;
}
-int as_i2c_close(int fd)
+int32_t as_i2c_close(struct as_i2c_device *aDev)
{
- return close(fd);
+ close(aDev->fi2c);
+ free(aDev);
+
+ return 0;
}
-int as_i2c_set_slave(int fd, uint8_t addr)
+int32_t as_i2c_set_slave_addr(struct as_i2c_device *aDev, uint8_t aAddr)
{
- if (ioctl(fd, I2C_SLAVE_FORCE, addr) < 0)
+ if (aAddr == 0) {
+ ERROR("Wrong slave address\n");
return -1;
+ }
+ if (ioctl(aDev->fi2c, I2C_SLAVE_FORCE, aAddr) < 0) {
+ ERROR("Can't set slave address\n");
+ return -1;
+ }
+ aDev->slave_addr = aAddr;
return 0;
}
+int32_t as_i2c_get_slave_addr(struct as_i2c_device *aDev) {
+ return aDev->slave_addr;
+}
-int as_i2c_read(int fd, uint8_t addr, uint8_t *data, size_t n)
+int32_t as_i2c_read(struct as_i2c_device *aDev,
+ uint8_t *aData, size_t n)
{
- struct i2c_msg msg = { addr, I2C_M_RD, n, data };
+ struct i2c_msg msg = { aDev->slave_addr, I2C_M_RD, n, aData };
struct i2c_rdwr_ioctl_data rdwr = { &msg, 1 };
- if (ioctl(fd, I2C_RDWR, &rdwr) < 0)
+ if (aDev->slave_addr == 0) {
+ ERROR("Slave address must be set before\n");
+ return -1;
+ }
+
+ if (ioctl(aDev->fi2c, I2C_RDWR, &rdwr) < 0)
return -1;
return 0;
}
-int as_i2c_write(int fd, uint8_t addr, const uint8_t *data, size_t n)
+int32_t as_i2c_write(struct as_i2c_device *aDev,
+ uint8_t *aData, size_t n)
{
- struct i2c_msg msg = { addr, 0, n, (uint8_t *)data };
+ struct i2c_msg msg = { aDev->slave_addr, 0, n, (uint8_t *)aData };
struct i2c_rdwr_ioctl_data rdwr = { &msg, 1 };
- if (ioctl(fd, I2C_RDWR, &rdwr) < 0)
+ if (aDev->slave_addr == 0) {
+ ERROR("Slave address must be set before\n");
+ return -1;
+ }
+
+ if (ioctl(aDev->fi2c, I2C_RDWR, &rdwr) < 0)
return -1;
return 0;
}
-
-int as_i2c_read_reg(int fd, uint8_t addr, uint8_t reg, uint8_t *data, size_t n)
+int32_t as_i2c_read_reg(struct as_i2c_device *aDev,
+ uint8_t aReg, uint8_t *aData, size_t n)
{
/* write reg */
- struct i2c_msg msg = { addr, 0, 1, ® };
+ struct i2c_msg msg = { aDev->slave_addr, 0, 1, &aReg };
struct i2c_rdwr_ioctl_data rdwr = { &msg, 1 };
- if (ioctl(fd, I2C_RDWR, &rdwr) < 0)
+ if (aDev->slave_addr == 0) {
+ ERROR("Slave address must be set before\n");
+ return -1;
+ }
+
+ if (ioctl(aDev->fi2c, I2C_RDWR, &rdwr) < 0) {
+ ERROR("Can't write on i2c\n");
return -1;
+ }
/* read data */
msg.flags = I2C_M_RD;
msg.len = n;
- msg.buf = data;
- if (ioctl(fd, I2C_RDWR, &rdwr) < 0)
+ msg.buf = aData;
+
+ if (ioctl(aDev->fi2c, I2C_RDWR, &rdwr) < 0) {
+ ERROR("Can't read on i2c\n");
return -2;
+ }
return 0;
}
-int as_i2c_write_reg(int fd, uint8_t addr, uint8_t reg, const uint8_t *data, size_t n)
+int32_t as_i2c_write_reg(struct as_i2c_device *aDev,
+ uint8_t aReg, const uint8_t *aData, size_t n)
{
uint8_t buf[n+1];
- buf[0] = reg;
- memcpy(buf+1, data, n);
+ if (aDev->slave_addr == 0) {
+ ERROR("Slave address must be set before\n");
+ return -1;
+ }
- return as_i2c_write(fd, addr, buf, sizeof(buf));
-}
+ buf[0] = aReg;
+ memcpy(buf+1, aData, n);
+ return as_i2c_write(aDev, buf, sizeof(buf));
+}
-int as_i2c_read_reg_byte(int fd, uint8_t addr, uint8_t reg)
+int32_t as_i2c_read_reg_byte(struct as_i2c_device *aDev, uint8_t aReg)
{
uint8_t val;
- int ret = as_i2c_read_reg(fd, addr, reg, &val, 1);
+ int ret = as_i2c_read_reg(aDev, aReg, &val, 1);
+
+ if (aDev->slave_addr == 0) {
+ ERROR("Slave address must be set before\n");
+ return -1;
+ }
if (ret < 0)
return ret;
@@ -122,9 +187,16 @@ int as_i2c_read_reg_byte(int fd, uint8_t addr, uint8_t reg)
return val;
}
-int as_i2c_write_reg_byte(int fd, uint8_t addr, uint8_t reg, uint8_t val)
+int32_t as_i2c_write_reg_byte(struct as_i2c_device *aDev,
+ uint8_t aReg, uint8_t aVal)
{
- uint8_t buf[2] = { reg, val };
+ uint8_t buf[2] = { aReg, aVal };
- return as_i2c_write(fd, addr, buf, 2);
+ if (aDev->slave_addr == 0) {
+ ERROR("Slave address must be set before\n");
+ return -1;
+ }
+
+ return as_i2c_write(aDev, buf, 2);
}
+
diff --git a/target/packages/as_devices/c/as_i2c.h b/target/packages/as_devices/c/as_i2c.h
index 2865631..bab3a95 100644
--- a/target/packages/as_devices/c/as_i2c.h
+++ b/target/packages/as_devices/c/as_i2c.h
@@ -15,25 +15,13 @@
*
*
* Copyright (C) 2009 Benoît Ryder <be...@ry...>
+ * Copyright (C) 2010, 2011 Fabien Marteau <fab...@ar...>
*
*/
#ifndef AS_I2C_H_
#define AS_I2C_H_
-/** @file
- * @brief Provide access to I2C devices.
- *
- * Once opened with as_i2c_open(), the I2C slave address to talk with should be
- * set using as_i2c_set_slave(). Then, standard \e read(), \e write() and
- * close() can be used. Otherwise, methods provided by this module can be used.
- * These methods does not use standard <em>read()/write</em> methods nor
- * combined transactions (several read/write messages in the same transaction).
- *
- * @note All methods will leave \e errno unchanged on system call errors, which
- * will happen when -1 is returned.
- */
-
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
@@ -41,92 +29,59 @@ extern "C" {
#include <inttypes.h>
#include <sys/types.h>
-/* Number of I2C busses on system */
-#define AS_I2C_DEV_COUNT 2
+/**
+ * Store i2c parameters
+ */
+struct as_i2c_device {
+ int i2c_id;
+ int fi2c;
+ uint8_t slave_addr;
+};
/** @brief Open an I2C bus.
- *
- * \e i2c_id is the ID of the I2C bus to open, it should be strictly lower than
- * \e AS_I2C_DEV_COUNT.
- *
- * @return the file descriptor of the opened device, -1 on error.
*/
-int as_i2c_open(unsigned int i2c_id);
+struct as_i2c_device *as_i2c_open(int aBusNumber);
/** @brief Close an I2C device.
- *
- * @return 0 on success, -1 on error.
- *
- * @note This is an alias of the standard \e close() system call.
*/
-int as_i2c_close(int fd);
+int32_t as_i2c_close(struct as_i2c_device *aDev);
-/** @brief Set chip's I2C slave address (to be used with read() & write() method)
- *
- * @return 0 on success, -1 on error.
+/** @brief Set chip's I2C slave address
+ */
+int32_t as_i2c_set_slave_addr(struct as_i2c_device *aDev, uint8_t aAddr);
+
+/** @brief Set chip's I2C slave address
*/
-int as_i2c_set_slave(int fd, uint8_t addr);
+int32_t as_i2c_get_slave_addr(struct as_i2c_device *aDev);
/** @brief Read several bytes (ioctl() method) from given chip.
- *
- * @param addr I2C address of chip to access
- *
- * @return 0 on success, -1 on error.
*/
-int as_i2c_read(int fd, uint8_t addr, uint8_t *data, size_t n);
+int32_t as_i2c_read(struct as_i2c_device *aDev,
+ uint8_t *aData, size_t n);
/** @brief Write several bytes (ioctl() method) to given chip.
- *
- * @param addr I2C address of chip to access
- *
- * @return 0 on success, -1 on error.
*/
-int as_i2c_write(int fd, uint8_t addr, const uint8_t *data, size_t n);
+int32_t as_i2c_write(struct as_i2c_device *aDev,
+ uint8_t *aData, size_t n);
/** @brief Read from given chip at a given register address (ioctl() method).
- *
- * Send the \e reg byte, then read bytes.
- *
- * @param addr I2C address of chip to access
- *
- * @return 0 on success, -1 on write error (\e reg byte), -2 on read error.
*/
-int as_i2c_read_reg(int fd, uint8_t addr, uint8_t reg, uint8_t *data, size_t n);
+int32_t as_i2c_read_reg(struct as_i2c_device *aDev,
+ uint8_t aReg, uint8_t *aData, size_t n);
/** @brief Write to given chip at a given register address (ioctl() method).
- *
- * Send the \e reg byte followed by data.
- *
- * @param addr I2C address of chip to access
- *
- * @return 0 on success, -1 on error.
*/
-int as_i2c_write_reg(int fd, uint8_t addr, uint8_t reg, const uint8_t *data, size_t n);
+int32_t as_i2c_write_reg(struct as_i2c_device *aDev,
+ uint8_t aReg, const uint8_t *aData, size_t n);
/** @brief Read a byte from the given register.
- *
- * Send the \e reg byte, then read and return a single byte.
- *
- * @param addr I2C address of chip to access
- *
- * @return the read byte, -1 on write error (\e reg byte), -2 on read error.
- *
- * @note Equivalent to \e as_i2c_read_reg() with a 1-byte buffer, but return
- * the read byte.
*/
-int as_i2c_read_reg_byte(int fd, uint8_t addr, uint8_t reg);
+int32_t as_i2c_read_reg_byte(struct as_i2c_device *aDev, uint8_t aReg);
/** @brief Write a byte to the given register.
- *
- * Send the \e reg byte followed by the \e val byte.
- *
- * @param addr I2C address of chip to access
- *
- * @return 0 on success, -1 on error.
- *
- * @note Equivalent to \e as_i2c_write() with a 2-byte buffer (reg + data).
*/
-int as_i2c_write_reg_byte(int fd, uint8_t addr, uint8_t reg, uint8_t val);
+int32_t as_i2c_write_reg_byte(struct as_i2c_device *aDev,
+ uint8_t aReg, uint8_t aVal);
#ifdef __cplusplus
}
hooks/post-receive
--
armadeus
|