41
41
import adafruit_bus_device .i2c_device as i2c_device
42
42
from digitalio import Direction
43
43
from micropython import const
44
- from adafruit_pn532 .adafruit_pn532 import PN532 , BusyError , _reset
44
+ from adafruit_pn532 .adafruit_pn532 import PN532 , BusyError
45
45
46
46
_I2C_ADDRESS = const (0x24 )
47
47
@@ -55,23 +55,23 @@ def __init__(self, i2c, *, irq=None, reset=None, req=None, debug=False):
55
55
reset pin and debugging output.
56
56
"""
57
57
self .debug = debug
58
- self ._irq = irq
59
58
self ._req = req
60
- if reset :
61
- _reset (reset )
62
59
self ._i2c = i2c_device .I2CDevice (i2c , _I2C_ADDRESS )
63
- super ().__init__ (debug = debug , reset = reset )
60
+ super ().__init__ (debug = debug , irq = irq , reset = reset )
64
61
65
62
def _wakeup (self ): # pylint: disable=no-self-use
66
63
"""Send any special commands/data to wake up PN532"""
64
+ if self ._reset_pin :
65
+ self ._reset_pin .value = True
66
+ time .sleep (0.01 )
67
67
if self ._req :
68
68
self ._req .direction = Direction .OUTPUT
69
- self ._req .value = True
70
- time .sleep (0.1 )
71
69
self ._req .value = False
72
- time .sleep (0.1 )
70
+ time .sleep (0.01 )
73
71
self ._req .value = True
74
- time .sleep (0.5 )
72
+ time .sleep (0.01 )
73
+ self .low_power = False
74
+ self .SAM_configuration () # Put the PN532 back in normal mode
75
75
76
76
def _wait_ready (self , timeout = 1 ):
77
77
"""Poll PN532 if status byte is ready, up to `timeout` seconds"""
@@ -82,11 +82,10 @@ def _wait_ready(self, timeout=1):
82
82
with self ._i2c :
83
83
self ._i2c .readinto (status )
84
84
except OSError :
85
- self ._wakeup ()
86
85
continue
87
86
if status == b"\x01 " :
88
87
return True # No longer busy
89
- time .sleep (0.05 ) # lets ask again soon!
88
+ time .sleep (0.01 ) # lets ask again soon!
90
89
# Timed out!
91
90
return False
92
91
@@ -101,8 +100,6 @@ def _read_data(self, count):
101
100
i2c .readinto (frame ) # ok get the data, plus statusbyte
102
101
if self .debug :
103
102
print ("Reading: " , [hex (i ) for i in frame [1 :]])
104
- else :
105
- time .sleep (0.1 )
106
103
return frame [1 :] # don't return the status byte
107
104
108
105
def _write_data (self , framebytes ):
0 commit comments