i2c: add api call to read byte from a specified register
authorAnton Krasovsky <anton@no-mad.net>
Thu, 30 Oct 2014 23:25:10 +0000 (23:25 +0000)
committerThomas Ingleby <thomas.c.ingleby@intel.com>
Fri, 31 Oct 2014 01:17:17 +0000 (01:17 +0000)
Signed-off-by: Anton Krasovsky <anton@no-mad.net>
Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
api/mraa/i2c.h
api/mraa/i2c.hpp
src/i2c/i2c.c

index 34c7395..c50d224 100644 (file)
@@ -96,6 +96,15 @@ int mraa_i2c_read(mraa_i2c_context dev, uint8_t *data, int length);
 uint8_t mraa_i2c_read_byte(mraa_i2c_context dev);
 
 /**
+ * Read a single byte from i2c context, from designated register
+ *
+ * @param dev The i2c context
+ * @param command The register
+ * @return The result of the read or -1 if failed
+ */
+uint8_t mraa_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command);
+
+/**
  * Write to an i2c context
  *
  * @param dev The i2c context
index 2adfd89..149b459 100644 (file)
@@ -144,6 +144,18 @@ class I2c {
         }
 
         /**
+         * Read an i2c register
+         *
+         * @param reg Register to read from
+
+         * @return char read from the bus
+         * @return char read from register
+         */
+        int readReg(char reg) {
+            return mraa_i2c_read_byte_data(m_i2c, reg);
+        }
+
+        /**
          * Write multiple bytes to the bus
          *
          * @param data The byte to send on the bus
index 7be4a0b..7fc0813 100644 (file)
@@ -101,6 +101,13 @@ mraa_i2c_read_byte(mraa_i2c_context dev)
     return byte;
 }
 
+uint8_t
+mraa_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
+{
+    uint8_t byte = i2c_smbus_read_byte_data(dev->fh, command);
+    return byte;
+}
+
 mraa_result_t
 mraa_i2c_write(mraa_i2c_context dev, const uint8_t* data, int length)
 {