The unified diff between revisions [d8ed90db..] and [8760ae92..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'i2c.c'

#
# old_revision [d8ed90db2d4284a290224447c40a0d9cef3fbc31]
# new_revision [8760ae9232295422550b79f09e55122390704b3c]
#
# patch "i2c.c"
#  from [7a497687684cdd6463a65bd4f3e08b1bc8f580a7]
#    to [1d978ba6c211e6b68c567fa852d9cbefe8ebad13]
#
============================================================
--- i2c.c	7a497687684cdd6463a65bd4f3e08b1bc8f580a7
+++ i2c.c	1d978ba6c211e6b68c567fa852d9cbefe8ebad13
@@ -29,8 +29,13 @@ void init_i2c(void)
 	IWREG(I2SCLL) = (25 * 100);
 	IWREG(I2SCLH) = (12 * 100);
 #else
+# if 0
 	IWREG(I2SCLL) = 1475; /* ~5kHz */
 	IWREG(I2SCLH) = 1475;
+# else
+	IWREG(I2SCLL) = 73; /* ~100kHz */
+	IWREG(I2SCLH) = 73;
+# endif
 #endif
 }
 
@@ -45,11 +50,6 @@ int i2c_wait(void)
 	return stat;
 }
 
-void i2c_go(void)
-{
-	IREG(I2CONCLR) = SIFLAG;
-}
-
 int i2c_conreg(void)
 {
 	return IREG(I2CONSET);
@@ -64,14 +64,12 @@ bool i2c_send_start(void)
 {
 	IREG(I2CONCLR) = STOFLAG | STAFLAG;
 	IREG(I2CONSET) = STAFLAG;
-/*	i2c_go(); */
 	switch (i2c_wait()) {
 	case 0x08:
 	case 0x10:
-/*		IREG(I2CONCLR) = STAFLAG; */
 		return TRUE;
 	default:
-/*		IREG(I2CONCLR) = STAFLAG; */
+		i2c_send_stop();
 		return FALSE;
 	}
 }
@@ -81,24 +79,42 @@ bool i2c_send_address(int addr, bool wri
 	return i2c_send_data((addr<<1) + (write?0:1));
 }
 
-bool i2c_send_data(int data)
+bool i2c_send_data(unsigned int data)
 {
 	IREG(I2DAT) = data;
-	IREG(I2CONCLR) = STAFLAG | SIFLAG;
+	IREG(I2CONCLR) = STAFLAG | STOFLAG | SIFLAG;
 	switch (i2c_wait()) {
 	case 0x18:
 	case 0x28:
+	case 0x40:
 		return TRUE;
 	default:
+		i2c_send_stop();
 		return FALSE;
 	}
 }
 
+bool i2c_receive_data(unsigned int *data, bool last)
+{
+	if (!last)
+		IREG(I2CONSET) = AAFLAG;
+	IREG(I2CONCLR) = STAFLAG | STOFLAG | SIFLAG | (last?AAFLAG:0);
+	switch (i2c_wait()) {
+	case 0x50:
+	case 0x58:
+		*data = IREG(I2DAT);
+		return TRUE;
+	default:
+		i2c_send_stop();
+		return FALSE;
+	}
+}
+
 void i2c_send_stop(void)
 {
 	IREG(I2CONCLR) = STAFLAG | AAFLAG;
 	IREG(I2CONSET) = STOFLAG;
-	i2c_go();
+	IREG(I2CONCLR) = SIFLAG;
 	/* Don't think we need to wait here. Could be wrong. */
 }