the enable/disable logic became somewhat hairy with autodetections and
[tv_i2c_hack] / src / i2c.c
index c7af41d..c37dd18 100644 (file)
--- a/src/i2c.c
+++ b/src/i2c.c
@@ -3,10 +3,14 @@
 #include <avr/interrupt.h>
 #include "i2c.h"
 
+#define PC_SDA 0x10
+#define PC_SCL 0x20
+
 enum {
        I2C_IDLE,
        I2C_MASTER_WRITE,
-       I2C_MASTER_READ
+       I2C_MASTER_READ,
+       I2C_HOLD        = 0xff
 };
 
 enum {
@@ -326,13 +330,22 @@ void i2c_check_async(void)
 void i2c_hold(void)
 {
        TWCR = 0;               /* make sure the AVR i2c hardware is disabled */
-       DDRC = 0x20;    /* ... and drive SCL pin low */
-       PORTC = 0;
+       DDRC |= PC_SCL; /* ... and drive SCL pin low */
+       PORTC &= ~PC_SCL;
+
+       i2c_mode = I2C_HOLD;
 }
 
 void i2c_release(void)
 {
-       DDRC = 0;
+       DDRC &= ~PC_SCL;
+
+       i2c_mode = I2C_IDLE;
+}
+
+unsigned char i2c_isheld(void)
+{
+       return i2c_mode == I2C_HOLD;
 }
 
 void i2c_abort(void)