Commit 58028a9e authored by Juergen Hasch's avatar Juergen Hasch

Additional fixes

parent e6aa8561
...@@ -239,7 +239,6 @@ checking. This is as planned, since all of these ...@@ -239,7 +239,6 @@ checking. This is as planned, since all of these
depend on the device you are interfacing with)""" depend on the device you are interfacing with)"""
def send_start_bit(self): def send_start_bit(self):
self.check_mode(['i2c', 'raw'])
self.write(0x02) self.write(0x02)
resp = self.response(1, True) resp = self.response(1, True)
if self.response(1, True) == '\x01': if self.response(1, True) == '\x01':
...@@ -249,7 +248,6 @@ def send_start_bit(self): ...@@ -249,7 +248,6 @@ def send_start_bit(self):
def send_stop_bit(self): def send_stop_bit(self):
self.check_mode(['i2c', 'raw'])
self.write(0x03) self.write(0x03)
if self.response(1, True) == 'x01': if self.response(1, True) == 'x01':
self.recurse_end() self.recurse_end()
...@@ -279,7 +277,6 @@ def bulk_trans(self, byte_count=1, byte_string=None): ...@@ -279,7 +277,6 @@ def bulk_trans(self, byte_count=1, byte_string=None):
In modes other than I2C I think it returns whatever data it gets while In modes other than I2C I think it returns whatever data it gets while
sending, but this feature is untested. PLEASE REPORT so that I can sending, but this feature is untested. PLEASE REPORT so that I can
document it.""" document it."""
# self.check_mode(not_bb)
if byte_string is None: if byte_string is None:
pass pass
self.write(0x10 | (byte_count - 1)) self.write(0x10 | (byte_count - 1))
......
...@@ -21,9 +21,8 @@ You should have received a copy of the GNU General Public License ...@@ -21,9 +21,8 @@ You should have received a copy of the GNU General Public License
along with pyBusPirate. If not, see <http://www.gnu.org/licenses/>. along with pyBusPirate. If not, see <http://www.gnu.org/licenses/>.
""" """
import serial from .BBIO_base import BBIO_base, ProtocolError
from .BBIO_base import BBIO_base, BPError, ProtocolError
class BitBang(BBIO_base): class BitBang(BBIO_base):
def __init__(self, portname='', speed=115200, timeout=0.1, connect=True): def __init__(self, portname='', speed=115200, timeout=0.1, connect=True):
...@@ -141,7 +140,6 @@ class BitBang(BBIO_base): ...@@ -141,7 +140,6 @@ class BitBang(BBIO_base):
self.write(0x14) self.write(0x14)
self.timeout(self.minDelay) self.timeout(self.minDelay)
ret = self.response(2, True) ret = self.response(2, True)
print('0: %d, 1: %d' % (ret[0], ret[1]))
voltage = (ret[0] << 8) + ret[1] voltage = (ret[0] << 8) + ret[1]
voltage = (voltage * 6.6) / 1024 voltage = (voltage * 6.6) / 1024
return voltage return voltage
...@@ -160,7 +158,6 @@ class BitBang(BBIO_base): ...@@ -160,7 +158,6 @@ class BitBang(BBIO_base):
ret = self.response(2, True) ret = self.response(2, True)
voltage = (ret[0] << 8) + ret[1] voltage = (ret[0] << 8) + ret[1]
voltage = (voltage * 6.6) / 1024 voltage = (voltage * 6.6) / 1024
# return voltage
if voltage < 10: if voltage < 10:
"""sometimes the input gets out of sync. This is the best error checking """sometimes the input gets out of sync. This is the best error checking
...@@ -176,13 +173,12 @@ class BitBang(BBIO_base): ...@@ -176,13 +173,12 @@ class BitBang(BBIO_base):
def stop_getting_adc_voltages(self): def stop_getting_adc_voltages(self):
"""I was encountering problems resetting out of adc mode, so I wrote this """I was encountering problems resetting out of adc mode, so I wrote this
little function""" little function"""
self.check_mode('adc')
self.port.flushInput() self.port.flushInput()
for i in range(5): for i in range(5):
self.write(0x00) self.write(0x00)
#r, w, e = select.select([self.port], [], [], 0.01); #r, w, e = select.select([self.port], [], [], 0.01);
r = self.response(1, True) r = self.response(1, binary=True)
if (r): break; if r: break;
self.port.flushInput() self.port.flushInput()
self.enter_bb() self.enter_bb()
return 1 return 1
...@@ -210,15 +206,18 @@ class BitBang(BBIO_base): ...@@ -210,15 +206,18 @@ class BitBang(BBIO_base):
int int
Number of errors Number of errors
""" """
self.port.flushInput()
if complete is True: if complete is True:
self.write(0x11) self.write(0x11)
else: else:
self.write(0x10) self.write(0x10)
self.timeout(self.minDelay * 50) self.timeout(1)
errors = self.response(1) errors = self.response(1, binary=True)
self.write(0xff) self.write(0xff)
if self.response(1) != '\x01': resp = self.response(1, binary=True)
if resp != b'\x01':
raise ProtocolError('Self test did not return to bitbang mode') raise ProtocolError('Self test did not return to bitbang mode')
self.timeout(self.minDelay)
return ord(errors) return ord(errors)
def enable_PWM(self, frequency, dutycycle=.5): def enable_PWM(self, frequency, dutycycle=.5):
......
...@@ -73,6 +73,7 @@ class I2C(BBIO_base): ...@@ -73,6 +73,7 @@ class I2C(BBIO_base):
return return
if self.mode != 'bb': if self.mode != 'bb':
super(I2C, self).enter() super(I2C, self).enter()
self.write(0x02) self.write(0x02)
self.timeout(self.minDelay * 10) self.timeout(self.minDelay * 10)
if self.response(4) == "I2C1": if self.response(4) == "I2C1":
......
...@@ -23,7 +23,7 @@ along with pyBusPirate. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,7 +23,7 @@ along with pyBusPirate. If not, see <http://www.gnu.org/licenses/>.
from . import I2C from . import I2C
def init_i2c(bp_device, power=True, pullups=True, speed=I2C.I2CSpeed._50KHZ): def init_i2c(bp_device, power=True, pullups=True, speed=I2C.I2C_speed['50KHZ']):
"""initializes i2c mode with some common settings hardwired """initializes i2c mode with some common settings hardwired
Parameters Parameters
...@@ -80,7 +80,7 @@ def i2c_write_data(bp_device, data): ...@@ -80,7 +80,7 @@ def i2c_write_data(bp_device, data):
return ack_signals return ack_signals
def sniff_i2c_devices(bp_device, power='off'): def sniff_i2c_devices(bp_device, power=False):
init_i2c(bp_device, power) init_i2c(bp_device, power)
working_addr = [] working_addr = []
for n in range(128): for n in range(128):
...@@ -93,6 +93,4 @@ def sniff_i2c_devices(bp_device, power='off'): ...@@ -93,6 +93,4 @@ def sniff_i2c_devices(bp_device, power='off'):
if 0 in ack_sig: if 0 in ack_sig:
working_addr += [n] working_addr += [n]
print(working_addr)
return working_addr return working_addr
...@@ -21,7 +21,7 @@ You should have received a copy of the GNU General Public License ...@@ -21,7 +21,7 @@ You should have received a copy of the GNU General Public License
along with pyBusPirate. If not, see <http://www.gnu.org/licenses/>. along with pyBusPirate. If not, see <http://www.gnu.org/licenses/>.
""" """
from .BitBang import BitBang from .BBIO_base import BBIO_base
class RawWireCfg: class RawWireCfg:
...@@ -41,7 +41,9 @@ class RawWire(BBIO_base): ...@@ -41,7 +41,9 @@ class RawWire(BBIO_base):
""" """
if self.mode == 'raw': if self.mode == 'raw':
return return
self.reset() if self.mode != 'bb':
super(RawWire, self).enter()
self.write(0x05) self.write(0x05)
self.timeout(self.minDelay * 10) self.timeout(self.minDelay * 10)
if self.response(4) == "RAW1": if self.response(4) == "RAW1":
...@@ -55,7 +57,6 @@ class RawWire(BBIO_base): ...@@ -55,7 +57,6 @@ class RawWire(BBIO_base):
def start_bit(self): def start_bit(self):
"""is kept in because it was in for legacy code, """is kept in because it was in for legacy code,
I recommend you use send_start_bit""" I recommend you use send_start_bit"""
self.check_mode('raw')
self.port.write(chr(0x02)) self.port.write(chr(0x02))
self.timeout(0.1) self.timeout(0.1)
return self.response(1) return self.response(1)
...@@ -63,55 +64,46 @@ class RawWire(BBIO_base): ...@@ -63,55 +64,46 @@ class RawWire(BBIO_base):
def stop_bit(self): def stop_bit(self):
"""is kept in because it was in for legacy code, """is kept in because it was in for legacy code,
I recommend you use send_stop_bit""" I recommend you use send_stop_bit"""
self.check_mode('raw')
self.port.write(chr(0x03)) self.port.write(chr(0x03))
self.timeout(0.1) self.timeout(0.1)
return self.response(1) return self.response(1)
def read_bit(self): def read_bit(self):
self.check_mode('raw')
self.port.write(chr(0x07)) self.port.write(chr(0x07))
self.timeout(0.1) self.timeout(0.1)
return self.response(1) return self.response(1)
def peek(self): def peek(self):
self.check_mode('raw')
self.port.write(chr(0x08)) self.port.write(chr(0x08))
self.timeout(0.1) self.timeout(0.1)
return self.response(1) return self.response(1)
def clock_tick(self): def clock_tick(self):
self.check_mode('raw')
self.port.write(chr(0x09)) self.port.write(chr(0x09))
self.timeout(0.1) self.timeout(0.1)
return self.response(1) return self.response(1)
def clock_low(self): def clock_low(self):
self.check_mode('raw')
self.port.write(chr(0x0a)) self.port.write(chr(0x0a))
self.timeout(0.1) self.timeout(0.1)
return self.response(1) return self.response(1)
def clock_high(self): def clock_high(self):
self.check_mode('raw')
self.port.write(chr(0x0b)) self.port.write(chr(0x0b))
self.timeout(0.1) self.timeout(0.1)
return self.response(1) return self.response(1)
def data_low(self): def data_low(self):
self.check_mode('raw')
self.port.write(chr(0x0c)) self.port.write(chr(0x0c))
self.timeout(0.1) self.timeout(0.1)
return self.response(1) return self.response(1)
def data_high(self): def data_high(self):
self.check_mode('raw')
self.port.write(chr(0x0d)) self.port.write(chr(0x0d))
self.timeout(0.1) self.timeout(0.1)
return self.response(1) return self.response(1)
def wire_cfg(self, pins = 0): def wire_cfg(self, pins = 0):
self.check_mode('raw')
self.port.write(chr(0x80 | pins)) self.port.write(chr(0x80 | pins))
self.timeout(0.1) self.timeout(0.1)
return self.response(1) return self.response(1)
...@@ -120,7 +112,6 @@ class RawWire(BBIO_base): ...@@ -120,7 +112,6 @@ class RawWire(BBIO_base):
# (make it similar to my configure_peripherals) # (make it similar to my configure_peripherals)
def bulk_clock_ticks(self, ticks = 1): def bulk_clock_ticks(self, ticks = 1):
self.check_mode('raw')
self.port.write(chr(0x20 | (ticks - 1))) self.port.write(chr(0x20 | (ticks - 1)))
self.timeout(0.1) self.timeout(0.1)
return self.response(1) return self.response(1)
...@@ -28,7 +28,6 @@ def test_connect_on_init(): ...@@ -28,7 +28,6 @@ def test_connect_on_init():
def test_adc(): def test_adc():
bb = BitBang() bb = BitBang()
value = bb.adc value = bb.adc
print(value)
assert 0.0 <= value <= 5.0 assert 0.0 <= value <= 5.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment