1919import ql_fs
2020import utime as time
2121from machine import UART
22- from machine import Timer
2322from queue import Queue
24- from machine import Pin
2523
2624SOH = b'\x01 '
2725STX = b'\x02 '
@@ -50,7 +48,7 @@ def __init__(self,
5048
5149 self ._uart = UART (uart , buadrate , databits , parity , stopbits , flowctl )
5250 self ._queue = Queue (maxsize = 1 )
53- self ._timer = Timer ( Timer . Timer1 )
51+ self ._timer = osTimer ( )
5452 self ._uart .set_callback (self ._uart_cb )
5553
5654 def _uart_cb (self , * args ):
@@ -70,7 +68,7 @@ def read(self, nbytes, timeout=0):
7068 if self ._uart .any () == 0 and timeout != 0 :
7169 timer_started = False
7270 if timeout > 0 : # < 0 for wait forever
73- self ._timer .start (period = timeout , mode = Timer . ONE_SHOT , callback = self ._timer_cb )
71+ self ._timer .start (timeout , 0 , self ._timer_cb )
7472 timer_started = True
7573 self ._queue .get ()
7674 if timer_started :
@@ -118,7 +116,7 @@ class Modem(object):
118116 0x7c26 , 0x6c07 , 0x5c64 , 0x4c45 , 0x3ca2 , 0x2c83 , 0x1ce0 , 0x0cc1 ,
119117 0xef1f , 0xff3e , 0xcf5d , 0xdf7c , 0xaf9b , 0xbfba , 0x8fd9 , 0x9ff8 ,
120118 0x6e17 , 0x7e36 , 0x4e55 , 0x5e74 , 0x2e93 , 0x3eb2 , 0x0ed1 , 0x1ef0 ,
121- ]
119+ ] # TODO release mem
122120
123121 def __init__ (self , reader , writer , mode = 'ymodem1k' ):
124122 self .reader = reader
@@ -232,12 +230,7 @@ def recv(self, crc_mode=1, retry=10, timeout=1000, delay=1, callback=None):
232230 return False
233231
234232 def _in_transfer_mode (self , crc_mode , retry , delay , timeout = 1000 , cancel = 0 , error_count = 0 ):
235- gpio1 = Pin (Pin .GPIO28 , Pin .OUT , Pin .PULL_DISABLE , 1 )
236233 while True :
237- if gpio1 .read () == 0 :
238- gpio1 .write (1 )
239- else :
240- gpio1 .write (0 )
241234 if error_count >= retry :
242235 self .abort ()
243236 return None
@@ -387,14 +380,14 @@ def _calc_crc(self, data, crc=0):
387380 return crc & 0xffff
388381
389382 def send (self ):
390- pass
383+ pass # TODO
391384
392385
393386def enter_ymodem (callback = None ):
394- serial_io = Serial (UART .UART3 )
387+ serial_io = Serial (UART .UART3 ) #TODO
395388 receiver = Modem (serial_io .read , serial_io .write )
396389 receiver .recv (callback = callback )
397- serial_io .close ()
390+ serial_io .close () #TODO
398391
399392
400393if __name__ == '__main__' :
0 commit comments