@@ -174,6 +174,7 @@ def __init__(self, *, debug=False, reset=None):
174
174
reset .value = True
175
175
time .sleep (1 )
176
176
try :
177
+ self ._wakeup ()
177
178
self .get_firmware_version () # first time often fails, try 2ce
178
179
return
179
180
except :
@@ -389,6 +390,38 @@ def mifare_classic_write_block(self, block_number, data):
389
390
return response [0 ] == 0x0
390
391
391
392
393
+ class PN532_UART (PN532 ):
394
+ """Driver for the PN532 connected over Serial UART"""
395
+ def __init__ (self , uart , * , irq = None , reset = None , debug = False ):
396
+ """Create an instance of the PN532 class using Serial connection
397
+ """
398
+ self .debug = debug
399
+ self ._irq = irq
400
+ self ._uart = uart
401
+ super ().__init__ (debug = debug , reset = reset )
402
+
403
+ def _wakeup (self ):
404
+ #self._write_frame([_HOSTTOPN532, _COMMAND_SAMCONFIGURATION, 0x01])
405
+ self .SAM_configuration ()
406
+
407
+ def _wait_ready (self , timeout = 1 ):
408
+ time .sleep (timeout )
409
+ return True
410
+
411
+ def _read_data (self , count ):
412
+ """Read a specified count of bytes from the PN532."""
413
+ frame = self ._uart .read (count )
414
+ if not frame :
415
+ raise BusyError ("No data read from PN532" )
416
+ if self .debug :
417
+ print ("Reading: " , [hex (i ) for i in frame ])
418
+ return frame
419
+
420
+ def _write_data (self , framebytes ):
421
+ while self ._uart .read (1 ): # this would be a lot nicer if we could query the # of bytes
422
+ pass
423
+ self ._uart .write ('\x55 \x55 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 ' ) # wake up!
424
+ self ._uart .write (framebytes )
392
425
393
426
class PN532_I2C (PN532 ):
394
427
"""Driver for the PN532 connected over I2C."""
@@ -404,6 +437,9 @@ def __init__(self, i2c, *, irq=None, reset=None, debug=False):
404
437
self ._i2c = i2c_device .I2CDevice (i2c , _I2C_ADDRESS )
405
438
super ().__init__ (debug = debug , reset = reset )
406
439
440
+ def _wakeup (self ):
441
+ time .sleep (0.5 )
442
+
407
443
def _wait_ready (self , timeout = 1 ):
408
444
status = bytearray (1 )
409
445
t = time .monotonic ()
@@ -444,6 +480,10 @@ def __init__(self, spi, cs_pin, *, irq=None, reset=None, debug=False):
444
480
self ._spi = spi_device .SPIDevice (spi , cs_pin )
445
481
super ().__init__ (debug = debug , reset = reset )
446
482
483
+ def _wakeup (self ):
484
+ with self ._spi as spi :
485
+ time .sleep (1 )
486
+
447
487
def _wait_ready (self , timeout = 1 ):
448
488
status = bytearray ([reverse_bit (_SPI_STATREAD ), 0 ])
449
489
0 commit comments