remove buggy workaround on read

This commit is contained in:
Florent Kermarrec 2012-09-15 20:13:18 +02:00
parent 84fabd28a2
commit 50da5bfbf0
1 changed files with 11 additions and 9 deletions

View File

@ -12,17 +12,16 @@ class Uart2Spi:
self.port = port self.port = port
self.baudrate = baudrate self.baudrate = baudrate
self.debug = debug self.debug = debug
self.uart = serial.Serial(port, baudrate, timeout=0.01) self.uart = serial.Serial(port, baudrate, timeout=0.25)
def read(self, addr): def read(self, addr):
while True: write_b(self.uart, 0x02)
write_b(self.uart, 0x02) write_b(self.uart, (addr>>8)&0xFF)
write_b(self.uart, (addr>>8)&0xFF) write_b(self.uart, (addr&0xFF))
write_b(self.uart, (addr&0xFF)) write_b(self.uart, 0x00)
write_b(self.uart, 0x00) read = self.uart.read()
read = self.uart.read() if self.debug:
if len(read) == 1: print("RD @ %04X" %addr)
break
return int(read[0]) return int(read[0])
def read_n(self, addr, n, endianess = "LE"): def read_n(self, addr, n, endianess = "LE"):
@ -33,8 +32,11 @@ class Uart2Spi:
r += self.read(addr+i)<<(8*i) r += self.read(addr+i)<<(8*i)
elif endianess == "LE": elif endianess == "LE":
r += self.read(addr+words-1-i)<<(8*i) r += self.read(addr+words-1-i)<<(8*i)
if self.debug:
print("RD @ %04X" %addr)
return r return r
def write(self, addr, data): def write(self, addr, data):
write_b(self.uart, 0x01) write_b(self.uart, 0x01)
write_b(self.uart, (addr>>8)&0xFF) write_b(self.uart, (addr>>8)&0xFF)