Index: I2C.py
===================================================================
--- I2C.py	(revision 546)
+++ I2C.py	(working copy)
@@ -36,31 +36,31 @@
 	
 class I2C(BBIO):
 	bulk_read = None
-	def __init__(self, port, speed):
-		BBIO.__init__(self, port, speed)
+	def __init__(self, port, speed, timeout=1):
+		BBIO.__init__(self, port, speed, timeout)
 
 	def send_start_bit(self):
 		self.port.write("\x02")
-		self.timeout(0.1)
+		#self.timeout(0.1)
 		return self.response()
 	
 	def send_stop_bit(self):
 		self.port.write("\x03")
-		self.timeout(0.1)
+		#self.timeout(0.1)
 		return self.response()
 		
 	def read_byte(self):
 		self.port.write("\x04")
-		self.timeout(0.1)
+		#self.timeout(0.1)
 		return self.response(1, True)
 		
 	def send_ack(self):
 		self.port.write("\x06")
-		self.timeout(0.1)
+		#self.timeout(0.1)
 		return self.response()
 		
 	def send_nack(self):
 		self.port.write("\x07")
-		self.timeout(0.1)
+		#self.timeout(0.1)
 		return self.response()
 
Index: I2Chigh.py
===================================================================
--- I2Chigh.py	(revision 0)
+++ I2Chigh.py	(revision 0)
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+# encoding: utf-8
+"""
+Created by Ondrej Caletka on 2010-11-06.
+Copyright 2010 Ondrej Caletka <ondrej.caletka@gmail.com>
+
+This file is part of pyBusPirate.
+
+pyBusPirate is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+pyBusPirate is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with pyBusPirate.  If not, see <http://www.gnu.org/licenses/>.
+"""
+from .I2C import *
+""" enter binary mode """
+
+class I2Chigh(I2C):
+    """High level I2C transactions"""
+    def __init__(self, port, speed, t=1):
+        I2C.__init__(self, port, speed, t);
+
+    def get_byte(self, i2caddr, addr):
+        """ Read one byte from address addr """
+        self.send_start_bit();
+        stat = self.bulk_trans(2, [i2caddr<<1, addr]);
+        self.send_start_bit();
+        stat += self.bulk_trans(1, [i2caddr<<1 | 1]);
+        r = self.read_byte();
+        self.send_nack();
+        self.send_stop_bit();
+        if stat.find(chr(0x01)) != -1:
+            raise IOError, "I2C command on address 0x%02x not acknowledged!"%(i2caddr);
+        return ord(r);
+
+    def set_byte(self, i2caddr, addr, value):
+        """ Write one byte to address addr """
+        self.send_start_bit();
+        stat = self.bulk_trans(3, [i2caddr<<1, addr, value]);
+        self.send_stop_bit();
+        if stat.find(chr(0x01)) != -1:
+            raise IOError, "I2C command on address 0x%02x not acknowledged!"%(i2caddr);
+
+
+    def command(self, i2caddr, cmd):
+        """ Writes one byte command to slave """
+        self.send_start_bit();
+        stat = self.bulk_trans(2, [i2caddr<<1, cmd]);
+        self.send_stop_bit();
+        if stat[0] == chr(0x01):
+            raise IOError, "I2C command on address 0x%02x not acknowledged!"%(i2caddr);
+
+    def set_word(self, i2caddr, addr, value):
+        """ Writes two byte value (big-endian) to address addr """
+        vh = value/256;
+        vl = value%256;
+        self.send_start_bit();
+        stat = self.bulk_trans(4, [i2caddr<<1, addr, vh, vl]);
+        self.send_stop_bit();
+        if stat.find(chr(0x01)) != -1:
+            raise IOError, "I2C command on address 0x%02x not acknowledged!"%(i2caddr);
+
+
+    def get_word(self, i2caddr, addr):
+        """ Reads two byte value (big-endian) from address addr """
+        self.send_start_bit();
+        stat = self.bulk_trans(2, [i2caddr<<1, addr]);
+        self.send_start_bit();
+        stat += self.bulk_trans(1, [i2caddr<<1 | 1]);
+        rh = self.read_byte();
+        self.send_ack();
+        rl = self.read_byte();
+        self.send_nack();
+        self.send_stop_bit();
+        if stat.find(chr(0x01)) != -1:
+            raise IOError, "I2C command on address 0x%02x not acknowledged!"%(i2caddr);
+        return ord(rh)*256+ord(rl);
+
+        

Property changes on: I2Chigh.py
___________________________________________________________________
Added: svn:executable
   + *

Index: BitBang.py
===================================================================
--- BitBang.py	(revision 546)
+++ BitBang.py	(working copy)
@@ -48,11 +48,11 @@
 		self.port = serial.Serial(p, s, timeout=t)
 	
 	def BBmode(self):
-		self.resetBP()
-		self.port.write("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
-		self.timeout(0.1)
-		self.port.flushInput();
-		self.reset()
+		self.port.flushInput();		
+		for i in range(20):
+			self.port.write("\x00");
+			r,w,e = select.select([self.port], [], [], 0.01);
+			if (r): break;
 		if self.response(5) == "BBIO1": return 1
 		else: return 0
 
@@ -95,8 +95,8 @@
 		self.reset()
 		self.port.write("\x0F")
 		self.timeout(0.1)
-		self.port.read(2000)
-		self.port.flush()
+		#self.port.read(2000)
+		self.port.flushInput()
 		return 1
 
 	def raw_cfg_pins(self, config):
@@ -162,11 +162,11 @@
 	def bulk_trans(self, byte_count=1, byte_string=None):
 		if byte_string == None: pass
 		self.port.write(chr(0x10 | (byte_count-1)))
-		self.timeout(0.1)
+		#self.timeout(0.1)
 		for i in range(byte_count):
 			self.port.write(chr(byte_string[i]))
-			self.timeout(0.1)
-		data = self.response(byte_count+2, True)
+			#self.timeout(0.1)
+		data = self.response(byte_count+1, True)
 		return data[1:]
 
 	def cfg_pins(self, pins=0):
