#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 {
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)