Commit a1d12ef3 authored by Jürgen Hasch's avatar Jürgen Hasch

Fix initialization

parent 3fba0fe9
...@@ -15,7 +15,7 @@ endif ...@@ -15,7 +15,7 @@ endif
# Internal variables. # Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
# the i18n builder cannot share the environment and doctrees with the others # the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
......
...@@ -84,22 +84,29 @@ class BBIO_base: ...@@ -84,22 +84,29 @@ class BBIO_base:
raise IOError('Device not connected') raise IOError('Device not connected')
self.timeout(self.minDelay * 10) self.timeout(self.minDelay * 10)
self.port.flushInput() self.port.flushInput()
for i in range(20):
for i in range(10):
self.write(0x00) self.write(0x00)
r = self.response(1, True) r = self.response(1, True)
if r: if r:
break break
for i in range(2):
self.write(0x00)
self.timeout(self.minDelay * 10)
self.port.flushInput() self.port.flushInput()
self.timeout(self.minDelay * 10)
resp = self.response(200)
self.write(0x00) self.write(0x00)
if self.response(5) == "BBIO1": resp = self.response(5)
# print('RESP:', resp)
if resp == "BBIO1":
self.mode = 'bb' self.mode = 'bb'
self.bp_config = 0x00 # configuration bits determine action of power sources and pullups self.bp_config = 0x00 # configuration bits determine action of power sources and pullups
self.bp_port = 0x00 # out_port similar to ports in microcontrollers self.bp_port = 0x00 # out_port similar to ports in microcontrollers
self.bp_dir = 0x1F # direction port similar to microchip microcontrollers. (1) is input, (0) is output self.bp_dir = 0x1F # direction port similar to microchip microcontrollers. (1) is input, (0) is output
self.recurse_end()
self.port.flushInput() self.port.flushInput()
return return True
self.recurse_flush(self.enter)
raise BPError('Could not enter bitbang mode') raise BPError('Could not enter bitbang mode')
...@@ -111,11 +118,11 @@ class BBIO_base: ...@@ -111,11 +118,11 @@ class BBIO_base:
and the Bus Pirate returns to the user terminal interface. Send 0x00 20 times to enter binary mode again. and the Bus Pirate returns to the user terminal interface. Send 0x00 20 times to enter binary mode again.
""" """
self.write(0x0f) self.write(0x0f)
self.port.reset_input_buffer() self.port.flushInput()
self.timeout(.1) self.timeout(.1)
self.mode = None self.mode = None
def connect(self, portname='', speed=115200, timeout=1): def connect(self, portname='', speed=115200, timeout=0.1):
""" will try to automatically find a port regardless of os """ will try to automatically find a port regardless of os
Parameters Parameters
...@@ -197,7 +204,7 @@ class BBIO_base: ...@@ -197,7 +204,7 @@ class BBIO_base:
self._attempts_ += 1 self._attempts_ += 1
for n in range(5): for n in range(5):
self.write(0x00) self.write(0x00)
self.port.flushInput() self.port.flushInput()
return function(*args) return function(*args)
raise IOError('bus pirate malfunctioning') raise IOError('bus pirate malfunctioning')
......
...@@ -49,7 +49,7 @@ PIN_POWER = 8 ...@@ -49,7 +49,7 @@ PIN_POWER = 8
class SPI(BBIO_base): class SPI(BBIO_base):
def __init__(self, portname='', speed=115200, timeout=1, connect=True): def __init__(self, portname='', speed=115200, timeout=0.1, connect=True):
""" Provide high-speed access to the Bus Pirate SPI hardware """ Provide high-speed access to the Bus Pirate SPI hardware
Parameters Parameters
...@@ -93,13 +93,13 @@ class SPI(BBIO_base): ...@@ -93,13 +93,13 @@ class SPI(BBIO_base):
""" """
if self.mode == 'spi': if self.mode == 'spi':
return return
if self.mode != 'bb':
super(SPI, self).enter()
self.write(0x01) self.write(0x01)
self.timeout(self.minDelay * 10)
if self.response(4) == "SPI1": if self.response(4) == "SPI1":
self.mode = 'spi' self.mode = 'spi'
self.recurse_end()
return return
self.recurse_flush(self.enter)
raise BPError('Could not enter SPI mode') raise BPError('Could not enter SPI mode')
@property @property
......
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