Lab 1 Program C

Dependents:   Lab1C

Fork of mbed by -deleted-

Revision:
11:1c1ebd0324fa
Parent:
4:5d1359a283bc
Child:
12:f63353af7be8
diff -r fcb9359f0959 -r 1c1ebd0324fa I2C.h
--- a/I2C.h	Thu May 14 14:44:00 2009 +0000
+++ b/I2C.h	Fri Aug 28 12:10:11 2009 +0000
@@ -1,80 +1,88 @@
 /* mbed Microcontroller Library - I2C
- * Copyright (c) 2007-2008, sford
- */
+ * Copyright (c) 2007-2009 ARM Limited. All rights reserved.
+ * sford
+ */ 
  
 #ifndef MBED_I2C_H
 #define MBED_I2C_H
 
+#include "platform.h"
+#include "PinNames.h"
+#include "PeripheralNames.h"
 #include "Base.h"
 
 namespace mbed {
 
 /* Class: I2C
  *  An I2C Master, used for communicating with I2C slave devices
+ *
+ * Example:
+ * > // Read from I2C slave at address 0x1234
+ * >
+ * > #include "mbed.h"
+ * >
+ * > I2C i2c(p28, p27);
+ * >
+ * > int main() {
+ * >     int address = 0x1234;
+ * >     char data[2];
+ * >     i2c.read(address,data,2);
+ * >     // ...
+ * > }
  */
 class I2C : public Base {
 
 public:
 
-	/* Group: Configuration Methods */
+    /* Constructor: I2C
+     *  Create an I2C Master interface, connected to the specified pins
+     *
+     * Variables:
+     *  sda - I2C data line pin
+     *  scl - I2C clock line pin
+     */
+    I2C(PinName sda, PinName scl, const char *name = NULL);
 
-	/* Constructor: I2C
-	 *  Create an I2C Master interface, connected to the specified pins
-	 *
-	 * Variables:
-	 *  sda - I2C data line pin
-	 *  scl - I2C clock line pin
+    /* Function: frequency
+     *  Set the frequency of the I2C interface
+     *
+     * Variables:
+     *  hz - The bus frequency in hertz
+     */
+    void frequency(int hz);
+
+    /* Function: read
+     *  Read from an I2C slave
      *
-	 * Pin Options:
-	 *  (9, 10) or (28, 27)	 
-	 */
-	I2C(int sda, int scl, const char *name = NULL);
-	
-	/* Function: frequency
-	 *  Set the frequency of the I2C interface
-	 *
-	 * Variables:
-	 *  hz - The bus frequency in hertz
-	 */
-	void frequency(int hz);
-	
-	/* Group: Access Methods */
-		
-	/* Function: read
-	 *  Read from an I2C slave
-	 *
-	 * Variables:
-	 *  address - 7-bit I2C slave address (0-127)
-	 *  data - Pointer to the byte-array to read data in to 
-	 *  length - Number of bytes to read
-	 */ 
-	void read(int address, char* data, int length); 
+     * Variables:
+     *  address - 7-bit I2C slave address (0-127)
+     *  data - Pointer to the byte-array to read data in to 
+     *  length - Number of bytes to read
+     *  returns - 0 on success (ack), or 1 on failure (nack)
+     */ 
+    int read(int address, char *data, int length); 
 
-	/* Function: write
-	 *  Write to an I2C slave
-	 *
-	 * Variables:
-	 *  address - 7-bit I2C slave address (0-127)
-	 *  data - Pointer to the byte-array data to send 
-	 *  length - Number of bytes to send
-	 */ 
-	void write(int address, char* data, int length);
-
+    /* Function: write
+     *  Write to an I2C slave
+     *
+     * Variables:
+     *  address - 7-bit I2C slave address (0-127)
+     *  data - Pointer to the byte-array data to send 
+     *  length - Number of bytes to send
+     *  returns - 0 on success (ack), or 1 on failure (nack)
+     */ 
+    int write(int address, const char *data, int length);
+    
 protected:
 
-	void configure();
-	
-	int _id;
+    I2CName _i2c;
+    
+    void aquire();
+    static I2C *_owner;
+    int _hz;
 
-	int _uid;
-	static int _uidcounter;
-		
-	int _hz;
-	static int _config[3];	
-		
 };
 
-}
+} // namespace mbed
 
 #endif
-